-
Notifications
You must be signed in to change notification settings - Fork 176
/
prefix.go
102 lines (88 loc) · 3.27 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
// (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
// codes for views with special meaning
codeStartedView = 10 // latest view hotstuff started
codeVotedView = 11 // latest view hotstuff voted on
// 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
// codes for indexing single identifier by identifier
codeHeightToBlock = 40 // index mapping height to block ID
codeBlockToSeal = 41 // index mapping a block its last payload seal
codeCollectionReference = 42 // index reference block ID for collection
codeBlockValidity = 43 // validity of block per HotStuff
// 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
codeBlockExecutionReceipt = 55 // index mapping block ID to execution receipt ID
codeBlockEpochStatus = 56 // index mapping block ID to epoch status
// codes related to epoch information
codeEpochSetup = 60 // EpochSetup service event, keyed by ID
codeEpochCommit = 61 // EpochCommit service event, keyed by ID
// legacy codes (should be cleaned up)
codeChunkDataPack = 100
codeCommit = 101
codeEvent = 102
codeExecutionStateInteractions = 103
codeTransactionResult = 104
codeFinalizedCluster = 105
codeIndexCollection = 200
codeIndexExecutionResultByBlock = 202
codeIndexCollectionByTransaction = 203
)
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))
}
}