Skip to content

Commit

Permalink
Changes to get the new Commit Plugin working in the integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
rstout committed Aug 8, 2024
1 parent 70da9cf commit 787844d
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 50 deletions.
File renamed without changes.
9 changes: 4 additions & 5 deletions commit_rmn_ocb/factory.go → commitrmnocb/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,10 @@ func (p *PluginFactory) NewReportingPlugin(config ocr3types.ReportingPluginConfi
), ocr3types.ReportingPluginInfo{
Name: "CCIPRoleCommit",
Limits: ocr3types.ReportingPluginLimits{
// No query for this commit implementation.
MaxQueryLength: 0,
MaxObservationLength: 20_000, // 20kB
MaxOutcomeLength: 10_000, // 10kB
MaxReportLength: 10_000, // 10kB
MaxQueryLength: 1024 * 1024, // 1MB
MaxObservationLength: 20_000, // 20kB
MaxOutcomeLength: 10_000, // 10kB
MaxReportLength: 10_000, // 10kB
MaxReportCount: 10,
},
}, nil
Expand Down
File renamed without changes.
24 changes: 14 additions & 10 deletions commit_rmn_ocb/observation.go → commitrmnocb/observation.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,33 +25,37 @@ func (p *Plugin) Observation(
) (types.Observation, error) {
previousOutcome, nextState := p.decodeOutcome(outCtx.PreviousOutcome)

observation := CommitPluginObservation{}

Check failure on line 28 in commitrmnocb/observation.go

View workflow job for this annotation

GitHub Actions / build-lint-test (1.21)

SA4006: this value of `observation` is never used (staticcheck)
switch nextState {
case SelectingRangesForReport:
offRampNextSeqNums := p.ObserveOffRampNextSeqNums(ctx)
return CommitPluginObservation{
OnRampMaxSeqNums: p.ObserveOnRampMaxSeqNums(offRampNextSeqNums),
observation = CommitPluginObservation{
OnRampMaxSeqNums: offRampNextSeqNums, // TODO: change
OffRampNextSeqNums: offRampNextSeqNums,
FChain: p.ObserveFChain(),
}.Encode()
}

case BuildingReport:
return CommitPluginObservation{
observation = CommitPluginObservation{
MerkleRoots: p.ObserveMerkleRoots(ctx, previousOutcome.RangesSelectedForReport),
GasPrices: p.ObserveGasPrices(ctx),
TokenPrices: p.ObserveTokenPrices(ctx),
FChain: p.ObserveFChain(),
}.Encode()
}

case WaitingForReportTransmission:
return CommitPluginObservation{
observation = CommitPluginObservation{
OffRampNextSeqNums: p.ObserveOffRampNextSeqNums(ctx),
FChain: p.ObserveFChain(),
}.Encode()
}

default:
p.lggr.Warnw("Unexpected state", "state", nextState)
return types.Observation{}, nil
}

p.lggr.Infow("Observation", "observation", observation)
return observation.Encode()
}

// ObserveOnRampMaxSeqNums Simply add NewMsgScanBatchSize to the offRampNextSeqNums
Expand Down Expand Up @@ -94,7 +98,7 @@ func (p *Plugin) ObserveOffRampNextSeqNums(ctx context.Context) []plugintypes.Se

result := make([]plugintypes.SeqNumChain, len(sourceChains))
for i := range sourceChains {
result = append(result, plugintypes.SeqNumChain{ChainSel: sourceChains[i], SeqNum: offRampNextSeqNums[i]})
result[i] = plugintypes.SeqNumChain{ChainSel: sourceChains[i], SeqNum: offRampNextSeqNums[i]}
}

return result
Expand All @@ -105,7 +109,7 @@ func (p *Plugin) ObserveOffRampNextSeqNums(ctx context.Context) []plugintypes.Se

