Skip to content

Commit

Permalink
Update end_slot_hook (#742)
Browse files Browse the repository at this point in the history
* add root_hash to end_sloot_hook

* update end slot hook

* support experimental

* allow unused variables

* fix experimental flag for hooks in evm
  • Loading branch information
bkolad authored and preston-evans98 committed Sep 14, 2023
1 parent 20447be commit 19913f4
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 6 deletions.
7 changes: 6 additions & 1 deletion examples/demo-stf/src/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,13 @@ impl<C: Context, Cond: ValidityCondition> SlotHooks<Cond> for Runtime<C> {

fn end_slot_hook(
&self,
_working_set: &mut sov_state::WorkingSet<<Self::Context as sov_modules_api::Spec>::Storage>,
#[allow(unused_variables)] root_hash: [u8; 32],
#[allow(unused_variables)] working_set: &mut sov_state::WorkingSet<
<Self::Context as sov_modules_api::Spec>::Storage,
>,
) {
#[cfg(feature = "experimental")]
self.evm.end_slot_hook(root_hash, working_set);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@ impl<C: Context, Cond: ValidityCondition> SlotHooks<Cond> for TestRuntime<C, Con
self.chain_state.begin_slot_hook(slot_data, working_set)
}

fn end_slot_hook(&self, _working_set: &mut WorkingSet<<Self::Context as Spec>::Storage>) {}
fn end_slot_hook(
&self,
_root_hash: [u8; 32],
_working_set: &mut WorkingSet<<Self::Context as Spec>::Storage>,
) {
}
}

impl<C: Context, Cond: ValidityCondition> BlobSelector for TestRuntime<C, Cond> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,10 @@ impl<Ctx: Context, Cond: ValidityCondition> SlotHooks<Cond> for ChainState<Ctx,
);
}

fn end_slot_hook(&self, _working_set: &mut WorkingSet<<Self::Context as Spec>::Storage>) {}
fn end_slot_hook(
&self,
_root_hash: [u8; 32],
_working_set: &mut WorkingSet<<Self::Context as Spec>::Storage>,
) {
}
}
9 changes: 9 additions & 0 deletions module-system/module-implementations/sov-evm/src/hooks.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use sov_state::WorkingSet;

use crate::Evm;

impl<C: sov_modules_api::Context> Evm<C> {
pub fn end_slot_hook(&self, _root_hash: [u8; 32], _working_set: &mut WorkingSet<C::Storage>) {
// TODO implement block creation logic.
}
}
2 changes: 2 additions & 0 deletions module-system/module-implementations/sov-evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ pub mod call;
pub mod evm;
#[cfg(feature = "experimental")]
pub mod genesis;
#[cfg(feature = "experimental")]
pub mod hooks;
#[cfg(feature = "native")]
#[cfg(feature = "experimental")]
pub mod query;
Expand Down
6 changes: 5 additions & 1 deletion module-system/sov-modules-api/src/hooks.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,9 @@ pub trait SlotHooks<Condition: ValidityCondition> {
working_set: &mut WorkingSet<<Self::Context as Spec>::Storage>,
);

fn end_slot_hook(&self, working_set: &mut WorkingSet<<Self::Context as Spec>::Storage>);
fn end_slot_hook(
&self,
root_hash: [u8; 32],
working_set: &mut WorkingSet<<Self::Context as Spec>::Storage>,
);
}
3 changes: 1 addition & 2 deletions module-system/sov-modules-stf-template/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ where
.expect("jellyfish merkle tree update must succeed");

let mut working_set = WorkingSet::new(self.current_storage.clone());

self.runtime.end_slot_hook(&mut working_set);
self.runtime.end_slot_hook(root_hash, &mut working_set);

(jmt::RootHash(root_hash), witness)
}
Expand Down

0 comments on commit 19913f4

Please sign in to comment.