Skip to content

Commit

Permalink
contracts: prevent root cache update if revise fails
Browse files Browse the repository at this point in the history
  • Loading branch information
n8maninger committed Feb 6, 2024
1 parent 48422cb commit 7391c15
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions host/contracts/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 7391c15

Please sign in to comment.