Skip to content

Commit

Permalink
feat(sequencer): transfer fees to block proposer instead of burning (#…
Browse files Browse the repository at this point in the history
…690)

## Summary
accumulate block fees during tx execution and transfer them to the block
proposer in `end_block`.

## Background
we don't want to burn tx fees especially not if they are IBC assets.

## Changes
- implement `get_block_fees`, `get_and_increase_block_fees`, and
`clear_block_fees` which get, increase, and clear the block fees
respectively
- during action execution where there is fee payment (transfer and
sequencer), update the current block fees state.
- in `begin_block` store the proposer address (needed b/c `end_block`
doesn't receive it, this can be removed when we move to comet 0.38)
- in `end_block` transfer the fees to the proposer and clear the cached
address

## Testing
unit test

## Breaking Changelist
changes the state by not burning tokens.

## Related Issues

closes  #649
  • Loading branch information
noot authored Jan 19, 2024
1 parent ede0e70 commit dc449e7
Show file tree
Hide file tree
Showing 6 changed files with 245 additions and 49 deletions.
61 changes: 31 additions & 30 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions crates/astria-core/src/sequencer/v1alpha1/asset.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
use std::{
fmt,
fmt::{
Display,
Formatter,
},
};

/// The default sequencer asset base denomination.
pub const DEFAULT_NATIVE_ASSET_DENOM: &str = "nria";

Expand Down Expand Up @@ -93,6 +101,12 @@ impl AsRef<[u8]> for Id {
}
}

impl Display for Id {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
write!(f, "{}", hex::encode(self.0))
}
}

/// Indicates that the protobuf response contained an array field that was not 32 bytes long.
#[derive(Debug, thiserror::Error)]
#[error("expected 32 bytes, got {received}")]
Expand Down
6 changes: 6 additions & 0 deletions crates/astria-sequencer/src/accounts/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::{
StateReadExt,
StateWriteExt,
},
state_ext::StateWriteExt as _,
transaction::action_handler::ActionHandler,
};

Expand Down Expand Up @@ -83,6 +84,11 @@ impl ActionHandler for TransferAction {
from: Address,
fee_asset_id: asset::Id,
) -> Result<()> {
state
.get_and_increase_block_fees(fee_asset_id, TRANSFER_FEE)
.await
.context("failed to add to block fees")?;

let transfer_asset_id = self.asset_id;

let from_balance = state
Expand Down
Loading

0 comments on commit dc449e7

Please sign in to comment.