From ed798eb0d935cf7270a8bcf0b0aee99de5e6e3f8 Mon Sep 17 00:00:00 2001 From: Charles Cooper Date: Tue, 23 Jul 2024 18:08:12 +0800 Subject: [PATCH] call _reset_fork before txn simulation to minimize the chance of divergence between fork and reality --- boa/network.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/boa/network.py b/boa/network.py index 2e252178..9668c29d 100644 --- a/boa/network.py +++ b/boa/network.py @@ -274,6 +274,10 @@ def execute_code( is_modifying=True, ir_executor=None, # maybe just have **kwargs to collect extra kwargs ): + if is_modifying: + # reset to latest block for code simulation + self._reset_fork() + # call execute_code for tracing side effects # note: we could get a perf improvement if we ran this in # the background while waiting on RPC network calls @@ -351,6 +355,10 @@ def execute_code( # OVERRIDES def deploy(self, sender=None, gas=None, value=0, bytecode=b"", **kwargs): + # reset to latest block for simulation + self._reset_fork() + + # simulate the deployment local_address, computation = super().deploy( sender=sender, gas=gas, value=value, bytecode=bytecode )