Skip to content

Commit

Permalink
Change all non-deposit related instances of source_action_index to …
Browse files Browse the repository at this point in the history
…`position_in_transaction`
  • Loading branch information
ethanoroshiba committed Oct 25, 2024
1 parent 4f7e53a commit b655313
Show file tree
Hide file tree
Showing 12 changed files with 44 additions and 40 deletions.

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

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

2 changes: 1 addition & 1 deletion crates/astria-sequencer/src/bridge/bridge_lock_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl ActionHandler for BridgeLock {
let source_action_index = state
.get_transaction_context()
.expect("current source should be set before executing action")
.source_action_index;
.position_in_transaction;

let deposit = Deposit {
bridge_address: self.to,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ mod tests {
state.put_transaction_context(TransactionContext {
address_bytes: [1; 20],
transaction_id: TransactionId::new([0; 32]),
source_action_index: 0,
position_in_transaction: 0,
});
state.put_base_prefix(ASTRIA_PREFIX.to_string()).unwrap();

Expand Down Expand Up @@ -155,7 +155,7 @@ mod tests {
state.put_transaction_context(TransactionContext {
address_bytes: sudo_address.bytes(),
transaction_id: TransactionId::new([0; 32]),
source_action_index: 0,
position_in_transaction: 0,
});
state.put_base_prefix(ASTRIA_PREFIX.to_string()).unwrap();
state
Expand Down
6 changes: 3 additions & 3 deletions crates/astria-sequencer/src/bridge/bridge_unlock_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ mod tests {
state.put_transaction_context(TransactionContext {
address_bytes: [1; 20],
transaction_id: TransactionId::new([0; 32]),
source_action_index: 0,
position_in_transaction: 0,
});
state.put_base_prefix(ASTRIA_PREFIX.to_string()).unwrap();

Expand Down Expand Up @@ -184,7 +184,7 @@ mod tests {
state.put_transaction_context(TransactionContext {
address_bytes: [1; 20],
transaction_id: TransactionId::new([0; 32]),
source_action_index: 0,
position_in_transaction: 0,
});
state.put_base_prefix(ASTRIA_PREFIX.to_string()).unwrap();

Expand Down Expand Up @@ -228,7 +228,7 @@ mod tests {
state.put_transaction_context(TransactionContext {
address_bytes: bridge_address.bytes(),
transaction_id: TransactionId::new([0; 32]),
source_action_index: 0,
position_in_transaction: 0,
});
state.put_base_prefix(ASTRIA_PREFIX.to_string()).unwrap();

Expand Down
2 changes: 1 addition & 1 deletion crates/astria-sequencer/src/fees/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ mod tests {
state.put_transaction_context(TransactionContext {
address_bytes: [1; 20],
transaction_id: TransactionId::new([0; 32]),
source_action_index: 0,
position_in_transaction: 0,
});
state.put_sudo_address([1; 20]).unwrap();

Expand Down
6 changes: 3 additions & 3 deletions crates/astria-sequencer/src/fees/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ pub(crate) struct Fee {
action_name: String,
asset: asset::Denom,
amount: u128,
source_action_index: u64,
position_in_transaction: u64,
}

impl Fee {
Expand Down Expand Up @@ -339,7 +339,7 @@ async fn check_and_pay_fees<S: StateWrite, T: FeeHandler + Protobuf>(
.get_transaction_context()
.expect("transaction source must be present in state when executing an action");
let from = transaction_context.address_bytes();
let source_action_index = transaction_context.source_action_index;
let position_in_transaction = transaction_context.position_in_transaction;

ensure!(
state
Expand All @@ -349,7 +349,7 @@ async fn check_and_pay_fees<S: StateWrite, T: FeeHandler + Protobuf>(
"invalid fee asset",
);
state
.add_fee_to_block_fees::<_, T>(fee_asset, total_fees, source_action_index)
.add_fee_to_block_fees::<_, T>(fee_asset, total_fees, position_in_transaction)
.wrap_err("failed to add to block fees")?;
state
.decrease_balance(&from, fee_asset, total_fees)
Expand Down
16 changes: 10 additions & 6 deletions crates/astria-sequencer/src/fees/state_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ pub(crate) trait StateWriteExt: StateWrite {
&mut self,
asset: &'a TAsset,
amount: u128,
source_action_index: u64,
position_in_transaction: u64,
) -> Result<()>
where
TAsset: Sync + std::fmt::Display,
Expand All @@ -397,7 +397,7 @@ pub(crate) trait StateWriteExt: StateWrite {
action_name: T::full_name(),
asset: asset::IbcPrefixed::from(asset).into(),
amount,
source_action_index,
position_in_transaction,
};

// Fee ABCI event recorded for reporting
Expand Down Expand Up @@ -577,7 +577,11 @@ fn construct_tx_fee_event(fee: &Fee) -> Event {
("actionName", fee.action_name.to_string()).index(),
("asset", fee.asset.to_string()).index(),
("feeAmount", fee.amount.to_string()).index(),
("positionInTransaction", fee.source_action_index.to_string()).index(),
(
"positionInTransaction",
fee.position_in_transaction.to_string(),
)
.index(),
],
)
}
Expand Down Expand Up @@ -634,7 +638,7 @@ mod tests {
action_name: "astria.protocol.transaction.v1.Transfer".to_string(),
asset: asset.to_ibc_prefixed().into(),
amount,
source_action_index: 0
position_in_transaction: 0
},
"fee balances are not what they were expected to be"
);
Expand Down Expand Up @@ -667,13 +671,13 @@ mod tests {
action_name: "astria.protocol.transaction.v1.Transfer".to_string(),
asset: asset_first.to_ibc_prefixed().into(),
amount: amount_first,
source_action_index: 0
position_in_transaction: 0
},
Fee {
action_name: "astria.protocol.transaction.v1.Transfer".to_string(),
asset: asset_second.to_ibc_prefixed().into(),
amount: amount_second,
source_action_index: 1
position_in_transaction: 1
},
]),
"returned fee balance vector not what was expected"
Expand Down
2 changes: 1 addition & 1 deletion crates/astria-sequencer/src/fees/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ async fn bridge_lock_fee_calculation_works_as_expected() {
state.put_transaction_context(TransactionContext {
address_bytes: from_address.bytes(),
transaction_id,
source_action_index: 0,
position_in_transaction: 0,
});
state.put_base_prefix(ASTRIA_PREFIX.to_string()).unwrap();

Expand Down
12 changes: 6 additions & 6 deletions crates/astria-sequencer/src/ibc/ics20_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ async fn emit_deposit<S: StateWrite>(
.get_transaction_context()
.ok_or_eyre("transaction source should be present in state when executing an action")?;
let source_transaction_id = transaction_context.transaction_id;
let source_action_index = transaction_context.source_action_index;
let source_action_index = transaction_context.position_in_transaction;

let deposit = Deposit {
bridge_address: *bridge_address,
Expand Down Expand Up @@ -934,7 +934,7 @@ mod tests {
state_tx.put_transaction_context(TransactionContext {
address_bytes: bridge_address.bytes(),
transaction_id: TransactionId::new([0; 32]),
source_action_index: 0,
position_in_transaction: 0,
});

let rollup_deposit_address = "rollupaddress";
Expand Down Expand Up @@ -1016,7 +1016,7 @@ mod tests {
state_tx.put_transaction_context(TransactionContext {
address_bytes: bridge_address.bytes(),
transaction_id: TransactionId::new([0; 32]),
source_action_index: 0,
position_in_transaction: 0,
});

let rollup_deposit_address = "rollupaddress";
Expand Down Expand Up @@ -1266,7 +1266,7 @@ mod tests {
state_tx.put_transaction_context(TransactionContext {
address_bytes: bridge_address.bytes(),
transaction_id: TransactionId::new([0; 32]),
source_action_index: 0,
position_in_transaction: 0,
});

state_tx
Expand Down Expand Up @@ -1350,7 +1350,7 @@ mod tests {
state_tx.put_transaction_context(TransactionContext {
address_bytes: bridge_address.bytes(),
transaction_id: TransactionId::new([0; 32]),
source_action_index: 0,
position_in_transaction: 0,
});

state_tx
Expand Down Expand Up @@ -1455,7 +1455,7 @@ mod tests {
let transaction_context = TransactionContext {
address_bytes: bridge_address.bytes(),
transaction_id: TransactionId::new([0; 32]),
source_action_index: 0,
position_in_transaction: 0,
};
state_tx.put_transaction_context(transaction_context);

Expand Down
2 changes: 1 addition & 1 deletion crates/astria-sequencer/src/transaction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ impl ActionHandler for Transaction {

// FIXME: this should create one span per `check_and_execute`
for (i, action) in (0..).zip(self.actions().iter()) {
transaction_context.source_action_index = i;
transaction_context.position_in_transaction = i;
state.put_transaction_context(transaction_context);

match action {
Expand Down
4 changes: 2 additions & 2 deletions crates/astria-sequencer/src/transaction/state_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ fn transaction_context() -> &'static str {
pub(crate) struct TransactionContext {
pub(crate) address_bytes: [u8; ADDRESS_LEN],
pub(crate) transaction_id: TransactionId,
pub(crate) source_action_index: u64,
pub(crate) position_in_transaction: u64,
}

impl TransactionContext {
Expand All @@ -32,7 +32,7 @@ impl From<&Transaction> for TransactionContext {
Self {
address_bytes: *value.address_bytes(),
transaction_id: value.id(),
source_action_index: 0,
position_in_transaction: 0,
}
}
}
Expand Down

0 comments on commit b655313

Please sign in to comment.