Skip to content

Commit

Permalink
Remove ocr2Node and use deployment.Node directly
Browse files Browse the repository at this point in the history
  • Loading branch information
archseer committed Nov 15, 2024
1 parent 0e83af9 commit 8729b74
Show file tree
Hide file tree
Showing 3 changed files with 94 additions and 172 deletions.
15 changes: 9 additions & 6 deletions deployment/keystone/changeset/update_node_capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@ var _ deployment.ChangeSet[*MutateNodeCapabilitiesRequest] = UpdateNodeCapabilit
type P2PSignerEnc = internal.P2PSignerEnc

func NewP2PSignerEnc(n *deployment.Node, registryChainSel uint64) (*P2PSignerEnc, error) {
p2p, signer, enc, err := kslib.ExtractKeys(n, registryChainSel)
if err != nil {
return nil, fmt.Errorf("failed to extract keys: %w", err)
}
evmCC := n.SelToOCRConfig[registryChainSel]
var signer [32]byte
copy(signer[:], evmCC.OnchainPublicKey)
var csakey [32]byte
copy(csakey[:], evmCC.ConfigEncryptionPublicKey[:])

// TODO: return error return value
return &P2PSignerEnc{
Signer: signer,
P2PKey: p2p,
EncryptionPublicKey: enc,
P2PKey: n.PeerID,
EncryptionPublicKey: csakey,
}, nil
}

