Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Ignacio Hagopian <[email protected]>
  • Loading branch information
jsign committed Oct 24, 2024
1 parent b08b06b commit dcaffc6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
25 changes: 11 additions & 14 deletions consensus/beacon/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,16 @@ func (beacon *Beacon) FinalizeAndAssemble(chain consensus.ChainHeaderReader, hea
proot common.Hash
)
if chain.Config().IsVerkle(header.Number, header.Time) {
parent := chain.GetHeaderByNumber(header.Number.Uint64() - 1)
if parent == nil {
return nil, fmt.Errorf("nil parent header for block %d", header.Number)
}
// Load transition state at beginning of block, because
// OpenTrie needs to know what the conversion status is.
state.Database().LoadTransitionState(parent.Root)

var err error
proot, stateDiff, proof, err = BuildVerkleProof(chain, header, state)
proot, stateDiff, proof, err = BuildVerkleProof(header, state, parent.Root)
if err != nil {
return nil, fmt.Errorf("error building verkle proof: %w", err)
}
Expand All @@ -420,24 +428,13 @@ func (beacon *Beacon) FinalizeAndAssemble(chain consensus.ChainHeaderReader, hea
return block, nil
}

func BuildVerkleProof(chain consensus.ChainHeaderReader, header *types.Header, state *state.StateDB) (common.Hash, verkle.StateDiff, *verkle.VerkleProof, error) {
func BuildVerkleProof(header *types.Header, state *state.StateDB, parentRoot common.Hash) (common.Hash, verkle.StateDiff, *verkle.VerkleProof, error) {
var (
proof *verkle.VerkleProof
stateDiff verkle.StateDiff
)

// Open the pre-tree to prove the pre-state against
parent := chain.GetHeaderByNumber(header.Number.Uint64() - 1)
if parent == nil {
return common.Hash{}, nil, nil, fmt.Errorf("nil parent header for block %d", header.Number)
}
parentRoot := parent.Root

// Load transition state at beginning of block, because
// OpenTrie needs to know what the conversion status is.
state.Database().LoadTransitionState(parent.Root)

preTrie, err := state.Database().OpenTrie(parent.Root)
preTrie, err := state.Database().OpenTrie(parentRoot)
if err != nil {
return common.Hash{}, nil, nil, fmt.Errorf("error opening pre-state tree root: %w", err)
}
Expand Down
6 changes: 5 additions & 1 deletion core/block_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ func (v *BlockValidator) ValidateState(block *types.Block, statedb *state.StateD
// test filling. When running these tests, geth decides when inserting some blocks that it is a side chain
// and the execution witness is lost. This is a workaround to avoid failing the tests until fixed.
if v.bc.Config().IsVerkle(header.Number, header.Time) && block.ExecutionWitness() != nil {
proot, stateDiff, proof, err := beacon.BuildVerkleProof(v.bc, header, statedb)
parent := v.bc.GetHeaderByNumber(header.Number.Uint64() - 1)
if parent == nil {
return fmt.Errorf("nil parent header for block %d", header.Number)
}
proot, stateDiff, proof, err := beacon.BuildVerkleProof(header, statedb, parent.Root)
if err != nil {
return fmt.Errorf("error building verkle proof: %w", err)
}
Expand Down

0 comments on commit dcaffc6

Please sign in to comment.