Skip to content

Commit a3cdded

Browse files
committed
replay changes
Signed-off-by: Ignacio Hagopian <[email protected]>
1 parent a586f0d commit a3cdded

File tree

9 files changed

+74
-61
lines changed

9 files changed

+74
-61
lines changed

cmd/utils/cmd.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ func ImportChain(chain *core.BlockChain, fn string) error {
170170
}
171171
defer fh.Close()
172172

173+
if _, err := fh.Seek(18224628422, 0); err != nil {
174+
panic(err)
175+
}
176+
173177
var reader io.Reader = fh
174178
if strings.HasSuffix(fn, ".gz") {
175179
if reader, err = gzip.NewReader(reader); err != nil {

cmd/utils/flags.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2157,8 +2157,30 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
21572157
}
21582158
vmcfg := vm.Config{EnablePreimageRecording: ctx.Bool(VMEnableDebugFlag.Name)}
21592159

2160+
// Override the chain config with provided settings.
2161+
var overrides core.ChainOverrides
2162+
if ctx.IsSet(OverrideCancun.Name) {
2163+
v := ctx.Uint64(OverrideCancun.Name)
2164+
overrides.OverrideCancun = &v
2165+
}
2166+
if ctx.IsSet(OverridePrague.Name) {
2167+
v := ctx.Uint64(OverridePrague.Name)
2168+
overrides.OverridePrague = &v
2169+
}
2170+
if ctx.IsSet(OverrideProofInBlock.Name) {
2171+
v := ctx.Bool(OverrideProofInBlock.Name)
2172+
overrides.OverrideProofInBlock = &v
2173+
}
2174+
if ctx.IsSet(OverrideOverlayStride.Name) {
2175+
v := ctx.Uint64(OverrideOverlayStride.Name)
2176+
overrides.OverrideOverlayStride = &v
2177+
}
2178+
if ctx.IsSet(ClearVerkleCosts.Name) {
2179+
params.ClearVerkleWitnessCosts()
2180+
}
2181+
21602182
// Disable transaction indexing/unindexing by default.
2161-
chain, err := core.NewBlockChain(chainDb, cache, gspec, nil, engine, vmcfg, nil, nil)
2183+
chain, err := core.NewBlockChain(chainDb, cache, gspec, &overrides, engine, vmcfg, nil, nil)
21622184
if err != nil {
21632185
Fatalf("Can't create BlockChain: %v", err)
21642186
}

core/block_validator.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
9898
return errors.New("data blobs present in block body")
9999
}
100100
}
101-
if !v.bc.HasBlockAndState(block.ParentHash(), block.NumberU64()-1) {
102-
if !v.bc.HasBlock(block.ParentHash(), block.NumberU64()-1) {
103-
return consensus.ErrUnknownAncestor
104-
}
105-
fmt.Println("failure here")
106-
return consensus.ErrPrunedAncestor
107-
}
101+
// if !v.bc.HasBlockAndState(block.ParentHash(), block.NumberU64()-1) {
102+
// if !v.bc.HasBlock(block.ParentHash(), block.NumberU64()-1) {
103+
// return consensus.ErrUnknownAncestor
104+
// }
105+
// fmt.Println("failure here")
106+
// return consensus.ErrPrunedAncestor
107+
// }
108108
return nil
109109
}
110110

