mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-07 14:46:44 +00:00
[NOD-842] Use flushToDB with the same transaction as everything else in saveChangesFromBlock and never ignore flushToDB errors (#662)
This commit is contained in:
parent
1cf443a63b
commit
624249c0f3
@ -486,25 +486,14 @@ func (dag *BlockDAG) addBlock(node *blockNode,
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
if errors.As(err, &RuleError{}) {
|
if errors.As(err, &RuleError{}) {
|
||||||
dag.index.SetStatusFlags(node, statusValidateFailed)
|
dag.index.SetStatusFlags(node, statusValidateFailed)
|
||||||
} else {
|
err := dag.index.flushToDB()
|
||||||
return nil, err
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
dag.blockCount++
|
|
||||||
}
|
|
||||||
|
|
||||||
// Intentionally ignore errors writing updated node status to DB. If
|
|
||||||
// it fails to write, it's not the end of the world. If the block is
|
|
||||||
// invalid, the worst that can happen is we revalidate the block
|
|
||||||
// after a restart.
|
|
||||||
if writeErr := dag.index.flushToDB(); writeErr != nil {
|
|
||||||
log.Warnf("Error flushing block index changes to disk: %s",
|
|
||||||
writeErr)
|
|
||||||
}
|
|
||||||
// If dag.connectBlock returned a rule error, return it here after updating DB
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
dag.blockCount++
|
||||||
return chainUpdates, nil
|
return chainUpdates, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -608,15 +597,14 @@ func (dag *BlockDAG) saveChangesFromBlock(block *util.Block, virtualUTXODiff *UT
|
|||||||
txsAcceptanceData MultiBlockTxsAcceptanceData, virtualTxsAcceptanceData MultiBlockTxsAcceptanceData,
|
txsAcceptanceData MultiBlockTxsAcceptanceData, virtualTxsAcceptanceData MultiBlockTxsAcceptanceData,
|
||||||
feeData compactFeeData) error {
|
feeData compactFeeData) error {
|
||||||
|
|
||||||
// Write any block status changes to DB before updating the DAG state.
|
|
||||||
err := dag.index.flushToDB()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Atomically insert info into the database.
|
// Atomically insert info into the database.
|
||||||
err = dag.db.Update(func(dbTx database.Tx) error {
|
err := dag.db.Update(func(dbTx database.Tx) error {
|
||||||
err := dag.utxoDiffStore.flushToDB(dbTx)
|
err := dag.index.flushToDBWithTx(dbTx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = dag.utxoDiffStore.flushToDB(dbTx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user