mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-12 23:13:45 +00:00
chg: move state sync event from block to header
This commit is contained in:
parent
1fd375eabf
commit
eec8916845
2 changed files with 35 additions and 31 deletions
|
|
@ -655,6 +655,8 @@ func (c *Bor) Prepare(chain consensus.ChainReader, header *types.Header) error {
|
||||||
// Finalize implements consensus.Engine, ensuring no uncles are set, nor block
|
// Finalize implements consensus.Engine, ensuring no uncles are set, nor block
|
||||||
// rewards given.
|
// rewards given.
|
||||||
func (c *Bor) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header) {
|
func (c *Bor) Finalize(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header) {
|
||||||
|
stateSyncData := []*types.StateData{}
|
||||||
|
var err error
|
||||||
headerNumber := header.Number.Uint64()
|
headerNumber := header.Number.Uint64()
|
||||||
if headerNumber%c.config.Sprint == 0 {
|
if headerNumber%c.config.Sprint == 0 {
|
||||||
cx := chainContext{Chain: chain, Bor: c}
|
cx := chainContext{Chain: chain, Bor: c}
|
||||||
|
|
@ -666,7 +668,7 @@ func (c *Bor) Finalize(chain consensus.ChainReader, header *types.Header, state
|
||||||
|
|
||||||
if !c.WithoutHeimdall {
|
if !c.WithoutHeimdall {
|
||||||
// commit statees
|
// commit statees
|
||||||
_, err := c.CommitStates(state, header, cx)
|
stateSyncData, err = c.CommitStates(state, header, cx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error while committing states", "error", err)
|
log.Error("Error while committing states", "error", err)
|
||||||
return
|
return
|
||||||
|
|
@ -677,6 +679,8 @@ func (c *Bor) Finalize(chain consensus.ChainReader, header *types.Header, state
|
||||||
// No block rewards in PoA, so the state remains as is and uncles are dropped
|
// No block rewards in PoA, so the state remains as is and uncles are dropped
|
||||||
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
|
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
|
||||||
header.UncleHash = types.CalcUncleHash(nil)
|
header.UncleHash = types.CalcUncleHash(nil)
|
||||||
|
header.SetStateSync(stateSyncData)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set,
|
// FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set,
|
||||||
|
|
@ -707,10 +711,11 @@ func (c *Bor) FinalizeAndAssemble(chain consensus.ChainReader, header *types.Hea
|
||||||
// No block rewards in PoA, so the state remains as is and uncles are dropped
|
// No block rewards in PoA, so the state remains as is and uncles are dropped
|
||||||
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
|
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
|
||||||
header.UncleHash = types.CalcUncleHash(nil)
|
header.UncleHash = types.CalcUncleHash(nil)
|
||||||
|
header.SetStateSync(stateSyncData)
|
||||||
|
|
||||||
// Assemble block
|
// Assemble block
|
||||||
block := types.NewBlock(header, txs, nil, receipts)
|
block := types.NewBlock(header, txs, nil, receipts)
|
||||||
|
|
||||||
block.SetStateSync(stateSyncData)
|
|
||||||
// return the final block for sealing
|
// return the final block for sealing
|
||||||
return block, nil
|
return block, nil
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -70,21 +70,22 @@ func (n *BlockNonce) UnmarshalText(input []byte) error {
|
||||||
|
|
||||||
// Header represents a block header in the Ethereum blockchain.
|
// Header represents a block header in the Ethereum blockchain.
|
||||||
type Header struct {
|
type Header struct {
|
||||||
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
|
ParentHash common.Hash `json:"parentHash" gencodec:"required"`
|
||||||
UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"`
|
UncleHash common.Hash `json:"sha3Uncles" gencodec:"required"`
|
||||||
Coinbase common.Address `json:"miner" gencodec:"required"`
|
Coinbase common.Address `json:"miner" gencodec:"required"`
|
||||||
Root common.Hash `json:"stateRoot" gencodec:"required"`
|
Root common.Hash `json:"stateRoot" gencodec:"required"`
|
||||||
TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
|
TxHash common.Hash `json:"transactionsRoot" gencodec:"required"`
|
||||||
ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
|
ReceiptHash common.Hash `json:"receiptsRoot" gencodec:"required"`
|
||||||
Bloom Bloom `json:"logsBloom" gencodec:"required"`
|
Bloom Bloom `json:"logsBloom" gencodec:"required"`
|
||||||
Difficulty *big.Int `json:"difficulty" gencodec:"required"`
|
Difficulty *big.Int `json:"difficulty" gencodec:"required"`
|
||||||
Number *big.Int `json:"number" gencodec:"required"`
|
Number *big.Int `json:"number" gencodec:"required"`
|
||||||
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
|
GasLimit uint64 `json:"gasLimit" gencodec:"required"`
|
||||||
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
|
GasUsed uint64 `json:"gasUsed" gencodec:"required"`
|
||||||
Time uint64 `json:"timestamp" gencodec:"required"`
|
Time uint64 `json:"timestamp" gencodec:"required"`
|
||||||
Extra []byte `json:"extraData" gencodec:"required"`
|
Extra []byte `json:"extraData" gencodec:"required"`
|
||||||
MixDigest common.Hash `json:"mixHash"`
|
MixDigest common.Hash `json:"mixHash"`
|
||||||
Nonce BlockNonce `json:"nonce"`
|
Nonce BlockNonce `json:"nonce"`
|
||||||
|
stateSyncData []*StateData
|
||||||
}
|
}
|
||||||
|
|
||||||
// field type overrides for gencodec
|
// field type overrides for gencodec
|
||||||
|
|
@ -112,6 +113,11 @@ func (h *Header) Size() common.StorageSize {
|
||||||
return headerSize + common.StorageSize(len(h.Extra)+(h.Difficulty.BitLen()+h.Number.BitLen())/8)
|
return headerSize + common.StorageSize(len(h.Extra)+(h.Difficulty.BitLen()+h.Number.BitLen())/8)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SetStateSync set sync data in block
|
||||||
|
func (b *Header) SetStateSync(stateData []*StateData) {
|
||||||
|
b.stateSyncData = stateData
|
||||||
|
}
|
||||||
|
|
||||||
// SanityCheck checks a few basic things -- these checks are way beyond what
|
// SanityCheck checks a few basic things -- these checks are way beyond what
|
||||||
// any 'sane' production values should hold, and can mainly be used to prevent
|
// any 'sane' production values should hold, and can mainly be used to prevent
|
||||||
// that the unbounded fields are stuffed with junk data to add processing
|
// that the unbounded fields are stuffed with junk data to add processing
|
||||||
|
|
@ -156,10 +162,9 @@ type Body struct {
|
||||||
|
|
||||||
// Block represents an entire block in the Ethereum blockchain.
|
// Block represents an entire block in the Ethereum blockchain.
|
||||||
type Block struct {
|
type Block struct {
|
||||||
header *Header
|
header *Header
|
||||||
uncles []*Header
|
uncles []*Header
|
||||||
transactions Transactions
|
transactions Transactions
|
||||||
stateSyncData []*StateData
|
|
||||||
// caches
|
// caches
|
||||||
hash atomic.Value
|
hash atomic.Value
|
||||||
size atomic.Value
|
size atomic.Value
|
||||||
|
|
@ -266,11 +271,6 @@ func CopyHeader(h *Header) *Header {
|
||||||
return &cpy
|
return &cpy
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetStateSync set sync data in block
|
|
||||||
func (b *Block) SetStateSync(stateData []*StateData) {
|
|
||||||
b.stateSyncData = stateData
|
|
||||||
}
|
|
||||||
|
|
||||||
// DecodeRLP decodes the Ethereum
|
// DecodeRLP decodes the Ethereum
|
||||||
func (b *Block) DecodeRLP(s *rlp.Stream) error {
|
func (b *Block) DecodeRLP(s *rlp.Stream) error {
|
||||||
var eb extblock
|
var eb extblock
|
||||||
|
|
@ -321,7 +321,7 @@ func (b *Block) GasLimit() uint64 { return b.header.GasLimit }
|
||||||
func (b *Block) GasUsed() uint64 { return b.header.GasUsed }
|
func (b *Block) GasUsed() uint64 { return b.header.GasUsed }
|
||||||
func (b *Block) Difficulty() *big.Int { return new(big.Int).Set(b.header.Difficulty) }
|
func (b *Block) Difficulty() *big.Int { return new(big.Int).Set(b.header.Difficulty) }
|
||||||
func (b *Block) Time() uint64 { return b.header.Time }
|
func (b *Block) Time() uint64 { return b.header.Time }
|
||||||
func (b *Block) StateSyncData() []*StateData { return b.stateSyncData }
|
func (b *Block) StateSyncData() []*StateData { return b.header.stateSyncData }
|
||||||
|
|
||||||
func (b *Block) NumberU64() uint64 { return b.header.Number.Uint64() }
|
func (b *Block) NumberU64() uint64 { return b.header.Number.Uint64() }
|
||||||
func (b *Block) MixDigest() common.Hash { return b.header.MixDigest }
|
func (b *Block) MixDigest() common.Hash { return b.header.MixDigest }
|
||||||
|
|
@ -378,10 +378,9 @@ func (b *Block) WithSeal(header *Header) *Block {
|
||||||
cpy := *header
|
cpy := *header
|
||||||
|
|
||||||
return &Block{
|
return &Block{
|
||||||
header: &cpy,
|
header: &cpy,
|
||||||
transactions: b.transactions,
|
transactions: b.transactions,
|
||||||
uncles: b.uncles,
|
uncles: b.uncles,
|
||||||
stateSyncData: b.stateSyncData,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue