From 722e246d07c78e5b14197f5f3ffd6f3bb6f54295 Mon Sep 17 00:00:00 2001 From: "ptsayli@gmail.com" <ptsayli@gmail.com> Date: Wed, 12 Aug 2020 15:27:01 +0530 Subject: [PATCH] Fix: resolve comments --- consensus/bor/bor.go | 10 ++++++---- core/blockchain.go | 5 ++++- core/types/block.go | 8 -------- core/types/state_data.go | 11 +++++++++++ 4 files changed, 21 insertions(+), 13 deletions(-) create mode 100644 core/types/state_data.go diff --git a/consensus/bor/bor.go b/consensus/bor/bor.go index f112eefdd..925406284 100644 --- a/consensus/bor/bor.go +++ b/consensus/bor/bor.go @@ -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 } diff --git a/core/blockchain.go b/core/blockchain.go index 1a0cfb6c2..6ecab669b 100644 --- a/core/blockchain.go +++ b/core/blockchain.go @@ -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}) diff --git a/core/types/block.go b/core/types/block.go index 6baafa225..be31b1a60 100644 --- a/core/types/block.go +++ b/core/types/block.go @@ -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. diff --git a/core/types/state_data.go b/core/types/state_data.go new file mode 100644 index 000000000..bd952627a --- /dev/null +++ b/core/types/state_data.go @@ -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 +} -- GitLab