-
Notifications
You must be signed in to change notification settings - Fork 5
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
Changes from 12 commits
74e7469
c11a9aa
c27f997
a693127
7fcacb7
a7e28ab
a555251
505afe3
1c94481
170ba79
61bd0c9
87753bb
b7ba839
73a0f3a
5bbd178
b958ca9
d665203
595aa83
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,10 @@ import ( | |
"github.com/smartcontractkit/chainlink-ccip/pkg/consts" | ||
) | ||
|
||
//go:generate mockery --name HomeChain --output ./mocks/ --case underscore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. q: shouldn't we keep this? Are the mocks generated somewhere else? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. removed the obselete comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @defistar wdym? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should keep the go:generate here. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. retained the comment back |
||
const ( | ||
PageSize = uint64(500) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to export, also better to rename There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. u[pdated |
||
) | ||
|
||
type HomeChain interface { | ||
GetChainConfig(chainSelector cciptypes.ChainSelector) (ChainConfig, error) | ||
GetAllChainConfigs() (map[cciptypes.ChainSelector]ChainConfig, error) | ||
|
@@ -115,24 +118,42 @@ 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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we add something like the following for extra safety?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added extra safety with hardCap for pageIndex but wouldnt this cap the max chains we can extract the config from? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can add some big value for the limit. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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) |
||
err := r.homeChainReader.GetLatestValue( | ||
ctx, | ||
consts.ContractNameCCIPConfig, | ||
consts.MethodNameGetAllChainConfigs, | ||
primitives.Unconfirmed, | ||
map[string]interface{}{ | ||
"pageIndex": pageIndex, | ||
"pageSize": PageSize, | ||
}, | ||
&chainConfigInfos, | ||
) | ||
if err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
return err | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's wrap that err There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. u[pdated with error wrapping |
||
} | ||
|
||
if len(chainConfigInfos) == 0 { | ||
break | ||
} | ||
|
||
allChainConfigInfos = append(allChainConfigInfos, chainConfigInfos...) | ||
pageIndex++ | ||
} | ||
if len(chainConfigInfos) == 0 { | ||
|
||
r.setState(convertOnChainConfigToHomeChainConfig(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(chainConfigInfos)) | ||
|
||
return nil | ||
} | ||
|
||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, create one pls