Skip to content

Commit 99ead59

Browse files
vreffCopilotkalverra
authored
Add keystore service to standardcapabilities delegate (#18274)
* Add keystore service to standardcapabilities delegate * Update chainlink-common version, fix trigger initialise func * fix nil pointer * fix lint * update gomodtidies * add p2p key use * undo removal of function * Update core/capabilities/integration_tests/keystone/contracts_setup.go Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * lowercase getSignerStringFromOCRKeyBundle * add error for no p2p key * fix merge conflict * lint * add changeset * add error check * lint * lint * lint * lint * Update chainlink-common, use single account signer. * resolve merge conflict * resolve merge conflict 2 * resolve merge conflict 2 * Fixes chainlink version in CI --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: Adam Hamrick <adam.hamrick@smartcontract.com>
1 parent 41148b5 commit 99ead59

File tree

32 files changed

+152
-113
lines changed

32 files changed

+152
-113
lines changed

.changeset/cyan-ears-fix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"chainlink": minor
3+
---
4+
5+
#change Add keystore service to standardcapabilities, refactor integration_tests/framework to use a p2p key in the test node

core/capabilities/fakes/consensus_nodag.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ func (fc *fakeConsensusNoDAG) Initialise(
103103
_ core.PipelineRunnerService,
104104
_ core.RelayerSet,
105105
_ core.OracleFactory,
106-
_ core.GatewayConnector) error {
106+
_ core.GatewayConnector,
107+
_ core.Keystore) error {
107108
return nil
108109
}

core/capabilities/fakes/evm_chain.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ func (fc *FakeEVMChain) Initialise(ctx context.Context, config string, _ core.Te
6565
_ core.PipelineRunnerService,
6666
_ core.RelayerSet,
6767
_ core.OracleFactory,
68-
_ core.GatewayConnector) error {
68+
_ core.GatewayConnector,
69+
_ core.Keystore) error {
6970
// TODO: do validation of config here
7071

7172
err := fc.Start(ctx)

core/capabilities/fakes/http_action.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ func (fh *DirectHTTPAction) Initialise(ctx context.Context, config string, _ cor
135135
_ core.PipelineRunnerService,
136136
_ core.RelayerSet,
137137
_ core.OracleFactory,
138-
_ core.GatewayConnector) error {
138+
_ core.GatewayConnector,
139+
_ core.Keystore) error {
139140
// TODO: do validation of config here
140141

141142
err := fh.Start(ctx)

core/capabilities/fakes/manual_cron_trigger.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ func (f *ManualCronTriggerService) Initialise(ctx context.Context, config string
5959
_ core.PipelineRunnerService,
6060
_ core.RelayerSet,
6161
_ core.OracleFactory,
62-
_ core.GatewayConnector) error {
62+
_ core.GatewayConnector,
63+
_ core.Keystore) error {
6364
f.lggr.Debugf("Initialising %s", ServiceName)
6465

6566
var cronConfig ManualCronConfig

core/capabilities/fakes/manual_http_trigger.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ func (f *ManualHTTPTriggerService) Initialise(ctx context.Context, config string
5555
_ core.PipelineRunnerService,
5656
_ core.RelayerSet,
5757
_ core.OracleFactory,
58-
_ core.GatewayConnector) error {
58+
_ core.GatewayConnector,
59+
_ core.Keystore) error {
5960
f.lggr.Debugf("Initialising %s", HTTPTriggerServiceName)
6061
return f.Start(ctx)
6162
}

core/capabilities/fakes/standard_capabilities_mocks.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ func (k *KVStoreMock) Get(ctx context.Context, key string) ([]byte, error) {
2323
return nil, nil
2424
}
2525

26+
type KeystoreMock struct{}
27+
28+
func (k *KeystoreMock) Accounts(ctx context.Context) (accounts []string, err error) {
29+
return nil, nil
30+
}
31+
func (k *KeystoreMock) Sign(ctx context.Context, account string, data []byte) (signed []byte, err error) {
32+
return nil, nil
33+
}
34+
2635
type ErrorLogMock struct{}
2736

2837
func (e *ErrorLogMock) SaveError(ctx context.Context, msg string) error {

core/capabilities/integration_tests/framework/capabilities_registry.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/smartcontractkit/chainlink-common/pkg/capabilities/pb"
1313
"github.com/smartcontractkit/chainlink-common/pkg/values"
1414
kcr "github.com/smartcontractkit/chainlink-evm/gethwrappers/keystone/generated/capabilities_registry_1_1_0"
15+
p2ptypes "github.com/smartcontractkit/chainlink/v2/core/services/p2p/types"
1516

1617
"github.com/stretchr/testify/require"
1718
)
@@ -88,9 +89,14 @@ func (r *CapabilitiesRegistry) setupDON(donInfo DonConfiguration, capabilities [
8889

8990
r.backend.Commit()
9091

92+
peerIDs := make([][32]byte, 0, len(donInfo.p2pKeys))
9193
nodes := []kcr.CapabilitiesRegistryNodeParams{}
92-
for _, peerID := range donInfo.peerIDs {
93-
n, innerErr := peerToNode(r.nodeOperatorID, peerID)
94+
for i, p2pkey := range donInfo.p2pKeys {
95+
signer, innerErr := getSignerStringFromOCRKeyBundle(donInfo.KeyBundles[i])
96+
require.NoError(r.t, innerErr)
97+
peer := peerIDAndOCRSigner{PeerID: p2ptypes.PeerID(p2pkey.PeerID()), Signer: signer}
98+
peerIDs = append(peerIDs, p2pkey.PeerID())
99+
n, innerErr := peerToNode(r.nodeOperatorID, peer)
94100
require.NoError(r.t, innerErr)
95101

96102
n.HashedCapabilityIds = hashedCapabilityIDs
@@ -101,9 +107,6 @@ func (r *CapabilitiesRegistry) setupDON(donInfo DonConfiguration, capabilities [
101107
require.NoError(r.t, err)
102108
r.backend.Commit()
103109

104-
ps, err := peers(donInfo.peerIDs)
105-
require.NoError(r.t, err)
106-
107110
var capabilityConfigurations []kcr.CapabilitiesRegistryCapabilityConfiguration
108111
for i, c := range capabilities {
109112
configBinary, err2 := proto.Marshal(c.donCapabilityConfig)
@@ -115,7 +118,7 @@ func (r *CapabilitiesRegistry) setupDON(donInfo DonConfiguration, capabilities [
115118
})
116119
}
117120

118-
_, err = r.contract.AddDON(r.backend.transactionOpts, ps, capabilityConfigurations, true, donInfo.AcceptsWorkflows, donInfo.F)
121+
_, err = r.contract.AddDON(r.backend.transactionOpts, peerIDs, capabilityConfigurations, true, donInfo.AcceptsWorkflows, donInfo.F)
119122
require.NoError(r.t, err)
120123
r.backend.Commit()
121124

core/capabilities/integration_tests/framework/don.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ type capabilityNode struct {
114114
registry *capabilities.Registry
115115
key ethkey.KeyV2
116116
KeyBundle ocr2key.KeyBundle
117-
peerID peer
117+
peer peerIDAndOCRSigner
118118
start func()
119119
}
120120

@@ -164,11 +164,13 @@ func NewDON(ctx context.Context, t *testing.T, lggr logger.Logger, donConfig Don
164164
CapabilityDONs: dependentDONs,
165165
}
166166

167+
signer, err := getSignerStringFromOCRKeyBundle(donConfig.KeyBundles[i])
168+
require.NoError(t, err)
167169
cn := &capabilityNode{
168170
registry: capabilityRegistry,
169171
key: donConfig.keys[i],
170172
KeyBundle: donConfig.KeyBundles[i],
171-
peerID: donConfig.peerIDs[i],
173+
peer: peerIDAndOCRSigner{PeerID: member, Signer: signer},
172174
}
173175
don.nodes = append(don.nodes, cn)
174176

@@ -187,7 +189,7 @@ func NewDON(ctx context.Context, t *testing.T, lggr logger.Logger, donConfig Don
187189
modifier(c, cn)
188190
}
189191
}, donContext.syncerFetcherFunc, donContext.computeFetcherFactory)
190-
192+
require.NoError(t, node.KeyStore.P2P().Add(ctx, donConfig.p2pKeys[i]))
191193
require.NoError(t, node.Start(testutils.Context(t)))
192194
cn.TestApplication = node
193195
}
@@ -231,12 +233,8 @@ func (d *DON) GetExternalCapabilities() (map[CapabilityRegistration]bool, error)
231233
}
232234

233235
for _, node := range d.nodes {
234-
peerIDBytes, err := peerIDToBytes(node.peerID.PeerID)
235-
if err != nil {
236-
return nil, fmt.Errorf("failed to convert peer ID to bytes: %w", err)
237-
}
238236
result[CapabilityRegistration{
239-
nodePeerID: hex.EncodeToString(peerIDBytes[:]),
237+
nodePeerID: hex.EncodeToString(node.peer.PeerID[:]),
240238
capabilityID: publishedCapability.registryConfig.LabelledName + "@" + publishedCapability.registryConfig.Version,
241239
capabilityDonID: d.GetID(),
242240
}] = true
@@ -254,8 +252,12 @@ func (d *DON) GetF() uint8 {
254252
return d.config.F
255253
}
256254

257-
func (d *DON) GetPeerIDs() []peer {
258-
return d.config.peerIDs
255+
func (d *DON) GetPeerIDsAndOCRSigners() []peerIDAndOCRSigner {
256+
peers := make([]peerIDAndOCRSigner, 0, len(d.nodes))
257+
for _, node := range d.nodes {
258+
peers = append(peers, node.peer)
259+
}
260+
return peers
259261
}
260262

261263
func (d *DON) Start(ctx context.Context) error {

core/capabilities/integration_tests/framework/don_configuration.go

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
commoncap "github.com/smartcontractkit/chainlink-common/pkg/capabilities"
88
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ethkey"
99
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ocr2key"
10+
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey"
1011
p2ptypes "github.com/smartcontractkit/chainlink/v2/core/services/p2p/types"
1112
)
1213

@@ -15,7 +16,7 @@ type DonConfiguration struct {
1516
name string
1617
keys []ethkey.KeyV2
1718
KeyBundles []ocr2key.KeyBundle
18-
peerIDs []peer
19+
p2pKeys []p2pkey.KeyV2
1920
}
2021

2122
// NewDonConfigurationParams exists purely to make it obvious in the test code what DON configuration is being used
@@ -31,20 +32,15 @@ func NewDonConfiguration(don NewDonConfigurationParams) (DonConfiguration, error
3132
return DonConfiguration{}, errors.New("invalid configuration, number of nodes must be at least 3*F+1")
3233
}
3334

34-
keyBundles, peerIDs, err := getKeyBundlesAndPeerIDs(don.Name, don.NumNodes)
35+
keyBundles, p2pKeys, err := getKeyBundlesAndP2PKeys(don.Name, don.NumNodes)
3536
if err != nil {
36-
return DonConfiguration{}, fmt.Errorf("failed to get key bundles and peer IDs: %w", err)
37+
return DonConfiguration{}, fmt.Errorf("failed to get key bundles and p2p keys: %w", err)
3738
}
3839

39-
donPeers := make([]p2ptypes.PeerID, len(peerIDs))
40+
donPeers := make([]p2ptypes.PeerID, len(p2pKeys))
4041
var donKeys []ethkey.KeyV2
41-
for i := 0; i < len(peerIDs); i++ {
42-
peerID := p2ptypes.PeerID{}
43-
err = peerID.UnmarshalText([]byte(peerIDs[i].PeerID))
44-
if err != nil {
45-
return DonConfiguration{}, fmt.Errorf("failed to unmarshal peer ID: %w", err)
46-
}
47-
donPeers[i] = peerID
42+
for i := 0; i < len(p2pKeys); i++ {
43+
donPeers[i] = p2ptypes.PeerID(p2pKeys[i].PeerID())
4844
newKey, err := ethkey.NewV2()
4945
if err != nil {
5046
return DonConfiguration{}, fmt.Errorf("failed to create key: %w", err)
@@ -60,7 +56,7 @@ func NewDonConfiguration(don NewDonConfigurationParams) (DonConfiguration, error
6056
AcceptsWorkflows: don.AcceptsWorkflows,
6157
},
6258
name: don.Name,
63-
peerIDs: peerIDs,
59+
p2pKeys: p2pKeys,
6460
keys: donKeys,
6561
KeyBundles: keyBundles,
6662
}

0 commit comments

Comments
 (0)