Skip to content

Commit 4558635

Browse files
al3martchungquantin
authored andcommitted
chore(revive): remove Debug buffer and add tracing support (#529)
* chore: sdk-7163 * chore: sdk-7166 * chore: sdk-7167
1 parent 10a90a4 commit 4558635

File tree

5 files changed

+130
-29
lines changed

5 files changed

+130
-29
lines changed

runtime/mainnet/src/apis.rs

Lines changed: 66 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ use xcm_runtime_apis::{
3333
// Local module imports
3434
use super::{
3535
config::{monetary::fee::WeightToFee, system::RuntimeBlockWeights, xcm as xcm_config},
36-
AccountId, Balance, Balances, Block, BlockNumber, BlockWeights, EthExtraImpl, EventRecord,
37-
Executive, ExtrinsicInclusionMode, InherentDataExt, Nfts, Nonce, OriginCaller, ParachainSystem,
36+
AccountId, Balance, Balances, Block, BlockNumber, BlockWeights, Executive,
37+
ExtrinsicInclusionMode, InherentDataExt, Nfts, Nonce, OriginCaller, ParachainSystem,
3838
PolkadotXcm, Revive, Runtime, RuntimeCall, RuntimeEvent, RuntimeGenesisConfig, RuntimeOrigin,
3939
SessionKeys, System, TransactionPayment, UncheckedExtrinsic, VERSION,
4040
};
@@ -395,7 +395,7 @@ impl_runtime_apis! {
395395
}
396396
}
397397

398-
impl pallet_revive::ReviveApi<Block, AccountId, Balance, Nonce, BlockNumber, EventRecord> for Runtime
398+
impl pallet_revive::ReviveApi<Block, AccountId, Balance, Nonce, BlockNumber> for Runtime
399399
{
400400
fn balance(address: H160) -> Balance {
401401
use frame_support::traits::fungible::Inspect;
@@ -438,16 +438,14 @@ impl_runtime_apis! {
438438
gas_limit: Option<Weight>,
439439
storage_deposit_limit: Option<Balance>,
440440
input_data: Vec<u8>,
441-
) -> pallet_revive::ContractResult<pallet_revive::ExecReturnValue, Balance, EventRecord> {
441+
) -> pallet_revive::ContractResult<pallet_revive::ExecReturnValue, Balance> {
442442
Revive::bare_call(
443443
RuntimeOrigin::signed(origin),
444444
dest,
445445
value,
446446
gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block),
447447
pallet_revive::DepositLimit::Balance(storage_deposit_limit.unwrap_or(u128::MAX)),
448448
input_data,
449-
pallet_revive::DebugInfo::UnsafeDebug,
450-
pallet_revive::CollectEvents::UnsafeCollect,
451449
)
452450
}
453451

@@ -459,7 +457,7 @@ impl_runtime_apis! {
459457
code: pallet_revive::Code,
460458
data: Vec<u8>,
461459
salt: Option<[u8; 32]>,
462-
) -> pallet_revive::ContractResult<pallet_revive::InstantiateReturnValue, Balance, EventRecord>
460+
) -> pallet_revive::ContractResult<pallet_revive::InstantiateReturnValue, Balance>
463461
{
464462
Revive::bare_instantiate(
465463
RuntimeOrigin::signed(origin),
@@ -469,8 +467,6 @@ impl_runtime_apis! {
469467
code,
470468
data,
471469
salt,
472-
pallet_revive::DebugInfo::UnsafeDebug,
473-
pallet_revive::CollectEvents::UnsafeCollect,
474470
)
475471
}
476472

@@ -496,6 +492,67 @@ impl_runtime_apis! {
496492
key
497493
)
498494
}
495+
496+
fn trace_block(
497+
block: Block,
498+
config: pallet_revive::evm::TracerConfig
499+
) -> Vec<(u32, pallet_revive::evm::CallTrace)> {
500+
use pallet_revive::tracing::trace;
501+
let mut tracer = config.build(Revive::evm_gas_from_weight);
502+
let mut traces = vec![];
503+
let (header, extrinsics) = block.deconstruct();
504+
505+
Executive::initialize_block(&header);
506+
for (index, ext) in extrinsics.into_iter().enumerate() {
507+
trace(&mut tracer, || {
508+
let _ = Executive::apply_extrinsic(ext);
509+
});
510+
511+
if let Some(tx_trace) = tracer.collect_traces().pop() {
512+
traces.push((index as u32, tx_trace));
513+
}
514+
}
515+
516+
traces
517+
}
518+
519+
fn trace_tx(
520+
block: Block,
521+
tx_index: u32,
522+
config: pallet_revive::evm::TracerConfig
523+
) -> Option<pallet_revive::evm::CallTrace> {
524+
use pallet_revive::tracing::trace;
525+
let mut tracer = config.build(Revive::evm_gas_from_weight);
526+
let (header, extrinsics) = block.deconstruct();
527+
528+
Executive::initialize_block(&header);
529+
for (index, ext) in extrinsics.into_iter().enumerate() {
530+
if index as u32 == tx_index {
531+
trace(&mut tracer, || {
532+
let _ = Executive::apply_extrinsic(ext);
533+
});
534+
break;
535+
} else {
536+
let _ = Executive::apply_extrinsic(ext);
537+
}
538+
}
539+
540+
tracer.collect_traces().pop()
541+
}
542+
543+
fn trace_call(
544+
tx: pallet_revive::evm::GenericTransaction,
545+
config: pallet_revive::evm::TracerConfig)
546+
-> Result<pallet_revive::evm::CallTrace, pallet_revive::EthTransactError>
547+
{
548+
use pallet_revive::tracing::trace;
549+
let mut tracer = config.build(Revive::evm_gas_from_weight);
550+
trace(&mut tracer, || {
551+
Self::eth_transact(tx)
552+
})?;
553+
554+
Ok(tracer.collect_traces().pop().expect("eth_transact succeeded, trace must exist, qed"))
555+
}
499556
}
500557
}
501558

