Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(sequencer)!: update storage keys locations and values (ENG-898) #1616

Merged
merged 8 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions crates/astria-sequencer/src/accounts/action.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use astria_core::{
protocol::transaction::v1alpha1::action::TransferAction,
Protobuf as _,
};
use astria_core::protocol::transaction::v1alpha1::action::TransferAction;
use astria_eyre::eyre::{
ensure,
OptionExt as _,
Expand Down Expand Up @@ -71,7 +68,7 @@ where
.await
.wrap_err("failed to get transfer base fee")?;
state
.get_and_increase_block_fees(&action.fee_asset, fee, TransferAction::full_name())
.get_and_increase_block_fees::<TransferAction, _>(&action.fee_asset, fee)
.await
.wrap_err("failed to add to block fees")?;

Expand Down
22 changes: 13 additions & 9 deletions crates/astria-sequencer/src/assets/state_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ use std::{
fmt::Display,
};

use astria_core::primitive::v1::asset;
use astria_core::{
primitive::v1::asset,
Protobuf,
};
use astria_eyre::{
anyhow_to_eyre,
eyre::{
Expand Down Expand Up @@ -36,13 +39,13 @@ use super::storage::{
use crate::storage::StoredValue;

/// Creates `abci::Event` of kind `tx.fees` for sequencer fee reporting
fn construct_tx_fee_event<T: Display>(asset: &T, fee_amount: u128, action_type: String) -> Event {
fn construct_tx_fee_event<P: Protobuf, T: Display>(asset: &T, fee_amount: u128) -> Event {
Fraser999 marked this conversation as resolved.
Show resolved Hide resolved
Event::new(
"tx.fees",
[
("asset", asset.to_string()).index(),
("feeAmount", fee_amount.to_string()).index(),
("actionType", action_type).index(),
("actionType", P::full_name()).index(),
],
)
}
Expand Down Expand Up @@ -174,17 +177,17 @@ pub(crate) trait StateWriteExt: StateWrite {

/// Adds `amount` to the block fees for `asset`.
#[instrument(skip_all)]
async fn get_and_increase_block_fees<'a, TAsset>(
async fn get_and_increase_block_fees<'a, P, TAsset>(
&mut self,
asset: &'a TAsset,
amount: u128,
action_type: String,
) -> Result<()>
where
TAsset: Sync + Display,
&'a TAsset: Into<Cow<'a, asset::IbcPrefixed>>,
P: Protobuf,
{
let tx_fee_event = construct_tx_fee_event(asset, amount, action_type);
let tx_fee_event = construct_tx_fee_event::<P, _>(asset, amount);
let block_fees_key = keys::block_fees(asset);

let current_amount = self
Expand Down Expand Up @@ -248,6 +251,7 @@ impl<T: StateWrite> StateWriteExt for T {}
mod tests {
use std::collections::HashSet;

use astria_core::protocol::transaction::v1alpha1::action::TransferAction;
use cnidarium::StateDelta;

use super::*;
Expand Down Expand Up @@ -315,7 +319,7 @@ mod tests {
let asset = asset_0();
let amount = 100u128;
state
.get_and_increase_block_fees(&asset, amount, "test".into())
.get_and_increase_block_fees::<TransferAction, _>(&asset, amount)
.await
.unwrap();

Expand All @@ -341,11 +345,11 @@ mod tests {
let amount_second = 200u128;

state
.get_and_increase_block_fees(&asset_first, amount_first, "test".into())
.get_and_increase_block_fees::<TransferAction, _>(&asset_first, amount_first)
.await
.unwrap();
state
.get_and_increase_block_fees(&asset_second, amount_second, "test".into())
.get_and_increase_block_fees::<TransferAction, _>(&asset_second, amount_second)
.await
.unwrap();
// holds expected
Expand Down
3 changes: 1 addition & 2 deletions crates/astria-sequencer/src/bridge/bridge_lock_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ use astria_core::{
TransferAction,
},
sequencerblock::v1alpha1::block::Deposit,
Protobuf as _,
};
use astria_eyre::eyre::{
ensure,
Expand Down Expand Up @@ -132,7 +131,7 @@ impl ActionHandler for BridgeLockAction {
let fee = byte_cost_multiplier
.saturating_mul(calculate_base_deposit_fee(&deposit).unwrap_or(u128::MAX));
state
.get_and_increase_block_fees(&self.fee_asset, fee, Self::full_name())
.get_and_increase_block_fees::<Self, _>(&self.fee_asset, fee)
.await
.wrap_err("failed to add to block fees")?;
state
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use astria_core::{
protocol::transaction::v1alpha1::action::BridgeSudoChangeAction,
Protobuf as _,
};
use astria_core::protocol::transaction::v1alpha1::action::BridgeSudoChangeAction;
use astria_eyre::eyre::{
bail,
ensure,
Expand Down Expand Up @@ -81,7 +78,7 @@ impl ActionHandler for BridgeSudoChangeAction {
.await
.wrap_err("failed to get bridge sudo change fee")?;
state
.get_and_increase_block_fees(&self.fee_asset, fee, Self::full_name())
.get_and_increase_block_fees::<Self, _>(&self.fee_asset, fee)
.await
.wrap_err("failed to add to block fees")?;
state
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use astria_core::{
primitive::v1::Address,
protocol::transaction::v1alpha1::action::InitBridgeAccountAction,
Protobuf as _,
};
use astria_eyre::eyre::{
bail,
Expand Down Expand Up @@ -109,7 +108,7 @@ impl ActionHandler for InitBridgeAccountAction {
)
.wrap_err("failed to put bridge account withdrawer address")?;
state
.get_and_increase_block_fees(&self.fee_asset, fee, Self::full_name())
.get_and_increase_block_fees::<Self, _>(&self.fee_asset, fee)
.await
.wrap_err("failed to get and increase block fees")?;
state
Expand Down
3 changes: 1 addition & 2 deletions crates/astria-sequencer/src/ibc/ics20_withdrawal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use astria_core::{
memos::v1alpha1::Ics20WithdrawalFromRollup,
transaction::v1alpha1::action,
},
Protobuf as _,
};
use astria_eyre::{
anyhow_to_eyre,
Expand Down Expand Up @@ -236,7 +235,7 @@ impl ActionHandler for action::Ics20Withdrawal {
};

state
.get_and_increase_block_fees(self.fee_asset(), fee, Self::full_name())
.get_and_increase_block_fees::<Self, _>(self.fee_asset(), fee)
.await
.wrap_err("failed to get and increase block fees")?;

Expand Down
7 changes: 2 additions & 5 deletions crates/astria-sequencer/src/sequence/action.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
use astria_core::{
protocol::transaction::v1alpha1::action::SequenceAction,
Protobuf as _,
};
use astria_core::protocol::transaction::v1alpha1::action::SequenceAction;
use astria_eyre::eyre::{
ensure,
OptionExt as _,
Expand Down Expand Up @@ -60,7 +57,7 @@ impl ActionHandler for SequenceAction {
ensure!(curr_balance >= fee, "insufficient funds");

state
.get_and_increase_block_fees(&self.fee_asset, fee, Self::full_name())
.get_and_increase_block_fees::<Self, _>(&self.fee_asset, fee)
.await
.wrap_err("failed to add to block fees")?;
state
Expand Down