From 38ebecb2fa410ce944ea8b00691b2f3fc82acd3d Mon Sep 17 00:00:00 2001
From: "ptsayli@gmail.com" <ptsayli@gmail.com>
Date: Tue, 11 Aug 2020 15:07:55 +0530
Subject: [PATCH] Fix: broadcast deposit event from non-validator node

---
 consensus/bor/bor.go    |  1 -
 core/blockchain.go      |  9 +++++----
 core/state_processor.go |  2 +-
 core/types/block.go     | 24 ++++++++++++++++++------
 4 files changed, 24 insertions(+), 12 deletions(-)

diff --git a/consensus/bor/bor.go b/consensus/bor/bor.go
index aae897723..2a81a2ad3 100644
--- a/consensus/bor/bor.go
+++ b/consensus/bor/bor.go
@@ -680,7 +680,6 @@ func (c *Bor) Finalize(chain consensus.ChainReader, header *types.Header, state
 	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,
diff --git a/core/blockchain.go b/core/blockchain.go
index 5a70de3fe..952dea7dc 100644
--- a/core/blockchain.go
+++ b/core/blockchain.go
@@ -1542,10 +1542,6 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
 		if emitHeadEvent {
 			bc.chainHeadFeed.Send(ChainHeadEvent{Block: block})
 		}
-		syncData := block.StateSyncData()
-		for _, data := range syncData {
-			bc.stateSyncFeed.Send(StateSyncEvent{StateData: data})
-		}
 	} else {
 		bc.chainSideFeed.Send(ChainSideEvent{Block: block})
 	}
@@ -1797,6 +1793,11 @@ func (bc *BlockChain) insertChain(chain types.Blocks, verifySeals bool) (int, er
 		// Process block using the parent state as reference point
 		substart := time.Now()
 		receipts, logs, usedGas, err := bc.processor.Process(block, statedb, bc.vmConfig)
+		syncData := block.StateSyncData()
+
+		for _, data := range syncData {
+			bc.stateSyncFeed.Send(StateSyncEvent{StateData: data})
+		}
 		if err != nil {
 			bc.reportBlock(block, receipts, err)
 			atomic.StoreUint32(&followupInterrupt, 1)
diff --git a/core/state_processor.go b/core/state_processor.go
index e6a5e9d68..ec98e3ee4 100644
--- a/core/state_processor.go
+++ b/core/state_processor.go
@@ -77,7 +77,7 @@ func (p *StateProcessor) Process(block *types.Block, statedb *state.StateDB, cfg
 	}
 	// Finalize the block, applying any consensus engine specific extras (e.g. block rewards)
 	p.engine.Finalize(p.bc, header, statedb, block.Transactions(), block.Uncles())
-
+	block.SetStateSync(header.StateData())
 	return receipts, allLogs, *usedGas, nil
 }
 
diff --git a/core/types/block.go b/core/types/block.go
index 3dd7366ae..c2ebaedd9 100644
--- a/core/types/block.go
+++ b/core/types/block.go
@@ -114,8 +114,18 @@ func (h *Header) Size() common.StorageSize {
 }
 
 // SetStateSync set sync data in block
-func (b *Header) SetStateSync(stateData []*StateData) {
-	b.stateSyncData = stateData
+func (h *Header) SetStateSync(stateData []*StateData) {
+	h.stateSyncData = stateData
+}
+
+// SetStateSync set sync data in block
+func (h *Block) SetStateSync(stateData []*StateData) {
+	h.stateSyncData = stateData
+}
+
+// StateSyncData set sync data in block
+func (h *Header) StateData() []*StateData {
+	return h.stateSyncData
 }
 
 // SanityCheck checks a few basic things -- these checks are way beyond what
@@ -162,9 +172,11 @@ type Body struct {
 
 // Block represents an entire block in the Ethereum blockchain.
 type Block struct {
-	header       *Header
-	uncles       []*Header
-	transactions Transactions
+	header        *Header
+	uncles        []*Header
+	transactions  Transactions
+	stateSyncData []*StateData
+
 	// caches
 	hash atomic.Value
 	size atomic.Value
@@ -321,7 +333,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.header.stateSyncData }
+func (b *Block) StateSyncData() []*StateData { return b.stateSyncData }
 
 func (b *Block) NumberU64() uint64        { return b.header.Number.Uint64() }
 func (b *Block) MixDigest() common.Hash   { return b.header.MixDigest }
-- 
GitLab