-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
refactor update & append capabilities #15563
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
0374992
refactor update & append capabilities
krehermann 8f2f464
Merge branch 'develop' into ks/cap-cs-refactor
krehermann dbedc94
fix tests; cleanup registry vs contractset
krehermann 4e368e6
Merge branch 'develop' into ks/cap-cs-refactor
krehermann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
129 changes: 129 additions & 0 deletions
129
deployment/keystone/changeset/append_node_capbilities_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package changeset_test | ||
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. typo in file name |
||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"golang.org/x/exp/maps" | ||
|
||
"github.com/smartcontractkit/ccip-owner-contracts/pkg/gethwrappers" | ||
commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset" | ||
"github.com/smartcontractkit/chainlink/deployment/keystone/changeset" | ||
kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey" | ||
) | ||
|
||
func TestAppendNodeCapabilities(t *testing.T) { | ||
t.Parallel() | ||
|
||
var ( | ||
capA = kcr.CapabilitiesRegistryCapability{ | ||
LabelledName: "capA", | ||
Version: "0.4.2", | ||
} | ||
capB = kcr.CapabilitiesRegistryCapability{ | ||
LabelledName: "capB", | ||
Version: "3.16.0", | ||
} | ||
caps = []kcr.CapabilitiesRegistryCapability{capA, capB} | ||
) | ||
t.Run("no mcms", func(t *testing.T) { | ||
te := SetupTestEnv(t, TestConfig{ | ||
WFDonConfig: DonConfig{N: 4}, | ||
AssetDonConfig: DonConfig{N: 4}, | ||
WriterDonConfig: DonConfig{N: 4}, | ||
NumChains: 1, | ||
}) | ||
|
||
newCapabilities := make(map[p2pkey.PeerID][]kcr.CapabilitiesRegistryCapability) | ||
for id, _ := range te.WFNodes { | ||
k, err := p2pkey.MakePeerID(id) | ||
require.NoError(t, err) | ||
newCapabilities[k] = caps | ||
} | ||
|
||
t.Run("succeeds if existing capabilities not explicit", func(t *testing.T) { | ||
cfg := changeset.AppendNodeCapabilitiesRequest{ | ||
RegistryChainSel: te.RegistrySelector, | ||
P2pToCapabilities: newCapabilities, | ||
} | ||
|
||
csOut, err := changeset.AppendNodeCapabilities(te.Env, &cfg) | ||
require.NoError(t, err) | ||
require.Len(t, csOut.Proposals, 0) | ||
require.Nil(t, csOut.AddressBook) | ||
|
||
validateCapabilityAppends(t, te, newCapabilities) | ||
}) | ||
}) | ||
t.Run("with mcms", func(t *testing.T) { | ||
te := SetupTestEnv(t, TestConfig{ | ||
WFDonConfig: DonConfig{N: 4}, | ||
AssetDonConfig: DonConfig{N: 4}, | ||
WriterDonConfig: DonConfig{N: 4}, | ||
NumChains: 1, | ||
UseMCMS: true, | ||
}) | ||
|
||
newCapabilities := make(map[p2pkey.PeerID][]kcr.CapabilitiesRegistryCapability) | ||
for id, _ := range te.WFNodes { | ||
k, err := p2pkey.MakePeerID(id) | ||
require.NoError(t, err) | ||
newCapabilities[k] = caps | ||
} | ||
|
||
cfg := changeset.AppendNodeCapabilitiesRequest{ | ||
RegistryChainSel: te.RegistrySelector, | ||
P2pToCapabilities: newCapabilities, | ||
UseMCMS: true, | ||
} | ||
|
||
csOut, err := changeset.AppendNodeCapabilities(te.Env, &cfg) | ||
require.NoError(t, err) | ||
require.Len(t, csOut.Proposals, 1) | ||
require.Len(t, csOut.Proposals[0].Transactions, 1) | ||
require.Len(t, csOut.Proposals[0].Transactions[0].Batch, 2) // add capabilities, update nodes | ||
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. ty for this comment |
||
require.Nil(t, csOut.AddressBook) | ||
|
||
// now apply the changeset such that the proposal is signed and execed | ||
contracts := te.ContractSets()[te.RegistrySelector] | ||
timelocks := map[uint64]*gethwrappers.RBACTimelock{ | ||
te.RegistrySelector: contracts.Timelock, | ||
} | ||
_, err = commonchangeset.ApplyChangesets(t, te.Env, timelocks, []commonchangeset.ChangesetApplication{ | ||
{ | ||
Changeset: commonchangeset.WrapChangeSet(changeset.AppendNodeCapabilities), | ||
Config: &cfg, | ||
}, | ||
}) | ||
require.NoError(t, err) | ||
validateCapabilityAppends(t, te, newCapabilities) | ||
}) | ||
|
||
} | ||
|
||
// validateUpdate checks reads nodes from the registry and checks they have the expected updates | ||
func validateCapabilityAppends(t *testing.T, te TestEnv, appended map[p2pkey.PeerID][]kcr.CapabilitiesRegistryCapability) { | ||
registry := te.ContractSets()[te.RegistrySelector].CapabilitiesRegistry | ||
wfP2PIDs := p2pIDs(t, maps.Keys(te.WFNodes)) | ||
nodes, err := registry.GetNodesByP2PIds(nil, wfP2PIDs) | ||
require.NoError(t, err) | ||
require.Len(t, nodes, len(wfP2PIDs)) | ||
for _, node := range nodes { | ||
want := appended[node.P2pId] | ||
require.NotNil(t, want) | ||
assertContainsCapabilities(t, registry, want, node) | ||
} | ||
} | ||
|
||
func assertContainsCapabilities(t *testing.T, registry *kcr.CapabilitiesRegistry, want []kcr.CapabilitiesRegistryCapability, got kcr.INodeInfoProviderNodeInfo) { | ||
wantHashes := make([][32]byte, len(want)) | ||
for i, c := range want { | ||
h, err := registry.GetHashedCapabilityId(nil, c.LabelledName, c.Version) | ||
require.NoError(t, err) | ||
wantHashes[i] = h | ||
assert.Contains(t, got.HashedCapabilityIds, h, "missing capability %v", c) | ||
} | ||
assert.LessOrEqual(t, len(want), len(got.HashedCapabilityIds)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
probably worth parameterizing this just in case you want to add timelock delay in the future. @carte7000 had a good idea here https://github.com/smartcontractkit/chainlink/pull/15525/files#diff-f6eeb14804b5d16769abc3f48ad18187965263d5e5d29345e4079e85199de731R38 to use an MCMS struct being nil/not-nil as a way to signal that but also keep the door open for any other MCMS specific params
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.
ack, will address in followup; have one more in the stack to merge