Skip to content

Commit

Permalink
bootstrapper metadata wip
Browse files Browse the repository at this point in the history
  • Loading branch information
krehermann committed Feb 27, 2025
1 parent 1160fca commit b345fb7
Showing 1 changed file with 91 additions and 3 deletions.
94 changes: 91 additions & 3 deletions deployment/keystone/changeset/test/env_setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ package test

import (
"context"
"encoding/json"
"errors"
"fmt"
"math"
"math/big"
"strconv"
"testing"

"github.com/stretchr/testify/require"
Expand All @@ -18,6 +20,8 @@ import (
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"

ocrcommontypes "github.com/smartcontractkit/libocr/commontypes"

"github.com/smartcontractkit/chainlink/deployment"
commonchangeset "github.com/smartcontractkit/chainlink/deployment/common/changeset"
"github.com/smartcontractkit/chainlink/deployment/common/proposalutils"
Expand All @@ -28,8 +32,12 @@ import (
"github.com/smartcontractkit/chainlink/deployment/keystone/changeset/internal"

"github.com/smartcontractkit/chainlink/deployment/keystone/changeset/workflowregistry"
"github.com/smartcontractkit/chainlink/v2/core/config/toml"
kcr "github.com/smartcontractkit/chainlink/v2/core/gethwrappers/keystone/generated/capabilities_registry_1_1_0"
"github.com/smartcontractkit/chainlink/v2/core/services/chainlink"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey"
"github.com/smartcontractkit/chainlink/v2/core/services/relay"
)

type DonConfig struct {
Expand All @@ -44,9 +52,56 @@ type DonConfig struct {
generatedKeys []importableKeys
}

type BootstrapConfig struct {
Name string
N int
Labels map[string]string

generatedKeys []importableKeys
bootstrappers []bootstrapperMetadata
}

func (b *BootstrapConfig) Locations() []ocrcommontypes.BootstrapperLocator {
locations := make([]ocrcommontypes.BootstrapperLocator, len(b.bootstrappers))
for i, bs := range b.bootstrappers {
locations[i] = bs.location()
}
return locations
}

type bootstrapperMetadata struct {
port int
importKey keystore.ImportableKey
}

func (b bootstrapperMetadata) mustPeerID() p2pkey.PeerID {
var x p2pkey.EncryptedP2PKeyExport
err := json.Unmarshal([]byte(b.importKey.JSON), &x)
if err != nil {
panic(fmt.Sprintf("failed to unmarshal bootstrapper key: %v", err))
}
return x.PeerID
}

func (b bootstrapperMetadata) location() ocrcommontypes.BootstrapperLocator {
return ocrcommontypes.BootstrapperLocator{
PeerID: b.mustPeerID().String(),
Addrs: []string{}, // TODO
}
}

func (b *BootstrapConfig) generateKeys(t *testing.T, ks *keystore.TestKeystore) {
if b.generatedKeys != nil {
return
}
b.generatedKeys = generateKeys(t, ks, generateKeysCfg{
N: b.N,
})
}

type importableKeys struct {
P2P keystore.ImportableKey
EthKeys map[int]keystore.ImportableEthKey
P2P keystore.ImportableKey // required
EthKeys map[int]keystore.ImportableEthKey // optional
}
type CapabilityNaturalKey struct {
LabelledName string
Expand All @@ -60,7 +115,7 @@ func (c DonConfig) Validate() error {
return nil
}

func (c *DonConfig) GenerateKeys(t *testing.T, ks *keystore.TestKeystore) {
func (c *DonConfig) generateKeys(t *testing.T, ks *keystore.TestKeystore) {
if c.generatedKeys != nil {
return
}
Expand All @@ -70,6 +125,39 @@ func (c *DonConfig) GenerateKeys(t *testing.T, ks *keystore.TestKeystore) {
})
}

func (c *DonConfig) GenerateOpts() map[string][]func(c *chainlink.Config, s *chainlink.Secrets) {
return nil
}

type capabilitiesTOMLConfigurer struct {
d2dListener string
don2don []ocrcommontypes.BootstrapperLocator
capCfg deployment.CapabilityRegistryConfig
wfCfg *deployment.CapabilityRegistryConfig
}

func (c *capabilitiesTOMLConfigurer) generate() *toml.Capabilities {
capabilities := &toml.Capabilities{}
capabilities.Peering.PeerID = nil
capabilities.Peering.V2.Enabled = ptr(true)
capabilities.Peering.V2.ListenAddresses = ptr([]string{c.d2dListener})
capabilities.Peering.V2.DefaultBootstrappers = ptr(c.don2don)
capabilities.ExternalRegistry.NetworkID = ptr(relay.NetworkEVM)
capabilities.ExternalRegistry.ChainID = ptr(strconv.FormatUint(uint64(c.capCfg.EVMChainID), 10))
capabilities.ExternalRegistry.Address = ptr(c.capCfg.Contract.String())
if c.wfCfg != nil {
capabilities.WorkflowRegistry.NetworkID = ptr(relay.NetworkEVM)
capabilities.WorkflowRegistry.ChainID = ptr(strconv.FormatUint(uint64(c.wfCfg.EVMChainID), 10))
capabilities.WorkflowRegistry.Address = ptr(c.wfCfg.Contract.String())
}
// todo gateway
return capabilities
}

func ptr[T any](v T) *T {
return &v
}

type testEnvIface interface {
ContractSets() map[uint64]changeset.ContractSet
CapabilitiesRegistry() *kcr.CapabilitiesRegistry
Expand Down

0 comments on commit b345fb7

Please sign in to comment.