-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Post-Shapella Replay #431
base: kaustinen-with-shapella
Are you sure you want to change the base?
Post-Shapella Replay #431
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,15 +18,11 @@ | |
package core | ||
|
||
import ( | ||
"bufio" | ||
"errors" | ||
"fmt" | ||
"io" | ||
"math" | ||
"math/big" | ||
"os" | ||
"runtime" | ||
"strconv" | ||
"strings" | ||
"sync" | ||
"sync/atomic" | ||
|
@@ -1535,30 +1531,6 @@ func (bc *BlockChain) InsertChain(chain types.Blocks) (int, error) { | |
return bc.insertChain(chain, true) | ||
} | ||
|
||
func findVerkleConversionBlock() (uint64, error) { | ||
if _, err := os.Stat("conversion.txt"); os.IsNotExist(err) { | ||
return math.MaxUint64, nil | ||
} | ||
|
||
f, err := os.Open("conversion.txt") | ||
if err != nil { | ||
log.Error("Failed to open conversion.txt", "err", err) | ||
return 0, err | ||
} | ||
defer f.Close() | ||
|
||
scanner := bufio.NewScanner(f) | ||
scanner.Scan() | ||
conversionBlock, err := strconv.ParseUint(scanner.Text(), 10, 64) | ||
if err != nil { | ||
log.Error("Failed to parse conversionBlock", "err", err) | ||
return 0, err | ||
} | ||
log.Info("Found conversion block info", "conversionBlock", conversionBlock) | ||
|
||
return conversionBlock, nil | ||
} | ||
|
||
// insertChain is the internal implementation of InsertChain, which assumes that | ||
// 1) chains are contiguous, and 2) The chain mutex is held. | ||
// | ||
|
@@ -1573,11 +1545,6 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) | |
return 0, nil | ||
} | ||
|
||
conversionBlock, err := findVerkleConversionBlock() | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
// Start a parallel signature recovery (signer will fluke on fork transition, minimal perf loss) | ||
SenderCacher.RecoverFromBlocks(types.MakeSigner(bc.chainConfig, chain[0].Number(), chain[0].Time()), chain) | ||
|
||
|
@@ -1767,18 +1734,19 @@ func (bc *BlockChain) insertChain(chain types.Blocks, setHead bool) (int, error) | |
// is the fork block and that the conversion needs to be marked at started. | ||
if !bc.stateCache.InTransition() && !bc.stateCache.Transitioned() { | ||
bc.stateCache.StartVerkleTransition(parent.Root, emptyVerkleRoot, bc.Config(), bc.Config().PragueTime, parent.Root) | ||
bc.stateCache.SetLastMerkleRoot(parent.Root) | ||
} | ||
} else { | ||
// If the verkle activation time hasn't started, declare it as "not started". | ||
// This is so that if the miner activates the conversion, the insertion happens | ||
// in the correct mode. | ||
bc.stateCache.InitTransitionStatus(false, false) | ||
} | ||
if parent.Number.Uint64() == conversionBlock { | ||
bc.StartVerkleTransition(parent.Root, emptyVerkleRoot, bc.Config(), &parent.Time, parent.Root) | ||
bc.stateCache.SetLastMerkleRoot(parent.Root) | ||
stateRoot := parent.Root | ||
if block.Header().Number.Uint64() == 4702178 { | ||
stateRoot = common.HexToHash("0x00") | ||
} | ||
Comment on lines
+1745
to
1748
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So this was a very ugly rabbit hole due to a bug in the way our previous replay data was exported. In the previous setup the first block to be replayed was 4702177 and unfortunately that block had a snapshot in the state. We need to force any second (i.e: previously 4702178) or further block to always read from the tree and not use snapshots. Maybe the new replay data wasn't corrupted in that way and we can remove this. But it's worth checking that |
||
statedb, err := state.New(parent.Root, bc.stateCache, bc.snaps) | ||
statedb, err := state.New(stateRoot, bc.stateCache, bc.snaps) | ||
if err != nil { | ||
return it.index, err | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -151,6 +151,7 @@ func init() { | |
func ActivePrecompiles(rules params.Rules) []common.Address { | ||
switch { | ||
case rules.IsPrague: | ||
// Note: this config should be correctly set depending on replay starting point. | ||
return PrecompiledAddressesBerlin | ||
Comment on lines
+154
to
155
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In our previous replay branch, we had to override this to be Left a comment here to remember to keep updating this as we keep rebasing Verkle further down the forks. I can remove it though, since maybe from now forward the default branch and replay data will always match. |
||
case rules.IsCancun: | ||
return PrecompiledAddressesCancun | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,10 +41,10 @@ type ( | |
func (evm *EVM) precompile(addr common.Address) (PrecompiledContract, bool) { | ||
var precompiles map[common.Address]PrecompiledContract | ||
switch { | ||
case evm.chainRules.IsPrague: | ||
precompiles = PrecompiledContractsBerlin | ||
case evm.chainRules.IsCancun: | ||
precompiles = PrecompiledContractsCancun | ||
case evm.chainRules.IsPrague: | ||
precompiles = PrecompiledContractsBerlin | ||
Comment on lines
-44
to
+47
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to express the correct order since we're rebased on top of shapella, not cancun. |
||
case evm.chainRules.IsBerlin: | ||
precompiles = PrecompiledContractsBerlin | ||
case evm.chainRules.IsIstanbul: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,11 +56,11 @@ func NewEVMInterpreter(evm *EVM) *EVMInterpreter { | |
// If jump table was not initialised we set the default one. | ||
var table *JumpTable | ||
switch { | ||
case evm.chainRules.IsPrague: | ||
// TODO replace with prooper instruction set when fork is specified | ||
table = &pragueInstructionSet | ||
case evm.chainRules.IsCancun: | ||
table = &cancunInstructionSet | ||
case evm.chainRules.IsPrague: | ||
// TODO replace with proper instruction set when fork is specified | ||
table = &shanghaiInstructionSet | ||
Comment on lines
-59
to
+63
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is an important change for replay since we're replaying history without many gas changes for Verkle. Before potentially merging this branch into |
||
case evm.chainRules.IsShanghai: | ||
table = &shanghaiInstructionSet | ||
case evm.chainRules.IsMerge: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -505,7 +505,7 @@ func (c *ChainConfig) IsCancun(num *big.Int, time uint64) bool { | |
|
||
// IsPrague returns whether num is either equal to the Prague fork time or greater. | ||
func (c *ChainConfig) IsPrague(num *big.Int, time uint64) bool { | ||
return c.IsLondon(num) && isTimestampForked(c.PragueTime, time) | ||
return c.IsShanghai(num, time) && isTimestampForked(c.PragueTime, time) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we might need to do a similar change in |
||
} | ||
|
||
// CheckCompatible checks whether scheduled fork transitions have been imported | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -223,6 +223,24 @@ func (trie *VerkleTrie) UpdateStorage(address common.Address, key, value []byte) | |
} | ||
|
||
func (t *VerkleTrie) DeleteAccount(addr common.Address) error { | ||
var ( | ||
err error | ||
values = make([][]byte, verkle.NodeWidth) | ||
stem = t.pointCache.GetTreeKeyVersionCached(addr[:]) | ||
) | ||
|
||
for i := 0; i < verkle.NodeWidth; i++ { | ||
values[i] = zero[:] | ||
} | ||
switch root := t.root.(type) { | ||
case *verkle.InternalNode: | ||
err = root.InsertValuesAtStem(stem, values, t.FlatdbNodeResolver) | ||
default: | ||
return errInvalidRootType | ||
} | ||
if err != nil { | ||
return fmt.Errorf("DeleteAccount (%x) error: %v", addr, err) | ||
} | ||
Comment on lines
+226
to
+243
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another thing that we should make dynamic if we merge replay in |
||
return nil | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was removed since we don't rely on the old
.txt
anymore but in timestamps.