diff --git a/Cargo.lock b/Cargo.lock index 13a44e9346e57..6dbbbc19668c4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -444,9 +444,9 @@ dependencies = [ [[package]] name = "anstyle" -version = "1.0.6" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" +checksum = "862ed96ca487e809f1c8e5a8447f6ee2cf102f846893800b20cebdf541fc6bbd" [[package]] name = "anstyle-parse" @@ -3298,9 +3298,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.13" +version = "4.5.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0fbb260a053428790f3de475e304ff84cdbc4face759ea7a3e64c1edd938a7fc" +checksum = "e2134bb3ea021b78629caa971416385309e0131b351b25e01dc16fb54e1b5fae" dependencies = [ "clap_builder", "clap_derive", @@ -3308,9 +3308,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.13" +version = "4.5.48" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64b17d7ea74e9f833c7dbf2cbe4fb12ff26783eda4782a8975b72f895c9b4d99" +checksum = "c2ba64afa3c0a6df7fa517765e31314e983f51dda798ffba27b988194fb65dc9" dependencies = [ "anstream", "anstyle", @@ -3330,9 +3330,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.13" +version = "4.5.47" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "501d359d5f3dcaf6ecdeee48833ae73ec6e42723a1e52419c79abf9507eec0a0" +checksum = "bbfd7eae0b0f1a6e63d4b13c9c478de77c2eb546fba158ad50b4203dc24b9f9c" dependencies = [ "heck 0.5.0", "proc-macro2 1.0.95", @@ -3342,9 +3342,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.0" +version = "0.7.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" +checksum = "b94f61472cee1439c0b966b47e3aca9ae07e45d070759512cd390ea2bebc6675" [[package]] name = "cmd_lib" @@ -7564,9 +7564,9 @@ dependencies = [ [[package]] name = "glob" -version = "0.3.1" +version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d2fabcfbdc87f4758337ca535fb41a6d701b65693ce38287d856d1674551ec9b" +checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" [[package]] name = "glob-match" @@ -14128,7 +14128,6 @@ dependencies = [ "frame-benchmarking", "frame-support", "frame-system", - "log", "pallet-balances", "parity-scale-codec", "scale-info", @@ -14137,6 +14136,7 @@ dependencies = [ "sp-io", "sp-runtime", "sp-transaction-storage-proof", + "tracing", ] [[package]] @@ -25581,12 +25581,12 @@ dependencies = [ [[package]] name = "terminal_size" -version = "0.3.0" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "21bebf2b7c9e0a515f6e0f8c51dc0f8e4696391e6f1ff30379559f8365fb0df7" +checksum = "60b8cb979cb11c32ce1603f8137b22262a9d131aaa5c37b5678025f22b8becd0" dependencies = [ - "rustix 0.38.42", - "windows-sys 0.48.0", + "rustix 1.0.8", + "windows-sys 0.60.2", ] [[package]] diff --git a/prdoc/pr_10445.prdoc b/prdoc/pr_10445.prdoc new file mode 100644 index 0000000000000..b5d65129c4769 --- /dev/null +++ b/prdoc/pr_10445.prdoc @@ -0,0 +1,9 @@ +title: Align Events Between Bulletin and SDK +doc: + - audience: Runtime Dev + description: | + Extends `Stored` and `Renewed` events with a `hash: ContentHash` field. + Replaces `log` with `tracing` to match Bulletin’s logging approach. +crates: +- name: pallet-transaction-storage + bump: major diff --git a/substrate/frame/transaction-storage/Cargo.toml b/substrate/frame/transaction-storage/Cargo.toml index c2784eea952a7..c3ee687bda0a9 100644 --- a/substrate/frame/transaction-storage/Cargo.toml +++ b/substrate/frame/transaction-storage/Cargo.toml @@ -21,7 +21,6 @@ codec = { workspace = true } frame-benchmarking = { optional = true, workspace = true } frame-support = { workspace = true } frame-system = { workspace = true } -log = { workspace = true } pallet-balances = { workspace = true } scale-info = { features = ["derive"], workspace = true } serde = { optional = true, workspace = true, default-features = true } @@ -29,6 +28,7 @@ sp-inherents = { workspace = true } sp-io = { workspace = true } sp-runtime = { workspace = true } sp-transaction-storage-proof = { workspace = true } +tracing = { workspace = true } [dev-dependencies] sp-transaction-storage-proof = { default-features = true, workspace = true } @@ -40,13 +40,13 @@ std = [ "frame-benchmarking?/std", "frame-support/std", "frame-system/std", - "log/std", "pallet-balances/std", "scale-info/std", "serde", "sp-inherents/std", "sp-io/std", "sp-runtime/std", + "tracing/std", ] runtime-benchmarks = [ "array-bytes", diff --git a/substrate/frame/transaction-storage/src/benchmarking.rs b/substrate/frame/transaction-storage/src/benchmarking.rs index 0b5b0dc994054..d65fd667d4ea5 100644 --- a/substrate/frame/transaction-storage/src/benchmarking.rs +++ b/substrate/frame/transaction-storage/src/benchmarking.rs @@ -128,30 +128,31 @@ mod benchmarks { fn store(l: Linear<1, { T::MaxTransactionSize::get() }>) { let caller: T::AccountId = whitelisted_caller(); let initial_balance = BalanceOf::::max_value().checked_div(&2u32.into()).unwrap(); + let data = vec![0u8; l as usize]; + let content_hash = sp_io::hashing::blake2_256(&data); T::Currency::set_balance(&caller, initial_balance); #[extrinsic_call] - _(RawOrigin::Signed(caller.clone()), vec![0u8; l as usize]); + _(RawOrigin::Signed(caller.clone()), data); assert!(!BlockTransactions::::get().is_empty()); - assert_last_event::(Event::Stored { index: 0 }.into()); + assert_last_event::(Event::Stored { index: 0, content_hash }.into()); } #[benchmark] fn renew() -> Result<(), BenchmarkError> { let caller: T::AccountId = whitelisted_caller(); let initial_balance = BalanceOf::::max_value().checked_div(&2u32.into()).unwrap(); + let data = vec![0u8; T::MaxTransactionSize::get() as usize]; + let content_hash = sp_io::hashing::blake2_256(&data); T::Currency::set_balance(&caller, initial_balance); - Pallet::::store( - RawOrigin::Signed(caller.clone()).into(), - vec![0u8; T::MaxTransactionSize::get() as usize], - )?; + Pallet::::store(RawOrigin::Signed(caller.clone()).into(), data)?; run_to_block::(1u32.into()); #[extrinsic_call] _(RawOrigin::Signed(caller.clone()), BlockNumberFor::::zero(), 0); - assert_last_event::(Event::Renewed { index: 0 }.into()); + assert_last_event::(Event::Renewed { index: 0, content_hash }.into()); Ok(()) } diff --git a/substrate/frame/transaction-storage/src/lib.rs b/substrate/frame/transaction-storage/src/lib.rs index 309363c4d148b..c97f46ab31f4c 100644 --- a/substrate/frame/transaction-storage/src/lib.rs +++ b/substrate/frame/transaction-storage/src/lib.rs @@ -61,6 +61,9 @@ pub use weights::WeightInfo; pub const DEFAULT_MAX_TRANSACTION_SIZE: u32 = 8 * 1024 * 1024; pub const DEFAULT_MAX_BLOCK_TRANSACTIONS: u32 = 512; +/// Hash of a stored blob of data. +type ContentHash = [u8; 32]; + /// State data for a stored transaction. #[derive( Encode, @@ -264,7 +267,7 @@ pub mod pallet { .map_err(|_| Error::::TooManyTransactions)?; Ok(()) })?; - Self::deposit_event(Event::Stored { index }); + Self::deposit_event(Event::Stored { index, content_hash }); Ok(()) } @@ -288,8 +291,8 @@ pub mod pallet { frame_system::Pallet::::extrinsic_index().ok_or(Error::::BadContext)?; Self::apply_fee(sender, info.size)?; - - sp_io::transaction_index::renew(extrinsic_index, info.content_hash.into()); + let content_hash = info.content_hash.into(); + sp_io::transaction_index::renew(extrinsic_index, content_hash); let mut index = 0; BlockTransactions::::mutate(|transactions| { @@ -308,7 +311,7 @@ pub mod pallet { }) .map_err(|_| Error::::TooManyTransactions) })?; - Self::deposit_event(Event::Renewed { index }); + Self::deposit_event(Event::Renewed { index, content_hash }); Ok(().into()) } @@ -349,11 +352,24 @@ pub mod pallet { #[pallet::generate_deposit(pub(super) fn deposit_event)] pub enum Event { /// Stored data under specified index. - Stored { index: u32 }, + Stored { index: u32, content_hash: ContentHash }, /// Renewed data under specified index. - Renewed { index: u32 }, + Renewed { index: u32, content_hash: ContentHash }, /// Storage proof was successfully checked. ProofChecked, + /// An account `who` was authorized to store `bytes` bytes in `transactions` transactions. + AccountAuthorized { who: T::AccountId, transactions: u32, bytes: u64 }, + /// An authorization for account `who` was refreshed. + AccountAuthorizationRefreshed { who: T::AccountId }, + /// Authorization was given for a preimage of `content_hash` (not exceeding `max_size`) to + /// be stored by anyone. + PreimageAuthorized { content_hash: ContentHash, max_size: u64 }, + /// An authorization for a preimage of `content_hash` was refreshed. + PreimageAuthorizationRefreshed { content_hash: ContentHash }, + /// An expired account authorization was removed. + ExpiredAccountAuthorizationRemoved { who: T::AccountId }, + /// An expired preimage authorization was removed. + ExpiredPreimageAuthorizationRemoved { content_hash: ContentHash }, } /// Collection of transaction metadata by block number.