good morning!!!!

Skip to content
Snippets Groups Projects
Commit eec89168 authored by ptsayli@gmail.com's avatar ptsayli@gmail.com
Browse files

chg: move state sync event from block to header

parent 1fd375ea
Branches
Tags
No related merge requests found
...@@ -655,6 +655,8 @@ func (c *Bor) Prepare(chain consensus.ChainReader, header *types.Header) error { ...@@ -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 ...@@ -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 ...@@ -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 ...@@ -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
} }
......
...@@ -85,6 +85,7 @@ type Header struct { ...@@ -85,6 +85,7 @@ type Header struct {
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 { ...@@ -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
...@@ -159,7 +165,6 @@ type Block struct { ...@@ -159,7 +165,6 @@ 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 { ...@@ -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 } ...@@ -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 }
...@@ -381,7 +381,6 @@ func (b *Block) WithSeal(header *Header) *Block { ...@@ -381,7 +381,6 @@ func (b *Block) WithSeal(header *Header) *Block {
header: &cpy, header: &cpy,
transactions: b.transactions, transactions: b.transactions,
uncles: b.uncles, uncles: b.uncles,
stateSyncData: b.stateSyncData,
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment