Skip to content

Commit

Permalink
Fix/ccip 2466 homechain config sync (#1077)
Browse files Browse the repository at this point in the history
Fix some of previous PR commit as it was merged with auto-merge before
addressing all of them.
  • Loading branch information
asoliman92 authored Jun 25, 2024
1 parent df11318 commit df2225c
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 157 deletions.
2 changes: 1 addition & 1 deletion core/services/ocr3/plugins/ccip/commit/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (p PluginFactory) NewReportingPlugin(config ocr3types.ReportingPluginConfig
nil, //reportCodec
nil, //msgHasher
nil, // lggr
nil, //homeChainPoller
nil, //homeChain
), ocr3types.ReportingPluginInfo{}, nil
}

Expand Down
24 changes: 8 additions & 16 deletions core/services/ocr3/plugins/ccip/commit/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ type Plugin struct {
msgHasher cciptypes.MessageHasher
lggr logger.Logger

homeChainPoller reader.HomeChainPoller
homeChain reader.HomeChain
}

func NewPlugin(
Expand All @@ -48,7 +48,7 @@ func NewPlugin(
reportCodec cciptypes.CommitPluginCodec,
msgHasher cciptypes.MessageHasher,
lggr logger.Logger,
homeChainPoller reader.HomeChainPoller,
homeChain reader.HomeChain,
) *Plugin {
return &Plugin{
nodeID: nodeID,
Expand All @@ -59,7 +59,7 @@ func NewPlugin(
reportCodec: reportCodec,
msgHasher: msgHasher,
lggr: lggr,
homeChainPoller: homeChainPoller,
homeChain: homeChain,
}
}

Expand Down Expand Up @@ -122,7 +122,7 @@ func (p *Plugin) Observation(ctx context.Context, outctx ocr3types.OutcomeContex
return types.Observation{}, fmt.Errorf("observe gas prices: %w", err)
}

fChain, err := p.homeChainPoller.GetFChain()
fChain, err := p.homeChain.GetFChain()
if err != nil {
return types.Observation{}, fmt.Errorf("get f chain: %w", err)
}
Expand Down Expand Up @@ -328,7 +328,7 @@ func (p *Plugin) Close() error {
}

func (p *Plugin) knownSourceChainsSlice() []cciptypes.ChainSelector {
knownSourceChains, err := p.homeChainPoller.GetKnownCCIPChains()
knownSourceChains, err := p.homeChain.GetKnownCCIPChains()
if err != nil {
p.lggr.Errorw("error getting known chains", "err", err)
return nil
Expand All @@ -343,7 +343,7 @@ func (p *Plugin) supportedChains() (mapset.Set[cciptypes.ChainSelector], error)
if !exists {
return nil, fmt.Errorf("oracle ID %d not found in oracleIDToP2pID", p.nodeID)
}
supportedChains, err := p.homeChainPoller.GetSupportedChainsForPeer(p2pID)
supportedChains, err := p.homeChain.GetSupportedChainsForPeer(p2pID)
if err != nil {
p.lggr.Warnw("error getting supported chains", err)
return mapset.NewSet[cciptypes.ChainSelector](), fmt.Errorf("error getting supported chains: %w", err)
Expand All @@ -352,18 +352,10 @@ func (p *Plugin) supportedChains() (mapset.Set[cciptypes.ChainSelector], error)
return supportedChains, nil
}

func (p *Plugin) getDestChainConfig() (reader.ChainConfig, error) {
cfg, err := p.homeChainPoller.GetChainConfig(p.cfg.DestChain)
if err != nil {
return reader.ChainConfig{}, fmt.Errorf("get chain config: %w", err)
}
return cfg, nil
}

func (p *Plugin) supportsDestChain() (bool, error) {
destChainConfig, err := p.getDestChainConfig()
destChainConfig, err := p.homeChain.GetChainConfig(p.cfg.DestChain)
if err != nil {
return false, fmt.Errorf("error getting chain config: %w", err)
return false, fmt.Errorf("get chain config: %w", err)
}
return destChainConfig.SupportedNodes.Contains(p.oracleIDToP2pID[p.nodeID]), nil
}
Expand Down
46 changes: 23 additions & 23 deletions core/services/ocr3/plugins/ccip/commit/plugin_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,17 @@ func setupEmptyOutcome(ctx context.Context, t *testing.T, lggr logger.Logger) []
},
}

homeChainPoller := setupHomeChainPoller(lggr, chainConfigInfos)
err := homeChainPoller.Start(ctx)
homeChain := setupHomeChainPoller(lggr, chainConfigInfos)
err := homeChain.Start(ctx)
if err != nil {
return nil
}

oracleIDToP2pID := GetP2pIDs(1, 2, 3)
nodes := []nodeSetup{
newNode(ctx, t, lggr, 1, cfg, homeChainPoller, oracleIDToP2pID),
newNode(ctx, t, lggr, 2, cfg, homeChainPoller, oracleIDToP2pID),
newNode(ctx, t, lggr, 3, cfg, homeChainPoller, oracleIDToP2pID),
newNode(ctx, t, lggr, 1, cfg, homeChain, oracleIDToP2pID),
newNode(ctx, t, lggr, 2, cfg, homeChain, oracleIDToP2pID),
newNode(ctx, t, lggr, 3, cfg, homeChain, oracleIDToP2pID),
}

for _, n := range nodes {
Expand All @@ -227,7 +227,7 @@ func setupEmptyOutcome(ctx context.Context, t *testing.T, lggr logger.Logger) []
).Return([]cciptypes.SeqNum{}, nil)
}

err = homeChainPoller.Close()
err = homeChain.Close()
if err != nil {
return nil
}
Expand Down Expand Up @@ -275,15 +275,15 @@ func setupAllNodesReadAllChains(ctx context.Context, t *testing.T, lggr logger.L
},
}

homeChainPoller := setupHomeChainPoller(lggr, chainConfigInfos)
err := homeChainPoller.Start(ctx)
homeChain := setupHomeChainPoller(lggr, chainConfigInfos)
err := homeChain.Start(ctx)
if err != nil {
return nil
}
oracleIDToP2pID := GetP2pIDs(1, 2, 3)
n1 := newNode(ctx, t, lggr, 1, cfg, homeChainPoller, oracleIDToP2pID)
n2 := newNode(ctx, t, lggr, 2, cfg, homeChainPoller, oracleIDToP2pID)
n3 := newNode(ctx, t, lggr, 3, cfg, homeChainPoller, oracleIDToP2pID)
n1 := newNode(ctx, t, lggr, 1, cfg, homeChain, oracleIDToP2pID)
n2 := newNode(ctx, t, lggr, 2, cfg, homeChain, oracleIDToP2pID)
n3 := newNode(ctx, t, lggr, 3, cfg, homeChain, oracleIDToP2pID)
nodes := []nodeSetup{n1, n2, n3}

for _, n := range nodes {
Expand Down Expand Up @@ -319,7 +319,7 @@ func setupAllNodesReadAllChains(ctx context.Context, t *testing.T, lggr logger.L
}

// No need to keep it running in the background anymore for this test
err = homeChainPoller.Close()
err = homeChain.Close()
if err != nil {
return nil
}
Expand Down Expand Up @@ -368,15 +368,15 @@ func setupNodesDoNotAgreeOnMsgs(ctx context.Context, t *testing.T, lggr logger.L
},
}

homeChainPoller := setupHomeChainPoller(lggr, chainConfigInfos)
err := homeChainPoller.Start(ctx)
homeChain := setupHomeChainPoller(lggr, chainConfigInfos)
err := homeChain.Start(ctx)
if err != nil {
return nil
}
oracleIDToP2pID := GetP2pIDs(1, 2, 3)
n1 := newNode(ctx, t, lggr, 1, cfg, homeChainPoller, oracleIDToP2pID)
n2 := newNode(ctx, t, lggr, 2, cfg, homeChainPoller, oracleIDToP2pID)
n3 := newNode(ctx, t, lggr, 3, cfg, homeChainPoller, oracleIDToP2pID)
n1 := newNode(ctx, t, lggr, 1, cfg, homeChain, oracleIDToP2pID)
n2 := newNode(ctx, t, lggr, 2, cfg, homeChain, oracleIDToP2pID)
n3 := newNode(ctx, t, lggr, 3, cfg, homeChain, oracleIDToP2pID)
nodes := []nodeSetup{n1, n2, n3}

for i, n := range nodes {
Expand Down Expand Up @@ -414,7 +414,7 @@ func setupNodesDoNotAgreeOnMsgs(ctx context.Context, t *testing.T, lggr logger.L
}

// No need to keep it running in the background anymore for this test
err = homeChainPoller.Close()
err = homeChain.Close()
if err != nil {
return nil
}
Expand All @@ -430,7 +430,7 @@ type nodeSetup struct {
msgHasher *mocks.MessageHasher
}

func newNode(ctx context.Context, t *testing.T, lggr logger.Logger, id int, cfg cciptypes.CommitPluginConfig, homeChainPoller reader.HomeChainPoller, oracleIDToP2pID map[commontypes.OracleID]libocrtypes.PeerID) nodeSetup {
func newNode(ctx context.Context, t *testing.T, lggr logger.Logger, id int, cfg cciptypes.CommitPluginConfig, homeChain reader.HomeChain, oracleIDToP2pID map[commontypes.OracleID]libocrtypes.PeerID) nodeSetup {
ccipReader := mocks.NewCCIPReader()
priceReader := mocks.NewTokenPricesReader()
reportCodec := mocks.NewCommitPluginJSONReportCodec()
Expand All @@ -446,7 +446,7 @@ func newNode(ctx context.Context, t *testing.T, lggr logger.Logger, id int, cfg
reportCodec,
msgHasher,
lggr,
homeChainPoller,
homeChain,
)

return nodeSetup{
Expand All @@ -458,7 +458,7 @@ func newNode(ctx context.Context, t *testing.T, lggr logger.Logger, id int, cfg
}
}

func setupHomeChainPoller(lggr logger.Logger, chainConfigInfos []reader.ChainConfigInfo) *reader.HomeChainConfigPoller {
func setupHomeChainPoller(lggr logger.Logger, chainConfigInfos []reader.ChainConfigInfo) reader.HomeChain {
homeChainReader := mocks.NewContractReaderMock()
homeChainReader.On(
"GetLatestValue", mock.Anything, "CCIPCapabilityConfiguration", "getAllChainConfigs", mock.Anything, mock.Anything).Run(
Expand All @@ -467,13 +467,13 @@ func setupHomeChainPoller(lggr logger.Logger, chainConfigInfos []reader.ChainCon
*arg = chainConfigInfos
}).Return(nil)

homeChainPoller := reader.NewHomeChainConfigPoller(
homeChain := reader.NewHomeChainConfigPoller(
homeChainReader,
lggr,
10*time.Millisecond, // to prevent linting error because of logging after finishing tests, we close the poller after each test, having lower polling interval make it catch up faster
)

return homeChainPoller
return homeChain
}
func GetP2pIDs(ids ...int) map[commontypes.OracleID]libocrtypes.PeerID {
res := make(map[commontypes.OracleID]libocrtypes.PeerID)
Expand Down
Loading

0 comments on commit df2225c

Please sign in to comment.