|
| 1 | +//nolint:golint,unused |
| 2 | +package operation |
| 3 | + |
| 4 | +import ( |
| 5 | + "encoding/binary" |
| 6 | + "fmt" |
| 7 | + |
| 8 | + "github.com/onflow/flow-go/model/flow" |
| 9 | +) |
| 10 | + |
| 11 | +const ( |
| 12 | + |
| 13 | + // codes for special database markers |
| 14 | + // codeMax = 1 // deprecated |
| 15 | + codeDBType = 2 // specifies a database type |
| 16 | + |
| 17 | + // codes for views with special meaning |
| 18 | + codeSafetyData = 10 // safety data for hotstuff state |
| 19 | + codeLivenessData = 11 // liveness data for hotstuff state |
| 20 | + |
| 21 | + // codes for fields associated with the root state |
| 22 | + codeSporkID = 13 |
| 23 | + codeProtocolVersion = 14 |
| 24 | + codeEpochCommitSafetyThreshold = 15 |
| 25 | + codeSporkRootBlockHeight = 16 |
| 26 | + |
| 27 | + // code for heights with special meaning |
| 28 | + codeFinalizedHeight = 20 // latest finalized block height |
| 29 | + codeSealedHeight = 21 // latest sealed block height |
| 30 | + codeClusterHeight = 22 // latest finalized height on cluster |
| 31 | + codeExecutedBlock = 23 // latest executed block with max height |
| 32 | + codeFinalizedRootHeight = 24 // the height of the highest finalized block contained in the root snapshot |
| 33 | + codeLastCompleteBlockHeight = 25 // the height of the last block for which all collections were received |
| 34 | + codeEpochFirstHeight = 26 // the height of the first block in a given epoch |
| 35 | + codeSealedRootHeight = 27 // the height of the highest sealed block contained in the root snapshot |
| 36 | + |
| 37 | + // codes for single entity storage |
| 38 | + codeHeader = 30 |
| 39 | + _ = 31 // DEPRECATED: 31 was used for identities before epochs |
| 40 | + codeGuarantee = 32 |
| 41 | + codeSeal = 33 |
| 42 | + codeTransaction = 34 |
| 43 | + codeCollection = 35 |
| 44 | + codeExecutionResult = 36 |
| 45 | + codeResultApproval = 37 |
| 46 | + codeChunk = 38 |
| 47 | + codeExecutionReceiptMeta = 39 // NOTE: prior to Mainnet25, this erroneously had the same value as codeExecutionResult (36) |
| 48 | + |
| 49 | + // codes for indexing single identifier by identifier/integer |
| 50 | + codeHeightToBlock = 40 // index mapping height to block ID |
| 51 | + codeBlockIDToLatestSealID = 41 // index mapping a block its last payload seal |
| 52 | + codeClusterBlockToRefBlock = 42 // index cluster block ID to reference block ID |
| 53 | + codeRefHeightToClusterBlock = 43 // index reference block height to cluster block IDs |
| 54 | + codeBlockIDToFinalizedSeal = 44 // index _finalized_ seal by sealed block ID |
| 55 | + codeBlockIDToQuorumCertificate = 45 // index of quorum certificates by block ID |
| 56 | + codeEpochProtocolStateByBlockID = 46 // index of epoch protocol state entry by block ID |
| 57 | + codeProtocolKVStoreByBlockID = 47 // index of protocol KV store entry by block ID |
| 58 | + |
| 59 | + // codes for indexing multiple identifiers by identifier |
| 60 | + codeBlockChildren = 50 // index mapping block ID to children blocks |
| 61 | + _ = 51 // DEPRECATED: 51 was used for identity indexes before epochs |
| 62 | + codePayloadGuarantees = 52 // index mapping block ID to payload guarantees |
| 63 | + codePayloadSeals = 53 // index mapping block ID to payload seals |
| 64 | + codeCollectionBlock = 54 // index mapping collection ID to block ID |
| 65 | + codeOwnBlockReceipt = 55 // index mapping block ID to execution receipt ID for execution nodes |
| 66 | + _ = 56 // DEPRECATED: 56 was used for block->epoch status prior to Dynamic Protocol State in Mainnet25 |
| 67 | + codePayloadReceipts = 57 // index mapping block ID to payload receipts |
| 68 | + codePayloadResults = 58 // index mapping block ID to payload results |
| 69 | + codeAllBlockReceipts = 59 // index mapping of blockID to multiple receipts |
| 70 | + codePayloadProtocolStateID = 60 // index mapping block ID to payload protocol state ID |
| 71 | + |
| 72 | + // codes related to protocol level information |
| 73 | + codeEpochSetup = 61 // EpochSetup service event, keyed by ID |
| 74 | + codeEpochCommit = 62 // EpochCommit service event, keyed by ID |
| 75 | + codeBeaconPrivateKey = 63 // BeaconPrivateKey, keyed by epoch counter |
| 76 | + codeDKGStarted = 64 // flag that the DKG for an epoch has been started |
| 77 | + codeDKGEnded = 65 // flag that the DKG for an epoch has ended (stores end state) |
| 78 | + codeVersionBeacon = 67 // flag for storing version beacons |
| 79 | + codeEpochProtocolState = 68 |
| 80 | + codeProtocolKVStore = 69 |
| 81 | + |
| 82 | + // code for ComputationResult upload status storage |
| 83 | + // NOTE: for now only GCP uploader is supported. When other uploader (AWS e.g.) needs to |
| 84 | + // be supported, we will need to define new code. |
| 85 | + codeComputationResults = 66 |
| 86 | + |
| 87 | + // job queue consumers and producers |
| 88 | + codeJobConsumerProcessed = 70 |
| 89 | + codeJobQueue = 71 |
| 90 | + codeJobQueuePointer = 72 |
| 91 | + |
| 92 | + // legacy codes (should be cleaned up) |
| 93 | + codeChunkDataPack = 100 |
| 94 | + codeCommit = 101 |
| 95 | + codeEvent = 102 |
| 96 | + codeExecutionStateInteractions = 103 |
| 97 | + codeTransactionResult = 104 |
| 98 | + codeFinalizedCluster = 105 |
| 99 | + codeServiceEvent = 106 |
| 100 | + codeTransactionResultIndex = 107 |
| 101 | + codeLightTransactionResult = 108 |
| 102 | + codeLightTransactionResultIndex = 109 |
| 103 | + codeTransactionResultErrorMessage = 110 |
| 104 | + codeTransactionResultErrorMessageIndex = 111 |
| 105 | + codeIndexCollection = 200 |
| 106 | + codeIndexExecutionResultByBlock = 202 |
| 107 | + codeIndexCollectionByTransaction = 203 |
| 108 | + codeIndexResultApprovalByChunk = 204 |
| 109 | + |
| 110 | + // TEMPORARY codes |
| 111 | + blockedNodeIDs = 205 // manual override for adding node IDs to list of ejected nodes, applies to networking layer only |
| 112 | + |
| 113 | + // internal failure information that should be preserved across restarts |
| 114 | + codeExecutionFork = 254 |
| 115 | + codeEpochEmergencyFallbackTriggered = 255 |
| 116 | +) |
| 117 | + |
| 118 | +func MakePrefix(code byte, keys ...interface{}) []byte { |
| 119 | + prefix := make([]byte, 1) |
| 120 | + prefix[0] = code |
| 121 | + for _, key := range keys { |
| 122 | + prefix = append(prefix, KeyPartToBytes(key)...) |
| 123 | + } |
| 124 | + return prefix |
| 125 | +} |
| 126 | + |
| 127 | +func KeyPartToBytes(v interface{}) []byte { |
| 128 | + switch i := v.(type) { |
| 129 | + case uint8: |
| 130 | + return []byte{i} |
| 131 | + case uint32: |
| 132 | + b := make([]byte, 4) |
| 133 | + binary.BigEndian.PutUint32(b, i) |
| 134 | + return b |
| 135 | + case uint64: |
| 136 | + b := make([]byte, 8) |
| 137 | + binary.BigEndian.PutUint64(b, i) |
| 138 | + return b |
| 139 | + case string: |
| 140 | + return []byte(i) |
| 141 | + case flow.Role: |
| 142 | + return []byte{byte(i)} |
| 143 | + case flow.Identifier: |
| 144 | + return i[:] |
| 145 | + case flow.ChainID: |
| 146 | + return []byte(i) |
| 147 | + default: |
| 148 | + panic(fmt.Sprintf("unsupported type to convert (%T)", v)) |
| 149 | + } |
| 150 | +} |
0 commit comments