github.com/koko1123/flow-go-1@v0.29.6/storage/badger/operation/commits.go (about)

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