diff --git a/commit/plugin_e2e_test.go b/commit/plugin_e2e_test.go index 872ed29f2..ac87c5959 100644 --- a/commit/plugin_e2e_test.go +++ b/commit/plugin_e2e_test.go @@ -404,18 +404,28 @@ func newNode( func setupHomeChainPoller(lggr logger.Logger, chainConfigInfos []reader.ChainConfigInfo) reader.HomeChain { homeChainReader := mocks.NewContractReaderMock() + var firstCall = true homeChainReader.On( "GetLatestValue", mock.Anything, consts.ContractNameCCIPConfig, consts.MethodNameGetAllChainConfigs, mock.Anything, - mock.Anything, + mock.MatchedBy(func(input map[string]interface{}) bool { + _, pageIndexExists := input["pageIndex"] + _, pageSizeExists := input["pageSize"] + return pageIndexExists && pageSizeExists + }), mock.Anything, ).Run( func(args mock.Arguments) { arg := args.Get(5).(*[]reader.ChainConfigInfo) - *arg = chainConfigInfos + if firstCall { + *arg = chainConfigInfos + firstCall = false + } else { + *arg = []reader.ChainConfigInfo{} // return empty for other pages + } }).Return(nil) homeChain := reader.NewHomeChainConfigPoller( diff --git a/execute/plugin_e2e_test.go b/execute/plugin_e2e_test.go index 98eecba6f..b58612bb5 100644 --- a/execute/plugin_e2e_test.go +++ b/execute/plugin_e2e_test.go @@ -83,18 +83,28 @@ type nodeSetup struct { func setupHomeChainPoller(lggr logger.Logger, chainConfigInfos []reader.ChainConfigInfo) reader.HomeChain { homeChainReader := mocks.NewContractReaderMock() + var firstCall = true homeChainReader.On( "GetLatestValue", mock.Anything, consts.ContractNameCCIPConfig, consts.MethodNameGetAllChainConfigs, mock.Anything, - mock.Anything, + mock.MatchedBy(func(input map[string]interface{}) bool { + _, pageIndexExists := input["pageIndex"] + _, pageSizeExists := input["pageSize"] + return pageIndexExists && pageSizeExists + }), mock.Anything, ).Run( func(args mock.Arguments) { arg := args.Get(5).(*[]reader.ChainConfigInfo) - *arg = chainConfigInfos + if firstCall { + *arg = chainConfigInfos + firstCall = false + } else { + *arg = []reader.ChainConfigInfo{} // return empty for other pages + } }).Return(nil) homeChain := reader.NewHomeChainConfigPoller( diff --git a/internal/reader/home_chain.go b/internal/reader/home_chain.go index 02cf357f6..f13043949 100644 --- a/internal/reader/home_chain.go +++ b/internal/reader/home_chain.go @@ -20,6 +20,11 @@ import ( "github.com/smartcontractkit/chainlink-ccip/pkg/consts" ) +const ( + defaultConfigPageSize = uint64(100) +) + +//go:generate mockery --name HomeChain --output ./mocks/ --case underscore type HomeChain interface { GetChainConfig(chainSelector cciptypes.ChainSelector) (ChainConfig, error) GetAllChainConfigs() (map[cciptypes.ChainSelector]ChainConfig, error) @@ -121,24 +126,43 @@ func (r *homeChainPoller) poll() { } func (r *homeChainPoller) fetchAndSetConfigs(ctx context.Context) error { - var chainConfigInfos []ChainConfigInfo - err := r.homeChainReader.GetLatestValue( - ctx, - consts.ContractNameCCIPConfig, - consts.MethodNameGetAllChainConfigs, - primitives.Unconfirmed, - nil, - &chainConfigInfos, - ) - if err != nil { - return err + var allChainConfigInfos []ChainConfigInfo + pageIndex := uint64(0) + + for { + var chainConfigInfos []ChainConfigInfo + err := r.homeChainReader.GetLatestValue( + ctx, + consts.ContractNameCCIPConfig, + consts.MethodNameGetAllChainConfigs, + primitives.Unconfirmed, + map[string]interface{}{ + "pageIndex": pageIndex, + "pageSize": defaultConfigPageSize, + }, + &chainConfigInfos, + ) + if err != nil { + return fmt.Errorf("get config index:%d pagesize:%d: %w", pageIndex, defaultConfigPageSize, err) + } + + allChainConfigInfos = append(allChainConfigInfos, chainConfigInfos...) + + if uint64(len(chainConfigInfos)) < defaultConfigPageSize { + break + } + + pageIndex++ } - if len(chainConfigInfos) == 0 { + + r.setState(convertOnChainConfigToHomeChainConfig(r.lggr, allChainConfigInfos)) + + if len(allChainConfigInfos) == 0 { // That's a legitimate case if there are no chain configs on chain yet r.lggr.Warnw("no on chain configs found") return nil } - r.setState(convertOnChainConfigToHomeChainConfig(r.lggr, chainConfigInfos)) + return nil }