-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make proper changeset; refactor to isolate code (#15070)
- Loading branch information
1 parent
cc5ba93
commit 007cf1f
Showing
11 changed files
with
390 additions
and
160 deletions.
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 was deleted.
Oops, something went wrong.
69 changes: 69 additions & 0 deletions
69
deployment/keystone/changeset/internal/append_node_capabilities.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,69 @@ | ||
package internal | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/smartcontractkit/chainlink-common/pkg/logger" | ||
"github.com/smartcontractkit/chainlink/deployment" | ||
kslib "github.com/smartcontractkit/chainlink/deployment/keystone" | ||
kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry" | ||
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey" | ||
) | ||
|
||
type AppendNodeCapabilitiesRequest struct { | ||
Chain deployment.Chain | ||
Registry *kcr.CapabilitiesRegistry | ||
|
||
P2pToCapabilities map[p2pkey.PeerID][]kcr.CapabilitiesRegistryCapability | ||
NopToNodes map[kcr.CapabilitiesRegistryNodeOperator][]*P2PSignerEnc | ||
} | ||
|
||
func (req *AppendNodeCapabilitiesRequest) Validate() error { | ||
if len(req.P2pToCapabilities) == 0 { | ||
return fmt.Errorf("p2pToCapabilities is empty") | ||
} | ||
if len(req.NopToNodes) == 0 { | ||
return fmt.Errorf("nopToNodes is empty") | ||
} | ||
if req.Registry == nil { | ||
return fmt.Errorf("registry is nil") | ||
} | ||
return nil | ||
} | ||
|
||
func AppendNodeCapabilitiesImpl(lggr logger.Logger, req *AppendNodeCapabilitiesRequest) (*UpdateNodesResponse, error) { | ||
if err := req.Validate(); err != nil { | ||
return nil, fmt.Errorf("failed to validate request: %w", err) | ||
} | ||
// collect all the capabilities and add them to the registry | ||
var capabilities []kcr.CapabilitiesRegistryCapability | ||
for _, cap := range req.P2pToCapabilities { | ||
capabilities = append(capabilities, cap...) | ||
} | ||
err := kslib.AddCapabilities(lggr, req.Registry, req.Chain, capabilities) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to add capabilities: %w", err) | ||
} | ||
|
||
// for each node, merge the new capabilities with the existing ones and update the node | ||
capsByPeer := make(map[p2pkey.PeerID][]kcr.CapabilitiesRegistryCapability) | ||
for p2pID, caps := range req.P2pToCapabilities { | ||
caps, err := AppendCapabilities(lggr, req.Registry, req.Chain, []p2pkey.PeerID{p2pID}, caps) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to append capabilities for p2p %s: %w", p2pID, err) | ||
} | ||
capsByPeer[p2pID] = caps[p2pID] | ||
} | ||
|
||
updateNodesReq := &UpdateNodesRequest{ | ||
Chain: req.Chain, | ||
Registry: req.Registry, | ||
P2pToCapabilities: capsByPeer, | ||
NopToNodes: req.NopToNodes, | ||
} | ||
resp, err := UpdateNodes(lggr, updateNodesReq) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to update nodes: %w", err) | ||
} | ||
return resp, nil | ||
} |
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.