Skip to content

Commit

Permalink
replay changes
Browse files Browse the repository at this point in the history
Signed-off-by: Ignacio Hagopian <[email protected]>
  • Loading branch information
jsign committed Jan 23, 2024
1 parent cebbd4f commit 4044d75
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 22 deletions.
1 change: 1 addition & 0 deletions cmd/geth/conversion.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
4702177
4 changes: 4 additions & 0 deletions cmd/utils/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ func ImportChain(chain *core.BlockChain, fn string) error {
}
defer fh.Close()

if _, err := fh.Seek(18224628422, 0); err != nil {
panic(err)
}

var reader io.Reader = fh
if strings.HasSuffix(fn, ".gz") {
if reader, err = gzip.NewReader(reader); err != nil {
Expand Down
23 changes: 22 additions & 1 deletion cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -2156,8 +2156,29 @@ func MakeChain(ctx *cli.Context, stack *node.Node, readonly bool) (*core.BlockCh
}
vmcfg := vm.Config{EnablePreimageRecording: ctx.Bool(VMEnableDebugFlag.Name)}

// Override the chain config with provided settings.
var overrides core.ChainOverrides
if ctx.IsSet(OverrideCancun.Name) {
v := ctx.Uint64(OverrideCancun.Name)
overrides.OverrideCancun = &v
}
if ctx.IsSet(OverridePrague.Name) {
v := ctx.Uint64(OverridePrague.Name)
overrides.OverridePrague = &v
}
if ctx.IsSet(OverrideProofInBlock.Name) {
v := ctx.Bool(OverrideProofInBlock.Name)
overrides.OverrideProofInBlock = &v
}
if ctx.IsSet(OverrideOverlayStride.Name) {
v := ctx.Uint64(OverrideOverlayStride.Name)
overrides.OverrideOverlayStride = &v
}
if ctx.IsSet(ClearVerkleCosts.Name) {
params.ClearVerkleWitnessCosts()
}
// Disable transaction indexing/unindexing by default.
chain, err := core.NewBlockChain(chainDb, cache, gspec, nil, engine, vmcfg, nil, nil)
chain, err := core.NewBlockChain(chainDb, cache, gspec, &overrides, engine, vmcfg, nil, nil)
if err != nil {
Fatalf("Can't create BlockChain: %v", err)
}
Expand Down
34 changes: 17 additions & 17 deletions core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ func (v *BlockValidator) ValidateBody(block *types.Block) error {
return errors.New("data blobs present in block body")
}
}
if !v.bc.HasBlockAndState(block.ParentHash(), block.NumberU64()-1) {
if !v.bc.HasBlock(block.ParentHash(), block.NumberU64()-1) {
return consensus.ErrUnknownAncestor
}
fmt.Println("failure here")
return consensus.ErrPrunedAncestor
}
// if !v.bc.HasBlockAndState(block.ParentHash(), block.NumberU64()-1) {
// if !v.bc.HasBlock(block.ParentHash(), block.NumberU64()-1) {
// return consensus.ErrUnknownAncestor
// }
// fmt.Println("failure here")
// return consensus.ErrPrunedAncestor
// }
return nil
}

Expand All @@ -121,16 +121,16 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD
if rbloom != header.Bloom {
return fmt.Errorf("invalid bloom (remote: %x local: %x)", header.Bloom, rbloom)
}
// Tre receipt Trie's root (R = (Tr [[H1, R1], ... [Hn, Rn]]))
receiptSha := types.DeriveSha(receipts, trie.NewStackTrie(nil))
if receiptSha != header.ReceiptHash {
return fmt.Errorf("invalid receipt root hash (remote: %x local: %x)", header.ReceiptHash, receiptSha)
}
// Validate the state root against the received state root and throw
// an error if they don't match.
if root := statedb.IntermediateRoot(v.config.IsEIP158(header.Number)); header.Root != root {
return fmt.Errorf("invalid merkle root (remote: %x local: %x) dberr: %w", header.Root, root, statedb.Error())
}
// // Tre receipt Trie's root (R = (Tr [[H1, R1], ... [Hn, Rn]]))
// receiptSha := types.DeriveSha(receipts, trie.NewStackTrie(nil))
// if receiptSha != header.ReceiptHash {
// return fmt.Errorf("invalid receipt root hash (remote: %x local: %x)", header.ReceiptHash, receiptSha)
// }
// // Validate the state root against the received state root and throw
// // an error if they don't match.
// if root := statedb.IntermediateRoot(v.config.IsEIP158(header.Number)); header.Root != root {
// return fmt.Errorf("invalid merkle root (remote: %x local: %x) dberr: %w", header.Root, root, statedb.Error())
// }
statedb.Database().SaveTransitionState(header.Root)
return nil
}
Expand Down
10 changes: 9 additions & 1 deletion core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/misc"
"github.com/ethereum/go-ethereum/core/overlay"
"github.com/ethereum/go-ethereum/core/state"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/core/vm"
Expand Down Expand Up @@ -97,7 +98,14 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
return nil, nil, 0, errors.New("withdrawals before shanghai")
}

// Perform the overlay transition, if relevant
state, err := p.bc.State()
if err != nil {
return nil, nil, 0, fmt.Errorf("get statedb: %s", err)
}
parent := p.bc.GetHeaderByHash(header.ParentHash)
if err := overlay.OverlayVerkleTransition(state, parent.Root, p.config.OverlayStride); err != nil {
log.Error("error performing the transition", "err", err)
}

// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
p.engine.Finalize(p.bc, header, statedb, block.Transactions(), block.Uncles(), withdrawals)
Expand Down
1 change: 0 additions & 1 deletion core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,6 @@ func (evm *EVM) Call(caller ContractRef, addr common.Address, input []byte, gas
}(gas)
}
}

if isPrecompile {
ret, gas, err = RunPrecompiledContract(p, input, gas)
} else {
Expand Down
3 changes: 2 additions & 1 deletion core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ func NewEVMInterpreter(evm *EVM) *EVMInterpreter {
switch {
case evm.chainRules.IsPrague:
// TODO replace with prooper instruction set when fork is specified
table = &shanghaiInstructionSet
// table = &shanghaiInstructionSet
table = &byzantiumInstructionSet
case evm.chainRules.IsCancun:
table = &cancunInstructionSet
case evm.chainRules.IsShanghai:
Expand Down
3 changes: 2 additions & 1 deletion params/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,8 @@ 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 num.Uint64() >= 4702177
// return c.IsLondon(num) && isTimestampForked(c.PragueTime, time)
}

// CheckCompatible checks whether scheduled fork transitions have been imported
Expand Down

0 comments on commit 4044d75

Please sign in to comment.