Skip to content

Commit

Permalink
feat(sequencer)!: add fees to genesis state (#1055)
Browse files Browse the repository at this point in the history
## Summary
instead of having hard coded default fee values, the fees now must be
set in the genesis file. this makes it more explicit as to how the
network is configured.

## Background
related to #1003

## Changes
- update genesis app state to contain required fees
- set these fees in state in `init_chain`

## Testing
unit tests

## Breaking Changelist
- genesis app state must now contain fees

## Related Issues

related to #1003
  • Loading branch information
noot authored May 9, 2024
1 parent 5f972b6 commit 55f16b9
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 34 deletions.
2 changes: 1 addition & 1 deletion charts/sequencer/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type: application
# This is the chart version. This version number should be incremented each time you make changes
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)
version: 0.13.5
version: 0.13.6

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand Down
8 changes: 8 additions & 0 deletions charts/sequencer/files/cometbft/config/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
],
"authority_sudo_address": "{{ .Values.config.sequencer.authoritySudoAddress }}",
"native_asset_base_denomination": "{{ .Values.config.sequencer.nativeAssetBaseDenomination }}",
"fees": {
"transfer_base_fee": 12,
"sequence_base_fee": 32,
"sequence_byte_cost_multiplier": 1,
"init_bridge_account_base_fee": 48,
"bridge_lock_byte_cost_multiplier": 1,
"ics20_withdrawal_base_fee": 24
},
"allowed_fee_assets": [
{{- range $index, $value := .Values.config.sequencer.allowedFeeAssets }}
{{- if $index }},{{- end }}
Expand Down
6 changes: 1 addition & 5 deletions crates/astria-sequencer/src/accounts/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ use crate::{
genesis::GenesisState,
};

/// Default transfer base fee.
/// TODO: put in app genesis state
pub(crate) const DEFAULT_TRANSFER_BASE_FEE: u128 = 12;

#[derive(Default)]
pub(crate) struct AccountsComponent;

Expand All @@ -38,7 +34,7 @@ impl Component for AccountsComponent {
}

state
.put_transfer_base_fee(DEFAULT_TRANSFER_BASE_FEE)
.put_transfer_base_fee(app_state.fees.transfer_base_fee)
.context("failed to put transfer base fee")?;
Ok(())
}
Expand Down
13 changes: 13 additions & 0 deletions crates/astria-sequencer/src/app/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use penumbra_ibc::params::IBCParameters;
use crate::{
app::App,
genesis::{
self,
Account,
GenesisState,
},
Expand Down Expand Up @@ -65,6 +66,17 @@ pub(crate) fn default_genesis_accounts() -> Vec<Account> {
]
}

pub(crate) fn default_fees() -> genesis::Fees {
genesis::Fees {
transfer_base_fee: 12,
sequence_base_fee: 32,
sequence_byte_cost_multiplier: 1,
init_bridge_account_base_fee: 48,
bridge_lock_byte_cost_multiplier: 1,
ics20_withdrawal_base_fee: 24,
}
}

pub(crate) async fn initialize_app_with_storage(
genesis_state: Option<GenesisState>,
genesis_validators: Vec<tendermint::validator::Update>,
Expand All @@ -84,6 +96,7 @@ pub(crate) async fn initialize_app_with_storage(
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(),
});

