Skip to content

Commit

Permalink
axe unnecessary config types
Browse files Browse the repository at this point in the history
  • Loading branch information
makramkd committed Aug 19, 2024
1 parent 48726fd commit 21c6548
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 177 deletions.
8 changes: 2 additions & 6 deletions commit/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,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"
Expand Down Expand Up @@ -110,11 +109,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,
Expand Down
27 changes: 15 additions & 12 deletions commit/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -69,7 +71,8 @@ func NewPlugin(
return &Plugin{
nodeID: nodeID,
oracleIDToP2pID: oracleIDToP2pID,
cfg: cfg,
offchainConfig: cfg,
destChain: destChain,
ccipReader: ccipReader,
readerSyncer: readerSyncer,
tokenPricesReader: tokenPricesReader,
Expand Down Expand Up @@ -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)
Expand All @@ -131,7 +134,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)
Expand Down Expand Up @@ -175,7 +178,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)
Expand Down Expand Up @@ -221,7 +224,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)
}
Expand Down Expand Up @@ -262,9 +265,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)
Expand Down Expand Up @@ -390,7 +393,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) {
Expand All @@ -409,7 +412,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)
}
Expand All @@ -418,7 +421,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)
}
Expand Down
23 changes: 12 additions & 11 deletions commit/plugin_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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}).
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand All @@ -384,7 +385,8 @@ func newNode(
context.Background(),
commontypes.OracleID(id),
oracleIDToP2pID,
cfg,
destChain,
offchainConfig,
ccipReader,
priceReader,
reportCodec,
Expand Down Expand Up @@ -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)
}

Expand Down Expand Up @@ -524,8 +526,7 @@ var (

pIDs1_2_3 = []libocrtypes.PeerID{{1}, {2}, {3}}

destCfg = pluginconfig.CommitPluginConfig{
DestChain: destChain,
offchainConfig = pluginconfig.CommitOffchainConfig{
NewMsgScanBatchSize: 256,
}
)
12 changes: 5 additions & 7 deletions commitrmnocb/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,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"
Expand Down Expand Up @@ -110,16 +109,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,
Expand Down
4 changes: 2 additions & 2 deletions commitrmnocb/outcome.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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)
Expand Down
14 changes: 8 additions & 6 deletions commitrmnocb/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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)
Expand All @@ -61,7 +63,7 @@ func NewPlugin(
homeChain: homeChain,
oracleIDToP2pID: oracleIDToP2pID,
nodeID: nodeID,
destChain: cfg.DestChain,
destChain: destChain,
}

observer := ObserverImpl{
Expand All @@ -77,7 +79,7 @@ func NewPlugin(
nodeID: nodeID,
oracleIDToP2pID: oracleIDToP2pID,
lggr: lggr,
cfg: cfg,
offchainConfig: offchainConfig,
tokenPricesReader: tokenPricesReader,
ccipReader: ccipReader,
homeChain: homeChain,
Expand Down
6 changes: 2 additions & 4 deletions execute/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
23 changes: 13 additions & 10 deletions execute/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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.
Expand All @@ -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
}
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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 {
Expand Down
Loading

0 comments on commit 21c6548

Please sign in to comment.