Skip to content

Commit

Permalink
implemented trait on Pallet
Browse files Browse the repository at this point in the history
  • Loading branch information
Maar-io committed Jul 17, 2023
1 parent 1333fb6 commit 687f9a3
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion frame/deepmind/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ pub mod pallet {
}
}
}

pub trait Tracer: Send {
// fn is_enabled() -> bool { false }

Expand Down Expand Up @@ -139,7 +140,7 @@ pub trait BlockTrait {
fn end_block(num: U256, size: u64, header: PartialHeader);
}

impl BlockTrait for BlockContext {
impl<T> BlockTrait for Pallet<T> {
fn end_block(num: U256, size: u64, header: PartialHeader) {
print(
format!(
Expand Down
11 changes: 7 additions & 4 deletions frame/ethereum/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ mod tests;

// mod firehose;
// use crate::firehose::BlockTrait;
use deepmind::BlockTrait as Firehose;
use deepmind::BlockTrait;

pub use catch_exec_info::catch_exec_info;

Expand Down Expand Up @@ -203,6 +203,8 @@ pub mod pallet {
type PostLogContent: Get<PostLogContent>;
/// The maximum length of the extra data in the Executed event.
type ExtraDataLength: Get<u32>;
/// Firehose implementation pallet
type Firehose: BlockTrait;
}

#[pallet::hooks]
Expand All @@ -217,7 +219,8 @@ pub mod pallet {
frame_system::Pallet::<T>::block_number(),
)),
);
<deepmind::BlockContext as Firehose>::finalize_block(n.unique_saturated_into());
// <deepmind::BlockContext as Firehose>::finalize_block(n.unique_saturated_into());
T::Firehose::finalize_block(n.unique_saturated_into());
// move block hash pruning window by one block
let block_hash_count = T::BlockHashCount::get();
let to_remove = n
Expand Down Expand Up @@ -437,7 +440,7 @@ impl<T: Config> Pallet<T> {
};
let block = ethereum::Block::new(partial_header.clone(), transactions.clone(), ommers);

<deepmind::BlockContext as Firehose>::end_block(block_number, 0, partial_header.clone());
T::Firehose::end_block(block_number, 0, partial_header.clone());
CurrentBlock::<T>::put(block.clone());
CurrentReceipts::<T>::put(receipts.clone());
CurrentTransactionStatuses::<T>::put(statuses.clone());
Expand Down Expand Up @@ -543,7 +546,7 @@ impl<T: Config> Pallet<T> {
transaction: Transaction,
) -> DispatchResultWithPostInfo {
let (to, _, info) = Self::execute(source, &transaction, None)?;
<deepmind::BlockContext as Firehose>::start_transaction(&transaction, &source, to);
T::Firehose::start_transaction(&transaction, &source, to);

catch_exec_info::fill_exec_info(&info);

Expand Down
4 changes: 4 additions & 0 deletions frame/ethereum/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,12 @@ frame_support::construct_runtime! {
Timestamp: pallet_timestamp::{Pallet, Call, Storage},
EVM: pallet_evm::{Pallet, Call, Storage, Config, Event<T>},
Ethereum: crate::{Pallet, Call, Storage, Event, Origin},
DeepMind: deepmind::{Pallet, Call, Storage},
}
}

impl deepmind::Config for Test {}

parameter_types! {
pub const BlockHashCount: u64 = 250;
}
Expand Down Expand Up @@ -182,6 +185,7 @@ impl Config for Test {
type StateRoot = IntermediateStateRoot<Self>;
type PostLogContent = PostBlockAndTxnHashes;
type ExtraDataLength = ConstU32<30>;
type Firehose = DeepMind;
}

impl fp_self_contained::SelfContainedCall for RuntimeCall {
Expand Down
1 change: 1 addition & 0 deletions template/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ fp-evm = { workspace = true }
fp-rpc = { workspace = true }
fp-self-contained = { workspace = true }
# Frontier FRAME
deepmind = { workspace = true }
pallet-base-fee = { workspace = true }
pallet-dynamic-fee = { workspace = true }
pallet-ethereum = { workspace = true }
Expand Down
4 changes: 4 additions & 0 deletions template/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,11 @@ impl pallet_ethereum::Config for Runtime {
type StateRoot = pallet_ethereum::IntermediateStateRoot<Self>;
type PostLogContent = PostBlockAndTxnHashes;
type ExtraDataLength = ConstU32<30>;
type Firehose = DeepMind;
}

impl deepmind::Config for Runtime {}

parameter_types! {
pub BoundDivision: U256 = U256::from(1024);
}
Expand Down Expand Up @@ -409,6 +412,7 @@ construct_runtime!(
DynamicFee: pallet_dynamic_fee,
BaseFee: pallet_base_fee,
HotfixSufficients: pallet_hotfix_sufficients,
DeepMind: deepmind::{Pallet, Call, Storage},
}
);

Expand Down

0 comments on commit 687f9a3

Please sign in to comment.