Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

emit event on remark #8120

Merged
merged 12 commits into from
Feb 28, 2021
6 changes: 6 additions & 0 deletions frame/system/benchmarking/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ benchmarks! {
let caller = whitelisted_caller();
}: _(RawOrigin::Signed(caller), remark_message)

remark_with_event {
let b in 0 .. *T::BlockLength::get().max.get(DispatchClass::Normal) as u32;
let remark_message = vec![1; b as usize];
let caller = whitelisted_caller();
}: _(RawOrigin::Signed(caller), remark_message)

set_heap_pages {
}: _(RawOrigin::Root, Default::default())

Expand Down
17 changes: 15 additions & 2 deletions frame/system/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,8 +292,6 @@ pub mod pallet {
///
/// # <weight>
/// - `O(1)`
/// - Base Weight: 0.665 µs, independent of remark length.
/// - No DB operations.
/// # </weight>
#[pallet::weight(T::SystemWeightInfo::remark(_remark.len() as u32))]
pub(crate) fn remark(origin: OriginFor<T>, _remark: Vec<u8>) -> DispatchResultWithPostInfo {
Expand Down Expand Up @@ -450,6 +448,19 @@ pub mod pallet {
storage::unhashed::kill_prefix(&prefix);
Ok(().into())
}

/// Make some on-chain remark and emit event.
///
/// # <weight>
/// - `O(1)`
/// - 1 event.
/// # </weight>
#[pallet::weight(T::SystemWeightInfo::remark_with_event(remark.len() as u32))]
pub(crate) fn remark_with_event(origin: OriginFor<T>, remark: Vec<u8>) -> DispatchResultWithPostInfo {
let who = ensure_signed(origin)?;
Self::deposit_event(Event::Remarked(who, remark));
Copy link
Member

Choose a reason for hiding this comment

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

But is it really a good idea to put the full remark into the event?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you have a suggestion? Put hash? Limit the remark length?

Copy link
Member

Choose a reason for hiding this comment

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

should be the hash of remark, not remark itself.

Ok(().into())
}
}

/// Event for the System pallet.
Expand All @@ -466,6 +477,8 @@ pub mod pallet {
NewAccount(T::AccountId),
/// An \[account\] was reaped.
KilledAccount(T::AccountId),
/// On on-chain remark happened. \[origin, remark\]
Remarked(T::AccountId, Vec<u8>),
}

/// Old name generated by `decl_event`.
Expand Down
7 changes: 7 additions & 0 deletions frame/system/src/weights.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ pub trait WeightInfo {
fn set_storage(i: u32, ) -> Weight;
fn kill_storage(i: u32, ) -> Weight;
fn kill_prefix(p: u32, ) -> Weight;
fn remark_with_event(b: u32, ) -> Weight;
}

/// Weights for frame_system using the Substrate node and recommended hardware.
Expand Down Expand Up @@ -85,6 +86,9 @@ impl<T: crate::Config> WeightInfo for SubstrateWeight<T> {
.saturating_add((845_000 as Weight).saturating_mul(p as Weight))
.saturating_add(T::DbWeight::get().writes((1 as Weight).saturating_mul(p as Weight)))
}
fn remark_with_event(_b: u32, ) -> Weight {
(1_973_000 as Weight)
}
}

// For backwards compatibility and tests
Expand Down Expand Up @@ -119,4 +123,7 @@ impl WeightInfo for () {
.saturating_add((845_000 as Weight).saturating_mul(p as Weight))
.saturating_add(RocksDbWeight::get().writes((1 as Weight).saturating_mul(p as Weight)))
}
fn remark_with_event(_b: u32, ) -> Weight {
(1_973_000 as Weight)
}
}