From 7d29fff415c9ad08ebb34e5052a89585ce60eee2 Mon Sep 17 00:00:00 2001 From: Darioush Jalali Date: Mon, 13 Feb 2023 02:01:35 -0800 Subject: [PATCH] eth/tracers: more fork overrides in traceBlockToFile (#26655) This change allows all post-Berlin forks to be specified as overrides for futureForkBlock in the config parameter for traceBlockToFile. --- eth/tracers/api.go | 57 ++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 47 insertions(+), 10 deletions(-) diff --git a/eth/tracers/api.go b/eth/tracers/api.go index 5a34d9d4a..55c56b40c 100644 --- a/eth/tracers/api.go +++ b/eth/tracers/api.go @@ -772,17 +772,9 @@ func (api *API) standardTraceBlockToFile(ctx context.Context, block *types.Block // actual specified block, not any preceding blocks that we have to go through // in order to obtain the state. // Therefore, it's perfectly valid to specify `"futureForkBlock": 0`, to enable `futureFork` - if config != nil && config.Overrides != nil { - // Copy the config, to not screw up the main config - // Note: the Clique-part is _not_ deep copied - chainConfigCopy := new(params.ChainConfig) - *chainConfigCopy = *chainConfig - chainConfig = chainConfigCopy - if berlin := config.Config.Overrides.BerlinBlock; berlin != nil { - chainConfig.BerlinBlock = berlin - canon = false - } + // Note: This copies the config, to not screw up the main config + chainConfig, canon = overrideConfig(chainConfig, config.Overrides) } for i, tx := range block.Transactions() { // Prepare the transaction for un-traced execution @@ -1006,3 +998,48 @@ func APIs(backend Backend) []rpc.API { }, } } + +// overrideConfig returns a copy of original with forks enabled by override enabled, +// along with a boolean that indicates whether the copy is canonical (equivalent to the original). +// Note: the Clique-part is _not_ deep copied +func overrideConfig(original *params.ChainConfig, override *params.ChainConfig) (*params.ChainConfig, bool) { + copy := new(params.ChainConfig) + *copy = *original + canon := true + + // Apply forks (after Berlin) to the copy. + if block := override.BerlinBlock; block != nil { + copy.BerlinBlock = block + canon = false + } + if block := override.LondonBlock; block != nil { + copy.LondonBlock = block + canon = false + } + if block := override.ArrowGlacierBlock; block != nil { + copy.ArrowGlacierBlock = block + canon = false + } + if block := override.GrayGlacierBlock; block != nil { + copy.GrayGlacierBlock = block + canon = false + } + if block := override.MergeNetsplitBlock; block != nil { + copy.MergeNetsplitBlock = block + canon = false + } + if timestamp := override.ShanghaiTime; timestamp != nil { + copy.ShanghaiTime = timestamp + canon = false + } + if timestamp := override.CancunTime; timestamp != nil { + copy.CancunTime = timestamp + canon = false + } + if timestamp := override.PragueTime; timestamp != nil { + copy.PragueTime = timestamp + canon = false + } + + return copy, canon +}