Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Accept home chain selector id in commit plugin factory #140

Merged
merged 23 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 50 additions & 16 deletions commit/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package commit

import (
"context"
"encoding/hex"
"errors"
"fmt"
"time"

"google.golang.org/grpc"

Expand All @@ -28,6 +30,7 @@ import (

const maxReportTransmissionCheckAttempts = 5
const maxQueryLength = 1024 * 1024 // 1MB
const rmnEnabled = false

// PluginFactoryConstructor implements common OCR3ReportingPluginClient and is used for initializing a plugin factory
// and a validation service.
Expand Down Expand Up @@ -56,14 +59,15 @@ func (p PluginFactoryConstructor) NewValidationService(ctx context.Context) (cor

// PluginFactory implements common ReportingPluginFactory and is used for (re-)initializing commit plugin instances.
type PluginFactory struct {
lggr logger.Logger
donID plugintypes.DonID
ocrConfig reader.OCR3ConfigWithMeta
commitCodec cciptypes.CommitPluginCodec
msgHasher cciptypes.MessageHasher
homeChainReader reader.HomeChain
contractReaders map[cciptypes.ChainSelector]types.ContractReader
chainWriters map[cciptypes.ChainSelector]types.ChainWriter
lggr logger.Logger
donID plugintypes.DonID
ocrConfig reader.OCR3ConfigWithMeta
commitCodec cciptypes.CommitPluginCodec
msgHasher cciptypes.MessageHasher
homeChainReader reader.HomeChain
homeChainSelector cciptypes.ChainSelector
contractReaders map[cciptypes.ChainSelector]types.ContractReader
chainWriters map[cciptypes.ChainSelector]types.ChainWriter
}

func NewPluginFactory(
Expand All @@ -73,18 +77,20 @@ func NewPluginFactory(
commitCodec cciptypes.CommitPluginCodec,
msgHasher cciptypes.MessageHasher,
homeChainReader reader.HomeChain,
homeChainSelector cciptypes.ChainSelector,
contractReaders map[cciptypes.ChainSelector]types.ContractReader,
chainWriters map[cciptypes.ChainSelector]types.ChainWriter,
) *PluginFactory {
return &PluginFactory{
lggr: lggr,
donID: donID,
ocrConfig: ocrConfig,
commitCodec: commitCodec,
msgHasher: msgHasher,
homeChainReader: homeChainReader,
contractReaders: contractReaders,
chainWriters: chainWriters,
lggr: lggr,
donID: donID,
ocrConfig: ocrConfig,
commitCodec: commitCodec,
msgHasher: msgHasher,
homeChainReader: homeChainReader,
homeChainSelector: homeChainSelector,
contractReaders: contractReaders,
chainWriters: chainWriters,
}
}

Expand All @@ -104,6 +110,32 @@ func (p *PluginFactory) NewReportingPlugin(config ocr3types.ReportingPluginConfi
oracleIDToP2PID[commontypes.OracleID(oracleID)] = p2pID
}

// Bind the RMNHome contract
var rmnHomeReader reader.RMNHome
if rmnEnabled {
rmnHomeAddress := p.ocrConfig.Config.RmnHomeAddress
rmnCr, ok := p.contractReaders[p.homeChainSelector]
if !ok {
return nil,
ocr3types.ReportingPluginInfo{},
fmt.Errorf("failed to find contract reader for home chain %d", p.homeChainSelector)
}
rmnHomeBoundContract := types.BoundContract{
Address: "0x" + hex.EncodeToString(rmnHomeAddress),
0xnogo marked this conversation as resolved.
Show resolved Hide resolved
Name: consts.ContractNameRMNHome,
}

if err1 := rmnCr.Bind(context.Background(), []types.BoundContract{rmnHomeBoundContract}); err1 != nil {
return nil, ocr3types.ReportingPluginInfo{}, fmt.Errorf("failed to bind RMNHome contract: %w", err1)
}
rmnHomeReader = reader.NewRMNHomePoller(
rmnCr,
rmnHomeBoundContract,
p.lggr,
100*time.Millisecond,
)
}

var onChainTokenPricesReader reader.PriceReader
// The node supports the chain that the token prices are on.
tokenPricesCr, ok := p.contractReaders[offchainConfig.PriceFeedChainSelector]
Expand Down Expand Up @@ -148,13 +180,15 @@ func (p *PluginFactory) NewReportingPlugin(config ocr3types.ReportingPluginConfi
NewMsgScanBatchSize: merklemulti.MaxNumberTreeLeaves,
MaxReportTransmissionCheckAttempts: maxReportTransmissionCheckAttempts,
OffchainConfig: offchainConfig,
RMNEnabled: rmnEnabled,
},
ccipReader,
onChainTokenPricesReader,
p.commitCodec,
p.msgHasher,
p.lggr,
p.homeChainReader,
rmnHomeReader,
config,
rmn.Config{}, // todo
), ocr3types.ReportingPluginInfo{
Expand Down
43 changes: 23 additions & 20 deletions commit/merkleroot/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,17 @@ import (
// It's setup to use RMN to query which messages to include in the merkle root and ensures
// the newly built merkle roots are the same as RMN roots.
type Processor struct {
oracleID commontypes.OracleID
cfg pluginconfig.CommitPluginConfig
lggr logger.Logger
observer Observer
ccipReader readerpkg.CCIPReader
reportingCfg ocr3types.ReportingPluginConfig
chainSupport plugincommon.ChainSupport
rmnClient rmn.Controller
rmnCrypto cciptypes.RMNCrypto
rmnConfig rmn.Config
oracleID commontypes.OracleID
cfg pluginconfig.CommitPluginConfig
lggr logger.Logger
observer Observer
ccipReader readerpkg.CCIPReader
reportingCfg ocr3types.ReportingPluginConfig
chainSupport plugincommon.ChainSupport
rmnClient rmn.Controller
rmnCrypto cciptypes.RMNCrypto
rmnConfig rmn.Config
rmnHomeReader reader.RMNHome
}

// NewProcessor creates a new Processor
Expand All @@ -44,6 +45,7 @@ func NewProcessor(
rmnClient rmn.Controller,
rmnCrypto cciptypes.RMNCrypto,
rmnConfig rmn.Config,
rmnHomeReader reader.RMNHome,
) *Processor {
observer := ObserverImpl{
lggr,
Expand All @@ -54,16 +56,17 @@ func NewProcessor(
msgHasher,
}
return &Processor{
oracleID: oracleID,
cfg: cfg,
lggr: lggr,
observer: observer,
ccipReader: ccipReader,
reportingCfg: reportingCfg,
chainSupport: chainSupport,
rmnClient: rmnClient,
rmnCrypto: rmnCrypto,
rmnConfig: rmnConfig,
oracleID: oracleID,
cfg: cfg,
lggr: lggr,
observer: observer,
ccipReader: ccipReader,
reportingCfg: reportingCfg,
chainSupport: chainSupport,
rmnClient: rmnClient,
rmnCrypto: rmnCrypto,
rmnConfig: rmnConfig,
rmnHomeReader: rmnHomeReader,
}
}

Expand Down
4 changes: 4 additions & 0 deletions commit/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type Plugin struct {
reportCodec cciptypes.CommitPluginCodec
lggr logger.Logger
homeChain reader.HomeChain
rmnHomeReader reader.RMNHome
reportingCfg ocr3types.ReportingPluginConfig
chainSupport plugincommon.ChainSupport
merkleRootProcessor plugincommon.PluginProcessor[merkleroot.Query, merkleroot.Observation, merkleroot.Outcome]
Expand All @@ -64,6 +65,7 @@ func NewPlugin(
msgHasher cciptypes.MessageHasher,
lggr logger.Logger,
homeChain reader.HomeChain,
rmnHomeReader reader.RMNHome,
reportingCfg ocr3types.ReportingPluginConfig,
rmnConfig rmn.Config,
) *Plugin {
Expand Down Expand Up @@ -93,6 +95,7 @@ func NewPlugin(
rmn.Controller(nil), // todo
cciptypes.RMNCrypto(nil), // todo
rmnConfig,
rmnHomeReader,
)

tokenPriceProcessor := tokenprice.NewProcessor(
Expand Down Expand Up @@ -133,6 +136,7 @@ func NewPlugin(
tokenPricesReader: tokenPricesReader,
ccipReader: ccipReader,
homeChain: homeChain,
rmnHomeReader: rmnHomeReader,
reportCodec: reportCodec,
reportingCfg: reportingCfg,
chainSupport: chainSupport,
Expand Down
2 changes: 2 additions & 0 deletions commit/plugin_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,7 @@ func setupNode(
reportCodec := mocks.NewCommitPluginJSONReportCodec()
msgHasher := mocks.NewMessageHasher()
homeChainReader := reader_mock.NewMockHomeChain(t)
rmnHomeReader := reader_mock.NewMockRMNHome(t)

fChain := map[ccipocr3.ChainSelector]int{}
supportedChainsForPeer := make(map[libocrtypes.PeerID]mapset.Set[ccipocr3.ChainSelector])
Expand Down Expand Up @@ -377,6 +378,7 @@ func setupNode(
msgHasher,
lggr,
homeChainReader,
rmnHomeReader,
reportingCfg,
rmn.Config{},
)
Expand Down
1 change: 1 addition & 0 deletions internal/reader/home_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ type OCR3Config struct {
F uint8 `json:"F"`
OffchainConfigVersion uint64 `json:"offchainConfigVersion"`
OfframpAddress []byte `json:"offrampAddress"`
RmnHomeAddress []byte `json:"rmnHomeAddress"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause all tests to fail because this is not on-chain yet. I think we should remove this for now and maybe add later when its finally in there?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be just empty? We are not using it (under the rmn feature flag).

It seems like ccip integ test are passing here: smartcontractkit/chainlink#14500

P2PIds [][32]byte `json:"p2pIds"`
Signers [][]byte `json:"signers"`
Transmitters [][]byte `json:"transmitters"`
Expand Down
Loading