From 7391c15269a9beca9648b0fb09ed9e97776878a2 Mon Sep 17 00:00:00 2001 From: Nate Maninger Date: Tue, 6 Feb 2024 14:29:55 -0800 Subject: [PATCH] contracts: prevent root cache update if revise fails --- host/contracts/contracts.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/host/contracts/contracts.go b/host/contracts/contracts.go index 6c5cce9a..5831b62a 100644 --- a/host/contracts/contracts.go +++ b/host/contracts/contracts.go @@ -332,12 +332,14 @@ func (cu *ContractUpdater) Commit(revision SignedRevision, usage Usage) error { start := time.Now() // revise the contract err := cu.store.ReviseContract(revision, cu.oldRoots, usage, cu.sectorActions) - if err == nil { - // clear the committed sector actions - cu.sectorActions = cu.sectorActions[:0] + if err != nil { + return err } + + // clear the committed sector actions + cu.sectorActions = cu.sectorActions[:0] // update the roots cache - cu.rootsCache.Add(revision.Revision.ParentID, cu.sectorRoots[:]) + cu.rootsCache.Add(revision.Revision.ParentID, append([]types.Hash256(nil), cu.sectorRoots...)) cu.log.Debug("contract update committed", zap.String("contractID", revision.Revision.ParentID.String()), zap.Uint64("revision", revision.Revision.RevisionNumber), zap.Duration("elapsed", time.Since(start))) - return err + return nil }