Skip to content

Commit

Permalink
feat(sequencer)!: fees go to sudo poa (#1104)
Browse files Browse the repository at this point in the history
## Summary
Gives block fees to POA authority, and updates some snapshot tests.

## Background
During POA phase of network, we want network fees to go to the authority
account. This allows use to rebate fees to proposers while figuring out
economics.

## Changes
- Fees to sudo instead of proposer.
- Update default genesis for tests. On first pass the snapshot tests
where not failing because the default proposer and the default sudo
address were the same (just a zero address). Updated default genesis so
this should fail in the future. If payee changes.
- Fix test for payee to now be a test for fees going to sudo address.

## Testing
CI. Updated snapshot test which was not working, manually verified that
changing back to proposer as fee recipient will cause test failure.

## Breaking Changelist
- Changes receiver of fees for all blocks.
  • Loading branch information
joroshiba authored May 23, 2024
1 parent 4fbce02 commit d177874
Show file tree
Hide file tree
Showing 6 changed files with 81 additions and 100 deletions.
26 changes: 10 additions & 16 deletions crates/astria-sequencer/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -747,13 +747,15 @@ impl App {
.get_chain_id()
.await
.context("failed to get chain ID from state")?;
let sudo_address = self
.state
.get_sudo_address()
.await
.context("failed to get sudo address from state")?;

// convert tendermint id to astria address; this assumes they are
// the same address, as they are both ed25519 keys
let proposer_address = finalize_block.proposer_address;
let astria_proposer_address =
Address::try_from_slice(finalize_block.proposer_address.as_bytes())
.context("failed to convert proposer tendermint id to astria address")?;

let height = finalize_block.height;
let time = finalize_block.time;
Expand Down Expand Up @@ -835,9 +837,7 @@ impl App {
tx_results.extend(execution_results);
};

let end_block = self
.end_block(height.value(), astria_proposer_address)
.await?;
let end_block = self.end_block(height.value(), sudo_address).await?;

// get and clear block deposits from state
let mut state_tx = StateDelta::new(self.state.clone());
Expand Down Expand Up @@ -1010,7 +1010,7 @@ impl App {
pub(crate) async fn end_block(
&mut self,
height: u64,
proposer_address: Address,
fee_recipient: Address,
) -> anyhow::Result<abci::response::EndBlock> {
let state_tx = StateDelta::new(self.state.clone());
let mut arc_state_tx = Arc::new(state_tx);
Expand Down Expand Up @@ -1059,16 +1059,10 @@ impl App {
.context("failed to get block fees")?;

for (asset, amount) in fees {
let balance = state_tx
.get_account_balance(proposer_address, asset)
.await
.context("failed to get proposer account balance")?;
let new_balance = balance
.checked_add(amount)
.context("account balance overflowed u128")?;
state_tx
.put_account_balance(proposer_address, asset, new_balance)
.context("failed to put proposer account balance")?;
.increase_balance(fee_recipient, asset, amount)
.await
.context("failed to increase fee recipient balance")?;
}

// clear block fees
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,36 @@ source: crates/astria-sequencer/src/app/tests_breaking_changes.rs
expression: app.app_hash.as_bytes()
---
[
110,
57,
239,
200,
69,
178,
164,
1,
209,
124,
151,
238,
176,
163,
203,
213,
34,
90,
171,
98,
3,
172,
104,
125,
33,
11,
77,
86,
230,
236,
153,
226,
74,
29,
92,
21,
38,
30,
218,
176,
165,
209
227,
158,
59,
19,
108,
136,
6,
56,
175,
113,
196,
108,
171,
66,
211,
241,
217,
82,
191,
152
]
Original file line number Diff line number Diff line change
Expand Up @@ -3,36 +3,36 @@ source: crates/astria-sequencer/src/app/tests_breaking_changes.rs
expression: app.app_hash.as_bytes()
---
[
219,
22,
109,
121,
104,
40,
134,
239,
14,
66,
234,
223,
96,
123,
174,
58,
255,
111,
202,
30,
237,
96,
84,
181,
106,
173,
93,
117,
49,
7,
3,
13,
206,
123,
228
244,
114,
95,
76,
26,
53,
191,
78,
217,
100,
131,
48,
137,
180,
89,
93,
56,
249,
56,
247,
253,
10,
113,
108,
87,
250,
68,
145
]
6 changes: 4 additions & 2 deletions crates/astria-sequencer/src/app/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ pub(crate) fn address_from_hex_string(s: &str) -> Address {
pub(crate) const ALICE_ADDRESS: &str = "1c0c490f1b5528d8173c5de46d131160e4b2c0c3";
pub(crate) const BOB_ADDRESS: &str = "34fec43c7fcab9aef3b3cf8aba855e41ee69ca3a";
pub(crate) const CAROL_ADDRESS: &str = "60709e2d391864b732b4f0f51e387abb76743871";
pub(crate) const JUDY_ADDRESS: &str = "bc5b91da07778eeaf622d0dcf4d7b4233525998d";
pub(crate) const TED_ADDRESS: &str = "4c4f91d8a918357ab5f6f19c1e179968fc39bb44";

pub(crate) fn get_alice_signing_key_and_address() -> (SigningKey, Address) {
// this secret key corresponds to ALICE_ADDRESS
Expand Down Expand Up @@ -101,8 +103,8 @@ pub(crate) async fn initialize_app_with_storage(

let genesis_state = genesis_state.unwrap_or_else(|| GenesisState {
accounts: default_genesis_accounts(),
authority_sudo_address: Address::from([0; 20]),
ibc_sudo_address: Address::from([0; 20]),
authority_sudo_address: address_from_hex_string(JUDY_ADDRESS),
ibc_sudo_address: address_from_hex_string(TED_ADDRESS),
ibc_relayer_addresses: vec![],
native_asset_base_denomination: DEFAULT_NATIVE_ASSET_DENOM.to_string(),
ibc_params: IBCParameters::default(),
Expand Down
24 changes: 4 additions & 20 deletions crates/astria-sequencer/src/app/tests_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use astria_core::{
sequencerblock::v1alpha1::block::Deposit,
};
use cnidarium::StateDelta;
use penumbra_ibc::params::IBCParameters;
use prost::Message as _;
use tendermint::{
abci::{
Expand Down Expand Up @@ -52,10 +51,7 @@ use crate::{
StateReadExt as _,
StateWriteExt,
},
genesis::{
Account,
GenesisState,
},
genesis::Account,
mempool::TransactionPriority,
proposal::commitment::generate_rollup_datas_commitment,
state_ext::StateReadExt as _,
Expand Down Expand Up @@ -191,18 +187,7 @@ async fn app_begin_block_remove_byzantine_validators() {

#[tokio::test]
async fn app_commit() {
let genesis_state = GenesisState {
accounts: default_genesis_accounts(),
authority_sudo_address: Address::from([0; 20]),
ibc_sudo_address: Address::from([0; 20]),
ibc_relayer_addresses: vec![],
native_asset_base_denomination: DEFAULT_NATIVE_ASSET_DENOM.to_string(),
ibc_params: IBCParameters::default(),
allowed_fee_assets: vec![DEFAULT_NATIVE_ASSET_DENOM.to_owned().into()],
fees: default_fees(),
};

let (mut app, storage) = initialize_app_with_storage(Some(genesis_state), vec![]).await;
let (mut app, storage) = initialize_app_with_storage(None, vec![]).await;
assert_eq!(app.state.get_block_height().await.unwrap(), 0);

let native_asset = get_native_asset().id();
Expand Down Expand Up @@ -243,7 +228,7 @@ async fn app_commit() {
}

#[tokio::test]
async fn app_transfer_block_fees_to_proposer() {
async fn app_transfer_block_fees_to_sudo() {
let (mut app, storage) = initialize_app_with_storage(None, vec![]).await;

let (alice_signing_key, _) = get_alice_signing_key_and_address();
Expand Down Expand Up @@ -271,7 +256,6 @@ async fn app_transfer_block_fees_to_proposer() {
let signed_tx = tx.into_signed(&alice_signing_key);

let proposer_address: tendermint::account::Id = [99u8; 20].to_vec().try_into().unwrap();
let sequencer_proposer_address = Address::try_from_slice(proposer_address.as_bytes()).unwrap();

let commitments = generate_rollup_datas_commitment(&[signed_tx.clone()], HashMap::new());

Expand All @@ -297,7 +281,7 @@ async fn app_transfer_block_fees_to_proposer() {
let transfer_fee = app.state.get_transfer_base_fee().await.unwrap();
assert_eq!(
app.state
.get_account_balance(sequencer_proposer_address, native_asset)
.get_account_balance(address_from_hex_string(JUDY_ADDRESS), native_asset)
.await
.unwrap(),
transfer_fee,
Expand Down
3 changes: 2 additions & 1 deletion crates/astria-sequencer/src/app/tests_breaking_changes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ async fn app_finalize_block_snapshot() {
let deposits = HashMap::from_iter(vec![(rollup_id, vec![expected_deposit.clone()])]);
let commitments = generate_rollup_datas_commitment(&[signed_tx.clone()], deposits.clone());

let timestamp = Time::now();
let timestamp = Time::unix_epoch();
let block_hash = Hash::try_from([99u8; 32].to_vec()).unwrap();
let finalize_block = abci::request::FinalizeBlock {
hash: block_hash,
Expand All @@ -138,6 +138,7 @@ async fn app_finalize_block_snapshot() {
app.finalize_block(finalize_block.clone(), storage.clone())
.await
.unwrap();
app.commit(storage.clone()).await;
insta::assert_json_snapshot!(app.app_hash.as_bytes());
}

Expand Down

0 comments on commit d177874

Please sign in to comment.