runtime/mainnet/src/config/revive.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ impl pallet_revive::Config for Runtime {
2929
// 30 percent of storage deposit held for using a code hash.
3030
type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
3131
type Currency = Balances;
32-
type Debug = ();
3332
type DepositPerByte = DepositPerByte;
3433
type DepositPerItem = DepositPerItem;
3534
type EthGasEncoder = ();
@@ -115,11 +114,6 @@ mod tests {
115114
assert_eq!(TypeId::of::<<Runtime as Config>::Currency>(), TypeId::of::<Balances>(),);
116115
}
117116

118-
#[test]
119-
fn debug_is_unset() {
120-
assert_eq!(TypeId::of::<<Runtime as Config>::Debug>(), TypeId::of::<()>(),);
121-
}
122-
123117
#[test]
124118
fn deposit_per_byte_is_correct() {
125119
assert_eq!(<<Runtime as Config>::DepositPerByte as Get<Balance>>::get(), deposit(0, 1),);

runtime/mainnet/src/lib.rs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,6 @@ pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::Account
7171
/// The address format for describing accounts.
7272
pub type Address = MultiAddress<AccountId, ()>;
7373

74-
/// Record of an event happening.
75-
pub type EventRecord = frame_system::EventRecord<
76-
<Runtime as frame_system::Config>::RuntimeEvent,
77-
<Runtime as frame_system::Config>::Hash,
78-
>;
79-
8074
/// Block header type as expected by this runtime.
8175
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;
8276

runtime/testnet/src/config/contracts.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ impl pallet_revive::Config for Runtime {
9898
// 30 percent of storage deposit held for using a code hash.
9999
type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
100100
type Currency = Balances;
101-
type Debug = ();
102101
type DepositPerByte = DepositPerByte;
103102
type DepositPerItem = DepositPerItem;
104103
type EthGasEncoder = ();

runtime/testnet/src/lib.rs

Lines changed: 64 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ impl_runtime_apis! {
683683
}
684684
}
685685

686-
impl pallet_revive::ReviveApi<Block, AccountId, Balance, Nonce, BlockNumber, EventRecord> for Runtime
686+
impl pallet_revive::ReviveApi<Block, AccountId, Balance, Nonce, BlockNumber> for Runtime
687687
{
688688
fn balance(address: H160) -> Balance {
689689
use frame_support::traits::fungible::Inspect;
@@ -726,16 +726,14 @@ impl_runtime_apis! {
726726
gas_limit: Option<Weight>,
727727
storage_deposit_limit: Option<Balance>,
728728
input_data: Vec<u8>,
729-
) -> pallet_revive::ContractResult<pallet_revive::ExecReturnValue, Balance, EventRecord> {
729+
) -> pallet_revive::ContractResult<pallet_revive::ExecReturnValue, Balance> {
730730
Revive::bare_call(
731731
RuntimeOrigin::signed(origin),
732732
dest,
733733
value,
734734
gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block),
735735
pallet_revive::DepositLimit::Balance(storage_deposit_limit.unwrap_or(u128::MAX)),
736736
input_data,
737-
pallet_revive::DebugInfo::UnsafeDebug,
738-
pallet_revive::CollectEvents::UnsafeCollect,
739737
)
740738
}
741739

@@ -747,7 +745,7 @@ impl_runtime_apis! {
747745
code: pallet_revive::Code,
748746
data: Vec<u8>,
749747
salt: Option<[u8; 32]>,
750-
) -> pallet_revive::ContractResult<pallet_revive::InstantiateReturnValue, Balance, EventRecord>
748+
) -> pallet_revive::ContractResult<pallet_revive::InstantiateReturnValue, Balance>
751749
{
752750
Revive::bare_instantiate(
753751
RuntimeOrigin::signed(origin),
@@ -757,8 +755,6 @@ impl_runtime_apis! {
757755
code,
758756
data,
759757
salt,
760-
pallet_revive::DebugInfo::UnsafeDebug,
761-
pallet_revive::CollectEvents::UnsafeCollect,
762758
)
763759
}
764760

@@ -784,6 +780,67 @@ impl_runtime_apis! {
784780
key
785781
)
786782
}
783+
784+
fn trace_block(
785+
block: Block,
786+
config: pallet_revive::evm::TracerConfig
787+
) -> Vec<(u32, pallet_revive::evm::CallTrace)> {
788+
use pallet_revive::tracing::trace;
789+
let mut tracer = config.build(Revive::evm_gas_from_weight);
790+
let mut traces = vec![];
791+
let (header, extrinsics) = block.deconstruct();
792+
793+
Executive::initialize_block(&header);
794+
for (index, ext) in extrinsics.into_iter().enumerate() {
795+
trace(&mut tracer, || {
796+
let _ = Executive::apply_extrinsic(ext);
797+
});
798+
799+
if let Some(tx_trace) = tracer.collect_traces().pop() {
800+
traces.push((index as u32, tx_trace));
801+
}
802+
}
803+
804+
traces
805+
}
806+
807+
fn trace_tx(
808+
block: Block,
809+
tx_index: u32,
810+
config: pallet_revive::evm::TracerConfig
811+
) -> Option<pallet_revive::evm::CallTrace> {
812+
use pallet_revive::tracing::trace;
813+
let mut tracer = config.build(Revive::evm_gas_from_weight);
814+
let (header, extrinsics) = block.deconstruct();
815+
816+
Executive::initialize_block(&header);
817+
for (index, ext) in extrinsics.into_iter().enumerate() {
818+
if index as u32 == tx_index {
819+
trace(&mut tracer, || {
820+
let _ = Executive::apply_extrinsic(ext);
821+
});
822+
break;
823+
} else {
824+
let _ = Executive::apply_extrinsic(ext);
825+
}
826+
}
827+
828+
tracer.collect_traces().pop()
829+
}
830+
831+
fn trace_call(
832+
tx: pallet_revive::evm::GenericTransaction,
833+
config: pallet_revive::evm::TracerConfig)
834+
-> Result<pallet_revive::evm::CallTrace, pallet_revive::EthTransactError>
835+
{
836+
use pallet_revive::tracing::trace;
837+
let mut tracer = config.build(Revive::evm_gas_from_weight);
838+
trace(&mut tracer, || {
839+
Self::eth_transact(tx)
840+
})?;
841+
842+
Ok(tracer.collect_traces().pop().expect("eth_transact succeeded, trace must exist, qed"))
843+
}
787844
}
788845

789846
impl pallet_ismp_runtime_api::IsmpRuntimeApi<Block, <Block as BlockT>::Hash> for Runtime {

0 commit comments

Comments
 (0)