forked from cometbft/cometbft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_key_layout.go
124 lines (99 loc) · 2.99 KB
/
db_key_layout.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
package store
import (
"fmt"
"github.com/google/orderedcode"
)
type BlockKeyLayout interface {
CalcBlockMetaKey(height int64) []byte
CalcBlockPartKey(height int64, partIndex int) []byte
CalcBlockCommitKey(height int64) []byte
CalcSeenCommitKey(height int64) []byte
CalcExtCommitKey(height int64) []byte
CalcBlockHashKey(hash []byte) []byte
}
type v1LegacyLayout struct{}
// CalcBlockCommitKey implements BlockKeyLayout.
func (*v1LegacyLayout) CalcBlockCommitKey(height int64) []byte {
return []byte(fmt.Sprintf("C:%v", height))
}
// CalcBlockHashKey implements BlockKeyLayout.
func (*v1LegacyLayout) CalcBlockHashKey(hash []byte) []byte {
return []byte(fmt.Sprintf("BH:%x", hash))
}
// CalcBlockMetaKey implements BlockKeyLayout.
func (*v1LegacyLayout) CalcBlockMetaKey(height int64) []byte {
return []byte(fmt.Sprintf("H:%v", height))
}
// CalcBlockPartKey implements BlockKeyLayout.
func (*v1LegacyLayout) CalcBlockPartKey(height int64, partIndex int) []byte {
return []byte(fmt.Sprintf("P:%v:%v", height, partIndex))
}
// CalcExtCommitKey implements BlockKeyLayout.
func (*v1LegacyLayout) CalcExtCommitKey(height int64) []byte {
return []byte(fmt.Sprintf("EC:%v", height))
}
// CalcSeenCommitKey implements BlockKeyLayout.
func (*v1LegacyLayout) CalcSeenCommitKey(height int64) []byte {
return []byte(fmt.Sprintf("SC:%v", height))
}
var _ BlockKeyLayout = (*v1LegacyLayout)(nil)
type v2Layout struct{}
// key prefixes.
const (
// prefixes are unique across all tm db's.
prefixBlockMeta = int64(0)
prefixBlockPart = int64(1)
prefixBlockCommit = int64(2)
prefixSeenCommit = int64(3)
prefixExtCommit = int64(4)
prefixBlockHash = int64(5)
)
// CalcBlockCommitKey implements BlockKeyLayout.
func (*v2Layout) CalcBlockCommitKey(height int64) []byte {
key, err := orderedcode.Append(nil, prefixBlockCommit, height)
if err != nil {
panic(err)
}
return key
}
// CalcBlockHashKey implements BlockKeyLayout.
func (*v2Layout) CalcBlockHashKey(hash []byte) []byte {
key, err := orderedcode.Append(nil, prefixBlockHash, string(hash))
if err != nil {
panic(err)
}
return key
}
// CalcBlockMetaKey implements BlockKeyLayout.
func (*v2Layout) CalcBlockMetaKey(height int64) []byte {
key, err := orderedcode.Append(nil, prefixBlockMeta, height)
if err != nil {
panic(err)
}
return key
}
// CalcBlockPartKey implements BlockKeyLayout.
func (*v2Layout) CalcBlockPartKey(height int64, partIndex int) []byte {
key, err := orderedcode.Append(nil, prefixBlockPart, height, int64(partIndex))
if err != nil {
panic(err)
}
return key
}
// CalcExtCommitKey implements BlockKeyLayout.
func (*v2Layout) CalcExtCommitKey(height int64) []byte {
key, err := orderedcode.Append(nil, prefixExtCommit, height)
if err != nil {
panic(err)
}
return key
}
// CalcSeenCommitKey implements BlockKeyLayout.
func (*v2Layout) CalcSeenCommitKey(height int64) []byte {
key, err := orderedcode.Append(nil, prefixSeenCommit, height)
if err != nil {
panic(err)
}
return key
}
var _ BlockKeyLayout = (*v2Layout)(nil)