mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-29 16:13:47 +00:00
fix: handle multiple state sync events
This commit is contained in:
parent
dfe6a86da5
commit
a5ba992bff
3 changed files with 16 additions and 15 deletions
|
|
@ -682,7 +682,7 @@ func (c *Bor) Finalize(chain consensus.ChainReader, header *types.Header, state
|
|||
// 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{}
|
||||
stateSyncData := []*types.StateData{}
|
||||
headerNumber := header.Number.Uint64()
|
||||
if headerNumber%c.config.Sprint == 0 {
|
||||
cx := chainContext{Chain: chain, Bor: c}
|
||||
|
|
@ -1093,8 +1093,8 @@ func (c *Bor) CommitStates(
|
|||
state *state.StateDB,
|
||||
header *types.Header,
|
||||
chain chainContext,
|
||||
) (*types.StateData, error) {
|
||||
var stateData types.StateData
|
||||
) ([]*types.StateData, error) {
|
||||
stateSyncs := make([]*types.StateData, 0)
|
||||
number := header.Number.Uint64()
|
||||
_lastStateID, err := c.GenesisContractsClient.LastStateId(number - 1)
|
||||
if err != nil {
|
||||
|
|
@ -1119,19 +1119,20 @@ func (c *Bor) CommitStates(
|
|||
break
|
||||
}
|
||||
|
||||
stateData = types.StateData{
|
||||
stateData := types.StateData{
|
||||
Did: eventRecord.ID,
|
||||
Contract: eventRecord.Contract,
|
||||
Data: hex.EncodeToString(eventRecord.Data),
|
||||
TxHash: eventRecord.TxHash,
|
||||
}
|
||||
stateSyncs = append(stateSyncs, &stateData)
|
||||
|
||||
if err := c.GenesisContractsClient.CommitState(eventRecord, state, header, chain); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
lastStateID++
|
||||
}
|
||||
return &stateData, nil
|
||||
return stateSyncs, nil
|
||||
}
|
||||
|
||||
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.
|
|||
}
|
||||
syncData := block.StateSyncData()
|
||||
// TODO: add emitStateSyncEvent flag check
|
||||
if syncData.Did != 0 {
|
||||
bc.stateSyncFeed.Send(StateSyncEvent{StateData: syncData})
|
||||
for _, data := range syncData {
|
||||
bc.stateSyncFeed.Send(StateSyncEvent{StateData: data})
|
||||
}
|
||||
} else {
|
||||
bc.chainSideFeed.Send(ChainSideEvent{Block: block})
|
||||
|
|
|
|||
|
|
@ -159,7 +159,7 @@ type Block struct {
|
|||
header *Header
|
||||
uncles []*Header
|
||||
transactions Transactions
|
||||
stateSyncData *StateData
|
||||
stateSyncData []*StateData
|
||||
// caches
|
||||
hash atomic.Value
|
||||
size atomic.Value
|
||||
|
|
@ -267,7 +267,7 @@ func CopyHeader(h *Header) *Header {
|
|||
}
|
||||
|
||||
// SetStateSync set sync data in block
|
||||
func (b *Block) SetStateSync(stateData *StateData) {
|
||||
func (b *Block) SetStateSync(stateData []*StateData) {
|
||||
b.stateSyncData = stateData
|
||||
}
|
||||
|
||||
|
|
@ -316,12 +316,12 @@ func (b *Block) Transaction(hash common.Hash) *Transaction {
|
|||
return nil
|
||||
}
|
||||
|
||||
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) 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.stateSyncData }
|
||||
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) 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.stateSyncData }
|
||||
|
||||
func (b *Block) NumberU64() uint64 { return b.header.Number.Uint64() }
|
||||
func (b *Block) MixDigest() common.Hash { return b.header.MixDigest }
|
||||
|
|
|
|||
Loading…
Reference in a new issue