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
75 changes: 66 additions & 9 deletions runtime/mainnet/src/apis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ use xcm_runtime_apis::{
// Local module imports
use super::{
config::{monetary::fee::WeightToFee, system::RuntimeBlockWeights, xcm as xcm_config},
AccountId, Balance, Balances, Block, BlockNumber, BlockWeights, EthExtraImpl, EventRecord,
Executive, ExtrinsicInclusionMode, InherentDataExt, Nfts, Nonce, OriginCaller, ParachainSystem,
AccountId, Balance, Balances, Block, BlockNumber, BlockWeights, Executive,
ExtrinsicInclusionMode, InherentDataExt, Nfts, Nonce, OriginCaller, ParachainSystem,
PolkadotXcm, Revive, Runtime, RuntimeCall, RuntimeEvent, RuntimeGenesisConfig, RuntimeOrigin,
SessionKeys, System, TransactionPayment, UncheckedExtrinsic, VERSION,
};
Expand Down Expand Up @@ -395,7 +395,7 @@ impl_runtime_apis! {
}
}

impl pallet_revive::ReviveApi<Block, AccountId, Balance, Nonce, BlockNumber, EventRecord> for Runtime
impl pallet_revive::ReviveApi<Block, AccountId, Balance, Nonce, BlockNumber> for Runtime
{
fn balance(address: H160) -> Balance {
use frame_support::traits::fungible::Inspect;
Expand Down Expand Up @@ -438,16 +438,14 @@ impl_runtime_apis! {
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
input_data: Vec<u8>,
) -> pallet_revive::ContractResult<pallet_revive::ExecReturnValue, Balance, EventRecord> {
) -> pallet_revive::ContractResult<pallet_revive::ExecReturnValue, Balance> {
Revive::bare_call(
RuntimeOrigin::signed(origin),
dest,
value,
gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block),
pallet_revive::DepositLimit::Balance(storage_deposit_limit.unwrap_or(u128::MAX)),
input_data,
pallet_revive::DebugInfo::UnsafeDebug,
pallet_revive::CollectEvents::UnsafeCollect,
)
}

Expand All @@ -459,7 +457,7 @@ impl_runtime_apis! {
code: pallet_revive::Code,
data: Vec<u8>,
salt: Option<[u8; 32]>,
) -> pallet_revive::ContractResult<pallet_revive::InstantiateReturnValue, Balance, EventRecord>
) -> pallet_revive::ContractResult<pallet_revive::InstantiateReturnValue, Balance>
{
Revive::bare_instantiate(
RuntimeOrigin::signed(origin),
Expand All @@ -469,8 +467,6 @@ impl_runtime_apis! {
code,
data,
salt,
pallet_revive::DebugInfo::UnsafeDebug,
pallet_revive::CollectEvents::UnsafeCollect,
)
}

Expand All @@ -496,6 +492,67 @@ impl_runtime_apis! {
key
)
}

fn trace_block(
block: Block,
config: pallet_revive::evm::TracerConfig
) -> Vec<(u32, pallet_revive::evm::CallTrace)> {
use pallet_revive::tracing::trace;
let mut tracer = config.build(Revive::evm_gas_from_weight);
let mut traces = vec![];
let (header, extrinsics) = block.deconstruct();

Executive::initialize_block(&header);
for (index, ext) in extrinsics.into_iter().enumerate() {
trace(&mut tracer, || {
let _ = Executive::apply_extrinsic(ext);
});

if let Some(tx_trace) = tracer.collect_traces().pop() {
traces.push((index as u32, tx_trace));
}
}

traces
}

fn trace_tx(
block: Block,
tx_index: u32,
config: pallet_revive::evm::TracerConfig
) -> Option<pallet_revive::evm::CallTrace> {
use pallet_revive::tracing::trace;
let mut tracer = config.build(Revive::evm_gas_from_weight);
let (header, extrinsics) = block.deconstruct();

Executive::initialize_block(&header);
for (index, ext) in extrinsics.into_iter().enumerate() {
if index as u32 == tx_index {
trace(&mut tracer, || {
let _ = Executive::apply_extrinsic(ext);
});
break;
} else {
let _ = Executive::apply_extrinsic(ext);
}
}

tracer.collect_traces().pop()
}

fn trace_call(
tx: pallet_revive::evm::GenericTransaction,
config: pallet_revive::evm::TracerConfig)
-> Result<pallet_revive::evm::CallTrace, pallet_revive::EthTransactError>
{
use pallet_revive::tracing::trace;
let mut tracer = config.build(Revive::evm_gas_from_weight);
trace(&mut tracer, || {
Self::eth_transact(tx)
})?;

Ok(tracer.collect_traces().pop().expect("eth_transact succeeded, trace must exist, qed"))
}
}
}

Expand Down
6 changes: 0 additions & 6 deletions runtime/mainnet/src/config/revive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ impl pallet_revive::Config for Runtime {
// 30 percent of storage deposit held for using a code hash.
type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
type Currency = Balances;
type Debug = ();
type DepositPerByte = DepositPerByte;
type DepositPerItem = DepositPerItem;
type EthGasEncoder = ();
Expand Down Expand Up @@ -115,11 +114,6 @@ mod tests {
assert_eq!(TypeId::of::<<Runtime as Config>::Currency>(), TypeId::of::<Balances>(),);
}

#[test]
fn debug_is_unset() {
assert_eq!(TypeId::of::<<Runtime as Config>::Debug>(), TypeId::of::<()>(),);
}

#[test]
fn deposit_per_byte_is_correct() {
assert_eq!(<<Runtime as Config>::DepositPerByte as Get<Balance>>::get(), deposit(0, 1),);
Expand Down
6 changes: 0 additions & 6 deletions runtime/mainnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,6 @@ pub type AccountId = <<Signature as Verify>::Signer as IdentifyAccount>::Account
/// The address format for describing accounts.
pub type Address = MultiAddress<AccountId, ()>;

/// Record of an event happening.
pub type EventRecord = frame_system::EventRecord<
<Runtime as frame_system::Config>::RuntimeEvent,
<Runtime as frame_system::Config>::Hash,
>;

/// Block header type as expected by this runtime.
pub type Header = generic::Header<BlockNumber, BlakeTwo256>;

Expand Down
1 change: 0 additions & 1 deletion runtime/testnet/src/config/contracts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ impl pallet_revive::Config for Runtime {
// 30 percent of storage deposit held for using a code hash.
type CodeHashLockupDepositPercent = CodeHashLockupDepositPercent;
type Currency = Balances;
type Debug = ();
type DepositPerByte = DepositPerByte;
type DepositPerItem = DepositPerItem;
type EthGasEncoder = ();
Expand Down
71 changes: 64 additions & 7 deletions runtime/testnet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ impl_runtime_apis! {
}
}

impl pallet_revive::ReviveApi<Block, AccountId, Balance, Nonce, BlockNumber, EventRecord> for Runtime
impl pallet_revive::ReviveApi<Block, AccountId, Balance, Nonce, BlockNumber> for Runtime
{
fn balance(address: H160) -> Balance {
use frame_support::traits::fungible::Inspect;
Expand Down Expand Up @@ -726,16 +726,14 @@ impl_runtime_apis! {
gas_limit: Option<Weight>,
storage_deposit_limit: Option<Balance>,
input_data: Vec<u8>,
) -> pallet_revive::ContractResult<pallet_revive::ExecReturnValue, Balance, EventRecord> {
) -> pallet_revive::ContractResult<pallet_revive::ExecReturnValue, Balance> {
Revive::bare_call(
RuntimeOrigin::signed(origin),
dest,
value,
gas_limit.unwrap_or(RuntimeBlockWeights::get().max_block),
pallet_revive::DepositLimit::Balance(storage_deposit_limit.unwrap_or(u128::MAX)),
input_data,
pallet_revive::DebugInfo::UnsafeDebug,
pallet_revive::CollectEvents::UnsafeCollect,
)
}

Expand All @@ -747,7 +745,7 @@ impl_runtime_apis! {
code: pallet_revive::Code,
data: Vec<u8>,
salt: Option<[u8; 32]>,
) -> pallet_revive::ContractResult<pallet_revive::InstantiateReturnValue, Balance, EventRecord>
) -> pallet_revive::ContractResult<pallet_revive::InstantiateReturnValue, Balance>
{
Revive::bare_instantiate(
RuntimeOrigin::signed(origin),
Expand All @@ -757,8 +755,6 @@ impl_runtime_apis! {
code,
data,
salt,
pallet_revive::DebugInfo::UnsafeDebug,
pallet_revive::CollectEvents::UnsafeCollect,
)
}

Expand All @@ -784,6 +780,67 @@ impl_runtime_apis! {
key
)
}

fn trace_block(
block: Block,
config: pallet_revive::evm::TracerConfig
) -> Vec<(u32, pallet_revive::evm::CallTrace)> {
use pallet_revive::tracing::trace;
let mut tracer = config.build(Revive::evm_gas_from_weight);
let mut traces = vec![];
let (header, extrinsics) = block.deconstruct();

Executive::initialize_block(&header);
for (index, ext) in extrinsics.into_iter().enumerate() {
trace(&mut tracer, || {
let _ = Executive::apply_extrinsic(ext);
});

if let Some(tx_trace) = tracer.collect_traces().pop() {
traces.push((index as u32, tx_trace));
}
}

traces
}

fn trace_tx(
block: Block,
tx_index: u32,
config: pallet_revive::evm::TracerConfig
) -> Option<pallet_revive::evm::CallTrace> {
use pallet_revive::tracing::trace;
let mut tracer = config.build(Revive::evm_gas_from_weight);
let (header, extrinsics) = block.deconstruct();

Executive::initialize_block(&header);
for (index, ext) in extrinsics.into_iter().enumerate() {
if index as u32 == tx_index {
trace(&mut tracer, || {
let _ = Executive::apply_extrinsic(ext);
});
break;
} else {
let _ = Executive::apply_extrinsic(ext);
}
}

tracer.collect_traces().pop()
}

fn trace_call(
tx: pallet_revive::evm::GenericTransaction,
config: pallet_revive::evm::TracerConfig)
-> Result<pallet_revive::evm::CallTrace, pallet_revive::EthTransactError>
{
use pallet_revive::tracing::trace;
let mut tracer = config.build(Revive::evm_gas_from_weight);
trace(&mut tracer, || {
Self::eth_transact(tx)
})?;

Ok(tracer.collect_traces().pop().expect("eth_transact succeeded, trace must exist, qed"))
}
}

impl pallet_ismp_runtime_api::IsmpRuntimeApi<Block, <Block as BlockT>::Hash> for Runtime {
Expand Down
Loading