@@ -121,16 +121,16 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD
121121
if rbloom != header.Bloom {
122122
return fmt.Errorf("invalid bloom (remote: %x local: %x)", header.Bloom, rbloom)
123123
}
124-
// Tre receipt Trie's root (R = (Tr [[H1, R1], ... [Hn, Rn]]))
125-
receiptSha := types.DeriveSha(receipts, trie.NewStackTrie(nil))
126-
if receiptSha != header.ReceiptHash {
127-
return fmt.Errorf("invalid receipt root hash (remote: %x local: %x)", header.ReceiptHash, receiptSha)
128-
}
129-
// Validate the state root against the received state root and throw
130-
// an error if they don't match.
131-
if root := statedb.IntermediateRoot(v.config.IsEIP158(header.Number)); header.Root != root {
132-
return fmt.Errorf("invalid merkle root (remote: %x local: %x) dberr: %w", header.Root, root, statedb.Error())
133-
}
124+
// // Tre receipt Trie's root (R = (Tr [[H1, R1], ... [Hn, Rn]]))
125+
// receiptSha := types.DeriveSha(receipts, trie.NewStackTrie(nil))
126+
// if receiptSha != header.ReceiptHash {
127+
// return fmt.Errorf("invalid receipt root hash (remote: %x local: %x)", header.ReceiptHash, receiptSha)
128+
// }
129+
// // Validate the state root against the received state root and throw
130+
// // an error if they don't match.
131+
// if root := statedb.IntermediateRoot(v.config.IsEIP158(header.Number)); header.Root != root {
132+
// return fmt.Errorf("invalid merkle root (remote: %x local: %x) dberr: %w", header.Root, root, statedb.Error())
133+
// }
134134
// Verify that the advertised root is correct before
135135
// it can be used as an identifier for the conversion
136136
// status.

core/blockchain.go

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,11 @@
1818
package core
1919

2020
import (
21-
"bufio"
2221
"errors"
2322
"fmt"
2423
"io"
25-
"math"
2624
"math/big"
27-
"os"
2825
"runtime"
29-
"strconv"
3026
"strings"
3127
"sync"
3228
"sync/atomic"
@@ -1535,30 +1531,6 @@ func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error) {
15351531
return bc.insertChain(chain, true)
15361532
}
15371533

1538-
func findVerkleConversionBlock() (uint64, error) {
1539-
if _, err := os.Stat("conversion.txt"); os.IsNotExist(err) {
1540-
return math.MaxUint64, nil
1541-
}
1542-
1543-
f, err := os.Open("conversion.txt")
1544-
if err != nil {
1545-
log.Error("Failed to open conversion.txt", "err", err)
1546-
return 0, err
1547-
}
1548-
defer f.Close()
1549-
1550-
scanner := bufio.NewScanner(f)
1551-
scanner.Scan()
1552-
conversionBlock, err := strconv.ParseUint(scanner.Text(), 10, 64)
1553-
if err != nil {
1554-
log.Error("Failed to parse conversionBlock", "err", err)
1555-
return 0, err
1556-
}
1557-
log.Info("Found conversion block info", "conversionBlock", conversionBlock)
1558-
1559-
return conversionBlock, nil
1560-
}
1561-
15621534
// insertChain is the internal implementation of InsertChain, which assumes that
15631535
// 1) chains are contiguous, and 2) The chain mutex is held.
15641536
//
@@ -1573,11 +1545,6 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
15731545
return 0, nil
15741546
}
15751547

1576-
conversionBlock, err := findVerkleConversionBlock()
1577-
if err != nil {
1578-
return 0, err
1579-
}
1580-
15811548
// Start a parallel signature recovery (signer will fluke on fork transition, minimal perf loss)
15821549
SenderCacher.RecoverFromBlocks(types.MakeSigner(bc.chainConfig, chain[0].Number(), chain[0].Time()), chain)
15831550

