Skip to content

Commit 3366506

Browse files
committed
feat: disable nonce checks
1 parent f82e063 commit 3366506

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "trevm"
3-
version = "0.20.2"
3+
version = "0.20.3"
44
rust-version = "1.83.0"
55
edition = "2021"
66
authors = ["init4"]

src/evm.rs

+27-3
Original file line numberDiff line numberDiff line change
@@ -891,9 +891,33 @@ impl<Db: Database, Insp, TrevmState: HasCfg> Trevm<Db, Insp, TrevmState> {
891891
self.disable_base_fee();
892892

893893
let mut new = f(self);
894-
if !previous {
895-
new.enable_base_fee();
896-
}
894+
new.inner.data.ctx.modify_cfg(|cfg| cfg.disable_base_fee = previous);
895+
new
896+
}
897+
898+
/// Disable nonce checks. This allows transactions to be sent with
899+
/// incorrect nonces, and is useful for things like system transactions.
900+
pub fn disable_nonce_check(&mut self) {
901+
self.inner.data.ctx.modify_cfg(|cfg| cfg.disable_nonce_check = true)
902+
}
903+
904+
/// Enable nonce checks. See [`Self::disable_nonce_check`].
905+
pub fn enable_nonce_check(&mut self) {
906+
self.inner.data.ctx.modify_cfg(|cfg| cfg.disable_nonce_check = false)
907+
}
908+
909+
/// Run a closure with nonce checks disabled, then restore the previous
910+
/// setting. This will not affect the block and tx, if those have been
911+
/// filled.
912+
pub fn without_nonce_check<F, NewState: HasCfg>(mut self, f: F) -> Trevm<Db, Insp, NewState>
913+
where
914+
F: FnOnce(Self) -> Trevm<Db, Insp, NewState>,
915+
{
916+
let previous = self.inner.cfg().disable_nonce_check;
917+
self.disable_nonce_check();
918+
919+
let mut new = f(self);
920+
new.inner.data.ctx.modify_cfg(|cfg| cfg.disable_nonce_check = previous);
897921
new
898922
}
899923
}

0 commit comments

Comments
 (0)