/
message.go
435 lines (335 loc) · 13.1 KB
/
message.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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
package protocol //
import (
"crypto/ed25519"
"github.com/smartcontractkit/libocr/commontypes"
"github.com/smartcontractkit/libocr/internal/byzquorum"
"github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types"
"github.com/smartcontractkit/libocr/offchainreporting2plus/types"
)
type EventToPacemaker[RI any] interface {
processPacemaker(pace *pacemakerState[RI])
}
type EventProgress[RI any] struct{}
var _ EventToPacemaker[struct{}] = (*EventProgress[struct{}])(nil) // implements EventToPacemaker
func (ev EventProgress[RI]) processPacemaker(pace *pacemakerState[RI]) {
pace.eventProgress()
}
type EventNewEpochRequest[RI any] struct{}
var _ EventToPacemaker[struct{}] = (*EventNewEpochRequest[struct{}])(nil) // implements EventToPacemaker
func (ev EventNewEpochRequest[RI]) processPacemaker(pace *pacemakerState[RI]) {
pace.eventNewEpochRequest()
}
type EventToOutcomeGeneration[RI any] interface {
processOutcomeGeneration(outgen *outcomeGenerationState[RI])
}
type EventNewEpochStart[RI any] struct {
Epoch uint64
}
var _ EventToOutcomeGeneration[struct{}] = EventNewEpochStart[struct{}]{}
func (ev EventNewEpochStart[RI]) processOutcomeGeneration(outgen *outcomeGenerationState[RI]) {
outgen.eventNewEpochStart(ev)
}
type EventToReportAttestation[RI any] interface {
processReportAttestation(repatt *reportAttestationState[RI])
}
type EventToTransmission[RI any] interface {
processTransmission(t *transmissionState[RI])
}
// Message is the interface used to pass an inter-oracle message to the local
// oracle process.
type Message[RI any] interface {
// CheckSize checks whether the given message conforms to the limits imposed by
// reportingPluginLimits
CheckSize(n int, f int, limits ocr3types.ReportingPluginLimits, maxReportSigLen int) bool
// process passes this Message instance to the oracle o, as a message from
// oracle with the given sender index
process(o *oracleState[RI], sender commontypes.OracleID)
}
// MessageWithSender records a msg with the index of the sender oracle
type MessageWithSender[RI any] struct {
Msg Message[RI]
Sender commontypes.OracleID
}
type MessageToPacemaker[RI any] interface {
Message[RI]
processPacemaker(pace *pacemakerState[RI], sender commontypes.OracleID)
}
type MessageToPacemakerWithSender[RI any] struct {
msg MessageToPacemaker[RI]
sender commontypes.OracleID
}
type MessageToOutcomeGeneration[RI any] interface {
Message[RI]
processOutcomeGeneration(outgen *outcomeGenerationState[RI], sender commontypes.OracleID)
epoch() uint64
}
type MessageToOutcomeGenerationWithSender[RI any] struct {
msg MessageToOutcomeGeneration[RI]
sender commontypes.OracleID
}
type MessageToReportAttestation[RI any] interface {
Message[RI]
processReportAttestation(repatt *reportAttestationState[RI], sender commontypes.OracleID)
}
type MessageToReportAttestationWithSender[RI any] struct {
msg MessageToReportAttestation[RI]
sender commontypes.OracleID
}
type MessageNewEpochWish[RI any] struct {
Epoch uint64
}
var _ MessageToPacemaker[struct{}] = (*MessageNewEpochWish[struct{}])(nil)
func (msg MessageNewEpochWish[RI]) CheckSize(n int, f int, _ ocr3types.ReportingPluginLimits, _ int) bool {
return true
}
func (msg MessageNewEpochWish[RI]) process(o *oracleState[RI], sender commontypes.OracleID) {
o.chNetToPacemaker <- MessageToPacemakerWithSender[RI]{msg, sender}
}
func (msg MessageNewEpochWish[RI]) processPacemaker(pace *pacemakerState[RI], sender commontypes.OracleID) {
pace.messageNewEpochWish(msg, sender)
}
type MessageEpochStartRequest[RI any] struct {
Epoch uint64
HighestCertified CertifiedPrepareOrCommit
SignedHighestCertifiedTimestamp SignedHighestCertifiedTimestamp
}
var _ MessageToOutcomeGeneration[struct{}] = (*MessageEpochStartRequest[struct{}])(nil)
func (msg MessageEpochStartRequest[RI]) CheckSize(n int, f int, limits ocr3types.ReportingPluginLimits, maxReportSigLen int) bool {
if !msg.HighestCertified.CheckSize(n, f, limits, maxReportSigLen) {
return false
}
if len(msg.SignedHighestCertifiedTimestamp.Signature) != ed25519.SignatureSize {
return false
}
return true
}
func (msg MessageEpochStartRequest[RI]) process(o *oracleState[RI], sender commontypes.OracleID) {
o.chNetToOutcomeGeneration <- MessageToOutcomeGenerationWithSender[RI]{
msg,
sender,
}
}
func (msg MessageEpochStartRequest[RI]) processOutcomeGeneration(outgen *outcomeGenerationState[RI], sender commontypes.OracleID) {
outgen.messageEpochStartRequest(msg, sender)
}
func (msg MessageEpochStartRequest[RI]) epoch() uint64 {
return msg.Epoch
}
type MessageEpochStart[RI any] struct {
Epoch uint64
EpochStartProof EpochStartProof
}
var _ MessageToOutcomeGeneration[struct{}] = (*MessageEpochStart[struct{}])(nil)
func (msg MessageEpochStart[RI]) CheckSize(n int, f int, limits ocr3types.ReportingPluginLimits, maxReportSigLen int) bool {
if !msg.EpochStartProof.HighestCertified.CheckSize(n, f, limits, maxReportSigLen) {
return false
}
if len(msg.EpochStartProof.HighestCertifiedProof) != byzquorum.Size(n, f) {
return false
}
for _, ashct := range msg.EpochStartProof.HighestCertifiedProof {
if len(ashct.SignedHighestCertifiedTimestamp.Signature) != ed25519.SignatureSize {
return false
}
}
return true
}
func (msg MessageEpochStart[RI]) process(o *oracleState[RI], sender commontypes.OracleID) {
o.chNetToOutcomeGeneration <- MessageToOutcomeGenerationWithSender[RI]{
msg,
sender,
}
}
func (msg MessageEpochStart[RI]) processOutcomeGeneration(outgen *outcomeGenerationState[RI], sender commontypes.OracleID) {
outgen.messageEpochStart(msg, sender)
}
func (msg MessageEpochStart[RI]) epoch() uint64 {
return msg.Epoch
}
type MessageRoundStart[RI any] struct {
Epoch uint64
SeqNr uint64
Query types.Query
}
var _ MessageToOutcomeGeneration[struct{}] = (*MessageRoundStart[struct{}])(nil)
func (msg MessageRoundStart[RI]) CheckSize(n int, f int, limits ocr3types.ReportingPluginLimits, maxReportSigLen int) bool {
return len(msg.Query) <= limits.MaxQueryLength
}
func (msg MessageRoundStart[RI]) process(o *oracleState[RI], sender commontypes.OracleID) {
o.chNetToOutcomeGeneration <- MessageToOutcomeGenerationWithSender[RI]{
msg,
sender,
}
}
func (msg MessageRoundStart[RI]) processOutcomeGeneration(outgen *outcomeGenerationState[RI], sender commontypes.OracleID) {
outgen.messageRoundStart(msg, sender)
}
func (msg MessageRoundStart[RI]) epoch() uint64 {
return msg.Epoch
}
type MessageObservation[RI any] struct {
Epoch uint64
SeqNr uint64
SignedObservation SignedObservation
}
var _ MessageToOutcomeGeneration[struct{}] = (*MessageObservation[struct{}])(nil)
func (msg MessageObservation[RI]) CheckSize(n int, f int, limits ocr3types.ReportingPluginLimits, maxReportSigLen int) bool {
return len(msg.SignedObservation.Observation) <= limits.MaxObservationLength && len(msg.SignedObservation.Signature) == ed25519.SignatureSize
}
func (msg MessageObservation[RI]) process(o *oracleState[RI], sender commontypes.OracleID) {
o.chNetToOutcomeGeneration <- MessageToOutcomeGenerationWithSender[RI]{
msg,
sender,
}
}
func (msg MessageObservation[RI]) processOutcomeGeneration(outgen *outcomeGenerationState[RI], sender commontypes.OracleID) {
outgen.messageObservation(msg, sender)
}
func (msg MessageObservation[RI]) epoch() uint64 {
return msg.Epoch
}
type MessageProposal[RI any] struct {
Epoch uint64
SeqNr uint64
AttributedSignedObservations []AttributedSignedObservation
}
var _ MessageToOutcomeGeneration[struct{}] = MessageProposal[struct{}]{}
func (msg MessageProposal[RI]) CheckSize(n int, f int, limits ocr3types.ReportingPluginLimits, maxReportSigLen int) bool {
if len(msg.AttributedSignedObservations) > n {
return false
}
for _, aso := range msg.AttributedSignedObservations {
if len(aso.SignedObservation.Observation) > limits.MaxObservationLength {
return false
}
if len(aso.SignedObservation.Signature) != ed25519.SignatureSize {
return false
}
}
return true
}
func (msg MessageProposal[RI]) process(o *oracleState[RI], sender commontypes.OracleID) {
o.chNetToOutcomeGeneration <- MessageToOutcomeGenerationWithSender[RI]{
msg,
sender,
}
}
func (msg MessageProposal[RI]) processOutcomeGeneration(outgen *outcomeGenerationState[RI], sender commontypes.OracleID) {
outgen.messageProposal(msg, sender)
}
func (msg MessageProposal[RI]) epoch() uint64 {
return msg.Epoch
}
type MessagePrepare[RI any] struct {
Epoch uint64
SeqNr uint64
Signature PrepareSignature
}
var _ MessageToOutcomeGeneration[struct{}] = MessagePrepare[struct{}]{}
func (msg MessagePrepare[RI]) CheckSize(n int, f int, limits ocr3types.ReportingPluginLimits, maxReportSigLen int) bool {
return len(msg.Signature) == ed25519.SignatureSize
}
func (msg MessagePrepare[RI]) process(o *oracleState[RI], sender commontypes.OracleID) {
o.chNetToOutcomeGeneration <- MessageToOutcomeGenerationWithSender[RI]{
msg,
sender,
}
}
func (msg MessagePrepare[RI]) processOutcomeGeneration(outgen *outcomeGenerationState[RI], sender commontypes.OracleID) {
outgen.messagePrepare(msg, sender)
}
func (msg MessagePrepare[RI]) epoch() uint64 {
return msg.Epoch
}
type MessageCommit[RI any] struct {
Epoch uint64
SeqNr uint64
Signature CommitSignature
}
var _ MessageToOutcomeGeneration[struct{}] = MessageCommit[struct{}]{}
func (msg MessageCommit[RI]) CheckSize(n int, f int, limits ocr3types.ReportingPluginLimits, maxReportSigLen int) bool {
return len(msg.Signature) == ed25519.SignatureSize
}
func (msg MessageCommit[RI]) process(o *oracleState[RI], sender commontypes.OracleID) {
o.chNetToOutcomeGeneration <- MessageToOutcomeGenerationWithSender[RI]{
msg,
sender,
}
}
func (msg MessageCommit[RI]) processOutcomeGeneration(outgen *outcomeGenerationState[RI], sender commontypes.OracleID) {
outgen.messageCommit(msg, sender)
}
func (msg MessageCommit[RI]) epoch() uint64 {
return msg.Epoch
}
type MessageReportSignatures[RI any] struct {
SeqNr uint64
ReportSignatures [][]byte
}
var _ MessageToReportAttestation[struct{}] = MessageReportSignatures[struct{}]{}
func (msg MessageReportSignatures[RI]) CheckSize(n int, f int, limits ocr3types.ReportingPluginLimits, maxReportSigLen int) bool {
if len(msg.ReportSignatures) > limits.MaxReportCount {
return false
}
for _, sig := range msg.ReportSignatures {
if len(sig) > maxReportSigLen {
return false
}
}
return true
}
func (msg MessageReportSignatures[RI]) process(o *oracleState[RI], sender commontypes.OracleID) {
o.chNetToReportAttestation <- MessageToReportAttestationWithSender[RI]{msg, sender}
}
func (msg MessageReportSignatures[RI]) processReportAttestation(repatt *reportAttestationState[RI], sender commontypes.OracleID) {
repatt.messageReportSignatures(msg, sender)
}
type MessageCertifiedCommitRequest[RI any] struct {
SeqNr uint64
}
var _ MessageToReportAttestation[struct{}] = MessageCertifiedCommitRequest[struct{}]{}
func (msg MessageCertifiedCommitRequest[RI]) CheckSize(n int, f int, _ ocr3types.ReportingPluginLimits, maxReportSigLen int) bool {
return true
}
func (msg MessageCertifiedCommitRequest[RI]) process(o *oracleState[RI], sender commontypes.OracleID) {
o.chNetToReportAttestation <- MessageToReportAttestationWithSender[RI]{msg, sender}
}
func (msg MessageCertifiedCommitRequest[RI]) processReportAttestation(repatt *reportAttestationState[RI], sender commontypes.OracleID) {
repatt.messageCertifiedCommitRequest(msg, sender)
}
type MessageCertifiedCommit[RI any] struct {
CertifiedCommit CertifiedCommit
}
var _ MessageToReportAttestation[struct{}] = MessageCertifiedCommit[struct{}]{}
func (msg MessageCertifiedCommit[RI]) CheckSize(n int, f int, limits ocr3types.ReportingPluginLimits, maxReportSigLen int) bool {
return msg.CertifiedCommit.CheckSize(n, f, limits, maxReportSigLen)
}
func (msg MessageCertifiedCommit[RI]) process(o *oracleState[RI], sender commontypes.OracleID) {
o.chNetToReportAttestation <- MessageToReportAttestationWithSender[RI]{msg, sender}
}
func (msg MessageCertifiedCommit[RI]) processReportAttestation(repatt *reportAttestationState[RI], sender commontypes.OracleID) {
repatt.messageCertifiedCommit(msg, sender)
}
type EventMissingOutcome[RI any] struct {
SeqNr uint64
}
var _ EventToReportAttestation[struct{}] = EventMissingOutcome[struct{}]{} // implements EventToReportAttestation
func (ev EventMissingOutcome[RI]) processReportAttestation(repatt *reportAttestationState[RI]) {
repatt.eventMissingOutcome(ev)
}
type EventCommittedOutcome[RI any] struct {
CertifiedCommit CertifiedCommit
}
var _ EventToReportAttestation[struct{}] = EventCommittedOutcome[struct{}]{} // implements EventToReportAttestation
func (ev EventCommittedOutcome[RI]) processReportAttestation(repatt *reportAttestationState[RI]) {
repatt.eventCommittedOutcome(ev)
}
type EventAttestedReport[RI any] struct {
SeqNr uint64
Index int
AttestedReport AttestedReportMany[RI]
}
var _ EventToTransmission[struct{}] = EventAttestedReport[struct{}]{} // implements EventToTransmission
func (ev EventAttestedReport[RI]) processTransmission(t *transmissionState[RI]) {
t.eventAttestedReport(ev)
}