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

chore(cre-deployment): refactor register nodes; add better test #16212

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

krehermann
Copy link
Contributor

@krehermann krehermann commented Feb 4, 2025

CRE-236

Add the AddNodes changeset
refactor RegisterNodes to seperate out reuseable logic
add lots of tests

Requires

Supports

@@ -615,19 +604,15 @@ func RegisterNodes(lggr logger.Logger, req *RegisterNodesRequest) (*RegisterNode
params, ok := nodeIDToParams[n.NodeID]

if !ok {
evmCC, exists := n.SelToOCRConfig[registryChainDetails]
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 the only call site of registryChainDetails; mv'd to helper

@krehermann krehermann force-pushed the cre/refactor-register-nodes branch from 42bf97a to b7282ba Compare February 4, 2025 21:34
params = capabilities_registry.CapabilitiesRegistryNodeParams{
NodeOperatorId: nop.NodeOperatorId,
Signer: signer,
P2pId: n.PeerID,
EncryptionPublicKey: csakey,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

csakey was a misleading var name

}, nil
}

tx, err := registry.AddNodes(registryChain.DeployerKey, nodes2Add)
tx, err := registry.AddNodes(req.RegistryChain.DeployerKey, nodes2Add)
if err != nil {
err = deployment.DecodeErr(capabilities_registry.CapabilitiesRegistryABI, err)
// no typed errors in the abi, so we have to do string matching
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 unneeded b/c getNodesToRegistry already dedups

Copy link
Contributor

github-actions bot commented Feb 4, 2025

AER Report: CI Core ran successfully ✅

aer_workflow , commit

AER Report: Operator UI CI ran successfully ✅

aer_workflow , commit

Copy link
Contributor

github-actions bot commented Feb 5, 2025

Flakeguard Summary

Ran new or updated tests between develop and a977493 (cre/refactor-register-nodes).

View Flaky Detector Details | Compare Changes

Found Flaky Tests ❌

2 Results
Name Pass Ratio Panicked? Timed Out? Race? Runs Successes Failures Skips Package Package Panicked? Avg Duration Code Owners
TestAddNodes 0.00% false false false 3 0 3 0 github.com/smartcontractkit/chainlink/deployment/keystone/changeset false 15.466666666s @smartcontractkit/keystone, @smartcontractkit/core, @smartcontractkit/deployment-automation
TestAddNodes/with_mcms 0.00% false false false 3 0 3 0 github.com/smartcontractkit/chainlink/deployment/keystone/changeset false 7.76s @smartcontractkit/keystone, @smartcontractkit/core, @smartcontractkit/deployment-automation

Artifacts

For detailed logs of the failed tests, please refer to the artifact failed-test-results-with-logs.json.

@krehermann krehermann marked this pull request as ready for review February 5, 2025 20:29
@krehermann krehermann requested review from a team, AnieeG and kylesmartin as code owners February 5, 2025 20:29
@krehermann krehermann changed the title refactor register nodes; add better test chore(cre-deployment): refactor register nodes; add better test Feb 5, 2025

var _ deployment.ChangeSet[*AddNodesRequest] = AddNodes

func AddNodes(env deployment.Environment, req *AddNodesRequest) (deployment.ChangesetOutput, error) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

checkErr func(t *testing.T, useMCMS bool, err error)
}
//run the same tests for both mcms and non-mcms
var mcmsConfigs = []*changeset.MCMSConfig{nil, {MinDuration: 0}}
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 is a nice evolution of the test convention; run all the tests for the both mcms & non mcms and ensure they do the same thing, up to much poorer mcms error handling

checkErr: func(t *testing.T, useMCMS bool, err error) {
require.NotNil(t, err)
if useMCMS {
assert.ErrorContains(t, err, "underlying transaction reverted")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

notice the loss of info when using mcms wrt contract errors

Copy link
Contributor

Choose a reason for hiding this comment

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

out of scope for this PR, but just out of curiosity: is there a way to bubble a more specific error up?

}
}
addResp, err := AddNodes(lggr, &AddNodesRequest{
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 is the refactored, shareable code that is leveraged in the new changeset

t: t,
nameToId: make(map[string][32]byte),
}
caps, err := registry.GetCapabilities(nil)
require.NoError(t, err)
for _, capb := range caps {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

populate the cache with onchain state

Copy link
Contributor

github-actions bot commented Feb 5, 2025

Flakeguard Summary

Ran new or updated tests between develop and bb63ef9 (cre/refactor-register-nodes).

View Flaky Detector Details | Compare Changes

Found Flaky Tests ❌

2 Results
Name Pass Ratio Panicked? Timed Out? Race? Runs Successes Failures Skips Package Package Panicked? Avg Duration Code Owners
TestAddNodes 66.67% false false false 3 2 1 0 github.com/smartcontractkit/chainlink/deployment/keystone/changeset/internal false 346.666666ms @smartcontractkit/keystone, @smartcontractkit/core, @smartcontractkit/deployment-automation
TestAddNodes/add_two_nodes 66.67% false false false 3 2 1 0 github.com/smartcontractkit/chainlink/deployment/keystone/changeset/internal false 40ms @smartcontractkit/keystone, @smartcontractkit/core, @smartcontractkit/deployment-automation

Artifacts

For detailed logs of the failed tests, please refer to the artifact failed-test-results-with-logs.json.

@krehermann krehermann force-pushed the cre/refactor-register-nodes branch from c7733ff to 6b16dad Compare February 6, 2025 00:05
AnieeG
AnieeG previously approved these changes Feb 6, 2025
// NOPIdentity is a node operator identity
//
// either by operator or registration ID must be non empty
// it is an error to have both set
Copy link
Contributor

Choose a reason for hiding this comment

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

/nit both set is an error: [why]

}

func (i NOPIdentity) Validate() error {
dflt := kcr.CapabilitiesRegistryNodeOperator{}
Copy link
Contributor

Choose a reason for hiding this comment

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

/nit dflt stands for what?

MCMSConfig *MCMSConfig
}

func (r *AddNodesRequest) Validate() error {
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this also run Validate on each CreateNodeRequest in CreateNodeRequests?

if err != nil {
return deployment.ChangesetOutput{}, fmt.Errorf("failed to resolve node params for node %s: %w", nodeName, err)
}
p2p := string(p.P2pId[:])
Copy link
Contributor

Choose a reason for hiding this comment

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

/nit, could the array to slice conversion happen in Resolve?

checkErr: func(t *testing.T, useMCMS bool, err error) {
require.NotNil(t, err)
if useMCMS {
assert.ErrorContains(t, err, "underlying transaction reverted")
Copy link
Contributor

Choose a reason for hiding this comment

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

out of scope for this PR, but just out of curiosity: is there a way to bubble a more specific error up?

NOPIdentity: changeset.NOPIdentity{
RegistrationID: te.Nops()[0].NodeOperatorId,
},
Signer: test32byte(t, "dupe signer"),
Copy link
Contributor

Choose a reason for hiding this comment

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

Signer, EncryptionPublicKey, and P2PID are all duplicated. Would it be valuable to test each duplicate individually?

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