mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-17 01: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
|
||||
// rewards given.
|
||||
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()
|
||||
if headerNumber%c.config.Sprint == 0 {
|
||||
cx := chainContext{Chain: chain, Bor: c}
|
||||
|
|
@ -666,7 +668,7 @@ func (c *Bor) Finalize(chain consensus.ChainReader, header *types.Header, state
|
|||
|
||||
if !c.WithoutHeimdall {
|
||||
// commit statees
|
||||
_, err := c.CommitStates(state, header, cx)
|
||||
stateSyncData, err = c.CommitStates(state, header, cx)
|
||||
if err != nil {
|
||||
log.Error("Error while committing states", "error", err)
|
||||
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
|
||||
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
|
||||
header.UncleHash = types.CalcUncleHash(nil)
|
||||
header.SetStateSync(stateSyncData)
|
||||
|
||||
}
|
||||
|
||||
// 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
|
||||
header.Root = state.IntermediateRoot(chain.Config().IsEIP158(header.Number))
|
||||
header.UncleHash = types.CalcUncleHash(nil)
|
||||
header.SetStateSync(stateSyncData)
|
||||
|
||||
// Assemble block
|
||||
block := types.NewBlock(header, txs, nil, receipts)
|
||||
|
||||
block.SetStateSync(stateSyncData)
|
||||
// return the final block for sealing
|
||||
return block, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ type Header struct {
|
|||
Extra []byte `json:"extraData" gencodec:"required"`
|
||||
MixDigest common.Hash `json:"mixHash"`
|
||||
Nonce BlockNonce `json:"nonce"`
|
||||
stateSyncData []*StateData
|
||||
}
|
||||
|
||||
// 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)
|
||||
}
|
||||
|
||||
// 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
|
||||
// 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
|
||||
|
|
@ -159,7 +165,6 @@ type Block struct {
|
|||
header *Header
|
||||
uncles []*Header
|
||||
transactions Transactions
|
||||
stateSyncData []*StateData
|
||||
// caches
|
||||
hash atomic.Value
|
||||
size atomic.Value
|
||||
|
|
@ -266,11 +271,6 @@ func CopyHeader(h *Header) *Header {
|
|||
return &cpy
|
||||
}
|
||||
|
||||
// SetStateSync set sync data in block
|
||||
func (b *Block) SetStateSync(stateData []*StateData) {
|
||||
b.stateSyncData = stateData
|
||||
}
|
||||
|
||||
// DecodeRLP decodes the Ethereum
|
||||
func (b *Block) DecodeRLP(s *rlp.Stream) error {
|
||||
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) Difficulty() *big.Int { return new(big.Int).Set(b.header.Difficulty) }
|
||||
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) MixDigest() common.Hash { return b.header.MixDigest }
|
||||
|
|
@ -381,7 +381,6 @@ func (b *Block) WithSeal(header *Header) *Block {
|
|||
header: &cpy,
|
||||
transactions: b.transactions,
|
||||
uncles: b.uncles,
|
||||
stateSyncData: b.stateSyncData,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue