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

RMN home and remote readers #137

Merged
merged 11 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 2 additions & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ packages:
github.com/smartcontractkit/chainlink-ccip/internal/reader:
interfaces:
HomeChain:
RMNHome:
RMNRemote:
CCIP:
PriceReader:
github.com/smartcontractkit/chainlink-ccip/internal/reader/contractreader:
Expand Down
78 changes: 78 additions & 0 deletions commit/merkleroot/rmn/types/config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package types

import (
"crypto/ed25519"

mapset "github.com/deckarep/golang-set/v2"

cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3"
)

type NodeID uint32
0xnogo marked this conversation as resolved.
Show resolved Hide resolved

// RMNHomeConfig contains the configuration fetched from the RMNHome contract.
type RMNHomeConfig struct {
Nodes []RMNHomeNodeInfo
SourceChainMinObservers map[cciptypes.ChainSelector]uint64
ConfigDigest cciptypes.Bytes32
OffchainConfig cciptypes.Bytes // The raw offchain config
}

// RMNHomeNodeInfo contains information about a node from the RMNHome contract.
type RMNHomeNodeInfo struct {
ID NodeID // ID is the index of this node in the RMN config
PeerID cciptypes.Bytes32 // The peer ID of the node
0xnogo marked this conversation as resolved.
Show resolved Hide resolved
SupportedSourceChains mapset.Set[cciptypes.ChainSelector] // Set of supported source chains by the node
OffchainPublicKey *ed25519.PublicKey // The private key is used to verify observations
0xnogo marked this conversation as resolved.
Show resolved Hide resolved
}

// RMNRemoteConfig contains the configuration fetched from the RMNRemote contract.
type RMNRemoteConfig struct {
ContractAddress cciptypes.Bytes
ConfigDigest cciptypes.Bytes32
Signers []RMNRemoteSignerInfo
MinSigners uint64
0xnogo marked this conversation as resolved.
Show resolved Hide resolved
ConfigVersion uint32
RmnReportVersion string // e.g., "RMN_V1_6_ANY2EVM_REPORT"
}

// RMNRemoteSignerInfo contains information about a signer from the RMNRemote contract.
type RMNRemoteSignerInfo struct {
SignerOnchainAddress cciptypes.Bytes // The signer's onchain address, used to verify report signature
0xnogo marked this conversation as resolved.
Show resolved Hide resolved
NodeIndex uint64 // The index of the node in the RMN config
SignObservationPrefix string // The prefix of the observation to sign
}

// VersionedConfigWithDigest mirrors RMNHome.sol's VersionedConfigWithDigest struct
type VersionedConfigWithDigest struct {
0xnogo marked this conversation as resolved.
Show resolved Hide resolved
// nolint:lll // don't split up the long url
// https://github.com/smartcontractkit/ccip/blob/e6e26ad31eef625faf68806a2b4f0549bc89b15c/contracts/src/v0.8/ccip/RMNRemote.sol#L34
ConfigDigest cciptypes.Bytes32 `json:"configDigest"`
VersionedConfig VersionedConfig `json:"versionedConfig"`
}

// VersionedConfig mirrors RMNHome.sol's VersionedConfig struct
type VersionedConfig struct {
Version uint32 `json:"version"`
Config Config `json:"config"`
}

// Config mirrors RMNHome.sol's Config struct
type Config struct {
Nodes []Node `json:"nodes"`
SourceChains []SourceChain `json:"sourceChains"`
OffchainConfig cciptypes.Bytes `json:"offchainConfig"`
}

// Node mirrors RMNHome.sol's Node struct
type Node struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need both? Seems like duplicate

Copy link
Contributor

Choose a reason for hiding this comment

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

or maybe this should not be exported?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This one is used as an interface between the contract and the reader. It's actually handy to have it exporter as it is used in the tests.

I wonder if we going to have these struct in the gethwrappers? This would allow us to remote them.

Copy link
Collaborator

Choose a reason for hiding this comment

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

The structs will be exported in the gethwrappers but we don't have access to gethwrappers here so we have to do this duplication.

Copy link
Contributor

Choose a reason for hiding this comment

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

What Makram said and we should have it generic enough as well. What if we change home chain to be non EVM in the future.

PeerID cciptypes.Bytes32 `json:"peerId"`
OffchainPublicKey cciptypes.Bytes32 `json:"offchainPublicKey"`
}

// SourceChain mirrors RMNHome.sol's SourceChain struct
type SourceChain struct {
ChainSelector cciptypes.ChainSelector `json:"chainSelector"`
MinObservers uint64 `json:"minObservers"`
ObserverNodesBitmap cciptypes.BigInt `json:"observerNodesBitmap"`
}
29 changes: 7 additions & 22 deletions internal/reader/home_chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/stretchr/testify/mock"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/libocr/commontypes"
libocrtypes "github.com/smartcontractkit/libocr/ragep2p/types"

"github.com/smartcontractkit/chainlink-common/pkg/logger"
Expand All @@ -23,15 +22,10 @@ import (
)

var (
chainA = cciptypes.ChainSelector(1)
chainB = cciptypes.ChainSelector(2)
chainC = cciptypes.ChainSelector(3)
oracleAId = commontypes.OracleID(1)
p2pOracleAId = libocrtypes.PeerID{byte(oracleAId)}
oracleBId = commontypes.OracleID(2)
p2pOracleBId = libocrtypes.PeerID{byte(oracleBId)}
oracleCId = commontypes.OracleID(3)
p2pOracleCId = libocrtypes.PeerID{byte(oracleCId)}
ccipConfigBoundContract = types.BoundContract{
Address: "0xCCIPConfigFakeAddress",
Name: consts.ContractNameCCIPConfig,
}
)

func TestHomeChainConfigPoller_HealthReport(t *testing.T) {
Expand All @@ -52,10 +46,7 @@ func TestHomeChainConfigPoller_HealthReport(t *testing.T) {
homeChainReader,
logger.Test(t),
tickTime,
types.BoundContract{
Address: "0xCCIPConfigFakeAddress",
Name: consts.ContractNameCCIPConfig,
},
ccipConfigBoundContract,
)
require.NoError(t, configPoller.Start(context.Background()))
// Initially it's healthy
Expand Down Expand Up @@ -151,10 +142,7 @@ func Test_PollingWorking(t *testing.T) {
homeChainReader,
logger.Test(t),
tickTime,
types.BoundContract{
Address: "0xCCIPConfigFakeAddress",
Name: consts.ContractNameCCIPConfig,
},
ccipConfigBoundContract,
)

require.NoError(t, configPoller.Start(context.Background()))
Expand Down Expand Up @@ -209,10 +197,7 @@ func Test_HomeChainPoller_GetOCRConfig(t *testing.T) {
homeChainReader,
logger.Test(t),
10*time.Millisecond,
types.BoundContract{
Address: "0xCCIPConfigFakeAddress",
Name: consts.ContractNameCCIPConfig,
},
ccipConfigBoundContract,
)

configs, err := configPoller.GetOCRConfigs(context.Background(), donID, pluginType)
Expand Down
Loading
Loading