Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions Cargo.lock

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

9 changes: 9 additions & 0 deletions prdoc/pr_10445.prdoc
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions substrate/frame/transaction-storage/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ 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 }
sp-inherents = { workspace = true }
sp-io = { workspace = true }
sp-runtime = { workspace = true }
sp-transaction-storage-proof = { workspace = true }
tracing = { workspace = true }
Comment on lines -24 to +31
Copy link
Contributor

@x3c41a x3c41a Nov 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you remove log and add tracing here? I don't see tracing added anywhere else except for this file

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make it consistent with the Bulletin chain repo. If you prefer, I can remove tracing, and then add it back later when it's needed.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, I don't mind having this change as part of this PR but, please, make sure to mention this change in the PR description or the prdoc file (or both 🙃)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

because when I see something like this - first thing that comes to mind - is that it was an unintentional change

Copy link
Contributor Author

@raymondkfcheung raymondkfcheung Nov 28, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated the PR desc and PRDoc: be7c1c6


[dev-dependencies]
sp-transaction-storage-proof = { default-features = true, workspace = true }
Expand All @@ -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",
Expand Down
15 changes: 8 additions & 7 deletions substrate/frame/transaction-storage/src/benchmarking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,30 +128,31 @@ mod benchmarks {
fn store(l: Linear<1, { T::MaxTransactionSize::get() }>) {
let caller: T::AccountId = whitelisted_caller();
let initial_balance = BalanceOf::<T>::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::<T>::get().is_empty());
assert_last_event::<T>(Event::Stored { index: 0 }.into());
assert_last_event::<T>(Event::Stored { index: 0, content_hash }.into());
}

#[benchmark]
fn renew() -> Result<(), BenchmarkError> {
let caller: T::AccountId = whitelisted_caller();
let initial_balance = BalanceOf::<T>::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::<T>::store(
RawOrigin::Signed(caller.clone()).into(),
vec![0u8; T::MaxTransactionSize::get() as usize],
)?;
Pallet::<T>::store(RawOrigin::Signed(caller.clone()).into(), data)?;
run_to_block::<T>(1u32.into());

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

assert_last_event::<T>(Event::Renewed { index: 0 }.into());
assert_last_event::<T>(Event::Renewed { index: 0, content_hash }.into());

Ok(())
}
Expand Down
28 changes: 22 additions & 6 deletions substrate/frame/transaction-storage/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -264,7 +267,7 @@ pub mod pallet {
.map_err(|_| Error::<T>::TooManyTransactions)?;
Ok(())
})?;
Self::deposit_event(Event::Stored { index });
Self::deposit_event(Event::Stored { index, content_hash });
Ok(())
}

Expand All @@ -288,8 +291,8 @@ pub mod pallet {
frame_system::Pallet::<T>::extrinsic_index().ok_or(Error::<T>::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::<T>::mutate(|transactions| {
Expand All @@ -308,7 +311,7 @@ pub mod pallet {
})
.map_err(|_| Error::<T>::TooManyTransactions)
})?;
Self::deposit_event(Event::Renewed { index });
Self::deposit_event(Event::Renewed { index, content_hash });
Ok(().into())
}

Expand Down Expand Up @@ -349,11 +352,24 @@ pub mod pallet {
#[pallet::generate_deposit(pub(super) fn deposit_event)]
pub enum Event<T: Config> {
/// 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.
Expand Down
Loading