-
Notifications
You must be signed in to change notification settings - Fork 175
/
prefix.go
139 lines (120 loc) · 5.02 KB
/
prefix.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
// (c) 2019 Dapper Labs - ALL RIGHTS RESERVED
package operation
import (
"encoding/binary"
"fmt"
"github.com/onflow/flow-go/model/flow"
)
const (
// codes for special database markers
codeMax = 1 // keeps track of the maximum key size
codeDBType = 2 // specifies a database type
// codes for views with special meaning
codeStartedView = 10 // latest view hotstuff started
codeVotedView = 11 // latest view hotstuff voted on
// codes for fields associated with the root state
codeRootQuorumCertificate = 12
codeSporkID = 13
codeProtocolVersion = 14
// 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
codeRootHeight = 24 // the height of the first loaded block
codeLastCompleteBlockHeight = 25 // the height of the last block for which all collections were received
// codes for single entity storage
// 31 was used for identities before epochs
codeHeader = 30
codeGuarantee = 32
codeSeal = 33
codeTransaction = 34
codeCollection = 35
codeExecutionResult = 36
codeExecutionReceiptMeta = 36
codeResultApproval = 37
codeChunk = 38
// codes for indexing single identifier by identifier/integeter
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
codeBlockValidity = 43 // validity of block per HotStuff
codeRefHeightToClusterBlock = 44 // index reference block height to cluster block IDs
codeBlockIDToFinalizedSeal = 45 // index _finalized_ seal by sealed block ID
// codes for indexing multiple identifiers by identifier
// NOTE: 51 was used for identity indexes before epochs
codeBlockChildren = 50 // index mapping block ID to children blocks
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
codeBlockEpochStatus = 56 // index mapping block ID to epoch status
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
codeIndexBlockByChunkID = 60 // index mapping chunk ID to block ID
// codes related to epoch 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)
// 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
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, b(key)...)
}
return prefix
}
func b(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))
}
}