good morning!!!!

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

fix: handle multiple state sync events

parent dfe6a86d
No related branches found
No related tags found
No related merge requests found
...@@ -682,7 +682,7 @@ func (c *Bor) Finalize(chain consensus.ChainReader, header *types.Header, state ...@@ -682,7 +682,7 @@ func (c *Bor) Finalize(chain consensus.ChainReader, header *types.Header, state
// FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set, // FinalizeAndAssemble implements consensus.Engine, ensuring no uncles are set,
// nor block rewards given, and returns the final block. // 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) { 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{} stateSyncData := []*types.StateData{}
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}
...@@ -1093,8 +1093,8 @@ func (c *Bor) CommitStates( ...@@ -1093,8 +1093,8 @@ func (c *Bor) CommitStates(
state *state.StateDB, state *state.StateDB,
header *types.Header, header *types.Header,
chain chainContext, chain chainContext,
) (*types.StateData, error) { ) ([]*types.StateData, error) {
var stateData types.StateData stateSyncs := make([]*types.StateData, 0)
number := header.Number.Uint64() number := header.Number.Uint64()
_lastStateID, err := c.GenesisContractsClient.LastStateId(number - 1) _lastStateID, err := c.GenesisContractsClient.LastStateId(number - 1)
if err != nil { if err != nil {
...@@ -1119,19 +1119,20 @@ func (c *Bor) CommitStates( ...@@ -1119,19 +1119,20 @@ func (c *Bor) CommitStates(
break break
} }
stateData = types.StateData{ stateData := types.StateData{
Did: eventRecord.ID, Did: eventRecord.ID,
Contract: eventRecord.Contract, Contract: eventRecord.Contract,
Data: hex.EncodeToString(eventRecord.Data), Data: hex.EncodeToString(eventRecord.Data),
TxHash: eventRecord.TxHash, TxHash: eventRecord.TxHash,
} }
stateSyncs = append(stateSyncs, &stateData)
if err := c.GenesisContractsClient.CommitState(eventRecord, state, header, chain); err != nil { if err := c.GenesisContractsClient.CommitState(eventRecord, state, header, chain); err != nil {
return nil, err return nil, err
} }
lastStateID++ lastStateID++
} }
return &stateData, nil return stateSyncs, nil
} }
func validateEventRecord(eventRecord *EventRecordWithTime, number uint64, to time.Time, lastStateID uint64, chainID string) error { func validateEventRecord(eventRecord *EventRecordWithTime, number uint64, to time.Time, lastStateID uint64, chainID string) error {
......
...@@ -1544,8 +1544,8 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types. ...@@ -1544,8 +1544,8 @@ func (bc *BlockChain) writeBlockWithState(block *types.Block, receipts []*types.
} }
syncData := block.StateSyncData() syncData := block.StateSyncData()
// TODO: add emitStateSyncEvent flag check // TODO: add emitStateSyncEvent flag check
if syncData.Did != 0 { for _, data := range syncData {
bc.stateSyncFeed.Send(StateSyncEvent{StateData: syncData}) bc.stateSyncFeed.Send(StateSyncEvent{StateData: data})
} }
} else { } else {
bc.chainSideFeed.Send(ChainSideEvent{Block: block}) bc.chainSideFeed.Send(ChainSideEvent{Block: block})
......
...@@ -159,7 +159,7 @@ type Block struct { ...@@ -159,7 +159,7 @@ type Block struct {
header *Header header *Header
uncles []*Header uncles []*Header
transactions Transactions transactions Transactions
stateSyncData *StateData stateSyncData []*StateData
// caches // caches
hash atomic.Value hash atomic.Value
size atomic.Value size atomic.Value
...@@ -267,7 +267,7 @@ func CopyHeader(h *Header) *Header { ...@@ -267,7 +267,7 @@ func CopyHeader(h *Header) *Header {
} }
// SetStateSync set sync data in block // SetStateSync set sync data in block
func (b *Block) SetStateSync(stateData *StateData) { func (b *Block) SetStateSync(stateData []*StateData) {
b.stateSyncData = stateData b.stateSyncData = stateData
} }
...@@ -316,12 +316,12 @@ func (b *Block) Transaction(hash common.Hash) *Transaction { ...@@ -316,12 +316,12 @@ func (b *Block) Transaction(hash common.Hash) *Transaction {
return nil return nil
} }
func (b *Block) Number() *big.Int { return new(big.Int).Set(b.header.Number) } func (b *Block) Number() *big.Int { return new(big.Int).Set(b.header.Number) }
func (b *Block) GasLimit() uint64 { return b.header.GasLimit } 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.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 }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment