diff --git a/commit/factory.go b/commit/factory.go index 197497412..2cf5a958a 100644 --- a/commit/factory.go +++ b/commit/factory.go @@ -8,7 +8,6 @@ import ( "google.golang.org/grpc" "github.com/smartcontractkit/chainlink-common/pkg/logger" - "github.com/smartcontractkit/chainlink-common/pkg/merklemulti" "github.com/smartcontractkit/chainlink-common/pkg/types" cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" "github.com/smartcontractkit/chainlink-common/pkg/types/core" @@ -113,11 +112,8 @@ func (p *PluginFactory) NewReportingPlugin(config ocr3types.ReportingPluginConfi context.Background(), config.OracleID, oracleIDToP2PID, - pluginconfig.CommitPluginConfig{ - DestChain: p.ocrConfig.Config.ChainSelector, - NewMsgScanBatchSize: merklemulti.MaxNumberTreeLeaves, - OffchainConfig: offchainConfig, - }, + p.ocrConfig.Config.ChainSelector, + offchainConfig, ccipReader, onChainTokenPricesReader, p.commitCodec, diff --git a/commit/plugin.go b/commit/plugin.go index 3d29087e4..1402f676e 100644 --- a/commit/plugin.go +++ b/commit/plugin.go @@ -33,7 +33,8 @@ import ( type Plugin struct { nodeID commontypes.OracleID oracleIDToP2pID map[commontypes.OracleID]libocrtypes.PeerID - cfg pluginconfig.CommitPluginConfig + offchainConfig pluginconfig.CommitOffchainConfig + destChain cciptypes.ChainSelector ccipReader reader.CCIP readerSyncer *plugincommon.BackgroundReaderSyncer tokenPricesReader reader.TokenPrices @@ -48,7 +49,8 @@ func NewPlugin( _ context.Context, nodeID commontypes.OracleID, oracleIDToP2pID map[commontypes.OracleID]libocrtypes.PeerID, - cfg pluginconfig.CommitPluginConfig, + destChain cciptypes.ChainSelector, + cfg pluginconfig.CommitOffchainConfig, ccipReader reader.CCIP, tokenPricesReader reader.TokenPrices, reportCodec cciptypes.CommitPluginCodec, @@ -69,7 +71,8 @@ func NewPlugin( return &Plugin{ nodeID: nodeID, oracleIDToP2pID: oracleIDToP2pID, - cfg: cfg, + offchainConfig: cfg, + destChain: destChain, ccipReader: ccipReader, readerSyncer: readerSyncer, tokenPricesReader: tokenPricesReader, @@ -118,7 +121,7 @@ func (p *Plugin) Observation( msgBaseDetails := make([]cciptypes.RampMessageHeader, 0) latestCommittedSeqNumsObservation, err := observeLatestCommittedSeqNums( - ctx, p.lggr, p.ccipReader, supportedChains, p.cfg.DestChain, p.knownSourceChainsSlice(), + ctx, p.lggr, p.ccipReader, supportedChains, p.destChain, p.knownSourceChainsSlice(), ) if err != nil { return types.Observation{}, fmt.Errorf("observe latest committed sequence numbers: %w", err) @@ -132,7 +135,7 @@ func (p *Plugin) Observation( tokenPrices, err = observeTokenPrices( ctx, p.tokenPricesReader, - maps.Keys(p.cfg.OffchainConfig.PriceSources), + maps.Keys(p.offchainConfig.PriceSources), ) if err != nil { return types.Observation{}, fmt.Errorf("observe token prices: %w", err) @@ -176,7 +179,7 @@ func (p *Plugin) Observation( p.msgHasher, supportedChains, prevOutcome.MaxSeqNums, - p.cfg.NewMsgScanBatchSize, + p.offchainConfig.NewMsgScanBatchSize, ) if err != nil { return types.Observation{}, fmt.Errorf("observe new messages: %w", err) @@ -222,7 +225,7 @@ func (p *Plugin) ValidateObservation( return fmt.Errorf("error finding supported chains by node: %w", err) } - err = validateObserverReadingEligibility(obs.NewMsgs, obs.MaxSeqNums, observerSupportedChains, p.cfg.DestChain) + err = validateObserverReadingEligibility(obs.NewMsgs, obs.MaxSeqNums, observerSupportedChains, p.destChain) if err != nil { return fmt.Errorf("validate observer %d reading eligibility: %w", ao.Observer, err) } @@ -263,9 +266,9 @@ func (p *Plugin) Outcome( fChains := fChainConsensus(decodedObservations) - fChainDest, ok := fChains[p.cfg.DestChain] + fChainDest, ok := fChains[p.destChain] if !ok { - return ocr3types.Outcome{}, fmt.Errorf("missing destination chain %d in fChain config", p.cfg.DestChain) + return ocr3types.Outcome{}, fmt.Errorf("missing destination chain %d in fChain config", p.destChain) } maxSeqNums := maxSeqNumsConsensus(p.lggr, fChainDest, decodedObservations) @@ -391,7 +394,7 @@ func (p *Plugin) knownSourceChainsSlice() []cciptypes.ChainSelector { knownSourceChainsSlice, func(i, j int) bool { return knownSourceChainsSlice[i] < knownSourceChainsSlice[j] }, ) - return slicelib.Filter(knownSourceChainsSlice, func(ch cciptypes.ChainSelector) bool { return ch != p.cfg.DestChain }) + return slicelib.Filter(knownSourceChainsSlice, func(ch cciptypes.ChainSelector) bool { return ch != p.destChain }) } func (p *Plugin) supportedChains(oracleID commontypes.OracleID) (mapset.Set[cciptypes.ChainSelector], error) { @@ -410,7 +413,7 @@ func (p *Plugin) supportedChains(oracleID commontypes.OracleID) (mapset.Set[ccip // If current node is a writer for the destination chain. func (p *Plugin) supportsDestChain() (bool, error) { - destChainConfig, err := p.homeChain.GetChainConfig(p.cfg.DestChain) + destChainConfig, err := p.homeChain.GetChainConfig(p.destChain) if err != nil { return false, fmt.Errorf("get chain config: %w", err) } @@ -419,7 +422,7 @@ func (p *Plugin) supportsDestChain() (bool, error) { func (p *Plugin) supportsTokenPriceChain() (bool, error) { tokPriceChainConfig, err := p.homeChain.GetChainConfig( - cciptypes.ChainSelector(p.cfg.OffchainConfig.TokenPriceChainSelector)) + cciptypes.ChainSelector(p.offchainConfig.TokenPriceChainSelector)) if err != nil { return false, fmt.Errorf("get token price chain config: %w", err) } diff --git a/commit/plugin_e2e_test.go b/commit/plugin_e2e_test.go index ac87c5959..de592bcdc 100644 --- a/commit/plugin_e2e_test.go +++ b/commit/plugin_e2e_test.go @@ -233,9 +233,9 @@ func setupEmptyOutcome(ctx context.Context, t *testing.T, lggr logger.Logger) [] oracleIDToP2pID := helpers.CreateOracleIDToP2pID(1, 2, 3) nodes := []nodeSetup{ - newNode(ctx, t, lggr, 1, destCfg, homeChain, oracleIDToP2pID), - newNode(ctx, t, lggr, 2, destCfg, homeChain, oracleIDToP2pID), - newNode(ctx, t, lggr, 3, destCfg, homeChain, oracleIDToP2pID), + newNode(ctx, t, lggr, 1, offchainConfig, destChain, homeChain, oracleIDToP2pID), + newNode(ctx, t, lggr, 2, offchainConfig, destChain, homeChain, oracleIDToP2pID), + newNode(ctx, t, lggr, 3, offchainConfig, destChain, homeChain, oracleIDToP2pID), } for _, n := range nodes { @@ -265,7 +265,7 @@ func setupAllNodesReadAllChains(ctx context.Context, t *testing.T, lggr logger.L var nodes []nodeSetup for i := 1; i <= 3; i++ { - n := newNode(ctx, t, lggr, i, destCfg, homeChain, oracleIDToP2pID) + n := newNode(ctx, t, lggr, i, offchainConfig, destChain, homeChain, oracleIDToP2pID) nodes = append(nodes, n) // then they fetch new msgs, there is nothing new on chainA mockMsgsBetweenSeqNums(ctx, n.ccipReader, chainA, seqNumA, emptyMsgs) @@ -299,7 +299,7 @@ func setupNodesDoNotAgreeOnMsgs(ctx context.Context, t *testing.T, lggr logger.L var nodes []nodeSetup for i := 1; i <= 3; i++ { - n := newNode(ctx, t, lggr, i, destCfg, homeChain, oracleIDToP2pID) + n := newNode(ctx, t, lggr, i, offchainConfig, destChain, homeChain, oracleIDToP2pID) nodes = append(nodes, n) // all nodes observe the same sequence numbers lastCommittedSeqNumA for chainA and lastCommittedSeqNumB for chainB n.ccipReader.On("NextSeqNum", ctx, []cciptypes.ChainSelector{chainA, chainB}). @@ -337,7 +337,7 @@ func setupNodesDoNotReportGasPrices(ctx context.Context, t *testing.T, lggr logg var nodes []nodeSetup for i := 1; i <= 3; i++ { - n := newNode(ctx, t, lggr, i, destCfg, homeChain, oracleIDToP2pID) + n := newNode(ctx, t, lggr, i, offchainConfig, destChain, homeChain, oracleIDToP2pID) nodes = append(nodes, n) // then they fetch new msgs, there is nothing new on chainA mockMsgsBetweenSeqNums(ctx, n.ccipReader, chainA, seqNumA, emptyMsgs) @@ -371,7 +371,8 @@ func newNode( _ *testing.T, lggr logger.Logger, id int, - cfg pluginconfig.CommitPluginConfig, + offchainConfig pluginconfig.CommitOffchainConfig, + destChain cciptypes.ChainSelector, homeChain reader.HomeChain, oracleIDToP2pID map[commontypes.OracleID]libocrtypes.PeerID, ) nodeSetup { @@ -384,7 +385,8 @@ func newNode( context.Background(), commontypes.OracleID(id), oracleIDToP2pID, - cfg, + destChain, + offchainConfig, ccipReader, priceReader, reportCodec, @@ -469,7 +471,7 @@ func mockMsgsBetweenSeqNums( "MsgsBetweenSeqNums", ctx, chain, - cciptypes.NewSeqNumRange(seqNum, cciptypes.SeqNum(int(seqNum)+destCfg.NewMsgScanBatchSize)), + cciptypes.NewSeqNumRange(seqNum, cciptypes.SeqNum(int(seqNum)+offchainConfig.NewMsgScanBatchSize)), ).Return(msgs, nil) } @@ -524,8 +526,7 @@ var ( pIDs1_2_3 = []libocrtypes.PeerID{{1}, {2}, {3}} - destCfg = pluginconfig.CommitPluginConfig{ - DestChain: destChain, + offchainConfig = pluginconfig.CommitOffchainConfig{ NewMsgScanBatchSize: 256, } ) diff --git a/commitrmnocb/factory.go b/commitrmnocb/factory.go index 05927af1a..3091c0384 100644 --- a/commitrmnocb/factory.go +++ b/commitrmnocb/factory.go @@ -12,7 +12,6 @@ import ( ragep2ptypes "github.com/smartcontractkit/libocr/ragep2p/types" "github.com/smartcontractkit/chainlink-common/pkg/logger" - "github.com/smartcontractkit/chainlink-common/pkg/merklemulti" "github.com/smartcontractkit/chainlink-common/pkg/types" cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" "github.com/smartcontractkit/chainlink-common/pkg/types/core" @@ -113,16 +112,15 @@ func (p *PluginFactory) NewReportingPlugin(config ocr3types.ReportingPluginConfi p.chainWriters, p.ocrConfig.Config.ChainSelector, ) + if offchainConfig.MaxReportTransmissionCheckAttempts == 0 { + offchainConfig.MaxReportTransmissionCheckAttempts = maxReportTransmissionCheckAttempts + } return NewPlugin( context.Background(), config.OracleID, oracleIDToP2PID, - pluginconfig.CommitPluginConfig{ - DestChain: p.ocrConfig.Config.ChainSelector, - NewMsgScanBatchSize: merklemulti.MaxNumberTreeLeaves, - MaxReportTransmissionCheckAttempts: maxReportTransmissionCheckAttempts, - OffchainConfig: offchainConfig, - }, + p.ocrConfig.Config.ChainSelector, + offchainConfig, ccipReader, onChainTokenPricesReader, p.commitCodec, diff --git a/commitrmnocb/outcome.go b/commitrmnocb/outcome.go index bea98f47c..d8792330d 100644 --- a/commitrmnocb/outcome.go +++ b/commitrmnocb/outcome.go @@ -25,7 +25,7 @@ func (p *Plugin) Outcome( previousOutcome, nextState := p.decodeOutcome(outCtx.PreviousOutcome) commitQuery := Query{} - consensusObservation, err := getConsensusObservation(p.lggr, p.reportingCfg.F, p.cfg.DestChain, aos) + consensusObservation, err := getConsensusObservation(p.lggr, p.reportingCfg.F, p.destChain, aos) if err != nil { return ocr3types.Outcome{}, err } @@ -41,7 +41,7 @@ func (p *Plugin) Outcome( case WaitingForReportTransmission: outcome = checkForReportTransmission( - p.lggr, p.cfg.MaxReportTransmissionCheckAttempts, previousOutcome, consensusObservation) + p.lggr, p.offchainConfig.MaxReportTransmissionCheckAttempts, previousOutcome, consensusObservation) default: p.lggr.Warnw("Unexpected state in Outcome", "state", nextState) diff --git a/commitrmnocb/plugin.go b/commitrmnocb/plugin.go index 0f234008b..7239e2817 100644 --- a/commitrmnocb/plugin.go +++ b/commitrmnocb/plugin.go @@ -21,7 +21,8 @@ import ( type Plugin struct { nodeID commontypes.OracleID oracleIDToP2pID map[commontypes.OracleID]libocrtypes.PeerID - cfg pluginconfig.CommitPluginConfig + destChain cciptypes.ChainSelector + offchainConfig pluginconfig.CommitOffchainConfig ccipReader reader.CCIP readerSyncer *plugincommon.BackgroundReaderSyncer tokenPricesReader reader.TokenPrices @@ -37,7 +38,8 @@ func NewPlugin( _ context.Context, nodeID commontypes.OracleID, oracleIDToP2pID map[commontypes.OracleID]libocrtypes.PeerID, - cfg pluginconfig.CommitPluginConfig, + destChain cciptypes.ChainSelector, + offchainConfig pluginconfig.CommitOffchainConfig, ccipReader reader.CCIP, tokenPricesReader reader.TokenPrices, reportCodec cciptypes.CommitPluginCodec, @@ -49,8 +51,8 @@ func NewPlugin( readerSyncer := plugincommon.NewBackgroundReaderSyncer( lggr, ccipReader, - syncTimeout(cfg.SyncTimeout), - syncFrequency(cfg.SyncFrequency), + syncTimeout(offchainConfig.SyncTimeout), + syncFrequency(offchainConfig.SyncFrequency), ) if err := readerSyncer.Start(context.Background()); err != nil { lggr.Errorw("error starting background reader syncer", "err", err) @@ -61,7 +63,7 @@ func NewPlugin( homeChain: homeChain, oracleIDToP2pID: oracleIDToP2pID, nodeID: nodeID, - destChain: cfg.DestChain, + destChain: destChain, } observer := ObserverImpl{ @@ -77,7 +79,8 @@ func NewPlugin( nodeID: nodeID, oracleIDToP2pID: oracleIDToP2pID, lggr: lggr, - cfg: cfg, + offchainConfig: offchainConfig, + destChain: destChain, tokenPricesReader: tokenPricesReader, ccipReader: ccipReader, homeChain: homeChain, diff --git a/execute/factory.go b/execute/factory.go index 5f3d487e7..fc6cf2f3e 100644 --- a/execute/factory.go +++ b/execute/factory.go @@ -109,11 +109,9 @@ func (p PluginFactory) NewReportingPlugin( ) return NewPlugin( + p.ocrConfig.Config.ChainSelector, config, - pluginconfig.ExecutePluginConfig{ - DestChain: p.ocrConfig.Config.ChainSelector, - OffchainConfig: offchainConfig, - }, + offchainConfig, oracleIDToP2PID, ccipReader, p.execCodec, diff --git a/execute/plugin.go b/execute/plugin.go index 7a75fcf35..f51f3b098 100644 --- a/execute/plugin.go +++ b/execute/plugin.go @@ -29,8 +29,9 @@ const maxReportSizeBytes = 250_000 // Plugin implements the main ocr3 plugin logic. type Plugin struct { - reportingCfg ocr3types.ReportingPluginConfig - cfg pluginconfig.ExecutePluginConfig + reportingCfg ocr3types.ReportingPluginConfig + offchainConfig pluginconfig.ExecuteOffchainConfig + destChain cciptypes.ChainSelector // providers ccipReader reader.CCIP @@ -46,8 +47,9 @@ type Plugin struct { } func NewPlugin( + destChain cciptypes.ChainSelector, reportingCfg ocr3types.ReportingPluginConfig, - cfg pluginconfig.ExecutePluginConfig, + offchainConfig pluginconfig.ExecuteOffchainConfig, oracleIDToP2pID map[commontypes.OracleID]libocrtypes.PeerID, ccipReader reader.CCIP, reportCodec cciptypes.ExecutePluginCodec, @@ -60,16 +62,17 @@ func NewPlugin( readerSyncer := plugincommon.NewBackgroundReaderSyncer( lggr, ccipReader, - syncTimeout(cfg.SyncTimeout), - syncFrequency(cfg.SyncFrequency), + syncTimeout(offchainConfig.SyncTimeout), + syncFrequency(offchainConfig.SyncFrequency), ) if err := readerSyncer.Start(context.Background()); err != nil { lggr.Errorw("error starting background reader syncer", "err", err) } return &Plugin{ + destChain: destChain, reportingCfg: reportingCfg, - cfg: cfg, + offchainConfig: offchainConfig, oracleIDToP2pID: oracleIDToP2pID, ccipReader: ccipReader, readerSyncer: readerSyncer, @@ -170,7 +173,7 @@ func (p *Plugin) Observation( state := previousOutcome.State.Next() switch state { case exectypes.GetCommitReports: - fetchFrom := time.Now().Add(-p.cfg.OffchainConfig.MessageVisibilityInterval.Duration()).UTC() + fetchFrom := time.Now().Add(-p.offchainConfig.MessageVisibilityInterval.Duration()).UTC() // Phase 1: Gather commit reports from the destination chain and determine which messages are required to build // a valid execution report. @@ -179,7 +182,7 @@ func (p *Plugin) Observation( return types.Observation{}, fmt.Errorf("unable to determine if the destination chain is supported: %w", err) } if supportsDest { - groupedCommits, err := getPendingExecutedReports(ctx, p.ccipReader, p.cfg.DestChain, fetchFrom, p.lggr) + groupedCommits, err := getPendingExecutedReports(ctx, p.ccipReader, p.destChain, fetchFrom, p.lggr) if err != nil { return types.Observation{}, err } @@ -436,7 +439,7 @@ func (p *Plugin) Outcome( p.estimateProvider, commitReports, maxReportSizeBytes, - p.cfg.OffchainConfig.BatchGasLimit) + p.offchainConfig.BatchGasLimit) if err != nil { return ocr3types.Outcome{}, fmt.Errorf("unable to extract proofs: %w", err) } @@ -571,7 +574,7 @@ func (p *Plugin) supportsDestChain() (bool, error) { if err != nil { return false, fmt.Errorf("error getting supported chains: %w", err) } - return chains.Contains(p.cfg.DestChain), nil + return chains.Contains(p.destChain), nil } func syncFrequency(configuredValue time.Duration) time.Duration { diff --git a/execute/plugin_e2e_test.go b/execute/plugin_e2e_test.go index b58612bb5..6662e7f3f 100644 --- a/execute/plugin_e2e_test.go +++ b/execute/plugin_e2e_test.go @@ -189,12 +189,9 @@ func setupSimpleTest( }, } - cfg := pluginconfig.ExecutePluginConfig{ - OffchainConfig: pluginconfig.ExecuteOffchainConfig{ - MessageVisibilityInterval: *commonconfig.MustNewDuration(8 * time.Hour), - BatchGasLimit: 100000000, - }, - DestChain: dstSelector, + offchainConfig := pluginconfig.ExecuteOffchainConfig{ + MessageVisibilityInterval: *commonconfig.MustNewDuration(8 * time.Hour), + BatchGasLimit: 100000000, } chainConfigInfos := []reader.ChainConfigInfo{ { @@ -231,9 +228,12 @@ func setupSimpleTest( oracleIDToP2pID := GetP2pIDs(1, 2, 3) nodes := []nodeSetup{ - newNode(ctx, t, lggr, cfg, msgHasher, ccipReader, homeChain, tokenDataReader, oracleIDToP2pID, 1, 1), - newNode(ctx, t, lggr, cfg, msgHasher, ccipReader, homeChain, tokenDataReader, oracleIDToP2pID, 2, 1), - newNode(ctx, t, lggr, cfg, msgHasher, ccipReader, homeChain, tokenDataReader, oracleIDToP2pID, 3, 1), + newNode(ctx, t, lggr, offchainConfig, dstSelector, + msgHasher, ccipReader, homeChain, tokenDataReader, oracleIDToP2pID, 1, 1), + newNode(ctx, t, lggr, offchainConfig, dstSelector, + msgHasher, ccipReader, homeChain, tokenDataReader, oracleIDToP2pID, 2, 1), + newNode(ctx, t, lggr, offchainConfig, dstSelector, + msgHasher, ccipReader, homeChain, tokenDataReader, oracleIDToP2pID, 3, 1), } err = homeChain.Close() @@ -247,7 +247,8 @@ func newNode( _ context.Context, _ *testing.T, lggr logger.Logger, - cfg pluginconfig.ExecutePluginConfig, + offchainConfig pluginconfig.ExecuteOffchainConfig, + destChain cciptypes.ChainSelector, msgHasher cciptypes.MessageHasher, ccipReader reader.CCIP, homeChain reader.HomeChain, @@ -264,8 +265,9 @@ func newNode( } node1 := NewPlugin( + destChain, rCfg, - cfg, + offchainConfig, oracleIDToP2pID, ccipReader, reportCodec, diff --git a/execute/plugin_test.go b/execute/plugin_test.go index 3119940ce..ad096b52f 100644 --- a/execute/plugin_test.go +++ b/execute/plugin_test.go @@ -28,7 +28,6 @@ import ( "github.com/smartcontractkit/chainlink-ccip/internal/reader" codec_mocks "github.com/smartcontractkit/chainlink-ccip/mocks/execute/internal_/gen" reader_mock "github.com/smartcontractkit/chainlink-ccip/mocks/internal_/reader" - "github.com/smartcontractkit/chainlink-ccip/pluginconfig" "github.com/smartcontractkit/chainlink-ccip/plugintypes" ) @@ -480,7 +479,7 @@ func TestPlugin_ShouldTransmitAcceptReport_Ineligible(t *testing.T) { lggr, logs := logger.TestObserved(t, zapcore.DebugLevel) p := &Plugin{ lggr: lggr, - cfg: pluginconfig.ExecutePluginConfig{DestChain: 1}, + destChain: 1, reportingCfg: ocr3types.ReportingPluginConfig{OracleID: 2}, homeChain: setupHomeChainPoller(lggr, []reader.ChainConfigInfo{}), oracleIDToP2pID: map[commontypes.OracleID]libocrtypes.PeerID{ @@ -507,7 +506,7 @@ func TestPlugin_ShouldTransmitAcceptReport_DecodeFailure(t *testing.T) { p := &Plugin{ lggr: logger.Test(t), - cfg: pluginconfig.ExecutePluginConfig{DestChain: 1}, + destChain: 1, reportingCfg: ocr3types.ReportingPluginConfig{OracleID: 2}, reportCodec: codec, homeChain: homeChain, @@ -531,7 +530,7 @@ func TestPlugin_ShouldTransmitAcceptReport_Success(t *testing.T) { p := &Plugin{ lggr: lggr, - cfg: pluginconfig.ExecutePluginConfig{DestChain: 1}, + destChain: 1, reportingCfg: ocr3types.ReportingPluginConfig{OracleID: 2}, reportCodec: codec, homeChain: homeChain, diff --git a/pluginconfig/commit.go b/pluginconfig/commit.go index 5f6b2e819..6d283438d 100644 --- a/pluginconfig/commit.go +++ b/pluginconfig/commit.go @@ -15,38 +15,6 @@ import ( cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" ) -type CommitPluginConfig struct { - // DestChain is the ccip destination chain configured for the commit plugin DON. - DestChain cciptypes.ChainSelector `json:"destChain"` - - // NewMsgScanBatchSize is the number of max new messages to scan, typically set to 256. - NewMsgScanBatchSize int `json:"newMsgScanBatchSize"` - - // The maximum number of times to check if the previous report has been transmitted - MaxReportTransmissionCheckAttempts uint - - // SyncTimeout is the timeout for syncing the commit plugin reader. - SyncTimeout time.Duration `json:"syncTimeout"` - - // SyncFrequency is the frequency at which the commit plugin reader should sync. - SyncFrequency time.Duration `json:"syncFrequency"` - - // OffchainConfig is the offchain config set for the commit DON. - OffchainConfig CommitOffchainConfig `json:"offchainConfig"` -} - -func (c CommitPluginConfig) Validate() error { - if c.DestChain == cciptypes.ChainSelector(0) { - return fmt.Errorf("destChain not set") - } - - if c.NewMsgScanBatchSize == 0 { - return fmt.Errorf("newMsgScanBatchSize not set") - } - - return c.OffchainConfig.Validate() -} - // ArbitrumPriceSource is the source of the TOKEN/USD price data of a particular token // on Arbitrum. // The commit plugin will use this to fetch prices for a particular token. @@ -112,9 +80,25 @@ type CommitOffchainConfig struct { // This will typically be an arbitrum testnet/mainnet chain depending on // the deployment. TokenPriceChainSelector uint64 `json:"tokenPriceChainSelector"` + + // The maximum number of times to check if the previous report has been transmitted + MaxReportTransmissionCheckAttempts uint `json:"maxReportTransmissionCheckAttempts"` + + // SyncTimeout is the timeout for syncing the commit plugin reader. + SyncTimeout time.Duration `json:"syncTimeout"` + + // SyncFrequency is the frequency at which the commit plugin reader should sync. + SyncFrequency time.Duration `json:"syncFrequency"` + + // NewMsgScanBatchSize is the number of max new messages to scan, typically set to 256. + NewMsgScanBatchSize int `json:"newMsgScanBatchSize"` } func (c CommitOffchainConfig) Validate() error { + if c.NewMsgScanBatchSize == 0 { + return fmt.Errorf("NewMsgScanBatchSize not set") + } + if c.RemoteGasPriceBatchWriteFrequency.Duration() == 0 { return errors.New("remoteGasPriceBatchWriteFrequency not set") } diff --git a/pluginconfig/commit_test.go b/pluginconfig/commit_test.go index 3fcd5b5f8..556678de5 100644 --- a/pluginconfig/commit_test.go +++ b/pluginconfig/commit_test.go @@ -7,63 +7,9 @@ import ( commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config" cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" "github.com/smartcontractkit/libocr/offchainreporting2plus/types" - "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) -func TestCommitPluginConfigValidate(t *testing.T) { - testCases := []struct { - name string - input CommitPluginConfig - expErr bool - }{ - { - name: "valid cfg", - input: CommitPluginConfig{ - DestChain: cciptypes.ChainSelector(1), - NewMsgScanBatchSize: 256, - OffchainConfig: CommitOffchainConfig{ - RemoteGasPriceBatchWriteFrequency: *commonconfig.MustNewDuration(1), - }, - }, - expErr: false, - }, - { - name: "dest chain is empty", - input: CommitPluginConfig{ - NewMsgScanBatchSize: 256, - }, - expErr: true, - }, - { - name: "zero priced tokens", - input: CommitPluginConfig{ - DestChain: cciptypes.ChainSelector(1), - NewMsgScanBatchSize: 256, - }, - expErr: true, - }, - { - name: "empty batch scan size", - input: CommitPluginConfig{ - DestChain: cciptypes.ChainSelector(1), - }, - expErr: true, - }, - } - - for _, tc := range testCases { - t.Run(tc.name, func(t *testing.T) { - actual := tc.input.Validate() - if tc.expErr { - assert.Error(t, actual) - return - } - assert.NoError(t, actual) - }) - } -} - func TestArbitrumPriceSource_Validate(t *testing.T) { type fields struct { AggregatorAddress string @@ -146,6 +92,7 @@ func TestArbitrumPriceSource_Validate(t *testing.T) { func TestCommitOffchainConfig_Validate(t *testing.T) { type fields struct { + NewMsgScanBatchSize int RemoteGasPriceBatchWriteFrequency commonconfig.Duration TokenPriceBatchWriteFrequency commonconfig.Duration PriceSources map[types.Account]ArbitrumPriceSource @@ -163,6 +110,7 @@ func TestCommitOffchainConfig_Validate(t *testing.T) { { "valid, with token price sources", fields{ + NewMsgScanBatchSize: 256, RemoteGasPriceBatchWriteFrequency: *commonconfig.MustNewDuration(1), TokenPriceBatchWriteFrequency: *commonconfig.MustNewDuration(1), PriceSources: map[types.Account]ArbitrumPriceSource{ @@ -179,6 +127,7 @@ func TestCommitOffchainConfig_Validate(t *testing.T) { { "valid, no token price sources", fields{ + NewMsgScanBatchSize: 256, RemoteGasPriceBatchWriteFrequency: *commonconfig.MustNewDuration(1), TokenPriceBatchWriteFrequency: *commonconfig.MustNewDuration(0), PriceSources: map[types.Account]ArbitrumPriceSource{}, @@ -189,6 +138,7 @@ func TestCommitOffchainConfig_Validate(t *testing.T) { { "invalid, token price sources with no frequency", fields{ + NewMsgScanBatchSize: 256, RemoteGasPriceBatchWriteFrequency: *commonconfig.MustNewDuration(1), TokenPriceBatchWriteFrequency: *commonconfig.MustNewDuration(0), PriceSources: map[types.Account]ArbitrumPriceSource{ @@ -204,6 +154,7 @@ func TestCommitOffchainConfig_Validate(t *testing.T) { { "invalid, price sources with no chain selector", fields{ + NewMsgScanBatchSize: 256, RemoteGasPriceBatchWriteFrequency: *commonconfig.MustNewDuration(1), TokenPriceBatchWriteFrequency: *commonconfig.MustNewDuration(1), PriceSources: map[types.Account]ArbitrumPriceSource{ @@ -216,10 +167,20 @@ func TestCommitOffchainConfig_Validate(t *testing.T) { }, true, }, + { + "invalid, new msg scan batch size not provided", + fields{ + RemoteGasPriceBatchWriteFrequency: *commonconfig.MustNewDuration(1), + TokenPriceBatchWriteFrequency: *commonconfig.MustNewDuration(1), + PriceSources: map[types.Account]ArbitrumPriceSource{}, + }, + true, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { c := CommitOffchainConfig{ + NewMsgScanBatchSize: tt.fields.NewMsgScanBatchSize, RemoteGasPriceBatchWriteFrequency: tt.fields.RemoteGasPriceBatchWriteFrequency, TokenPriceBatchWriteFrequency: tt.fields.TokenPriceBatchWriteFrequency, PriceSources: tt.fields.PriceSources, diff --git a/pluginconfig/execute.go b/pluginconfig/execute.go index f2065f97e..f0b550c8b 100644 --- a/pluginconfig/execute.go +++ b/pluginconfig/execute.go @@ -6,26 +6,8 @@ import ( "time" commonconfig "github.com/smartcontractkit/chainlink-common/pkg/config" - cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3" ) -// ExecutePluginConfig is configuration for the execute plugin -// which includes the offchain configuration as well as other parameters -// fetched from the OCR configuration. -type ExecutePluginConfig struct { - // DestChain is the ccip destination chain configured for the execute DON. - DestChain cciptypes.ChainSelector `json:"destChain"` - - // SyncTimeout is the timeout for syncing the exec plugin ccip reader. - SyncTimeout time.Duration `json:"syncTimeout"` - - // SyncFrequency is the frequency at which the exec plugin ccip reader should sync. - SyncFrequency time.Duration `json:"syncFrequency"` - - // OffchainConfig is the offchain config set for the exec DON. - OffchainConfig ExecuteOffchainConfig `json:"offchainConfig"` -} - // ExecuteOffchainConfig is the OCR offchainConfig for the exec plugin. // This is posted onchain as part of the OCR configuration process of the exec plugin. // Every plugin is provided this configuration in its encoded form in the NewReportingPlugin @@ -52,6 +34,12 @@ type ExecuteOffchainConfig struct { // BatchingStrategyID is the strategy to use for batching messages. BatchingStrategyID uint32 `json:"batchingStrategyID"` + + // SyncTimeout is the timeout for syncing the exec plugin ccip reader. + SyncTimeout time.Duration `json:"syncTimeout"` + + // SyncFrequency is the frequency at which the exec plugin ccip reader should sync. + SyncFrequency time.Duration `json:"syncFrequency"` } func (e ExecuteOffchainConfig) Validate() error {