Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extend the Executed event #1040

Merged
Merged
Show file tree
Hide file tree
Changes from 4 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
35 changes: 32 additions & 3 deletions frame/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ use sp_runtime::{
transaction_validity::{
InvalidTransaction, TransactionValidity, TransactionValidityError, ValidTransactionBuilder,
},
DispatchErrorWithPostInfo, RuntimeDebug,
DispatchErrorWithPostInfo, RuntimeDebug, SaturatedConversion,
};
use sp_std::{marker::PhantomData, prelude::*};

Expand Down Expand Up @@ -196,6 +196,8 @@ pub mod pallet {
type StateRoot: Get<H256>;
/// What's included in the PostLog.
type PostLogContent: Get<PostLogContent>;
/// The maximum length of the extra data in the Executed event.
type ExtraDataLength: Get<u32>;
}

#[pallet::hooks]
Expand Down Expand Up @@ -302,6 +304,7 @@ pub mod pallet {
to: H160,
transaction_hash: H256,
exit_reason: ExitReason,
extra_data: Vec<u8>,
},
}

Expand Down Expand Up @@ -545,9 +548,9 @@ impl<T: Config> Pallet<T> {
let transaction_hash = transaction.hash();
let transaction_index = pending.len() as u32;

let (reason, status, used_gas, dest) = match info {
let (reason, status, used_gas, dest, extra_data) = match info {
CallOrCreateInfo::Call(info) => (
info.exit_reason,
info.exit_reason.clone(),
TransactionStatus {
transaction_hash,
transaction_index,
Expand All @@ -563,6 +566,30 @@ impl<T: Config> Pallet<T> {
},
info.used_gas,
to,
match info.exit_reason {
ExitReason::Revert(_) => {
const LEN_START: usize = 36;
const MESSAGE_START: usize = 68;

let data = info.value;
if data.len() > MESSAGE_START {
let message_len = U256::from(&data[LEN_START..MESSAGE_START])
.saturated_into::<usize>();
let message_end = MESSAGE_START.saturating_add(
message_len.min(T::ExtraDataLength::get() as usize),
);

if data.len() >= message_end {
boundless-forest marked this conversation as resolved.
Show resolved Hide resolved
data[MESSAGE_START..message_end].to_vec()
} else {
data
}
} else {
data
}
}
_ => vec![],
},
),
CallOrCreateInfo::Create(info) => (
info.exit_reason,
Expand All @@ -581,6 +608,7 @@ impl<T: Config> Pallet<T> {
},
info.used_gas,
Some(info.value),
Vec::new(),
),
};

Expand Down Expand Up @@ -629,6 +657,7 @@ impl<T: Config> Pallet<T> {
to: dest.unwrap_or_default(),
transaction_hash,
exit_reason: reason,
extra_data,
});

Ok(PostDispatchInfo {
Expand Down
1 change: 1 addition & 0 deletions frame/ethereum/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ impl Config for Test {
type RuntimeEvent = RuntimeEvent;
type StateRoot = IntermediateStateRoot<Self>;
type PostLogContent = PostBlockAndTxnHashes;
type ExtraDataLength = ConstU32<30>;
}

impl fp_self_contained::SelfContainedCall for RuntimeCall {
Expand Down
1 change: 1 addition & 0 deletions template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ impl pallet_ethereum::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;
type PostLogContent = PostBlockAndTxnHashes;
type ExtraDataLength = ConstU32<30>;
}

parameter_types! {
Expand Down