forked from vguardbc/vguardbft
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cache.go
79 lines (69 loc) · 2.15 KB
/
cache.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
package main
/*
The implementation of V-Guard follows a "cache more, lock less" policy. This design
reduces lock overhead and contention while storing more intermediate results.
Intermediate consensus information for data batches are stored separately in the
ordering and consensus phases.
*/
import (
"encoding/hex"
"sync"
)
// ordSnapshot stores consensus information for each block in the ordering phase
// the map stores <blockID, blockSnapshot>
var ordSnapshot = struct {
m map[int64]*blockSnapshot
sync.RWMutex
}{m: make(map[int64]*blockSnapshot)}
// cmtSnapshot stores consensus information for each block in the consensus phase
// the map stores <blockID, blockSnapshot>
var cmtSnapshot = struct {
m map[int64]*blockSnapshot
sync.RWMutex
}{m: make(map[int64]*blockSnapshot)}
type blockSnapshot struct {
sync.RWMutex
// The hash of the block
hash []byte
// The data entries
entries map[int]Entry
// The signatures collected from validators to be converted to a threshold signature
sigs [][]byte
// rcvSig is the threshold signature of this block
tSig []byte
// The booth of this block
booth Booth
}
var vgTxMeta = struct {
sync.RWMutex
sigs map[int][][]byte // <rangeId, sigs[]>
hash map[int][]byte
blockIDs map[int][]int64 // <rangeId, []blockIDs>
}{
sigs: make(map[int][][]byte),
hash: make(map[int][]byte),
blockIDs: make(map[int][]int64),
}
var vgTxData = struct {
sync.RWMutex
tx map[int]map[string][][]Entry // map<consInstID, map<orderingBooth, []entry>>
boo map[int]Booth //<consInstID, Booth>
}{
tx: make(map[int]map[string][][]Entry),
boo: make(map[int]Booth),
}
func storeVgTx(consInstID int) {
vgTxData.RLock()
ordBoo := vgTxData.tx[consInstID]
cmtBoo := vgTxData.boo[consInstID]
vgTxData.RUnlock()
log.Infof("VGTX %d in Cmt Booth: %v | total # of tx: %d", consInstID, cmtBoo.Indices, vgrec.GetLastIdx()*BatchSize)
for key, chunk := range ordBoo { //map<boo, [][]entries>
log.Infof("ordering booth: %v | len(ordBoo[%v]): %v", key, key, len(chunk))
for _, entries := range chunk {
for _, e := range entries {
log.Infof("ts: %v; tx: %v", e.TimeStamp, hex.EncodeToString(e.Tx))
}
}
}
}