Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions internal/singlewriter/overlay_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func (oi *overlayIterator) advanceBase() {
}

oi.baseNext = true

oi.baseKey = bytes.Clone(k)
}

Expand Down
17 changes: 17 additions & 0 deletions offchainreporting2plus/internal/config/ocr3_1config/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ type PublicConfigMetrics struct {
maxDurationShouldAcceptAttestedReport prometheus.Gauge
maxDurationShouldTransmitAcceptedReport prometheus.Gauge

prevSeqNr prometheus.Gauge

n prometheus.Gauge
f prometheus.Gauge

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

prevSeqNr := prometheus.NewGauge(prometheus.GaugeOpts{
Name: "ocr3_1_config_prev_seq_nr",
Help: "See https://pkg.go.dev/github.com/smartcontractkit/libocr/offchainreporting2plus/internal/config/ocr3_1config#PublicConfig for details",
})
if publicConfig.PrevSeqNr != nil {
prevSeqNr.Set(float64(*publicConfig.PrevSeqNr))
} else {
prevSeqNr.Set(0)
}
metricshelper.RegisterOrLogError(logger, registerer, prevSeqNr, "ocr3_1_config_prev_seq_nr")

n := prometheus.NewGauge(prometheus.GaugeOpts{
Name: "ocr3_1_config_n",
Help: "The number of oracles participating in this protocol instance",
Expand Down Expand Up @@ -391,6 +404,8 @@ func NewPublicConfigMetrics(
maxDurationShouldAcceptAttestedReport,
maxDurationShouldTransmitAcceptedReport,

prevSeqNr,

n,
f,
minRoundInterval,
Expand Down Expand Up @@ -446,6 +461,8 @@ func (pm *PublicConfigMetrics) Close() {
pm.registerer.Unregister(pm.maxDurationShouldAcceptAttestedReport)
pm.registerer.Unregister(pm.maxDurationShouldTransmitAcceptedReport)

pm.registerer.Unregister(pm.prevSeqNr)

pm.registerer.Unregister(pm.n)
pm.registerer.Unregister(pm.f)
pm.registerer.Unregister(pm.minRoundInterval)
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,47 @@ type PublicConfig struct {
MaxDurationShouldAcceptAttestedReport time.Duration // Context deadline passed to ShouldAcceptAttestedReport.
MaxDurationShouldTransmitAcceptedReport time.Duration // Context deadline passed to ShouldTransmitAcceptedReport.

// PrevConfigDigest is the config digest of the previous instance that this
// next instance is a continuation of. The previous instance must overlap in
// at least one oracle with the next instance, though larger overlaps are
// highly encouraged and will improve the initial synchronization
// performance.
//
// WARNING! This is an advanced feature and should only be used if you
// *really* know what you are doing. Failure to set this or any of the other
// Prev fields correctly will result in the instance not making any
// progress or data loss.
PrevConfigDigest *types.ConfigDigest
// PrevSeqNr is the sequence number of the previous instance that this next
// instance will continue from. Sequence numbers in the next instance will
// continue from PrevSeqNr. This must be a snapshot sequence number for the
// previous instance, i.e., PrevSeqNr % PrevInstanceConfig.SnapshotInterval
// == 0. The overlapping oracle must have locally committed the state as of
// PrevSeqNr and the snapshot associated with PrevSeqNr must be in the
// retention window implied by
// PrevInstanceConfig.MaxHistoricalSnapshotsRetained and
// PrevInstanceConfig.SnapshotInterval. (For instances whose previous
// instance already has a PrevSeqNr, this imples PrevSeqNr >
// PrevInstanceConfig.PrevSeqNr.)
//
// Be aware that any state transitions committed after PrevSeqNr in the
// previous instance will not be available in the next instance (and
// typically be lost forever).
//
// WARNING! This is an advanced feature and should only be used if you
// *really* know what you are doing. Failure to set this or any of the other
// Prev fields correctly will result in the instance not making any
// progress or data loss.
PrevSeqNr *uint64
// PrevHistoryDigest is the history digest of the previous instance at
// PrevSeqNr.
//
// WARNING! This is an advanced feature and should only be used if you
// *really* know what you are doing. Failure to set this or any of the other
// Prev fields correctly will result in the instance not making any
// progress or data loss.
PrevHistoryDigest *types.HistoryDigest

// The maximum number of oracles that are assumed to be faulty while the
// protocol can retain liveness and safety. Unless you really know what
// you’re doing, be sure to set this to floor((n-1)/3) where n is the total
Expand Down Expand Up @@ -297,6 +338,23 @@ func (c *PublicConfig) GetBlobChunkBytes() int {
return util.NilCoalesce(c.BlobChunkBytes, DefaultBlobChunkBytes)
}

type PublicConfigPrevFields struct {
PrevConfigDigest types.ConfigDigest
PrevSeqNr uint64
PrevHistoryDigest types.HistoryDigest
}

func (c *PublicConfig) GetPrevFields() (PublicConfigPrevFields, bool) {
if c.PrevConfigDigest == nil || c.PrevSeqNr == nil || c.PrevHistoryDigest == nil {
return PublicConfigPrevFields{}, false
}
return PublicConfigPrevFields{
*c.PrevConfigDigest,
*c.PrevSeqNr,
*c.PrevHistoryDigest,
}, true
}

// The minimum interval between round starts.
// This is not a guaranteed lower bound. For example, a malicious leader could
// violate this bound.
Expand Down Expand Up @@ -400,6 +458,10 @@ func publicConfigFromContractConfig(skipInsaneForProductionChecks bool, change t
oc.MaxDurationShouldAcceptAttestedReport,
oc.MaxDurationShouldTransmitAcceptedReport,

oc.PrevConfigDigest,
oc.PrevSeqNr,
oc.PrevHistoryDigest,

int(change.F),
change.OnchainConfig,
change.ConfigDigest,
Expand Down Expand Up @@ -554,6 +616,13 @@ func checkPublicConfigParameters(cfg PublicConfig) error {
// be made when you change this function!
/////////////////////////////////////////////////////////////////

if !((cfg.PrevConfigDigest == nil) == (cfg.PrevSeqNr == nil) && (cfg.PrevSeqNr == nil) == (cfg.PrevHistoryDigest == nil)) {
return fmt.Errorf("PrevConfigDigest, PrevSeqNr, and PrevHistoryDigest must all be set or all be nil")
}
if cfg.PrevSeqNr != nil && !(0 < *cfg.PrevSeqNr) {
return fmt.Errorf("PrevSeqNr (%v) must be positive if non-nil", *cfg.PrevSeqNr)
}

if !(0 <= cfg.F && cfg.F*3 < cfg.N()) {
return fmt.Errorf("F (%v) must be non-negative and less than N/3 (N = %v)",
cfg.F, cfg.N())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ type offchainConfig struct {
WarnDurationCommitted time.Duration
MaxDurationShouldAcceptAttestedReport time.Duration
MaxDurationShouldTransmitAcceptedReport time.Duration
PrevConfigDigest *types.ConfigDigest
PrevSeqNr *uint64
PrevHistoryDigest *types.HistoryDigest
SharedSecretEncryptions config.SharedSecretEncryptions
}

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

var prevConfigDigest *types.ConfigDigest
if len(offchainConfigProto.PrevConfigDigest) != 0 {
d, err := types.BytesToConfigDigest(offchainConfigProto.PrevConfigDigest)
if err != nil {
return offchainConfig{}, fmt.Errorf("invalid PrevConfigDigest: %w", err)
}
prevConfigDigest = &d
}

var prevHistoryDigest *types.HistoryDigest
if len(offchainConfigProto.PrevHistoryDigest) != 0 {
d, err := types.BytesToHistoryDigest(offchainConfigProto.PrevHistoryDigest)
if err != nil {
return offchainConfig{}, fmt.Errorf("invalid PrevHistoryDigest: %w", err)
}
prevHistoryDigest = &d
}

return offchainConfig{
time.Duration(offchainConfigProto.GetDeltaProgressNanoseconds()),
util.PointerIntegerCast[time.Duration](offchainConfigProto.DeltaResendNanoseconds),
Expand Down Expand Up @@ -186,6 +207,9 @@ func deprotoOffchainConfig(
time.Duration(offchainConfigProto.GetWarnDurationCommittedNanoseconds()),
time.Duration(offchainConfigProto.GetMaxDurationShouldAcceptAttestedReportNanoseconds()),
time.Duration(offchainConfigProto.GetMaxDurationShouldTransmitAcceptedReportNanoseconds()),
prevConfigDigest,
offchainConfigProto.PrevSeqNr,
prevHistoryDigest,
sharedSecretEncryptions,
}, nil
}
Expand Down Expand Up @@ -230,6 +254,16 @@ func enprotoOffchainConfig(o offchainConfig) OffchainConfigProto {
offchainPublicKeys = append(offchainPublicKeys, k[:])
}
sharedSecretEncryptions := enprotoSharedSecretEncryptions(o.SharedSecretEncryptions)

var prevConfigDigestBytes []byte
if o.PrevConfigDigest != nil {
prevConfigDigestBytes = o.PrevConfigDigest[:]
}
var prevHistoryDigestBytes []byte
if o.PrevHistoryDigest != nil {
prevHistoryDigestBytes = o.PrevHistoryDigest[:]
}

return OffchainConfigProto{
// zero-initialize protobuf built-ins
protoimpl.MessageState{},
Expand Down Expand Up @@ -275,6 +309,9 @@ func enprotoOffchainConfig(o offchainConfig) OffchainConfigProto {
uint64(o.WarnDurationCommitted),
uint64(o.MaxDurationShouldAcceptAttestedReport),
uint64(o.MaxDurationShouldTransmitAcceptedReport),
prevConfigDigestBytes,
o.PrevSeqNr,
prevHistoryDigestBytes,
&sharedSecretEncryptions,
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ func ContractSetConfigArgsFromSharedConfigDeterministic(
c.WarnDurationCommitted,
c.MaxDurationShouldAcceptAttestedReport,
c.MaxDurationShouldTransmitAcceptedReport,
c.PrevConfigDigest,
c.PrevSeqNr,
c.PrevHistoryDigest,
sharedSecretEncryptions,
}).serialize()
return signers, transmitters, uint8(c.F), c.OnchainConfig, config.OCR3_1OffchainConfigVersion, offchainConfig_, nil
Expand Down
Loading
Loading