Fix: resolve comments

This commit is contained in:
ptsayli@gmail.com 2020-08-12 15:27:01 +05:30
parent ae38eea1f3
commit 722e246d07
4 changed files with 21 additions and 13 deletions

View file

@ -679,13 +679,14 @@ 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)
r := chain.(*core.BlockChain)
r.SetStateSync(stateSyncData)
bc := chain.(*core.BlockChain)
bc.SetStateSync(stateSyncData)
}
// FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set,
// nor block rewards given, and returns the final block.
func (c *Bor) FinalizeAndAssemble(chain consensus.ChainReader, header *types.Header, state *state.StateDB, txs []*types.Transaction, uncles []*types.Header, receipts []*types.Receipt) (*types.Block, error) {
stateSyncData := []*types.StateData{}
headerNumber := header.Number.Uint64()
if headerNumber%c.config.Sprint == 0 {
cx := chainContext{Chain: chain, Bor: c}
@ -699,7 +700,7 @@ func (c *Bor) FinalizeAndAssemble(chain consensus.ChainReader, header *types.Hea
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 nil, err
@ -713,7 +714,8 @@ func (c *Bor) FinalizeAndAssemble(chain consensus.ChainReader, header *types.Hea
// Assemble block
block := types.NewBlock(header, txs, nil, receipts)
bc := chain.(*core.BlockChain)
bc.SetStateSync(stateSyncData)
// return the final block for sealing
return block, nil
}

View file

@ -335,7 +335,7 @@ func NewBlockChain(db ethdb.Database, cacheConfig *CacheConfig, chainConfig *par
return bc, nil
}
// SetStateSync set sync data in block
// SetStateSync set sync data in state_data
func (bc *BlockChain) SetStateSync(stateData []*types.StateData) {
bc.stateSyncData = stateData
}
@ -1548,6 +1548,9 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
// event here.
if emitHeadEvent {
bc.chainHeadFeed.Send(ChainHeadEvent{Block: block})
for _, data := range bc.stateSyncData {
bc.stateSyncFeed.Send(StateSyncEvent{StateData: data})
}
}
} else {
bc.chainSideFeed.Send(ChainSideEvent{Block: block})

View file

@ -66,14 +66,6 @@ func (n *BlockNonce) UnmarshalText(input []byte) error {
return hexutil.UnmarshalFixedText("BlockNonce", input, n[:])
}
// StateData represents state received from Ethereum Blockchain
type StateData struct {
Did uint64
Contract common.Address
Data string
TxHash common.Hash
}
//go:generate gencodec -type Header -field-override headerMarshaling -out gen_header_json.go
// Header represents a block header in the Ethereum blockchain.

11
core/types/state_data.go Normal file
View file

@ -0,0 +1,11 @@
package types
import "github.com/maticnetwork/bor/common"
// StateData represents state received from Ethereum Blockchain
type StateData struct {
Did uint64
Contract common.Address
Data string
TxHash common.Hash
}