Skip to content

Commit f757162

Browse files
Align Events between Bulletin and SDK (#10445)
* Align events between Bulletin and SDK * Extends `Stored` and `Renewed` events with a `hash: ContentHash` field. * Replaces `log` with `tracing` to match Bulletin’s logging approach. Addresses paritytech/polkadot-bulletin-chain#86, paritytech/polkadot-bulletin-chain#123 Relates to - [x] paritytech/polkadot-bulletin-chain#124 - [x] paritytech/polkadot-bulletin-chain#127 - [x] paritytech/polkadot-bulletin-chain#129 --------- Co-authored-by: cmd[bot] <41898282+github-actions[bot]@users.noreply.github.com>
1 parent f67648a commit f757162

File tree

5 files changed

+58
-32
lines changed

5 files changed

+58
-32
lines changed

Cargo.lock

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

prdoc/pr_10445.prdoc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
title: Align Events Between Bulletin and SDK
2+
doc:
3+
- audience: Runtime Dev
4+
description: |
5+
Extends `Stored` and `Renewed` events with a `hash: ContentHash` field.
6+
Replaces `log` with `tracing` to match Bulletin’s logging approach.
7+
crates:
8+
- name: pallet-transaction-storage
9+
bump: major

substrate/frame/transaction-storage/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,14 @@ codec = { workspace = true }
2121
frame-benchmarking = { optional = true, workspace = true }
2222
frame-support = { workspace = true }
2323
frame-system = { workspace = true }
24-
log = { workspace = true }
2524
pallet-balances = { workspace = true }
2625
scale-info = { features = ["derive"], workspace = true }
2726
serde = { optional = true, workspace = true, default-features = true }
2827
sp-inherents = { workspace = true }
2928
sp-io = { workspace = true }
3029
sp-runtime = { workspace = true }
3130
sp-transaction-storage-proof = { workspace = true }
31+
tracing = { workspace = true }
3232

3333
[dev-dependencies]
3434
sp-transaction-storage-proof = { default-features = true, workspace = true }
@@ -40,13 +40,13 @@ std = [
4040
"frame-benchmarking?/std",
4141
"frame-support/std",
4242
"frame-system/std",
43-
"log/std",
4443
"pallet-balances/std",
4544
"scale-info/std",
4645
"serde",
4746
"sp-inherents/std",
4847
"sp-io/std",
4948
"sp-runtime/std",
49+
"tracing/std",
5050
]
5151
runtime-benchmarks = [
5252
"array-bytes",

substrate/frame/transaction-storage/src/benchmarking.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,30 +128,31 @@ mod benchmarks {
128128
fn store(l: Linear<1, { T::MaxTransactionSize::get() }>) {
129129
let caller: T::AccountId = whitelisted_caller();
130130
let initial_balance = BalanceOf::<T>::max_value().checked_div(&2u32.into()).unwrap();
131+
let data = vec![0u8; l as usize];
132+
let content_hash = sp_io::hashing::blake2_256(&data);
131133
T::Currency::set_balance(&caller, initial_balance);
132134

133135
#[extrinsic_call]
134-
_(RawOrigin::Signed(caller.clone()), vec![0u8; l as usize]);
136+
_(RawOrigin::Signed(caller.clone()), data);
135137

136138
assert!(!BlockTransactions::<T>::get().is_empty());
137-
assert_last_event::<T>(Event::Stored { index: 0 }.into());
139+
assert_last_event::<T>(Event::Stored { index: 0, content_hash }.into());
138140
}
139141

140142
#[benchmark]
141143
fn renew() -> Result<(), BenchmarkError> {
142144
let caller: T::AccountId = whitelisted_caller();
143145
let initial_balance = BalanceOf::<T>::max_value().checked_div(&2u32.into()).unwrap();
146+
let data = vec![0u8; T::MaxTransactionSize::get() as usize];
147+
let content_hash = sp_io::hashing::blake2_256(&data);
144148
T::Currency::set_balance(&caller, initial_balance);
145-
Pallet::<T>::store(
146-
RawOrigin::Signed(caller.clone()).into(),
147-
vec![0u8; T::MaxTransactionSize::get() as usize],
148-
)?;
149+
Pallet::<T>::store(RawOrigin::Signed(caller.clone()).into(), data)?;
149150
run_to_block::<T>(1u32.into());
150151

151152
#[extrinsic_call]
152153
_(RawOrigin::Signed(caller.clone()), BlockNumberFor::<T>::zero(), 0);
153154

154-
assert_last_event::<T>(Event::Renewed { index: 0 }.into());
155+
assert_last_event::<T>(Event::Renewed { index: 0, content_hash }.into());
155156

156157
Ok(())
157158
}

substrate/frame/transaction-storage/src/lib.rs

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,9 @@ pub use weights::WeightInfo;
6161
pub const DEFAULT_MAX_TRANSACTION_SIZE: u32 = 8 * 1024 * 1024;
6262
pub const DEFAULT_MAX_BLOCK_TRANSACTIONS: u32 = 512;
6363

64+
/// Hash of a stored blob of data.
65+
type ContentHash = [u8; 32];
66+
6467
/// State data for a stored transaction.
6568
#[derive(
6669
Encode,
@@ -264,7 +267,7 @@ pub mod pallet {
264267
.map_err(|_| Error::<T>::TooManyTransactions)?;
265268
Ok(())
266269
})?;
267-
Self::deposit_event(Event::Stored { index });
270+
Self::deposit_event(Event::Stored { index, content_hash });
268271
Ok(())
269272
}
270273

@@ -288,8 +291,8 @@ pub mod pallet {
288291
frame_system::Pallet::<T>::extrinsic_index().ok_or(Error::<T>::BadContext)?;
289292

290293
Self::apply_fee(sender, info.size)?;
291-
292-
sp_io::transaction_index::renew(extrinsic_index, info.content_hash.into());
294+
let content_hash = info.content_hash.into();
295+
sp_io::transaction_index::renew(extrinsic_index, content_hash);
293296

294297
let mut index = 0;
295298
BlockTransactions::<T>::mutate(|transactions| {
@@ -308,7 +311,7 @@ pub mod pallet {
308311
})
309312
.map_err(|_| Error::<T>::TooManyTransactions)
310313
})?;
311-
Self::deposit_event(Event::Renewed { index });
314+
Self::deposit_event(Event::Renewed { index, content_hash });
312315
Ok(().into())
313316
}
314317

@@ -349,11 +352,24 @@ pub mod pallet {
349352
#[pallet::generate_deposit(pub(super) fn deposit_event)]
350353
pub enum Event<T: Config> {
351354
/// Stored data under specified index.
352-
Stored { index: u32 },
355+
Stored { index: u32, content_hash: ContentHash },
353356
/// Renewed data under specified index.
354-
Renewed { index: u32 },
357+
Renewed { index: u32, content_hash: ContentHash },
355358
/// Storage proof was successfully checked.
356359
ProofChecked,
360+
/// An account `who` was authorized to store `bytes` bytes in `transactions` transactions.
361+
AccountAuthorized { who: T::AccountId, transactions: u32, bytes: u64 },
362+
/// An authorization for account `who` was refreshed.
363+
AccountAuthorizationRefreshed { who: T::AccountId },
364+
/// Authorization was given for a preimage of `content_hash` (not exceeding `max_size`) to
365+
/// be stored by anyone.
366+
PreimageAuthorized { content_hash: ContentHash, max_size: u64 },
367+
/// An authorization for a preimage of `content_hash` was refreshed.
368+
PreimageAuthorizationRefreshed { content_hash: ContentHash },
369+
/// An expired account authorization was removed.
370+
ExpiredAccountAuthorizationRemoved { who: T::AccountId },
371+
/// An expired preimage authorization was removed.
372+
ExpiredPreimageAuthorizationRemoved { content_hash: ContentHash },
357373
}
358374

359375
/// Collection of transaction metadata by block number.

0 commit comments

Comments
 (0)