Skip to content

Commit

Permalink
feat: CCIP-2495 ConfigPagination for CCIPConfig (#53)
Browse files Browse the repository at this point in the history
* feat: CCIP-2495 ConfigPagination for CCIPConfig

* fix: CCIP-2594 optimise pagination termination condition for ccip-config

* fix: CCIP-2594 pagination fix for ccip-config query

* fix: CCIP-2594 CCIPConfig Pagination query fix

* fix: CCIP-2594 remove pageIndex HardLimit for query on CCIPConfig

* fix: CCIP-2594 Poller Test assertion updated
  • Loading branch information
defistar authored Aug 16, 2024
1 parent 7bdc5fd commit 48726fd
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 17 deletions.
14 changes: 12 additions & 2 deletions commit/plugin_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
14 changes: 12 additions & 2 deletions execute/plugin_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
50 changes: 37 additions & 13 deletions internal/reader/home_chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 48726fd

Please sign in to comment.