Skip to content

Commit

Permalink
eth/tracers: more fork overrides in traceBlockToFile (#26655)
Browse files Browse the repository at this point in the history
This change allows all post-Berlin forks to be specified as overrides for futureForkBlock in the config parameter for traceBlockToFile.
  • Loading branch information
darioush committed Feb 13, 2023
1 parent 2def62b commit 7d29fff
Showing 1 changed file with 47 additions and 10 deletions.
57 changes: 47 additions & 10 deletions eth/tracers/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

0 comments on commit 7d29fff

Please sign in to comment.