github.com/koko1123/flow-go-1@v0.29.6/storage/badger/operation/prefix.go (about) 1 // (c) 2019 Dapper Labs - ALL RIGHTS RESERVED 2 3 package operation 4 5 import ( 6 "encoding/binary" 7 "fmt" 8 9 "github.com/koko1123/flow-go-1/model/flow" 10 ) 11 12 const ( 13 14 // codes for special database markers 15 codeMax = 1 // keeps track of the maximum key size 16 codeDBType = 2 // specifies a database type 17 18 // codes for views with special meaning 19 codeStartedView = 10 // latest view hotstuff started 20 codeVotedView = 11 // latest view hotstuff voted on 21 22 // codes for fields associated with the root state 23 codeRootQuorumCertificate = 12 24 codeSporkID = 13 25 codeProtocolVersion = 14 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 codeRootHeight = 24 // the height of the first loaded block 33 codeLastCompleteBlockHeight = 25 // the height of the last block for which all collections were received 34 35 // codes for single entity storage 36 // 31 was used for identities before epochs 37 codeHeader = 30 38 codeGuarantee = 32 39 codeSeal = 33 40 codeTransaction = 34 41 codeCollection = 35 42 codeExecutionResult = 36 43 codeExecutionReceiptMeta = 36 44 codeResultApproval = 37 45 codeChunk = 38 46 47 // codes for indexing single identifier by identifier/integeter 48 codeHeightToBlock = 40 // index mapping height to block ID 49 codeBlockIDToLatestSealID = 41 // index mapping a block its last payload seal 50 codeClusterBlockToRefBlock = 42 // index cluster block ID to reference block ID 51 codeBlockValidity = 43 // validity of block per HotStuff 52 codeRefHeightToClusterBlock = 44 // index reference block height to cluster block IDs 53 codeBlockIDToFinalizedSeal = 45 // index _finalized_ seal by sealed block ID 54 55 // codes for indexing multiple identifiers by identifier 56 // NOTE: 51 was used for identity indexes before epochs 57 codeBlockChildren = 50 // index mapping block ID to children blocks 58 codePayloadGuarantees = 52 // index mapping block ID to payload guarantees 59 codePayloadSeals = 53 // index mapping block ID to payload seals 60 codeCollectionBlock = 54 // index mapping collection ID to block ID 61 codeOwnBlockReceipt = 55 // index mapping block ID to execution receipt ID for execution nodes 62 codeBlockEpochStatus = 56 // index mapping block ID to epoch status 63 codePayloadReceipts = 57 // index mapping block ID to payload receipts 64 codePayloadResults = 58 // index mapping block ID to payload results 65 codeAllBlockReceipts = 59 // index mapping of blockID to multiple receipts 66 codeIndexBlockByChunkID = 60 // index mapping chunk ID to block ID 67 68 // codes related to epoch information 69 codeEpochSetup = 61 // EpochSetup service event, keyed by ID 70 codeEpochCommit = 62 // EpochCommit service event, keyed by ID 71 codeBeaconPrivateKey = 63 // BeaconPrivateKey, keyed by epoch counter 72 codeDKGStarted = 64 // flag that the DKG for an epoch has been started 73 codeDKGEnded = 65 // flag that the DKG for an epoch has ended (stores end state) 74 75 // code for ComputationResult upload status storage 76 // NOTE: for now only GCP uploader is supported. When other uploader (AWS e.g.) needs to 77 // be supported, we will need to define new code. 78 codeComputationResults = 66 79 80 // job queue consumers and producers 81 codeJobConsumerProcessed = 70 82 codeJobQueue = 71 83 codeJobQueuePointer = 72 84 85 // legacy codes (should be cleaned up) 86 codeChunkDataPack = 100 87 codeCommit = 101 88 codeEvent = 102 89 codeExecutionStateInteractions = 103 90 codeTransactionResult = 104 91 codeFinalizedCluster = 105 92 codeServiceEvent = 106 93 codeTransactionResultIndex = 107 94 codeIndexCollection = 200 95 codeIndexExecutionResultByBlock = 202 96 codeIndexCollectionByTransaction = 203 97 codeIndexResultApprovalByChunk = 204 98 99 // TEMPORARY codes 100 blockedNodeIDs = 205 // manual override for adding node IDs to list of ejected nodes, applies to networking layer only 101 102 // internal failure information that should be preserved across restarts 103 codeExecutionFork = 254 104 codeEpochEmergencyFallbackTriggered = 255 105 ) 106 107 func makePrefix(code byte, keys ...interface{}) []byte { 108 prefix := make([]byte, 1) 109 prefix[0] = code 110 for _, key := range keys { 111 prefix = append(prefix, b(key)...) 112 } 113 return prefix 114 } 115 116 func b(v interface{}) []byte { 117 switch i := v.(type) { 118 case uint8: 119 return []byte{i} 120 case uint32: 121 b := make([]byte, 4) 122 binary.BigEndian.PutUint32(b, i) 123 return b 124 case uint64: 125 b := make([]byte, 8) 126 binary.BigEndian.PutUint64(b, i) 127 return b 128 case string: 129 return []byte(i) 130 case flow.Role: 131 return []byte{byte(i)} 132 case flow.Identifier: 133 return i[:] 134 case flow.ChainID: 135 return []byte(i) 136 default: 137 panic(fmt.Sprintf("unsupported type to convert (%T)", v)) 138 } 139 }