Skip to content

Commit 0a5e2f9

Browse files
authored
Merge pull request #128 from smartcontractkit/copy-c5c6c7271a7e85046308ac586c68e3d8a4d1bf5a
Improvements:
2 parents 7324c20 + ee30a6c commit 0a5e2f9

29 files changed

+2206
-692
lines changed

internal/singlewriter/overlay_transaction.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ func (oi *overlayIterator) advanceBase() {
108108
}
109109

110110
oi.baseNext = true
111+
111112
oi.baseKey = bytes.Clone(k)
112113
}
113114

offchainreporting2plus/internal/config/ocr3_1config/metrics.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ type PublicConfigMetrics struct {
5757
maxDurationShouldAcceptAttestedReport prometheus.Gauge
5858
maxDurationShouldTransmitAcceptedReport prometheus.Gauge
5959

60+
prevSeqNr prometheus.Gauge
61+
6062
n prometheus.Gauge
6163
f prometheus.Gauge
6264

@@ -319,6 +321,17 @@ func NewPublicConfigMetrics(
319321
maxDurationShouldTransmitAcceptedReport.Set(publicConfig.MaxDurationShouldTransmitAcceptedReport.Seconds())
320322
metricshelper.RegisterOrLogError(logger, registerer, maxDurationShouldTransmitAcceptedReport, "ocr3_1_config_max_duration_should_transmit_accepted_report_seconds")
321323

324+
prevSeqNr := prometheus.NewGauge(prometheus.GaugeOpts{
325+
Name: "ocr3_1_config_prev_seq_nr",
326+
Help: "See https://pkg.go.dev/github.com/smartcontractkit/libocr/offchainreporting2plus/internal/config/ocr3_1config#PublicConfig for details",
327+
})
328+
if publicConfig.PrevSeqNr != nil {
329+
prevSeqNr.Set(float64(*publicConfig.PrevSeqNr))
330+
} else {
331+
prevSeqNr.Set(0)
332+
}
333+
metricshelper.RegisterOrLogError(logger, registerer, prevSeqNr, "ocr3_1_config_prev_seq_nr")
334+
322335
n := prometheus.NewGauge(prometheus.GaugeOpts{
323336
Name: "ocr3_1_config_n",
324337
Help: "The number of oracles participating in this protocol instance",
@@ -391,6 +404,8 @@ func NewPublicConfigMetrics(
391404
maxDurationShouldAcceptAttestedReport,
392405
maxDurationShouldTransmitAcceptedReport,
393406

407+
prevSeqNr,
408+
394409
n,
395410
f,
396411
minRoundInterval,
@@ -446,6 +461,8 @@ func (pm *PublicConfigMetrics) Close() {
446461
pm.registerer.Unregister(pm.maxDurationShouldAcceptAttestedReport)
447462
pm.registerer.Unregister(pm.maxDurationShouldTransmitAcceptedReport)
448463

464+
pm.registerer.Unregister(pm.prevSeqNr)
465+
449466
pm.registerer.Unregister(pm.n)
450467
pm.registerer.Unregister(pm.f)
451468
pm.registerer.Unregister(pm.minRoundInterval)

offchainreporting2plus/internal/config/ocr3_1config/offchainreporting3_1_offchain_config.pb.go

Lines changed: 116 additions & 80 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

offchainreporting2plus/internal/config/ocr3_1config/public_config.go

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,47 @@ type PublicConfig struct {
190190
MaxDurationShouldAcceptAttestedReport time.Duration // Context deadline passed to ShouldAcceptAttestedReport.
191191
MaxDurationShouldTransmitAcceptedReport time.Duration // Context deadline passed to ShouldTransmitAcceptedReport.
192192

193+
// PrevConfigDigest is the config digest of the previous instance that this
194+
// next instance is a continuation of. The previous instance must overlap in
195+
// at least one oracle with the next instance, though larger overlaps are
196+
// highly encouraged and will improve the initial synchronization
197+
// performance.
198+
//
199+
// WARNING! This is an advanced feature and should only be used if you
200+
// *really* know what you are doing. Failure to set this or any of the other
201+
// Prev fields correctly will result in the instance not making any
202+
// progress or data loss.
203+
PrevConfigDigest *types.ConfigDigest
204+
// PrevSeqNr is the sequence number of the previous instance that this next
205+
// instance will continue from. Sequence numbers in the next instance will
206+
// continue from PrevSeqNr. This must be a snapshot sequence number for the
207+
// previous instance, i.e., PrevSeqNr % PrevInstanceConfig.SnapshotInterval
208+
// == 0. The overlapping oracle must have locally committed the state as of
209+
// PrevSeqNr and the snapshot associated with PrevSeqNr must be in the
210+
// retention window implied by
211+
// PrevInstanceConfig.MaxHistoricalSnapshotsRetained and
212+
// PrevInstanceConfig.SnapshotInterval. (For instances whose previous
213+
// instance already has a PrevSeqNr, this imples PrevSeqNr >
214+
// PrevInstanceConfig.PrevSeqNr.)
215+
//
216+
// Be aware that any state transitions committed after PrevSeqNr in the
217+
// previous instance will not be available in the next instance (and
218+
// typically be lost forever).
219+
//
220+
// WARNING! This is an advanced feature and should only be used if you
221+
// *really* know what you are doing. Failure to set this or any of the other
222+
// Prev fields correctly will result in the instance not making any
223+
// progress or data loss.
224+
PrevSeqNr *uint64
225+
// PrevHistoryDigest is the history digest of the previous instance at
226+
// PrevSeqNr.
227+
//
228+
// WARNING! This is an advanced feature and should only be used if you
229+
// *really* know what you are doing. Failure to set this or any of the other
230+
// Prev fields correctly will result in the instance not making any
231+
// progress or data loss.
232+
PrevHistoryDigest *types.HistoryDigest
233+
193234
// The maximum number of oracles that are assumed to be faulty while the
194235
// protocol can retain liveness and safety. Unless you really know what
195236
// you’re doing, be sure to set this to floor((n-1)/3) where n is the total
@@ -297,6 +338,23 @@ func (c *PublicConfig) GetBlobChunkBytes() int {
297338
return util.NilCoalesce(c.BlobChunkBytes, DefaultBlobChunkBytes)
298339
}
299340

341+
type PublicConfigPrevFields struct {
342+
PrevConfigDigest types.ConfigDigest
343+
PrevSeqNr uint64
344+
PrevHistoryDigest types.HistoryDigest
345+
}
346+
347+
func (c *PublicConfig) GetPrevFields() (PublicConfigPrevFields, bool) {
348+
if c.PrevConfigDigest == nil || c.PrevSeqNr == nil || c.PrevHistoryDigest == nil {
349+
return PublicConfigPrevFields{}, false
350+
}
351+
return PublicConfigPrevFields{
352+
*c.PrevConfigDigest,
353+
*c.PrevSeqNr,
354+
*c.PrevHistoryDigest,
355+
}, true
356+
}
357+
300358
// The minimum interval between round starts.
301359
// This is not a guaranteed lower bound. For example, a malicious leader could
302360
// violate this bound.
@@ -400,6 +458,10 @@ func publicConfigFromContractConfig(skipInsaneForProductionChecks bool, change t
400458
oc.MaxDurationShouldAcceptAttestedReport,
401459
oc.MaxDurationShouldTransmitAcceptedReport,
402460

461+
oc.PrevConfigDigest,
462+
oc.PrevSeqNr,
463+
oc.PrevHistoryDigest,
464+
403465
int(change.F),
404466
change.OnchainConfig,
405467
change.ConfigDigest,
@@ -554,6 +616,13 @@ func checkPublicConfigParameters(cfg PublicConfig) error {
554616
// be made when you change this function!
555617
/////////////////////////////////////////////////////////////////
556618

619+
if !((cfg.PrevConfigDigest == nil) == (cfg.PrevSeqNr == nil) && (cfg.PrevSeqNr == nil) == (cfg.PrevHistoryDigest == nil)) {
620+
return fmt.Errorf("PrevConfigDigest, PrevSeqNr, and PrevHistoryDigest must all be set or all be nil")
621+
}
622+
if cfg.PrevSeqNr != nil && !(0 < *cfg.PrevSeqNr) {
623+
return fmt.Errorf("PrevSeqNr (%v) must be positive if non-nil", *cfg.PrevSeqNr)
624+
}
625+
557626
if !(0 <= cfg.F && cfg.F*3 < cfg.N()) {
558627
return fmt.Errorf("F (%v) must be non-negative and less than N/3 (N = %v)",
559628
cfg.F, cfg.N())

offchainreporting2plus/internal/config/ocr3_1config/serialize.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ type offchainConfig struct {
7070
WarnDurationCommitted time.Duration
7171
MaxDurationShouldAcceptAttestedReport time.Duration
7272
MaxDurationShouldTransmitAcceptedReport time.Duration
73+
PrevConfigDigest *types.ConfigDigest
74+
PrevSeqNr *uint64
75+
PrevHistoryDigest *types.HistoryDigest
7376
SharedSecretEncryptions config.SharedSecretEncryptions
7477
}
7578

@@ -135,6 +138,24 @@ func deprotoOffchainConfig(
135138
return offchainConfig{}, fmt.Errorf("could not unmarshal shared protobuf: %w", err)
136139
}
137140

141+
var prevConfigDigest *types.ConfigDigest
142+
if len(offchainConfigProto.PrevConfigDigest) != 0 {
143+
d, err := types.BytesToConfigDigest(offchainConfigProto.PrevConfigDigest)
144+
if err != nil {
145+
return offchainConfig{}, fmt.Errorf("invalid PrevConfigDigest: %w", err)
146+
}
147+
prevConfigDigest = &d
148+
}
149+
150+
var prevHistoryDigest *types.HistoryDigest
151+
if len(offchainConfigProto.PrevHistoryDigest) != 0 {
152+
d, err := types.BytesToHistoryDigest(offchainConfigProto.PrevHistoryDigest)
153+
if err != nil {
154+
return offchainConfig{}, fmt.Errorf("invalid PrevHistoryDigest: %w", err)
155+
}
156+
prevHistoryDigest = &d
157+
}
158+
138159
return offchainConfig{
139160
time.Duration(offchainConfigProto.GetDeltaProgressNanoseconds()),
140161
util.PointerIntegerCast[time.Duration](offchainConfigProto.DeltaResendNanoseconds),
@@ -186,6 +207,9 @@ func deprotoOffchainConfig(
186207
time.Duration(offchainConfigProto.GetWarnDurationCommittedNanoseconds()),
187208
time.Duration(offchainConfigProto.GetMaxDurationShouldAcceptAttestedReportNanoseconds()),
188209
time.Duration(offchainConfigProto.GetMaxDurationShouldTransmitAcceptedReportNanoseconds()),
210+
prevConfigDigest,
211+
offchainConfigProto.PrevSeqNr,
212+
prevHistoryDigest,
189213
sharedSecretEncryptions,
190214
}, nil
191215
}
@@ -230,6 +254,16 @@ func enprotoOffchainConfig(o offchainConfig) OffchainConfigProto {
230254
offchainPublicKeys = append(offchainPublicKeys, k[:])
231255
}
232256
sharedSecretEncryptions := enprotoSharedSecretEncryptions(o.SharedSecretEncryptions)
257+
258+
var prevConfigDigestBytes []byte
259+
if o.PrevConfigDigest != nil {
260+
prevConfigDigestBytes = o.PrevConfigDigest[:]
261+
}
262+
var prevHistoryDigestBytes []byte
263+
if o.PrevHistoryDigest != nil {
264+
prevHistoryDigestBytes = o.PrevHistoryDigest[:]
265+
}
266+
233267
return OffchainConfigProto{
234268
// zero-initialize protobuf built-ins
235269
protoimpl.MessageState{},
@@ -275,6 +309,9 @@ func enprotoOffchainConfig(o offchainConfig) OffchainConfigProto {
275309
uint64(o.WarnDurationCommitted),
276310
uint64(o.MaxDurationShouldAcceptAttestedReport),
277311
uint64(o.MaxDurationShouldTransmitAcceptedReport),
312+
prevConfigDigestBytes,
313+
o.PrevSeqNr,
314+
prevHistoryDigestBytes,
278315
&sharedSecretEncryptions,
279316
}
280317
}

offchainreporting2plus/internal/config/ocr3_1config/shared_config.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,9 @@ func ContractSetConfigArgsFromSharedConfigDeterministic(
186186
c.WarnDurationCommitted,
187187
c.MaxDurationShouldAcceptAttestedReport,
188188
c.MaxDurationShouldTransmitAcceptedReport,
189+
c.PrevConfigDigest,
190+
c.PrevSeqNr,
191+
c.PrevHistoryDigest,
189192
sharedSecretEncryptions,
190193
}).serialize()
191194
return signers, transmitters, uint8(c.F), c.OnchainConfig, config.OCR3_1OffchainConfigVersion, offchainConfig_, nil

0 commit comments

Comments
 (0)