Add WriteStateSnapshot #15

Merged
roysc merged 23 commits from with-iterator-tracker into main 2023-09-28 03:35:47 +00:00
3 changed files with 4 additions and 1 deletions
Showing only changes of commit 5b51346a83 - Show all commits

View File

@ -85,7 +85,6 @@ func (tx *BatchTx) BlockNumber() string {
} }
func (tx *BatchTx) RollbackOnFailure(err error) { func (tx *BatchTx) RollbackOnFailure(err error) {
if p := recover(); p != nil { if p := recover(); p != nil {
defer tx.close() defer tx.close()
log.Info("panic detected before tx submission, rolling back the tx", "panic", p) log.Info("panic detected before tx submission, rolling back the tx", "panic", p)

View File

@ -54,8 +54,11 @@ type StateDiffIndexer interface {
// Batch required for indexing data atomically // Batch required for indexing data atomically
type Batch interface { type Batch interface {
// Submit commits the batch transaction
Submit() error Submit() error
// BlockNumber is the block number of the header this batch contains
BlockNumber() string BlockNumber() string
// RollbackOnFailure rolls back the batch transaction if the error is not nil
RollbackOnFailure(error) RollbackOnFailure(error)
} }

View File

@ -823,6 +823,7 @@ func (sds *Service) writeStateDiff(block *types.Block, parentRoot common.Hash, p
if err != nil { if err != nil {
return err return err
} }
defer tx.RollbackOnFailure(err)
// TODO: review/remove the need to sync here // TODO: review/remove the need to sync here
var nodeMtx, ipldMtx sync.Mutex var nodeMtx, ipldMtx sync.Mutex