mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-26 14:46:42 +00:00
allow overwriting block hash
This commit is contained in:
parent
7e26589b67
commit
f7ed2af11e
1 changed files with 20 additions and 15 deletions
|
|
@ -191,10 +191,10 @@ type Body struct {
|
||||||
// - We do not copy body data on access because it does not affect the caches, and also
|
// - We do not copy body data on access because it does not affect the caches, and also
|
||||||
// because it would be too expensive.
|
// because it would be too expensive.
|
||||||
type Block struct {
|
type Block struct {
|
||||||
Header_ *Header
|
Header_ *Header
|
||||||
uncles []*Header
|
uncles []*Header
|
||||||
Txs Transactions
|
Txs Transactions
|
||||||
withdrawals Withdrawals
|
withdrawals Withdrawals
|
||||||
|
|
||||||
// caches
|
// caches
|
||||||
hash atomic.Value
|
hash atomic.Value
|
||||||
|
|
@ -446,20 +446,20 @@ func NewBlockWithHeader(header *Header) *Block {
|
||||||
// the sealed one.
|
// the sealed one.
|
||||||
func (b *Block) WithSeal(header *Header) *Block {
|
func (b *Block) WithSeal(header *Header) *Block {
|
||||||
return &Block{
|
return &Block{
|
||||||
Header_: CopyHeader(header),
|
Header_: CopyHeader(header),
|
||||||
Txs: b.Txs,
|
Txs: b.Txs,
|
||||||
uncles: b.uncles,
|
uncles: b.uncles,
|
||||||
withdrawals: b.withdrawals,
|
withdrawals: b.withdrawals,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// WithBody returns a copy of the block with the given transaction and uncle contents.
|
// WithBody returns a copy of the block with the given transaction and uncle contents.
|
||||||
func (b *Block) WithBody(transactions []*Transaction, uncles []*Header) *Block {
|
func (b *Block) WithBody(transactions []*Transaction, uncles []*Header) *Block {
|
||||||
block := &Block{
|
block := &Block{
|
||||||
Header_: b.Header_,
|
Header_: b.Header_,
|
||||||
Txs: make([]*Transaction, len(transactions)),
|
Txs: make([]*Transaction, len(transactions)),
|
||||||
uncles: make([]*Header, len(uncles)),
|
uncles: make([]*Header, len(uncles)),
|
||||||
withdrawals: b.withdrawals,
|
withdrawals: b.withdrawals,
|
||||||
}
|
}
|
||||||
copy(block.Txs, transactions)
|
copy(block.Txs, transactions)
|
||||||
for i := range uncles {
|
for i := range uncles {
|
||||||
|
|
@ -471,9 +471,9 @@ func (b *Block) WithBody(transactions []*Transaction, uncles []*Header) *Block {
|
||||||
// WithWithdrawals returns a copy of the block containing the given withdrawals.
|
// WithWithdrawals returns a copy of the block containing the given withdrawals.
|
||||||
func (b *Block) WithWithdrawals(withdrawals []*Withdrawal) *Block {
|
func (b *Block) WithWithdrawals(withdrawals []*Withdrawal) *Block {
|
||||||
block := &Block{
|
block := &Block{
|
||||||
Header_: b.Header_,
|
Header_: b.Header_,
|
||||||
Txs: b.Txs,
|
Txs: b.Txs,
|
||||||
uncles: b.uncles,
|
uncles: b.uncles,
|
||||||
}
|
}
|
||||||
if withdrawals != nil {
|
if withdrawals != nil {
|
||||||
block.withdrawals = make([]*Withdrawal, len(withdrawals))
|
block.withdrawals = make([]*Withdrawal, len(withdrawals))
|
||||||
|
|
@ -493,6 +493,11 @@ func (b *Block) Hash() common.Hash {
|
||||||
return v
|
return v
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Used by tracer/simulation. Should never be called in actual execution.
|
||||||
|
func (b *Block) OverwriteHash(h common.Hash) {
|
||||||
|
b.hash.Store(h)
|
||||||
|
}
|
||||||
|
|
||||||
type Blocks []*Block
|
type Blocks []*Block
|
||||||
|
|
||||||
// HeaderParentHashFromRLP returns the parentHash of an RLP-encoded
|
// HeaderParentHashFromRLP returns the parentHash of an RLP-encoded
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue