-
Notifications
You must be signed in to change notification settings - Fork 0
/
fuzz_msg.go
142 lines (125 loc) · 3.09 KB
/
fuzz_msg.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
140
141
142
package tbft
import (
"chainmaker.org/chainmaker/pb-go/v2/common"
consensuspb "chainmaker.org/chainmaker/pb-go/v2/consensus"
tbftpb "chainmaker.org/chainmaker/pb-go/v2/consensus/tbft"
netpb "chainmaker.org/chainmaker/pb-go/v2/net"
)
const (
Int32 = iota
Uint64
String
byteArray
stringArray
)
type Map map[string]*Value
type Value struct {
Type string
Payload interface{}
}
func UnresolvedPointer(payload interface{}) *Value {
return &Value{
Type: "Pointer",
Payload: payload,
}
}
func Int32ToValue(payload int32) *Value {
return &Value{
Type: "int32",
Payload: payload,
}
}
func UInt64ToValue(payload uint64) *Value {
return &Value{
Type: "uint64",
Payload: payload,
}
}
func StringToValue(payload string) *Value {
return &Value{
Type: "string",
Payload: payload,
}
}
func ByteArrayToValue(payload []byte) *Value {
return &Value{
Type: "[]byte",
Payload: payload,
}
}
func StringArrayToValue(payload []string) *Value {
return &Value{
Type: "[]string",
Payload: payload,
}
}
func VoteToValue(vote *tbftpb.Vote) *Value {
return &Value{
Type: "map",
Payload: Map{
"Type": Int32ToValue(int32(vote.Type)),
"Voter": StringToValue(vote.Voter),
"Height": UInt64ToValue(vote.Height),
"Round": Int32ToValue(vote.Round),
"Hash": ByteArrayToValue(vote.Hash),
"InvalidTxs": StringArrayToValue(vote.InvalidTxs),
"Endorsement": UnresolvedPointer(vote.Endorsement),
},
}
}
func BlockToValue(block *common.Block) *Value {
return &Value{
Type: "map_Block",
Payload: Map{
"Header": UnresolvedPointer(block.Header),
"Dag": UnresolvedPointer(block.Dag),
"Txs": UnresolvedPointer(block.Txs),
"AdditionalData": UnresolvedPointer(block.AdditionalData),
},
}
}
func RwSetVerifyFailTxsToValue(txs *consensuspb.RwSetVerifyFailTxs) *Value {
return &Value{
Type: "map_RwSetVerifyFailTxs",
Payload: Map{
"BlockHeight": UInt64ToValue(txs.BlockHeight),
"TxIds": StringArrayToValue(txs.TxIds),
},
}
}
func ConsensusMsgToValue(consensusMsg *ConsensusMsg) *Value {
var res = &Value{
Type: "map_ConsensusMsg",
Payload: Map{
"Type": Int32ToValue(int32(consensusMsg.Type)),
},
}
if consensusMsg.Type == tbftpb.TBFTMsgType_MSG_PREVOTE || consensusMsg.Type == tbftpb.TBFTMsgType_MSG_PRECOMMIT {
res.Payload.(Map)["Msg"] = VoteToValue(consensusMsg.Msg.(*tbftpb.Vote))
}
return res
}
func NetMsgToValue(netMsg netpb.NetMsg) *Value {
return &Value{
Type: "map_netMsg",
Payload: Map{
"Type": Int32ToValue(int32(netMsg.Type)),
"Payload": UnresolvedPointer(netMsg.Payload),
"To": StringToValue(netMsg.To),
},
}
}
func TBFTMsgToValue(msg tbftpb.TBFTMsg) *Value {
var res = &Value{
Type: "map_TBFTMsg",
Payload: Map{
"Type": Int32ToValue(int32(msg.Type)),
},
}
if msg.Type == tbftpb.TBFTMsgType_MSG_PROPOSE {
res.Payload.(Map)["Msg"] = UnresolvedPointer(msg.Msg)
} else if msg.Type == tbftpb.TBFTMsgType_MSG_PREVOTE || msg.Type == tbftpb.TBFTMsgType_MSG_PRECOMMIT {
res.Payload.(Map)["Msg"] = UnresolvedPointer(msg.Msg)
}
return res
}