-
Notifications
You must be signed in to change notification settings - Fork 5
/
types.go
88 lines (69 loc) · 1.93 KB
/
types.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
package block_stm
import (
"bytes"
storetypes "cosmossdk.io/store/types"
)
type (
TxnIndex int
Incarnation uint
)
type TxnVersion struct {
Index TxnIndex
Incarnation Incarnation
}
var InvalidTxnVersion = TxnVersion{-1, 0}
func (v TxnVersion) Valid() bool {
return v.Index >= 0
}
type Key []byte
type ReadDescriptor struct {
Key Key
// invalid Version means the key is read from storage
Version TxnVersion
}
type IteratorOptions struct {
// [Start, End) is the range of the iterator
Start Key
End Key
Ascending bool
}
type IteratorDescriptor struct {
IteratorOptions
// Stop is not `nil` if the iteration is not exhausted and stops at a key before reaching the end of the range,
// the effective range is `[start, stop]`.
// when replaying, it should also stops at the stop key.
Stop Key
// Reads is the list of keys that is observed by the iterator.
Reads []ReadDescriptor
}
type ReadSet struct {
Reads []ReadDescriptor
Iterators []IteratorDescriptor
}
type MultiReadSet = map[int]*ReadSet
type KeyItem interface {
GetKey() []byte
}
func KeyItemLess[T KeyItem](a, b T) bool {
return bytes.Compare(a.GetKey(), b.GetKey()) < 0
}
// TxExecutor executes transactions on top of a multi-version memory view.
type TxExecutor func(TxnIndex, MultiStore)
type MultiStore interface {
GetStore(storetypes.StoreKey) storetypes.Store
GetKVStore(storetypes.StoreKey) storetypes.KVStore
GetObjKVStore(storetypes.StoreKey) storetypes.ObjKVStore
}
// MVStore is a value type agnostic interface for `MVData`, to keep `MVMemory` value type agnostic.
type MVStore interface {
Delete(Key, TxnIndex)
WriteEstimate(Key, TxnIndex)
ValidateReadSet(TxnIndex, *ReadSet) bool
SnapshotToStore(storetypes.Store)
}
// MVView is a value type agnostic interface for `MVMemoryView`, to keep `MultiMVMemoryView` value type agnostic.
type MVView interface {
storetypes.Store
ApplyWriteSet(TxnVersion) Locations
ReadSet() *ReadSet
}