-
Notifications
You must be signed in to change notification settings - Fork 180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Extract uncurried functions from storage writes #6803
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
8202f87
extract non-curried writes functions
zhangchiqing 1876026
handle closer error
zhangchiqing a0068e1
simplify and consolidate CloseAndMergeError
zhangchiqing 522e0f3
Apply suggestions from code review
zhangchiqing f285e90
Apply suggestions from code review
zhangchiqing 39b4531
use assert.Error
zhangchiqing 36ae5ce
lint
zhangchiqing File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
//nolint:golint,unused | ||
package operation | ||
|
||
import ( | ||
"encoding/binary" | ||
"fmt" | ||
|
||
"github.com/onflow/flow-go/model/flow" | ||
) | ||
|
||
const ( | ||
|
||
// codes for special database markers | ||
// codeMax = 1 // deprecated | ||
codeDBType = 2 // specifies a database type | ||
|
||
// codes for views with special meaning | ||
codeSafetyData = 10 // safety data for hotstuff state | ||
codeLivenessData = 11 // liveness data for hotstuff state | ||
|
||
// codes for fields associated with the root state | ||
codeSporkID = 13 | ||
codeProtocolVersion = 14 | ||
codeEpochCommitSafetyThreshold = 15 | ||
codeSporkRootBlockHeight = 16 | ||
|
||
// code for heights with special meaning | ||
codeFinalizedHeight = 20 // latest finalized block height | ||
codeSealedHeight = 21 // latest sealed block height | ||
codeClusterHeight = 22 // latest finalized height on cluster | ||
codeExecutedBlock = 23 // latest executed block with max height | ||
codeFinalizedRootHeight = 24 // the height of the highest finalized block contained in the root snapshot | ||
codeLastCompleteBlockHeight = 25 // the height of the last block for which all collections were received | ||
codeEpochFirstHeight = 26 // the height of the first block in a given epoch | ||
codeSealedRootHeight = 27 // the height of the highest sealed block contained in the root snapshot | ||
|
||
// codes for single entity storage | ||
codeHeader = 30 | ||
_ = 31 // DEPRECATED: 31 was used for identities before epochs | ||
codeGuarantee = 32 | ||
codeSeal = 33 | ||
codeTransaction = 34 | ||
codeCollection = 35 | ||
codeExecutionResult = 36 | ||
codeResultApproval = 37 | ||
codeChunk = 38 | ||
codeExecutionReceiptMeta = 39 // NOTE: prior to Mainnet25, this erroneously had the same value as codeExecutionResult (36) | ||
|
||
// codes for indexing single identifier by identifier/integer | ||
codeHeightToBlock = 40 // index mapping height to block ID | ||
codeBlockIDToLatestSealID = 41 // index mapping a block its last payload seal | ||
codeClusterBlockToRefBlock = 42 // index cluster block ID to reference block ID | ||
codeRefHeightToClusterBlock = 43 // index reference block height to cluster block IDs | ||
codeBlockIDToFinalizedSeal = 44 // index _finalized_ seal by sealed block ID | ||
codeBlockIDToQuorumCertificate = 45 // index of quorum certificates by block ID | ||
codeEpochProtocolStateByBlockID = 46 // index of epoch protocol state entry by block ID | ||
codeProtocolKVStoreByBlockID = 47 // index of protocol KV store entry by block ID | ||
|
||
// codes for indexing multiple identifiers by identifier | ||
codeBlockChildren = 50 // index mapping block ID to children blocks | ||
_ = 51 // DEPRECATED: 51 was used for identity indexes before epochs | ||
codePayloadGuarantees = 52 // index mapping block ID to payload guarantees | ||
codePayloadSeals = 53 // index mapping block ID to payload seals | ||
codeCollectionBlock = 54 // index mapping collection ID to block ID | ||
codeOwnBlockReceipt = 55 // index mapping block ID to execution receipt ID for execution nodes | ||
_ = 56 // DEPRECATED: 56 was used for block->epoch status prior to Dynamic Protocol State in Mainnet25 | ||
codePayloadReceipts = 57 // index mapping block ID to payload receipts | ||
codePayloadResults = 58 // index mapping block ID to payload results | ||
codeAllBlockReceipts = 59 // index mapping of blockID to multiple receipts | ||
codePayloadProtocolStateID = 60 // index mapping block ID to payload protocol state ID | ||
|
||
// codes related to protocol level information | ||
codeEpochSetup = 61 // EpochSetup service event, keyed by ID | ||
codeEpochCommit = 62 // EpochCommit service event, keyed by ID | ||
codeBeaconPrivateKey = 63 // BeaconPrivateKey, keyed by epoch counter | ||
codeDKGStarted = 64 // flag that the DKG for an epoch has been started | ||
codeDKGEnded = 65 // flag that the DKG for an epoch has ended (stores end state) | ||
codeVersionBeacon = 67 // flag for storing version beacons | ||
codeEpochProtocolState = 68 | ||
codeProtocolKVStore = 69 | ||
|
||
// code for ComputationResult upload status storage | ||
// NOTE: for now only GCP uploader is supported. When other uploader (AWS e.g.) needs to | ||
// be supported, we will need to define new code. | ||
codeComputationResults = 66 | ||
|
||
// job queue consumers and producers | ||
codeJobConsumerProcessed = 70 | ||
codeJobQueue = 71 | ||
codeJobQueuePointer = 72 | ||
|
||
// legacy codes (should be cleaned up) | ||
codeChunkDataPack = 100 | ||
codeCommit = 101 | ||
codeEvent = 102 | ||
codeExecutionStateInteractions = 103 | ||
codeTransactionResult = 104 | ||
codeFinalizedCluster = 105 | ||
codeServiceEvent = 106 | ||
codeTransactionResultIndex = 107 | ||
codeLightTransactionResult = 108 | ||
codeLightTransactionResultIndex = 109 | ||
codeTransactionResultErrorMessage = 110 | ||
codeTransactionResultErrorMessageIndex = 111 | ||
codeIndexCollection = 200 | ||
codeIndexExecutionResultByBlock = 202 | ||
codeIndexCollectionByTransaction = 203 | ||
codeIndexResultApprovalByChunk = 204 | ||
|
||
// TEMPORARY codes | ||
blockedNodeIDs = 205 // manual override for adding node IDs to list of ejected nodes, applies to networking layer only | ||
|
||
// internal failure information that should be preserved across restarts | ||
codeExecutionFork = 254 | ||
codeEpochEmergencyFallbackTriggered = 255 | ||
) | ||
|
||
func MakePrefix(code byte, keys ...interface{}) []byte { | ||
prefix := make([]byte, 1) | ||
prefix[0] = code | ||
for _, key := range keys { | ||
prefix = append(prefix, KeyPartToBytes(key)...) | ||
} | ||
return prefix | ||
} | ||
|
||
func KeyPartToBytes(v interface{}) []byte { | ||
switch i := v.(type) { | ||
case uint8: | ||
return []byte{i} | ||
case uint32: | ||
b := make([]byte, 4) | ||
binary.BigEndian.PutUint32(b, i) | ||
return b | ||
case uint64: | ||
b := make([]byte, 8) | ||
binary.BigEndian.PutUint64(b, i) | ||
return b | ||
case string: | ||
return []byte(i) | ||
case flow.Role: | ||
return []byte{byte(i)} | ||
case flow.Identifier: | ||
return i[:] | ||
case flow.ChainID: | ||
return []byte(i) | ||
default: | ||
panic(fmt.Sprintf("unsupported type to convert (%T)", v)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where did these constants come from? Is this a unrelated thing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are copied from https://github.com/onflow/flow-go/blob/master/storage/badger/operation/prefix.go