github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/storage/badger/operation/commits.go (about) 1 package operation 2 3 import ( 4 "github.com/dgraph-io/badger/v2" 5 6 "github.com/onflow/flow-go/model/flow" 7 ) 8 9 // IndexStateCommitment indexes a state commitment. 10 // 11 // State commitments are keyed by the block whose execution results in the state with the given commit. 12 func IndexStateCommitment(blockID flow.Identifier, commit flow.StateCommitment) func(*badger.Txn) error { 13 return insert(makePrefix(codeCommit, blockID), commit) 14 } 15 16 // BatchIndexStateCommitment indexes a state commitment into a batch 17 // 18 // State commitments are keyed by the block whose execution results in the state with the given commit. 19 func BatchIndexStateCommitment(blockID flow.Identifier, commit flow.StateCommitment) func(batch *badger.WriteBatch) error { 20 return batchWrite(makePrefix(codeCommit, blockID), commit) 21 } 22 23 // LookupStateCommitment gets a state commitment keyed by block ID 24 // 25 // State commitments are keyed by the block whose execution results in the state with the given commit. 26 func LookupStateCommitment(blockID flow.Identifier, commit *flow.StateCommitment) func(*badger.Txn) error { 27 return retrieve(makePrefix(codeCommit, blockID), commit) 28 } 29 30 // RemoveStateCommitment removes the state commitment by block ID 31 func RemoveStateCommitment(blockID flow.Identifier) func(*badger.Txn) error { 32 return remove(makePrefix(codeCommit, blockID)) 33 } 34 35 // BatchRemoveStateCommitment batch removes the state commitment by block ID 36 // No errors are expected during normal operation, even if no entries are matched. 37 // If Badger unexpectedly fails to process the request, the error is wrapped in a generic error and returned. 38 func BatchRemoveStateCommitment(blockID flow.Identifier) func(batch *badger.WriteBatch) error { 39 return batchRemove(makePrefix(codeCommit, blockID)) 40 }