app.init_chain(
Expand Down
1 change: 1 addition & 0 deletions crates/astria-sequencer/src/app/tests_app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ async fn app_commit() {
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;
Expand Down
10 changes: 10 additions & 0 deletions crates/astria-sequencer/src/app/tests_execute_transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,7 @@ async fn app_execute_transaction_validator_update() {
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 = initialize_app(Some(genesis_state), vec![]).await;

Expand Down Expand Up @@ -321,6 +322,7 @@ async fn app_execute_transaction_ibc_relayer_change_addition() {
native_asset_base_denomination: DEFAULT_NATIVE_ASSET_DENOM.to_string(),
allowed_fee_assets: vec![DEFAULT_NATIVE_ASSET_DENOM.to_owned().into()],
ibc_params: IBCParameters::default(),
fees: default_fees(),
};
let mut app = initialize_app(Some(genesis_state), vec![]).await;

Expand Down Expand Up @@ -350,6 +352,7 @@ async fn app_execute_transaction_ibc_relayer_change_deletion() {
native_asset_base_denomination: DEFAULT_NATIVE_ASSET_DENOM.to_string(),
allowed_fee_assets: vec![DEFAULT_NATIVE_ASSET_DENOM.to_owned().into()],
ibc_params: IBCParameters::default(),
fees: default_fees(),
};
let mut app = initialize_app(Some(genesis_state), vec![]).await;

Expand Down Expand Up @@ -379,6 +382,7 @@ async fn app_execute_transaction_ibc_relayer_change_invalid() {
native_asset_base_denomination: DEFAULT_NATIVE_ASSET_DENOM.to_string(),
allowed_fee_assets: vec![DEFAULT_NATIVE_ASSET_DENOM.to_owned().into()],
ibc_params: IBCParameters::default(),
fees: default_fees(),
};
let mut app = initialize_app(Some(genesis_state), vec![]).await;

Expand Down Expand Up @@ -406,6 +410,7 @@ async fn app_execute_transaction_sudo_address_change() {
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 = initialize_app(Some(genesis_state), vec![]).await;

Expand Down Expand Up @@ -442,6 +447,7 @@ async fn app_execute_transaction_sudo_address_change_error() {
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 = initialize_app(Some(genesis_state), vec![]).await;

Expand Down Expand Up @@ -479,6 +485,7 @@ async fn app_execute_transaction_fee_asset_change_addition() {
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 = initialize_app(Some(genesis_state), vec![]).await;

Expand Down Expand Up @@ -519,6 +526,7 @@ async fn app_execute_transaction_fee_asset_change_removal() {
DEFAULT_NATIVE_ASSET_DENOM.to_owned().into(),
test_asset.clone(),
],
fees: default_fees(),
};
let mut app = initialize_app(Some(genesis_state), vec![]).await;

Expand Down Expand Up @@ -558,6 +566,7 @@ async fn app_execute_transaction_fee_asset_change_invalid() {
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 = initialize_app(Some(genesis_state), vec![]).await;

Expand Down Expand Up @@ -844,6 +853,7 @@ async fn app_execute_transaction_mint() {
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 = initialize_app(Some(genesis_state), vec![]).await;

Expand Down
13 changes: 2 additions & 11 deletions crates/astria-sequencer/src/bridge/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ use crate::{
genesis::GenesisState,
};

/// Default base fee for a [`InitBridgeAccountAction`].
const DEFAULT_INIT_BRIDGE_ACCOUNT_BASE_FEE: u128 = 48;

/// Default multiplier for the cost of a byte in a [`BridgeLockAction`].
///
/// Note that the base fee for a [`BridgeLockAction`] is the same as the
/// base fee for a [`TransferAction`].
const DEFAULT_BRIDGE_LOCK_BYTE_COST_MULTIPLIER: u128 = 1;

#[derive(Default)]
pub(crate) struct BridgeComponent;

Expand All @@ -31,8 +22,8 @@ impl Component for BridgeComponent {

#[instrument(name = "BridgeComponent::init_chain", skip(state))]
async fn init_chain<S: StateWriteExt>(mut state: S, app_state: &Self::AppState) -> Result<()> {
state.put_init_bridge_account_base_fee(DEFAULT_INIT_BRIDGE_ACCOUNT_BASE_FEE);
state.put_bridge_lock_byte_cost_multiplier(DEFAULT_BRIDGE_LOCK_BYTE_COST_MULTIPLIER);
state.put_init_bridge_account_base_fee(app_state.fees.init_bridge_account_base_fee);
state.put_bridge_lock_byte_cost_multiplier(app_state.fees.bridge_lock_byte_cost_multiplier);
Ok(())
}

Expand Down
19 changes: 19 additions & 0 deletions crates/astria-sequencer/src/genesis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ pub(crate) struct GenesisState {
pub(crate) ibc_params: IBCParameters,
#[serde(deserialize_with = "deserialize_assets")]
pub(crate) allowed_fee_assets: Vec<asset::Denom>,
pub(crate) fees: Fees,
}

#[derive(Debug, Deserialize)]
pub(crate) struct Fees {
pub(crate) transfer_base_fee: u128,
pub(crate) sequence_base_fee: u128,
pub(crate) sequence_byte_cost_multiplier: u128,
pub(crate) init_bridge_account_base_fee: u128,
pub(crate) bridge_lock_byte_cost_multiplier: u128,
pub(crate) ics20_withdrawal_base_fee: u128,
}

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -101,6 +112,14 @@ mod test {
"inbound_ics20_transfers_enabled": true,
"outbound_ics20_transfers_enabled": true
},
"fees": {
"transfer_base_fee": 12,
"sequence_base_fee": 32,
"sequence_byte_cost_multiplier": 1,
"init_bridge_account_base_fee": 48,
"bridge_lock_byte_cost_multiplier": 1,
"ics20_withdrawal_base_fee": 24
},
"native_asset_base_denomination": "nria",
"allowed_fee_assets": ["nria"]
}
Expand Down
4 changes: 1 addition & 3 deletions crates/astria-sequencer/src/ibc/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ use crate::{
},
};

pub(crate) const DEFAULT_ICS20_WITHDRAWAL_FEE: u128 = 24;

#[derive(Default)]
pub(crate) struct IbcComponent;

Expand All @@ -51,7 +49,7 @@ impl Component for IbcComponent {
}

state
.put_ics20_withdrawal_base_fee(DEFAULT_ICS20_WITHDRAWAL_FEE)
.put_ics20_withdrawal_base_fee(app_state.fees.ics20_withdrawal_base_fee)
.context("failed to put ics20 withdrawal base fee")?;
Ok(())
}
Expand Down
10 changes: 2 additions & 8 deletions crates/astria-sequencer/src/sequence/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ use crate::{
genesis::GenesisState,
};

/// Default base fee for a [`SequenceAction`].
const DEFAULT_SEQUENCE_ACTION_BASE_FEE: u128 = 32;

/// Default multiplier for the cost of a byte in a [`SequenceAction`].
const DEFAULT_SEQUENCE_ACTION_BYTE_COST_MULTIPLIER: u128 = 1;

#[derive(Default)]
pub(crate) struct SequenceComponent;

Expand All @@ -28,9 +22,9 @@ impl Component for SequenceComponent {

#[instrument(name = "SequenceComponent::init_chain", skip(state))]
async fn init_chain<S: StateWriteExt>(mut state: S, app_state: &Self::AppState) -> Result<()> {
state.put_sequence_action_base_fee(DEFAULT_SEQUENCE_ACTION_BASE_FEE);
state.put_sequence_action_base_fee(app_state.fees.sequence_base_fee);
state
.put_sequence_action_byte_cost_multiplier(DEFAULT_SEQUENCE_ACTION_BYTE_COST_MULTIPLIER);
.put_sequence_action_byte_cost_multiplier(app_state.fees.sequence_byte_cost_multiplier);
Ok(())
}

Expand Down
2 changes: 2 additions & 0 deletions crates/astria-sequencer/src/service/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ mod test {

use super::*;
use crate::{
app::test_utils::default_fees,
asset::get_native_asset,
mempool::{
Mempool,
Expand Down Expand Up @@ -470,6 +471,7 @@ mod test {
native_asset_base_denomination: DEFAULT_NATIVE_ASSET_DENOM.to_string(),
ibc_params: penumbra_ibc::params::IBCParameters::default(),
allowed_fee_assets: vec![DEFAULT_NATIVE_ASSET_DENOM.to_owned().into()],
fees: default_fees(),
}
}
}
Expand Down
8 changes: 2 additions & 6 deletions crates/astria-sequencer/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,9 +497,7 @@ mod test {
let snapshot = storage.latest_snapshot();
let mut state_tx = StateDelta::new(snapshot);

state_tx
.put_transfer_base_fee(crate::accounts::component::DEFAULT_TRANSFER_BASE_FEE)
.unwrap();
state_tx.put_transfer_base_fee(12).unwrap();
state_tx.put_sequence_action_base_fee(0);
state_tx.put_sequence_action_byte_cost_multiplier(1);
state_tx.put_ics20_withdrawal_base_fee(1).unwrap();
Expand Down Expand Up @@ -565,9 +563,7 @@ mod test {
let snapshot = storage.latest_snapshot();
let mut state_tx = StateDelta::new(snapshot);

state_tx
.put_transfer_base_fee(crate::accounts::component::DEFAULT_TRANSFER_BASE_FEE)
.unwrap();
state_tx.put_transfer_base_fee(12).unwrap();
state_tx.put_sequence_action_base_fee(0);
state_tx.put_sequence_action_byte_cost_multiplier(1);
state_tx.put_ics20_withdrawal_base_fee(1).unwrap();
Expand Down
8 changes: 8 additions & 0 deletions crates/astria-sequencer/test-genesis-app-state.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,14 @@
"inbound_ics20_transfers_enabled": true,
"outbound_ics20_transfers_enabled": true
},
"fees": {
"transfer_base_fee": 12,
"sequence_base_fee": 32,
"sequence_byte_cost_multiplier": 1,
"init_bridge_account_base_fee": 48,
"bridge_lock_byte_cost_multiplier": 1,
"ics20_withdrawal_base_fee": 24
},
"native_asset_base_denomination": "nria",
"allowed_fee_assets": ["nria"]
}

0 comments on commit 55f16b9

Please sign in to comment.