From 8d1a70f823a82a144fb837a375a12b2a659b714d Mon Sep 17 00:00:00 2001 From: Marco Granelli Date: Tue, 3 Jun 2025 15:41:13 +0200 Subject: [PATCH 1/3] Updates block proposer balances for foreing fees --- chain/src/main.rs | 9 ++++++++- shared/src/block.rs | 13 +++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/chain/src/main.rs b/chain/src/main.rs index c5ad0da4..45b96c39 100644 --- a/chain/src/main.rs +++ b/chain/src/main.rs @@ -286,7 +286,14 @@ async fn crawling_fn( namada_service::query_native_addresses_balance_change(Token::Native( native_token.clone(), )); - let addresses = block.addresses_with_balance_change(&native_token); + let addresses = block.addresses_with_balance_change( + &native_token, + block + .header + .proposer_address_namada + .as_ref() + .map(|address| Id::Account(address.clone())), + ); let token_supplies = first_block_in_epoch .eq(&block_height) diff --git a/shared/src/block.rs b/shared/src/block.rs index 7c26ac55..410d5d2a 100644 --- a/shared/src/block.rs +++ b/shared/src/block.rs @@ -687,6 +687,7 @@ impl Block { pub fn addresses_with_balance_change( &self, native_token: &Id, + block_proposer: Option, ) -> HashSet { self.transactions .iter() @@ -703,10 +704,22 @@ impl Block { .flatten() .collect(); + // Push the balance change of the gas payer balance_changes.push(BalanceChange::new( wrapper_tx.fee.gas_payer.clone(), Token::Native(wrapper_tx.fee.gas_token.clone()), )); + // If the token is not the native one also push the balanche + // change of the block proposer (the balance change for the + // native token is pushed by default) + if let Some(block_proposer) = &block_proposer { + if &wrapper_tx.fee.gas_token != native_token { + balance_changes.push(BalanceChange::new( + block_proposer.to_owned(), + Token::Native(wrapper_tx.fee.gas_token.clone()), + )); + } + } balance_changes }) From 23b864852f664172fc1235936d05f3961364e7fc Mon Sep 17 00:00:00 2001 From: Marco Granelli Date: Tue, 3 Jun 2025 15:49:16 +0200 Subject: [PATCH 2/3] Refactors extraction of block proposer --- chain/src/main.rs | 9 +-------- shared/src/block.rs | 9 +++++---- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/chain/src/main.rs b/chain/src/main.rs index 45b96c39..c5ad0da4 100644 --- a/chain/src/main.rs +++ b/chain/src/main.rs @@ -286,14 +286,7 @@ async fn crawling_fn( namada_service::query_native_addresses_balance_change(Token::Native( native_token.clone(), )); - let addresses = block.addresses_with_balance_change( - &native_token, - block - .header - .proposer_address_namada - .as_ref() - .map(|address| Id::Account(address.clone())), - ); + let addresses = block.addresses_with_balance_change(&native_token); let token_supplies = first_block_in_epoch .eq(&block_height) diff --git a/shared/src/block.rs b/shared/src/block.rs index 410d5d2a..2b897fde 100644 --- a/shared/src/block.rs +++ b/shared/src/block.rs @@ -687,7 +687,6 @@ impl Block { pub fn addresses_with_balance_change( &self, native_token: &Id, - block_proposer: Option, ) -> HashSet { self.transactions .iter() @@ -712,10 +711,12 @@ impl Block { // If the token is not the native one also push the balanche // change of the block proposer (the balance change for the // native token is pushed by default) - if let Some(block_proposer) = &block_proposer { - if &wrapper_tx.fee.gas_token != native_token { + if &wrapper_tx.fee.gas_token != native_token { + if let Some(block_proposer) = + &self.header.proposer_address_namada + { balance_changes.push(BalanceChange::new( - block_proposer.to_owned(), + Id::Account(block_proposer.to_owned()), Token::Native(wrapper_tx.fee.gas_token.clone()), )); } From dd4fa85cf67ee1aa02bd7fb4ac3430b621cb897c Mon Sep 17 00:00:00 2001 From: Marco Granelli Date: Wed, 4 Jun 2025 15:44:05 +0200 Subject: [PATCH 3/3] Updates PGF balance on foreing fee payment --- shared/src/block.rs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/shared/src/block.rs b/shared/src/block.rs index 2b897fde..f60cc165 100644 --- a/shared/src/block.rs +++ b/shared/src/block.rs @@ -708,10 +708,18 @@ impl Block { wrapper_tx.fee.gas_payer.clone(), Token::Native(wrapper_tx.fee.gas_token.clone()), )); - // If the token is not the native one also push the balanche - // change of the block proposer (the balance change for the - // native token is pushed by default) + + // If the token is not the native one also push the balance + // change of PGF (fee reserve) and the block proposer (the + // balance change for the native token is pushed by default) if &wrapper_tx.fee.gas_token != native_token { + balance_changes.push(BalanceChange::new( + Id::from(namada_sdk::address::Address::Internal( + namada_sdk::address::InternalAddress::Pgf, + )), + Token::Native(wrapper_tx.fee.gas_token.clone()), + )); + if let Some(block_proposer) = &self.header.proposer_address_namada {