-
Notifications
You must be signed in to change notification settings - Fork 20
/
post_quorum.go
178 lines (169 loc) · 9.4 KB
/
post_quorum.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package postconsensus
import (
"fmt"
"github.com/attestantio/go-eth2-client/spec"
"github.com/bloxapp/ssv-spec/qbft"
"github.com/bloxapp/ssv-spec/ssv/spectest/tests"
"github.com/bloxapp/ssv-spec/types"
"github.com/bloxapp/ssv-spec/types/testingutils"
)
// PostQuorum tests a msg received post post-consensus quorum
func PostQuorum() tests.SpecTest {
ks := testingutils.Testing4SharesSet()
expectedErr := "failed processing post consensus message: invalid post-consensus message: no running duty"
multiSpecTest := &tests.MultiMsgProcessingSpecTest{
Name: "post consensus post quorum",
Tests: []*tests.MsgProcessingSpecTest{
{
Name: "sync committee contribution",
Runner: decideRunner(
testingutils.SyncCommitteeContributionRunner(ks),
&testingutils.TestingSyncCommitteeContributionDuty,
testingutils.TestSyncCommitteeContributionConsensusData,
),
Duty: &testingutils.TestingSyncCommitteeContributionDuty,
Messages: []*types.SignedSSVMessage{
testingutils.SignedSSVMessageF(ks, testingutils.SSVMsgSyncCommitteeContribution(nil, testingutils.PostConsensusSyncCommitteeContributionMsg(ks.Shares[1], 1, ks))),
testingutils.SignedSSVMessageF(ks, testingutils.SSVMsgSyncCommitteeContribution(nil, testingutils.PostConsensusSyncCommitteeContributionMsg(ks.Shares[2], 2, ks))),
testingutils.SignedSSVMessageF(ks, testingutils.SSVMsgSyncCommitteeContribution(nil, testingutils.PostConsensusSyncCommitteeContributionMsg(ks.Shares[3], 3, ks))),
testingutils.SignedSSVMessageF(ks, testingutils.SSVMsgSyncCommitteeContribution(nil, testingutils.PostConsensusSyncCommitteeContributionMsg(ks.Shares[4], 4, ks))),
},
PostDutyRunnerStateRoot: postQuorumSyncCommitteeContributionSC().Root(),
PostDutyRunnerState: postQuorumSyncCommitteeContributionSC().ExpectedState,
OutputMessages: []*types.SignedPartialSignatureMessage{},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingSignedSyncCommitteeContributions(testingutils.TestingSyncCommitteeContributions[0], testingutils.TestingContributionProofsSigned[0], ks)),
testingutils.GetSSZRootNoError(testingutils.TestingSignedSyncCommitteeContributions(testingutils.TestingSyncCommitteeContributions[1], testingutils.TestingContributionProofsSigned[1], ks)),
testingutils.GetSSZRootNoError(testingutils.TestingSignedSyncCommitteeContributions(testingutils.TestingSyncCommitteeContributions[2], testingutils.TestingContributionProofsSigned[2], ks)),
},
DontStartDuty: true,
ExpectedError: expectedErr,
},
{
Name: "sync committee",
Runner: decideRunner(
testingutils.SyncCommitteeRunner(ks),
&testingutils.TestingSyncCommitteeDuty,
testingutils.TestSyncCommitteeConsensusData,
),
Duty: &testingutils.TestingSyncCommitteeDuty,
Messages: []*types.SignedSSVMessage{
testingutils.SignedSSVMessageF(ks, testingutils.SSVMsgSyncCommittee(nil, testingutils.PostConsensusSyncCommitteeMsg(ks.Shares[1], 1))),
testingutils.SignedSSVMessageF(ks, testingutils.SSVMsgSyncCommittee(nil, testingutils.PostConsensusSyncCommitteeMsg(ks.Shares[2], 2))),
testingutils.SignedSSVMessageF(ks, testingutils.SSVMsgSyncCommittee(nil, testingutils.PostConsensusSyncCommitteeMsg(ks.Shares[3], 3))),
testingutils.SignedSSVMessageF(ks, testingutils.SSVMsgSyncCommittee(nil, testingutils.PostConsensusSyncCommitteeMsg(ks.Shares[4], 4))),
},
PostDutyRunnerStateRoot: postQuorumSyncCommitteeSC().Root(),
PostDutyRunnerState: postQuorumSyncCommitteeSC().ExpectedState,
OutputMessages: []*types.SignedPartialSignatureMessage{},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingSignedSyncCommitteeBlockRoot(ks)),
},
DontStartDuty: true,
ExpectedError: expectedErr,
},
{
Name: "aggregator",
Runner: decideRunner(
testingutils.AggregatorRunner(ks),
&testingutils.TestingAggregatorDuty,
testingutils.TestAggregatorConsensusData,
),
Duty: &testingutils.TestingAggregatorDuty,
Messages: []*types.SignedSSVMessage{
testingutils.SignedSSVMessageF(ks, testingutils.SSVMsgAggregator(nil, testingutils.PostConsensusAggregatorMsg(ks.Shares[1], 1))),
testingutils.SignedSSVMessageF(ks, testingutils.SSVMsgAggregator(nil, testingutils.PostConsensusAggregatorMsg(ks.Shares[2], 2))),
testingutils.SignedSSVMessageF(ks, testingutils.SSVMsgAggregator(nil, testingutils.PostConsensusAggregatorMsg(ks.Shares[3], 3))),
testingutils.SignedSSVMessageF(ks, testingutils.SSVMsgAggregator(nil, testingutils.PostConsensusAggregatorMsg(ks.Shares[4], 4))),
},
PostDutyRunnerStateRoot: postQuorumAggregatorSC().Root(),
PostDutyRunnerState: postQuorumAggregatorSC().ExpectedState,
OutputMessages: []*types.SignedPartialSignatureMessage{},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingSignedAggregateAndProof(ks)),
},
DontStartDuty: true,
ExpectedError: expectedErr,
},
{
Name: "attester",
Runner: decideRunner(
testingutils.AttesterRunner(ks),
&testingutils.TestingAttesterDuty,
testingutils.TestAttesterConsensusData,
),
Duty: &testingutils.TestingAttesterDuty,
Messages: []*types.SignedSSVMessage{
testingutils.SignedSSVMessageF(ks, testingutils.SSVMsgAttester(nil, testingutils.PostConsensusAttestationMsg(ks.Shares[1], 1, qbft.FirstHeight))),
testingutils.SignedSSVMessageF(ks, testingutils.SSVMsgAttester(nil, testingutils.PostConsensusAttestationMsg(ks.Shares[2], 2, qbft.FirstHeight))),
testingutils.SignedSSVMessageF(ks, testingutils.SSVMsgAttester(nil, testingutils.PostConsensusAttestationMsg(ks.Shares[3], 3, qbft.FirstHeight))),
testingutils.SignedSSVMessageF(ks, testingutils.SSVMsgAttester(nil, testingutils.PostConsensusAttestationMsg(ks.Shares[4], 4, qbft.FirstHeight))),
},
PostDutyRunnerStateRoot: postQuorumAttesterSC().Root(),
PostDutyRunnerState: postQuorumAttesterSC().ExpectedState,
OutputMessages: []*types.SignedPartialSignatureMessage{},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingSignedAttestation(ks)),
},
DontStartDuty: true,
ExpectedError: expectedErr,
},
},
}
// proposerV creates a test specification for versioned proposer.
proposerV := func(version spec.DataVersion) *tests.MsgProcessingSpecTest {
return &tests.MsgProcessingSpecTest{
Name: fmt.Sprintf("proposer (%s)", version.String()),
Runner: decideRunner(
testingutils.ProposerRunner(ks),
testingutils.TestingProposerDutyV(version),
testingutils.TestProposerConsensusDataV(version),
),
Duty: testingutils.TestingProposerDutyV(version),
Messages: []*types.SignedSSVMessage{
testingutils.SignedSSVMessageF(ks, testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsgV(ks.Shares[1], 1, version))),
testingutils.SignedSSVMessageF(ks, testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsgV(ks.Shares[2], 2, version))),
testingutils.SignedSSVMessageF(ks, testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsgV(ks.Shares[3], 3, version))),
testingutils.SignedSSVMessageF(ks, testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsgV(ks.Shares[4], 4, version))),
},
PostDutyRunnerStateRoot: postQuorumProposerSC(version).Root(),
PostDutyRunnerState: postQuorumProposerSC(version).ExpectedState,
OutputMessages: []*types.SignedPartialSignatureMessage{},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingSignedBeaconBlockV(ks, version)),
},
DontStartDuty: true,
ExpectedError: expectedErr,
}
}
// proposerBlindedV creates a test specification for versioned proposer with blinded block.
proposerBlindedV := func(version spec.DataVersion) *tests.MsgProcessingSpecTest {
return &tests.MsgProcessingSpecTest{
Name: fmt.Sprintf("proposer blinded block (%s)", version.String()),
Runner: decideRunner(
testingutils.ProposerBlindedBlockRunner(ks),
testingutils.TestingProposerDutyV(version),
testingutils.TestProposerBlindedBlockConsensusDataV(version),
),
Duty: testingutils.TestingProposerDutyV(version),
Messages: []*types.SignedSSVMessage{
testingutils.SignedSSVMessageF(ks, testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsgV(ks.Shares[1], 1, version))),
testingutils.SignedSSVMessageF(ks, testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsgV(ks.Shares[2], 2, version))),
testingutils.SignedSSVMessageF(ks, testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsgV(ks.Shares[3], 3, version))),
testingutils.SignedSSVMessageF(ks, testingutils.SSVMsgProposer(nil, testingutils.PostConsensusProposerMsgV(ks.Shares[4], 4, version))),
},
PostDutyRunnerStateRoot: postQuorumBlindedProposerSC(version).Root(),
PostDutyRunnerState: postQuorumBlindedProposerSC(version).ExpectedState,
OutputMessages: []*types.SignedPartialSignatureMessage{},
BeaconBroadcastedRoots: []string{
testingutils.GetSSZRootNoError(testingutils.TestingSignedBlindedBeaconBlockV(ks, version)),
},
DontStartDuty: true,
ExpectedError: expectedErr,
}
}
for _, v := range testingutils.SupportedBlockVersions {
multiSpecTest.Tests = append(multiSpecTest.Tests, []*tests.MsgProcessingSpecTest{proposerV(v), proposerBlindedV(v)}...)
}
return multiSpecTest
}