@@ -1767,18 +1734,19 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error)
17671734
// is the fork block and that the conversion needs to be marked at started.
17681735
if !bc.stateCache.InTransition() && !bc.stateCache.Transitioned() {
17691736
bc.stateCache.StartVerkleTransition(parent.Root, emptyVerkleRoot, bc.Config(), bc.Config().PragueTime, parent.Root)
1737+
bc.stateCache.SetLastMerkleRoot(parent.Root)
17701738
}
17711739
} else {
17721740
// If the verkle activation time hasn't started, declare it as "not started".
17731741
// This is so that if the miner activates the conversion, the insertion happens
17741742
// in the correct mode.
17751743
bc.stateCache.InitTransitionStatus(false, false)
17761744
}
1777-
if parent.Number.Uint64() == conversionBlock {
1778-
bc.StartVerkleTransition(parent.Root, emptyVerkleRoot, bc.Config(), &parent.Time, parent.Root)
1779-
bc.stateCache.SetLastMerkleRoot(parent.Root)
1745+
stateRoot := parent.Root
1746+
if block.Header().Number.Uint64() == 4702178 {
1747+
stateRoot = common.HexToHash("0x00")
17801748
}
1781-
statedb, err := state.New(parent.Root, bc.stateCache, bc.snaps)
1749+
statedb, err := state.New(stateRoot, bc.stateCache, bc.snaps)
17821750
if err != nil {
17831751
return it.index, err
17841752
}

core/vm/contracts.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,7 @@ func init() {
151151
func ActivePrecompiles(rules params.Rules) []common.Address {
152152
switch {
153153
case rules.IsPrague:
154+
// Note: this config should be correctly set depending on replay starting point.
154155
return PrecompiledAddressesBerlin
155156
case rules.IsCancun:
156157
return PrecompiledAddressesCancun

core/vm/evm.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ type (
4141
func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) {
4242
var precompiles map[common.Address]PrecompiledContract
4343
switch {
44-
case evm.chainRules.IsPrague:
45-
precompiles = PrecompiledContractsBerlin
4644
case evm.chainRules.IsCancun:
4745
precompiles = PrecompiledContractsCancun
46+
case evm.chainRules.IsPrague:
47+
precompiles = PrecompiledContractsBerlin
4848
case evm.chainRules.IsBerlin:
4949
precompiles = PrecompiledContractsBerlin
5050
case evm.chainRules.IsIstanbul:

core/vm/interpreter.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,11 @@ func NewEVMInterpreter(evm *EVM) *EVMInterpreter {
5656
// If jump table was not initialised we set the default one.
5757
var table *JumpTable
5858
switch {
59-
case evm.chainRules.IsPrague:
60-
// TODO replace with prooper instruction set when fork is specified
61-
table = &pragueInstructionSet
6259
case evm.chainRules.IsCancun:
6360
table = &cancunInstructionSet
61+
case evm.chainRules.IsPrague:
62+
// TODO replace with proper instruction set when fork is specified
63+
table = &shanghaiInstructionSet
6464
case evm.chainRules.IsShanghai:
6565
table = &shanghaiInstructionSet
6666
case evm.chainRules.IsMerge:

params/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ func (c *ChainConfig) IsCancun(num *big.Int, time uint64) bool {
505505

506506
// IsPrague returns whether num is either equal to the Prague fork time or greater.
507507
func (c *ChainConfig) IsPrague(num *big.Int, time uint64) bool {
508-
return c.IsLondon(num) && isTimestampForked(c.PragueTime, time)
508+
return c.IsShanghai(num, time) && isTimestampForked(c.PragueTime, time)
509509
}
510510

511511
// CheckCompatible checks whether scheduled fork transitions have been imported

trie/verkle.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,24 @@ func (trie *VerkleTrie) UpdateStorage(address common.Address, key, value []byte)
223223
}
224224

225225
func (t *VerkleTrie) DeleteAccount(addr common.Address) error {
226+
var (
227+
err error
228+
values = make([][]byte, verkle.NodeWidth)
229+
stem = t.pointCache.GetTreeKeyVersionCached(addr[:])
230+
)
231+
232+
for i := 0; i < verkle.NodeWidth; i++ {
233+
values[i] = zero[:]
234+
}
235+
switch root := t.root.(type) {
236+
case *verkle.InternalNode:
237+
err = root.InsertValuesAtStem(stem, values, t.FlatdbNodeResolver)
238+
default:
239+
return errInvalidRootType
240+
}
241+
if err != nil {
242+
return fmt.Errorf("DeleteAccount (%x) error: %v", addr, err)
243+
}
226244
return nil
227245
}
228246

0 commit comments

Comments
 (0)