Skip to content

Commit

Permalink
Use address type in discovery plugin. (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
winder authored Oct 31, 2024
1 parent 90546c4 commit 35a8474
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 74 deletions.
20 changes: 10 additions & 10 deletions internal/plugincommon/discovery/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,11 +125,11 @@ func (cdp *ContractDiscoveryProcessor) ValidateObservation(
// aggObs is used to store multiple observations for each value being observed.
type aggObs struct {
fChain map[cciptypes.ChainSelector][]int
onrampAddrs map[cciptypes.ChainSelector][][]byte
feeQuoterAddrs map[cciptypes.ChainSelector][][]byte
nonceManagerAddrs map[cciptypes.ChainSelector][][]byte
rmnRemoteAddrs map[cciptypes.ChainSelector][][]byte
routerAddrs map[cciptypes.ChainSelector][][]byte
onrampAddrs map[cciptypes.ChainSelector][]cciptypes.UnknownAddress
feeQuoterAddrs map[cciptypes.ChainSelector][]cciptypes.UnknownAddress
nonceManagerAddrs map[cciptypes.ChainSelector][]cciptypes.UnknownAddress
rmnRemoteAddrs map[cciptypes.ChainSelector][]cciptypes.UnknownAddress
routerAddrs map[cciptypes.ChainSelector][]cciptypes.UnknownAddress
}

// aggregateObservations combines observations for multiple objects into aggObs, which is a convenient
Expand All @@ -141,11 +141,11 @@ func aggregateObservations(
) aggObs {
obs := aggObs{
fChain: make(map[cciptypes.ChainSelector][]int),
onrampAddrs: make(map[cciptypes.ChainSelector][][]byte),
feeQuoterAddrs: make(map[cciptypes.ChainSelector][][]byte),
nonceManagerAddrs: make(map[cciptypes.ChainSelector][][]byte),
rmnRemoteAddrs: make(map[cciptypes.ChainSelector][][]byte),
routerAddrs: make(map[cciptypes.ChainSelector][][]byte),
onrampAddrs: make(map[cciptypes.ChainSelector][]cciptypes.UnknownAddress),
feeQuoterAddrs: make(map[cciptypes.ChainSelector][]cciptypes.UnknownAddress),
nonceManagerAddrs: make(map[cciptypes.ChainSelector][]cciptypes.UnknownAddress),
rmnRemoteAddrs: make(map[cciptypes.ChainSelector][]cciptypes.UnknownAddress),
routerAddrs: make(map[cciptypes.ChainSelector][]cciptypes.UnknownAddress),
}
for _, ao := range aos {
for chainSel, f := range ao.Observation.FChain {
Expand Down
124 changes: 62 additions & 62 deletions internal/plugincommon/discovery/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,26 +39,26 @@ func TestContractDiscoveryProcessor_Observation_SupportsDest_HappyPath(t *testin
dest: 1,
source: 2,
}
expectedNonceManager := []byte("nonceManager")
expectedOnRamp := map[cciptypes.ChainSelector][]byte{
source: []byte("onRamp"),
expectedNonceManager := cciptypes.UnknownAddress("nonceManager")
expectedOnRamp := map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
source: cciptypes.UnknownAddress("onRamp"),
}
expectedFeeQuoter := map[cciptypes.ChainSelector][]byte{
source: []byte("from_source_onramp"),
dest: []byte("from_dest_offramp"),
expectedFeeQuoter := map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
source: cciptypes.UnknownAddress("from_source_onramp"),
dest: cciptypes.UnknownAddress("from_dest_offramp"),
}
expectedRMNRemote := []byte("rmnRemote")
expectedRouter := []byte("router")
expectedRMNRemote := cciptypes.UnknownAddress("rmnRemote")
expectedRouter := cciptypes.UnknownAddress("router")
expectedContracts := reader.ContractAddresses{
consts.ContractNameNonceManager: map[cciptypes.ChainSelector][]byte{
consts.ContractNameNonceManager: map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
dest: expectedNonceManager,
},
consts.ContractNameOnRamp: expectedOnRamp,
consts.ContractNameFeeQuoter: expectedFeeQuoter,
consts.ContractNameRMNRemote: map[cciptypes.ChainSelector][]byte{
consts.ContractNameRMNRemote: map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
dest: expectedRMNRemote,
},
consts.ContractNameRouter: map[cciptypes.ChainSelector][]byte{
consts.ContractNameRouter: map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
source: expectedRouter,
},
}
Expand Down Expand Up @@ -218,22 +218,22 @@ func TestContractDiscoveryProcessor_Outcome_HappyPath(t *testing.T) {
source1: fSource1,
source2: fSource2,
}
expectedNonceManager := []byte("nonceManager")
expectedOnRamp := map[cciptypes.ChainSelector][]byte{
dest: []byte("onRamp"),
expectedNonceManager := cciptypes.UnknownAddress("nonceManager")
expectedOnRamp := map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
dest: cciptypes.UnknownAddress("onRamp"),
}
expectedRMNRemote := []byte("rmnRemote")
expectedRMNRemote := cciptypes.UnknownAddress("rmnRemote")
expectedContracts := reader.ContractAddresses{
consts.ContractNameNonceManager: map[cciptypes.ChainSelector][]byte{
consts.ContractNameNonceManager: map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
dest: expectedNonceManager,
},
consts.ContractNameOnRamp: expectedOnRamp,
consts.ContractNameRMNRemote: map[cciptypes.ChainSelector][]byte{
consts.ContractNameRMNRemote: map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
dest: expectedRMNRemote,
},
consts.ContractNameFeeQuoter: map[cciptypes.ChainSelector][]byte{
source1: []byte("feeQuoter1"),
source2: []byte("feeQuoter2"),
consts.ContractNameFeeQuoter: map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
source1: cciptypes.UnknownAddress("feeQuoter1"),
source2: cciptypes.UnknownAddress("feeQuoter2"),
},
consts.ContractNameRouter: {},
}
Expand All @@ -254,7 +254,7 @@ func TestContractDiscoveryProcessor_Outcome_HappyPath(t *testing.T) {

obsSrc := discoverytypes.Observation{
FChain: expectedFChain,
Addresses: map[string]map[cciptypes.ChainSelector][]byte{
Addresses: map[string]map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
consts.ContractNameOnRamp: expectedOnRamp,
consts.ContractNameNonceManager: {
dest: expectedNonceManager,
Expand Down Expand Up @@ -302,21 +302,21 @@ func TestContractDiscovery_Outcome_HappyPath_FRoleDONAndFDestChainAreDifferent(t
source1: fSource1,
source2: fSource2,
}
expectedNonceManager := []byte("nonceManager")
expectedOnRamp := map[cciptypes.ChainSelector][]byte{
dest: []byte("onRamp"),
expectedNonceManager := cciptypes.UnknownAddress("nonceManager")
expectedOnRamp := map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
dest: cciptypes.UnknownAddress("onRamp"),
}
expectedRMNRemote := []byte("rmnRemote")
expectedRMNRemote := cciptypes.UnknownAddress("rmnRemote")
expectedContracts := reader.ContractAddresses{
consts.ContractNameNonceManager: map[cciptypes.ChainSelector][]byte{
consts.ContractNameNonceManager: map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
dest: expectedNonceManager,
},
consts.ContractNameOnRamp: expectedOnRamp,
consts.ContractNameRMNRemote: map[cciptypes.ChainSelector][]byte{
consts.ContractNameRMNRemote: map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
dest: expectedRMNRemote,
},
consts.ContractNameRouter: {
dest: []byte("router"),
dest: cciptypes.UnknownAddress("router"),
},
consts.ContractNameFeeQuoter: {}, // no consensus
}
Expand All @@ -337,16 +337,16 @@ func TestContractDiscovery_Outcome_HappyPath_FRoleDONAndFDestChainAreDifferent(t

fChainObs := discoverytypes.Observation{
FChain: expectedFChain,
Addresses: map[string]map[cciptypes.ChainSelector][]byte{
Addresses: map[string]map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
consts.ContractNameFeeQuoter: {
source1: []byte("fee_quoter_1"),
source2: []byte("fee_quoter_2"),
source1: cciptypes.UnknownAddress("fee_quoter_1"),
source2: cciptypes.UnknownAddress("fee_quoter_2"),
},
},
}
destObs := discoverytypes.Observation{
FChain: expectedFChain,
Addresses: map[string]map[cciptypes.ChainSelector][]byte{
Addresses: map[string]map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
consts.ContractNameOnRamp: expectedOnRamp,
consts.ContractNameNonceManager: {
dest: expectedNonceManager,
Expand All @@ -355,7 +355,7 @@ func TestContractDiscovery_Outcome_HappyPath_FRoleDONAndFDestChainAreDifferent(t
dest: expectedRMNRemote,
},
consts.ContractNameRouter: {
dest: []byte("router"),
dest: cciptypes.UnknownAddress("router"),
},
},
}
Expand Down Expand Up @@ -396,11 +396,11 @@ func TestContractDiscoveryProcessor_Outcome_NotEnoughObservations(t *testing.T)
source1: fSource1,
source2: fSource2,
}
observedNonceManager := []byte("nonceManager")
observedRMNRemote := []byte("rmnRemote")
observedOnRamp := map[cciptypes.ChainSelector][]byte{
source1: []byte("onRamp"),
source2: []byte("onRamp"),
observedNonceManager := cciptypes.UnknownAddress("nonceManager")
observedRMNRemote := cciptypes.UnknownAddress("rmnRemote")
observedOnRamp := map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
source1: cciptypes.UnknownAddress("onRamp"),
source2: cciptypes.UnknownAddress("onRamp"),
}
// we expect no contracts here due to not enough observations to come to consensus.
expectedContracts := reader.ContractAddresses{
Expand Down Expand Up @@ -430,7 +430,7 @@ func TestContractDiscoveryProcessor_Outcome_NotEnoughObservations(t *testing.T)
}
destObs := discoverytypes.Observation{
FChain: expectedFChain,
Addresses: map[string]map[cciptypes.ChainSelector][]byte{
Addresses: map[string]map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
consts.ContractNameOnRamp: observedOnRamp,
consts.ContractNameNonceManager: {
dest: observedNonceManager,
Expand Down Expand Up @@ -479,17 +479,17 @@ func TestContractDiscoveryProcessor_Outcome_ErrorSyncingContracts(t *testing.T)
source1: fSource1,
source2: fSource2,
}
expectedNonceManager := []byte("nonceManager")
expectedOnRamp := map[cciptypes.ChainSelector][]byte{
dest: []byte("onRamp"),
expectedNonceManager := cciptypes.UnknownAddress("nonceManager")
expectedOnRamp := map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
dest: cciptypes.UnknownAddress("onRamp"),
}
expectedRMNRemote := []byte("rmnRemote")
expectedRMNRemote := cciptypes.UnknownAddress("rmnRemote")
expectedContracts := reader.ContractAddresses{
consts.ContractNameNonceManager: map[cciptypes.ChainSelector][]byte{
consts.ContractNameNonceManager: map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
dest: expectedNonceManager,
},
consts.ContractNameOnRamp: expectedOnRamp,
consts.ContractNameRMNRemote: map[cciptypes.ChainSelector][]byte{
consts.ContractNameRMNRemote: map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
dest: expectedRMNRemote,
},
consts.ContractNameFeeQuoter: {},
Expand All @@ -513,7 +513,7 @@ func TestContractDiscoveryProcessor_Outcome_ErrorSyncingContracts(t *testing.T)

obs := discoverytypes.Observation{
FChain: expectedFChain,
Addresses: map[string]map[cciptypes.ChainSelector][]byte{
Addresses: map[string]map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
consts.ContractNameOnRamp: expectedOnRamp,
consts.ContractNameNonceManager: {
dest: expectedNonceManager,
Expand Down Expand Up @@ -647,46 +647,46 @@ func TestContractDiscoveryProcessor_ValidateObservation_OracleNotAllowedToObserv
},
{
name: "onramps are only discovered on dest (error)",
addresses: map[string]map[cciptypes.ChainSelector][]byte{
addresses: map[string]map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
consts.ContractNameOnRamp: {
dest + 1: []byte("1"),
dest + 2: []byte("2"),
dest + 3: []byte("3"),
dest + 1: cciptypes.UnknownAddress("1"),
dest + 2: cciptypes.UnknownAddress("2"),
dest + 3: cciptypes.UnknownAddress("3"),
},
},
errStr: "oracle 1 is not allowed to observe contract (OnRamp) on the destination chain ChainSelector(1)",
},
{
name: "onramps are only discovered on dest (pass)",
supportedChains: []cciptypes.ChainSelector{dest},
addresses: map[string]map[cciptypes.ChainSelector][]byte{
addresses: map[string]map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
consts.ContractNameOnRamp: {
dest + 1: []byte("1"),
dest + 2: []byte("2"),
dest + 3: []byte("3"),
dest + 1: cciptypes.UnknownAddress("1"),
dest + 2: cciptypes.UnknownAddress("2"),
dest + 3: cciptypes.UnknownAddress("3"),
},
},
},
{
name: "FeeQuoter is discovered on the same chain (error)",
supportedChains: []cciptypes.ChainSelector{dest},
addresses: map[string]map[cciptypes.ChainSelector][]byte{
addresses: map[string]map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
consts.ContractNameFeeQuoter: {
dest + 1: []byte("1"),
dest + 2: []byte("2"),
dest + 3: []byte("3"),
dest + 1: cciptypes.UnknownAddress("1"),
dest + 2: cciptypes.UnknownAddress("2"),
dest + 3: cciptypes.UnknownAddress("3"),
},
},
errStr: "oracle 1 is not allowed to observe chain ChainSelector",
},
{
name: "FeeQuoter is discovered on the same chain (pass)",
supportedChains: []cciptypes.ChainSelector{dest + 1, dest + 2, dest + 3},
addresses: map[string]map[cciptypes.ChainSelector][]byte{
addresses: map[string]map[cciptypes.ChainSelector]cciptypes.UnknownAddress{
consts.ContractNameFeeQuoter: {
dest + 1: []byte("1"),
dest + 2: []byte("2"),
dest + 3: []byte("3"),
dest + 1: cciptypes.UnknownAddress("1"),
dest + 2: cciptypes.UnknownAddress("2"),
dest + 3: cciptypes.UnknownAddress("3"),
},
},
},
Expand Down
4 changes: 2 additions & 2 deletions pkg/reader/ccip_interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@ var (

// ContractAddresses is a map of contract names across all chain selectors and their address.
// Currently only one contract per chain per name is supported.
type ContractAddresses map[string]map[cciptypes.ChainSelector][]byte
type ContractAddresses map[string]map[cciptypes.ChainSelector]cciptypes.UnknownAddress

func (ca ContractAddresses) Append(contract string, chain cciptypes.ChainSelector, address []byte) ContractAddresses {
resp := ca
if resp == nil {
resp = make(ContractAddresses)
}
if resp[contract] == nil {
resp[contract] = make(map[cciptypes.ChainSelector][]byte)
resp[contract] = make(map[cciptypes.ChainSelector]cciptypes.UnknownAddress)
}
resp[contract][chain] = address
return resp
Expand Down

0 comments on commit 35a8474

Please sign in to comment.