Expand Down
67 changes: 32 additions & 35 deletions deployment/keystone/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func ConfigureRegistry(ctx context.Context, lggr logger.Logger, req ConfigureCon

// all the subsequent calls to the registry are in terms of nodes
// compute the mapping of dons to their nodes for reuse in various registry calls
donToOcr2Nodes, err := mapDonsToNodes(donInfos, true, req.RegistryChainSel)
donToNodes, err := mapDonsToNodes(donInfos, true, req.RegistryChainSel)
if err != nil {
return nil, fmt.Errorf("failed to map dons to nodes: %w", err)
}
Expand Down Expand Up @@ -247,7 +247,7 @@ func ConfigureRegistry(ctx context.Context, lggr logger.Logger, req ConfigureCon
registry: registry,
chain: registryChain,
nopToNodeIDs: nopsToNodeIDs,
donToOcr2Nodes: donToOcr2Nodes,
donToNodes: donToNodes,
donToCapabilities: capabilitiesResp.donToCapabilities,
nops: nopsResp.Nops,
})
Expand All @@ -264,7 +264,7 @@ func ConfigureRegistry(ctx context.Context, lggr logger.Logger, req ConfigureCon
chain: registryChain,
nodeIDToParams: nodesResp.nodeIDToParams,
donToCapabilities: capabilitiesResp.donToCapabilities,
donToOcr2Nodes: donToOcr2Nodes,
donToNodes: donToNodes,
})
if err != nil {
return nil, fmt.Errorf("failed to register DONS: %w", err)
Expand Down Expand Up @@ -376,19 +376,11 @@ func ConfigureOCR3ContractFromJD(env *deployment.Environment, chainSel uint64, n
if err != nil {
return err
}
var ocr2nodes []*ocr2Node
for _, node := range nodes {
n, err := newOcr2NodeFromJD(&node, chainSel)
if err != nil {
return fmt.Errorf("failed to create ocr2 node from clo node: %w", err)
}
ocr2nodes = append(ocr2nodes, n)
}
_, err = configureOCR3contract(configureOCR3Request{
cfg: cfg,
chain: registryChain,
contract: contract,
nodes: ocr2nodes,
nodes: nodes,
})
return err
}
Expand Down Expand Up @@ -588,7 +580,7 @@ type registerNodesRequest struct {
registry *kcr.CapabilitiesRegistry
chain deployment.Chain
nopToNodeIDs map[kcr.CapabilitiesRegistryNodeOperator][]string
donToOcr2Nodes map[string][]*ocr2Node
donToNodes map[string][]deployment.Node
donToCapabilities map[string][]RegisteredCapability
nops []*kcr.CapabilitiesRegistryNodeOperatorAdded
}
Expand Down Expand Up @@ -621,7 +613,7 @@ func registerNodes(lggr logger.Logger, req *registerNodesRequest) (*registerNode
}

nodeIDToParams := make(map[string]kcr.CapabilitiesRegistryNodeParams)
for don, ocr2nodes := range req.donToOcr2Nodes {
for don, nodes := range req.donToNodes {
caps, ok := req.donToCapabilities[don]
if !ok {
return nil, fmt.Errorf("capabilities not found for node operator %s", don)
Expand All @@ -632,23 +624,27 @@ func registerNodes(lggr logger.Logger, req *registerNodesRequest) (*registerNode
}
lggr.Debugw("hashed capability ids", "don", don, "ids", hashedCapabilityIds)

for _, n := range ocr2nodes {
if n.IsBoostrap { // bootstraps are part of the DON but don't host capabilities
for _, n := range nodes {
if n.IsBootstrap { // bootstraps are part of the DON but don't host capabilities
continue
}
fmt.Printf("nodeToRegisterNop %+v\n", nodeToRegisterNop)
nop, ok := nodeToRegisterNop[n.ID]
nop, ok := nodeToRegisterNop[n.NodeID]
if !ok {
return nil, fmt.Errorf("node operator not found for node %s", n.ID)
return nil, fmt.Errorf("node operator not found for node %s", n.NodeID)
}
params, ok := nodeIDToParams[n.ID]
params, ok := nodeIDToParams[n.NodeID]

if !ok {
evmCC := n.SelToOCRConfig[req.chain.Selector]
var signer [32]byte
copy(signer[:], evmCC.OnchainPublicKey)
var csakey [32]byte
copy(csakey[:], evmCC.ConfigEncryptionPublicKey[:])
params = kcr.CapabilitiesRegistryNodeParams{
NodeOperatorId: nop.NodeOperatorId,
Signer: n.Signer,
P2pId: n.P2PKey,
EncryptionPublicKey: n.EncryptionPublicKey,
Signer: signer,
P2pId: n.PeerID,
EncryptionPublicKey: csakey,
HashedCapabilityIds: hashedCapabilityIds,
}
} else {
Expand All @@ -668,7 +664,7 @@ func registerNodes(lggr logger.Logger, req *registerNodesRequest) (*registerNode
}
params.HashedCapabilityIds = append(params.HashedCapabilityIds, newCapIds...)
}
nodeIDToParams[n.ID] = params
nodeIDToParams[n.NodeID] = params
}
}

Expand Down Expand Up @@ -721,7 +717,7 @@ type registerDonsRequest struct {

nodeIDToParams map[string]kcr.CapabilitiesRegistryNodeParams
donToCapabilities map[string][]RegisteredCapability
donToOcr2Nodes map[string][]*ocr2Node
donToNodes map[string][]deployment.Node
}

type registerDonsResponse struct {
Expand All @@ -740,7 +736,7 @@ func sortedHash(p2pids [][32]byte) string {
}

func registerDons(lggr logger.Logger, req registerDonsRequest) (*registerDonsResponse, error) {
lggr.Infow("registering DONs...", "len", len(req.donToOcr2Nodes))
lggr.Infow("registering DONs...", "len", len(req.donToNodes))
// track hash of sorted p2pids to don name because the registry return value does not include the don name
// and we need to map it back to the don name to access the other mapping data such as the don's capabilities & nodes
p2pIdsToDon := make(map[string]string)
Expand All @@ -757,15 +753,15 @@ func registerDons(lggr logger.Logger, req registerDonsRequest) (*registerDonsRes
}
lggr.Infow("fetched existing DONs...", "len", len(donInfos), "lenByNodesHash", len(existingDONs))

for don, ocr2nodes := range req.donToOcr2Nodes {
for don, nodes := range req.donToNodes {
var p2pIds [][32]byte
for _, n := range ocr2nodes {
if n.IsBoostrap {
for _, n := range nodes {
if n.IsBootstrap {
continue
}
params, ok := req.nodeIDToParams[n.ID]
params, ok := req.nodeIDToParams[n.NodeID]
if !ok {
return nil, fmt.Errorf("node params not found for non-bootstrap node %s", n.ID)
return nil, fmt.Errorf("node params not found for non-bootstrap node %s", n.NodeID)
}
p2pIds = append(p2pIds, params.P2pId)
}
Expand Down Expand Up @@ -875,7 +871,8 @@ func configureForwarder(lggr logger.Logger, chain deployment.Chain, fwdr *kf.Key
continue
}
ver := dn.Info.ConfigCount // note config count on the don info is the version on the forwarder
tx, err := fwdr.SetConfig(chain.DeployerKey, dn.Info.Id, ver, dn.Info.F, dn.signers())
signers := dn.signers(chain.Selector)
tx, err := fwdr.SetConfig(chain.DeployerKey, dn.Info.Id, ver, dn.Info.F, signers)
if err != nil {
err = DecodeErr(kf.KeystoneForwarderABI, err)
return fmt.Errorf("failed to call SetConfig for forwarder %s on chain %d: %w", fwdr.Address().String(), chain.Selector, err)
Expand All @@ -885,7 +882,7 @@ func configureForwarder(lggr logger.Logger, chain deployment.Chain, fwdr *kf.Key
err = DecodeErr(kf.KeystoneForwarderABI, err)
return fmt.Errorf("failed to confirm SetConfig for forwarder %s: %w", fwdr.Address().String(), err)
}
lggr.Debugw("configured forwarder", "forwarder", fwdr.Address().String(), "donId", dn.Info.Id, "version", ver, "f", dn.Info.F, "signers", dn.signers())
lggr.Debugw("configured forwarder", "forwarder", fwdr.Address().String(), "donId", dn.Info.Id, "version", ver, "f", dn.Info.F, "signers", signers)
}
return nil
}
Expand All @@ -894,7 +891,7 @@ type configureOCR3Request struct {
cfg *OracleConfigWithSecrets
chain deployment.Chain
contract *kocr3.OCR3Capability
nodes []*ocr2Node
nodes []deployment.Node
}
type configureOCR3Response struct {
ocrConfig Orc2drOracleConfig
Expand All @@ -904,7 +901,7 @@ func configureOCR3contract(req configureOCR3Request) (*configureOCR3Response, er
if req.contract == nil {
return nil, fmt.Errorf("OCR3 contract is nil")
}
nks := makeNodeKeysSlice(req.nodes)
nks := makeNodeKeysSlice(req.nodes, req.chain.Selector)
ocrConfig, err := GenerateOCR3Config(*req.cfg, nks)
if err != nil {
return nil, fmt.Errorf("failed to generate OCR3 config: %w", err)
Expand Down
Loading

0 comments on commit 8729b74

Please sign in to comment.