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

Allow only price aggregator contract to have multiple bindings [CCIP-4781] #426

Merged
merged 4 commits into from
Jan 9, 2025

Conversation

asoliman92
Copy link
Contributor

@asoliman92 asoliman92 commented Jan 9, 2025

Allow only price aggregator contract to have multiple bindings, othe contracts should only have one instance at any single time.

core ref: 843e228fba3c5264d34fb5bc2bd972f1576057d8

Core PR: smartcontractkit/chainlink#15854

… contracts should only have one instance at any single time.
@asoliman92 asoliman92 changed the title Allow only price aggregator contract to have multiple bindings, other… Allow only price aggregator contract to have multiple bindings [CCIP-4781] Jan 9, 2025
@asoliman92 asoliman92 marked this pull request as ready for review January 9, 2025 10:33
@asoliman92 asoliman92 requested a review from a team as a code owner January 9, 2025 10:33
pkg/contractreader/extended.go Outdated Show resolved Hide resolved
pkg/contractreader/extended.go Show resolved Hide resolved
makramkd
makramkd previously approved these changes Jan 9, 2025
} else {
if len(e.contractBindingsByName[binding.Name]) > 0 {
// Unbind the previous binding
err := e.reader.Unbind(ctx, []types.BoundContract{e.contractBindingsByName[binding.Name][0].Binding})
Copy link
Collaborator

Choose a reason for hiding this comment

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

Double checking - are we certain there's only one other binding in this situation?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because of the current condition yes there should only be one binding.

Copy link
Contributor

Choose a reason for hiding this comment

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

There could be more if the extended reader was created with a reader that already had bound contracts. But that would just mean there are some dangling bindings, our discovery code would work fine because error checking is done using the contractBindingsByName list.

pkg/contractreader/extended.go Outdated Show resolved Hide resolved
pkg/contractreader/extended.go Outdated Show resolved Hide resolved
Copy link

github-actions bot commented Jan 9, 2025

Metric CCIP-4781-binding-bug main
Coverage 76.5% 76.3%

@asoliman92 asoliman92 merged commit ff9d86b into main Jan 9, 2025
17 checks passed
Comment on lines +271 to +275
if e.multiBindAllowed[binding.Name] {
e.contractBindingsByName[binding.Name] = append(e.contractBindingsByName[binding.Name], ExtendedBoundContract{
BoundAt: time.Now(),
Binding: binding,
})
Copy link
Contributor

Choose a reason for hiding this comment

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

style nit: I would be tempted to rewrite this to avoid the else. Something like

    // unbind previous contract if needed
    if len(e.contractBindingsByName[binding.Name]) > 0 && e.multiBindAllowed[binding.Name] {
        e.reader.Unbind(...)
        e.contractBindingsByName[binding.Name] = nil
    }

    // existing logic here
}

Copy link
Contributor

@winder winder left a comment

Choose a reason for hiding this comment

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

Looks good, one minor suggestions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants