github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/storage/badger/operation/spork.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  // InsertSporkID inserts the spork ID for the present spork. A single database
    10  // and protocol state instance spans at most one spork, so this is inserted
    11  // exactly once, when bootstrapping the state.
    12  func InsertSporkID(sporkID flow.Identifier) func(*badger.Txn) error {
    13  	return insert(makePrefix(codeSporkID), sporkID)
    14  }
    15  
    16  // RetrieveSporkID retrieves the spork ID for the present spork.
    17  func RetrieveSporkID(sporkID *flow.Identifier) func(*badger.Txn) error {
    18  	return retrieve(makePrefix(codeSporkID), sporkID)
    19  }
    20  
    21  // InsertSporkRootBlockHeight inserts the spork root block height for the present spork.
    22  // A single database and protocol state instance spans at most one spork, so this is inserted
    23  // exactly once, when bootstrapping the state.
    24  func InsertSporkRootBlockHeight(height uint64) func(*badger.Txn) error {
    25  	return insert(makePrefix(codeSporkRootBlockHeight), height)
    26  }
    27  
    28  // RetrieveSporkRootBlockHeight retrieves the spork root block height for the present spork.
    29  func RetrieveSporkRootBlockHeight(height *uint64) func(*badger.Txn) error {
    30  	return retrieve(makePrefix(codeSporkRootBlockHeight), height)
    31  }
    32  
    33  // InsertProtocolVersion inserts the protocol version for the present spork.
    34  // A single database and protocol state instance spans at most one spork, and
    35  // a spork has exactly one protocol version for its duration, so this is
    36  // inserted exactly once, when bootstrapping the state.
    37  func InsertProtocolVersion(version uint) func(*badger.Txn) error {
    38  	return insert(makePrefix(codeProtocolVersion), version)
    39  }
    40  
    41  // RetrieveProtocolVersion retrieves the protocol version for the present spork.
    42  func RetrieveProtocolVersion(version *uint) func(*badger.Txn) error {
    43  	return retrieve(makePrefix(codeProtocolVersion), version)
    44  }
    45  
    46  // InsertEpochCommitSafetyThreshold inserts the epoch commit safety threshold
    47  // for the present spork.
    48  // A single database and protocol state instance spans at most one spork, and
    49  // a spork has exactly one protocol version for its duration, so this is
    50  // inserted exactly once, when bootstrapping the state.
    51  func InsertEpochCommitSafetyThreshold(threshold uint64) func(*badger.Txn) error {
    52  	return insert(makePrefix(codeEpochCommitSafetyThreshold), threshold)
    53  }
    54  
    55  // RetrieveEpochCommitSafetyThreshold retrieves the epoch commit safety threshold
    56  // for the present spork.
    57  func RetrieveEpochCommitSafetyThreshold(threshold *uint64) func(*badger.Txn) error {
    58  	return retrieve(makePrefix(codeEpochCommitSafetyThreshold), threshold)
    59  }