From 7e00378748f6e1149e91a8caed93a0e965b0b9f9 Mon Sep 17 00:00:00 2001 From: Ethan Oroshiba Date: Fri, 6 Dec 2024 10:42:55 -0600 Subject: [PATCH 1/7] chore(core, sequencer): add names to all snapshot tests (#1690) ## Summary Added names to all snapshot tests which did not have them. ## Background If a certain test had multiple snapshot assertions, they would be named based on their ordering. Hence any reordering, removal, or addition of the snapshots would break the test, which should not be the case. This change aims to fix this problem as well as establish a best practice of naming snapshots moving forward. ## Changes - Added names to all snapshot tests and regenerated all snapshots not within Conductor (due to code freeze) ## Testing Passing all tests. ## Related Issues closes #1656 --- .../src/primitive/v1/asset/denom.rs | 8 +++--- ...nom__serde_impl__tests__ibc_prefixed.snap} | 0 ...erde_impl__tests__ibc_prefixed_denom.snap} | 0 ...m__serde_impl__tests__trace_prefixed.snap} | 0 ...de_impl__tests__trace_prefixed_denom.snap} | 0 crates/astria-core/src/primitive/v1/mod.rs | 4 +-- ...__tests__compat_bech32_non_m_address.snap} | 2 +- ...ive__v1__tests__main_bech32m_address.snap} | 2 +- ...l__genesis__v1__tests__genesis_state.snap} | 2 +- crates/astria-core/src/protocol/genesis/v1.rs | 2 +- ...__tests__ics20_transfer_deposit_memo.snap} | 3 +- ...s__ics20_withdrawal_from_rollup_memo.snap} | 3 +- crates/astria-core/src/protocol/memos/v1.rs | 4 +-- .../src/protocol/transaction/v1/mod.rs | 2 +- .../src/accounts/storage/keys.rs | 4 +-- ...s__storage__keys__tests__balance_key.snap} | 0 ...nts__storage__keys__tests__nonce_key.snap} | 0 .../src/address/storage/keys.rs | 4 +-- ...s__storage__keys__tests__base_prefix.snap} | 3 +- ...rage__keys__tests__ibc_compat_prefix.snap} | 3 +- ...reaking_changes__app_hash_at_genesis.snap} | 0 ...anges__app_hash_execute_every_action.snap} | 0 ...ing_changes__app_hash_finalize_block.snap} | 0 .../astria-sequencer/src/app/storage/keys.rs | 10 +++---- ...orage__keys__tests__block_height_key.snap} | 3 +- ...ge__keys__tests__block_timestamp_key.snap} | 3 +- ...__storage__keys__tests__chain_id_key.snap} | 3 +- ...ge__keys__tests__revision_number_key.snap} | 3 +- ...ge__keys__tests__storage_version_key.snap} | 1 - .../src/app/tests_breaking_changes.rs | 6 ++-- .../src/assets/storage/keys.rs | 4 +-- ...e__keys__tests__asset_key_test_asset.snap} | 1 - ...orage__keys__tests__native_asset_key.snap} | 3 +- .../src/authority/storage/keys.rs | 6 ++-- ...orage__keys__tests__sudo_address_key.snap} | 3 +- ...rage__keys__tests__validator_set_key.snap} | 3 +- ...__keys__tests__validator_updates_key.snap} | 1 - .../src/bridge/storage/keys.rs | 28 +++++++++++++------ ...__storage__keys__tests__asset_id_key.snap} | 0 ...keys__tests__bridge_sudo_address_key.snap} | 0 ...__tests__bridge_withdrawal_event_key.snap} | 0 ...tests__bridge_withdrawer_address_key.snap} | 0 ...e__storage__keys__tests__deposit_key.snap} | 0 ..._keys__tests__ephemeral_deposits_key.snap} | 0 ...ests__last_tx_id_for_bridge_acct_key.snap} | 0 ..._storage__keys__tests__rollup_id_key.snap} | 0 .../astria-sequencer/src/grpc/storage/keys.rs | 21 ++++++++++---- ...eys__tests__block_hash_by_height_key.snap} | 1 - ...tests__rollup_data_by_has_and_id_key.snap} | 1 - ..._keys__tests__rollup_ids_by_hash_key.snap} | 1 - ...eys__tests__rollup_ids_proof_by_hash.snap} | 1 - ...ollup_transactions_proof_by_hash_key.snap} | 1 - ...__sequencer_block_header_by_hash_key.snap} | 1 - .../astria-sequencer/src/ibc/storage/keys.rs | 9 ++++-- ...ge__keys__tests__channel_balance_key.snap} | 0 ...torage__keys__tests__ibc_relayer_key.snap} | 0 ...__storage__keys__tests__ibc_sudo_key.snap} | 3 +- 57 files changed, 83 insertions(+), 80 deletions(-) rename crates/astria-core/src/primitive/v1/asset/snapshots/{astria_core__primitive__v1__asset__denom__serde_impl__tests__snapshots.snap => astria_core__primitive__v1__asset__denom__serde_impl__tests__ibc_prefixed.snap} (100%) rename crates/astria-core/src/primitive/v1/asset/snapshots/{astria_core__primitive__v1__asset__denom__serde_impl__tests__snapshots-3.snap => astria_core__primitive__v1__asset__denom__serde_impl__tests__ibc_prefixed_denom.snap} (100%) rename crates/astria-core/src/primitive/v1/asset/snapshots/{astria_core__primitive__v1__asset__denom__serde_impl__tests__snapshots-2.snap => astria_core__primitive__v1__asset__denom__serde_impl__tests__trace_prefixed.snap} (100%) rename crates/astria-core/src/primitive/v1/asset/snapshots/{astria_core__primitive__v1__asset__denom__serde_impl__tests__snapshots-4.snap => astria_core__primitive__v1__asset__denom__serde_impl__tests__trace_prefixed_denom.snap} (100%) rename crates/astria-core/src/primitive/v1/snapshots/{astria_core__primitive__v1__tests__snapshots-2.snap => astria_core__primitive__v1__tests__compat_bech32_non_m_address.snap} (78%) rename crates/astria-core/src/primitive/v1/snapshots/{astria_core__primitive__v1__tests__snapshots.snap => astria_core__primitive__v1__tests__main_bech32m_address.snap} (77%) rename crates/astria-core/src/protocol/genesis/snapshots/{astria_core__protocol__genesis__v1__tests__genesis_state_is_unchanged.snap => astria_core__protocol__genesis__v1__tests__genesis_state.snap} (97%) rename crates/astria-core/src/protocol/memos/snapshots/{astria_core__protocol__memos__v1__tests__ics20_transfer_deposit_memo_snapshot.snap => astria_core__protocol__memos__v1__tests__ics20_transfer_deposit_memo.snap} (51%) rename crates/astria-core/src/protocol/memos/snapshots/{astria_core__protocol__memos__v1__tests__ics20_withdrawal_from_rollup_memo_snapshot.snap => astria_core__protocol__memos__v1__tests__ics20_withdrawal_from_rollup_memo.snap} (70%) rename crates/astria-sequencer/src/accounts/storage/snapshots/{astria_sequencer__accounts__storage__keys__tests__keys_should_not_change.snap => astria_sequencer__accounts__storage__keys__tests__balance_key.snap} (100%) rename crates/astria-sequencer/src/accounts/storage/snapshots/{astria_sequencer__accounts__storage__keys__tests__keys_should_not_change-2.snap => astria_sequencer__accounts__storage__keys__tests__nonce_key.snap} (100%) rename crates/astria-sequencer/src/address/storage/snapshots/{astria_sequencer__address__storage__keys__tests__keys_should_not_change.snap => astria_sequencer__address__storage__keys__tests__base_prefix.snap} (65%) rename crates/astria-sequencer/src/address/storage/snapshots/{astria_sequencer__address__storage__keys__tests__keys_should_not_change-2.snap => astria_sequencer__address__storage__keys__tests__ibc_compat_prefix.snap} (64%) rename crates/astria-sequencer/src/app/snapshots/{astria_sequencer__app__tests_breaking_changes__app_genesis_snapshot.snap => astria_sequencer__app__tests_breaking_changes__app_hash_at_genesis.snap} (100%) rename crates/astria-sequencer/src/app/snapshots/{astria_sequencer__app__tests_breaking_changes__app_execute_transaction_with_every_action_snapshot.snap => astria_sequencer__app__tests_breaking_changes__app_hash_execute_every_action.snap} (100%) rename crates/astria-sequencer/src/app/snapshots/{astria_sequencer__app__tests_breaking_changes__app_finalize_block_snapshot.snap => astria_sequencer__app__tests_breaking_changes__app_hash_finalize_block.snap} (100%) rename crates/astria-sequencer/src/app/storage/snapshots/{astria_sequencer__app__storage__keys__tests__keys_should_not_change-3.snap => astria_sequencer__app__storage__keys__tests__block_height_key.snap} (62%) rename crates/astria-sequencer/src/app/storage/snapshots/{astria_sequencer__app__storage__keys__tests__keys_should_not_change-4.snap => astria_sequencer__app__storage__keys__tests__block_timestamp_key.snap} (62%) rename crates/astria-sequencer/src/app/storage/snapshots/{astria_sequencer__app__storage__keys__tests__keys_should_not_change.snap => astria_sequencer__app__storage__keys__tests__chain_id_key.snap} (63%) rename crates/astria-sequencer/src/app/storage/snapshots/{astria_sequencer__app__storage__keys__tests__keys_should_not_change-2.snap => astria_sequencer__app__storage__keys__tests__revision_number_key.snap} (62%) rename crates/astria-sequencer/src/app/storage/snapshots/{astria_sequencer__app__storage__keys__tests__keys_should_not_change-5.snap => astria_sequencer__app__storage__keys__tests__storage_version_key.snap} (87%) rename crates/astria-sequencer/src/assets/storage/snapshots/{astria_sequencer__assets__storage__keys__tests__keys_should_not_change-2.snap => astria_sequencer__assets__storage__keys__tests__asset_key_test_asset.snap} (90%) rename crates/astria-sequencer/src/assets/storage/snapshots/{astria_sequencer__assets__storage__keys__tests__keys_should_not_change.snap => astria_sequencer__assets__storage__keys__tests__native_asset_key.snap} (64%) rename crates/astria-sequencer/src/authority/storage/snapshots/{astria_sequencer__authority__storage__keys__tests__keys_should_not_change.snap => astria_sequencer__authority__storage__keys__tests__sudo_address_key.snap} (63%) rename crates/astria-sequencer/src/authority/storage/snapshots/{astria_sequencer__authority__storage__keys__tests__keys_should_not_change-2.snap => astria_sequencer__authority__storage__keys__tests__validator_set_key.snap} (62%) rename crates/astria-sequencer/src/authority/storage/snapshots/{astria_sequencer__authority__storage__keys__tests__keys_should_not_change-3.snap => astria_sequencer__authority__storage__keys__tests__validator_updates_key.snap} (87%) rename crates/astria-sequencer/src/bridge/storage/snapshots/{astria_sequencer__bridge__storage__keys__tests__keys_should_not_change-3.snap => astria_sequencer__bridge__storage__keys__tests__asset_id_key.snap} (100%) rename crates/astria-sequencer/src/bridge/storage/snapshots/{astria_sequencer__bridge__storage__keys__tests__keys_should_not_change-4.snap => astria_sequencer__bridge__storage__keys__tests__bridge_sudo_address_key.snap} (100%) rename crates/astria-sequencer/src/bridge/storage/snapshots/{astria_sequencer__bridge__storage__keys__tests__keys_should_not_change-6.snap => astria_sequencer__bridge__storage__keys__tests__bridge_withdrawal_event_key.snap} (100%) rename crates/astria-sequencer/src/bridge/storage/snapshots/{astria_sequencer__bridge__storage__keys__tests__keys_should_not_change-5.snap => astria_sequencer__bridge__storage__keys__tests__bridge_withdrawer_address_key.snap} (100%) rename crates/astria-sequencer/src/bridge/storage/snapshots/{astria_sequencer__bridge__storage__keys__tests__keys_should_not_change-7.snap => astria_sequencer__bridge__storage__keys__tests__deposit_key.snap} (100%) rename crates/astria-sequencer/src/bridge/storage/snapshots/{astria_sequencer__bridge__storage__keys__tests__keys_should_not_change.snap => astria_sequencer__bridge__storage__keys__tests__ephemeral_deposits_key.snap} (100%) rename crates/astria-sequencer/src/bridge/storage/snapshots/{astria_sequencer__bridge__storage__keys__tests__keys_should_not_change-8.snap => astria_sequencer__bridge__storage__keys__tests__last_tx_id_for_bridge_acct_key.snap} (100%) rename crates/astria-sequencer/src/bridge/storage/snapshots/{astria_sequencer__bridge__storage__keys__tests__keys_should_not_change-2.snap => astria_sequencer__bridge__storage__keys__tests__rollup_id_key.snap} (100%) rename crates/astria-sequencer/src/grpc/storage/snapshots/{astria_sequencer__grpc__storage__keys__tests__keys_should_not_change.snap => astria_sequencer__grpc__storage__keys__tests__block_hash_by_height_key.snap} (86%) rename crates/astria-sequencer/src/grpc/storage/snapshots/{astria_sequencer__grpc__storage__keys__tests__keys_should_not_change-3.snap => astria_sequencer__grpc__storage__keys__tests__rollup_data_by_has_and_id_key.snap} (92%) rename crates/astria-sequencer/src/grpc/storage/snapshots/{astria_sequencer__grpc__storage__keys__tests__keys_should_not_change-4.snap => astria_sequencer__grpc__storage__keys__tests__rollup_ids_by_hash_key.snap} (89%) rename crates/astria-sequencer/src/grpc/storage/snapshots/{astria_sequencer__grpc__storage__keys__tests__keys_should_not_change-6.snap => astria_sequencer__grpc__storage__keys__tests__rollup_ids_proof_by_hash.snap} (90%) rename crates/astria-sequencer/src/grpc/storage/snapshots/{astria_sequencer__grpc__storage__keys__tests__keys_should_not_change-5.snap => astria_sequencer__grpc__storage__keys__tests__rollup_transactions_proof_by_hash_key.snap} (90%) rename crates/astria-sequencer/src/grpc/storage/snapshots/{astria_sequencer__grpc__storage__keys__tests__keys_should_not_change-2.snap => astria_sequencer__grpc__storage__keys__tests__sequencer_block_header_by_hash_key.snap} (90%) rename crates/astria-sequencer/src/ibc/storage/snapshots/{astria_sequencer__ibc__storage__keys__tests__keys_should_not_change-2.snap => astria_sequencer__ibc__storage__keys__tests__channel_balance_key.snap} (100%) rename crates/astria-sequencer/src/ibc/storage/snapshots/{astria_sequencer__ibc__storage__keys__tests__keys_should_not_change-3.snap => astria_sequencer__ibc__storage__keys__tests__ibc_relayer_key.snap} (100%) rename crates/astria-sequencer/src/ibc/storage/snapshots/{astria_sequencer__ibc__storage__keys__tests__keys_should_not_change.snap => astria_sequencer__ibc__storage__keys__tests__ibc_sudo_key.snap} (62%) diff --git a/crates/astria-core/src/primitive/v1/asset/denom.rs b/crates/astria-core/src/primitive/v1/asset/denom.rs index e28159fbc7..f85511bd54 100644 --- a/crates/astria-core/src/primitive/v1/asset/denom.rs +++ b/crates/astria-core/src/primitive/v1/asset/denom.rs @@ -792,10 +792,10 @@ mod serde_impl { } #[test] fn snapshots() { - insta::assert_json_snapshot!(ibc_prefixed()); - insta::assert_json_snapshot!(trace_prefixed()); - insta::assert_json_snapshot!(Denom::from(ibc_prefixed())); - insta::assert_json_snapshot!(Denom::from(trace_prefixed())); + insta::assert_json_snapshot!("ibc_prefixed", ibc_prefixed()); + insta::assert_json_snapshot!("trace_prefixed", trace_prefixed()); + insta::assert_json_snapshot!("ibc_prefixed_denom", Denom::from(ibc_prefixed())); + insta::assert_json_snapshot!("trace_prefixed_denom", Denom::from(trace_prefixed())); } } } diff --git a/crates/astria-core/src/primitive/v1/asset/snapshots/astria_core__primitive__v1__asset__denom__serde_impl__tests__snapshots.snap b/crates/astria-core/src/primitive/v1/asset/snapshots/astria_core__primitive__v1__asset__denom__serde_impl__tests__ibc_prefixed.snap similarity index 100% rename from crates/astria-core/src/primitive/v1/asset/snapshots/astria_core__primitive__v1__asset__denom__serde_impl__tests__snapshots.snap rename to crates/astria-core/src/primitive/v1/asset/snapshots/astria_core__primitive__v1__asset__denom__serde_impl__tests__ibc_prefixed.snap diff --git a/crates/astria-core/src/primitive/v1/asset/snapshots/astria_core__primitive__v1__asset__denom__serde_impl__tests__snapshots-3.snap b/crates/astria-core/src/primitive/v1/asset/snapshots/astria_core__primitive__v1__asset__denom__serde_impl__tests__ibc_prefixed_denom.snap similarity index 100% rename from crates/astria-core/src/primitive/v1/asset/snapshots/astria_core__primitive__v1__asset__denom__serde_impl__tests__snapshots-3.snap rename to crates/astria-core/src/primitive/v1/asset/snapshots/astria_core__primitive__v1__asset__denom__serde_impl__tests__ibc_prefixed_denom.snap diff --git a/crates/astria-core/src/primitive/v1/asset/snapshots/astria_core__primitive__v1__asset__denom__serde_impl__tests__snapshots-2.snap b/crates/astria-core/src/primitive/v1/asset/snapshots/astria_core__primitive__v1__asset__denom__serde_impl__tests__trace_prefixed.snap similarity index 100% rename from crates/astria-core/src/primitive/v1/asset/snapshots/astria_core__primitive__v1__asset__denom__serde_impl__tests__snapshots-2.snap rename to crates/astria-core/src/primitive/v1/asset/snapshots/astria_core__primitive__v1__asset__denom__serde_impl__tests__trace_prefixed.snap diff --git a/crates/astria-core/src/primitive/v1/asset/snapshots/astria_core__primitive__v1__asset__denom__serde_impl__tests__snapshots-4.snap b/crates/astria-core/src/primitive/v1/asset/snapshots/astria_core__primitive__v1__asset__denom__serde_impl__tests__trace_prefixed_denom.snap similarity index 100% rename from crates/astria-core/src/primitive/v1/asset/snapshots/astria_core__primitive__v1__asset__denom__serde_impl__tests__snapshots-4.snap rename to crates/astria-core/src/primitive/v1/asset/snapshots/astria_core__primitive__v1__asset__denom__serde_impl__tests__trace_prefixed_denom.snap diff --git a/crates/astria-core/src/primitive/v1/mod.rs b/crates/astria-core/src/primitive/v1/mod.rs index 7477eac667..fe2279960f 100644 --- a/crates/astria-core/src/primitive/v1/mod.rs +++ b/crates/astria-core/src/primitive/v1/mod.rs @@ -410,7 +410,7 @@ mod tests { .prefix(ASTRIA_ADDRESS_PREFIX) .try_build() .unwrap(); - insta::assert_json_snapshot!(&main_address.to_raw()); + insta::assert_json_snapshot!("main_bech32m_address", &main_address.to_raw()); let compat_address = main_address .to_prefix(ASTRIA_COMPAT_ADDRESS_PREFIX) @@ -418,7 +418,7 @@ mod tests { .to_format::(); // We don't allow serializing non bech32m addresses due to // its impl via the protobuf type. - insta::assert_snapshot!(&compat_address); + insta::assert_snapshot!("compat_bech32_non_m_address", &compat_address); } #[test] diff --git a/crates/astria-core/src/primitive/v1/snapshots/astria_core__primitive__v1__tests__snapshots-2.snap b/crates/astria-core/src/primitive/v1/snapshots/astria_core__primitive__v1__tests__compat_bech32_non_m_address.snap similarity index 78% rename from crates/astria-core/src/primitive/v1/snapshots/astria_core__primitive__v1__tests__snapshots-2.snap rename to crates/astria-core/src/primitive/v1/snapshots/astria_core__primitive__v1__tests__compat_bech32_non_m_address.snap index afa9f15103..f8a198c53d 100644 --- a/crates/astria-core/src/primitive/v1/snapshots/astria_core__primitive__v1__tests__snapshots-2.snap +++ b/crates/astria-core/src/primitive/v1/snapshots/astria_core__primitive__v1__tests__compat_bech32_non_m_address.snap @@ -1,5 +1,5 @@ --- source: crates/astria-core/src/primitive/v1/mod.rs -expression: "&bech32_address" +expression: "&compat_address" --- astriacompat19g4z52329g4z52329g4z52329g4z52322jspvr diff --git a/crates/astria-core/src/primitive/v1/snapshots/astria_core__primitive__v1__tests__snapshots.snap b/crates/astria-core/src/primitive/v1/snapshots/astria_core__primitive__v1__tests__main_bech32m_address.snap similarity index 77% rename from crates/astria-core/src/primitive/v1/snapshots/astria_core__primitive__v1__tests__snapshots.snap rename to crates/astria-core/src/primitive/v1/snapshots/astria_core__primitive__v1__tests__main_bech32m_address.snap index 7aca827420..7de615818f 100644 --- a/crates/astria-core/src/primitive/v1/snapshots/astria_core__primitive__v1__tests__snapshots.snap +++ b/crates/astria-core/src/primitive/v1/snapshots/astria_core__primitive__v1__tests__main_bech32m_address.snap @@ -1,6 +1,6 @@ --- source: crates/astria-core/src/primitive/v1/mod.rs -expression: address +expression: "&main_address.to_raw()" --- { "bech32m": "astria19g4z52329g4z52329g4z52329g4z5232ayenag" diff --git a/crates/astria-core/src/protocol/genesis/snapshots/astria_core__protocol__genesis__v1__tests__genesis_state_is_unchanged.snap b/crates/astria-core/src/protocol/genesis/snapshots/astria_core__protocol__genesis__v1__tests__genesis_state.snap similarity index 97% rename from crates/astria-core/src/protocol/genesis/snapshots/astria_core__protocol__genesis__v1__tests__genesis_state_is_unchanged.snap rename to crates/astria-core/src/protocol/genesis/snapshots/astria_core__protocol__genesis__v1__tests__genesis_state.snap index 1949b88854..05a657196e 100644 --- a/crates/astria-core/src/protocol/genesis/snapshots/astria_core__protocol__genesis__v1__tests__genesis_state_is_unchanged.snap +++ b/crates/astria-core/src/protocol/genesis/snapshots/astria_core__protocol__genesis__v1__tests__genesis_state.snap @@ -1,5 +1,5 @@ --- -source: crates/astria-core/src/protocol/genesis/v1alpha1.rs +source: crates/astria-core/src/protocol/genesis/v1.rs expression: genesis_state() --- { diff --git a/crates/astria-core/src/protocol/genesis/v1.rs b/crates/astria-core/src/protocol/genesis/v1.rs index 168998a521..de177b1cc9 100644 --- a/crates/astria-core/src/protocol/genesis/v1.rs +++ b/crates/astria-core/src/protocol/genesis/v1.rs @@ -1046,6 +1046,6 @@ mod tests { #[cfg(feature = "serde")] #[test] fn genesis_state_is_unchanged() { - insta::assert_json_snapshot!(genesis_state()); + insta::assert_json_snapshot!("genesis_state", genesis_state()); } } diff --git a/crates/astria-core/src/protocol/memos/snapshots/astria_core__protocol__memos__v1__tests__ics20_transfer_deposit_memo_snapshot.snap b/crates/astria-core/src/protocol/memos/snapshots/astria_core__protocol__memos__v1__tests__ics20_transfer_deposit_memo.snap similarity index 51% rename from crates/astria-core/src/protocol/memos/snapshots/astria_core__protocol__memos__v1__tests__ics20_transfer_deposit_memo_snapshot.snap rename to crates/astria-core/src/protocol/memos/snapshots/astria_core__protocol__memos__v1__tests__ics20_transfer_deposit_memo.snap index b31b2f864d..0238893328 100644 --- a/crates/astria-core/src/protocol/memos/snapshots/astria_core__protocol__memos__v1__tests__ics20_transfer_deposit_memo_snapshot.snap +++ b/crates/astria-core/src/protocol/memos/snapshots/astria_core__protocol__memos__v1__tests__ics20_transfer_deposit_memo.snap @@ -1,6 +1,5 @@ --- -source: crates/astria-core/src/protocol/memos/v1alpha1.rs -assertion_line: 28 +source: crates/astria-core/src/protocol/memos/v1.rs expression: memo --- { diff --git a/crates/astria-core/src/protocol/memos/snapshots/astria_core__protocol__memos__v1__tests__ics20_withdrawal_from_rollup_memo_snapshot.snap b/crates/astria-core/src/protocol/memos/snapshots/astria_core__protocol__memos__v1__tests__ics20_withdrawal_from_rollup_memo.snap similarity index 70% rename from crates/astria-core/src/protocol/memos/snapshots/astria_core__protocol__memos__v1__tests__ics20_withdrawal_from_rollup_memo_snapshot.snap rename to crates/astria-core/src/protocol/memos/snapshots/astria_core__protocol__memos__v1__tests__ics20_withdrawal_from_rollup_memo.snap index d3f43f6eb0..4cd0482db4 100644 --- a/crates/astria-core/src/protocol/memos/snapshots/astria_core__protocol__memos__v1__tests__ics20_withdrawal_from_rollup_memo_snapshot.snap +++ b/crates/astria-core/src/protocol/memos/snapshots/astria_core__protocol__memos__v1__tests__ics20_withdrawal_from_rollup_memo.snap @@ -1,6 +1,5 @@ --- -source: crates/astria-core/src/protocol/memos/v1alpha1.rs -assertion_line: 19 +source: crates/astria-core/src/protocol/memos/v1.rs expression: memo --- { diff --git a/crates/astria-core/src/protocol/memos/v1.rs b/crates/astria-core/src/protocol/memos/v1.rs index 9e9aa76cf2..0fb031b3c0 100644 --- a/crates/astria-core/src/protocol/memos/v1.rs +++ b/crates/astria-core/src/protocol/memos/v1.rs @@ -16,7 +16,7 @@ mod tests { memo: "hello".to_string(), }; - insta::assert_json_snapshot!(memo); + insta::assert_json_snapshot!("ics20_withdrawal_from_rollup_memo", memo); } #[test] @@ -25,6 +25,6 @@ mod tests { rollup_deposit_address: "an-address-on-the-rollup".to_string(), }; - insta::assert_json_snapshot!(memo); + insta::assert_json_snapshot!("ics20_transfer_deposit_memo", memo); } } diff --git a/crates/astria-core/src/protocol/transaction/v1/mod.rs b/crates/astria-core/src/protocol/transaction/v1/mod.rs index 59616514d8..0f26b69b65 100644 --- a/crates/astria-core/src/protocol/transaction/v1/mod.rs +++ b/crates/astria-core/src/protocol/transaction/v1/mod.rs @@ -621,7 +621,7 @@ mod tests { body_bytes: body.to_raw().encode_to_vec().into(), }; - insta::assert_json_snapshot!(tx.id().to_raw()); + insta::assert_json_snapshot!("transaction_id", tx.id().to_raw()); } #[test] diff --git a/crates/astria-sequencer/src/accounts/storage/keys.rs b/crates/astria-sequencer/src/accounts/storage/keys.rs index ceb9f9c191..17669eabff 100644 --- a/crates/astria-sequencer/src/accounts/storage/keys.rs +++ b/crates/astria-sequencer/src/accounts/storage/keys.rs @@ -85,8 +85,8 @@ mod tests { #[test] fn keys_should_not_change() { - insta::assert_snapshot!(balance(&address(), &asset())); - insta::assert_snapshot!(nonce(&address())); + insta::assert_snapshot!("balance_key", balance(&address(), &asset())); + insta::assert_snapshot!("nonce_key", nonce(&address())); } #[test] diff --git a/crates/astria-sequencer/src/accounts/storage/snapshots/astria_sequencer__accounts__storage__keys__tests__keys_should_not_change.snap b/crates/astria-sequencer/src/accounts/storage/snapshots/astria_sequencer__accounts__storage__keys__tests__balance_key.snap similarity index 100% rename from crates/astria-sequencer/src/accounts/storage/snapshots/astria_sequencer__accounts__storage__keys__tests__keys_should_not_change.snap rename to crates/astria-sequencer/src/accounts/storage/snapshots/astria_sequencer__accounts__storage__keys__tests__balance_key.snap diff --git a/crates/astria-sequencer/src/accounts/storage/snapshots/astria_sequencer__accounts__storage__keys__tests__keys_should_not_change-2.snap b/crates/astria-sequencer/src/accounts/storage/snapshots/astria_sequencer__accounts__storage__keys__tests__nonce_key.snap similarity index 100% rename from crates/astria-sequencer/src/accounts/storage/snapshots/astria_sequencer__accounts__storage__keys__tests__keys_should_not_change-2.snap rename to crates/astria-sequencer/src/accounts/storage/snapshots/astria_sequencer__accounts__storage__keys__tests__nonce_key.snap diff --git a/crates/astria-sequencer/src/address/storage/keys.rs b/crates/astria-sequencer/src/address/storage/keys.rs index af58a1d79f..5e123af6d7 100644 --- a/crates/astria-sequencer/src/address/storage/keys.rs +++ b/crates/astria-sequencer/src/address/storage/keys.rs @@ -9,8 +9,8 @@ mod tests { #[test] fn keys_should_not_change() { - insta::assert_snapshot!(BASE_PREFIX); - insta::assert_snapshot!(IBC_COMPAT_PREFIX); + insta::assert_snapshot!("base_prefix", BASE_PREFIX); + insta::assert_snapshot!("ibc_compat_prefix", IBC_COMPAT_PREFIX); } #[test] diff --git a/crates/astria-sequencer/src/address/storage/snapshots/astria_sequencer__address__storage__keys__tests__keys_should_not_change.snap b/crates/astria-sequencer/src/address/storage/snapshots/astria_sequencer__address__storage__keys__tests__base_prefix.snap similarity index 65% rename from crates/astria-sequencer/src/address/storage/snapshots/astria_sequencer__address__storage__keys__tests__keys_should_not_change.snap rename to crates/astria-sequencer/src/address/storage/snapshots/astria_sequencer__address__storage__keys__tests__base_prefix.snap index d0121e06ae..7a479c085a 100644 --- a/crates/astria-sequencer/src/address/storage/snapshots/astria_sequencer__address__storage__keys__tests__keys_should_not_change.snap +++ b/crates/astria-sequencer/src/address/storage/snapshots/astria_sequencer__address__storage__keys__tests__base_prefix.snap @@ -1,6 +1,5 @@ --- source: crates/astria-sequencer/src/address/storage/keys.rs -assertion_line: 10 -expression: BASE_PREFIX_KEY +expression: BASE_PREFIX --- address/prefixes/base diff --git a/crates/astria-sequencer/src/address/storage/snapshots/astria_sequencer__address__storage__keys__tests__keys_should_not_change-2.snap b/crates/astria-sequencer/src/address/storage/snapshots/astria_sequencer__address__storage__keys__tests__ibc_compat_prefix.snap similarity index 64% rename from crates/astria-sequencer/src/address/storage/snapshots/astria_sequencer__address__storage__keys__tests__keys_should_not_change-2.snap rename to crates/astria-sequencer/src/address/storage/snapshots/astria_sequencer__address__storage__keys__tests__ibc_compat_prefix.snap index 78e5051afb..c9fec6073a 100644 --- a/crates/astria-sequencer/src/address/storage/snapshots/astria_sequencer__address__storage__keys__tests__keys_should_not_change-2.snap +++ b/crates/astria-sequencer/src/address/storage/snapshots/astria_sequencer__address__storage__keys__tests__ibc_compat_prefix.snap @@ -1,6 +1,5 @@ --- source: crates/astria-sequencer/src/address/storage/keys.rs -assertion_line: 11 -expression: IBC_COMPAT_PREFIX_KEY +expression: IBC_COMPAT_PREFIX --- address/prefixes/ibc_compat diff --git a/crates/astria-sequencer/src/app/snapshots/astria_sequencer__app__tests_breaking_changes__app_genesis_snapshot.snap b/crates/astria-sequencer/src/app/snapshots/astria_sequencer__app__tests_breaking_changes__app_hash_at_genesis.snap similarity index 100% rename from crates/astria-sequencer/src/app/snapshots/astria_sequencer__app__tests_breaking_changes__app_genesis_snapshot.snap rename to crates/astria-sequencer/src/app/snapshots/astria_sequencer__app__tests_breaking_changes__app_hash_at_genesis.snap diff --git a/crates/astria-sequencer/src/app/snapshots/astria_sequencer__app__tests_breaking_changes__app_execute_transaction_with_every_action_snapshot.snap b/crates/astria-sequencer/src/app/snapshots/astria_sequencer__app__tests_breaking_changes__app_hash_execute_every_action.snap similarity index 100% rename from crates/astria-sequencer/src/app/snapshots/astria_sequencer__app__tests_breaking_changes__app_execute_transaction_with_every_action_snapshot.snap rename to crates/astria-sequencer/src/app/snapshots/astria_sequencer__app__tests_breaking_changes__app_hash_execute_every_action.snap diff --git a/crates/astria-sequencer/src/app/snapshots/astria_sequencer__app__tests_breaking_changes__app_finalize_block_snapshot.snap b/crates/astria-sequencer/src/app/snapshots/astria_sequencer__app__tests_breaking_changes__app_hash_finalize_block.snap similarity index 100% rename from crates/astria-sequencer/src/app/snapshots/astria_sequencer__app__tests_breaking_changes__app_finalize_block_snapshot.snap rename to crates/astria-sequencer/src/app/snapshots/astria_sequencer__app__tests_breaking_changes__app_hash_finalize_block.snap diff --git a/crates/astria-sequencer/src/app/storage/keys.rs b/crates/astria-sequencer/src/app/storage/keys.rs index 564fab2cdf..8a1c1e51c8 100644 --- a/crates/astria-sequencer/src/app/storage/keys.rs +++ b/crates/astria-sequencer/src/app/storage/keys.rs @@ -15,11 +15,11 @@ mod tests { #[test] fn keys_should_not_change() { - insta::assert_snapshot!(CHAIN_ID); - insta::assert_snapshot!(REVISION_NUMBER); - insta::assert_snapshot!(BLOCK_HEIGHT); - insta::assert_snapshot!(BLOCK_TIMESTAMP); - insta::assert_snapshot!(storage_version_by_height(42)); + insta::assert_snapshot!("chain_id_key", CHAIN_ID); + insta::assert_snapshot!("revision_number_key", REVISION_NUMBER); + insta::assert_snapshot!("block_height_key", BLOCK_HEIGHT); + insta::assert_snapshot!("block_timestamp_key", BLOCK_TIMESTAMP); + insta::assert_snapshot!("storage_version_key", storage_version_by_height(42)); } #[test] diff --git a/crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__keys_should_not_change-3.snap b/crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__block_height_key.snap similarity index 62% rename from crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__keys_should_not_change-3.snap rename to crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__block_height_key.snap index 4c70738ab6..62ab7280cb 100644 --- a/crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__keys_should_not_change-3.snap +++ b/crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__block_height_key.snap @@ -1,6 +1,5 @@ --- source: crates/astria-sequencer/src/app/storage/keys.rs -assertion_line: 22 -expression: BLOCK_HEIGHT_KEY +expression: BLOCK_HEIGHT --- app/block_height diff --git a/crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__keys_should_not_change-4.snap b/crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__block_timestamp_key.snap similarity index 62% rename from crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__keys_should_not_change-4.snap rename to crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__block_timestamp_key.snap index ac8904c633..7ba8209205 100644 --- a/crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__keys_should_not_change-4.snap +++ b/crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__block_timestamp_key.snap @@ -1,6 +1,5 @@ --- source: crates/astria-sequencer/src/app/storage/keys.rs -assertion_line: 23 -expression: BLOCK_TIMESTAMP_KEY +expression: BLOCK_TIMESTAMP --- app/block_timestamp diff --git a/crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__keys_should_not_change.snap b/crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__chain_id_key.snap similarity index 63% rename from crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__keys_should_not_change.snap rename to crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__chain_id_key.snap index d90a517589..bc8b080ca2 100644 --- a/crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__keys_should_not_change.snap +++ b/crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__chain_id_key.snap @@ -1,6 +1,5 @@ --- source: crates/astria-sequencer/src/app/storage/keys.rs -assertion_line: 18 -expression: CHAIN_ID_KEY +expression: CHAIN_ID --- app/chain_id diff --git a/crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__keys_should_not_change-2.snap b/crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__revision_number_key.snap similarity index 62% rename from crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__keys_should_not_change-2.snap rename to crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__revision_number_key.snap index 5ef5391478..f6ca73a0b0 100644 --- a/crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__keys_should_not_change-2.snap +++ b/crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__revision_number_key.snap @@ -1,6 +1,5 @@ --- source: crates/astria-sequencer/src/app/storage/keys.rs -assertion_line: 21 -expression: REVISION_NUMBER_KEY +expression: REVISION_NUMBER --- app/revision_number diff --git a/crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__keys_should_not_change-5.snap b/crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__storage_version_key.snap similarity index 87% rename from crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__keys_should_not_change-5.snap rename to crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__storage_version_key.snap index 2129ee5473..84896aa427 100644 --- a/crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__keys_should_not_change-5.snap +++ b/crates/astria-sequencer/src/app/storage/snapshots/astria_sequencer__app__storage__keys__tests__storage_version_key.snap @@ -1,6 +1,5 @@ --- source: crates/astria-sequencer/src/app/storage/keys.rs -assertion_line: 22 expression: storage_version_by_height(42) --- app/storage_version/42 diff --git a/crates/astria-sequencer/src/app/tests_breaking_changes.rs b/crates/astria-sequencer/src/app/tests_breaking_changes.rs index dd1c14c4d4..2118d41d4d 100644 --- a/crates/astria-sequencer/src/app/tests_breaking_changes.rs +++ b/crates/astria-sequencer/src/app/tests_breaking_changes.rs @@ -81,7 +81,7 @@ use crate::{ #[tokio::test] async fn app_genesis_snapshot() { let app = initialize_app(None, vec![]).await; - insta::assert_json_snapshot!(app.app_hash.as_bytes()); + insta::assert_json_snapshot!("app_hash_at_genesis", app.app_hash.as_bytes()); } #[tokio::test] @@ -161,7 +161,7 @@ async fn app_finalize_block_snapshot() { .await .unwrap(); app.commit(storage.clone()).await; - insta::assert_json_snapshot!(app.app_hash.as_bytes()); + insta::assert_json_snapshot!("app_hash_finalize_block", app.app_hash.as_bytes()); } // Note: this tests every action except for `Ics20Withdrawal` and `IbcRelay`. @@ -368,5 +368,5 @@ async fn app_execute_transaction_with_every_action_snapshot() { app.prepare_commit(storage.clone()).await.unwrap(); app.commit(storage.clone()).await; - insta::assert_json_snapshot!(app.app_hash.as_bytes()); + insta::assert_json_snapshot!("app_hash_execute_every_action", app.app_hash.as_bytes()); } diff --git a/crates/astria-sequencer/src/assets/storage/keys.rs b/crates/astria-sequencer/src/assets/storage/keys.rs index 4cfb588aad..69565beed8 100644 --- a/crates/astria-sequencer/src/assets/storage/keys.rs +++ b/crates/astria-sequencer/src/assets/storage/keys.rs @@ -29,8 +29,8 @@ mod tests { #[test] fn keys_should_not_change() { - insta::assert_snapshot!(NATIVE_ASSET); - insta::assert_snapshot!(asset(&test_asset())); + insta::assert_snapshot!("native_asset_key", NATIVE_ASSET); + insta::assert_snapshot!("asset_key_test_asset", asset(&test_asset())); } #[test] diff --git a/crates/astria-sequencer/src/assets/storage/snapshots/astria_sequencer__assets__storage__keys__tests__keys_should_not_change-2.snap b/crates/astria-sequencer/src/assets/storage/snapshots/astria_sequencer__assets__storage__keys__tests__asset_key_test_asset.snap similarity index 90% rename from crates/astria-sequencer/src/assets/storage/snapshots/astria_sequencer__assets__storage__keys__tests__keys_should_not_change-2.snap rename to crates/astria-sequencer/src/assets/storage/snapshots/astria_sequencer__assets__storage__keys__tests__asset_key_test_asset.snap index f2b86e3f42..7598ba14eb 100644 --- a/crates/astria-sequencer/src/assets/storage/snapshots/astria_sequencer__assets__storage__keys__tests__keys_should_not_change-2.snap +++ b/crates/astria-sequencer/src/assets/storage/snapshots/astria_sequencer__assets__storage__keys__tests__asset_key_test_asset.snap @@ -1,6 +1,5 @@ --- source: crates/astria-sequencer/src/assets/storage/keys.rs -assertion_line: 87 expression: asset(&test_asset()) --- assets/ibc/be429a02d00837245167a2616674a979a2ac6f9806468b48a975b156ad711320 diff --git a/crates/astria-sequencer/src/assets/storage/snapshots/astria_sequencer__assets__storage__keys__tests__keys_should_not_change.snap b/crates/astria-sequencer/src/assets/storage/snapshots/astria_sequencer__assets__storage__keys__tests__native_asset_key.snap similarity index 64% rename from crates/astria-sequencer/src/assets/storage/snapshots/astria_sequencer__assets__storage__keys__tests__keys_should_not_change.snap rename to crates/astria-sequencer/src/assets/storage/snapshots/astria_sequencer__assets__storage__keys__tests__native_asset_key.snap index b7c28d8f3f..137bad2b26 100644 --- a/crates/astria-sequencer/src/assets/storage/snapshots/astria_sequencer__assets__storage__keys__tests__keys_should_not_change.snap +++ b/crates/astria-sequencer/src/assets/storage/snapshots/astria_sequencer__assets__storage__keys__tests__native_asset_key.snap @@ -1,6 +1,5 @@ --- source: crates/astria-sequencer/src/assets/storage/keys.rs -assertion_line: 84 -expression: NATIVE_ASSET_KEY +expression: NATIVE_ASSET --- assets/native_asset diff --git a/crates/astria-sequencer/src/authority/storage/keys.rs b/crates/astria-sequencer/src/authority/storage/keys.rs index 0120a0b425..169185b357 100644 --- a/crates/astria-sequencer/src/authority/storage/keys.rs +++ b/crates/astria-sequencer/src/authority/storage/keys.rs @@ -10,9 +10,9 @@ mod tests { #[test] fn keys_should_not_change() { - insta::assert_snapshot!(SUDO); - insta::assert_snapshot!(VALIDATOR_SET); - insta::assert_snapshot!(VALIDATOR_UPDATES); + insta::assert_snapshot!("sudo_address_key", SUDO); + insta::assert_snapshot!("validator_set_key", VALIDATOR_SET); + insta::assert_snapshot!("validator_updates_key", VALIDATOR_UPDATES); } #[test] diff --git a/crates/astria-sequencer/src/authority/storage/snapshots/astria_sequencer__authority__storage__keys__tests__keys_should_not_change.snap b/crates/astria-sequencer/src/authority/storage/snapshots/astria_sequencer__authority__storage__keys__tests__sudo_address_key.snap similarity index 63% rename from crates/astria-sequencer/src/authority/storage/snapshots/astria_sequencer__authority__storage__keys__tests__keys_should_not_change.snap rename to crates/astria-sequencer/src/authority/storage/snapshots/astria_sequencer__authority__storage__keys__tests__sudo_address_key.snap index a046006094..5847837e58 100644 --- a/crates/astria-sequencer/src/authority/storage/snapshots/astria_sequencer__authority__storage__keys__tests__keys_should_not_change.snap +++ b/crates/astria-sequencer/src/authority/storage/snapshots/astria_sequencer__authority__storage__keys__tests__sudo_address_key.snap @@ -1,6 +1,5 @@ --- source: crates/astria-sequencer/src/authority/storage/keys.rs -assertion_line: 15 -expression: SUDO_STORAGE_KEY +expression: SUDO --- authority/sudo diff --git a/crates/astria-sequencer/src/authority/storage/snapshots/astria_sequencer__authority__storage__keys__tests__keys_should_not_change-2.snap b/crates/astria-sequencer/src/authority/storage/snapshots/astria_sequencer__authority__storage__keys__tests__validator_set_key.snap similarity index 62% rename from crates/astria-sequencer/src/authority/storage/snapshots/astria_sequencer__authority__storage__keys__tests__keys_should_not_change-2.snap rename to crates/astria-sequencer/src/authority/storage/snapshots/astria_sequencer__authority__storage__keys__tests__validator_set_key.snap index 2bbd4fa8d0..f8678c4090 100644 --- a/crates/astria-sequencer/src/authority/storage/snapshots/astria_sequencer__authority__storage__keys__tests__keys_should_not_change-2.snap +++ b/crates/astria-sequencer/src/authority/storage/snapshots/astria_sequencer__authority__storage__keys__tests__validator_set_key.snap @@ -1,6 +1,5 @@ --- source: crates/astria-sequencer/src/authority/storage/keys.rs -assertion_line: 16 -expression: VALIDATOR_SET_STORAGE_KEY +expression: VALIDATOR_SET --- authority/validator_set diff --git a/crates/astria-sequencer/src/authority/storage/snapshots/astria_sequencer__authority__storage__keys__tests__keys_should_not_change-3.snap b/crates/astria-sequencer/src/authority/storage/snapshots/astria_sequencer__authority__storage__keys__tests__validator_updates_key.snap similarity index 87% rename from crates/astria-sequencer/src/authority/storage/snapshots/astria_sequencer__authority__storage__keys__tests__keys_should_not_change-3.snap rename to crates/astria-sequencer/src/authority/storage/snapshots/astria_sequencer__authority__storage__keys__tests__validator_updates_key.snap index 1a0f29c99f..eca60bfd40 100644 --- a/crates/astria-sequencer/src/authority/storage/snapshots/astria_sequencer__authority__storage__keys__tests__keys_should_not_change-3.snap +++ b/crates/astria-sequencer/src/authority/storage/snapshots/astria_sequencer__authority__storage__keys__tests__validator_updates_key.snap @@ -1,6 +1,5 @@ --- source: crates/astria-sequencer/src/authority/storage/keys.rs -assertion_line: 15 expression: VALIDATOR_UPDATES --- authority/validator_updates diff --git a/crates/astria-sequencer/src/bridge/storage/keys.rs b/crates/astria-sequencer/src/bridge/storage/keys.rs index a8618637b4..358127c92e 100644 --- a/crates/astria-sequencer/src/bridge/storage/keys.rs +++ b/crates/astria-sequencer/src/bridge/storage/keys.rs @@ -91,14 +91,26 @@ mod tests { #[test] fn keys_should_not_change() { - insta::assert_snapshot!(DEPOSITS_EPHEMERAL); - insta::assert_snapshot!(rollup_id(&address())); - insta::assert_snapshot!(asset_id(&address())); - insta::assert_snapshot!(bridge_account_sudo_address(&address())); - insta::assert_snapshot!(bridge_account_withdrawer_address(&address())); - insta::assert_snapshot!(bridge_account_withdrawal_event(&address(), "the-event")); - insta::assert_snapshot!(deposit(&[1; 32], &RollupId::new([2; 32]))); - insta::assert_snapshot!(last_transaction_id_for_bridge_account(&address())); + insta::assert_snapshot!("ephemeral_deposits_key", DEPOSITS_EPHEMERAL); + insta::assert_snapshot!("rollup_id_key", rollup_id(&address())); + insta::assert_snapshot!("asset_id_key", asset_id(&address())); + insta::assert_snapshot!( + "bridge_sudo_address_key", + bridge_account_sudo_address(&address()) + ); + insta::assert_snapshot!( + "bridge_withdrawer_address_key", + bridge_account_withdrawer_address(&address()) + ); + insta::assert_snapshot!( + "bridge_withdrawal_event_key", + bridge_account_withdrawal_event(&address(), "the-event") + ); + insta::assert_snapshot!("deposit_key", deposit(&[1; 32], &RollupId::new([2; 32]))); + insta::assert_snapshot!( + "last_tx_id_for_bridge_acct_key", + last_transaction_id_for_bridge_account(&address()) + ); } #[test] diff --git a/crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__keys_should_not_change-3.snap b/crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__asset_id_key.snap similarity index 100% rename from crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__keys_should_not_change-3.snap rename to crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__asset_id_key.snap diff --git a/crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__keys_should_not_change-4.snap b/crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__bridge_sudo_address_key.snap similarity index 100% rename from crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__keys_should_not_change-4.snap rename to crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__bridge_sudo_address_key.snap diff --git a/crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__keys_should_not_change-6.snap b/crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__bridge_withdrawal_event_key.snap similarity index 100% rename from crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__keys_should_not_change-6.snap rename to crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__bridge_withdrawal_event_key.snap diff --git a/crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__keys_should_not_change-5.snap b/crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__bridge_withdrawer_address_key.snap similarity index 100% rename from crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__keys_should_not_change-5.snap rename to crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__bridge_withdrawer_address_key.snap diff --git a/crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__keys_should_not_change-7.snap b/crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__deposit_key.snap similarity index 100% rename from crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__keys_should_not_change-7.snap rename to crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__deposit_key.snap diff --git a/crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__keys_should_not_change.snap b/crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__ephemeral_deposits_key.snap similarity index 100% rename from crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__keys_should_not_change.snap rename to crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__ephemeral_deposits_key.snap diff --git a/crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__keys_should_not_change-8.snap b/crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__last_tx_id_for_bridge_acct_key.snap similarity index 100% rename from crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__keys_should_not_change-8.snap rename to crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__last_tx_id_for_bridge_acct_key.snap diff --git a/crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__keys_should_not_change-2.snap b/crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__rollup_id_key.snap similarity index 100% rename from crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__keys_should_not_change-2.snap rename to crates/astria-sequencer/src/bridge/storage/snapshots/astria_sequencer__bridge__storage__keys__tests__rollup_id_key.snap diff --git a/crates/astria-sequencer/src/grpc/storage/keys.rs b/crates/astria-sequencer/src/grpc/storage/keys.rs index 3c5280fe7f..1abb38ae18 100644 --- a/crates/astria-sequencer/src/grpc/storage/keys.rs +++ b/crates/astria-sequencer/src/grpc/storage/keys.rs @@ -50,12 +50,21 @@ mod tests { #[test] fn keys_should_not_change() { - insta::assert_snapshot!(block_hash_by_height(42)); - insta::assert_snapshot!(sequencer_block_header_by_hash(&HASH)); - insta::assert_snapshot!(rollup_data_by_hash_and_rollup_id(&HASH, &ROLLUP_ID)); - insta::assert_snapshot!(rollup_ids_by_hash(&HASH)); - insta::assert_snapshot!(rollup_transactions_proof_by_hash(&HASH)); - insta::assert_snapshot!(rollup_ids_proof_by_hash(&HASH)); + insta::assert_snapshot!("block_hash_by_height_key", block_hash_by_height(42)); + insta::assert_snapshot!( + "sequencer_block_header_by_hash_key", + sequencer_block_header_by_hash(&HASH) + ); + insta::assert_snapshot!( + "rollup_data_by_has_and_id_key", + rollup_data_by_hash_and_rollup_id(&HASH, &ROLLUP_ID) + ); + insta::assert_snapshot!("rollup_ids_by_hash_key", rollup_ids_by_hash(&HASH)); + insta::assert_snapshot!( + "rollup_transactions_proof_by_hash_key", + rollup_transactions_proof_by_hash(&HASH) + ); + insta::assert_snapshot!("rollup_ids_proof_by_hash", rollup_ids_proof_by_hash(&HASH)); } #[test] diff --git a/crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__keys_should_not_change.snap b/crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__block_hash_by_height_key.snap similarity index 86% rename from crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__keys_should_not_change.snap rename to crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__block_hash_by_height_key.snap index 95b4e91a7d..618abb7347 100644 --- a/crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__keys_should_not_change.snap +++ b/crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__block_hash_by_height_key.snap @@ -1,6 +1,5 @@ --- source: crates/astria-sequencer/src/grpc/storage/keys.rs -assertion_line: 44 expression: block_hash_by_height(42) --- grpc/block_hash/42 diff --git a/crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__keys_should_not_change-3.snap b/crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__rollup_data_by_has_and_id_key.snap similarity index 92% rename from crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__keys_should_not_change-3.snap rename to crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__rollup_data_by_has_and_id_key.snap index bef72d21bd..54d98329fd 100644 --- a/crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__keys_should_not_change-3.snap +++ b/crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__rollup_data_by_has_and_id_key.snap @@ -1,6 +1,5 @@ --- source: crates/astria-sequencer/src/grpc/storage/keys.rs -assertion_line: 46 expression: "rollup_data_by_hash_and_rollup_id(&HASH, &ROLLUP_ID)" --- grpc/rollup_data/AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE=/AgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgI= diff --git a/crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__keys_should_not_change-4.snap b/crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__rollup_ids_by_hash_key.snap similarity index 89% rename from crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__keys_should_not_change-4.snap rename to crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__rollup_ids_by_hash_key.snap index 5ee0401df5..61da04ba37 100644 --- a/crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__keys_should_not_change-4.snap +++ b/crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__rollup_ids_by_hash_key.snap @@ -1,6 +1,5 @@ --- source: crates/astria-sequencer/src/grpc/storage/keys.rs -assertion_line: 49 expression: rollup_ids_by_hash(&HASH) --- grpc/rollup_ids/AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE= diff --git a/crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__keys_should_not_change-6.snap b/crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__rollup_ids_proof_by_hash.snap similarity index 90% rename from crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__keys_should_not_change-6.snap rename to crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__rollup_ids_proof_by_hash.snap index cc164f9882..c573f4cea8 100644 --- a/crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__keys_should_not_change-6.snap +++ b/crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__rollup_ids_proof_by_hash.snap @@ -1,6 +1,5 @@ --- source: crates/astria-sequencer/src/grpc/storage/keys.rs -assertion_line: 51 expression: rollup_ids_proof_by_hash(&HASH) --- grpc/rollup_ids_proof/AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE= diff --git a/crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__keys_should_not_change-5.snap b/crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__rollup_transactions_proof_by_hash_key.snap similarity index 90% rename from crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__keys_should_not_change-5.snap rename to crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__rollup_transactions_proof_by_hash_key.snap index e221b2d469..45f3dc60cc 100644 --- a/crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__keys_should_not_change-5.snap +++ b/crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__rollup_transactions_proof_by_hash_key.snap @@ -1,6 +1,5 @@ --- source: crates/astria-sequencer/src/grpc/storage/keys.rs -assertion_line: 50 expression: rollup_transactions_proof_by_hash(&HASH) --- grpc/rollup_txs_proof/AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE= diff --git a/crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__keys_should_not_change-2.snap b/crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__sequencer_block_header_by_hash_key.snap similarity index 90% rename from crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__keys_should_not_change-2.snap rename to crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__sequencer_block_header_by_hash_key.snap index 018d0b55f2..4448a02ad2 100644 --- a/crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__keys_should_not_change-2.snap +++ b/crates/astria-sequencer/src/grpc/storage/snapshots/astria_sequencer__grpc__storage__keys__tests__sequencer_block_header_by_hash_key.snap @@ -1,6 +1,5 @@ --- source: crates/astria-sequencer/src/grpc/storage/keys.rs -assertion_line: 45 expression: sequencer_block_header_by_hash(&HASH) --- grpc/block_header/AQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQEBAQE= diff --git a/crates/astria-sequencer/src/ibc/storage/keys.rs b/crates/astria-sequencer/src/ibc/storage/keys.rs index 00cc0b5fd8..b1f2ab2f81 100644 --- a/crates/astria-sequencer/src/ibc/storage/keys.rs +++ b/crates/astria-sequencer/src/ibc/storage/keys.rs @@ -56,9 +56,12 @@ mod tests { #[test] fn keys_should_not_change() { - insta::assert_snapshot!(IBC_SUDO); - insta::assert_snapshot!(channel_balance(&channel_id(), &asset())); - insta::assert_snapshot!(ibc_relayer(&address())); + insta::assert_snapshot!("ibc_sudo_key", IBC_SUDO); + insta::assert_snapshot!( + "channel_balance_key", + channel_balance(&channel_id(), &asset()) + ); + insta::assert_snapshot!("ibc_relayer_key", ibc_relayer(&address())); } #[test] diff --git a/crates/astria-sequencer/src/ibc/storage/snapshots/astria_sequencer__ibc__storage__keys__tests__keys_should_not_change-2.snap b/crates/astria-sequencer/src/ibc/storage/snapshots/astria_sequencer__ibc__storage__keys__tests__channel_balance_key.snap similarity index 100% rename from crates/astria-sequencer/src/ibc/storage/snapshots/astria_sequencer__ibc__storage__keys__tests__keys_should_not_change-2.snap rename to crates/astria-sequencer/src/ibc/storage/snapshots/astria_sequencer__ibc__storage__keys__tests__channel_balance_key.snap diff --git a/crates/astria-sequencer/src/ibc/storage/snapshots/astria_sequencer__ibc__storage__keys__tests__keys_should_not_change-3.snap b/crates/astria-sequencer/src/ibc/storage/snapshots/astria_sequencer__ibc__storage__keys__tests__ibc_relayer_key.snap similarity index 100% rename from crates/astria-sequencer/src/ibc/storage/snapshots/astria_sequencer__ibc__storage__keys__tests__keys_should_not_change-3.snap rename to crates/astria-sequencer/src/ibc/storage/snapshots/astria_sequencer__ibc__storage__keys__tests__ibc_relayer_key.snap diff --git a/crates/astria-sequencer/src/ibc/storage/snapshots/astria_sequencer__ibc__storage__keys__tests__keys_should_not_change.snap b/crates/astria-sequencer/src/ibc/storage/snapshots/astria_sequencer__ibc__storage__keys__tests__ibc_sudo_key.snap similarity index 62% rename from crates/astria-sequencer/src/ibc/storage/snapshots/astria_sequencer__ibc__storage__keys__tests__keys_should_not_change.snap rename to crates/astria-sequencer/src/ibc/storage/snapshots/astria_sequencer__ibc__storage__keys__tests__ibc_sudo_key.snap index c8f53e7af2..b00a3ab756 100644 --- a/crates/astria-sequencer/src/ibc/storage/snapshots/astria_sequencer__ibc__storage__keys__tests__keys_should_not_change.snap +++ b/crates/astria-sequencer/src/ibc/storage/snapshots/astria_sequencer__ibc__storage__keys__tests__ibc_sudo_key.snap @@ -1,6 +1,5 @@ --- source: crates/astria-sequencer/src/ibc/storage/keys.rs -assertion_line: 63 -expression: IBC_SUDO_KEY +expression: IBC_SUDO --- ibc/sudo From 3931de084ae3f0d0eeed9bf52b34dad7f2bbdb74 Mon Sep 17 00:00:00 2001 From: Fraser Hutchison <190532+Fraser999@users.noreply.github.com> Date: Fri, 6 Dec 2024 17:15:10 +0000 Subject: [PATCH 2/7] chore(bridge-contracts): add snapshot test for memo (#1753) ## Summary This adds a snapshot test for the memo field being populated from the withdrawal info. ## Background The new test should serve to emphasize that the schema of the memo field is part of the API and changes to this could well be breaking. ## Changes - Moved some code unchanged inside the existing `memo_to_json` and removed the generic parameter. - Added snapshot test. ## Testing This _is_ a test. ## Changelogs No updates required - this is only adding a test. ## Related Issues Closes #1752. --------- Co-authored-by: noot <36753753+noot@users.noreply.github.com> --- Cargo.lock | 1 + crates/astria-bridge-contracts/Cargo.toml | 3 + crates/astria-bridge-contracts/src/lib.rs | 72 +++++++++++++------ ...ridge_contracts__tests__memo_snapshot.snap | 6 ++ 4 files changed, 60 insertions(+), 22 deletions(-) create mode 100644 crates/astria-bridge-contracts/src/snapshots/astria_bridge_contracts__tests__memo_snapshot.snap diff --git a/Cargo.lock b/Cargo.lock index c1605c33e2..c2e4aad8d7 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -505,6 +505,7 @@ dependencies = [ "ethers", "futures", "ibc-types", + "insta", "prost", "serde", "serde_json", diff --git a/crates/astria-bridge-contracts/Cargo.toml b/crates/astria-bridge-contracts/Cargo.toml index ef6ce29f7f..a398dc9d2a 100644 --- a/crates/astria-bridge-contracts/Cargo.toml +++ b/crates/astria-bridge-contracts/Cargo.toml @@ -18,3 +18,6 @@ serde_json = { workspace = true } tendermint = { workspace = true } thiserror = { workspace = true } tracing = { workspace = true, optional = true } + +[dev-dependencies] +insta = { workspace = true } diff --git a/crates/astria-bridge-contracts/src/lib.rs b/crates/astria-bridge-contracts/src/lib.rs index 8dcebad093..6b0bab9973 100644 --- a/crates/astria-bridge-contracts/src/lib.rs +++ b/crates/astria-bridge-contracts/src/lib.rs @@ -33,6 +33,7 @@ use ethers::{ Filter, Log, H256, + U256, }, }; pub use generated::*; @@ -432,14 +433,10 @@ where let transaction_hash = log .transaction_hash - .ok_or_else(|| GetWithdrawalActionsError::log_without_transaction_hash(&log))? - .encode_hex(); + .ok_or_else(|| GetWithdrawalActionsError::log_without_transaction_hash(&log))?; let event_index = log .log_index - .ok_or_else(|| GetWithdrawalActionsError::log_without_log_index(&log))? - .encode_hex(); - - let rollup_withdrawal_event_id = format!("{transaction_hash}.{event_index}"); + .ok_or_else(|| GetWithdrawalActionsError::log_without_log_index(&log))?; let event = decode_log::(log) .map_err(GetWithdrawalActionsError::decode_log)?; @@ -454,13 +451,9 @@ where .expect("must be set if this method is entered"), ); - let memo = memo_to_json(&memos::v1::Ics20WithdrawalFromRollup { - memo: event.memo.clone(), - rollup_block_number, - rollup_return_address: event.sender.encode_hex(), - rollup_withdrawal_event_id, - }) - .map_err(GetWithdrawalActionsError::encode_memo)?; + let memo = + make_withdrawal_memo(&event, rollup_block_number, &transaction_hash, &event_index) + .map_err(GetWithdrawalActionsError::encode_memo)?; let amount = calculate_amount(&event, self.asset_withdrawal_divisor) .map_err(GetWithdrawalActionsError::calculate_withdrawal_amount)?; @@ -494,14 +487,13 @@ where let transaction_hash = log .transaction_hash - .ok_or_else(|| GetWithdrawalActionsError::log_without_transaction_hash(&log))? - .encode_hex(); + .ok_or_else(|| GetWithdrawalActionsError::log_without_transaction_hash(&log))?; let event_index = log .log_index - .ok_or_else(|| GetWithdrawalActionsError::log_without_log_index(&log))? - .encode_hex(); + .ok_or_else(|| GetWithdrawalActionsError::log_without_log_index(&log))?; - let rollup_withdrawal_event_id = format!("{transaction_hash}.{event_index}"); + let rollup_withdrawal_event_id = + rollup_withdrawal_event_id(&transaction_hash, &event_index); let event = decode_log::(log) .map_err(GetWithdrawalActionsError::decode_log)?; @@ -698,9 +690,31 @@ struct EncodeMemoError { source: serde_json::Error, } -fn memo_to_json(memo: &T) -> Result { - serde_json::to_string(memo).map_err(|source| EncodeMemoError { - proto_message: T::full_name(), +fn rollup_withdrawal_event_id(transaction_hash: &H256, event_index: &U256) -> String { + format!( + "{}.{}", + transaction_hash.encode_hex(), + event_index.encode_hex() + ) +} + +fn make_withdrawal_memo( + event: &Ics20WithdrawalFilter, + rollup_block_number: u64, + transaction_hash: &H256, + event_index: &U256, +) -> Result { + use prost::Name as _; + type Memo = memos::v1::Ics20WithdrawalFromRollup; + + let withdrawal = Memo { + memo: event.memo.clone(), + rollup_block_number, + rollup_return_address: event.sender.encode_hex(), + rollup_withdrawal_event_id: rollup_withdrawal_event_id(transaction_hash, event_index), + }; + serde_json::to_string(&withdrawal).map_err(|source| EncodeMemoError { + proto_message: Memo::full_name(), source, }) } @@ -723,9 +737,23 @@ fn timeout_in_5_min() -> u64 { #[cfg(test)] mod tests { - use super::max_timeout_height; + use super::*; + #[test] fn max_timeout_height_does_not_panic() { max_timeout_height(); } + + #[test] + fn memo_format_should_not_change() { + let event = Ics20WithdrawalFilter { + sender: "14cbd075f796969cf5dbd853da492d86071f97ed".parse().unwrap(), + amount: U256::one(), + destination_chain_address: "destination address".to_string(), + memo: "".to_string(), + }; + let json_encoded_memo = + make_withdrawal_memo(&event, 999, &H256::from_slice(&[1; 32]), &U256::one()).unwrap(); + insta::assert_snapshot!("memo_snapshot", json_encoded_memo); + } } diff --git a/crates/astria-bridge-contracts/src/snapshots/astria_bridge_contracts__tests__memo_snapshot.snap b/crates/astria-bridge-contracts/src/snapshots/astria_bridge_contracts__tests__memo_snapshot.snap new file mode 100644 index 0000000000..9ae2b92bd2 --- /dev/null +++ b/crates/astria-bridge-contracts/src/snapshots/astria_bridge_contracts__tests__memo_snapshot.snap @@ -0,0 +1,6 @@ +--- +source: crates/astria-bridge-contracts/src/lib.rs +assertion_line: 757 +expression: json_encoded_memo +--- +{"rollupBlockNumber":"999","rollupWithdrawalEventId":"0x0101010101010101010101010101010101010101010101010101010101010101.0x0000000000000000000000000000000000000000000000000000000000000001","rollupReturnAddress":"0x00000000000000000000000014cbd075f796969cf5dbd853da492d86071f97ed","memo":""} From 3419c74aad903810756563b912d92dc5aba50cdc Mon Sep 17 00:00:00 2001 From: Fraser Hutchison <190532+Fraser999@users.noreply.github.com> Date: Fri, 6 Dec 2024 17:15:58 +0000 Subject: [PATCH 3/7] chore: add tests for ABCI error codes (#1754) ## Summary Added tests for the ABCI error codes. ## Background The new snapshot test should serve to emphasize that the error codes are part of the API and changes here would be breaking. The other test should help avoid accidental duplication of a value. ## Changes - Added a snapshot test. - Added a test for unique values of error codes. ## Testing These _are_ tests. ## Changelogs No updates required - this is only adding unit tests. ## Related Issues Closes #1634. Co-authored-by: noot <36753753+noot@users.noreply.github.com> --- crates/astria-core/src/protocol/abci.rs | 48 ++++++++++++++++++- ...otocol__abci__tests__AbciErrorCode::1.snap | 5 ++ ...tocol__abci__tests__AbciErrorCode::10.snap | 5 ++ ...tocol__abci__tests__AbciErrorCode::11.snap | 5 ++ ...tocol__abci__tests__AbciErrorCode::12.snap | 5 ++ ...tocol__abci__tests__AbciErrorCode::13.snap | 5 ++ ...tocol__abci__tests__AbciErrorCode::14.snap | 5 ++ ...tocol__abci__tests__AbciErrorCode::15.snap | 5 ++ ...tocol__abci__tests__AbciErrorCode::16.snap | 5 ++ ...tocol__abci__tests__AbciErrorCode::17.snap | 5 ++ ...otocol__abci__tests__AbciErrorCode::2.snap | 5 ++ ...otocol__abci__tests__AbciErrorCode::3.snap | 5 ++ ...otocol__abci__tests__AbciErrorCode::4.snap | 5 ++ ...otocol__abci__tests__AbciErrorCode::5.snap | 5 ++ ...otocol__abci__tests__AbciErrorCode::6.snap | 5 ++ ...otocol__abci__tests__AbciErrorCode::7.snap | 5 ++ ...otocol__abci__tests__AbciErrorCode::8.snap | 5 ++ ...otocol__abci__tests__AbciErrorCode::9.snap | 5 ++ 18 files changed, 131 insertions(+), 2 deletions(-) create mode 100644 crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::1.snap create mode 100644 crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::10.snap create mode 100644 crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::11.snap create mode 100644 crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::12.snap create mode 100644 crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::13.snap create mode 100644 crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::14.snap create mode 100644 crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::15.snap create mode 100644 crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::16.snap create mode 100644 crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::17.snap create mode 100644 crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::2.snap create mode 100644 crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::3.snap create mode 100644 crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::4.snap create mode 100644 crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::5.snap create mode 100644 crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::6.snap create mode 100644 crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::7.snap create mode 100644 crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::8.snap create mode 100644 crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::9.snap diff --git a/crates/astria-core/src/protocol/abci.rs b/crates/astria-core/src/protocol/abci.rs index 4047ae679f..916f2efe9a 100644 --- a/crates/astria-core/src/protocol/abci.rs +++ b/crates/astria-core/src/protocol/abci.rs @@ -19,13 +19,14 @@ impl AbciErrorCode { pub const VALUE_NOT_FOUND: Self = Self(unsafe { NonZeroU32::new_unchecked(8) }); pub const TRANSACTION_EXPIRED: Self = Self(unsafe { NonZeroU32::new_unchecked(9) }); pub const TRANSACTION_FAILED: Self = Self(unsafe { NonZeroU32::new_unchecked(10) }); - pub const TRANSACTION_INSERTION_FAILED: Self = Self(unsafe { NonZeroU32::new_unchecked(11) }); - pub const LOWER_NONCE_INVALIDATED: Self = Self(unsafe { NonZeroU32::new_unchecked(12) }); + pub const TRANSACTION_INSERTION_FAILED: Self = Self(unsafe { NonZeroU32::new_unchecked(11) }); + pub const LOWER_NONCE_INVALIDATED: Self = Self(unsafe { NonZeroU32::new_unchecked(12) }); pub const BAD_REQUEST: Self = Self(unsafe { NonZeroU32::new_unchecked(13) }); pub const ALREADY_PRESENT: Self = Self(unsafe { NonZeroU32::new_unchecked(14) }); pub const NONCE_TAKEN: Self = Self(unsafe { NonZeroU32::new_unchecked(15) }); pub const ACCOUNT_SIZE_LIMIT: Self = Self(unsafe { NonZeroU32::new_unchecked(16) }); pub const PARKED_FULL: Self = Self(unsafe { NonZeroU32::new_unchecked(17) }); + // NOTE: When adding a new code, ensure it is added to `ALL_CODES` in the `tests` module below. } impl AbciErrorCode { @@ -76,3 +77,46 @@ impl std::fmt::Display for AbciErrorCode { write!(f, "{}: {}", self.0, self.info()) } } + +#[cfg(test)] +mod tests { + use std::collections::BTreeSet; + + use super::*; + + const ALL_CODES: [AbciErrorCode; 17] = [ + AbciErrorCode::UNKNOWN_PATH, + AbciErrorCode::INVALID_PARAMETER, + AbciErrorCode::INTERNAL_ERROR, + AbciErrorCode::INVALID_NONCE, + AbciErrorCode::TRANSACTION_TOO_LARGE, + AbciErrorCode::INSUFFICIENT_FUNDS, + AbciErrorCode::INVALID_CHAIN_ID, + AbciErrorCode::VALUE_NOT_FOUND, + AbciErrorCode::TRANSACTION_EXPIRED, + AbciErrorCode::TRANSACTION_FAILED, + AbciErrorCode::TRANSACTION_INSERTION_FAILED, + AbciErrorCode::LOWER_NONCE_INVALIDATED, + AbciErrorCode::BAD_REQUEST, + AbciErrorCode::ALREADY_PRESENT, + AbciErrorCode::NONCE_TAKEN, + AbciErrorCode::ACCOUNT_SIZE_LIMIT, + AbciErrorCode::PARKED_FULL, + ]; + + #[test] + fn error_code_snapshots() { + for error_code in ALL_CODES { + let name = format!("AbciErrorCode::{}", error_code.value()); + insta::assert_snapshot!(name, error_code); + } + } + + #[test] + fn ensure_codes_are_unique() { + let mut values = BTreeSet::new(); + for code in ALL_CODES { + assert!(values.insert(code.value()), "duplicate value for {code:?}"); + } + } +} diff --git a/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::1.snap b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::1.snap new file mode 100644 index 0000000000..7f2d7fa477 --- /dev/null +++ b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::1.snap @@ -0,0 +1,5 @@ +--- +source: crates/astria-core/src/protocol/abci.rs +expression: error_code +--- +1: provided path is unknown diff --git a/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::10.snap b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::10.snap new file mode 100644 index 0000000000..dddafed37b --- /dev/null +++ b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::10.snap @@ -0,0 +1,5 @@ +--- +source: crates/astria-core/src/protocol/abci.rs +expression: error_code +--- +10: the transaction failed to execute in prepare_proposal() diff --git a/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::11.snap b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::11.snap new file mode 100644 index 0000000000..0d95b0e655 --- /dev/null +++ b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::11.snap @@ -0,0 +1,5 @@ +--- +source: crates/astria-core/src/protocol/abci.rs +expression: error_code +--- +11: the transaction failed insertion into the mempool diff --git a/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::12.snap b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::12.snap new file mode 100644 index 0000000000..4872baa2a7 --- /dev/null +++ b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::12.snap @@ -0,0 +1,5 @@ +--- +source: crates/astria-core/src/protocol/abci.rs +expression: error_code +--- +12: lower nonce was invalidated in mempool diff --git a/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::13.snap b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::13.snap new file mode 100644 index 0000000000..e094b106fe --- /dev/null +++ b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::13.snap @@ -0,0 +1,5 @@ +--- +source: crates/astria-core/src/protocol/abci.rs +expression: error_code +--- +13: the request payload was malformed diff --git a/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::14.snap b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::14.snap new file mode 100644 index 0000000000..3f904c48fe --- /dev/null +++ b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::14.snap @@ -0,0 +1,5 @@ +--- +source: crates/astria-core/src/protocol/abci.rs +expression: error_code +--- +14: the transaction is already present in the mempool diff --git a/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::15.snap b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::15.snap new file mode 100644 index 0000000000..2e01c9a592 --- /dev/null +++ b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::15.snap @@ -0,0 +1,5 @@ +--- +source: crates/astria-core/src/protocol/abci.rs +expression: error_code +--- +15: there is already a transaction with the same nonce for the account in the mempool diff --git a/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::16.snap b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::16.snap new file mode 100644 index 0000000000..9130798686 --- /dev/null +++ b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::16.snap @@ -0,0 +1,5 @@ +--- +source: crates/astria-core/src/protocol/abci.rs +expression: error_code +--- +16: the account has reached the maximum number of parked transactions diff --git a/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::17.snap b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::17.snap new file mode 100644 index 0000000000..c2b1abd2ed --- /dev/null +++ b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::17.snap @@ -0,0 +1,5 @@ +--- +source: crates/astria-core/src/protocol/abci.rs +expression: error_code +--- +17: the mempool is out of space for more parked transactions diff --git a/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::2.snap b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::2.snap new file mode 100644 index 0000000000..03112a8ccd --- /dev/null +++ b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::2.snap @@ -0,0 +1,5 @@ +--- +source: crates/astria-core/src/protocol/abci.rs +expression: error_code +--- +2: one or more path parameters were invalid diff --git a/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::3.snap b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::3.snap new file mode 100644 index 0000000000..a1cfa0e86c --- /dev/null +++ b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::3.snap @@ -0,0 +1,5 @@ +--- +source: crates/astria-core/src/protocol/abci.rs +expression: error_code +--- +3: an internal server error occurred diff --git a/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::4.snap b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::4.snap new file mode 100644 index 0000000000..5c8d975c27 --- /dev/null +++ b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::4.snap @@ -0,0 +1,5 @@ +--- +source: crates/astria-core/src/protocol/abci.rs +expression: error_code +--- +4: the provided nonce was invalid diff --git a/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::5.snap b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::5.snap new file mode 100644 index 0000000000..b7f009f0c9 --- /dev/null +++ b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::5.snap @@ -0,0 +1,5 @@ +--- +source: crates/astria-core/src/protocol/abci.rs +expression: error_code +--- +5: the provided transaction was too large diff --git a/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::6.snap b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::6.snap new file mode 100644 index 0000000000..07df14d451 --- /dev/null +++ b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::6.snap @@ -0,0 +1,5 @@ +--- +source: crates/astria-core/src/protocol/abci.rs +expression: error_code +--- +6: insufficient funds diff --git a/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::7.snap b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::7.snap new file mode 100644 index 0000000000..c0767b6d92 --- /dev/null +++ b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::7.snap @@ -0,0 +1,5 @@ +--- +source: crates/astria-core/src/protocol/abci.rs +expression: error_code +--- +7: the provided chain id was invalid diff --git a/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::8.snap b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::8.snap new file mode 100644 index 0000000000..52ffe44117 --- /dev/null +++ b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::8.snap @@ -0,0 +1,5 @@ +--- +source: crates/astria-core/src/protocol/abci.rs +expression: error_code +--- +8: the requested value was not found diff --git a/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::9.snap b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::9.snap new file mode 100644 index 0000000000..94fc4ca2ed --- /dev/null +++ b/crates/astria-core/src/protocol/snapshots/astria_core__protocol__abci__tests__AbciErrorCode::9.snap @@ -0,0 +1,5 @@ +--- +source: crates/astria-core/src/protocol/abci.rs +expression: error_code +--- +9: the transaction expired in the app's mempool From 903e1f3c659479142fe17e2782033e2ec5e31769 Mon Sep 17 00:00:00 2001 From: Fraser Hutchison <190532+Fraser999@users.noreply.github.com> Date: Fri, 6 Dec 2024 17:20:49 +0000 Subject: [PATCH 4/7] chore(sequencer): refactor fees (#1811) ## Summary This reduces a lot of boilerplate around fees. ## Background The boilerplate code is very prone to copy-paste errors. Changing the 14 different (but structurally identical) `FeeComponent` structs into a single one with a generic arg reduces a lot of the boilerplate code. This PR replaces #1739 (an initial, more restricted refactor) and #1794 (a PR on top of #1739). It comprises the net changes of these two PRs in [the first commit](https://github.com/astriaorg/astria/commit/a8ec42406cf3da629ddef1420e302708c3d8ccf9), followed by most of the changes suggested by @eoroshiba's review of #1794 in [the second commit](https://github.com/astriaorg/astria/commit/c92dc989d5e99dfbbc78efbfaa1b1910824c957c). [The third commit](https://github.com/astriaorg/astria/commit/1316e076f7b495d2bfa78c8ae9bcea71d6fe97a8) is also in response to @eoroshiba's suggestion to remove the fee aliases, and is a single commit in case others prefer that change to be reverted. ## Changes - In core, replaced fee component structs with a new `FeeComponents` where `T` will be some action type. - In sequencer, changed the `FeeHandler` trait fairly radically to support the new form of fees. ## Testing Existing tests are sufficient - there should be no changed functionality to the business logic. ## Changelogs No updates required. ## Related Issues Closes #1715. --- Cargo.lock | 2 +- crates/astria-core/src/protocol/fees/v1.rs | 168 ++--- crates/astria-core/src/protocol/genesis/v1.rs | 232 +++---- .../transaction/v1/action/group/tests.rs | 7 +- .../src/protocol/transaction/v1/action/mod.rs | 169 +++-- crates/astria-sequencer-utils/Cargo.toml | 1 + .../src/genesis_example.rs | 144 +--- crates/astria-sequencer/Cargo.toml | 1 - .../impls/bridge_sudo_change.rs | 7 +- .../src/action_handler/impls/bridge_unlock.rs | 7 +- .../src/action_handler/impls/fee_change.rs | 248 ++++--- .../src/action_handler/impls/transaction.rs | 21 +- .../src/app/benchmark_and_test_utils.rs | 212 ++---- .../src/app/tests_app/mempool.rs | 20 +- .../astria-sequencer/src/app/tests_app/mod.rs | 4 +- .../src/app/tests_execute_transaction.rs | 27 +- crates/astria-sequencer/src/fees/component.rs | 28 +- crates/astria-sequencer/src/fees/mod.rs | 447 ++++++++----- crates/astria-sequencer/src/fees/query.rs | 369 ++++------- crates/astria-sequencer/src/fees/state_ext.rs | 620 ++---------------- .../astria-sequencer/src/fees/storage/keys.rs | 106 +-- .../astria-sequencer/src/fees/storage/mod.rs | 16 - ...rage__keys__tests__transfer_fees_key.snap} | 0 .../src/fees/storage/values.rs | 238 ++----- crates/astria-sequencer/src/fees/tests.rs | 61 +- .../astria-sequencer/src/service/info/mod.rs | 108 +-- crates/astria-sequencer/src/test_utils.rs | 39 +- .../src/transaction/checks.rs | 135 +--- 28 files changed, 1279 insertions(+), 2158 deletions(-) rename crates/astria-sequencer/src/fees/storage/snapshots/{astria_sequencer__fees__storage__keys__tests__transer_fees_key.snap => astria_sequencer__fees__storage__keys__tests__transfer_fees_key.snap} (100%) diff --git a/Cargo.lock b/Cargo.lock index c2e4aad8d7..def7009d8b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -842,7 +842,6 @@ dependencies = [ "insta", "maplit", "matchit", - "paste", "penumbra-ibc", "penumbra-proto", "penumbra-tower-trace", @@ -964,6 +963,7 @@ dependencies = [ "hex", "indenter", "itertools 0.12.1", + "penumbra-ibc", "predicates", "prost", "rlp", diff --git a/crates/astria-core/src/protocol/fees/v1.rs b/crates/astria-core/src/protocol/fees/v1.rs index f77441a90c..fb5571e9b9 100644 --- a/crates/astria-core/src/protocol/fees/v1.rs +++ b/crates/astria-core/src/protocol/fees/v1.rs @@ -1,8 +1,33 @@ +use std::{ + fmt::{ + self, + Debug, + Formatter, + }, + marker::PhantomData, +}; + +use penumbra_ibc::IbcRelay; use prost::Name as _; use crate::{ generated::astria::protocol::fees::v1 as raw, primitive::v1::asset, + protocol::transaction::v1::action::{ + BridgeLock, + BridgeSudoChange, + BridgeUnlock, + FeeAssetChange, + FeeChange, + IbcRelayerChange, + IbcSudoChange, + Ics20Withdrawal, + InitBridgeAccount, + RollupDataSubmission, + SudoAddressChange, + Transfer, + ValidatorUpdate, + }, Protobuf, }; @@ -49,6 +74,7 @@ macro_rules! impl_protobuf_for_fee_components { multiplier: multiplier .ok_or_else(|| Self::Error::missing_field(Self::Raw::full_name(), "multiplier"))? .into(), + _phantom: PhantomData, }) } @@ -56,6 +82,7 @@ macro_rules! impl_protobuf_for_fee_components { let Self { base, multiplier, + _phantom, } = self; Self::Raw { base: Some(base.into()), @@ -67,104 +94,79 @@ macro_rules! impl_protobuf_for_fee_components { }; } impl_protobuf_for_fee_components!( - TransferFeeComponents => raw::TransferFeeComponents, - RollupDataSubmissionFeeComponents => raw::RollupDataSubmissionFeeComponents, - Ics20WithdrawalFeeComponents => raw::Ics20WithdrawalFeeComponents, - InitBridgeAccountFeeComponents => raw::InitBridgeAccountFeeComponents, - BridgeLockFeeComponents => raw::BridgeLockFeeComponents, - BridgeUnlockFeeComponents => raw::BridgeUnlockFeeComponents, - BridgeSudoChangeFeeComponents => raw::BridgeSudoChangeFeeComponents, - ValidatorUpdateFeeComponents => raw::ValidatorUpdateFeeComponents, - IbcRelayerChangeFeeComponents => raw::IbcRelayerChangeFeeComponents, - IbcRelayFeeComponents => raw::IbcRelayFeeComponents, - FeeAssetChangeFeeComponents => raw::FeeAssetChangeFeeComponents, - FeeChangeFeeComponents => raw::FeeChangeFeeComponents, - SudoAddressChangeFeeComponents => raw::SudoAddressChangeFeeComponents, - IbcSudoChangeFeeComponents => raw::IbcSudoChangeFeeComponents, + FeeComponents => raw::TransferFeeComponents, + FeeComponents => raw::RollupDataSubmissionFeeComponents, + FeeComponents => raw::Ics20WithdrawalFeeComponents, + FeeComponents => raw::InitBridgeAccountFeeComponents, + FeeComponents => raw::BridgeLockFeeComponents, + FeeComponents => raw::BridgeUnlockFeeComponents, + FeeComponents => raw::BridgeSudoChangeFeeComponents, + FeeComponents => raw::ValidatorUpdateFeeComponents, + FeeComponents => raw::IbcRelayerChangeFeeComponents, + FeeComponents => raw::IbcRelayFeeComponents, + FeeComponents => raw::FeeAssetChangeFeeComponents, + FeeComponents => raw::FeeChangeFeeComponents, + FeeComponents => raw::SudoAddressChangeFeeComponents, + FeeComponents => raw::IbcSudoChangeFeeComponents, ); -#[derive(Clone, Copy, Debug, PartialEq)] -pub struct TransferFeeComponents { - pub base: u128, - pub multiplier: u128, -} - -#[derive(Clone, Copy, Debug, PartialEq)] -pub struct RollupDataSubmissionFeeComponents { - pub base: u128, - pub multiplier: u128, -} - -#[derive(Clone, Copy, Debug, PartialEq)] -pub struct Ics20WithdrawalFeeComponents { - pub base: u128, - pub multiplier: u128, -} - -#[derive(Clone, Copy, Debug, PartialEq)] -pub struct InitBridgeAccountFeeComponents { - pub base: u128, - pub multiplier: u128, -} - -#[derive(Clone, Copy, Debug, PartialEq)] -pub struct BridgeLockFeeComponents { - pub base: u128, - pub multiplier: u128, +pub struct FeeComponents { + base: u128, + multiplier: u128, + _phantom: PhantomData, } -#[derive(Clone, Copy, Debug, PartialEq)] -pub struct BridgeUnlockFeeComponents { - pub base: u128, - pub multiplier: u128, -} - -#[derive(Clone, Copy, Debug, PartialEq)] -pub struct BridgeSudoChangeFeeComponents { - pub base: u128, - pub multiplier: u128, -} +impl FeeComponents { + #[must_use] + pub fn new(base: u128, multiplier: u128) -> Self { + Self { + base, + multiplier, + _phantom: PhantomData, + } + } -#[derive(Clone, Copy, Debug, PartialEq)] -pub struct IbcRelayFeeComponents { - pub base: u128, - pub multiplier: u128, -} + #[must_use] + pub fn base(&self) -> u128 { + self.base + } -#[derive(Clone, Copy, Debug, PartialEq)] -pub struct ValidatorUpdateFeeComponents { - pub base: u128, - pub multiplier: u128, + #[must_use] + pub fn multiplier(&self) -> u128 { + self.multiplier + } } -#[derive(Clone, Copy, Debug, PartialEq)] -pub struct FeeAssetChangeFeeComponents { - pub base: u128, - pub multiplier: u128, +impl Debug for FeeComponents { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.debug_struct(&format!("FeeComponents<{}>", T::Raw::NAME)) + .field("base", &self.base) + .field("multiplier", &self.multiplier) + .finish() + } } -#[derive(Clone, Copy, Debug, PartialEq)] -pub struct FeeChangeFeeComponents { - pub base: u128, - pub multiplier: u128, +impl Debug for FeeComponents { + fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { + f.debug_struct("FeeComponents") + .field("base", &self.base) + .field("multiplier", &self.multiplier) + .finish() + } } -#[derive(Clone, Copy, Debug, PartialEq)] -pub struct IbcRelayerChangeFeeComponents { - pub base: u128, - pub multiplier: u128, +impl Clone for FeeComponents { + fn clone(&self) -> Self { + *self + } } -#[derive(Clone, Copy, Debug, PartialEq)] -pub struct SudoAddressChangeFeeComponents { - pub base: u128, - pub multiplier: u128, -} +impl Copy for FeeComponents {} -#[derive(Clone, Copy, Debug, PartialEq)] -pub struct IbcSudoChangeFeeComponents { - pub base: u128, - pub multiplier: u128, +impl PartialEq for FeeComponents { + fn eq(&self, other: &Self) -> bool { + self.base == other.base && self.multiplier == other.multiplier + } } #[derive(Debug, Clone)] diff --git a/crates/astria-core/src/protocol/genesis/v1.rs b/crates/astria-core/src/protocol/genesis/v1.rs index de177b1cc9..2dac7e1aae 100644 --- a/crates/astria-core/src/protocol/genesis/v1.rs +++ b/crates/astria-core/src/protocol/genesis/v1.rs @@ -1,6 +1,7 @@ use std::convert::Infallible; pub use penumbra_ibc::params::IBCParameters; +use penumbra_ibc::IbcRelay; use crate::{ generated::astria::protocol::genesis::v1 as raw, @@ -15,22 +16,26 @@ use crate::{ Bech32, Bech32m, }, - protocol::fees::v1::{ - BridgeLockFeeComponents, - BridgeSudoChangeFeeComponents, - BridgeUnlockFeeComponents, - FeeAssetChangeFeeComponents, - FeeChangeFeeComponents, - FeeComponentError, - IbcRelayFeeComponents, - IbcRelayerChangeFeeComponents, - IbcSudoChangeFeeComponents, - Ics20WithdrawalFeeComponents, - InitBridgeAccountFeeComponents, - RollupDataSubmissionFeeComponents, - SudoAddressChangeFeeComponents, - TransferFeeComponents, - ValidatorUpdateFeeComponents, + protocol::{ + fees::v1::{ + FeeComponentError, + FeeComponents, + }, + transaction::v1::action::{ + BridgeLock, + BridgeSudoChange, + BridgeUnlock, + FeeAssetChange, + FeeChange, + IbcRelayerChange, + IbcSudoChange, + Ics20Withdrawal, + InitBridgeAccount, + RollupDataSubmission, + SudoAddressChange, + Transfer, + ValidatorUpdate, + }, }, Protobuf, }; @@ -580,20 +585,20 @@ impl From for IBCParameters { #[derive(Clone, Debug)] pub struct GenesisFees { - pub rollup_data_submission: Option, - pub transfer: Option, - pub ics20_withdrawal: Option, - pub init_bridge_account: Option, - pub bridge_lock: Option, - pub bridge_unlock: Option, - pub bridge_sudo_change: Option, - pub ibc_relay: Option, - pub validator_update: Option, - pub fee_asset_change: Option, - pub fee_change: FeeChangeFeeComponents, - pub ibc_relayer_change: Option, - pub sudo_address_change: Option, - pub ibc_sudo_change: Option, + pub rollup_data_submission: Option>, + pub transfer: Option>, + pub ics20_withdrawal: Option>, + pub init_bridge_account: Option>, + pub bridge_lock: Option>, + pub bridge_unlock: Option>, + pub bridge_sudo_change: Option>, + pub ibc_relay: Option>, + pub validator_update: Option>, + pub fee_asset_change: Option>, + pub fee_change: FeeComponents, + pub ibc_relayer_change: Option>, + pub sudo_address_change: Option>, + pub ibc_sudo_change: Option>, } impl Protobuf for GenesisFees { @@ -623,65 +628,65 @@ impl Protobuf for GenesisFees { } = raw; let rollup_data_submission = rollup_data_submission .clone() - .map(RollupDataSubmissionFeeComponents::try_from_raw) + .map(FeeComponents::::try_from_raw) .transpose() .map_err(|e| FeesError::fee_components("rollup_data_submission", e))?; let transfer = transfer .clone() - .map(TransferFeeComponents::try_from_raw) + .map(FeeComponents::::try_from_raw) .transpose() .map_err(|e| FeesError::fee_components("transfer", e))?; let ics20_withdrawal = ics20_withdrawal .clone() - .map(Ics20WithdrawalFeeComponents::try_from_raw) + .map(FeeComponents::::try_from_raw) .transpose() .map_err(|e| FeesError::fee_components("ics20_withdrawal", e))?; let init_bridge_account = init_bridge_account .clone() - .map(InitBridgeAccountFeeComponents::try_from_raw) + .map(FeeComponents::::try_from_raw) .transpose() .map_err(|e| FeesError::fee_components("init_bridge_account", e))?; let bridge_lock = bridge_lock .clone() - .map(BridgeLockFeeComponents::try_from_raw) + .map(FeeComponents::::try_from_raw) .transpose() .map_err(|e| FeesError::fee_components("bridge_lock", e))?; let bridge_unlock = bridge_unlock .clone() - .map(BridgeUnlockFeeComponents::try_from_raw) + .map(FeeComponents::::try_from_raw) .transpose() .map_err(|e| FeesError::fee_components("bridge_unlock", e))?; let bridge_sudo_change = bridge_sudo_change .clone() - .map(BridgeSudoChangeFeeComponents::try_from_raw) + .map(FeeComponents::::try_from_raw) .transpose() .map_err(|e| FeesError::fee_components("bridge_sudo_change", e))?; let ibc_relay = ibc_relay .clone() - .map(IbcRelayFeeComponents::try_from_raw) + .map(FeeComponents::::try_from_raw) .transpose() .map_err(|e| FeesError::fee_components("ibc_relay", e))?; let validator_update = validator_update .clone() - .map(ValidatorUpdateFeeComponents::try_from_raw) + .map(FeeComponents::::try_from_raw) .transpose() .map_err(|e| FeesError::fee_components("validator_update", e))?; let fee_asset_change = fee_asset_change .clone() - .map(FeeAssetChangeFeeComponents::try_from_raw) + .map(FeeComponents::::try_from_raw) .transpose() .map_err(|e| FeesError::fee_components("fee_asset_change", e))?; - let fee_change = FeeChangeFeeComponents::try_from_raw( + let fee_change = FeeComponents::::try_from_raw( fee_change .clone() .ok_or_else(|| Self::Error::field_not_set("fee_change"))?, @@ -690,19 +695,19 @@ impl Protobuf for GenesisFees { let ibc_relayer_change = ibc_relayer_change .clone() - .map(IbcRelayerChangeFeeComponents::try_from_raw) + .map(FeeComponents::::try_from_raw) .transpose() .map_err(|e| FeesError::fee_components("ibc_relayer_change", e))?; let sudo_address_change = sudo_address_change .clone() - .map(SudoAddressChangeFeeComponents::try_from_raw) + .map(FeeComponents::::try_from_raw) .transpose() .map_err(|e| FeesError::fee_components("sudo_address_change", e))?; let ibc_sudo_change = ibc_sudo_change .clone() - .map(IbcSudoChangeFeeComponents::try_from_raw) + .map(FeeComponents::::try_from_raw) .transpose() .map_err(|e| FeesError::fee_components("ibc_sudo_change", e))?; @@ -742,27 +747,29 @@ impl Protobuf for GenesisFees { ibc_sudo_change, } = self; Self::Raw { - transfer: transfer.map(|act| TransferFeeComponents::to_raw(&act)), + transfer: transfer.map(|act| FeeComponents::::to_raw(&act)), rollup_data_submission: rollup_data_submission - .map(|act| RollupDataSubmissionFeeComponents::to_raw(&act)), + .map(|act| FeeComponents::::to_raw(&act)), ics20_withdrawal: ics20_withdrawal - .map(|act| Ics20WithdrawalFeeComponents::to_raw(&act)), + .map(|act| FeeComponents::::to_raw(&act)), init_bridge_account: init_bridge_account - .map(|act| InitBridgeAccountFeeComponents::to_raw(&act)), - bridge_lock: bridge_lock.map(|act| BridgeLockFeeComponents::to_raw(&act)), - bridge_unlock: bridge_unlock.map(|act| BridgeUnlockFeeComponents::to_raw(&act)), + .map(|act| FeeComponents::::to_raw(&act)), + bridge_lock: bridge_lock.map(|act| FeeComponents::::to_raw(&act)), + bridge_unlock: bridge_unlock.map(|act| FeeComponents::::to_raw(&act)), bridge_sudo_change: bridge_sudo_change - .map(|act| BridgeSudoChangeFeeComponents::to_raw(&act)), - ibc_relay: ibc_relay.map(|act| IbcRelayFeeComponents::to_raw(&act)), + .map(|act| FeeComponents::::to_raw(&act)), + ibc_relay: ibc_relay.map(|act| FeeComponents::::to_raw(&act)), validator_update: validator_update - .map(|act| ValidatorUpdateFeeComponents::to_raw(&act)), - fee_asset_change: fee_asset_change.map(|act| FeeAssetChangeFeeComponents::to_raw(&act)), + .map(|act| FeeComponents::::to_raw(&act)), + fee_asset_change: fee_asset_change + .map(|act| FeeComponents::::to_raw(&act)), fee_change: Some(fee_change.to_raw()), ibc_relayer_change: ibc_relayer_change - .map(|act| IbcRelayerChangeFeeComponents::to_raw(&act)), + .map(|act| FeeComponents::::to_raw(&act)), sudo_address_change: sudo_address_change - .map(|act| SudoAddressChangeFeeComponents::to_raw(&act)), - ibc_sudo_change: ibc_sudo_change.map(|act| IbcSudoChangeFeeComponents::to_raw(&act)), + .map(|act| FeeComponents::::to_raw(&act)), + ibc_sudo_change: ibc_sudo_change + .map(|act| FeeComponents::::to_raw(&act)), } } } @@ -837,7 +844,6 @@ mod tests { .unwrap() } - #[expect(clippy::too_many_lines, reason = "for testing purposes")] fn proto_genesis_state() -> raw::GenesisAppState { raw::GenesisAppState { accounts: vec![ @@ -870,104 +876,22 @@ mod tests { }), allowed_fee_assets: vec!["nria".into()], fees: Some(raw::GenesisFees { - transfer: Some( - TransferFeeComponents { - base: 12, - multiplier: 0, - } - .to_raw(), - ), + transfer: Some(FeeComponents::::new(12, 0).to_raw()), rollup_data_submission: Some( - RollupDataSubmissionFeeComponents { - base: 32, - multiplier: 1, - } - .to_raw(), - ), - init_bridge_account: Some( - InitBridgeAccountFeeComponents { - base: 48, - multiplier: 0, - } - .to_raw(), - ), - bridge_lock: Some( - BridgeLockFeeComponents { - base: 12, - multiplier: 1, - } - .to_raw(), - ), - bridge_unlock: Some( - BridgeUnlockFeeComponents { - base: 12, - multiplier: 0, - } - .to_raw(), - ), - bridge_sudo_change: Some( - BridgeSudoChangeFeeComponents { - base: 24, - multiplier: 0, - } - .to_raw(), - ), - ics20_withdrawal: Some( - Ics20WithdrawalFeeComponents { - base: 24, - multiplier: 0, - } - .to_raw(), - ), - ibc_relay: Some( - IbcRelayFeeComponents { - base: 0, - multiplier: 0, - } - .to_raw(), - ), - validator_update: Some( - ValidatorUpdateFeeComponents { - base: 0, - multiplier: 0, - } - .to_raw(), - ), - fee_asset_change: Some( - FeeAssetChangeFeeComponents { - base: 0, - multiplier: 0, - } - .to_raw(), - ), - fee_change: Some( - FeeChangeFeeComponents { - base: 0, - multiplier: 0, - } - .to_raw(), - ), - ibc_relayer_change: Some( - IbcRelayerChangeFeeComponents { - base: 0, - multiplier: 0, - } - .to_raw(), - ), - sudo_address_change: Some( - SudoAddressChangeFeeComponents { - base: 0, - multiplier: 0, - } - .to_raw(), - ), - ibc_sudo_change: Some( - IbcSudoChangeFeeComponents { - base: 0, - multiplier: 0, - } - .to_raw(), + FeeComponents::::new(32, 1).to_raw(), ), + init_bridge_account: Some(FeeComponents::::new(48, 0).to_raw()), + bridge_lock: Some(FeeComponents::::new(12, 1).to_raw()), + bridge_unlock: Some(FeeComponents::::new(12, 0).to_raw()), + bridge_sudo_change: Some(FeeComponents::::new(24, 0).to_raw()), + ics20_withdrawal: Some(FeeComponents::::new(24, 0).to_raw()), + ibc_relay: Some(FeeComponents::::new(0, 0).to_raw()), + validator_update: Some(FeeComponents::::new(0, 0).to_raw()), + fee_asset_change: Some(FeeComponents::::new(0, 0).to_raw()), + fee_change: Some(FeeComponents::::new(0, 0).to_raw()), + ibc_relayer_change: Some(FeeComponents::::new(0, 0).to_raw()), + sudo_address_change: Some(FeeComponents::::new(0, 0).to_raw()), + ibc_sudo_change: Some(FeeComponents::::new(0, 0).to_raw()), }), } } diff --git a/crates/astria-core/src/protocol/transaction/v1/action/group/tests.rs b/crates/astria-core/src/protocol/transaction/v1/action/group/tests.rs index 6eb546ab91..b06d16723e 100644 --- a/crates/astria-core/src/protocol/transaction/v1/action/group/tests.rs +++ b/crates/astria-core/src/protocol/transaction/v1/action/group/tests.rs @@ -19,6 +19,7 @@ use crate::{ BridgeUnlock, FeeAssetChange, FeeChange, + FeeComponents, IbcRelayerChange, IbcSudoChange, Ics20Withdrawal, @@ -26,7 +27,6 @@ use crate::{ RollupDataSubmission, SudoAddressChange, Transfer, - TransferFeeComponents, ValidatorUpdate, }, }; @@ -104,10 +104,7 @@ fn from_list_of_actions_bundleable_sudo() { let asset: Denom = "nria".parse().unwrap(); let actions = vec![ - Action::FeeChange(FeeChange::Transfer(TransferFeeComponents { - base: 100, - multiplier: 0, - })), + Action::FeeChange(FeeChange::Transfer(FeeComponents::::new(100, 0))), Action::FeeAssetChange(FeeAssetChange::Addition(asset)), Action::IbcRelayerChange(IbcRelayerChange::Addition(address)), ]; diff --git a/crates/astria-core/src/protocol/transaction/v1/action/mod.rs b/crates/astria-core/src/protocol/transaction/v1/action/mod.rs index 80ba7d2326..5c2b93745b 100644 --- a/crates/astria-core/src/protocol/transaction/v1/action/mod.rs +++ b/crates/astria-core/src/protocol/transaction/v1/action/mod.rs @@ -22,21 +22,8 @@ use crate::{ RollupId, }, protocol::fees::v1::{ - BridgeLockFeeComponents, - BridgeSudoChangeFeeComponents, - BridgeUnlockFeeComponents, - FeeAssetChangeFeeComponents, - FeeChangeFeeComponents, FeeComponentError, - IbcRelayFeeComponents, - IbcRelayerChangeFeeComponents, - IbcSudoChangeFeeComponents, - Ics20WithdrawalFeeComponents, - InitBridgeAccountFeeComponents, - RollupDataSubmissionFeeComponents, - SudoAddressChangeFeeComponents, - TransferFeeComponents, - ValidatorUpdateFeeComponents, + FeeComponents, }, Protobuf, }; @@ -1942,20 +1929,20 @@ enum FeeChangeErrorKind { #[derive(Debug, Clone)] pub enum FeeChange { - Transfer(TransferFeeComponents), - RollupDataSubmission(RollupDataSubmissionFeeComponents), - Ics20Withdrawal(Ics20WithdrawalFeeComponents), - InitBridgeAccount(InitBridgeAccountFeeComponents), - BridgeLock(BridgeLockFeeComponents), - BridgeUnlock(BridgeUnlockFeeComponents), - BridgeSudoChange(BridgeSudoChangeFeeComponents), - IbcRelay(IbcRelayFeeComponents), - ValidatorUpdate(ValidatorUpdateFeeComponents), - FeeAssetChange(FeeAssetChangeFeeComponents), - FeeChange(FeeChangeFeeComponents), - IbcRelayerChange(IbcRelayerChangeFeeComponents), - SudoAddressChange(SudoAddressChangeFeeComponents), - IbcSudoChange(IbcSudoChangeFeeComponents), + Transfer(FeeComponents), + RollupDataSubmission(FeeComponents), + Ics20Withdrawal(FeeComponents), + InitBridgeAccount(FeeComponents), + BridgeLock(FeeComponents), + BridgeUnlock(FeeComponents), + BridgeSudoChange(FeeComponents), + IbcRelay(FeeComponents), + ValidatorUpdate(FeeComponents), + FeeAssetChange(FeeComponents), + FeeChange(FeeComponents), + IbcRelayerChange(FeeComponents), + SudoAddressChange(FeeComponents), + IbcSudoChange(FeeComponents), } impl Protobuf for FeeChange { @@ -2021,54 +2008,148 @@ impl Protobuf for FeeChange { fn try_from_raw_ref(proto: &raw::FeeChange) -> Result { Ok(match &proto.fee_components { Some(raw::fee_change::FeeComponents::Transfer(fee_change)) => { - Self::Transfer(TransferFeeComponents::try_from_raw_ref(fee_change)?) + Self::Transfer(FeeComponents::::try_from_raw_ref(fee_change)?) } Some(raw::fee_change::FeeComponents::RollupDataSubmission(fee_change)) => { - Self::RollupDataSubmission(RollupDataSubmissionFeeComponents::try_from_raw_ref( + Self::RollupDataSubmission(FeeComponents::::try_from_raw_ref( fee_change, )?) } Some(raw::fee_change::FeeComponents::Ics20Withdrawal(fee_change)) => { - Self::Ics20Withdrawal(Ics20WithdrawalFeeComponents::try_from_raw_ref(fee_change)?) + Self::Ics20Withdrawal(FeeComponents::::try_from_raw_ref( + fee_change, + )?) } Some(raw::fee_change::FeeComponents::InitBridgeAccount(fee_change)) => { - Self::InitBridgeAccount(InitBridgeAccountFeeComponents::try_from_raw_ref( + Self::InitBridgeAccount(FeeComponents::::try_from_raw_ref( fee_change, )?) } Some(raw::fee_change::FeeComponents::BridgeLock(fee_change)) => { - Self::BridgeLock(BridgeLockFeeComponents::try_from_raw_ref(fee_change)?) + Self::BridgeLock(FeeComponents::::try_from_raw_ref(fee_change)?) } Some(raw::fee_change::FeeComponents::BridgeUnlock(fee_change)) => { - Self::BridgeUnlock(BridgeUnlockFeeComponents::try_from_raw_ref(fee_change)?) + Self::BridgeUnlock(FeeComponents::::try_from_raw_ref(fee_change)?) } Some(raw::fee_change::FeeComponents::BridgeSudoChange(fee_change)) => { - Self::BridgeSudoChange(BridgeSudoChangeFeeComponents::try_from_raw_ref(fee_change)?) + Self::BridgeSudoChange(FeeComponents::::try_from_raw_ref( + fee_change, + )?) } Some(raw::fee_change::FeeComponents::IbcRelay(fee_change)) => { - Self::IbcRelay(IbcRelayFeeComponents::try_from_raw_ref(fee_change)?) + Self::IbcRelay(FeeComponents::::try_from_raw_ref(fee_change)?) } Some(raw::fee_change::FeeComponents::ValidatorUpdate(fee_change)) => { - Self::ValidatorUpdate(ValidatorUpdateFeeComponents::try_from_raw_ref(fee_change)?) + Self::ValidatorUpdate(FeeComponents::::try_from_raw_ref( + fee_change, + )?) } Some(raw::fee_change::FeeComponents::FeeAssetChange(fee_change)) => { - Self::FeeAssetChange(FeeAssetChangeFeeComponents::try_from_raw_ref(fee_change)?) + Self::FeeAssetChange(FeeComponents::::try_from_raw_ref( + fee_change, + )?) } Some(raw::fee_change::FeeComponents::FeeChange(fee_change)) => { - Self::FeeChange(FeeChangeFeeComponents::try_from_raw_ref(fee_change)?) + Self::FeeChange(FeeComponents::::try_from_raw_ref(fee_change)?) } Some(raw::fee_change::FeeComponents::IbcRelayerChange(fee_change)) => { - Self::IbcRelayerChange(IbcRelayerChangeFeeComponents::try_from_raw_ref(fee_change)?) + Self::IbcRelayerChange(FeeComponents::::try_from_raw_ref( + fee_change, + )?) } Some(raw::fee_change::FeeComponents::SudoAddressChange(fee_change)) => { - Self::SudoAddressChange(SudoAddressChangeFeeComponents::try_from_raw_ref( + Self::SudoAddressChange(FeeComponents::::try_from_raw_ref( fee_change, )?) } - Some(raw::fee_change::FeeComponents::IbcSudoChange(fee_change)) => { - Self::IbcSudoChange(IbcSudoChangeFeeComponents::try_from_raw_ref(fee_change)?) - } + Some(raw::fee_change::FeeComponents::IbcSudoChange(fee_change)) => Self::IbcSudoChange( + FeeComponents::::try_from_raw_ref(fee_change)?, + ), None => return Err(FeeChangeError::field_unset("fee_components")), }) } } + +impl From> for FeeChange { + fn from(fee: FeeComponents) -> Self { + FeeChange::Transfer(fee) + } +} + +impl From> for FeeChange { + fn from(fee: FeeComponents) -> Self { + FeeChange::RollupDataSubmission(fee) + } +} + +impl From> for FeeChange { + fn from(fee: FeeComponents) -> Self { + FeeChange::Ics20Withdrawal(fee) + } +} + +impl From> for FeeChange { + fn from(fee: FeeComponents) -> Self { + FeeChange::InitBridgeAccount(fee) + } +} + +impl From> for FeeChange { + fn from(fee: FeeComponents) -> Self { + FeeChange::BridgeLock(fee) + } +} + +impl From> for FeeChange { + fn from(fee: FeeComponents) -> Self { + FeeChange::BridgeUnlock(fee) + } +} + +impl From> for FeeChange { + fn from(fee: FeeComponents) -> Self { + FeeChange::BridgeSudoChange(fee) + } +} + +impl From> for FeeChange { + fn from(fee: FeeComponents) -> Self { + FeeChange::IbcRelay(fee) + } +} + +impl From> for FeeChange { + fn from(fee: FeeComponents) -> Self { + FeeChange::ValidatorUpdate(fee) + } +} + +impl From> for FeeChange { + fn from(fee: FeeComponents) -> Self { + FeeChange::FeeAssetChange(fee) + } +} + +impl From> for FeeChange { + fn from(fee: FeeComponents) -> Self { + FeeChange::FeeChange(fee) + } +} + +impl From> for FeeChange { + fn from(fee: FeeComponents) -> Self { + FeeChange::IbcRelayerChange(fee) + } +} + +impl From> for FeeChange { + fn from(fee: FeeComponents) -> Self { + FeeChange::SudoAddressChange(fee) + } +} + +impl From> for FeeChange { + fn from(fee: FeeComponents) -> Self { + FeeChange::IbcSudoChange(fee) + } +} diff --git a/crates/astria-sequencer-utils/Cargo.toml b/crates/astria-sequencer-utils/Cargo.toml index 9f0bed5d91..2c2974577f 100644 --- a/crates/astria-sequencer-utils/Cargo.toml +++ b/crates/astria-sequencer-utils/Cargo.toml @@ -21,6 +21,7 @@ ethers-core = "2.0.14" hex = { workspace = true } indenter = "0.3.3" itertools = { workspace = true } +penumbra-ibc = { workspace = true } prost = { workspace = true } rlp = "0.5.2" serde = { workspace = true } diff --git a/crates/astria-sequencer-utils/src/genesis_example.rs b/crates/astria-sequencer-utils/src/genesis_example.rs index 6d7d277719..12a09ca709 100644 --- a/crates/astria-sequencer-utils/src/genesis_example.rs +++ b/crates/astria-sequencer-utils/src/genesis_example.rs @@ -12,26 +12,26 @@ use astria_core::{ }, primitive::v1::Address, protocol::{ - fees::v1::{ - BridgeLockFeeComponents, - BridgeSudoChangeFeeComponents, - BridgeUnlockFeeComponents, - FeeAssetChangeFeeComponents, - FeeChangeFeeComponents, - IbcRelayFeeComponents, - IbcRelayerChangeFeeComponents, - IbcSudoChangeFeeComponents, - Ics20WithdrawalFeeComponents, - InitBridgeAccountFeeComponents, - RollupDataSubmissionFeeComponents, - SudoAddressChangeFeeComponents, - TransferFeeComponents, - ValidatorUpdateFeeComponents, - }, + fees::v1::FeeComponents, genesis::v1::{ Account, GenesisAppState, }, + transaction::v1::action::{ + BridgeLock, + BridgeSudoChange, + BridgeUnlock, + FeeAssetChange, + FeeChange, + IbcRelayerChange, + IbcSudoChange, + Ics20Withdrawal, + InitBridgeAccount, + RollupDataSubmission, + SudoAddressChange, + Transfer, + ValidatorUpdate, + }, }, Protobuf, }; @@ -39,6 +39,7 @@ use astria_eyre::eyre::{ Result, WrapErr as _, }; +use penumbra_ibc::IbcRelay; const ASTRIA_ADDRESS_PREFIX: &str = "astria"; @@ -90,7 +91,6 @@ fn address_prefixes() -> AddressPrefixes { } } -#[expect(clippy::too_many_lines, reason = "all lines reasonably necessary")] fn proto_genesis_state() -> astria_core::generated::astria::protocol::genesis::v1::GenesisAppState { astria_core::generated::astria::protocol::genesis::v1::GenesisAppState { accounts: accounts().into_iter().map(Protobuf::into_raw).collect(), @@ -107,104 +107,22 @@ fn proto_genesis_state() -> astria_core::generated::astria::protocol::genesis::v }), allowed_fee_assets: vec!["nria".parse().unwrap()], fees: Some(GenesisFees { - transfer: Some( - TransferFeeComponents { - base: 12, - multiplier: 0, - } - .to_raw(), - ), + transfer: Some(FeeComponents::::new(12, 0).to_raw()), rollup_data_submission: Some( - RollupDataSubmissionFeeComponents { - base: 32, - multiplier: 1, - } - .to_raw(), - ), - init_bridge_account: Some( - InitBridgeAccountFeeComponents { - base: 48, - multiplier: 0, - } - .to_raw(), - ), - bridge_lock: Some( - BridgeLockFeeComponents { - base: 12, - multiplier: 1, - } - .to_raw(), - ), - bridge_unlock: Some( - BridgeUnlockFeeComponents { - base: 12, - multiplier: 0, - } - .to_raw(), - ), - bridge_sudo_change: Some( - BridgeSudoChangeFeeComponents { - base: 24, - multiplier: 0, - } - .to_raw(), - ), - ics20_withdrawal: Some( - Ics20WithdrawalFeeComponents { - base: 24, - multiplier: 0, - } - .to_raw(), - ), - ibc_relay: Some( - IbcRelayFeeComponents { - base: 0, - multiplier: 0, - } - .to_raw(), - ), - validator_update: Some( - ValidatorUpdateFeeComponents { - base: 0, - multiplier: 0, - } - .to_raw(), - ), - fee_asset_change: Some( - FeeAssetChangeFeeComponents { - base: 0, - multiplier: 0, - } - .to_raw(), - ), - fee_change: Some( - FeeChangeFeeComponents { - base: 0, - multiplier: 0, - } - .to_raw(), - ), - ibc_relayer_change: Some( - IbcRelayerChangeFeeComponents { - base: 0, - multiplier: 0, - } - .to_raw(), - ), - sudo_address_change: Some( - SudoAddressChangeFeeComponents { - base: 0, - multiplier: 0, - } - .to_raw(), - ), - ibc_sudo_change: Some( - IbcSudoChangeFeeComponents { - base: 0, - multiplier: 0, - } - .to_raw(), + FeeComponents::::new(32, 1).to_raw(), ), + init_bridge_account: Some(FeeComponents::::new(48, 0).to_raw()), + bridge_lock: Some(FeeComponents::::new(12, 1).to_raw()), + bridge_unlock: Some(FeeComponents::::new(12, 0).to_raw()), + bridge_sudo_change: Some(FeeComponents::::new(24, 0).to_raw()), + ics20_withdrawal: Some(FeeComponents::::new(24, 0).to_raw()), + ibc_relay: Some(FeeComponents::::new(0, 0).to_raw()), + validator_update: Some(FeeComponents::::new(0, 0).to_raw()), + fee_asset_change: Some(FeeComponents::::new(0, 0).to_raw()), + fee_change: Some(FeeComponents::::new(0, 0).to_raw()), + ibc_relayer_change: Some(FeeComponents::::new(0, 0).to_raw()), + sudo_address_change: Some(FeeComponents::::new(0, 0).to_raw()), + ibc_sudo_change: Some(FeeComponents::::new(0, 0).to_raw()), }), } } diff --git a/crates/astria-sequencer/Cargo.toml b/crates/astria-sequencer/Cargo.toml index 999bd4c547..a2b8ee67b7 100644 --- a/crates/astria-sequencer/Cargo.toml +++ b/crates/astria-sequencer/Cargo.toml @@ -77,7 +77,6 @@ config = { package = "astria-config", path = "../astria-config", features = [ "tests", ] } insta = { workspace = true, features = ["json"] } -paste = "1.0.15" maplit = "1.0.2" rand_chacha = "0.3.1" tokio = { workspace = true, features = ["test-util"] } diff --git a/crates/astria-sequencer/src/action_handler/impls/bridge_sudo_change.rs b/crates/astria-sequencer/src/action_handler/impls/bridge_sudo_change.rs index 6bdb3ee4f4..a69775cf5f 100644 --- a/crates/astria-sequencer/src/action_handler/impls/bridge_sudo_change.rs +++ b/crates/astria-sequencer/src/action_handler/impls/bridge_sudo_change.rs @@ -83,7 +83,7 @@ mod tests { use astria_core::{ primitive::v1::TransactionId, protocol::{ - fees::v1::BridgeSudoChangeFeeComponents, + fees::v1::FeeComponents, transaction::v1::action::BridgeSudoChange, }, }; @@ -164,10 +164,7 @@ mod tests { }); state.put_base_prefix(ASTRIA_PREFIX.to_string()).unwrap(); state - .put_bridge_sudo_change_fees(BridgeSudoChangeFeeComponents { - base: 10, - multiplier: 0, - }) + .put_fees(FeeComponents::::new(10, 0)) .unwrap(); let fee_asset = test_asset(); diff --git a/crates/astria-sequencer/src/action_handler/impls/bridge_unlock.rs b/crates/astria-sequencer/src/action_handler/impls/bridge_unlock.rs index 10da98c5a4..d2362a5742 100644 --- a/crates/astria-sequencer/src/action_handler/impls/bridge_unlock.rs +++ b/crates/astria-sequencer/src/action_handler/impls/bridge_unlock.rs @@ -109,7 +109,7 @@ mod tests { TransactionId, }, protocol::{ - fees::v1::BridgeUnlockFeeComponents, + fees::v1::FeeComponents, transaction::v1::action::BridgeUnlock, }, }; @@ -235,10 +235,7 @@ mod tests { let transfer_fee = 10; let transfer_amount = 100; state - .put_bridge_unlock_fees(BridgeUnlockFeeComponents { - base: transfer_fee, - multiplier: 0, - }) + .put_fees(FeeComponents::::new(transfer_fee, 0)) .unwrap(); let to_address = astria_address(&[2; 20]); diff --git a/crates/astria-sequencer/src/action_handler/impls/fee_change.rs b/crates/astria-sequencer/src/action_handler/impls/fee_change.rs index d83cf2ed61..f066ded9ea 100644 --- a/crates/astria-sequencer/src/action_handler/impls/fee_change.rs +++ b/crates/astria-sequencer/src/action_handler/impls/fee_change.rs @@ -36,46 +36,46 @@ impl ActionHandler for FeeChange { match self { Self::Transfer(fees) => state - .put_transfer_fees(*fees) + .put_fees(*fees) .wrap_err("failed to put transfer fees"), Self::RollupDataSubmission(fees) => state - .put_rollup_data_submission_fees(*fees) + .put_fees(*fees) .wrap_err("failed to put sequence fees"), Self::Ics20Withdrawal(fees) => state - .put_ics20_withdrawal_fees(*fees) + .put_fees(*fees) .wrap_err("failed to put ics20 withdrawal fees"), Self::InitBridgeAccount(fees) => state - .put_init_bridge_account_fees(*fees) + .put_fees(*fees) .wrap_err("failed to put init bridge account fees"), Self::BridgeLock(fees) => state - .put_bridge_lock_fees(*fees) + .put_fees(*fees) .wrap_err("failed to put bridge lock fees"), Self::BridgeUnlock(fees) => state - .put_bridge_unlock_fees(*fees) + .put_fees(*fees) .wrap_err("failed to put bridge unlock fees"), Self::BridgeSudoChange(fees) => state - .put_bridge_sudo_change_fees(*fees) + .put_fees(*fees) .wrap_err("failed to put bridge sudo change fees"), Self::IbcRelay(fees) => state - .put_ibc_relay_fees(*fees) + .put_fees(*fees) .wrap_err("failed to put ibc relay fees"), Self::ValidatorUpdate(fees) => state - .put_validator_update_fees(*fees) + .put_fees(*fees) .wrap_err("failed to put validator update fees"), Self::FeeAssetChange(fees) => state - .put_fee_asset_change_fees(*fees) + .put_fees(*fees) .wrap_err("failed to put fee asset change fees"), Self::FeeChange(fees) => state - .put_fee_change_fees(*fees) + .put_fees(*fees) .wrap_err("failed to put fee change fees"), Self::IbcRelayerChange(fees) => state - .put_ibc_relayer_change_fees(*fees) + .put_fees(*fees) .wrap_err("failed to put ibc relayer change fees"), Self::SudoAddressChange(fees) => state - .put_sudo_address_change_fees(*fees) + .put_fees(*fees) .wrap_err("failed to put sudo address change fees"), Self::IbcSudoChange(fees) => state - .put_ibc_sudo_change_fees(*fees) + .put_fees(*fees) .wrap_err("failed to put ibc sudo change fees"), } } @@ -83,100 +83,154 @@ impl ActionHandler for FeeChange { #[cfg(test)] mod tests { + use std::fmt::Debug; + use astria_core::{ primitive::v1::TransactionId, - protocol::transaction::v1::action::FeeChange, + protocol::{ + fees::v1::*, + transaction::v1::action::*, + }, }; + use astria_eyre::eyre::Report; + use penumbra_ibc::IbcRelay; use crate::{ action_handler::ActionHandler as _, authority::StateWriteExt as _, - fees::StateReadExt as _, + fees::{ + FeeHandler, + StateReadExt as _, + }, + storage::StoredValue, transaction::{ StateWriteExt as _, TransactionContext, }, }; - /// This macro generates a test named e.g. `transfer_fee_change_action_executes` which asserts - /// that executing a `FeeChange` tx for the given action results in the fees being stored for - /// the given action. - macro_rules! test_fee_change_action { - ( $( $fee_name:tt => $fee_ty:tt ),* $(,)?) => { - $( - paste::item! { - #[tokio::test] - async fn [< $fee_name _fee_change_action_executes >] () { - use astria_core::protocol::fees::v1:: [< $fee_ty FeeComponents >] as Fees; - - let storage = cnidarium::TempStorage::new().await.unwrap(); - let snapshot = storage.latest_snapshot(); - let mut state = cnidarium::StateDelta::new(snapshot); - - // Put the context to enable the txs to execute. - state.put_transaction_context(TransactionContext { - address_bytes: [1; 20], - transaction_id: TransactionId::new([0; 32]), - position_in_transaction: 0, - }); - state.put_sudo_address([1; 20]).unwrap(); - - assert!(state - .[< get_ $fee_name _fees >] () - .await - .expect(stringify!(should not error fetching unstored $fee_name fees)) - .is_none()); - - // Execute an initial fee change tx to store the first version of the fees. - let initial_fees = Fees { - base: 1, - multiplier: 2, - }; - let fee_change = FeeChange:: $fee_ty (initial_fees); - fee_change.check_and_execute(&mut state).await.unwrap(); - - let retrieved_fees = state - .[< get_ $fee_name _fees >] () - .await - .expect(stringify!(should not error fetching initial $fee_name fees)) - .expect(stringify!(initial $fee_name fees should be stored)); - assert_eq!(initial_fees, retrieved_fees); - - // Execute a second fee change tx to overwrite the fees. - let new_fees = Fees { - base: 3, - multiplier: 4, - }; - let fee_change = FeeChange:: $fee_ty (new_fees); - fee_change.check_and_execute(&mut state).await.unwrap(); - - let retrieved_fees = state - .[< get_ $fee_name _fees >] () - .await - .expect(stringify!(should not error fetching new $fee_name fees)) - .expect(stringify!(new $fee_name fees should be stored)); - assert_ne!(initial_fees, retrieved_fees); - assert_eq!(new_fees, retrieved_fees); - } - } - )* - }; - } - - test_fee_change_action!( - transfer => Transfer, - rollup_data_submission => RollupDataSubmission, - ics20_withdrawal => Ics20Withdrawal, - init_bridge_account => InitBridgeAccount, - bridge_lock => BridgeLock, - bridge_unlock => BridgeUnlock, - bridge_sudo_change => BridgeSudoChange, - validator_update => ValidatorUpdate, - ibc_relayer_change => IbcRelayerChange, - ibc_relay => IbcRelay, - fee_asset_change => FeeAssetChange, - fee_change => FeeChange, - sudo_address_change => SudoAddressChange, - ibc_sudo_change => IbcSudoChange, - ); + #[tokio::test] + async fn transfer_fee_change_action_executes_as_expected() { + test_fee_change_action::().await; + } + + #[tokio::test] + async fn rollup_data_submission_fee_change_action_executes_as_expected() { + test_fee_change_action::().await; + } + + #[tokio::test] + async fn ics20_withdrawal_fee_change_action_executes_as_expected() { + test_fee_change_action::().await; + } + + #[tokio::test] + async fn init_bridge_account_fee_change_action_executes_as_expected() { + test_fee_change_action::().await; + } + + #[tokio::test] + async fn bridge_lock_fee_change_action_executes_as_expected() { + test_fee_change_action::().await; + } + + #[tokio::test] + async fn bridge_unlock_fee_change_action_executes_as_expected() { + test_fee_change_action::().await; + } + + #[tokio::test] + async fn bridge_sudo_change_fee_change_action_executes_as_expected() { + test_fee_change_action::().await; + } + + #[tokio::test] + async fn validator_update_fee_change_action_executes_as_expected() { + test_fee_change_action::().await; + } + + #[tokio::test] + async fn ibc_relay_fee_change_action_executes_as_expected() { + test_fee_change_action::().await; + } + + #[tokio::test] + async fn ibc_relayer_change_fee_change_action_executes_as_expected() { + test_fee_change_action::().await; + } + + #[tokio::test] + async fn fee_asset_change_fee_change_action_executes_as_expected() { + test_fee_change_action::().await; + } + + #[tokio::test] + async fn fee_change_fee_change_action_executes_as_expected() { + test_fee_change_action::().await; + } + + #[tokio::test] + async fn sudo_address_change_fee_change_action_executes_as_expected() { + test_fee_change_action::().await; + } + + #[tokio::test] + async fn ibc_sudo_change_fee_change_action_executes_as_expected() { + test_fee_change_action::().await; + } + + async fn test_fee_change_action<'a, F>() + where + F: FeeHandler, + FeeComponents: TryFrom, Error = Report> + Debug, + FeeChange: From>, + { + let storage = cnidarium::TempStorage::new().await.unwrap(); + let snapshot = storage.latest_snapshot(); + let mut state = cnidarium::StateDelta::new(snapshot); + + // Put the context to enable the txs to execute. + state.put_transaction_context(TransactionContext { + address_bytes: [1; 20], + transaction_id: TransactionId::new([0; 32]), + position_in_transaction: 0, + }); + state.put_sudo_address([1; 20]).unwrap(); + + assert!( + state + .get_fees::() + .await + .expect("should not error fetching unstored action fees") + .is_none() + ); + + // Execute an initial fee change tx to store the first version of the fees. + let initial_fees = FeeComponents::::new(1, 2); + let initial_fee_change = FeeChange::from(initial_fees); + initial_fee_change + .check_and_execute(&mut state) + .await + .unwrap(); + + let retrieved_fees = state + .get_fees::() + .await + .expect("should not error fetching initial action fees") + .expect("initial action fees should be stored"); + assert_eq!(initial_fees, retrieved_fees); + + // Execute a second fee change tx to overwrite the fees. + let new_fees = FeeComponents::::new(3, 4); + let new_fee_change = FeeChange::from(new_fees); + new_fee_change.check_and_execute(&mut state).await.unwrap(); + + let retrieved_fees = state + .get_fees::() + .await + .expect("should not error fetching new action fees") + .expect("new action fees should be stored"); + assert_ne!(initial_fees, retrieved_fees); + assert_eq!(new_fees, retrieved_fees); + } } diff --git a/crates/astria-sequencer/src/action_handler/impls/transaction.rs b/crates/astria-sequencer/src/action_handler/impls/transaction.rs index 29df7cc10a..a5b66bf4fd 100644 --- a/crates/astria-sequencer/src/action_handler/impls/transaction.rs +++ b/crates/astria-sequencer/src/action_handler/impls/transaction.rs @@ -1,8 +1,11 @@ use std::fmt; -use astria_core::protocol::transaction::v1::{ - Action, - Transaction, +use astria_core::protocol::{ + fees::v1::FeeComponents, + transaction::v1::{ + Action, + Transaction, + }, }; use astria_eyre::{ anyhow_to_eyre, @@ -10,6 +13,7 @@ use astria_eyre::{ ensure, Context as _, OptionExt as _, + Report, Result, }, }; @@ -31,6 +35,7 @@ use crate::{ host_interface::AstriaHost, StateReadExt as _, }, + storage::StoredValue, transaction::{ check_balance_for_total_fees_and_transfers, StateWriteExt as _, @@ -271,10 +276,12 @@ impl ActionHandler for Transaction { } } -async fn check_execute_and_pay_fees( - action: &T, - mut state: S, -) -> Result<()> { +async fn check_execute_and_pay_fees<'a, T, S>(action: &T, mut state: S) -> Result<()> +where + T: ActionHandler + FeeHandler + Sync, + FeeComponents: TryFrom, Error = Report>, + S: StateWrite, +{ action.check_and_execute(&mut state).await?; action.check_and_pay_fees(&mut state).await?; Ok(()) diff --git a/crates/astria-sequencer/src/app/benchmark_and_test_utils.rs b/crates/astria-sequencer/src/app/benchmark_and_test_utils.rs index e2852fd225..7171bce58d 100644 --- a/crates/astria-sequencer/src/app/benchmark_and_test_utils.rs +++ b/crates/astria-sequencer/src/app/benchmark_and_test_utils.rs @@ -6,28 +6,27 @@ use astria_core::{ IbcPrefixed, }, protocol::{ - fees::v1::{ - BridgeLockFeeComponents, - BridgeSudoChangeFeeComponents, - BridgeUnlockFeeComponents, - FeeAssetChangeFeeComponents, - FeeChangeFeeComponents, - IbcRelayFeeComponents, - IbcRelayerChangeFeeComponents, - IbcSudoChangeFeeComponents, - Ics20WithdrawalFeeComponents, - InitBridgeAccountFeeComponents, - RollupDataSubmissionFeeComponents, - SudoAddressChangeFeeComponents, - TransferFeeComponents, - ValidatorUpdateFeeComponents, - }, + fees::v1::FeeComponents, genesis::v1::{ Account, AddressPrefixes, GenesisAppState, }, - transaction::v1::action::ValidatorUpdate, + transaction::v1::action::{ + BridgeLock, + BridgeSudoChange, + BridgeUnlock, + FeeAssetChange, + FeeChange, + IbcRelayerChange, + IbcSudoChange, + Ics20Withdrawal, + InitBridgeAccount, + RollupDataSubmission, + SudoAddressChange, + Transfer, + ValidatorUpdate, + }, }, Protobuf, }; @@ -37,6 +36,7 @@ use cnidarium::{ StateDelta, Storage, }; +use penumbra_ibc::IbcRelay; use telemetry::Metrics as _; use crate::{ @@ -70,62 +70,22 @@ pub(crate) fn address_prefixes() -> AddressPrefixes { pub(crate) fn default_fees() -> astria_core::protocol::genesis::v1::GenesisFees { astria_core::protocol::genesis::v1::GenesisFees { - transfer: Some(TransferFeeComponents { - base: 12, - multiplier: 0, - }), - rollup_data_submission: Some(RollupDataSubmissionFeeComponents { - base: 32, - multiplier: 1, - }), - init_bridge_account: Some(InitBridgeAccountFeeComponents { - base: 48, - multiplier: 0, - }), - bridge_lock: Some(BridgeLockFeeComponents { - base: 12, // should reflect transfer fee - multiplier: 1, - }), - bridge_sudo_change: Some(BridgeSudoChangeFeeComponents { - base: 24, - multiplier: 0, - }), - ics20_withdrawal: Some(Ics20WithdrawalFeeComponents { - base: 24, - multiplier: 0, - }), - bridge_unlock: Some(BridgeUnlockFeeComponents { - base: 12, // should reflect transfer fee - multiplier: 0, - }), - ibc_relay: Some(IbcRelayFeeComponents { - base: 0, - multiplier: 0, - }), - validator_update: Some(ValidatorUpdateFeeComponents { - base: 0, - multiplier: 0, - }), - fee_asset_change: Some(FeeAssetChangeFeeComponents { - base: 0, - multiplier: 0, - }), - fee_change: FeeChangeFeeComponents { - base: 0, - multiplier: 0, - }, - ibc_relayer_change: Some(IbcRelayerChangeFeeComponents { - base: 0, - multiplier: 0, - }), - sudo_address_change: Some(SudoAddressChangeFeeComponents { - base: 0, - multiplier: 0, - }), - ibc_sudo_change: Some(IbcSudoChangeFeeComponents { - base: 0, - multiplier: 0, - }), + transfer: Some(FeeComponents::::new(12, 0)), + rollup_data_submission: Some(FeeComponents::::new(32, 1)), + init_bridge_account: Some(FeeComponents::::new(48, 0)), + // should reflect transfer fee + bridge_lock: Some(FeeComponents::::new(12, 1)), + bridge_sudo_change: Some(FeeComponents::::new(24, 0)), + ics20_withdrawal: Some(FeeComponents::::new(24, 0)), + // should reflect transfer fee + bridge_unlock: Some(FeeComponents::::new(12, 0)), + ibc_relay: Some(FeeComponents::::new(0, 0)), + validator_update: Some(FeeComponents::::new(0, 0)), + fee_asset_change: Some(FeeComponents::::new(0, 0)), + fee_change: FeeComponents::::new(0, 0), + ibc_relayer_change: Some(FeeComponents::::new(0, 0)), + sudo_address_change: Some(FeeComponents::::new(0, 0)), + ibc_sudo_change: Some(FeeComponents::::new(0, 0)), } } @@ -287,10 +247,6 @@ pub(crate) fn mock_state_put_account_nonce( state.put_account_nonce(address, nonce).unwrap(); } -#[expect( - clippy::too_many_lines, - reason = "lines come from necessary fees setup" -)] pub(crate) async fn mock_state_getter() -> StateDelta { let storage = cnidarium::TempStorage::new().await.unwrap(); let snapshot = storage.latest_snapshot(); @@ -320,130 +276,88 @@ pub(crate) async fn mock_state_getter() -> StateDelta { .unwrap(); // setup tx fees - // setup tx fees - let transfer_fees = TransferFeeComponents { - base: 0, - multiplier: 0, - }; + let transfer_fees = FeeComponents::::new(0, 0); state - .put_transfer_fees(transfer_fees) + .put_fees(transfer_fees) .wrap_err("failed to initiate transfer fee components") .unwrap(); - let rollup_data_submission_fees = RollupDataSubmissionFeeComponents { - base: MOCK_SEQUENCE_FEE, - multiplier: 0, - }; + let rollup_data_submission_fees = + FeeComponents::::new(MOCK_SEQUENCE_FEE, 0); state - .put_rollup_data_submission_fees(rollup_data_submission_fees) - .wrap_err("failed to initiate sequence action fee components") + .put_fees(rollup_data_submission_fees) + .wrap_err("failed to initiate rollup data submission fee components") .unwrap(); - let ics20_withdrawal_fees = Ics20WithdrawalFeeComponents { - base: 0, - multiplier: 0, - }; + let ics20_withdrawal_fees = FeeComponents::::new(0, 0); state - .put_ics20_withdrawal_fees(ics20_withdrawal_fees) + .put_fees(ics20_withdrawal_fees) .wrap_err("failed to initiate ics20 withdrawal fee components") .unwrap(); - let init_bridge_account_fees = InitBridgeAccountFeeComponents { - base: 0, - multiplier: 0, - }; + let init_bridge_account_fees = FeeComponents::::new(0, 0); state - .put_init_bridge_account_fees(init_bridge_account_fees) + .put_fees(init_bridge_account_fees) .wrap_err("failed to initiate init bridge account fee components") .unwrap(); - let bridge_lock_fees = BridgeLockFeeComponents { - base: 0, - multiplier: 0, - }; + let bridge_lock_fees = FeeComponents::::new(0, 0); state - .put_bridge_lock_fees(bridge_lock_fees) + .put_fees(bridge_lock_fees) .wrap_err("failed to initiate bridge lock fee components") .unwrap(); - let bridge_unlock_fees = BridgeUnlockFeeComponents { - base: 0, - multiplier: 0, - }; + let bridge_unlock_fees = FeeComponents::::new(0, 0); state - .put_bridge_unlock_fees(bridge_unlock_fees) + .put_fees(bridge_unlock_fees) .wrap_err("failed to initiate bridge unlock fee components") .unwrap(); - let bridge_sudo_change_fees = BridgeSudoChangeFeeComponents { - base: 0, - multiplier: 0, - }; + let bridge_sudo_change_fees = FeeComponents::::new(0, 0); state - .put_bridge_sudo_change_fees(bridge_sudo_change_fees) + .put_fees(bridge_sudo_change_fees) .wrap_err("failed to initiate bridge sudo change fee components") .unwrap(); - let ibc_relay_fees = IbcRelayFeeComponents { - base: 0, - multiplier: 0, - }; + let ibc_relay_fees = FeeComponents::::new(0, 0); state - .put_ibc_relay_fees(ibc_relay_fees) + .put_fees(ibc_relay_fees) .wrap_err("failed to initiate ibc relay fee components") .unwrap(); - let validator_update_fees = ValidatorUpdateFeeComponents { - base: 0, - multiplier: 0, - }; + let validator_update_fees = FeeComponents::::new(0, 0); state - .put_validator_update_fees(validator_update_fees) + .put_fees(validator_update_fees) .wrap_err("failed to initiate validator update fee components") .unwrap(); - let fee_asset_change_fees = FeeAssetChangeFeeComponents { - base: 0, - multiplier: 0, - }; + let fee_asset_change_fees = FeeComponents::::new(0, 0); state - .put_fee_asset_change_fees(fee_asset_change_fees) + .put_fees(fee_asset_change_fees) .wrap_err("failed to initiate fee asset change fee components") .unwrap(); - let fee_change_fees = FeeChangeFeeComponents { - base: 0, - multiplier: 0, - }; + let fee_change_fees = FeeComponents::::new(0, 0); state - .put_fee_change_fees(fee_change_fees) + .put_fees(fee_change_fees) .wrap_err("failed to initiate fee change fees fee components") .unwrap(); - let ibc_relayer_change_fees = IbcRelayerChangeFeeComponents { - base: 0, - multiplier: 0, - }; + let ibc_relayer_change_fees = FeeComponents::::new(0, 0); state - .put_ibc_relayer_change_fees(ibc_relayer_change_fees) + .put_fees(ibc_relayer_change_fees) .wrap_err("failed to initiate ibc relayer change fee components") .unwrap(); - let sudo_address_change_fees = SudoAddressChangeFeeComponents { - base: 0, - multiplier: 0, - }; + let sudo_address_change_fees = FeeComponents::::new(0, 0); state - .put_sudo_address_change_fees(sudo_address_change_fees) + .put_fees(sudo_address_change_fees) .wrap_err("failed to initiate sudo address change fee components") .unwrap(); - let ibc_sudo_change_fees = IbcSudoChangeFeeComponents { - base: 0, - multiplier: 0, - }; + let ibc_sudo_change_fees = FeeComponents::::new(0, 0); state - .put_ibc_sudo_change_fees(ibc_sudo_change_fees) + .put_fees(ibc_sudo_change_fees) .wrap_err("failed to initiate ibc sudo change fee components") .unwrap(); diff --git a/crates/astria-sequencer/src/app/tests_app/mempool.rs b/crates/astria-sequencer/src/app/tests_app/mempool.rs index adc304d585..4a30b4460b 100644 --- a/crates/astria-sequencer/src/app/tests_app/mempool.rs +++ b/crates/astria-sequencer/src/app/tests_app/mempool.rs @@ -2,7 +2,7 @@ use std::collections::HashMap; use astria_core::{ protocol::{ - fees::v1::TransferFeeComponents, + fees::v1::FeeComponents, genesis::v1::Account, transaction::v1::{ action::{ @@ -55,11 +55,7 @@ async fn trigger_cleaning() { // create tx which will cause mempool cleaning flag to be set let tx_trigger = TransactionBody::builder() .actions(vec![ - FeeChange::Transfer(TransferFeeComponents { - base: 10, - multiplier: 0, - }) - .into(), + FeeChange::Transfer(FeeComponents::::new(10, 0)).into(), ]) .chain_id("test") .try_build() @@ -151,11 +147,7 @@ async fn do_not_trigger_cleaning() { // (wrong sudo signer) let tx_fail = TransactionBody::builder() .actions(vec![ - FeeChange::Transfer(TransferFeeComponents { - base: 10, - multiplier: 0, - }) - .into(), + FeeChange::Transfer(FeeComponents::::new(10, 0)).into(), ]) .chain_id("test") .try_build() @@ -252,11 +244,7 @@ async fn maintenance_recosting_promotes() { // create tx which will enable recost tx to pass let tx_recost = TransactionBody::builder() .actions(vec![ - FeeChange::Transfer(TransferFeeComponents { - base: 10, - multiplier: 0, - }) - .into(), + FeeChange::Transfer(FeeComponents::::new(10, 0)).into(), ]) .chain_id("test") .try_build() diff --git a/crates/astria-sequencer/src/app/tests_app/mod.rs b/crates/astria-sequencer/src/app/tests_app/mod.rs index b91e107105..c0cd55b1ca 100644 --- a/crates/astria-sequencer/src/app/tests_app/mod.rs +++ b/crates/astria-sequencer/src/app/tests_app/mod.rs @@ -284,11 +284,11 @@ async fn app_transfer_block_fees_to_sudo() { // assert that transaction fees were transferred to the block proposer let transfer_base_fee = app .state - .get_transfer_fees() + .get_fees::() .await .expect("should not error fetching transfer fees") .expect("transfer fees should be stored") - .base; + .base(); assert_eq!( app.state .get_account_balance(&astria_address_from_hex_string(JUDY_ADDRESS), &nria()) diff --git a/crates/astria-sequencer/src/app/tests_execute_transaction.rs b/crates/astria-sequencer/src/app/tests_execute_transaction.rs index 011d789270..7f5d778e36 100644 --- a/crates/astria-sequencer/src/app/tests_execute_transaction.rs +++ b/crates/astria-sequencer/src/app/tests_execute_transaction.rs @@ -8,10 +8,7 @@ use astria_core::{ RollupId, }, protocol::{ - fees::v1::{ - InitBridgeAccountFeeComponents, - RollupDataSubmissionFeeComponents, - }, + fees::v1::FeeComponents, genesis::v1::GenesisAppState, transaction::v1::{ action::{ @@ -141,11 +138,11 @@ async fn app_execute_transaction_transfer() { ); let transfer_base = app .state - .get_transfer_fees() + .get_fees::() .await .expect("should not error fetching transfer fees") .expect("transfer fees should be stored") - .base; + .base(); assert_eq!( app.state .get_account_balance(&alice_address, &nria()) @@ -213,11 +210,11 @@ async fn app_execute_transaction_transfer_not_native_token() { let transfer_base = app .state - .get_transfer_fees() + .get_fees::() .await .expect("should not error fetching transfer fees") .expect("transfer fees should be stored") - .base; + .base(); assert_eq!( app.state .get_account_balance(&alice_address, &nria()) @@ -280,10 +277,7 @@ async fn app_execute_transaction_sequence() { let mut app = initialize_app(None, vec![]).await; let mut state_tx = StateDelta::new(app.state.clone()); state_tx - .put_rollup_data_submission_fees(RollupDataSubmissionFeeComponents { - base: 0, - multiplier: 1, - }) + .put_fees(FeeComponents::::new(0, 1)) .unwrap(); app.apply(state_tx); @@ -618,10 +612,7 @@ async fn app_execute_transaction_init_bridge_account_ok() { let mut state_tx = StateDelta::new(app.state.clone()); let fee = 12; // arbitrary state_tx - .put_init_bridge_account_fees(InitBridgeAccountFeeComponents { - base: fee, - multiplier: 0, - }) + .put_fees(FeeComponents::::new(fee, 0)) .unwrap(); app.apply(state_tx); @@ -1014,11 +1005,11 @@ async fn app_execute_transaction_bridge_lock_unlock_action_ok() { // unlock transfer action let transfer_base = app .state - .get_transfer_fees() + .get_fees::() .await .expect("should not error fetching transfer fees") .expect("transfer fees should be stored") - .base; + .base(); state_tx .put_account_balance(&bridge_address, &nria(), transfer_base) .unwrap(); diff --git a/crates/astria-sequencer/src/fees/component.rs b/crates/astria-sequencer/src/fees/component.rs index 03ed7cb36c..e22e4480d7 100644 --- a/crates/astria-sequencer/src/fees/component.rs +++ b/crates/astria-sequencer/src/fees/component.rs @@ -37,96 +37,96 @@ impl Component for FeesComponent { let transfer_fees = app_state.fees().transfer; if let Some(transfer_fees) = transfer_fees { state - .put_transfer_fees(transfer_fees) + .put_fees(transfer_fees) .wrap_err("failed to store transfer fee components")?; } let rollup_data_submission_fees = app_state.fees().rollup_data_submission; if let Some(rollup_data_submission_fees) = rollup_data_submission_fees { state - .put_rollup_data_submission_fees(rollup_data_submission_fees) + .put_fees(rollup_data_submission_fees) .wrap_err("failed to store rollup data submission fee components")?; } let ics20_withdrawal_fees = app_state.fees().ics20_withdrawal; if let Some(ics20_withdrawal_fees) = ics20_withdrawal_fees { state - .put_ics20_withdrawal_fees(ics20_withdrawal_fees) + .put_fees(ics20_withdrawal_fees) .wrap_err("failed to store ics20 withdrawal fee components")?; } let init_bridge_account_fees = app_state.fees().init_bridge_account; if let Some(init_bridge_account_fees) = init_bridge_account_fees { state - .put_init_bridge_account_fees(init_bridge_account_fees) + .put_fees(init_bridge_account_fees) .wrap_err("failed to store init bridge account fee components")?; } let bridge_lock_fees = app_state.fees().bridge_lock; if let Some(bridge_lock_fees) = bridge_lock_fees { state - .put_bridge_lock_fees(bridge_lock_fees) + .put_fees(bridge_lock_fees) .wrap_err("failed to store bridge lock fee components")?; } let bridge_unlock_fees = app_state.fees().bridge_unlock; if let Some(bridge_unlock_fees) = bridge_unlock_fees { state - .put_bridge_unlock_fees(bridge_unlock_fees) + .put_fees(bridge_unlock_fees) .wrap_err("failed to store bridge unlock fee components")?; } let bridge_sudo_change_fees = app_state.fees().bridge_sudo_change; if let Some(bridge_sudo_change_fees) = bridge_sudo_change_fees { state - .put_bridge_sudo_change_fees(bridge_sudo_change_fees) + .put_fees(bridge_sudo_change_fees) .wrap_err("failed to store bridge sudo change fee components")?; } let ibc_relay_fees = app_state.fees().ibc_relay; if let Some(ibc_relay_fees) = ibc_relay_fees { state - .put_ibc_relay_fees(ibc_relay_fees) + .put_fees(ibc_relay_fees) .wrap_err("failed to store ibc relay fee components")?; } let validator_update_fees = app_state.fees().validator_update; if let Some(validator_update_fees) = validator_update_fees { state - .put_validator_update_fees(validator_update_fees) + .put_fees(validator_update_fees) .wrap_err("failed to store validator update fee components")?; } let fee_asset_change_fees = app_state.fees().fee_asset_change; if let Some(fee_asset_change_fees) = fee_asset_change_fees { state - .put_fee_asset_change_fees(fee_asset_change_fees) + .put_fees(fee_asset_change_fees) .wrap_err("failed to store fee asset change fee components")?; } let fee_change_fees = app_state.fees().fee_change; state - .put_fee_change_fees(fee_change_fees) + .put_fees(fee_change_fees) .wrap_err("failed to store fee change fee components")?; let ibc_relayer_change_fees = app_state.fees().ibc_relayer_change; if let Some(ibc_relayer_change_fees) = ibc_relayer_change_fees { state - .put_ibc_relayer_change_fees(ibc_relayer_change_fees) + .put_fees(ibc_relayer_change_fees) .wrap_err("failed to store ibc relayer change fee components")?; } let sudo_address_change_fees = app_state.fees().sudo_address_change; if let Some(sudo_address_change_fees) = sudo_address_change_fees { state - .put_sudo_address_change_fees(sudo_address_change_fees) + .put_fees(sudo_address_change_fees) .wrap_err("failed to store sudo address change fee components")?; } let ibc_sudo_change_fees = app_state.fees().ibc_sudo_change; if let Some(ibc_sudo_change_fees) = ibc_sudo_change_fees { state - .put_ibc_sudo_change_fees(ibc_sudo_change_fees) + .put_fees(ibc_sudo_change_fees) .wrap_err("failed to store ibc sudo change fee components")?; } diff --git a/crates/astria-sequencer/src/fees/mod.rs b/crates/astria-sequencer/src/fees/mod.rs index 9536888e65..ba6557d522 100644 --- a/crates/astria-sequencer/src/fees/mod.rs +++ b/crates/astria-sequencer/src/fees/mod.rs @@ -1,8 +1,8 @@ use astria_core::{ primitive::v1::asset, - protocol::transaction::{ - self, - v1::action::{ + protocol::{ + fees::v1::FeeComponents, + transaction::v1::action::{ BridgeLock, BridgeSudoChange, BridgeUnlock, @@ -10,6 +10,7 @@ use astria_core::{ FeeChange, IbcRelayerChange, IbcSudoChange, + Ics20Withdrawal, InitBridgeAccount, RollupDataSubmission, SudoAddressChange, @@ -22,11 +23,13 @@ use astria_core::{ use astria_eyre::eyre::{ self, ensure, - OptionExt as _, + eyre, + Report, WrapErr as _, }; use cnidarium::StateWrite; use penumbra_ibc::IbcRelay; +use prost::Name; use tracing::{ instrument, Level, @@ -50,17 +53,12 @@ pub(crate) use state_ext::{ StateWriteExt, }; +use crate::storage::StoredValue; + /// The base byte length of a deposit, as determined by /// [`tests::get_base_deposit_fee()`]. const DEPOSIT_BASE_FEE: u128 = 16; -#[async_trait::async_trait] -pub(crate) trait FeeHandler { - async fn check_and_pay_fees(&self, state: S) -> eyre::Result<()>; - - fn variable_component(&self) -> u128; -} - #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub(crate) struct Fee { action_name: String, @@ -80,279 +78,384 @@ impl Fee { } #[async_trait::async_trait] -impl FeeHandler for Transfer { - #[instrument(skip_all, err)] - async fn check_and_pay_fees(&self, state: S) -> eyre::Result<()> { +pub(crate) trait FeeHandler: Send { + /// The Pascal-case type name, e.g. `RollupDataSubmission`. + // NOTE: We only require this function due to `IbcRelay` not implementing `Protobuf`. + fn name() -> &'static str; + + /// The full name including the protobuf package, e.g. + /// `astria.protocol.transaction.v1.RollupDataSubmission`. + // NOTE: We only require this function due to `IbcRelay` not implementing `Protobuf`. + fn full_name() -> String; + + /// The snake-case type name, e.g. `rollup_data_submission`. + fn snake_case_name() -> &'static str; + + /// The variable value derived from `self` which is multiplied by the `multiplier` of the + /// `FeeComponents` for this action to produce the variable portion of the total fees for this + /// action. + /// + /// Many actions have fixed fees, meaning this method returns `0`. + fn variable_component(&self) -> u128; + + /// The asset to be used to pay the fees. + /// + /// If this method returns `None`, the action is free. + fn fee_asset(&self) -> Option<&asset::Denom>; + + #[instrument(skip_all, err(level = Level::WARN))] + async fn check_and_pay_fees<'a, S>(&self, mut state: S) -> eyre::Result<()> + where + S: StateWrite, + FeeComponents: TryFrom, Error = Report>, + { let fees = state - .get_transfer_fees() + .get_fees::() .await - .wrap_err("error fetching transfer fees")? - .ok_or_eyre("transfer fees not found, so this action is disabled")?; - check_and_pay_fees(self, fees.base, fees.multiplier, state, &self.fee_asset).await + .wrap_err_with(|| format!("error fetching {} fees", Self::name()))? + .ok_or_else(|| { + eyre!( + "{} fees not found, so this action is disabled", + Self::name() + ) + })?; + let Some(fee_asset) = self.fee_asset() else { + // If the action has no associated fee asset, there are no fees to pay. + return Ok(()); + }; + + ensure!( + state + .is_allowed_fee_asset(fee_asset) + .await + .wrap_err("failed to check allowed fee assets in state")?, + "invalid fee asset", + ); + + let variable_fee = self.variable_component().saturating_mul(fees.multiplier()); + let total_fees = fees.base().saturating_add(variable_fee); + let transaction_context = state + .get_transaction_context() + .expect("transaction source must be present in state when executing an action"); + let from = transaction_context.address_bytes(); + let position_in_transaction = transaction_context.position_in_transaction; + + state.add_fee_to_block_fees::<_, Self>(fee_asset, total_fees, position_in_transaction); + state + .decrease_balance(&from, fee_asset, total_fees) + .await + .wrap_err("failed to decrease balance for fee payment")?; + Ok(()) + } +} + +impl FeeHandler for Transfer { + fn name() -> &'static str { + ::Raw::NAME + } + + fn full_name() -> String { + ::full_name() + } + + fn snake_case_name() -> &'static str { + "transfer" } - #[instrument(skip_all)] fn variable_component(&self) -> u128 { 0 } + + fn fee_asset(&self) -> Option<&asset::Denom> { + Some(&self.fee_asset) + } } -#[async_trait::async_trait] impl FeeHandler for BridgeLock { - #[instrument(skip_all, err)] - async fn check_and_pay_fees(&self, state: S) -> eyre::Result<()> { - let fees = state - .get_bridge_lock_fees() - .await - .wrap_err("error fetching bridge lock fees")? - .ok_or_eyre("bridge lock fees not found, so this action is disabled")?; - check_and_pay_fees(self, fees.base, fees.multiplier, state, &self.fee_asset).await + fn name() -> &'static str { + ::Raw::NAME + } + + fn full_name() -> String { + ::full_name() + } + + fn snake_case_name() -> &'static str { + "bridge_lock" } - #[instrument(skip_all)] fn variable_component(&self) -> u128 { base_deposit_fee(&self.asset, &self.destination_chain_address) } + + fn fee_asset(&self) -> Option<&asset::Denom> { + Some(&self.fee_asset) + } } -#[async_trait::async_trait] impl FeeHandler for BridgeSudoChange { - #[instrument(skip_all, err)] - async fn check_and_pay_fees(&self, state: S) -> eyre::Result<()> { - let fees = state - .get_bridge_sudo_change_fees() - .await - .wrap_err("error fetching bridge sudo change fees")? - .ok_or_eyre("bridge sudo change fees not found, so this action is disabled")?; - check_and_pay_fees(self, fees.base, fees.multiplier, state, &self.fee_asset).await + fn name() -> &'static str { + ::Raw::NAME + } + + fn full_name() -> String { + ::full_name() + } + + fn snake_case_name() -> &'static str { + "bridge_sudo_change" } - #[instrument(skip_all)] fn variable_component(&self) -> u128 { 0 } + + fn fee_asset(&self) -> Option<&asset::Denom> { + Some(&self.fee_asset) + } } -#[async_trait::async_trait] impl FeeHandler for BridgeUnlock { - #[instrument(skip_all, err)] - async fn check_and_pay_fees(&self, state: S) -> eyre::Result<()> { - let fees = state - .get_bridge_unlock_fees() - .await - .wrap_err("error fetching bridge unlock fees")? - .ok_or_eyre("bridge unlock fees not found, so this action is disabled")?; - check_and_pay_fees(self, fees.base, fees.multiplier, state, &self.fee_asset).await + fn name() -> &'static str { + ::Raw::NAME + } + + fn full_name() -> String { + ::full_name() + } + + fn snake_case_name() -> &'static str { + "bridge_unlock" } - #[instrument(skip_all)] fn variable_component(&self) -> u128 { 0 } + + fn fee_asset(&self) -> Option<&asset::Denom> { + Some(&self.fee_asset) + } } -#[async_trait::async_trait] impl FeeHandler for InitBridgeAccount { - #[instrument(skip_all, err)] - async fn check_and_pay_fees(&self, state: S) -> eyre::Result<()> { - let fees = state - .get_init_bridge_account_fees() - .await - .wrap_err("error fetching init bridge account fees")? - .ok_or_eyre("init bridge account fees not found, so this action is disabled")?; - check_and_pay_fees(self, fees.base, fees.multiplier, state, &self.fee_asset).await + fn name() -> &'static str { + ::Raw::NAME + } + + fn full_name() -> String { + ::full_name() + } + + fn snake_case_name() -> &'static str { + "init_bridge_account" } - #[instrument(skip_all)] fn variable_component(&self) -> u128 { 0 } + + fn fee_asset(&self) -> Option<&asset::Denom> { + Some(&self.fee_asset) + } } -#[async_trait::async_trait] -impl FeeHandler for transaction::v1::action::Ics20Withdrawal { - #[instrument(skip_all, err)] - async fn check_and_pay_fees(&self, state: S) -> eyre::Result<()> { - let fees = state - .get_ics20_withdrawal_fees() - .await - .wrap_err("error fetching ics20 withdrawal fees")? - .ok_or_eyre("ics20 withdrawal fees not found, so this action is disabled")?; - check_and_pay_fees(self, fees.base, fees.multiplier, state, &self.fee_asset).await +impl FeeHandler for Ics20Withdrawal { + fn name() -> &'static str { + ::Raw::NAME + } + + fn full_name() -> String { + ::full_name() + } + + fn snake_case_name() -> &'static str { + "ics20_withdrawal" } - #[instrument(skip_all)] fn variable_component(&self) -> u128 { 0 } + + fn fee_asset(&self) -> Option<&asset::Denom> { + Some(&self.fee_asset) + } } -#[async_trait::async_trait] impl FeeHandler for RollupDataSubmission { - #[instrument(skip_all, err)] - async fn check_and_pay_fees(&self, state: S) -> eyre::Result<()> { - let fees = state - .get_rollup_data_submission_fees() - .await - .wrap_err("error fetching rollup data submission fees")? - .ok_or_eyre("rollup data submission fees not found, so this action is disabled")?; - check_and_pay_fees(self, fees.base, fees.multiplier, state, &self.fee_asset).await + fn name() -> &'static str { + ::Raw::NAME + } + + fn full_name() -> String { + ::full_name() + } + + fn snake_case_name() -> &'static str { + "rollup_data_submission" } - #[instrument(skip_all)] fn variable_component(&self) -> u128 { u128::try_from(self.data.len()) .expect("converting a usize to a u128 should work on any currently existing machine") } + + fn fee_asset(&self) -> Option<&asset::Denom> { + Some(&self.fee_asset) + } } -#[async_trait::async_trait] impl FeeHandler for ValidatorUpdate { - #[instrument(skip_all, err)] - async fn check_and_pay_fees(&self, state: S) -> eyre::Result<()> { - state - .get_validator_update_fees() - .await - .wrap_err("error fetching validator update fees")? - .ok_or_eyre("validator update fees not found, so this action is disabled")?; - Ok(()) + fn name() -> &'static str { + ::Raw::NAME + } + + fn full_name() -> String { + ::full_name() + } + + fn snake_case_name() -> &'static str { + "validator_update" } fn variable_component(&self) -> u128 { 0 } + + fn fee_asset(&self) -> Option<&asset::Denom> { + None + } } -#[async_trait::async_trait] impl FeeHandler for SudoAddressChange { - #[instrument(skip_all, err)] - async fn check_and_pay_fees(&self, state: S) -> eyre::Result<()> { - state - .get_sudo_address_change_fees() - .await - .wrap_err("error fetching sudo address change fees")? - .ok_or_eyre("sudo address change fees not found, so this action is disabled")?; - Ok(()) + fn name() -> &'static str { + ::Raw::NAME + } + + fn full_name() -> String { + ::full_name() + } + + fn snake_case_name() -> &'static str { + "sudo_address_change" } fn variable_component(&self) -> u128 { 0 } + + fn fee_asset(&self) -> Option<&asset::Denom> { + None + } } -#[async_trait::async_trait] impl FeeHandler for FeeChange { - #[instrument(skip_all, err)] - async fn check_and_pay_fees(&self, state: S) -> eyre::Result<()> { - state - .get_fee_change_fees() - .await - .wrap_err("error fetching fee change fees")? - .ok_or_eyre("fee change fees not found, so this action is disabled")?; - Ok(()) + fn name() -> &'static str { + ::Raw::NAME + } + + fn full_name() -> String { + ::full_name() + } + + fn snake_case_name() -> &'static str { + "fee_change" } fn variable_component(&self) -> u128 { 0 } + + fn fee_asset(&self) -> Option<&asset::Denom> { + None + } } -#[async_trait::async_trait] impl FeeHandler for IbcSudoChange { - #[instrument(skip_all, err)] - async fn check_and_pay_fees(&self, state: S) -> eyre::Result<()> { - state - .get_ibc_sudo_change_fees() - .await - .wrap_err("error fetching ibc sudo change fees")? - .ok_or_eyre("ibc sudo change fees not found, so this action is disabled")?; - Ok(()) + fn name() -> &'static str { + ::Raw::NAME + } + + fn full_name() -> String { + ::full_name() + } + + fn snake_case_name() -> &'static str { + "ibc_sudo_change" } fn variable_component(&self) -> u128 { 0 } + + fn fee_asset(&self) -> Option<&asset::Denom> { + None + } } -#[async_trait::async_trait] impl FeeHandler for IbcRelayerChange { - #[instrument(skip_all, err)] - async fn check_and_pay_fees(&self, state: S) -> eyre::Result<()> { - state - .get_ibc_relayer_change_fees() - .await - .wrap_err("error fetching ibc relayer change fees")? - .ok_or_eyre("ibc relayer change fees not found, so this action is disabled")?; - Ok(()) + fn name() -> &'static str { + ::Raw::NAME + } + + fn full_name() -> String { + ::full_name() + } + + fn snake_case_name() -> &'static str { + "ibc_relayer_change" } fn variable_component(&self) -> u128 { 0 } + + fn fee_asset(&self) -> Option<&asset::Denom> { + None + } } -#[async_trait::async_trait] impl FeeHandler for FeeAssetChange { - #[instrument(skip_all, err)] - async fn check_and_pay_fees(&self, state: S) -> eyre::Result<()> { - state - .get_fee_asset_change_fees() - .await - .wrap_err("error fetching fee asset change fees")? - .ok_or_eyre("fee asset change fees not found, so this action is disabled")?; - Ok(()) + fn name() -> &'static str { + ::Raw::NAME + } + + fn full_name() -> String { + ::full_name() + } + + fn snake_case_name() -> &'static str { + "fee_asset_change" } fn variable_component(&self) -> u128 { 0 } + + fn fee_asset(&self) -> Option<&asset::Denom> { + None + } } -#[async_trait::async_trait] impl FeeHandler for IbcRelay { - #[instrument(skip_all, err)] - async fn check_and_pay_fees(&self, state: S) -> eyre::Result<()> { - state - .get_ibc_relay_fees() - .await - .wrap_err("error fetching ibc relay fees")? - .ok_or_eyre("ibc relay fees not found, so this action is disabled")?; - Ok(()) + fn name() -> &'static str { + penumbra_proto::penumbra::core::component::ibc::v1::IbcRelay::NAME + } + + fn full_name() -> String { + penumbra_proto::penumbra::core::component::ibc::v1::IbcRelay::full_name() + } + + fn snake_case_name() -> &'static str { + "ibc_relay" } fn variable_component(&self) -> u128 { 0 } -} -#[instrument(skip_all, err(level = Level::WARN))] -async fn check_and_pay_fees( - act: &T, - base: u128, - multiplier: u128, - mut state: S, - fee_asset: &asset::Denom, -) -> eyre::Result<()> { - let total_fees = base.saturating_add(act.variable_component().saturating_mul(multiplier)); - let transaction_context = state - .get_transaction_context() - .expect("transaction source must be present in state when executing an action"); - let from = transaction_context.address_bytes(); - let position_in_transaction = transaction_context.position_in_transaction; - - ensure!( - state - .is_allowed_fee_asset(fee_asset) - .await - .wrap_err("failed to check allowed fee assets in state")?, - "invalid fee asset", - ); - state.add_fee_to_block_fees::<_, T>(fee_asset, total_fees, position_in_transaction); - state - .decrease_balance(&from, fee_asset, total_fees) - .await - .wrap_err("failed to decrease balance for fee payment")?; - Ok(()) + fn fee_asset(&self) -> Option<&asset::Denom> { + None + } } /// Returns a modified byte length of the deposit event. Length is calculated with reasonable values diff --git a/crates/astria-sequencer/src/fees/query.rs b/crates/astria-sequencer/src/fees/query.rs index b2a74e18e6..d4b28dc768 100644 --- a/crates/astria-sequencer/src/fees/query.rs +++ b/crates/astria-sequencer/src/fees/query.rs @@ -12,7 +12,23 @@ use astria_core::{ protocol::{ abci::AbciErrorCode, asset::v1::AllowedFeeAssetsResponse, + fees::v1::FeeComponents, transaction::v1::{ + action::{ + BridgeLock, + BridgeSudoChange, + BridgeUnlock, + FeeAssetChange, + FeeChange, + IbcRelayerChange, + IbcSudoChange, + Ics20Withdrawal, + InitBridgeAccount, + RollupDataSubmission, + SudoAddressChange, + Transfer, + ValidatorUpdate, + }, Action, TransactionBody, }, @@ -21,7 +37,9 @@ use astria_core::{ }; use astria_eyre::eyre::{ self, + eyre, OptionExt as _, + Report, WrapErr as _, }; use cnidarium::{ @@ -32,6 +50,7 @@ use futures::{ FutureExt as _, StreamExt as _, }; +use penumbra_ibc::IbcRelay; use prost::{ Message as _, Name as _, @@ -51,13 +70,14 @@ use tracing::{ warn, }; -use super::{ - FeeHandler, - StateReadExt as _, -}; use crate::{ app::StateReadExt as _, assets::StateReadExt as _, + fees::{ + FeeHandler, + StateReadExt as _, + }, + storage::StoredValue, }; async fn find_trace_prefixed_or_return_ibc( @@ -260,204 +280,102 @@ pub(crate) async fn get_fees_for_transaction( tx: &TransactionBody, state: &S, ) -> eyre::Result> { - let transfer_fees = OnceCell::new(); - let rollup_data_submission_fees = OnceCell::new(); - let ics20_withdrawal_fees = OnceCell::new(); - let init_bridge_account_fees = OnceCell::new(); - let bridge_lock_fees = OnceCell::new(); - let bridge_unlock_fees = OnceCell::new(); - let bridge_sudo_change_fees = OnceCell::new(); - let validator_update_fees = OnceCell::new(); - let sudo_address_change_fees = OnceCell::new(); - let ibc_sudo_change_fees = OnceCell::new(); - let ibc_relay_fees = OnceCell::new(); - let ibc_relayer_change_fees = OnceCell::new(); - let fee_asset_change_fees = OnceCell::new(); - let fee_change_fees = OnceCell::new(); + let transfer_fees: OnceCell>> = OnceCell::new(); + let rollup_data_submission_fees: OnceCell>> = + OnceCell::new(); + let ics20_withdrawal_fees: OnceCell>> = OnceCell::new(); + let init_bridge_account_fees: OnceCell>> = + OnceCell::new(); + let bridge_lock_fees: OnceCell>> = OnceCell::new(); + let bridge_unlock_fees: OnceCell>> = OnceCell::new(); + let bridge_sudo_change_fees: OnceCell>> = + OnceCell::new(); + let validator_update_fees: OnceCell>> = OnceCell::new(); + let sudo_address_change_fees: OnceCell>> = + OnceCell::new(); + let ibc_sudo_change_fees: OnceCell>> = OnceCell::new(); + let ibc_relay_fees: OnceCell>> = OnceCell::new(); + let ibc_relayer_change_fees: OnceCell>> = + OnceCell::new(); + let fee_asset_change_fees: OnceCell>> = OnceCell::new(); + let fee_change_fees: OnceCell>> = OnceCell::new(); let mut fees_by_asset = HashMap::new(); for action in tx.actions() { match action { Action::Transfer(act) => { - let transfer_fees = transfer_fees - .get_or_try_init(|| async { state.get_transfer_fees().await }) - .await - .wrap_err("failed to get transfer fees")? - .ok_or_eyre("fees not found for `Transfer` action, hence it is disabled")?; - calculate_and_add_fees( - act, - act.fee_asset.to_ibc_prefixed(), - &mut fees_by_asset, - transfer_fees.base, - transfer_fees.multiplier, - ); + let fees = get_or_init_fees(state, &transfer_fees).await?; + calculate_and_add_fees(act, &mut fees_by_asset, fees); } Action::RollupDataSubmission(act) => { - let rollup_data_submission_fees = rollup_data_submission_fees - .get_or_try_init(|| async { state.get_rollup_data_submission_fees().await }) - .await - .wrap_err("failed to get rollup data submission fees")? - .ok_or_eyre( - "fees not found for `RollupDataSubmission` action, hence it is disabled", - )?; - calculate_and_add_fees( - act, - act.fee_asset.to_ibc_prefixed(), - &mut fees_by_asset, - rollup_data_submission_fees.base, - rollup_data_submission_fees.multiplier, - ); + let fees = get_or_init_fees(state, &rollup_data_submission_fees).await?; + calculate_and_add_fees(act, &mut fees_by_asset, fees); } Action::Ics20Withdrawal(act) => { - let ics20_withdrawal_fees = ics20_withdrawal_fees - .get_or_try_init(|| async { state.get_ics20_withdrawal_fees().await }) - .await - .wrap_err("failed to get ics20 withdrawal fees")? - .ok_or_eyre( - "fees not found for `Ics20Withdrawal` action, hence it is disabled", - )?; - calculate_and_add_fees( - act, - act.fee_asset.to_ibc_prefixed(), - &mut fees_by_asset, - ics20_withdrawal_fees.base, - ics20_withdrawal_fees.multiplier, - ); + let fees = get_or_init_fees(state, &ics20_withdrawal_fees).await?; + calculate_and_add_fees(act, &mut fees_by_asset, fees); } Action::InitBridgeAccount(act) => { - let init_bridge_account_fees = init_bridge_account_fees - .get_or_try_init(|| async { state.get_init_bridge_account_fees().await }) - .await - .wrap_err("failed to get init bridge account fees")? - .ok_or_eyre( - "fees not found for `InitBridgeAccount` action, hence it is disabled", - )?; - calculate_and_add_fees( - act, - act.fee_asset.to_ibc_prefixed(), - &mut fees_by_asset, - init_bridge_account_fees.base, - init_bridge_account_fees.multiplier, - ); + let fees = get_or_init_fees(state, &init_bridge_account_fees).await?; + calculate_and_add_fees(act, &mut fees_by_asset, fees); } Action::BridgeLock(act) => { - let bridge_lock_fees = bridge_lock_fees - .get_or_try_init(|| async { state.get_bridge_lock_fees().await }) - .await - .wrap_err("failed to get bridge lock fees")? - .ok_or_eyre("fees not found for `BridgeLock` action, hence it is disabled")?; - calculate_and_add_fees( - act, - act.fee_asset.to_ibc_prefixed(), - &mut fees_by_asset, - bridge_lock_fees.base, - bridge_lock_fees.multiplier, - ); + let fees = get_or_init_fees(state, &bridge_lock_fees).await?; + calculate_and_add_fees(act, &mut fees_by_asset, fees); } Action::BridgeUnlock(act) => { - let bridge_unlock_fees = bridge_unlock_fees - .get_or_try_init(|| async { state.get_bridge_unlock_fees().await }) - .await - .wrap_err("failed to get bridge unlock fees")? - .ok_or_eyre("fees not found for `BridgeUnlock` action, hence it is disabled")?; - calculate_and_add_fees( - act, - act.fee_asset.to_ibc_prefixed(), - &mut fees_by_asset, - bridge_unlock_fees.base, - bridge_unlock_fees.multiplier, - ); + let fees = get_or_init_fees(state, &bridge_unlock_fees).await?; + calculate_and_add_fees(act, &mut fees_by_asset, fees); } Action::BridgeSudoChange(act) => { - let bridge_sudo_change_fees = bridge_sudo_change_fees - .get_or_try_init(|| async { state.get_bridge_sudo_change_fees().await }) - .await - .wrap_err("failed to get bridge sudo change fees")? - .ok_or_eyre( - "fees not found for `BridgeSudoChange` action, hence it is disabled", - )?; - calculate_and_add_fees( - act, - act.fee_asset.to_ibc_prefixed(), - &mut fees_by_asset, - bridge_sudo_change_fees.base, - bridge_sudo_change_fees.multiplier, - ); + let fees = get_or_init_fees(state, &bridge_sudo_change_fees).await?; + calculate_and_add_fees(act, &mut fees_by_asset, fees); } - Action::ValidatorUpdate(_) => { - validator_update_fees - .get_or_try_init(|| async { state.get_validator_update_fees().await }) - .await - .wrap_err("failed to get validator update fees")? - .ok_or_eyre( - "fees not found for `ValidatorUpdate` action, hence it is disabled", - )?; + Action::ValidatorUpdate(act) => { + let fees = get_or_init_fees(state, &validator_update_fees).await?; + calculate_and_add_fees(act, &mut fees_by_asset, fees); } - Action::SudoAddressChange(_) => { - sudo_address_change_fees - .get_or_try_init(|| async { state.get_sudo_address_change_fees().await }) - .await - .wrap_err("failed to get sudo address change fees")? - .ok_or_eyre( - "fees not found for `SudoAddressChange` action, hence it is disabled", - )?; + Action::SudoAddressChange(act) => { + let fees = get_or_init_fees(state, &sudo_address_change_fees).await?; + calculate_and_add_fees(act, &mut fees_by_asset, fees); } - Action::IbcSudoChange(_) => { - ibc_sudo_change_fees - .get_or_try_init(|| async { state.get_ibc_sudo_change_fees().await }) - .await - .wrap_err("failed to get ibc sudo change fees")? - .ok_or_eyre( - "fees not found for `IbcSudoChange` action, hence it is disabled", - )?; + Action::IbcSudoChange(act) => { + let fees = get_or_init_fees(state, &ibc_sudo_change_fees).await?; + calculate_and_add_fees(act, &mut fees_by_asset, fees); } - Action::Ibc(_) => { - ibc_relay_fees - .get_or_try_init(|| async { state.get_ibc_relay_fees().await }) - .await - .wrap_err("failed to get ibc relay fees")? - .ok_or_eyre("fees not found for `IbcRelay` action, hence it is disabled")?; + Action::Ibc(act) => { + let fees = get_or_init_fees(state, &ibc_relay_fees).await?; + calculate_and_add_fees(act, &mut fees_by_asset, fees); } - Action::IbcRelayerChange(_) => { - ibc_relayer_change_fees - .get_or_try_init(|| async { state.get_ibc_relayer_change_fees().await }) - .await - .wrap_err("failed to get ibc relayer change fees")? - .ok_or_eyre( - "fees not found for `IbcRelayerChange` action, hence it is disabled", - )?; + Action::IbcRelayerChange(act) => { + let fees = get_or_init_fees(state, &ibc_relayer_change_fees).await?; + calculate_and_add_fees(act, &mut fees_by_asset, fees); } - Action::FeeAssetChange(_) => { - fee_asset_change_fees - .get_or_try_init(|| async { state.get_fee_asset_change_fees().await }) - .await - .wrap_err("failed to get fee asset change fees")? - .ok_or_eyre( - "fees not found for `FeeAssetChange` action, hence it is disabled", - )?; + Action::FeeAssetChange(act) => { + let fees = get_or_init_fees(state, &fee_asset_change_fees).await?; + calculate_and_add_fees(act, &mut fees_by_asset, fees); } - Action::FeeChange(_) => { - fee_change_fees - .get_or_try_init(|| async { state.get_fee_change_fees().await }) - .await - .wrap_err("failed to get fee change fees")? - .ok_or_eyre( - "fees not found for `FeeChange` action, which cannot be disabled", - )?; + Action::FeeChange(act) => { + let fees = get_or_init_fees(state, &fee_change_fees).await?; + calculate_and_add_fees(act, &mut fees_by_asset, fees); } } } Ok(fees_by_asset) } -fn calculate_and_add_fees( - act: &T, - fee_asset: asset::IbcPrefixed, +fn calculate_and_add_fees( + action: &F, fees_by_asset: &mut HashMap, - base: u128, - multiplier: u128, + fees: &FeeComponents, ) { - let total_fees = base.saturating_add(multiplier.saturating_mul(act.variable_component())); + let Some(fee_asset) = action.fee_asset().map(Denom::to_ibc_prefixed) else { + // If there's no fee asset, we don't charge fees. + return; + }; + let base = fees.base(); + let multiplier = fees.multiplier(); + let total_fees = base.saturating_add(multiplier.saturating_mul(action.variable_component())); fees_by_asset .entry(fee_asset) .and_modify(|amt| *amt = amt.saturating_add(total_fees)) @@ -498,6 +416,29 @@ fn preprocess_fees_request(request: &request::Query) -> Result( + state: &S, + fee_components: &'a OnceCell>>, +) -> eyre::Result<&'a FeeComponents> +where + F: FeeHandler, + FeeComponents: TryFrom, Error = Report>, + S: StateRead, +{ + let fees = fee_components + .get_or_try_init(|| async { state.get_fees::().await }) + .await + .wrap_err_with(|| format!("failed to get fees for `{}` action", F::snake_case_name()))? + .as_ref() + .ok_or_else(|| { + eyre!( + "fees not found for `{}` action, hence it is disabled", + F::snake_case_name() + ) + })?; + Ok(fees) +} + #[derive(serde::Serialize)] struct AllFeeComponents { transfer: FetchResult, @@ -524,13 +465,13 @@ enum FetchResult { Component(FeeComponent), } -impl From>> for FetchResult -where - FeeComponent: From, -{ - fn from(value: eyre::Result>) -> Self { +impl From>>> for FetchResult { + fn from(value: eyre::Result>>) -> Self { match value { - Ok(Some(val)) => Self::Component(val.into()), + Ok(Some(val)) => Self::Component(FeeComponent { + base: val.base(), + multiplier: val.multiplier(), + }), Ok(None) => Self::Missing("not set"), Err(err) => Self::Err(err.to_string()), } @@ -546,30 +487,30 @@ async fn get_all_fee_components(state: &S) -> AllFeeComponents { bridge_lock, bridge_unlock, bridge_sudo_change, - ibc_relay, validator_update, - fee_asset_change, - fee_change, - ibc_relayer_change, sudo_address_change, ibc_sudo_change, + ibc_relay, + ibc_relayer_change, + fee_asset_change, + fee_change, ) = join!( - state.get_transfer_fees().map(fetch_to_response), + state.get_fees::().map(FetchResult::from), state - .get_rollup_data_submission_fees() - .map(fetch_to_response), - state.get_ics20_withdrawal_fees().map(fetch_to_response), - state.get_init_bridge_account_fees().map(fetch_to_response), - state.get_bridge_lock_fees().map(fetch_to_response), - state.get_bridge_unlock_fees().map(fetch_to_response), - state.get_bridge_sudo_change_fees().map(fetch_to_response), - state.get_ibc_relay_fees().map(fetch_to_response), - state.get_validator_update_fees().map(fetch_to_response), - state.get_fee_asset_change_fees().map(fetch_to_response), - state.get_fee_change_fees().map(fetch_to_response), - state.get_ibc_relayer_change_fees().map(fetch_to_response), - state.get_sudo_address_change_fees().map(fetch_to_response), - state.get_ibc_sudo_change_fees().map(fetch_to_response), + .get_fees::() + .map(FetchResult::from), + state.get_fees::().map(FetchResult::from), + state.get_fees::().map(FetchResult::from), + state.get_fees::().map(FetchResult::from), + state.get_fees::().map(FetchResult::from), + state.get_fees::().map(FetchResult::from), + state.get_fees::().map(FetchResult::from), + state.get_fees::().map(FetchResult::from), + state.get_fees::().map(FetchResult::from), + state.get_fees::().map(FetchResult::from), + state.get_fees::().map(FetchResult::from), + state.get_fees::().map(FetchResult::from), + state.get_fees::().map(FetchResult::from), ); AllFeeComponents { transfer, @@ -589,46 +530,8 @@ async fn get_all_fee_components(state: &S) -> AllFeeComponents { } } -fn fetch_to_response(value: eyre::Result>) -> FetchResult -where - FeeComponent: From, -{ - value.into() -} - #[derive(serde::Serialize)] struct FeeComponent { base: u128, multiplier: u128, } - -macro_rules! impl_from_domain_fee_component { - ( $($dt:ty ),* $(,)?) => { - $( - impl From<$dt> for FeeComponent { - fn from(val: $dt) -> Self { - Self { - base: val.base, - multiplier: val.multiplier, - } - } - } - )* - } -} -impl_from_domain_fee_component!( - astria_core::protocol::fees::v1::BridgeLockFeeComponents, - astria_core::protocol::fees::v1::BridgeSudoChangeFeeComponents, - astria_core::protocol::fees::v1::BridgeUnlockFeeComponents, - astria_core::protocol::fees::v1::FeeAssetChangeFeeComponents, - astria_core::protocol::fees::v1::FeeChangeFeeComponents, - astria_core::protocol::fees::v1::IbcRelayFeeComponents, - astria_core::protocol::fees::v1::IbcRelayerChangeFeeComponents, - astria_core::protocol::fees::v1::IbcSudoChangeFeeComponents, - astria_core::protocol::fees::v1::Ics20WithdrawalFeeComponents, - astria_core::protocol::fees::v1::InitBridgeAccountFeeComponents, - astria_core::protocol::fees::v1::RollupDataSubmissionFeeComponents, - astria_core::protocol::fees::v1::SudoAddressChangeFeeComponents, - astria_core::protocol::fees::v1::TransferFeeComponents, - astria_core::protocol::fees::v1::ValidatorUpdateFeeComponents, -); diff --git a/crates/astria-sequencer/src/fees/state_ext.rs b/crates/astria-sequencer/src/fees/state_ext.rs index d3a74ba65f..d62d682f86 100644 --- a/crates/astria-sequencer/src/fees/state_ext.rs +++ b/crates/astria-sequencer/src/fees/state_ext.rs @@ -10,27 +10,12 @@ use std::{ use astria_core::{ primitive::v1::asset, - protocol::fees::v1::{ - BridgeLockFeeComponents, - BridgeSudoChangeFeeComponents, - BridgeUnlockFeeComponents, - FeeAssetChangeFeeComponents, - FeeChangeFeeComponents, - IbcRelayFeeComponents, - IbcRelayerChangeFeeComponents, - IbcSudoChangeFeeComponents, - Ics20WithdrawalFeeComponents, - InitBridgeAccountFeeComponents, - RollupDataSubmissionFeeComponents, - SudoAddressChangeFeeComponents, - TransferFeeComponents, - ValidatorUpdateFeeComponents, - }, - Protobuf, + protocol::fees::v1::FeeComponents, }; use astria_eyre::{ anyhow_to_eyre, eyre::{ + Report, Result, WrapErr as _, }, @@ -46,12 +31,9 @@ use tendermint::abci::Event; use tracing::instrument; use super::{ - storage::{ + storage::keys::{ self, - keys::{ - self, - extract_asset_from_allowed_asset_key, - }, + extract_asset_from_allowed_asset_key, }, Fee, FeeHandler, @@ -97,256 +79,26 @@ pub(crate) trait StateReadExt: StateRead { } #[instrument(skip_all)] - async fn get_transfer_fees(&self) -> Result> { - let bytes = self - .get_raw(keys::TRANSFER) - .await - .map_err(anyhow_to_eyre) - .wrap_err("failed reading raw transfer fee components from state")?; - let Some(bytes) = bytes else { - return Ok(None); - }; - StoredValue::deserialize(&bytes) - .and_then(|value| { - storage::TransferFeeComponentsStorage::try_from(value) - .map(|fees| Some(TransferFeeComponents::from(fees))) - }) - .wrap_err("invalid fees bytes") - } - - #[instrument(skip_all)] - async fn get_rollup_data_submission_fees( - &self, - ) -> Result> { - let bytes = self - .get_raw(keys::ROLLUP_DATA_SUBMISSION) - .await - .map_err(anyhow_to_eyre) - .wrap_err("failed reading raw sequence fee components from state")?; - let Some(bytes) = bytes else { - return Ok(None); - }; - StoredValue::deserialize(&bytes) - .and_then(|value| { - storage::RollupDataSubmissionFeeComponentsStorage::try_from(value) - .map(|fees| Some(RollupDataSubmissionFeeComponents::from(fees))) - }) - .wrap_err("invalid fees bytes") - } - - #[instrument(skip_all)] - async fn get_ics20_withdrawal_fees(&self) -> Result> { - let bytes = self - .get_raw(keys::ICS20_WITHDRAWAL) - .await - .map_err(anyhow_to_eyre) - .wrap_err("failed reading raw ics20 withdrawal fee components from state")?; - let Some(bytes) = bytes else { - return Ok(None); - }; - StoredValue::deserialize(&bytes) - .and_then(|value| { - storage::Ics20WithdrawalFeeComponentsStorage::try_from(value) - .map(|fees| Some(Ics20WithdrawalFeeComponents::from(fees))) - }) - .wrap_err("invalid fees bytes") - } - - #[instrument(skip_all)] - async fn get_init_bridge_account_fees(&self) -> Result> { - let bytes = self - .get_raw(keys::INIT_BRIDGE_ACCOUNT) - .await - .map_err(anyhow_to_eyre) - .wrap_err("failed reading raw init bridge account fee components from state")?; - let Some(bytes) = bytes else { - return Ok(None); - }; - StoredValue::deserialize(&bytes) - .and_then(|value| { - storage::InitBridgeAccountFeeComponentsStorage::try_from(value) - .map(|fees| Some(InitBridgeAccountFeeComponents::from(fees))) - }) - .wrap_err("invalid fees bytes") - } - - #[instrument(skip_all)] - async fn get_bridge_lock_fees(&self) -> Result> { - let bytes = self - .get_raw(keys::BRIDGE_LOCK) - .await - .map_err(anyhow_to_eyre) - .wrap_err("failed reading raw bridge lock fee components from state")?; - let Some(bytes) = bytes else { - return Ok(None); - }; - StoredValue::deserialize(&bytes) - .and_then(|value| { - storage::BridgeLockFeeComponentsStorage::try_from(value) - .map(|fees| Some(BridgeLockFeeComponents::from(fees))) - }) - .wrap_err("invalid fees bytes") - } - - #[instrument(skip_all)] - async fn get_bridge_unlock_fees(&self) -> Result> { - let bytes = self - .get_raw(keys::BRIDGE_UNLOCK) - .await - .map_err(anyhow_to_eyre) - .wrap_err("failed reading raw bridge unlock fee components from state")?; - let Some(bytes) = bytes else { - return Ok(None); - }; - StoredValue::deserialize(&bytes) - .and_then(|value| { - storage::BridgeUnlockFeeComponentsStorage::try_from(value) - .map(|fees| Some(BridgeUnlockFeeComponents::from(fees))) - }) - .wrap_err("invalid fees bytes") - } - - #[instrument(skip_all)] - async fn get_bridge_sudo_change_fees(&self) -> Result> { - let bytes = self - .get_raw(keys::BRIDGE_SUDO_CHANGE) - .await - .map_err(anyhow_to_eyre) - .wrap_err("failed reading raw bridge sudo change fee components from state")?; - let Some(bytes) = bytes else { - return Ok(None); - }; - StoredValue::deserialize(&bytes) - .and_then(|value| { - storage::BridgeSudoChangeFeeComponentsStorage::try_from(value) - .map(|fees| Some(BridgeSudoChangeFeeComponents::from(fees))) - }) - .wrap_err("invalid fees bytes") - } - - #[instrument(skip_all)] - async fn get_ibc_relay_fees(&self) -> Result> { - let bytes = self - .get_raw(keys::IBC_RELAY) - .await - .map_err(anyhow_to_eyre) - .wrap_err("failed reading raw ibc relay fee components from state")?; - let Some(bytes) = bytes else { - return Ok(None); - }; - StoredValue::deserialize(&bytes) - .and_then(|value| { - storage::IbcRelayFeeComponentsStorage::try_from(value) - .map(|fees| Some(IbcRelayFeeComponents::from(fees))) - }) - .wrap_err("invalid fees bytes") - } - - #[instrument(skip_all)] - async fn get_validator_update_fees(&self) -> Result> { - let bytes = self - .get_raw(keys::VALIDATOR_UPDATE) - .await - .map_err(anyhow_to_eyre) - .wrap_err("failed reading raw validator update fee components from state")?; - let Some(bytes) = bytes else { - return Ok(None); - }; - StoredValue::deserialize(&bytes) - .and_then(|value| { - storage::ValidatorUpdateFeeComponentsStorage::try_from(value) - .map(|fees| Some(ValidatorUpdateFeeComponents::from(fees))) - }) - .wrap_err("invalid fees bytes") - } - - #[instrument(skip_all)] - async fn get_fee_asset_change_fees(&self) -> Result> { - let bytes = self - .get_raw(keys::FEE_ASSET_CHANGE) - .await - .map_err(anyhow_to_eyre) - .wrap_err("failed reading raw fee asset change fee components from state")?; - let Some(bytes) = bytes else { - return Ok(None); - }; - StoredValue::deserialize(&bytes) - .and_then(|value| { - storage::FeeAssetChangeFeeComponentsStorage::try_from(value) - .map(|fees| Some(FeeAssetChangeFeeComponents::from(fees))) - }) - .wrap_err("invalid fees bytes") - } - - #[instrument(skip_all)] - async fn get_fee_change_fees(&self) -> Result> { - let bytes = self - .get_raw(keys::FEE_CHANGE) - .await - .map_err(anyhow_to_eyre) - .wrap_err("failed reading raw fee change fee components from state")?; - let Some(bytes) = bytes else { - return Ok(None); - }; - StoredValue::deserialize(&bytes) - .and_then(|value| { - storage::FeeChangeFeeComponentsStorage::try_from(value) - .map(|fees| Some(FeeChangeFeeComponents::from(fees))) - }) - .wrap_err("invalid fees bytes") - } - - #[instrument(skip_all)] - async fn get_ibc_relayer_change_fees(&self) -> Result> { - let bytes = self - .get_raw(keys::IBC_RELAYER_CHANGE) - .await - .map_err(anyhow_to_eyre) - .wrap_err("failed reading raw ibc relayer change fee components from state")?; - let Some(bytes) = bytes else { - return Ok(None); - }; - StoredValue::deserialize(&bytes) - .and_then(|value| { - storage::IbcRelayerChangeFeeComponentsStorage::try_from(value) - .map(|fees| Some(IbcRelayerChangeFeeComponents::from(fees))) - }) - .wrap_err("invalid fees bytes") - } - - #[instrument(skip_all)] - async fn get_sudo_address_change_fees(&self) -> Result> { - let bytes = self - .get_raw(keys::SUDO_ADDRESS_CHANGE) - .await - .map_err(anyhow_to_eyre) - .wrap_err("failed reading raw sudo address change fee components from state")?; - let Some(bytes) = bytes else { - return Ok(None); - }; - StoredValue::deserialize(&bytes) - .and_then(|value| { - storage::SudoAddressChangeFeeComponentsStorage::try_from(value) - .map(|fees| Some(SudoAddressChangeFeeComponents::from(fees))) - }) - .wrap_err("invalid fees bytes") - } - - #[instrument(skip_all)] - async fn get_ibc_sudo_change_fees(&self) -> Result> { + async fn get_fees<'a, F>(&self) -> Result>> + where + F: FeeHandler + ?Sized, + FeeComponents: TryFrom, Error = Report>, + { let bytes = self - .get_raw(keys::IBC_SUDO_CHANGE) + .get_raw(&keys::name::()) .await .map_err(anyhow_to_eyre) - .wrap_err("failed reading raw ibc sudo change fee components from state")?; + .wrap_err_with(|| { + format!( + "failed reading raw {} fee components from state", + F::snake_case_name() + ) + })?; let Some(bytes) = bytes else { return Ok(None); }; StoredValue::deserialize(&bytes) - .and_then(|value| { - storage::IbcSudoChangeFeeComponentsStorage::try_from(value) - .map(|fees| Some(IbcSudoChangeFeeComponents::from(fees))) - }) + .and_then(|value| FeeComponents::::try_from(value).map(Some)) .wrap_err("invalid fees bytes") } @@ -378,7 +130,7 @@ impl StateReadExt for T {} pub(crate) trait StateWriteExt: StateWrite { /// Constructs and adds `Fee` object to the block fees vec. #[instrument(skip_all)] - fn add_fee_to_block_fees<'a, TAsset, T: FeeHandler + Protobuf>( + fn add_fee_to_block_fees<'a, TAsset, F: FeeHandler + ?Sized>( &mut self, asset: &'a TAsset, amount: u128, @@ -390,7 +142,7 @@ pub(crate) trait StateWriteExt: StateWrite { let current_fees: Option> = self.object_get(keys::BLOCK); let fee = Fee { - action_name: T::full_name(), + action_name: F::full_name(), asset: asset::IbcPrefixed::from(asset).into(), amount, position_in_transaction, @@ -411,133 +163,15 @@ pub(crate) trait StateWriteExt: StateWrite { } #[instrument(skip_all)] - fn put_transfer_fees(&mut self, fees: TransferFeeComponents) -> Result<()> { - let bytes = StoredValue::from(storage::TransferFeeComponentsStorage::from(fees)) - .serialize() - .wrap_err("failed to serialize fees")?; - self.put_raw(keys::TRANSFER.to_string(), bytes); - Ok(()) - } - - #[instrument(skip_all)] - fn put_rollup_data_submission_fees( - &mut self, - fees: RollupDataSubmissionFeeComponents, - ) -> Result<()> { - let bytes = StoredValue::from(storage::RollupDataSubmissionFeeComponentsStorage::from( - fees, - )) - .serialize() - .wrap_err("failed to serialize fees")?; - self.put_raw(keys::ROLLUP_DATA_SUBMISSION.to_string(), bytes); - Ok(()) - } - - #[instrument(skip_all)] - fn put_ics20_withdrawal_fees(&mut self, fees: Ics20WithdrawalFeeComponents) -> Result<()> { - let bytes = StoredValue::from(storage::Ics20WithdrawalFeeComponentsStorage::from(fees)) - .serialize() - .wrap_err("failed to serialize fees")?; - self.put_raw(keys::ICS20_WITHDRAWAL.to_string(), bytes); - Ok(()) - } - - #[instrument(skip_all)] - fn put_init_bridge_account_fees(&mut self, fees: InitBridgeAccountFeeComponents) -> Result<()> { - let bytes = StoredValue::from(storage::InitBridgeAccountFeeComponentsStorage::from(fees)) - .serialize() - .wrap_err("failed to serialize fees")?; - self.put_raw(keys::INIT_BRIDGE_ACCOUNT.to_string(), bytes); - Ok(()) - } - - #[instrument(skip_all)] - fn put_bridge_lock_fees(&mut self, fees: BridgeLockFeeComponents) -> Result<()> { - let bytes = StoredValue::from(storage::BridgeLockFeeComponentsStorage::from(fees)) - .serialize() - .wrap_err("failed to serialize fees")?; - self.put_raw(keys::BRIDGE_LOCK.to_string(), bytes); - Ok(()) - } - - #[instrument(skip_all)] - fn put_bridge_unlock_fees(&mut self, fees: BridgeUnlockFeeComponents) -> Result<()> { - let bytes = StoredValue::from(storage::BridgeUnlockFeeComponentsStorage::from(fees)) - .serialize() - .wrap_err("failed to serialize fees")?; - self.put_raw(keys::BRIDGE_UNLOCK.to_string(), bytes); - Ok(()) - } - - #[instrument(skip_all)] - fn put_bridge_sudo_change_fees(&mut self, fees: BridgeSudoChangeFeeComponents) -> Result<()> { - let bytes = StoredValue::from(storage::BridgeSudoChangeFeeComponentsStorage::from(fees)) - .serialize() - .wrap_err("failed to serialize fees")?; - self.put_raw(keys::BRIDGE_SUDO_CHANGE.to_string(), bytes); - Ok(()) - } - - #[instrument(skip_all)] - fn put_ibc_relay_fees(&mut self, fees: IbcRelayFeeComponents) -> Result<()> { - let bytes = StoredValue::from(storage::IbcRelayFeeComponentsStorage::from(fees)) - .serialize() - .wrap_err("failed to serialize fees")?; - self.put_raw(keys::IBC_RELAY.to_string(), bytes); - Ok(()) - } - - #[instrument(skip_all)] - fn put_validator_update_fees(&mut self, fees: ValidatorUpdateFeeComponents) -> Result<()> { - let bytes = StoredValue::from(storage::ValidatorUpdateFeeComponentsStorage::from(fees)) - .serialize() - .wrap_err("failed to serialize fees")?; - self.put_raw(keys::VALIDATOR_UPDATE.to_string(), bytes); - Ok(()) - } - - #[instrument(skip_all)] - fn put_fee_asset_change_fees(&mut self, fees: FeeAssetChangeFeeComponents) -> Result<()> { - let bytes = StoredValue::from(storage::FeeAssetChangeFeeComponentsStorage::from(fees)) - .serialize() - .wrap_err("failed to serialize fees")?; - self.put_raw(keys::FEE_ASSET_CHANGE.to_string(), bytes); - Ok(()) - } - - #[instrument(skip_all)] - fn put_fee_change_fees(&mut self, fees: FeeChangeFeeComponents) -> Result<()> { - let bytes = StoredValue::from(storage::FeeChangeFeeComponentsStorage::from(fees)) - .serialize() - .wrap_err("failed to serialize fees")?; - self.put_raw(keys::FEE_CHANGE.to_string(), bytes); - Ok(()) - } - - #[instrument(skip_all)] - fn put_ibc_relayer_change_fees(&mut self, fees: IbcRelayerChangeFeeComponents) -> Result<()> { - let bytes = StoredValue::from(storage::IbcRelayerChangeFeeComponentsStorage::from(fees)) - .serialize() - .wrap_err("failed to serialize fees")?; - self.put_raw(keys::IBC_RELAYER_CHANGE.to_string(), bytes); - Ok(()) - } - - #[instrument(skip_all)] - fn put_sudo_address_change_fees(&mut self, fees: SudoAddressChangeFeeComponents) -> Result<()> { - let bytes = StoredValue::from(storage::SudoAddressChangeFeeComponentsStorage::from(fees)) - .serialize() - .wrap_err("failed to serialize fees")?; - self.put_raw(keys::SUDO_ADDRESS_CHANGE.to_string(), bytes); - Ok(()) - } - - #[instrument(skip_all)] - fn put_ibc_sudo_change_fees(&mut self, fees: IbcSudoChangeFeeComponents) -> Result<()> { - let bytes = StoredValue::from(storage::IbcSudoChangeFeeComponentsStorage::from(fees)) + fn put_fees<'a, F>(&mut self, fees: FeeComponents) -> Result<()> + where + F: FeeHandler, + StoredValue<'a>: From>, + { + let bytes = StoredValue::from(fees) .serialize() .wrap_err("failed to serialize fees")?; - self.put_raw(keys::IBC_SUDO_CHANGE.to_string(), bytes); + self.put_raw(keys::name::(), bytes); Ok(()) } @@ -582,14 +216,18 @@ fn construct_tx_fee_event(fee: &Fee) -> Event { #[cfg(test)] mod tests { - use std::collections::HashSet; + use std::{ + collections::HashSet, + fmt::Debug, + }; - use astria_core::protocol::transaction::v1::action::Transfer; + use astria_core::protocol::transaction::v1::action::*; use cnidarium::StateDelta; use futures::{ StreamExt as _, TryStreamExt as _, }; + use penumbra_ibc::IbcRelay; use tokio::pin; use super::*; @@ -672,230 +310,90 @@ mod tests { ); } - #[tokio::test] - async fn transfer_fees_round_trip() { + async fn fees_round_trip<'a, F>() + where + F: FeeHandler, + FeeComponents: TryFrom, Error = Report> + Debug, + StoredValue<'a>: From>, + { let storage = cnidarium::TempStorage::new().await.unwrap(); let snapshot = storage.latest_snapshot(); let mut state = StateDelta::new(snapshot); - let fee_components = TransferFeeComponents { - base: 123, - multiplier: 1, - }; + let fee_components = FeeComponents::::new(123, 1); + state.put_fees(fee_components).unwrap(); + let retrieved_fees = state.get_fees().await.unwrap(); + assert_eq!(retrieved_fees, Some(fee_components)); + } - state.put_transfer_fees(fee_components).unwrap(); - let retrieved_fee = state.get_transfer_fees().await.unwrap(); - assert_eq!(retrieved_fee, Some(fee_components)); + #[tokio::test] + async fn transfer_fees_round_trip() { + fees_round_trip::().await; } #[tokio::test] async fn rollup_data_submission_fees_round_trip() { - let storage = cnidarium::TempStorage::new().await.unwrap(); - let snapshot = storage.latest_snapshot(); - let mut state = StateDelta::new(snapshot); - - let fee_components = RollupDataSubmissionFeeComponents { - base: 123, - multiplier: 1, - }; - - state - .put_rollup_data_submission_fees(fee_components) - .unwrap(); - let retrieved_fee = state.get_rollup_data_submission_fees().await.unwrap(); - assert_eq!(retrieved_fee, Some(fee_components)); + fees_round_trip::().await; } #[tokio::test] async fn ics20_withdrawal_fees_round_trip() { - let storage = cnidarium::TempStorage::new().await.unwrap(); - let snapshot = storage.latest_snapshot(); - let mut state = StateDelta::new(snapshot); - - let fee_components = Ics20WithdrawalFeeComponents { - base: 123, - multiplier: 1, - }; - - state.put_ics20_withdrawal_fees(fee_components).unwrap(); - let retrieved_fee = state.get_ics20_withdrawal_fees().await.unwrap(); - assert_eq!(retrieved_fee, Some(fee_components)); + fees_round_trip::().await; } #[tokio::test] async fn init_bridge_account_fees_round_trip() { - let storage = cnidarium::TempStorage::new().await.unwrap(); - let snapshot = storage.latest_snapshot(); - let mut state = StateDelta::new(snapshot); - - let fee_components = InitBridgeAccountFeeComponents { - base: 123, - multiplier: 1, - }; - - state.put_init_bridge_account_fees(fee_components).unwrap(); - let retrieved_fee = state.get_init_bridge_account_fees().await.unwrap(); - assert_eq!(retrieved_fee, Some(fee_components)); + fees_round_trip::().await; } #[tokio::test] async fn bridge_lock_fees_round_trip() { - let storage = cnidarium::TempStorage::new().await.unwrap(); - let snapshot = storage.latest_snapshot(); - let mut state = StateDelta::new(snapshot); - - let fee_components = BridgeLockFeeComponents { - base: 123, - multiplier: 1, - }; - - state.put_bridge_lock_fees(fee_components).unwrap(); - let retrieved_fee = state.get_bridge_lock_fees().await.unwrap(); - assert_eq!(retrieved_fee, Some(fee_components)); + fees_round_trip::().await; } #[tokio::test] async fn bridge_unlock_fees_round_trip() { - let storage = cnidarium::TempStorage::new().await.unwrap(); - let snapshot = storage.latest_snapshot(); - let mut state = StateDelta::new(snapshot); - - let fee_components = BridgeUnlockFeeComponents { - base: 123, - multiplier: 1, - }; - - state.put_bridge_unlock_fees(fee_components).unwrap(); - let retrieved_fee = state.get_bridge_unlock_fees().await.unwrap(); - assert_eq!(retrieved_fee, Some(fee_components)); + fees_round_trip::().await; } #[tokio::test] async fn bridge_sudo_change_fees_round_trip() { - let storage = cnidarium::TempStorage::new().await.unwrap(); - let snapshot = storage.latest_snapshot(); - let mut state = StateDelta::new(snapshot); - - let fee_components = BridgeSudoChangeFeeComponents { - base: 123, - multiplier: 1, - }; - - state.put_bridge_sudo_change_fees(fee_components).unwrap(); - let retrieved_fee = state.get_bridge_sudo_change_fees().await.unwrap(); - assert_eq!(retrieved_fee, Some(fee_components)); + fees_round_trip::().await; } #[tokio::test] async fn ibc_relay_fees_round_trip() { - let storage = cnidarium::TempStorage::new().await.unwrap(); - let snapshot = storage.latest_snapshot(); - let mut state = StateDelta::new(snapshot); - - let fee_components = IbcRelayFeeComponents { - base: 123, - multiplier: 1, - }; - - state.put_ibc_relay_fees(fee_components).unwrap(); - let retrieved_fee = state.get_ibc_relay_fees().await.unwrap(); - assert_eq!(retrieved_fee, Some(fee_components)); + fees_round_trip::().await; } #[tokio::test] async fn validator_update_fees_round_trip() { - let storage = cnidarium::TempStorage::new().await.unwrap(); - let snapshot = storage.latest_snapshot(); - let mut state = StateDelta::new(snapshot); - - let fee_components = ValidatorUpdateFeeComponents { - base: 123, - multiplier: 1, - }; - - state.put_validator_update_fees(fee_components).unwrap(); - let retrieved_fee = state.get_validator_update_fees().await.unwrap(); - assert_eq!(retrieved_fee, Some(fee_components)); + fees_round_trip::().await; } #[tokio::test] async fn fee_asset_change_fees_round_trip() { - let storage = cnidarium::TempStorage::new().await.unwrap(); - let snapshot = storage.latest_snapshot(); - let mut state = StateDelta::new(snapshot); - - let fee_components = FeeAssetChangeFeeComponents { - base: 123, - multiplier: 1, - }; - - state.put_fee_asset_change_fees(fee_components).unwrap(); - let retrieved_fee = state.get_fee_asset_change_fees().await.unwrap(); - assert_eq!(retrieved_fee, Some(fee_components)); + fees_round_trip::().await; } #[tokio::test] async fn fee_change_fees_round_trip() { - let storage = cnidarium::TempStorage::new().await.unwrap(); - let snapshot = storage.latest_snapshot(); - let mut state = StateDelta::new(snapshot); - - let fee_components = FeeChangeFeeComponents { - base: 123, - multiplier: 1, - }; - - state.put_fee_change_fees(fee_components).unwrap(); - let retrieved_fee = state.get_fee_change_fees().await.unwrap(); - assert_eq!(retrieved_fee, Some(fee_components)); + fees_round_trip::().await; } #[tokio::test] async fn ibc_relayer_change_fees_round_trip() { - let storage = cnidarium::TempStorage::new().await.unwrap(); - let snapshot = storage.latest_snapshot(); - let mut state = StateDelta::new(snapshot); - - let fee_components = IbcRelayerChangeFeeComponents { - base: 123, - multiplier: 1, - }; - - state.put_ibc_relayer_change_fees(fee_components).unwrap(); - let retrieved_fee = state.get_ibc_relayer_change_fees().await.unwrap(); - assert_eq!(retrieved_fee, Some(fee_components)); + fees_round_trip::().await; } #[tokio::test] async fn sudo_address_change_fees_round_trip() { - let storage = cnidarium::TempStorage::new().await.unwrap(); - let snapshot = storage.latest_snapshot(); - let mut state = StateDelta::new(snapshot); - - let fee_components = SudoAddressChangeFeeComponents { - base: 123, - multiplier: 1, - }; - - state.put_sudo_address_change_fees(fee_components).unwrap(); - let retrieved_fee = state.get_sudo_address_change_fees().await.unwrap(); - assert_eq!(retrieved_fee, Some(fee_components)); + fees_round_trip::().await; } #[tokio::test] async fn ibc_sudo_change_fees_round_trip() { - let storage = cnidarium::TempStorage::new().await.unwrap(); - let snapshot = storage.latest_snapshot(); - let mut state = StateDelta::new(snapshot); - - let fee_components = IbcSudoChangeFeeComponents { - base: 123, - multiplier: 1, - }; - - state.put_ibc_sudo_change_fees(fee_components).unwrap(); - let retrieved_fee = state.get_ibc_sudo_change_fees().await.unwrap(); - assert_eq!(retrieved_fee, Some(fee_components)); + fees_round_trip::().await; } #[tokio::test] diff --git a/crates/astria-sequencer/src/fees/storage/keys.rs b/crates/astria-sequencer/src/fees/storage/keys.rs index 946c9fbef5..b9584a9004 100644 --- a/crates/astria-sequencer/src/fees/storage/keys.rs +++ b/crates/astria-sequencer/src/fees/storage/keys.rs @@ -7,24 +7,16 @@ use astria_eyre::eyre::{ Context as _, }; -use crate::storage::keys::Asset; - -pub(in crate::fees) const TRANSFER: &str = "fees/transfer"; -pub(in crate::fees) const ICS20_WITHDRAWAL: &str = "fees/ics20_withdrawal"; -pub(in crate::fees) const INIT_BRIDGE_ACCOUNT: &str = "fees/init_bridge_account"; -pub(in crate::fees) const BRIDGE_LOCK: &str = "fees/bridge_lock"; -pub(in crate::fees) const BRIDGE_UNLOCK: &str = "fees/bridge_unlock"; -pub(in crate::fees) const BRIDGE_SUDO_CHANGE: &str = "fees/bridge_sudo_change"; -pub(in crate::fees) const IBC_RELAY: &str = "fees/ibc_relay"; -pub(in crate::fees) const VALIDATOR_UPDATE: &str = "fees/validator_update"; -pub(in crate::fees) const FEE_ASSET_CHANGE: &str = "fees/fee_asset_change"; -pub(in crate::fees) const FEE_CHANGE: &str = "fees/fee_change"; -pub(in crate::fees) const IBC_RELAYER_CHANGE: &str = "fees/ibc_relayer_change"; -pub(in crate::fees) const ROLLUP_DATA_SUBMISSION: &str = "fees/rollup_data_submission"; -pub(in crate::fees) const SUDO_ADDRESS_CHANGE: &str = "fees/sudo_address_change"; -pub(in crate::fees) const IBC_SUDO_CHANGE: &str = "fees/ibc_sudo_change"; +use crate::{ + fees::FeeHandler, + storage::keys::Asset, +}; + pub(in crate::fees) const BLOCK: &str = "fees/block"; // NOTE: `BLOCK` is only used in the ephemeral store. pub(in crate::fees) const ALLOWED_ASSET_PREFIX: &str = "fees/allowed_asset/"; +pub(in crate::fees) fn name() -> String { + format!("fees/{}", F::snake_case_name()) +} pub(in crate::fees) fn allowed_asset<'a, TAsset>(asset: &'a TAsset) -> String where @@ -51,8 +43,26 @@ fn extract_asset_from_key(key: &str, prefix: &str) -> eyre::Result #[cfg(test)] mod tests { - use astria_core::primitive::v1::asset::Denom; + use astria_core::{ + primitive::v1::asset::Denom, + protocol::transaction::v1::action::{ + BridgeLock, + BridgeSudoChange, + BridgeUnlock, + FeeAssetChange, + FeeChange, + IbcRelayerChange, + IbcSudoChange, + Ics20Withdrawal, + InitBridgeAccount, + RollupDataSubmission, + SudoAddressChange, + Transfer, + ValidatorUpdate, + }, + }; use insta::assert_snapshot; + use penumbra_ibc::IbcRelay; use super::*; @@ -64,42 +74,46 @@ mod tests { #[test] fn keys_should_not_change() { - // NOTE: This helper struct is just to avoid having 14 snapshot files to contend with. // NOTE: `BLOCK` is only used in the ephemeral store, so isn't included here. - assert_snapshot!("bridge_lock_fees_key", BRIDGE_LOCK); - assert_snapshot!("bridge_sudo_change_fees_key", BRIDGE_SUDO_CHANGE); - assert_snapshot!("bridge_unlock_fees_key", BRIDGE_UNLOCK); - assert_snapshot!("fee_asset_change_fees_key", FEE_ASSET_CHANGE); + + fn check() { + assert_snapshot!(format!("{}_fees_key", F::snake_case_name()), name::()); + } + + check::(); + check::(); + check::(); + check::(); + check::(); + check::(); + check::(); + check::(); + check::(); + check::(); + check::(); + check::(); + check::(); + check::(); assert_snapshot!("allowed_asset_prefix", ALLOWED_ASSET_PREFIX); - assert_snapshot!("fee_change_fees_key", FEE_CHANGE); - assert_snapshot!("ibc_relay_fees_key", IBC_RELAY); - assert_snapshot!("ibc_relayer_change_fees_key", IBC_RELAYER_CHANGE); - assert_snapshot!("ibc_sudo_change_fees_key", IBC_SUDO_CHANGE); - assert_snapshot!("ics20_withdrawal_fees_key", ICS20_WITHDRAWAL); - assert_snapshot!("init_bridge_account_fees_key", INIT_BRIDGE_ACCOUNT); - assert_snapshot!("rollup_data_submission_fees_key", ROLLUP_DATA_SUBMISSION); - assert_snapshot!("sudo_address_change_fees_key", SUDO_ADDRESS_CHANGE); - assert_snapshot!("transer_fees_key", TRANSFER); - assert_snapshot!("validator_update_fees_key", VALIDATOR_UPDATE); assert_snapshot!("allowed_asset_key", allowed_asset(&test_asset())); } #[test] fn keys_should_have_component_prefix() { - assert!(TRANSFER.starts_with(COMPONENT_PREFIX)); - assert!(ROLLUP_DATA_SUBMISSION.starts_with(COMPONENT_PREFIX)); - assert!(ICS20_WITHDRAWAL.starts_with(COMPONENT_PREFIX)); - assert!(INIT_BRIDGE_ACCOUNT.starts_with(COMPONENT_PREFIX)); - assert!(BRIDGE_LOCK.starts_with(COMPONENT_PREFIX)); - assert!(BRIDGE_UNLOCK.starts_with(COMPONENT_PREFIX)); - assert!(BRIDGE_SUDO_CHANGE.starts_with(COMPONENT_PREFIX)); - assert!(IBC_RELAY.starts_with(COMPONENT_PREFIX)); - assert!(VALIDATOR_UPDATE.starts_with(COMPONENT_PREFIX)); - assert!(FEE_ASSET_CHANGE.starts_with(COMPONENT_PREFIX)); - assert!(FEE_CHANGE.starts_with(COMPONENT_PREFIX)); - assert!(IBC_RELAYER_CHANGE.starts_with(COMPONENT_PREFIX)); - assert!(SUDO_ADDRESS_CHANGE.starts_with(COMPONENT_PREFIX)); - assert!(IBC_SUDO_CHANGE.starts_with(COMPONENT_PREFIX)); + assert!(name::().starts_with(COMPONENT_PREFIX)); + assert!(name::().starts_with(COMPONENT_PREFIX)); + assert!(name::().starts_with(COMPONENT_PREFIX)); + assert!(name::().starts_with(COMPONENT_PREFIX)); + assert!(name::().starts_with(COMPONENT_PREFIX)); + assert!(name::().starts_with(COMPONENT_PREFIX)); + assert!(name::().starts_with(COMPONENT_PREFIX)); + assert!(name::().starts_with(COMPONENT_PREFIX)); + assert!(name::().starts_with(COMPONENT_PREFIX)); + assert!(name::().starts_with(COMPONENT_PREFIX)); + assert!(name::().starts_with(COMPONENT_PREFIX)); + assert!(name::().starts_with(COMPONENT_PREFIX)); + assert!(name::().starts_with(COMPONENT_PREFIX)); + assert!(name::().starts_with(COMPONENT_PREFIX)); assert!(ALLOWED_ASSET_PREFIX.starts_with(COMPONENT_PREFIX)); assert!(allowed_asset(&test_asset()).starts_with(COMPONENT_PREFIX)); } diff --git a/crates/astria-sequencer/src/fees/storage/mod.rs b/crates/astria-sequencer/src/fees/storage/mod.rs index 2de95a747b..df15ffb7a2 100644 --- a/crates/astria-sequencer/src/fees/storage/mod.rs +++ b/crates/astria-sequencer/src/fees/storage/mod.rs @@ -2,19 +2,3 @@ pub(super) mod keys; mod values; pub(crate) use values::Value; -pub(super) use values::{ - BridgeLockFeeComponentsStorage, - BridgeSudoChangeFeeComponentsStorage, - BridgeUnlockFeeComponentsStorage, - FeeAssetChangeFeeComponentsStorage, - FeeChangeFeeComponentsStorage, - IbcRelayFeeComponentsStorage, - IbcRelayerChangeFeeComponentsStorage, - IbcSudoChangeFeeComponentsStorage, - Ics20WithdrawalFeeComponentsStorage, - InitBridgeAccountFeeComponentsStorage, - RollupDataSubmissionFeeComponentsStorage, - SudoAddressChangeFeeComponentsStorage, - TransferFeeComponentsStorage, - ValidatorUpdateFeeComponentsStorage, -}; diff --git a/crates/astria-sequencer/src/fees/storage/snapshots/astria_sequencer__fees__storage__keys__tests__transer_fees_key.snap b/crates/astria-sequencer/src/fees/storage/snapshots/astria_sequencer__fees__storage__keys__tests__transfer_fees_key.snap similarity index 100% rename from crates/astria-sequencer/src/fees/storage/snapshots/astria_sequencer__fees__storage__keys__tests__transer_fees_key.snap rename to crates/astria-sequencer/src/fees/storage/snapshots/astria_sequencer__fees__storage__keys__tests__transfer_fees_key.snap diff --git a/crates/astria-sequencer/src/fees/storage/values.rs b/crates/astria-sequencer/src/fees/storage/values.rs index c3dcc9fbe1..138b2f8cbd 100644 --- a/crates/astria-sequencer/src/fees/storage/values.rs +++ b/crates/astria-sequencer/src/fees/storage/values.rs @@ -1,24 +1,27 @@ -use astria_core::protocol::fees::v1::{ - BridgeLockFeeComponents, - BridgeSudoChangeFeeComponents, - BridgeUnlockFeeComponents, - FeeAssetChangeFeeComponents, - FeeChangeFeeComponents, - IbcRelayFeeComponents, - IbcRelayerChangeFeeComponents, - IbcSudoChangeFeeComponents, - Ics20WithdrawalFeeComponents, - InitBridgeAccountFeeComponents, - RollupDataSubmissionFeeComponents, - SudoAddressChangeFeeComponents, - TransferFeeComponents, - ValidatorUpdateFeeComponents, +use astria_core::protocol::{ + fees::v1::FeeComponents as DomainFeeComponents, + transaction::v1::action::{ + BridgeLock, + BridgeSudoChange, + BridgeUnlock, + FeeAssetChange, + FeeChange, + IbcRelayerChange, + IbcSudoChange, + Ics20Withdrawal, + InitBridgeAccount, + RollupDataSubmission, + SudoAddressChange, + Transfer, + ValidatorUpdate, + }, }; use astria_eyre::eyre::bail; use borsh::{ BorshDeserialize, BorshSerialize, }; +use penumbra_ibc::IbcRelay; #[derive(Debug, BorshSerialize, BorshDeserialize)] pub(crate) struct Value(ValueImpl); @@ -29,178 +32,81 @@ pub(crate) struct Value(ValueImpl); reason = "want to make it clear that these are fees and not actions" )] enum ValueImpl { - TransferFees(TransferFeeComponentsStorage), - SequenceFees(RollupDataSubmissionFeeComponentsStorage), - Ics20WithdrawalFees(Ics20WithdrawalFeeComponentsStorage), - InitBridgeAccountFees(InitBridgeAccountFeeComponentsStorage), - BridgeLockFees(BridgeLockFeeComponentsStorage), - BridgeUnlockFees(BridgeUnlockFeeComponentsStorage), - BridgeSudoChangeFees(BridgeSudoChangeFeeComponentsStorage), - IbcRelayFees(IbcRelayFeeComponentsStorage), - ValidatorUpdateFees(ValidatorUpdateFeeComponentsStorage), - FeeAssetChangeFees(FeeAssetChangeFeeComponentsStorage), - FeeChangeFees(FeeChangeFeeComponentsStorage), - IbcRelayerChangeFees(IbcRelayerChangeFeeComponentsStorage), - IbcSudoChangeFees(IbcSudoChangeFeeComponentsStorage), - SudoAddressChangeFees(SudoAddressChangeFeeComponentsStorage), -} - -macro_rules! impl_from_for_fee_component{ - ( $( $domain_ty:ty => $storage_ty:ty),* $(,)? ) => { - $( - impl From<$domain_ty> for $storage_ty { - fn from(val: $domain_ty) -> Self { - Self{base: val.base, multiplier: val.multiplier} - } - } - impl From<$storage_ty> for $domain_ty { - fn from(val: $storage_ty) -> Self { - Self{base: val.base, multiplier: val.multiplier} - } - } - )* - } + TransferFees(FeeComponents), + RollupDataSubmissionFees(FeeComponents), + Ics20WithdrawalFees(FeeComponents), + InitBridgeAccountFees(FeeComponents), + BridgeLockFees(FeeComponents), + BridgeUnlockFees(FeeComponents), + BridgeSudoChangeFees(FeeComponents), + IbcRelayFees(FeeComponents), + ValidatorUpdateFees(FeeComponents), + FeeAssetChangeFees(FeeComponents), + FeeChangeFees(FeeComponents), + IbcRelayerChangeFees(FeeComponents), + IbcSudoChangeFees(FeeComponents), + SudoAddressChangeFees(FeeComponents), } macro_rules! impl_from_for_fee_storage { - ( $( $storage_ty:ty => $value_impl:ident),* $(,)? ) => { + ( $( $domain_ty:ty => $value_impl:ident),* $(,)? ) => { $( - impl<'a> From<$storage_ty> for crate::storage::StoredValue<'a> { - fn from(fees: $storage_ty) -> Self { - crate::storage::StoredValue::Fees(Value(ValueImpl::$value_impl(fees))) + impl<'a> From<$domain_ty> for crate::storage::StoredValue<'a> { + fn from(fees: $domain_ty) -> Self { + crate::storage::StoredValue::Fees(Value(ValueImpl::$value_impl(fees.into()))) } } - impl<'a> TryFrom> for $storage_ty { + impl<'a> TryFrom> for $domain_ty { type Error = astria_eyre::eyre::Error; - fn try_from(value: crate::storage::StoredValue<'a>) -> Result { - let crate::storage::StoredValue::Fees(Value(ValueImpl::$value_impl(fees))) = value else { - let value_impl_ty = concat!("ValueImpl::", stringify!($value_impl)); - bail!( - "fees stored value type mismatch: expected {value_impl_ty}, found {value:?}" - ); - }; - Ok(fees) - } + fn try_from(value: crate::storage::StoredValue<'a>) -> Result { + let crate::storage::StoredValue::Fees(Value(ValueImpl::$value_impl(fees))) = value else { + let value_impl_ty = concat!("ValueImpl::", stringify!($value_impl)); + bail!( + "fees stored value type mismatch: expected {value_impl_ty}, found {value:?}" + ); + }; + Ok(fees.into()) + } } )* } } #[derive(Debug, BorshSerialize, BorshDeserialize)] -pub(in crate::fees) struct TransferFeeComponentsStorage { - pub base: u128, - pub multiplier: u128, -} - -#[derive(Debug, BorshSerialize, BorshDeserialize)] -pub(in crate::fees) struct RollupDataSubmissionFeeComponentsStorage { - pub base: u128, - pub multiplier: u128, -} - -#[derive(Debug, BorshSerialize, BorshDeserialize)] -pub(in crate::fees) struct Ics20WithdrawalFeeComponentsStorage { - pub base: u128, - pub multiplier: u128, -} - -#[derive(Debug, BorshSerialize, BorshDeserialize)] -pub(in crate::fees) struct InitBridgeAccountFeeComponentsStorage { - pub base: u128, - pub multiplier: u128, -} - -#[derive(Debug, BorshSerialize, BorshDeserialize)] -pub(in crate::fees) struct BridgeLockFeeComponentsStorage { - pub base: u128, - pub multiplier: u128, -} - -#[derive(Debug, BorshSerialize, BorshDeserialize)] -pub(in crate::fees) struct BridgeUnlockFeeComponentsStorage { - pub base: u128, - pub multiplier: u128, -} - -#[derive(Debug, BorshSerialize, BorshDeserialize)] -pub(in crate::fees) struct BridgeSudoChangeFeeComponentsStorage { - pub base: u128, - pub multiplier: u128, -} - -#[derive(Debug, BorshSerialize, BorshDeserialize)] -pub(in crate::fees) struct IbcRelayFeeComponentsStorage { - pub base: u128, - pub multiplier: u128, -} - -#[derive(Debug, BorshSerialize, BorshDeserialize)] -pub(in crate::fees) struct ValidatorUpdateFeeComponentsStorage { - pub base: u128, - pub multiplier: u128, -} - -#[derive(Debug, BorshSerialize, BorshDeserialize)] -pub(in crate::fees) struct FeeAssetChangeFeeComponentsStorage { - pub base: u128, - pub multiplier: u128, -} - -#[derive(Debug, BorshSerialize, BorshDeserialize)] -pub(in crate::fees) struct FeeChangeFeeComponentsStorage { - pub base: u128, - pub multiplier: u128, -} - -#[derive(Debug, BorshSerialize, BorshDeserialize)] -pub(in crate::fees) struct IbcRelayerChangeFeeComponentsStorage { +pub(in crate::fees) struct FeeComponents { pub base: u128, pub multiplier: u128, } -#[derive(Debug, BorshSerialize, BorshDeserialize)] -pub(in crate::fees) struct IbcSudoChangeFeeComponentsStorage { - pub base: u128, - pub multiplier: u128, +impl From> for FeeComponents { + fn from(fees: DomainFeeComponents) -> Self { + Self { + base: fees.base(), + multiplier: fees.multiplier(), + } + } } -#[derive(Debug, BorshSerialize, BorshDeserialize)] -pub(in crate::fees) struct SudoAddressChangeFeeComponentsStorage { - pub base: u128, - pub multiplier: u128, +impl From for DomainFeeComponents { + fn from(fees: FeeComponents) -> Self { + Self::new(fees.base, fees.multiplier) + } } -impl_from_for_fee_component!( - TransferFeeComponents => TransferFeeComponentsStorage, - RollupDataSubmissionFeeComponents => RollupDataSubmissionFeeComponentsStorage, - Ics20WithdrawalFeeComponents => Ics20WithdrawalFeeComponentsStorage, - InitBridgeAccountFeeComponents => InitBridgeAccountFeeComponentsStorage, - BridgeLockFeeComponents => BridgeLockFeeComponentsStorage, - BridgeUnlockFeeComponents => BridgeUnlockFeeComponentsStorage, - BridgeSudoChangeFeeComponents => BridgeSudoChangeFeeComponentsStorage, - IbcRelayFeeComponents => IbcRelayFeeComponentsStorage, - ValidatorUpdateFeeComponents => ValidatorUpdateFeeComponentsStorage, - FeeAssetChangeFeeComponents => FeeAssetChangeFeeComponentsStorage, - FeeChangeFeeComponents => FeeChangeFeeComponentsStorage, - IbcRelayerChangeFeeComponents => IbcRelayerChangeFeeComponentsStorage, - IbcSudoChangeFeeComponents => IbcSudoChangeFeeComponentsStorage, - SudoAddressChangeFeeComponents => SudoAddressChangeFeeComponentsStorage, -); - impl_from_for_fee_storage!( - TransferFeeComponentsStorage => TransferFees, - RollupDataSubmissionFeeComponentsStorage => SequenceFees, - Ics20WithdrawalFeeComponentsStorage => Ics20WithdrawalFees, - InitBridgeAccountFeeComponentsStorage => InitBridgeAccountFees, - BridgeLockFeeComponentsStorage => BridgeLockFees, - BridgeUnlockFeeComponentsStorage => BridgeUnlockFees, - BridgeSudoChangeFeeComponentsStorage => BridgeSudoChangeFees, - IbcRelayFeeComponentsStorage => IbcRelayFees, - ValidatorUpdateFeeComponentsStorage => ValidatorUpdateFees, - FeeAssetChangeFeeComponentsStorage => FeeAssetChangeFees, - FeeChangeFeeComponentsStorage => FeeChangeFees, - IbcRelayerChangeFeeComponentsStorage => IbcRelayerChangeFees, - IbcSudoChangeFeeComponentsStorage => IbcSudoChangeFees, - SudoAddressChangeFeeComponentsStorage => SudoAddressChangeFees, + DomainFeeComponents => TransferFees, + DomainFeeComponents => RollupDataSubmissionFees, + DomainFeeComponents => Ics20WithdrawalFees, + DomainFeeComponents => InitBridgeAccountFees, + DomainFeeComponents => BridgeLockFees, + DomainFeeComponents => BridgeUnlockFees, + DomainFeeComponents => BridgeSudoChangeFees, + DomainFeeComponents => IbcRelayFees, + DomainFeeComponents => ValidatorUpdateFees, + DomainFeeComponents => FeeAssetChangeFees, + DomainFeeComponents => FeeChangeFees, + DomainFeeComponents => IbcRelayerChangeFees, + DomainFeeComponents => IbcSudoChangeFees, + DomainFeeComponents => SudoAddressChangeFees, ); diff --git a/crates/astria-sequencer/src/fees/tests.rs b/crates/astria-sequencer/src/fees/tests.rs index ca43c492c9..8a6f2202ff 100644 --- a/crates/astria-sequencer/src/fees/tests.rs +++ b/crates/astria-sequencer/src/fees/tests.rs @@ -11,13 +11,7 @@ use astria_core::{ TRANSACTION_ID_LEN, }, protocol::{ - fees::v1::{ - BridgeLockFeeComponents, - BridgeSudoChangeFeeComponents, - InitBridgeAccountFeeComponents, - RollupDataSubmissionFeeComponents, - TransferFeeComponents, - }, + fees::v1::FeeComponents, transaction::v1::{ action::{ BridgeLock, @@ -80,10 +74,7 @@ async fn ensure_correct_block_fees_transfer() { let mut state = StateDelta::new(snapshot); let transfer_base = 1; state - .put_transfer_fees(TransferFeeComponents { - base: transfer_base, - multiplier: 0, - }) + .put_fees(FeeComponents::::new(transfer_base, 0)) .unwrap(); let alice = get_alice_signing_key(); @@ -120,10 +111,7 @@ async fn ensure_correct_block_fees_sequence() { let snapshot = storage.latest_snapshot(); let mut state = StateDelta::new(snapshot); state - .put_rollup_data_submission_fees(RollupDataSubmissionFeeComponents { - base: 1, - multiplier: 1, - }) + .put_fees(FeeComponents::::new(1, 1)) .unwrap(); let alice = get_alice_signing_key(); @@ -161,10 +149,10 @@ async fn ensure_correct_block_fees_init_bridge_acct() { let mut state = StateDelta::new(snapshot); let init_bridge_account_base = 1; state - .put_init_bridge_account_fees(InitBridgeAccountFeeComponents { - base: init_bridge_account_base, - multiplier: 0, - }) + .put_fees(FeeComponents::::new( + init_bridge_account_base, + 0, + )) .unwrap(); let alice = get_alice_signing_key(); @@ -212,16 +200,13 @@ async fn ensure_correct_block_fees_bridge_lock() { let bridge_lock_byte_cost_multiplier = 1; state - .put_transfer_fees(TransferFeeComponents { - base: transfer_base, - multiplier: 0, - }) + .put_fees(FeeComponents::::new(transfer_base, 0)) .unwrap(); state - .put_bridge_lock_fees(BridgeLockFeeComponents { - base: transfer_base, - multiplier: bridge_lock_byte_cost_multiplier, - }) + .put_fees(FeeComponents::::new( + transfer_base, + bridge_lock_byte_cost_multiplier, + )) .unwrap(); state .put_bridge_account_rollup_id(&bridge_address, rollup_id) @@ -283,10 +268,7 @@ async fn ensure_correct_block_fees_bridge_sudo_change() { let sudo_change_base = 1; state - .put_bridge_sudo_change_fees(BridgeSudoChangeFeeComponents { - base: sudo_change_base, - multiplier: 0, - }) + .put_fees(FeeComponents::::new(sudo_change_base, 0)) .unwrap(); state .put_bridge_account_sudo_address(&bridge_address, alice_address) @@ -338,17 +320,12 @@ async fn bridge_lock_fee_calculation_works_as_expected() { }); state.put_base_prefix(ASTRIA_PREFIX.to_string()).unwrap(); - let transfer_fees = TransferFeeComponents { - base: transfer_fee, - multiplier: 0, - }; - state.put_transfer_fees(transfer_fees).unwrap(); - - let bridge_lock_fees = BridgeLockFeeComponents { - base: transfer_fee, - multiplier: 2, - }; - state.put_bridge_lock_fees(bridge_lock_fees).unwrap(); + state + .put_fees(FeeComponents::::new(transfer_fee, 0)) + .unwrap(); + state + .put_fees(FeeComponents::::new(transfer_fee, 2)) + .unwrap(); let bridge_address = astria_address(&[1; 20]); let asset = test_asset(); diff --git a/crates/astria-sequencer/src/service/info/mod.rs b/crates/astria-sequencer/src/service/info/mod.rs index 6254f58632..e093514cae 100644 --- a/crates/astria-sequencer/src/service/info/mod.rs +++ b/crates/astria-sequencer/src/service/info/mod.rs @@ -175,21 +175,21 @@ mod tests { protocol::{ account::v1::BalanceResponse, asset::v1::DenomResponse, - fees::v1::{ - BridgeLockFeeComponents, - BridgeSudoChangeFeeComponents, - BridgeUnlockFeeComponents, - FeeAssetChangeFeeComponents, - FeeChangeFeeComponents, - IbcRelayFeeComponents, - IbcRelayerChangeFeeComponents, - IbcSudoChangeFeeComponents, - Ics20WithdrawalFeeComponents, - InitBridgeAccountFeeComponents, - RollupDataSubmissionFeeComponents, - SudoAddressChangeFeeComponents, - TransferFeeComponents, - ValidatorUpdateFeeComponents, + fees::v1::FeeComponents, + transaction::v1::action::{ + BridgeLock, + BridgeSudoChange, + BridgeUnlock, + FeeAssetChange, + FeeChange, + IbcRelayerChange, + IbcSudoChange, + Ics20Withdrawal, + InitBridgeAccount, + RollupDataSubmission, + SudoAddressChange, + Transfer, + ValidatorUpdate, }, }, }; @@ -197,14 +197,10 @@ mod tests { StateDelta, StateWrite, }; + use penumbra_ibc::IbcRelay; use prost::Message as _; - use tendermint::v0_38::abci::{ - request, - InfoRequest, - InfoResponse, - }; - use super::Info; + use super::*; use crate::{ accounts::StateWriteExt as _, address::{ @@ -497,88 +493,46 @@ mod tests { fn write_all_the_fees(mut state: S) { state - .put_bridge_lock_fees(BridgeLockFeeComponents { - base: 1, - multiplier: 1, - }) + .put_fees(FeeComponents::::new(1, 1)) .unwrap(); state - .put_bridge_unlock_fees(BridgeUnlockFeeComponents { - base: 2, - multiplier: 2, - }) + .put_fees(FeeComponents::::new(2, 2)) .unwrap(); state - .put_bridge_sudo_change_fees(BridgeSudoChangeFeeComponents { - base: 3, - multiplier: 3, - }) + .put_fees(FeeComponents::::new(3, 3)) .unwrap(); state - .put_fee_asset_change_fees(FeeAssetChangeFeeComponents { - base: 4, - multiplier: 4, - }) + .put_fees(FeeComponents::::new(4, 4)) .unwrap(); state - .put_fee_change_fees(FeeChangeFeeComponents { - base: 5, - multiplier: 5, - }) + .put_fees(FeeComponents::::new(5, 5)) .unwrap(); state - .put_init_bridge_account_fees(InitBridgeAccountFeeComponents { - base: 6, - multiplier: 6, - }) + .put_fees(FeeComponents::::new(6, 6)) .unwrap(); state - .put_ibc_relay_fees(IbcRelayFeeComponents { - base: 7, - multiplier: 7, - }) + .put_fees(FeeComponents::::new(7, 7)) .unwrap(); state - .put_ibc_relayer_change_fees(IbcRelayerChangeFeeComponents { - base: 8, - multiplier: 8, - }) + .put_fees(FeeComponents::::new(8, 8)) .unwrap(); state - .put_ibc_sudo_change_fees(IbcSudoChangeFeeComponents { - base: 9, - multiplier: 9, - }) + .put_fees(FeeComponents::::new(9, 9)) .unwrap(); state - .put_ics20_withdrawal_fees(Ics20WithdrawalFeeComponents { - base: 10, - multiplier: 10, - }) + .put_fees(FeeComponents::::new(10, 10)) .unwrap(); state - .put_rollup_data_submission_fees(RollupDataSubmissionFeeComponents { - base: 11, - multiplier: 11, - }) + .put_fees(FeeComponents::::new(11, 11)) .unwrap(); state - .put_sudo_address_change_fees(SudoAddressChangeFeeComponents { - base: 12, - multiplier: 12, - }) + .put_fees(FeeComponents::::new(12, 12)) .unwrap(); state - .put_transfer_fees(TransferFeeComponents { - base: 13, - multiplier: 13, - }) + .put_fees(FeeComponents::::new(13, 13)) .unwrap(); state - .put_validator_update_fees(ValidatorUpdateFeeComponents { - base: 14, - multiplier: 14, - }) + .put_fees(FeeComponents::::new(14, 14)) .unwrap(); } } diff --git a/crates/astria-sequencer/src/test_utils.rs b/crates/astria-sequencer/src/test_utils.rs index 65c2ff327f..d9d7934239 100644 --- a/crates/astria-sequencer/src/test_utils.rs +++ b/crates/astria-sequencer/src/test_utils.rs @@ -1,9 +1,10 @@ -use astria_core::primitive::v1::{ - Address, - Bech32, +use astria_core::{ + primitive::v1::{ + Address, + Bech32, + }, + protocol::transaction::v1::action::RollupDataSubmission, }; -#[cfg(test)] -use astria_core::protocol::fees::v1::RollupDataSubmissionFeeComponents; use crate::benchmark_and_test_utils::ASTRIA_COMPAT_PREFIX; @@ -29,22 +30,20 @@ pub(crate) async fn calculate_rollup_data_submission_fee_from_state< data: &[u8], state: &S, ) -> u128 { - let RollupDataSubmissionFeeComponents { - base, - multiplier, - } = state - .get_rollup_data_submission_fees() + let fees = state + .get_fees::() .await .expect("should not error fetching rollup data submission fees") .expect("rollup data submission fees should be stored"); - base.checked_add( - multiplier - .checked_mul( - data.len() - .try_into() - .expect("a usize should always convert to a u128"), - ) - .expect("fee multiplication should not overflow"), - ) - .expect("fee addition should not overflow") + fees.base() + .checked_add( + fees.multiplier() + .checked_mul( + data.len() + .try_into() + .expect("a usize should always convert to a u128"), + ) + .expect("fee multiplication should not overflow"), + ) + .expect("fee addition should not overflow") } diff --git a/crates/astria-sequencer/src/transaction/checks.rs b/crates/astria-sequencer/src/transaction/checks.rs index 3e00c7b0f4..bff86e838e 100644 --- a/crates/astria-sequencer/src/transaction/checks.rs +++ b/crates/astria-sequencer/src/transaction/checks.rs @@ -132,17 +132,14 @@ mod tests { ADDRESS_LEN, }, protocol::{ - fees::v1::{ - BridgeLockFeeComponents, - BridgeSudoChangeFeeComponents, - BridgeUnlockFeeComponents, - Ics20WithdrawalFeeComponents, - InitBridgeAccountFeeComponents, - RollupDataSubmissionFeeComponents, - TransferFeeComponents, - }, + fees::v1::FeeComponents, transaction::v1::{ action::{ + BridgeLock, + BridgeSudoChange, + BridgeUnlock, + Ics20Withdrawal, + InitBridgeAccount, RollupDataSubmission, Transfer, }, @@ -174,7 +171,6 @@ mod tests { }; #[tokio::test] - #[expect(clippy::too_many_lines, reason = "it's a test")] async fn check_balance_total_fees_transfers_ok() { let storage = cnidarium::TempStorage::new().await.unwrap(); let snapshot = storage.latest_snapshot(); @@ -182,67 +178,26 @@ mod tests { state_tx.put_base_prefix("astria".to_string()).unwrap(); state_tx.put_native_asset(nria()).unwrap(); - let transfer_fees = TransferFeeComponents { - base: 12, - multiplier: 0, - }; state_tx - .put_transfer_fees(transfer_fees) - .wrap_err("failed to initiate transfer fee components") + .put_fees(FeeComponents::::new(12, 0)) .unwrap(); - - let rollup_data_submission_fees = RollupDataSubmissionFeeComponents { - base: 0, - multiplier: 1, - }; state_tx - .put_rollup_data_submission_fees(rollup_data_submission_fees) - .wrap_err("failed to initiate sequence action fee components") + .put_fees(FeeComponents::::new(0, 1)) .unwrap(); - - let ics20_withdrawal_fees = Ics20WithdrawalFeeComponents { - base: 1, - multiplier: 0, - }; state_tx - .put_ics20_withdrawal_fees(ics20_withdrawal_fees) - .wrap_err("failed to initiate ics20 withdrawal fee components") + .put_fees(FeeComponents::::new(1, 0)) .unwrap(); - - let init_bridge_account_fees = InitBridgeAccountFeeComponents { - base: 12, - multiplier: 0, - }; state_tx - .put_init_bridge_account_fees(init_bridge_account_fees) - .wrap_err("failed to initiate init bridge account fee components") + .put_fees(FeeComponents::::new(12, 0)) .unwrap(); - - let bridge_lock_fees = BridgeLockFeeComponents { - base: 0, - multiplier: 1, - }; state_tx - .put_bridge_lock_fees(bridge_lock_fees) - .wrap_err("failed to initiate bridge lock fee components") + .put_fees(FeeComponents::::new(0, 1)) .unwrap(); - - let bridge_unlock_fees = BridgeUnlockFeeComponents { - base: 0, - multiplier: 0, - }; state_tx - .put_bridge_unlock_fees(bridge_unlock_fees) - .wrap_err("failed to initiate bridge unlock fee components") + .put_fees(FeeComponents::::new(0, 0)) .unwrap(); - - let bridge_sudo_change_fees = BridgeSudoChangeFeeComponents { - base: 24, - multiplier: 0, - }; state_tx - .put_bridge_sudo_change_fees(bridge_sudo_change_fees) - .wrap_err("failed to initiate bridge sudo change fee components") + .put_fees(FeeComponents::::new(24, 0)) .unwrap(); let other_asset = "other".parse::().unwrap(); @@ -251,11 +206,11 @@ mod tests { let amount = 100; let data = Bytes::from_static(&[0; 32]); let transfer_fee = state_tx - .get_transfer_fees() + .get_fees::() .await .expect("should not error fetching transfer fees") .expect("transfer fees should be stored") - .base; + .base(); state_tx .increase_balance( &state_tx @@ -307,7 +262,6 @@ mod tests { } #[tokio::test] - #[expect(clippy::too_many_lines, reason = "it's a test")] async fn check_balance_total_fees_and_transfers_insufficient_other_asset_balance() { let storage = cnidarium::TempStorage::new().await.unwrap(); let snapshot = storage.latest_snapshot(); @@ -315,67 +269,26 @@ mod tests { state_tx.put_base_prefix(ASTRIA_PREFIX.to_string()).unwrap(); state_tx.put_native_asset(nria()).unwrap(); - let transfer_fees = TransferFeeComponents { - base: 12, - multiplier: 0, - }; state_tx - .put_transfer_fees(transfer_fees) - .wrap_err("failed to initiate transfer fee components") + .put_fees(FeeComponents::::new(12, 0)) .unwrap(); - - let rollup_data_submission_fees = RollupDataSubmissionFeeComponents { - base: 0, - multiplier: 1, - }; state_tx - .put_rollup_data_submission_fees(rollup_data_submission_fees) - .wrap_err("failed to initiate sequence action fee components") + .put_fees(FeeComponents::::new(0, 1)) .unwrap(); - - let ics20_withdrawal_fees = Ics20WithdrawalFeeComponents { - base: 1, - multiplier: 0, - }; state_tx - .put_ics20_withdrawal_fees(ics20_withdrawal_fees) - .wrap_err("failed to initiate ics20 withdrawal fee components") + .put_fees(FeeComponents::::new(1, 0)) .unwrap(); - - let init_bridge_account_fees = InitBridgeAccountFeeComponents { - base: 12, - multiplier: 0, - }; state_tx - .put_init_bridge_account_fees(init_bridge_account_fees) - .wrap_err("failed to initiate init bridge account fee components") + .put_fees(FeeComponents::::new(12, 0)) .unwrap(); - - let bridge_lock_fees = BridgeLockFeeComponents { - base: 0, - multiplier: 1, - }; state_tx - .put_bridge_lock_fees(bridge_lock_fees) - .wrap_err("failed to initiate bridge lock fee components") + .put_fees(FeeComponents::::new(0, 1)) .unwrap(); - - let bridge_unlock_fees = BridgeUnlockFeeComponents { - base: 0, - multiplier: 0, - }; state_tx - .put_bridge_unlock_fees(bridge_unlock_fees) - .wrap_err("failed to initiate bridge unlock fee components") + .put_fees(FeeComponents::::new(0, 0)) .unwrap(); - - let bridge_sudo_change_fees = BridgeSudoChangeFeeComponents { - base: 24, - multiplier: 0, - }; state_tx - .put_bridge_sudo_change_fees(bridge_sudo_change_fees) - .wrap_err("failed to initiate bridge sudo change fee components") + .put_fees(FeeComponents::::new(24, 0)) .unwrap(); let other_asset = "other".parse::().unwrap(); @@ -384,11 +297,11 @@ mod tests { let amount = 100; let data = Bytes::from_static(&[0; 32]); let transfer_fee = state_tx - .get_transfer_fees() + .get_fees::() .await .expect("should not error fetching transfer fees") .expect("transfer fees should be stored") - .base; + .base(); state_tx .increase_balance( &state_tx From bbdf4a54b9e51671b0528e804f193d5b57302664 Mon Sep 17 00:00:00 2001 From: noot <36753753+noot@users.noreply.github.com> Date: Tue, 10 Dec 2024 02:22:11 +0900 Subject: [PATCH 5/7] fix(sequencer): bump penumbra dep to commit with ibc height fix (#1856) ## Summary bump penumbra dep to commit with ibc height fix as it was merged upstream: https://github.com/penumbra-zone/penumbra/commit/ac7abacc9bb09503d6fd6a396bc0b6850079084e ## Background see #1691 ## Changes - bump penumbra dep to commit with ibc height fix ## Testing it has been tested on the current live networks already --- Cargo.lock | 57 +++++++++++++++--------------- Cargo.toml | 7 ++-- crates/astria-sequencer/Cargo.toml | 2 +- 3 files changed, 34 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index def7009d8b..dc5c5bd69c 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1873,8 +1873,8 @@ dependencies = [ [[package]] name = "cnidarium" -version = "0.80.7" -source = "git+https://github.com/penumbra-zone/penumbra.git?tag=v0.80.7#35f9f2f64a652b6055a39ff227e504636436cb7e" +version = "0.80.9" +source = "git+https://github.com/penumbra-zone/penumbra.git?rev=ac7abacc9bb09503d6fd6a396bc0b6850079084e#ac7abacc9bb09503d6fd6a396bc0b6850079084e" dependencies = [ "anyhow", "async-trait", @@ -1902,8 +1902,8 @@ dependencies = [ [[package]] name = "cnidarium-component" -version = "0.80.7" -source = "git+https://github.com/penumbra-zone/penumbra.git?tag=v0.80.7#35f9f2f64a652b6055a39ff227e504636436cb7e" +version = "0.80.9" +source = "git+https://github.com/penumbra-zone/penumbra.git?rev=ac7abacc9bb09503d6fd6a396bc0b6850079084e#ac7abacc9bb09503d6fd6a396bc0b6850079084e" dependencies = [ "anyhow", "async-trait", @@ -2447,8 +2447,8 @@ dependencies = [ [[package]] name = "decaf377-fmd" -version = "0.80.7" -source = "git+https://github.com/penumbra-zone/penumbra.git?tag=v0.80.7#35f9f2f64a652b6055a39ff227e504636436cb7e" +version = "0.80.9" +source = "git+https://github.com/penumbra-zone/penumbra.git?rev=ac7abacc9bb09503d6fd6a396bc0b6850079084e#ac7abacc9bb09503d6fd6a396bc0b6850079084e" dependencies = [ "ark-ff 0.4.2", "ark-serialize 0.4.2", @@ -2461,8 +2461,8 @@ dependencies = [ [[package]] name = "decaf377-ka" -version = "0.80.7" -source = "git+https://github.com/penumbra-zone/penumbra.git?tag=v0.80.7#35f9f2f64a652b6055a39ff227e504636436cb7e" +version = "0.80.9" +source = "git+https://github.com/penumbra-zone/penumbra.git?rev=ac7abacc9bb09503d6fd6a396bc0b6850079084e#ac7abacc9bb09503d6fd6a396bc0b6850079084e" dependencies = [ "ark-ff 0.4.2", "decaf377", @@ -3248,8 +3248,9 @@ dependencies = [ [[package]] name = "f4jumble" -version = "0.0.0" -source = "git+https://github.com/zcash/librustzcash?rev=2425a0869098e3b0588ccd73c42716bcf418612c#2425a0869098e3b0588ccd73c42716bcf418612c" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0a83e8d7fd0c526af4aad893b7c9fe41e2699ed8a776a6c74aecdeafe05afc75" dependencies = [ "blake2b_simd 1.0.2", ] @@ -5750,8 +5751,8 @@ dependencies = [ [[package]] name = "penumbra-asset" -version = "0.80.7" -source = "git+https://github.com/penumbra-zone/penumbra.git?tag=v0.80.7#35f9f2f64a652b6055a39ff227e504636436cb7e" +version = "0.80.9" +source = "git+https://github.com/penumbra-zone/penumbra.git?rev=ac7abacc9bb09503d6fd6a396bc0b6850079084e#ac7abacc9bb09503d6fd6a396bc0b6850079084e" dependencies = [ "anyhow", "ark-ff 0.4.2", @@ -5789,8 +5790,8 @@ dependencies = [ [[package]] name = "penumbra-ibc" -version = "0.80.7" -source = "git+https://github.com/penumbra-zone/penumbra.git?tag=v0.80.7#35f9f2f64a652b6055a39ff227e504636436cb7e" +version = "0.80.9" +source = "git+https://github.com/penumbra-zone/penumbra.git?rev=ac7abacc9bb09503d6fd6a396bc0b6850079084e#ac7abacc9bb09503d6fd6a396bc0b6850079084e" dependencies = [ "anyhow", "ark-ff 0.4.2", @@ -5826,8 +5827,8 @@ dependencies = [ [[package]] name = "penumbra-keys" -version = "0.80.7" -source = "git+https://github.com/penumbra-zone/penumbra.git?tag=v0.80.7#35f9f2f64a652b6055a39ff227e504636436cb7e" +version = "0.80.9" +source = "git+https://github.com/penumbra-zone/penumbra.git?rev=ac7abacc9bb09503d6fd6a396bc0b6850079084e#ac7abacc9bb09503d6fd6a396bc0b6850079084e" dependencies = [ "aes", "anyhow", @@ -5870,8 +5871,8 @@ dependencies = [ [[package]] name = "penumbra-num" -version = "0.80.7" -source = "git+https://github.com/penumbra-zone/penumbra.git?tag=v0.80.7#35f9f2f64a652b6055a39ff227e504636436cb7e" +version = "0.80.9" +source = "git+https://github.com/penumbra-zone/penumbra.git?rev=ac7abacc9bb09503d6fd6a396bc0b6850079084e#ac7abacc9bb09503d6fd6a396bc0b6850079084e" dependencies = [ "anyhow", "ark-ff 0.4.2", @@ -5906,8 +5907,8 @@ dependencies = [ [[package]] name = "penumbra-proto" -version = "0.80.7" -source = "git+https://github.com/penumbra-zone/penumbra.git?tag=v0.80.7#35f9f2f64a652b6055a39ff227e504636436cb7e" +version = "0.80.9" +source = "git+https://github.com/penumbra-zone/penumbra.git?rev=ac7abacc9bb09503d6fd6a396bc0b6850079084e#ac7abacc9bb09503d6fd6a396bc0b6850079084e" dependencies = [ "anyhow", "async-trait", @@ -5935,8 +5936,8 @@ dependencies = [ [[package]] name = "penumbra-sct" -version = "0.80.7" -source = "git+https://github.com/penumbra-zone/penumbra.git?tag=v0.80.7#35f9f2f64a652b6055a39ff227e504636436cb7e" +version = "0.80.9" +source = "git+https://github.com/penumbra-zone/penumbra.git?rev=ac7abacc9bb09503d6fd6a396bc0b6850079084e#ac7abacc9bb09503d6fd6a396bc0b6850079084e" dependencies = [ "anyhow", "ark-ff 0.4.2", @@ -5971,8 +5972,8 @@ dependencies = [ [[package]] name = "penumbra-tct" -version = "0.80.7" -source = "git+https://github.com/penumbra-zone/penumbra.git?tag=v0.80.7#35f9f2f64a652b6055a39ff227e504636436cb7e" +version = "0.80.9" +source = "git+https://github.com/penumbra-zone/penumbra.git?rev=ac7abacc9bb09503d6fd6a396bc0b6850079084e#ac7abacc9bb09503d6fd6a396bc0b6850079084e" dependencies = [ "ark-ed-on-bls12-377", "ark-ff 0.4.2", @@ -6000,8 +6001,8 @@ dependencies = [ [[package]] name = "penumbra-tower-trace" -version = "0.80.7" -source = "git+https://github.com/penumbra-zone/penumbra.git?tag=v0.80.7#35f9f2f64a652b6055a39ff227e504636436cb7e" +version = "0.80.9" +source = "git+https://github.com/penumbra-zone/penumbra.git?rev=ac7abacc9bb09503d6fd6a396bc0b6850079084e#ac7abacc9bb09503d6fd6a396bc0b6850079084e" dependencies = [ "futures", "hex", @@ -6022,8 +6023,8 @@ dependencies = [ [[package]] name = "penumbra-txhash" -version = "0.80.7" -source = "git+https://github.com/penumbra-zone/penumbra.git?tag=v0.80.7#35f9f2f64a652b6055a39ff227e504636436cb7e" +version = "0.80.9" +source = "git+https://github.com/penumbra-zone/penumbra.git?rev=ac7abacc9bb09503d6fd6a396bc0b6850079084e#ac7abacc9bb09503d6fd6a396bc0b6850079084e" dependencies = [ "anyhow", "blake2b_simd 1.0.2", diff --git a/Cargo.toml b/Cargo.toml index bded5e96a9..33ab556fb5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -81,9 +81,10 @@ itoa = "1.0.10" jsonrpsee = { version = "0.20" } pbjson-types = "0.6" # Note that when updating the penumbra versions, vendored types in `proto/sequencerapis/astria_vendored` may need to be updated as well. -penumbra-ibc = { git = "https://github.com/penumbra-zone/penumbra.git", tag = "v0.80.7", default-features = false } -penumbra-proto = { git = "https://github.com/penumbra-zone/penumbra.git", tag = "v0.80.7" } -penumbra-tower-trace = { git = "https://github.com/penumbra-zone/penumbra.git", tag = "v0.80.7" } +# can update to a tagged version when https://github.com/penumbra-zone/penumbra/commit/ac7abacc9bb09503d6fd6a396bc0b6850079084e is released +penumbra-ibc = { git = "https://github.com/penumbra-zone/penumbra.git", rev = "ac7abacc9bb09503d6fd6a396bc0b6850079084e", default-features = false } +penumbra-proto = { git = "https://github.com/penumbra-zone/penumbra.git", rev = "ac7abacc9bb09503d6fd6a396bc0b6850079084e" } +penumbra-tower-trace = { git = "https://github.com/penumbra-zone/penumbra.git", rev = "ac7abacc9bb09503d6fd6a396bc0b6850079084e" } pin-project-lite = "0.2.13" prost = "0.12" rand = "0.8.5" diff --git a/crates/astria-sequencer/Cargo.toml b/crates/astria-sequencer/Cargo.toml index a2b8ee67b7..56014df011 100644 --- a/crates/astria-sequencer/Cargo.toml +++ b/crates/astria-sequencer/Cargo.toml @@ -33,7 +33,7 @@ telemetry = { package = "astria-telemetry", path = "../astria-telemetry", featur ] } borsh = { version = "1.5.1", features = ["bytes", "derive"] } -cnidarium = { git = "https://github.com/penumbra-zone/penumbra.git", tag = "v0.80.7", features = [ +cnidarium = { git = "https://github.com/penumbra-zone/penumbra.git", rev = "ac7abacc9bb09503d6fd6a396bc0b6850079084e", features = [ "metrics", ] } ibc-proto = { version = "0.41.0", features = ["server"] } From 6e91760cd67832db997c1534b5dc0394d7d0d113 Mon Sep 17 00:00:00 2001 From: Fraser Hutchison <190532+Fraser999@users.noreply.github.com> Date: Tue, 10 Dec 2024 10:48:31 +0000 Subject: [PATCH 6/7] chore: update `url` dependency (#1869) ## Summary Updated the version of `url`. ## Background Running `cargo audit` yields a warning of a vulnerability in `idna` (see [RUSTSEC-2024-0421](https://rustsec.org/advisories/RUSTSEC-2024-0421)). The suggested fix is to upgrade `idna` to >= v1.0.0. `idna` is only a dependency in our tree of `url`, and we cannot upgrade `idna` to >= v1.0.0 without upgrading `url`. However, upgrading `url` from v2.5.2 to v2.5.4 causes the `idna` dependency to upgrade to v1.0.3, hence fixing the issue. ## Changes - Ran `cargo update -p url` to increase the version of `idna` to v1.0.3. ## Testing Ran normal test suite. ## Changelogs Changelogs updated. --- Cargo.lock | 274 +++++++++++++++++-- crates/astria-bridge-contracts/CHANGELOG.md | 6 + crates/astria-bridge-withdrawer/CHANGELOG.md | 4 + crates/astria-cli/CHANGELOG.md | 13 +- crates/astria-composer/CHANGELOG.md | 4 + crates/astria-conductor/CHANGELOG.md | 4 + crates/astria-core/CHANGELOG.md | 30 +- crates/astria-sequencer-relayer/CHANGELOG.md | 4 + crates/astria-sequencer/CHANGELOG.md | 1 + 9 files changed, 297 insertions(+), 43 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index dc5c5bd69c..130b3bff21 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4400,6 +4400,124 @@ dependencies = [ "sha3", ] +[[package]] +name = "icu_collections" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db2fa452206ebee18c4b5c2274dbf1de17008e874b4dc4f0aea9d01ca79e4526" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locid" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13acbb8371917fc971be86fc8057c41a64b521c184808a698c02acc242dbf637" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_locid_transform" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "01d11ac35de8e40fdeda00d9e1e9d92525f3f9d887cdd7aa81d727596788b54e" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_locid_transform_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_locid_transform_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fdc8ff3388f852bede6b579ad4e978ab004f139284d7b28715f773507b946f6e" + +[[package]] +name = "icu_normalizer" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "19ce3e0da2ec68599d193c93d088142efd7f9c5d6fc9b803774855747dc6a84f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "utf16_iter", + "utf8_iter", + "write16", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8cafbf7aa791e9b22bec55a167906f9e1215fd475cd22adfcf660e03e989516" + +[[package]] +name = "icu_properties" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93d6020766cfc6302c15dbbc9c8778c37e62c14427cb7f6e601d849e092aeef5" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locid_transform", + "icu_properties_data", + "icu_provider", + "tinystr", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67a8effbc3dd3e4ba1afa8ad918d5684b8868b3b26500753effea8d2eed19569" + +[[package]] +name = "icu_provider" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ed421c8a8ef78d3e2dbc98a973be2f3770cb42b606e3ab18d6237c4dfde68d9" +dependencies = [ + "displaydoc", + "icu_locid", + "icu_provider_macros", + "stable_deref_trait", + "tinystr", + "writeable", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_provider_macros" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ec89e9337638ecdc08744df490b221a7399bf8d164eb52a665454e60e075ad6" +dependencies = [ + "proc-macro2 1.0.86", + "quote", + "syn 2.0.75", +] + [[package]] name = "ident_case" version = "1.0.1" @@ -4408,12 +4526,23 @@ checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" [[package]] name = "idna" -version = "0.5.0" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "686f825264d630750a544639377bae737628043f20d38bbc029e8f29ea968a7e" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "634d9b1461af396cad843f47fdba5597a4f9e6ddd4bfb6ff5d85028c25cb12f6" +checksum = "daca1df1c957320b2cf139ac61e7bd64fed304c5040df000a745aa1de3b4ef71" dependencies = [ - "unicode-bidi", - "unicode-normalization", + "icu_normalizer", + "icu_properties", ] [[package]] @@ -5009,6 +5138,12 @@ version = "0.4.14" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +[[package]] +name = "litemap" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ee93343901ab17bd981295f2cf0026d4ad018c7c31ba84549a4ddbb47a45104" + [[package]] name = "litrs" version = "0.4.1" @@ -7631,6 +7766,17 @@ version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" +[[package]] +name = "synstructure" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8af7666ab7b6390ab78131fb5b0fce11d6b7a6951602017c35fa82800708971" +dependencies = [ + "proc-macro2 1.0.86", + "quote", + "syn 2.0.75", +] + [[package]] name = "system-configuration" version = "0.5.1" @@ -7931,6 +8077,16 @@ dependencies = [ "crunchy", ] +[[package]] +name = "tinystr" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9117f5d4db391c1cf6927e7bea3db74b9a1c1add8f7eda9ffd5364f40f57b82f" +dependencies = [ + "displaydoc", + "zerovec", +] + [[package]] name = "tinyvec" version = "1.8.0" @@ -8532,27 +8688,12 @@ dependencies = [ "version_check", ] -[[package]] -name = "unicode-bidi" -version = "0.3.15" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "08f95100a766bf4f8f28f90d77e0a5461bbdb219042e7679bebe79004fed8d75" - [[package]] name = "unicode-ident" version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" -[[package]] -name = "unicode-normalization" -version = "0.1.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56d1686db2308d901306f92a263857ef59ea39678a5458e7cb17f01415101f5" -dependencies = [ - "tinyvec", -] - [[package]] name = "unicode-width" version = "0.1.13" @@ -8613,9 +8754,9 @@ checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" [[package]] name = "url" -version = "2.5.2" +version = "2.5.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "22784dbdf76fdde8af1aeda5622b546b422b6fc585325248a2bf9f5e41e94d6c" +checksum = "32f8b686cadd1473f4bd0117a5d28d36b1ade384ea9b5069a1c40aefed7fda60" dependencies = [ "form_urlencoded", "idna", @@ -8635,6 +8776,18 @@ version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "09cc8ee72d2a9becf2f2febe0205bbed8fc6615b7cb429ad062dc7b7ddd036a9" +[[package]] +name = "utf16_iter" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8232dd3cdaed5356e0f716d285e4b40b932ac434100fe9b7e0e8e935b9e6246" + +[[package]] +name = "utf8_iter" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be" + [[package]] name = "utf8parse" version = "0.2.2" @@ -9151,6 +9304,18 @@ dependencies = [ "tokio", ] +[[package]] +name = "write16" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1890f4022759daae28ed4fe62859b1236caebfc61ede2f63ed4e695f3f6d936" + +[[package]] +name = "writeable" +version = "0.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e9df38ee2d2c3c5948ea468a8406ff0db0b29ae1ffde1bcf20ef305bcc95c51" + [[package]] name = "ws_stream_wasm" version = "0.7.4" @@ -9185,6 +9350,30 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cfe53a6657fd280eaa890a3bc59152892ffa3e30101319d168b781ed6529b049" +[[package]] +name = "yoke" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "120e6aef9aa629e3d4f52dc8cc43a015c7724194c97dfaf45180d2daf2b77f40" +dependencies = [ + "serde", + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.7.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2380878cad4ac9aac1e2435f3eb4020e8374b5f13c296cb75b4620ff8e229154" +dependencies = [ + "proc-macro2 1.0.86", + "quote", + "syn 2.0.75", + "synstructure", +] + [[package]] name = "zerocopy" version = "0.7.35" @@ -9206,6 +9395,27 @@ dependencies = [ "syn 2.0.75", ] +[[package]] +name = "zerofrom" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cff3ee08c995dee1859d998dea82f7374f2826091dd9cd47def953cae446cd2e" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "595eed982f7d355beb85837f651fa22e90b3c044842dc7f2c2842c086f295808" +dependencies = [ + "proc-macro2 1.0.86", + "quote", + "syn 2.0.75", + "synstructure", +] + [[package]] name = "zeroize" version = "1.8.1" @@ -9226,6 +9436,28 @@ dependencies = [ "syn 2.0.75", ] +[[package]] +name = "zerovec" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa2b893d79df23bfb12d5461018d408ea19dfafe76c2c7ef6d4eba614f8ff079" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6eafa6dfb17584ea3e2bd6e76e0cc15ad7af12b09abdd1ca55961bed9b1063c6" +dependencies = [ + "proc-macro2 1.0.86", + "quote", + "syn 2.0.75", +] + [[package]] name = "zstd-sys" version = "2.0.13+zstd.1.5.6" diff --git a/crates/astria-bridge-contracts/CHANGELOG.md b/crates/astria-bridge-contracts/CHANGELOG.md index 5e821bef75..d064918d0c 100644 --- a/crates/astria-bridge-contracts/CHANGELOG.md +++ b/crates/astria-bridge-contracts/CHANGELOG.md @@ -9,6 +9,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## Unreleased +### Changed + +- Update `idna` dependency to resolve cargo audit warning [#1869](https://github.com/astriaorg/astria/pull/1869). + +### Fixed + - Read the provided contract's `decimals` function, falling back to a hardcoded value of 18 if the call fails. [#1762](https://github.com/astriaorg/astria/pull/1762) diff --git a/crates/astria-bridge-withdrawer/CHANGELOG.md b/crates/astria-bridge-withdrawer/CHANGELOG.md index e298881919..59090f4cd0 100644 --- a/crates/astria-bridge-withdrawer/CHANGELOG.md +++ b/crates/astria-bridge-withdrawer/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Update `idna` dependency to resolve cargo audit warning [#1869](https://github.com/astriaorg/astria/pull/1869). + ## [1.0.1] - 2024-11-01 ### Fixed diff --git a/crates/astria-cli/CHANGELOG.md b/crates/astria-cli/CHANGELOG.md index 8bb8637b8f..7cadb8c69a 100644 --- a/crates/astria-cli/CHANGELOG.md +++ b/crates/astria-cli/CHANGELOG.md @@ -13,16 +13,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Add `fee-assets` subcommand to `sequencer` CLI [#1816](https://github.com/astriaorg/astria/pull/1816). -### Fixed - -- Fixed ICS20 withdrawal source when using channel with more than one - port/channel combo. [#1768](https://github.com/astriaorg/astria/pull/1768) - ### Changed -- Removed default values from `--sequencer.chain-id` and `--sequencer-url` arguments +- Update `idna` dependency to resolve cargo audit warning [#1869](https://github.com/astriaorg/astria/pull/1869). +- Remove default values from `--sequencer.chain-id` and `--sequencer-url` arguments [#1792](https://github.com/astriaorg/astria/pull/1792) +### Fixed + +- Fix ICS20 withdrawal source when using channel with more than one + port/channel combo. [#1768](https://github.com/astriaorg/astria/pull/1768) + ## [0.5.1] - 2024-10-23 ### Added diff --git a/crates/astria-composer/CHANGELOG.md b/crates/astria-composer/CHANGELOG.md index e430c3d066..52a945378c 100644 --- a/crates/astria-composer/CHANGELOG.md +++ b/crates/astria-composer/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Update `idna` dependency to resolve cargo audit warning [#1869](https://github.com/astriaorg/astria/pull/1869). + ## [1.0.0] - 2024-10-25 ### Changed diff --git a/crates/astria-conductor/CHANGELOG.md b/crates/astria-conductor/CHANGELOG.md index eb75e304d5..b9de90e6d4 100644 --- a/crates/astria-conductor/CHANGELOG.md +++ b/crates/astria-conductor/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Update `idna` dependency to resolve cargo audit warning [#1869](https://github.com/astriaorg/astria/pull/1869). + ## [1.0.0] - 2024-10-25 ### Changed diff --git a/crates/astria-core/CHANGELOG.md b/crates/astria-core/CHANGELOG.md index 0477f1767c..b24c5b2855 100644 --- a/crates/astria-core/CHANGELOG.md +++ b/crates/astria-core/CHANGELOG.md @@ -12,28 +12,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Initial release. -- Added method `TracePrefixed::leading_channel` to read the left-most channel of - a trace prefixed ICS20 asset [#1768](https://github.com/astriaorg/astria/pull/1768) -- Added `impl Protobuf for Address` [#1802](https://github.com/astriaorg/astria/pull/1802) +- Add method `TracePrefixed::leading_channel` to read the left-most channel of + a trace prefixed ICS20 asset [#1768](https://github.com/astriaorg/astria/pull/1768). +- Add `impl Protobuf for Address` [#1802](https://github.com/astriaorg/astria/pull/1802). ### Changed -- Moved `astria_core::crypto` to `astria-core-crypto` and reexported +- Move `astria_core::crypto` to `astria-core-crypto` and reexport `astria_core_crypto as crypto` (this change is transparent) - [#1800](https://github.com/astriaorg/astria/pull/1800/) -- Moved definitions of address domain type to `astria-core-address` and - reexported items using the same aliases [#1802](https://github.com/astriaorg/astria/pull/1802) - -### Changed - + [#1800](https://github.com/astriaorg/astria/pull/1800/). +- Move definitions of address domain type to `astria-core-address` and + reexport items using the same aliases [#1802](https://github.com/astriaorg/astria/pull/1802). - Move all Astria APIs generated from the Protobuf spec from `astria_core::generated` to `astria_core::generated::astria` - [#1825](https://github.com/astriaorg/astria/pull/1825) + [#1825](https://github.com/astriaorg/astria/pull/1825). +- Update `idna` dependency to resolve cargo audit warning [#1869](https://github.com/astriaorg/astria/pull/1869). ### Removed -- Removed method `TracePrefixed::last_channel` [#1768](https://github.com/astriaorg/astria/pull/1768) -- Removed method `SigningKey::try_address` [#1800](https://github.com/astriaorg/astria/pull/1800/) -- Removed inherent methods `Address::try_from_raw` and `Address::to_raw` - [#1802](https://github.com/astriaorg/astria/pull/1802) -- Removed `AddressBuilder::with_iter` from public interface [#1802](https://github.com/astriaorg/astria/pull/1802) +- Remove method `TracePrefixed::last_channel` [#1768](https://github.com/astriaorg/astria/pull/1768). +- Remove method `SigningKey::try_address` [#1800](https://github.com/astriaorg/astria/pull/1800/). +- Remove inherent methods `Address::try_from_raw` and `Address::to_raw` + [#1802](https://github.com/astriaorg/astria/pull/1802). +- Remove `AddressBuilder::with_iter` from public interface [#1802](https://github.com/astriaorg/astria/pull/1802). diff --git a/crates/astria-sequencer-relayer/CHANGELOG.md b/crates/astria-sequencer-relayer/CHANGELOG.md index 63d39156ac..b2afb363c8 100644 --- a/crates/astria-sequencer-relayer/CHANGELOG.md +++ b/crates/astria-sequencer-relayer/CHANGELOG.md @@ -9,6 +9,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Update `idna` dependency to resolve cargo audit warning [#1869](https://github.com/astriaorg/astria/pull/1869). + ## [1.0.0] - 2024-10-25 ### Changed diff --git a/crates/astria-sequencer/CHANGELOG.md b/crates/astria-sequencer/CHANGELOG.md index 3fffea9a55..c80e93586f 100644 --- a/crates/astria-sequencer/CHANGELOG.md +++ b/crates/astria-sequencer/CHANGELOG.md @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Index all event attributes [#1786](https://github.com/astriaorg/astria/pull/1786). - Consolidate action handling to single module [#1759](https://github.com/astriaorg/astria/pull/1759). - Ensure all deposit assets are trace prefixed [#1807](https://github.com/astriaorg/astria/pull/1807). +- Update `idna` dependency to resolve cargo audit warning [#1869](https://github.com/astriaorg/astria/pull/1869). ## [1.0.0] - 2024-10-25 From 86e00798e002c4571998d4ff2e987c866926f7a1 Mon Sep 17 00:00:00 2001 From: Jordan Oroshiba Date: Tue, 10 Dec 2024 11:48:24 -0800 Subject: [PATCH 7/7] chore(ci): action to autoclose stale issues and prs (#1862) ## Summary Adds a regularly scheduled action to mark PRs and issues as stale, and then autoclose with a message if no action taken. ## Background Sometimes issues & pull requests stay around without action or cleanup. By tagging stale items and checking them we can make sure the list of PRs and issues we have is actually actionable. Closing does not impact ability to find and use in future, but makes sure that pertinent issues are easy to find. --- .github/workflows/scheduled.yml | 36 +++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/.github/workflows/scheduled.yml b/.github/workflows/scheduled.yml index 45549618ed..dc5d58b067 100644 --- a/.github/workflows/scheduled.yml +++ b/.github/workflows/scheduled.yml @@ -1,5 +1,6 @@ name: Scheduled on: + workflow_dispatch: schedule: - cron: '0 0 * * *' @@ -14,3 +15,38 @@ jobs: - uses: rustsec/audit-check@v2.0.0 with: token: ${{ secrets.GITHUB_TOKEN }} + stale: + runs-on: ubuntu-latest + permissions: + issues: write + pull-requests: write + steps: + - uses: actions/stale@v9 + with: + # Utilize a separate token for the stale worker to avoid rate limiting + repo-token: ${{ secrets.STALE_WORKER_TOKEN }} + # This is half the number of operations allowed per hour for the + # GitHub API. + operations-per-run: 2500 + days-before-stale: 45 + days-before-close: 7 + # start with the oldest issues first, as they are most likely to be stale. + ascending: true + stale-issue-label: 'stale' + stale-pr-label: 'stale' + # Allow tagging issues in such a way that they are exempt from the stale check + exempt-issue-labels: 'ignore-stale' + exempt-pr-labels: 'ignore-stale' + # Labels to easily find issues closed because they are stale. + close-issue-label: 'closed-stale' + close-pr-label: 'closed-stale' + stale-issue-message: | + This issue is stale because it has been open 45 days with no activity. Remove stale label or this issue + be closed in 7 days. + close-issue-message: 'This issue was closed because it was stale' + stale-pr-message: | + This PR is stale because it has been open 45 days with no activity. Remove stale label or this PR will be + closed in 7 days. + close-pr-message: 'This PR was closed because it has been stale.' + # Exempt anything added to a milestone from being considered stale + exempt-all-milestones: true