Skip to content

Commit

Permalink
chore(sequencer): change name of source_action_index to `position_i…
Browse files Browse the repository at this point in the history
…n_transaction` (#1746)

## Summary
Changed all non-deposit related instances of `source_action_index` to
`position_in_transaction`

## Background
This is meant to be more descriptive and less confusing to consumers.
Deposits should stay the same, though, for parity with Geth and to avoid
breaking changes.

## Changes
- Changed all instances of `source_action_index` to
`position_in_transaction`, excluding deposits..

## Testing
Passing all tests

## Related Issues
closes #1735
  • Loading branch information
ethanoroshiba authored Dec 2, 2024
1 parent e67fdb9 commit ab87d35
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 27 deletions.
4 changes: 2 additions & 2 deletions crates/astria-sequencer/src/bridge/bridge_lock_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,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;

// map asset to trace prefixed asset for deposit, if it is not already
let deposit_asset = match self.asset.as_trace_prefixed() {
Expand Down Expand Up @@ -157,7 +157,7 @@ mod tests {
state.put_transaction_context(TransactionContext {
address_bytes: *from_address.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
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
15 changes: 9 additions & 6 deletions crates/astria-sequencer/src/fees/state_ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,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 @@ -394,7 +394,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 @@ -574,7 +574,10 @@ fn construct_tx_fee_event(fee: &Fee) -> Event {
("actionName", fee.action_name.to_string()),
("asset", fee.asset.to_string()),
("feeAmount", fee.amount.to_string()),
("positionInTransaction", fee.source_action_index.to_string()),
(
"positionInTransaction",
fee.position_in_transaction.to_string(),
),
],
)
}
Expand Down Expand Up @@ -631,7 +634,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 @@ -664,13 +667,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 @@ -334,7 +334,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 ab87d35

Please sign in to comment.