Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
archseer committed Nov 22, 2024
1 parent dec4508 commit 26f5904
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 29 deletions.
3 changes: 2 additions & 1 deletion deployment/environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ func NodeInfo(nodeIDs []string, oc NodeChainConfigsLister) (Nodes, error) {
// Might make sense to change proto as peerID/multiAddr is 1-1 with nodeID?
peerID = MustPeerIDFromString(chainConfig.Ocr2Config.P2PKeyBundle.PeerId)
multiAddr = chainConfig.Ocr2Config.Multiaddr
adminAddr = chainConfig.AdminAddress
if chainConfig.Ocr2Config.IsBootstrap {
// NOTE: Assume same peerID for all chains.
// Might make sense to change proto as peerID is 1-1 with nodeID?
Expand Down Expand Up @@ -364,6 +363,8 @@ func NodeInfo(nodeIDs []string, oc NodeChainConfigsLister) (Nodes, error) {
return nil, err
}
case nodev1.ChainType_CHAIN_TYPE_EVM:
// NOTE: Assume same adminAddr for all chains. We always use EVM addr
adminAddr = chainConfig.AdminAddress
details, err = chain_selectors.GetChainDetailsByChainIDAndFamily(chainConfig.Chain.Id, chain_selectors.FamilyEVM)
if err != nil {
return nil, err
Expand Down
20 changes: 10 additions & 10 deletions deployment/keystone/changeset/internal/update_don_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package internal_test
import (
"bytes"
"encoding/hex"
"fmt"
"math/big"
"sort"
"strconv"
Expand Down Expand Up @@ -189,14 +190,21 @@ func newNode(t *testing.T, cfg minimalNodeCfg) deployment.Node {
signingAddr, err := hex.DecodeString(cfg.signingAddr)
require.NoError(t, err)

var pubkey [32]byte
if _, err := hex.Decode(pubkey[:], []byte(cfg.pubKey)); err != nil {
panic(fmt.Sprintf("failed to decode pubkey %s: %v", pubkey, err))
}

return deployment.Node{
NodeID: cfg.id,
PeerID: cfg.p2p.PeerID(),
CSAKey: cfg.pubKey,
AdminAddr: cfg.admin.String(),
SelToOCRConfig: map[chainsel.ChainDetails]deployment.OCRConfig{
registryChainDetails: {
OnchainPublicKey: signingAddr,
PeerID: cfg.p2p.PeerID(),
OnchainPublicKey: signingAddr,
PeerID: cfg.p2p.PeerID(),
ConfigEncryptionPublicKey: pubkey,
},
},
}
Expand Down Expand Up @@ -305,11 +313,3 @@ func testDon(t *testing.T, don kslib.DonInfo) kstest.Don {
CapabilityConfigs: capabilityConfigs,
}
}

func newP2PSignerEnc(signer [32]byte, p2pkey p2pkey.PeerID, encryptionPublicKey [32]byte) *internal.P2PSignerEnc {
return &internal.P2PSignerEnc{
Signer: signer,
P2PKey: p2pkey,
EncryptionPublicKey: encryptionPublicKey,
}
}
10 changes: 6 additions & 4 deletions deployment/keystone/changeset/update_node_capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,21 @@ func NewP2PSignerEnc(n *deployment.Node, registryChainSel uint64) (*P2PSignerEnc
// TODO: deduplicate everywhere
registryChainID, err := chainsel.ChainIdFromSelector(registryChainSel)
if err != nil {
panic(err)
return nil, err
}
registryChainDetails, err := chainsel.GetChainDetailsByChainIDAndFamily(strconv.Itoa(int(registryChainID)), chainsel.FamilyEVM)
if err != nil {
panic(err)
return nil, err
}
evmCC, exists := n.SelToOCRConfig[registryChainDetails]
if !exists {
return nil, fmt.Errorf("NewP2PSignerEnc: registryChainSel not found on node: %v", registryChainSel)
}
evmCC := n.SelToOCRConfig[registryChainDetails]
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: n.PeerID,
Expand Down
11 changes: 7 additions & 4 deletions deployment/keystone/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -639,11 +639,11 @@ func registerNodes(lggr logger.Logger, req *registerNodesRequest) (*registerNode
// TODO: deduplicate everywhere
registryChainID, err := chainsel.ChainIdFromSelector(req.chain.Selector)
if err != nil {
panic(err)
return nil, err
}
registryChainDetails, err := chainsel.GetChainDetailsByChainIDAndFamily(strconv.Itoa(int(registryChainID)), chainsel.FamilyEVM)
if err != nil {
panic(err)
return nil, err
}

nodeIDToParams := make(map[string]kcr.CapabilitiesRegistryNodeParams)
Expand All @@ -669,7 +669,10 @@ func registerNodes(lggr logger.Logger, req *registerNodesRequest) (*registerNode
params, ok := nodeIDToParams[n.NodeID]

if !ok {
evmCC := n.SelToOCRConfig[registryChainDetails]
evmCC, exists := n.SelToOCRConfig[registryChainDetails]
if !exists {
return nil, fmt.Errorf("config for selector not found on node: %v", req.chain.Selector)
}
var signer [32]byte
copy(signer[:], evmCC.OnchainPublicKey)
var csakey [32]byte
Expand Down Expand Up @@ -905,7 +908,7 @@ 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
signers := dn.signers(chain.Selector)
signers := dn.signers(chainsel.FamilyEVM)
tx, err := fwdr.SetConfig(chain.DeployerKey, dn.Info.Id, ver, dn.Info.F, signers)
if err != nil {
err = DecodeErr(kf.KeystoneForwarderABI, err)
Expand Down
28 changes: 18 additions & 10 deletions deployment/keystone/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -242,25 +242,33 @@ type RegisteredDon struct {
Nodes []deployment.Node
}

func (d RegisteredDon) signers(registryChainSel uint64) []common.Address {
func (d RegisteredDon) signers(chainFamily string) []common.Address {
sort.Slice(d.Nodes, func(i, j int) bool {
return d.Nodes[i].PeerID.String() < d.Nodes[j].PeerID.String()
})
registryChainID, err := chainsel.ChainIdFromSelector(registryChainSel)
if err != nil {
panic(err)
}
registryChainDetails, err := chainsel.GetChainDetailsByChainIDAndFamily(strconv.Itoa(int(registryChainID)), chainsel.FamilyEVM)
if err != nil {
panic(err)
}
var out []common.Address
for _, n := range d.Nodes {
if n.IsBootstrap {
continue
}
var found bool
var registryChainDetails chainsel.ChainDetails
for details, _ := range n.SelToOCRConfig {
if family, err := chainsel.GetSelectorFamily(details.ChainSelector); err == nil && family == chainFamily {
found = true
registryChainDetails = details

}
}
if !found {
panic(fmt.Sprintf("chainType not found: %v", chainFamily))
}
// eth address is the first 20 bytes of the Signer
signer := n.SelToOCRConfig[registryChainDetails].OnchainPublicKey
config, exists := n.SelToOCRConfig[registryChainDetails]
if !exists {
panic(fmt.Sprintf("chainID not found: %v", registryChainDetails))
}
signer := config.OnchainPublicKey
signerAddress := common.BytesToAddress(signer)
out = append(out, signerAddress)
}
Expand Down

0 comments on commit 26f5904

Please sign in to comment.