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

modify the getAllChainConfigs function call from smartcontract with pagination based logic #21

Closed
wants to merge 18 commits into from

Conversation

defistar
Copy link
Contributor

@defistar defistar commented Jul 4, 2024

feat: CCIP-2594 modify the getAllChainConfigs function call from smartcontract with pagination based logic

@defistar defistar self-assigned this Jul 4, 2024
@defistar defistar marked this pull request as draft July 4, 2024 11:24
return err
var allChainConfigInfos []ChainConfigInfo
pageIndex := uint64(0)
pageSize := uint64(500)

Choose a reason for hiding this comment

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

suggestion: should we make this configurable through the function params, or separate it out as a const to another file / top of file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

will be moving to constant on top of same file

},
&chainConfigInfos,
)
if err != nil {

Choose a reason for hiding this comment

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

q: when do we get an error? Is it always guaranteed to return an empty array if I am accessing out of bounds pages (e.g. 10 pages beyond what is available)?

Should we add a comment that we always expect a result to be returned?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it returns anempty array in absence of any data, will never throw errors
there could be scenarios due to rpc issues

// 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(chainConfigInfos))
r.setState(convertOnChainConfigToHomeChainConfig(allChainConfigInfos))

Choose a reason for hiding this comment

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

q: why are we skipping state sets when there are no configs? Isn't an empty array a valid state?

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 was an existing approach, yeah in case if the contract function returns empty array
we can still set it but isnt it redundant execution where we can retain initial state as-is
unless there are entries earluer and for some reason the config is removed and state is stale
is this a valid scenario?

Choose a reason for hiding this comment

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

It could save a null pointer reference though down the line - my thinking is that would be less error-prone

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated to set in case if results are empty or non-empty

@defistar defistar marked this pull request as ready for review July 16, 2024 14:25
@defistar defistar requested a review from elatoskinas July 17, 2024 03:33
@@ -392,6 +392,8 @@ func newNode(
homeChain,
)

//ccipReader.On("Sync", mock.Anything).Return(true, nil)

Choose a reason for hiding this comment

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

nit: should we remove this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed

pageIndex++
}

if len(allChainConfigInfos) >= 0 {

Choose a reason for hiding this comment

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

suggestion: the check is redundant - the length of an array will always be >= 0 - we can remove it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed redundant check

@@ -16,7 +16,10 @@ import (
cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3"
)

//go:generate mockery --name HomeChain --output ./mocks/ --case underscore

Choose a reason for hiding this comment

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

q: shouldn't we keep this? Are the mocks generated somewhere else?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed the obselete comment

Copy link
Contributor

Choose a reason for hiding this comment

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

@defistar wdym?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

there was a comment added to use mockery command. that was not supposed to be here.it must be in readme doc.
so deleted that from code @dimkouv

Choose a reason for hiding this comment

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

https://vektra.github.io/mockery/latest/#why-mockery - the purpose of the comment is a directive to generate mockery mocks from my understanding (see //go:generate mockery --name DB example) - adding it to the README would not apply any change. Could you elaborate on why you think it's not supposed to be here?

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should keep the go:generate here.
Created the ticket CCIP-2901 that @winder will work on.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

retained the comment back

@defistar defistar requested a review from elatoskinas July 17, 2024 12:39
@defistar defistar force-pushed the feature/CCIP-2594-CCIPConfigPagination branch from 0ce9024 to 7fcacb7 Compare July 29, 2024 19:53
@@ -78,18 +78,28 @@ type nodeSetup struct {

func setupHomeChainPoller(lggr logger.Logger, chainConfigInfos []reader.ChainConfigInfo) reader.HomeChain {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we de-dup func setupHomeChainPoller in a follow-up maybe?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

should we create a JIRA task for this to followup? @dimkouv

Copy link
Contributor

Choose a reason for hiding this comment

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

yes, create one pls

@@ -16,7 +16,10 @@ import (
cciptypes "github.com/smartcontractkit/chainlink-common/pkg/types/ccipocr3"
)

//go:generate mockery --name HomeChain --output ./mocks/ --case underscore
Copy link
Contributor

Choose a reason for hiding this comment

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

@defistar wdym?

pageIndex := uint64(0)

for {
var chainConfigInfos []ChainConfigInfo
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add something like the following for extra safety?

const pageIndexHardLimit = 100

for {
   ...
   pageIndex++

   if pageIndex > pageIndexHardLimit {
      return fmt.Errorf("something is wrong!")
   }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added extra safety with hardCap for pageIndex
its included in for loop and once for loop exits we check if the pageIndex > pageIndexHardLimit
log a warn message

but wouldnt this cap the max chains we can extract the config from?

@dimkouv

Copy link
Contributor

Choose a reason for hiding this comment

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

We can add some big value for the limit.

Choose a reason for hiding this comment

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

Why do we need a hard limit, as opposed to just giving a warning and fetching everything?

Choose a reason for hiding this comment

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

I think it would be painful to debug if we don't return all pages and just emit a warning (as opposed to either returning all pages, or throwing an exception)

&chainConfigInfos,
)
if err != nil {
return err
Copy link
Contributor

Choose a reason for hiding this comment

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

let's wrap that err "get config index:1 pagesize:2: <err>"

Copy link
Contributor Author

Choose a reason for hiding this comment

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

u[pdated with error wrapping

@@ -19,7 +19,10 @@ import (
"github.com/smartcontractkit/chainlink-ccip/pkg/consts"
)

//go:generate mockery --name HomeChain --output ./mocks/ --case underscore
const (
PageSize = uint64(500)
Copy link
Contributor

Choose a reason for hiding this comment

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

no need to export, also better to rename defaultConfigPageSize.
Isn't 500 too much?, I would expect something closer to 10

Copy link
Contributor Author

Choose a reason for hiding this comment

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

u[pdated

@defistar defistar added the enhancement New feature or request label Jul 30, 2024
Copy link

Test Coverage

Branch Coverage
feature/CCIP-2594-CCIPConfigPagination 77.5%
ccip-develop 77.4%

@defistar defistar requested a review from elatoskinas July 31, 2024 10:40
@defistar defistar closed this Aug 16, 2024
@mateusz-sekara mateusz-sekara deleted the feature/CCIP-2594-CCIPConfigPagination branch November 8, 2024 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants