Skip to content

Commit

Permalink
Add Prague fork support (erigontech#7005)
Browse files Browse the repository at this point in the history
Prague is the next EL fork after
[Cancun](https://github.com/ethereum/execution-specs/blob/master/network-upgrades/mainnet-upgrades/cancun.md).
This change picks up ledgerwatch/erigon-lib#913,
adds support of the fork, and moves Verkle trees to it.
  • Loading branch information
yperbasis authored Mar 2, 2023
1 parent 2ff8f3b commit 1dab298
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 42 deletions.
39 changes: 2 additions & 37 deletions consensus/misc/eip1559_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,43 +30,8 @@ import (
// copyConfig does a _shallow_ copy of a given config. Safe to set new values, but
// do not use e.g. SetInt() on the numbers. For testing only
func copyConfig(original *chain.Config) *chain.Config {
return &chain.Config{
ChainName: original.ChainName,
ChainID: original.ChainID,
Consensus: original.Consensus,
HomesteadBlock: original.HomesteadBlock,
DAOForkBlock: original.DAOForkBlock,
DAOForkSupport: original.DAOForkSupport,
TangerineWhistleBlock: original.TangerineWhistleBlock,
TangerineWhistleHash: original.TangerineWhistleHash,
SpuriousDragonBlock: original.SpuriousDragonBlock,
ByzantiumBlock: original.ByzantiumBlock,
ConstantinopleBlock: original.ConstantinopleBlock,
PetersburgBlock: original.PetersburgBlock,
IstanbulBlock: original.IstanbulBlock,
MuirGlacierBlock: original.MuirGlacierBlock,
BerlinBlock: original.BerlinBlock,
LondonBlock: original.LondonBlock,
ArrowGlacierBlock: original.ArrowGlacierBlock,
GrayGlacierBlock: original.GrayGlacierBlock,
TerminalTotalDifficulty: original.TerminalTotalDifficulty,
TerminalTotalDifficultyPassed: original.TerminalTotalDifficultyPassed,
MergeNetsplitBlock: original.MergeNetsplitBlock,
ShanghaiTime: original.ShanghaiTime,
CancunTime: original.CancunTime,
RamanujanBlock: original.RamanujanBlock,
NielsBlock: original.NielsBlock,
MirrorSyncBlock: original.MirrorSyncBlock,
BrunoBlock: original.BrunoBlock,
EulerBlock: original.EulerBlock,
GibbsBlock: original.GibbsBlock,
PosdaoBlock: original.PosdaoBlock,
Ethash: original.Ethash,
Clique: original.Clique,
Aura: original.Aura,
Parlia: original.Parlia,
Bor: original.Bor,
}
copy := *original
return &copy
}

func config() *chain.Config {
Expand Down
2 changes: 2 additions & 0 deletions core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ func copyJumpTable(jt *JumpTable) *JumpTable {
func NewEVMInterpreter(evm VMInterpreter, cfg Config) *EVMInterpreter {
var jt *JumpTable
switch {
case evm.ChainRules().IsPrague:
jt = &pragueInstructionSet
case evm.ChainRules().IsCancun:
jt = &cancunInstructionSet
case evm.ChainRules().IsShanghai:
Expand Down
10 changes: 10 additions & 0 deletions core/vm/jump_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ var (
londonInstructionSet = newLondonInstructionSet()
shanghaiInstructionSet = newShanghaiInstructionSet()
cancunInstructionSet = newCancunInstructionSet()
pragueInstructionSet = newPragueInstructionSet()
)

// JumpTable contains the EVM opcodes supported at a given fork.
Expand All @@ -85,6 +86,15 @@ func validateAndFillMaxStack(jt *JumpTable) {
}
}

// newPragueInstructionSet returns the frontier, homestead, byzantium,
// constantinople, istanbul, petersburg, berlin, london, paris, shanghai,
// cancun, and prague instructions.
func newPragueInstructionSet() JumpTable {
instructionSet := newCancunInstructionSet()
validateAndFillMaxStack(&instructionSet)
return instructionSet
}

// newCancunInstructionSet returns the frontier, homestead, byzantium,
// constantinople, istanbul, petersburg, berlin, london, paris, shanghai,
// and cancun instructions.
Expand Down
1 change: 1 addition & 0 deletions core/vm/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func setDefaults(cfg *Config) {
GrayGlacierBlock: new(big.Int),
ShanghaiTime: new(big.Int),
CancunTime: new(big.Int),
PragueTime: new(big.Int),
}
}

Expand Down
4 changes: 2 additions & 2 deletions eth/stagedsync/default_stages.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,15 @@ func DefaultStages(ctx context.Context, snapshots SnapshotsCfg, headers HeadersC
ID: stages.IntermediateHashes,
Description: "Generate intermediate hashes and computing state root",
Forward: func(firstCycle bool, badBlockUnwind bool, s *StageState, u Unwinder, tx kv.RwTx, quiet bool) error {
if exec.chainConfig.IsCancun(0) {
if exec.chainConfig.IsPrague(0) {
_, err := SpawnVerkleTrie(s, u, tx, trieCfg, ctx)
return err
}
_, err := SpawnIntermediateHashesStage(s, u, tx, trieCfg, ctx, quiet)
return err
},
Unwind: func(firstCycle bool, u *UnwindState, s *StageState, tx kv.RwTx) error {
if exec.chainConfig.IsCancun(0) {
if exec.chainConfig.IsPrague(0) {
return UnwindVerkleTrie(u, s, tx, trieCfg, ctx)
}
return UnwindIntermediateHashesStage(u, s, tx, trieCfg, ctx)
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/ledgerwatch/erigon
go 1.18

require (
github.com/ledgerwatch/erigon-lib v0.0.0-20230301065635-fc6d2d0b39ad
github.com/ledgerwatch/erigon-lib v0.0.0-20230302161235-37a1bdc80606
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230224032817-e29f5ad218a2
github.com/ledgerwatch/log/v3 v3.7.0
github.com/ledgerwatch/secp256k1 v1.0.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -517,8 +517,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758 h1:0D5M2HQSGD3PYPwICLl+/9oulQauOuETfgFvhBDffs0=
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
github.com/ledgerwatch/erigon-lib v0.0.0-20230301065635-fc6d2d0b39ad h1:yduDUvCubAhxC+Gtg6b/37xPKBam+UZzMM7bDfGWFyQ=
github.com/ledgerwatch/erigon-lib v0.0.0-20230301065635-fc6d2d0b39ad/go.mod h1:xcrJLJiNfthKFectsWBUtRJK9d6XtjiyQRGVeImRYRs=
github.com/ledgerwatch/erigon-lib v0.0.0-20230302161235-37a1bdc80606 h1:sLTTcb58oy3VOq4q1fP4ENJlqdDA2LDFt8CZcxgd9Yw=
github.com/ledgerwatch/erigon-lib v0.0.0-20230302161235-37a1bdc80606/go.mod h1:xcrJLJiNfthKFectsWBUtRJK9d6XtjiyQRGVeImRYRs=
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230224032817-e29f5ad218a2 h1:Vf5oUCq9s4JSLd5/WJxq8zTuMY5Brn8So0yeJDvUauc=
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230224032817-e29f5ad218a2/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo=
github.com/ledgerwatch/log/v3 v3.7.0 h1:aFPEZdwZx4jzA3+/Pf8wNDN5tCI0cIolq/kfvgcM+og=
Expand Down

0 comments on commit 1dab298

Please sign in to comment.