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

Pass the RMNRemote address instead of proxy #265

Merged
merged 2 commits into from
Oct 24, 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
4 changes: 4 additions & 0 deletions pkg/consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const (
ContractNameNonceManager = "NonceManager"
ContractNameRMNHome = "RMNHome"
ContractNameRMNRemote = "RMNRemote"
ContractNameRMNProxy = "RMNProxy"
ContractNameRouter = "Router"
ContractNameCCTPMessageTransmitter = "MessageTransmitter"
)
Expand Down Expand Up @@ -104,6 +105,9 @@ const (
// Used by the rmn remote reader.
MethodNameGetVersionedConfig = "GetVersionedConfig"
MethodNameGetReportDigestHeader = "GetReportDigestHeader"

// RMNProxy.sol methods
MethodNameGetARM = "GetARM"
)

// Event Names
Expand Down
47 changes: 42 additions & 5 deletions pkg/reader/ccip.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,11 +569,19 @@ func (r *ccipChainReader) GetRMNRemoteConfig(
return rmntypes.RemoteConfig{}, err
}

contractAddress, err := r.GetContractAddress(consts.ContractNameRMNRemote, destChainSelector)
// RMNRemote address stored in the offramp static config is actually the proxy contract address.
// Here we will get the RMNRemote address from the proxy contract by calling the RMNProxy contract.
proxyContractAddress, err := r.GetContractAddress(consts.ContractNameRMNRemote, destChainSelector)
0xnogo marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return rmntypes.RemoteConfig{}, fmt.Errorf("get RMNRemote contract address: %w", err)
return rmntypes.RemoteConfig{}, fmt.Errorf("get RMNRemote proxy contract address: %w", err)
}

rmnRemoteAddress, err := r.getRMNRemoteAddress(ctx, destChainSelector, proxyContractAddress)
if err != nil {
return rmntypes.RemoteConfig{}, fmt.Errorf("get RMNRemote address: %w", err)
}
r.lggr.Debugw("got RMNRemote address", "address", rmnRemoteAddress)

// TODO: make the calls in parallel using errgroup
var vc versionedConfig
err = r.contractReaders[destChainSelector].ExtendedGetLatestValue(
Expand Down Expand Up @@ -615,7 +623,7 @@ func (r *ccipChainReader) GetRMNRemoteConfig(
}

return rmntypes.RemoteConfig{
ContractAddress: contractAddress,
ContractAddress: rmnRemoteAddress,
ConfigDigest: cciptypes.Bytes32(vc.Config.RMNHomeContractConfigDigest),
Signers: signers,
MinSigners: vc.Config.MinSigners,
Expand Down Expand Up @@ -668,7 +676,7 @@ func (r *ccipChainReader) discoverOffRampContracts(
&staticConfig,
)
if err != nil {
return nil, fmt.Errorf("unable to lookup nonce manager and rmn remote (offramp static config): %w", err)
return nil, fmt.Errorf("unable to lookup nonce manager and rmn proxy remote (offramp static config): %w", err)
}
resp = resp.Append(consts.ContractNameNonceManager, chain, staticConfig.NonceManager)
resp = resp.Append(consts.ContractNameRMNRemote, chain, staticConfig.RmnRemote)
Expand Down Expand Up @@ -1225,12 +1233,41 @@ type config struct {
MinSigners uint64 `json:"minSigners"`
}

// versionnedConfig is used to parse the response from the RMNRemote contract's getVersionedConfig method.
// versionedConfig is used to parse the response from the RMNRemote contract's getVersionedConfig method.
// See: https://github.com/smartcontractkit/ccip/blob/ccip-develop/contracts/src/v0.8/ccip/rmn/RMNRemote.sol#L167-L169
type versionedConfig struct {
Version uint32 `json:"version"`
Config config `json:"config"`
}

// getARM gets the RMN remote address from the RMN proxy address.
// See: https://github.com/smartcontractkit/chainlink/blob/3c7817c566c5d0aa14519c679fa85b227ac97cc5/contracts/src/v0.8/ccip/rmn/ARMProxy.sol#L40-L44
//
//nolint:lll
func (r *ccipChainReader) getRMNRemoteAddress(
ctx context.Context,
chain cciptypes.ChainSelector,
rmnRemoteProxyAddress []byte) ([]byte, error) {
_, err := bindExtendedReaderContract(ctx, r.lggr, r.contractReaders, chain, consts.ContractNameRMNProxy, rmnRemoteProxyAddress)
if err != nil {
return nil, fmt.Errorf("bind RMN proxy contract: %w", err)
}

// get the RMN remote address from the proxy
var rmnRemoteAddress []byte
err = r.getDestinationData(
ctx,
chain,
consts.ContractNameRMNProxy,
consts.MethodNameGetARM,
&rmnRemoteAddress,
)
if err != nil {
return nil, fmt.Errorf("unable to lookup RMN remote address (RMN proxy): %w", err)
}

return rmnRemoteAddress, nil
}

// Interface compliance check
var _ CCIPReader = (*ccipChainReader)(nil)
Loading