mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
use WithWitness and rename a few variables
This commit is contained in:
parent
0d72a4c26b
commit
7f99bdc137
3 changed files with 24 additions and 9 deletions
|
|
@ -252,7 +252,9 @@ func ExecutableDataToBlock(data ExecutableData, versionedHashes []common.Hash, b
|
||||||
BlobGasUsed: data.BlobGasUsed,
|
BlobGasUsed: data.BlobGasUsed,
|
||||||
ParentBeaconRoot: beaconRoot,
|
ParentBeaconRoot: beaconRoot,
|
||||||
}
|
}
|
||||||
block := types.NewBlockWithHeader(header).WithBody(types.Body{Transactions: txs, Uncles: nil, Withdrawals: data.Withdrawals, Witness: data.ExecutionWitness})
|
block := types.NewBlockWithHeader(header)
|
||||||
|
block = block.WithBody(types.Body{Transactions: txs, Uncles: nil, Withdrawals: data.Withdrawals})
|
||||||
|
block = block.WithWitness(data.ExecutionWitness)
|
||||||
if block.Hash() != data.BlockHash {
|
if block.Hash() != data.BlockHash {
|
||||||
return nil, fmt.Errorf("blockhash mismatch, want %x, got %x", data.BlockHash, block.Hash())
|
return nil, fmt.Errorf("blockhash mismatch, want %x, got %x", data.BlockHash, block.Hash())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -404,15 +404,15 @@ func (beacon *Beacon) FinalizeAndAssemble(chain consensus.ChainHeaderReader, hea
|
||||||
return nil, fmt.Errorf("error opening pre-state tree root: %w", err)
|
return nil, fmt.Errorf("error opening pre-state tree root: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
vtrpre, okpre := preTrie.(*trie.VerkleTrie)
|
vktPreTrie, okpre := preTrie.(*trie.VerkleTrie)
|
||||||
vtrpost, okpost := state.GetTrie().(*trie.VerkleTrie)
|
vktPostTrie, okpost := state.GetTrie().(*trie.VerkleTrie)
|
||||||
if okpre && okpost {
|
if okpre && okpost {
|
||||||
if len(keys) > 0 {
|
if len(keys) > 0 {
|
||||||
p, k, err := vtrpre.Proof(vtrpost, keys, vtrpre.FlatdbNodeResolver)
|
verkleProof, stateDiff, err := vktPreTrie.Proof(vktPostTrie, keys, vktPreTrie.FlatdbNodeResolver)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error generating verkle proof for block %d: %w", header.Number, err)
|
return nil, fmt.Errorf("error generating verkle proof for block %d: %w", header.Number, err)
|
||||||
}
|
}
|
||||||
block.SetVerkleProof(p, k)
|
return block.WithWitness(&types.ExecutionWitness{StateDiff: stateDiff, VerkleProof: verkleProof}), nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -180,7 +180,6 @@ type Body struct {
|
||||||
Transactions []*Transaction
|
Transactions []*Transaction
|
||||||
Uncles []*Header
|
Uncles []*Header
|
||||||
Withdrawals []*Withdrawal `rlp:"optional"`
|
Withdrawals []*Withdrawal `rlp:"optional"`
|
||||||
Witness *ExecutionWitness `rlp:"-"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Block represents an Ethereum block.
|
// Block represents an Ethereum block.
|
||||||
|
|
@ -341,7 +340,7 @@ func (b *Block) EncodeRLP(w io.Writer) error {
|
||||||
// Body returns the non-header content of the block.
|
// Body returns the non-header content of the block.
|
||||||
// Note the returned data is not an independent copy.
|
// Note the returned data is not an independent copy.
|
||||||
func (b *Block) Body() *Body {
|
func (b *Block) Body() *Body {
|
||||||
return &Body{b.transactions, b.uncles, b.withdrawals, b.witness}
|
return &Body{b.transactions, b.uncles, b.withdrawals}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Accessors for body data. These do not return a copy because the content
|
// Accessors for body data. These do not return a copy because the content
|
||||||
|
|
@ -473,7 +472,6 @@ func (b *Block) WithBody(body Body) *Block {
|
||||||
transactions: slices.Clone(body.Transactions),
|
transactions: slices.Clone(body.Transactions),
|
||||||
uncles: make([]*Header, len(body.Uncles)),
|
uncles: make([]*Header, len(body.Uncles)),
|
||||||
withdrawals: slices.Clone(body.Withdrawals),
|
withdrawals: slices.Clone(body.Withdrawals),
|
||||||
witness: body.Witness,
|
|
||||||
}
|
}
|
||||||
for i := range body.Uncles {
|
for i := range body.Uncles {
|
||||||
block.uncles[i] = CopyHeader(body.Uncles[i])
|
block.uncles[i] = CopyHeader(body.Uncles[i])
|
||||||
|
|
@ -481,6 +479,21 @@ func (b *Block) WithBody(body Body) *Block {
|
||||||
return block
|
return block
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (b *Block) WithWitness(witness *ExecutionWitness) *Block {
|
||||||
|
|
||||||
|
block := &Block{
|
||||||
|
header: b.header,
|
||||||
|
transactions: slices.Clone(b.transactions),
|
||||||
|
uncles: make([]*Header, len(b.uncles)),
|
||||||
|
withdrawals: slices.Clone(b.withdrawals),
|
||||||
|
witness: witness,
|
||||||
|
}
|
||||||
|
for i := range b.uncles {
|
||||||
|
block.uncles[i] = CopyHeader(b.uncles[i])
|
||||||
|
}
|
||||||
|
return block
|
||||||
|
}
|
||||||
|
|
||||||
// Hash returns the keccak256 hash of b's header.
|
// Hash returns the keccak256 hash of b's header.
|
||||||
// The hash is computed on the first call and cached thereafter.
|
// The hash is computed on the first call and cached thereafter.
|
||||||
func (b *Block) Hash() common.Hash {
|
func (b *Block) Hash() common.Hash {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue