-
Notifications
You must be signed in to change notification settings - Fork 199
/
common.go
142 lines (126 loc) · 3.79 KB
/
common.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 interceptedBlocks
import (
"github.com/ElrondNetwork/elrond-go-core/core"
"github.com/ElrondNetwork/elrond-go-core/core/check"
"github.com/ElrondNetwork/elrond-go-core/data"
"github.com/ElrondNetwork/elrond-go-core/data/block"
"github.com/ElrondNetwork/elrond-go/process"
"github.com/ElrondNetwork/elrond-go/sharding"
)
func checkBlockHeaderArgument(arg *ArgInterceptedBlockHeader) error {
if arg == nil {
return process.ErrNilArgumentStruct
}
if len(arg.HdrBuff) == 0 {
return process.ErrNilBuffer
}
if check.IfNil(arg.Marshalizer) {
return process.ErrNilMarshalizer
}
if check.IfNil(arg.Hasher) {
return process.ErrNilHasher
}
if check.IfNil(arg.ShardCoordinator) {
return process.ErrNilShardCoordinator
}
if check.IfNil(arg.HeaderSigVerifier) {
return process.ErrNilHeaderSigVerifier
}
if check.IfNil(arg.HeaderIntegrityVerifier) {
return process.ErrNilHeaderIntegrityVerifier
}
if check.IfNil(arg.EpochStartTrigger) {
return process.ErrNilEpochStartTrigger
}
if check.IfNil(arg.ValidityAttester) {
return process.ErrNilValidityAttester
}
return nil
}
func checkMiniblockArgument(arg *ArgInterceptedMiniblock) error {
if arg == nil {
return process.ErrNilArgumentStruct
}
if len(arg.MiniblockBuff) == 0 {
return process.ErrNilBuffer
}
if check.IfNil(arg.Marshalizer) {
return process.ErrNilMarshalizer
}
if check.IfNil(arg.Hasher) {
return process.ErrNilHasher
}
if check.IfNil(arg.ShardCoordinator) {
return process.ErrNilShardCoordinator
}
return nil
}
func checkHeaderHandler(hdr data.HeaderHandler) error {
if len(hdr.GetPubKeysBitmap()) == 0 {
return process.ErrNilPubKeysBitmap
}
if len(hdr.GetPrevHash()) == 0 {
return process.ErrNilPreviousBlockHash
}
if len(hdr.GetSignature()) == 0 {
return process.ErrNilSignature
}
if len(hdr.GetRootHash()) == 0 {
return process.ErrNilRootHash
}
if len(hdr.GetRandSeed()) == 0 {
return process.ErrNilRandSeed
}
if len(hdr.GetPrevRandSeed()) == 0 {
return process.ErrNilPrevRandSeed
}
return nil
}
func checkMetaShardInfo(shardInfo []block.ShardData, coordinator sharding.Coordinator) error {
for _, sd := range shardInfo {
if sd.ShardID >= coordinator.NumberOfShards() && sd.ShardID != core.MetachainShardId {
return process.ErrInvalidShardId
}
err := checkShardData(sd, coordinator)
if err != nil {
return err
}
}
return nil
}
func checkShardData(sd block.ShardData, coordinator sharding.Coordinator) error {
for _, smbh := range sd.ShardMiniBlockHeaders {
isWrongSenderShardId := smbh.SenderShardID >= coordinator.NumberOfShards() &&
smbh.SenderShardID != core.MetachainShardId &&
smbh.SenderShardID != core.AllShardId
isWrongDestinationShardId := smbh.ReceiverShardID >= coordinator.NumberOfShards() &&
smbh.ReceiverShardID != core.MetachainShardId &&
smbh.ReceiverShardID != core.AllShardId
isWrongShardId := isWrongSenderShardId || isWrongDestinationShardId
if isWrongShardId {
return process.ErrInvalidShardId
}
if len(smbh.Reserved) > 0 {
return process.ErrReservedFieldNotSupportedYet
}
}
return nil
}
func checkMiniblocks(miniblocks []block.MiniBlockHeader, coordinator sharding.Coordinator) error {
for _, miniblock := range miniblocks {
isWrongSenderShardId := miniblock.SenderShardID >= coordinator.NumberOfShards() &&
miniblock.SenderShardID != core.MetachainShardId &&
miniblock.SenderShardID != core.AllShardId
isWrongDestinationShardId := miniblock.ReceiverShardID >= coordinator.NumberOfShards() &&
miniblock.ReceiverShardID != core.MetachainShardId &&
miniblock.ReceiverShardID != core.AllShardId
isWrongShardId := isWrongSenderShardId || isWrongDestinationShardId
if isWrongShardId {
return process.ErrInvalidShardId
}
if len(miniblock.Reserved) > 0 {
return process.ErrReservedFieldNotSupportedYet
}
}
return nil
}