// ObserveMerkleRoots TODO: doc
func (p *Plugin) ObserveMerkleRoots(ctx context.Context, ranges []ChainRange) []cciptypes.MerkleRootChain {
roots := make([]cciptypes.MerkleRootChain, len(ranges))
roots := make([]cciptypes.MerkleRootChain, 0)
supportedChains, err := p.supportedChains(p.nodeID)
if err != nil {
p.lggr.Warnw("call to supportedChains failed", "err", err)
Expand Down Expand Up @@ -139,7 +143,7 @@ func (p *Plugin) ObserveMerkleRoots(ctx context.Context, ranges []ChainRange) []
// computeMerkleRoot Compute the merkle root of a list of messages
func computeMerkleRoot(msgs []cciptypes.Message) (cciptypes.Bytes32, error) {
msgSeqNumToHash := make(map[cciptypes.SeqNum]cciptypes.Bytes32)
seqNums := make([]cciptypes.SeqNum, len(msgs))
seqNums := make([]cciptypes.SeqNum, 0)

for _, msg := range msgs {
seqNum := msg.Header.SequenceNumber
Expand Down
60 changes: 35 additions & 25 deletions commit_rmn_ocb/outcome.go → commitrmnocb/outcome.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,36 +21,38 @@ func (p *Plugin) Outcome(
outCtx ocr3types.OutcomeContext, query types.Query, aos []types.AttributedObservation,
) (ocr3types.Outcome, error) {
previousOutcome, nextState := p.decodeOutcome(outCtx.PreviousOutcome)
commitQuery, err := DecodeCommitPluginQuery(query)
if err != nil {
return ocr3types.Outcome{}, err
}
commitQuery := CommitQuery{}

consensusObservation, err := p.getConsensusObservation(aos)
if err != nil {
return ocr3types.Outcome{}, err
}

outcome := CommitPluginOutcome{}

Check failure on line 31 in commitrmnocb/outcome.go

View workflow job for this annotation

GitHub Actions / build-lint-test (1.21)

SA4006: this value of `outcome` is never used (staticcheck)

switch nextState {
case SelectingRangesForReport:
return p.ReportRangesOutcome(commitQuery, consensusObservation)
outcome = p.ReportRangesOutcome(commitQuery, consensusObservation)

case BuildingReport:
return p.buildReport(commitQuery, consensusObservation)
outcome = p.buildReport(commitQuery, consensusObservation)

case WaitingForReportTransmission:
return p.checkForReportTransmission(previousOutcome, consensusObservation)
outcome = p.checkForReportTransmission(previousOutcome, consensusObservation)

default:
return nil, fmt.Errorf("outcome unexpected state: %d", nextState)
}

p.lggr.Infow("Commit Plugin Outcome", "outcome", outcome, "oid", p.nodeID)
return outcome.Encode()
}

// ReportRangesOutcome determines the sequence number ranges for each chain to build a report from in the next round
func (p *Plugin) ReportRangesOutcome(
query CommitQuery,
consensusObservation ConsensusObservation,
) (ocr3types.Outcome, error) {
) CommitPluginOutcome {
rangesToReport := make([]ChainRange, 0)

rmnOnRampMaxSeqNumsMap := make(map[cciptypes.ChainSelector]cciptypes.SeqNum)
Expand Down Expand Up @@ -88,15 +90,15 @@ func (p *Plugin) ReportRangesOutcome(
RangesSelectedForReport: rangesToReport,
}

return outcome.Encode()
return outcome
}

// Given a set of observed merkle roots, gas prices and token prices, and roots from RMN, construct a report
// to transmit on-chain
func (p *Plugin) buildReport(
query CommitQuery,

Check failure on line 99 in commitrmnocb/outcome.go

View workflow job for this annotation

GitHub Actions / build-lint-test (1.21)

`(*Plugin).buildReport` - `query` is unused (unparam)
consensusObservation ConsensusObservation,
) (ocr3types.Outcome, error) {
) CommitPluginOutcome {
// TODO: Only include chains in the report that have gas prices?

// TODO: token prices validation
Expand All @@ -109,12 +111,19 @@ func (p *Plugin) buildReport(
return roots[i].ChainSel < roots[j].ChainSel
})

return CommitPluginOutcome{
OutcomeType: ReportGenerated,
outcomeType := ReportGenerated
if len(roots) == 0 {
outcomeType = ReportEmpty
}

outcome := CommitPluginOutcome{
OutcomeType: outcomeType,
RootsToReport: roots,
GasPrices: consensusObservation.GasPricesSortedArray(),
TokenPrices: consensusObservation.TokenPricesSortedArray(),
}.Encode()
}

return outcome
}

// checkForReportTransmission checks if the OffRamp has an updated set of max seq nums compared to the seq nums that
Expand All @@ -127,7 +136,7 @@ func (p *Plugin) buildReport(
func (p *Plugin) checkForReportTransmission(
previousOutcome CommitPluginOutcome,
consensusObservation ConsensusObservation,
) (ocr3types.Outcome, error) {
) CommitPluginOutcome {

offRampUpdated := false
for _, previousSeqNumChain := range previousOutcome.OffRampNextSeqNums {
Expand All @@ -142,20 +151,21 @@ func (p *Plugin) checkForReportTransmission(
if offRampUpdated {
return CommitPluginOutcome{
OutcomeType: ReportTransmitted,
}.Encode()
}
}

if previousOutcome.ReportTransmissionCheckAttempts+1 >= p.cfg.MaxReportTransmissionCheckAttempts {
p.lggr.Warnw("Failed to detect report transmission")
return CommitPluginOutcome{
OutcomeType: ReportNotTransmitted,
}.Encode()
}
}

return CommitPluginOutcome{
OutcomeType: ReportNotYetTransmitted,
OffRampNextSeqNums: previousOutcome.OffRampNextSeqNums,
ReportTransmissionCheckAttempts: previousOutcome.ReportTransmissionCheckAttempts + 1,
}.Encode()
}
}

// getConsensusObservation Combine the list of observations into a single consensus observation
Expand All @@ -169,17 +179,17 @@ func (p *Plugin) getConsensusObservation(aos []types.AttributedObservation) (Con
fmt.Errorf("no consensus value for fDestChain, DestChain: %d", p.cfg.DestChain)
}

fTokenChain, exists := fChains[cciptypes.ChainSelector(p.cfg.OffchainConfig.TokenPriceChainSelector)]
if !exists {
return ConsensusObservation{},
fmt.Errorf("no consensus value for fTokenChain, TokenPriceChain: %d",
p.cfg.OffchainConfig.TokenPriceChainSelector)
}
//fTokenChain, exists := fChains[cciptypes.ChainSelector(p.cfg.OffchainConfig.TokenPriceChainSelector)]
//if !exists {
// return ConsensusObservation{},
// fmt.Errorf("no consensus value for fTokenChain, TokenPriceChain: %d",
// p.cfg.OffchainConfig.TokenPriceChainSelector)
//}

consensusObs := ConsensusObservation{
MerkleRoots: p.merkleRootConsensus(aggObs.MerkleRoots, fChains),
GasPrices: p.gasPriceConsensus(aggObs.GasPrices, fChains),
TokenPrices: p.tokenPriceConsensus(aggObs.TokenPrices, fTokenChain),
GasPrices: make(map[cciptypes.ChainSelector]cciptypes.BigInt), // p.gasPriceConsensus(aggObs.GasPrices, fChains),
TokenPrices: make(map[types.Account]cciptypes.BigInt), // p.tokenPriceConsensus(aggObs.TokenPrices, fTokenChain),
OnRampMaxSeqNums: p.onRampMaxSeqNumsConsensus(aggObs.OnRampMaxSeqNums, fChains),
OffRampNextSeqNums: p.offRampMaxSeqNumsConsensus(aggObs.OffRampNextSeqNums, fDestChain),
FChain: fChains,
Expand Down
File renamed without changes.
File renamed without changes.
4 changes: 4 additions & 0 deletions commit_rmn_ocb/report.go → commitrmnocb/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ func (p *Plugin) Reports(seqNr uint64, outcomeBytes ocr3types.Outcome) ([]ocr3ty
return nil, fmt.Errorf("failed to decode CommitPluginOutcome: %w", err)
}

if outcome.OutcomeType != ReportGenerated {
return []ocr3types.ReportWithInfo[[]byte]{}, nil
}

rep := cciptypes.NewCommitPluginReport(outcome.RootsToReport, outcome.TokenPrices, outcome.GasPrices)

encodedReport, err := p.reportCodec.Encode(context.Background(), rep)
Expand Down
23 changes: 15 additions & 8 deletions commit_rmn_ocb/types.go → commitrmnocb/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,14 @@ type AggregatedObservation struct {

// aggregateObservations takes a list of observations and produces an AggregatedObservation
func aggregateObservations(aos []types.AttributedObservation) AggregatedObservation {
aggObs := AggregatedObservation{}
aggObs := AggregatedObservation{
MerkleRoots: make(map[cciptypes.ChainSelector][]cciptypes.MerkleRootChain),
GasPrices: make(map[cciptypes.ChainSelector][]cciptypes.BigInt),
TokenPrices: make(map[types.Account][]cciptypes.BigInt),
OnRampMaxSeqNums: make(map[cciptypes.ChainSelector][]cciptypes.SeqNum),
OffRampNextSeqNums: make(map[cciptypes.ChainSelector][]cciptypes.SeqNum),
FChain: make(map[cciptypes.ChainSelector][]int),
}

for _, ao := range aos {
obs, err := DecodeCommitPluginObservation(ao.Observation)
Expand Down Expand Up @@ -194,13 +201,13 @@ const (
)

type CommitPluginOutcome struct {
OutcomeType CommitPluginOutcomeType
RangesSelectedForReport []ChainRange
RootsToReport []cciptypes.MerkleRootChain
OffRampNextSeqNums []plugintypes.SeqNumChain
TokenPrices []cciptypes.TokenPrice `json:"tokenPrices"`
GasPrices []cciptypes.GasPriceChain `json:"gasPrices"`
ReportTransmissionCheckAttempts uint `json:"reportTransmissionCheckAttempts"`
OutcomeType CommitPluginOutcomeType `json:"outcomeType"`
RangesSelectedForReport []ChainRange `json:"rangesSelectedForReport"`
RootsToReport []cciptypes.MerkleRootChain `json:"rootsToReport"`
OffRampNextSeqNums []plugintypes.SeqNumChain `json:"offRampNextSeqNums"`
TokenPrices []cciptypes.TokenPrice `json:"tokenPrices"`
GasPrices []cciptypes.GasPriceChain `json:"gasPrices"`
ReportTransmissionCheckAttempts uint `json:"reportTransmissionCheckAttempts"`
}

// Encode TODO: sort all lists here to ensure deterministic serialization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ func validateObservedOnRampMaxSeqNums(
seenChains := mapset.NewSet[cciptypes.ChainSelector]()
for _, seqNumChain := range onRampMaxSeqNums {
if !observerSupportedChains.Contains(seqNumChain.ChainSel) {
return fmt.Errorf("found onRampMaxSeqNum for chain %d, but this chain is not supported by Observer %d",
seqNumChain.ChainSel, observer)
return fmt.Errorf("found onRampMaxSeqNum for chain %d, but this chain is not supported by Observer %d, "+
"observerSupportedChains: %v, onRampMaxSeqNums: %v",
seqNumChain.ChainSel, observer, observerSupportedChains, onRampMaxSeqNums)
}

if seenChains.Contains(seqNumChain.ChainSel) {
Expand Down
File renamed without changes.

0 comments on commit 787844d

Please sign in to comment.