diff --git a/commit_rmn_ocb/README.md b/commitrmnocb/README.md similarity index 100% rename from commit_rmn_ocb/README.md rename to commitrmnocb/README.md diff --git a/commit_rmn_ocb/factory.go b/commitrmnocb/factory.go similarity index 96% rename from commit_rmn_ocb/factory.go rename to commitrmnocb/factory.go index 0e3fb1ece..8c64c2e40 100644 --- a/commit_rmn_ocb/factory.go +++ b/commitrmnocb/factory.go @@ -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 diff --git a/commit_rmn_ocb/metrics.go b/commitrmnocb/metrics.go similarity index 100% rename from commit_rmn_ocb/metrics.go rename to commitrmnocb/metrics.go diff --git a/commit_rmn_ocb/observation.go b/commitrmnocb/observation.go similarity index 93% rename from commit_rmn_ocb/observation.go rename to commitrmnocb/observation.go index 8fa30f0ce..b2195b5e7 100644 --- a/commit_rmn_ocb/observation.go +++ b/commitrmnocb/observation.go @@ -25,33 +25,37 @@ func (p *Plugin) Observation( ) (types.Observation, error) { previousOutcome, nextState := p.decodeOutcome(outCtx.PreviousOutcome) + observation := CommitPluginObservation{} 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 @@ -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 @@ -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) @@ -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 diff --git a/commit_rmn_ocb/outcome.go b/commitrmnocb/outcome.go similarity index 91% rename from commit_rmn_ocb/outcome.go rename to commitrmnocb/outcome.go index 9cc8f8aa6..2045fb1db 100644 --- a/commit_rmn_ocb/outcome.go +++ b/commitrmnocb/outcome.go @@ -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{} + 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) @@ -88,7 +90,7 @@ 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 @@ -96,7 +98,7 @@ func (p *Plugin) ReportRangesOutcome( func (p *Plugin) buildReport( query CommitQuery, consensusObservation ConsensusObservation, -) (ocr3types.Outcome, error) { +) CommitPluginOutcome { // TODO: Only include chains in the report that have gas prices? // TODO: token prices validation @@ -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 @@ -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 { @@ -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 @@ -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, diff --git a/commit_rmn_ocb/plugin.go b/commitrmnocb/plugin.go similarity index 100% rename from commit_rmn_ocb/plugin.go rename to commitrmnocb/plugin.go diff --git a/commit_rmn_ocb/query.go b/commitrmnocb/query.go similarity index 100% rename from commit_rmn_ocb/query.go rename to commitrmnocb/query.go diff --git a/commit_rmn_ocb/report.go b/commitrmnocb/report.go similarity index 95% rename from commit_rmn_ocb/report.go rename to commitrmnocb/report.go index d7660c1a3..6ad8c0f73 100644 --- a/commit_rmn_ocb/report.go +++ b/commitrmnocb/report.go @@ -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) diff --git a/commit_rmn_ocb/types.go b/commitrmnocb/types.go similarity index 88% rename from commit_rmn_ocb/types.go rename to commitrmnocb/types.go index 080ca3adb..ac216add1 100644 --- a/commit_rmn_ocb/types.go +++ b/commitrmnocb/types.go @@ -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) @@ -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 diff --git a/commit_rmn_ocb/validate_observation.go b/commitrmnocb/validate_observation.go similarity index 95% rename from commit_rmn_ocb/validate_observation.go rename to commitrmnocb/validate_observation.go index 508207384..a6bfeaa91 100644 --- a/commit_rmn_ocb/validate_observation.go +++ b/commitrmnocb/validate_observation.go @@ -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) { diff --git a/commit_rmn_ocb/validate_observation_test.go b/commitrmnocb/validate_observation_test.go similarity index 100% rename from commit_rmn_ocb/validate_observation_test.go rename to commitrmnocb/validate_observation_test.go