Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 13 additions & 8 deletions consensus/bor/bor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1062,7 +1062,6 @@ func (c *Bor) Finalize(chain consensus.ChainHeaderReader, header *types.Header,
return nil
}
}

// Get the underlying state for updating consensus time
state := wrappedState.Inner()
state.BorConsensusTime = time.Since(start)
Expand All @@ -1077,7 +1076,10 @@ func (c *Bor) Finalize(chain consensus.ChainHeaderReader, header *types.Header,
}

if len(stateSyncData) > 0 && c.config != nil && c.config.IsStateSync(big.NewInt(int64(headerNumber))) {
receipts = insertStateSyncTransactionAndCalculateReceipt(stateSyncData, header, body, wrappedState, receipts)
stateSyncTx := types.NewTx(&types.StateSyncTx{
StateSyncData: stateSyncData,
})
receipts = insertStateSyncTransactionAndCalculateReceipt(stateSyncTx, header, body, wrappedState, receipts)
} else {
// set state sync
hc := chain.(*core.HeaderChain)
Expand All @@ -1086,12 +1088,11 @@ func (c *Bor) Finalize(chain consensus.ChainHeaderReader, header *types.Header,
return receipts
}

func insertStateSyncTransactionAndCalculateReceipt(stateSyncData []*types.StateSyncData, header *types.Header, body *types.Body, state vm.StateDB, receipts []*types.Receipt) []*types.Receipt {
stateSyncTx := types.NewTx(&types.StateSyncTx{
StateSyncData: stateSyncData,
})
body.Transactions = append(body.Transactions, stateSyncTx)
func insertStateSyncTransactionAndCalculateReceipt(stateSyncTx *types.Transaction, header *types.Header, body *types.Body, state vm.StateDB, receipts []*types.Receipt) []*types.Receipt {
allLogs := state.Logs()
sort.SliceStable(allLogs, func(i, j int) bool {
return allLogs[i].Index < allLogs[j].Index
})
logsFromReceiptCount := countLogsFromReceipts(receipts)
stateSyncLogs := allLogs[logsFromReceiptCount:]

Expand Down Expand Up @@ -1212,7 +1213,11 @@ func (c *Bor) FinalizeAndAssemble(chain consensus.ChainHeaderReader, header *typ
header.UncleHash = types.CalcUncleHash(nil)

if len(stateSyncData) > 0 && c.config != nil && c.config.IsStateSync(big.NewInt(int64(headerNumber))) {
receipts = insertStateSyncTransactionAndCalculateReceipt(stateSyncData, header, body, state, receipts)
stateSyncTx := types.NewTx(&types.StateSyncTx{
StateSyncData: stateSyncData,
})
body.Transactions = append(body.Transactions, stateSyncTx)
receipts = insertStateSyncTransactionAndCalculateReceipt(stateSyncTx, header, body, state, receipts)
} else {
// set state sync
bc := chain.(core.BorStateSyncer)
Expand Down
Loading