Skip to content

Commit

Permalink
feat: expose workflow key to clo
Browse files Browse the repository at this point in the history
  • Loading branch information
agparadiso committed Nov 18, 2024
1 parent 7cd17d6 commit 875d583
Show file tree
Hide file tree
Showing 14 changed files with 568 additions and 45 deletions.
1 change: 1 addition & 0 deletions .mockery.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ packages:
config:
filename: starknet.go
VRF:
Workflow:
github.com/smartcontractkit/chainlink/v2/core/services/ocr:
interfaces:
OCRContractTrackerDB:
Expand Down
2 changes: 1 addition & 1 deletion core/scripts/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ require (
github.com/smartcontractkit/chainlink-data-streams v0.1.1-0.20241018134907-a00ba3729b5e // indirect
github.com/smartcontractkit/chainlink-feeds v0.1.1 // indirect
github.com/smartcontractkit/chainlink-protos/job-distributor v0.4.0 // indirect
github.com/smartcontractkit/chainlink-protos/orchestrator v0.3.0 // indirect
github.com/smartcontractkit/chainlink-protos/orchestrator v0.3.1 // indirect
github.com/smartcontractkit/chainlink-solana v1.1.1-0.20241115191142-8b8369c1f44e // indirect
github.com/smartcontractkit/chainlink-starknet/relayer v0.1.1-0.20241017135645-176a23722fd8 // indirect
github.com/smartcontractkit/chainlink-testing-framework/lib v1.50.13 // indirect
Expand Down
4 changes: 2 additions & 2 deletions core/scripts/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1419,8 +1419,8 @@ github.com/smartcontractkit/chainlink-feeds v0.1.1 h1:JzvUOM/OgGQA1sOqTXXl52R6An
github.com/smartcontractkit/chainlink-feeds v0.1.1/go.mod h1:55EZ94HlKCfAsUiKUTNI7QlE/3d3IwTlsU3YNa/nBb4=
github.com/smartcontractkit/chainlink-protos/job-distributor v0.4.0 h1:1xTm8UGeDUAjvCXRh08+4xBRX33owH5MqC522JdelM0=
github.com/smartcontractkit/chainlink-protos/job-distributor v0.4.0/go.mod h1:/dVVLXrsp+V0AbcYGJo3XMzKg3CkELsweA/TTopCsKE=
github.com/smartcontractkit/chainlink-protos/orchestrator v0.3.0 h1:PBUaFfPLm+Efq7H9kdfGBivH+QhJ6vB5EZTR/sCZsxI=
github.com/smartcontractkit/chainlink-protos/orchestrator v0.3.0/go.mod h1:m/A3lqD7ms/RsQ9BT5P2uceYY0QX5mIt4KQxT2G6qEo=
github.com/smartcontractkit/chainlink-protos/orchestrator v0.3.1 h1:r8shFMAbMmhAcXWrj/etTbdv+ghyzFpiK/uCOP5ijgE=
github.com/smartcontractkit/chainlink-protos/orchestrator v0.3.1/go.mod h1:m/A3lqD7ms/RsQ9BT5P2uceYY0QX5mIt4KQxT2G6qEo=
github.com/smartcontractkit/chainlink-solana v1.1.1-0.20241115191142-8b8369c1f44e h1:XxTWJ9VIXK+XuAjP5131PqqBn0NEt5lBvnRAWRdqy8A=
github.com/smartcontractkit/chainlink-solana v1.1.1-0.20241115191142-8b8369c1f44e/go.mod h1:mGmRvlk54ufCufV4EBWizOGtXoXfePoFAuYEVC8EwdY=
github.com/smartcontractkit/chainlink-starknet/relayer v0.1.1-0.20241017135645-176a23722fd8 h1:B4DFdk6MGcQnoCjjMBCx7Z+GWQpxRWJ4O8W/dVJyWGA=
Expand Down
22 changes: 22 additions & 0 deletions core/services/feeds/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/keystore"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ocrkey"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/p2pkey"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/workflowkey"
"github.com/smartcontractkit/chainlink/v2/core/services/ocr"
ocr2 "github.com/smartcontractkit/chainlink/v2/core/services/ocr2/validate"
"github.com/smartcontractkit/chainlink/v2/core/services/ocrbootstrap"
Expand Down Expand Up @@ -126,6 +127,7 @@ type service struct {
p2pKeyStore keystore.P2P
ocr1KeyStore keystore.OCR
ocr2KeyStore keystore.OCR2
workflowKeyStore keystore.Workflow
jobSpawner job.Spawner
gCfg GeneralConfig
featCfg FeatureConfig
Expand Down Expand Up @@ -168,6 +170,7 @@ func NewService(
csaKeyStore: keyStore.CSA(),
ocr1KeyStore: keyStore.OCR(),
ocr2KeyStore: keyStore.OCR2(),
workflowKeyStore: keyStore.Workflow(),
gCfg: gCfg,
featCfg: fCfg,
insecureCfg: insecureCfg,
Expand Down Expand Up @@ -275,9 +278,15 @@ func (s *service) SyncNodeInfo(ctx context.Context, id int64) error {
cfgMsgs = append(cfgMsgs, cfgMsg)
}

workflowKey, err := s.getWorkflowKey()
if err != nil {
return errors.Wrap(err, "could not fetch workflow key")
}

if _, err = fmsClient.UpdateNode(ctx, &pb.UpdateNodeRequest{
Version: s.version,
ChainConfigs: cfgMsgs,
WorkflowKey: workflowKey.PublicKeyString(),
}); err != nil {
return err
}
Expand Down Expand Up @@ -1143,6 +1152,19 @@ func (s *service) getCSAPrivateKey() (privkey []byte, err error) {
return keys[0].Raw(), nil
}

// getWorkflowKey gets the server's Workflow key
// because we will have only one key, we can get the first key
func (s *service) getWorkflowKey() (*workflowkey.Key, error) {
keys, err := s.workflowKeyStore.GetAll()
if err != nil {
return nil, err
}
if len(keys) < 1 {
return nil, errors.New("Workflow key does not exist")
}
return &keys[0], nil
}

// observeJobProposalCounts is a helper method that queries the repository for the count of
// job proposals by status and then updates prometheus gauges.
func (s *service) observeJobProposalCounts(ctx context.Context) error {
Expand Down
86 changes: 56 additions & 30 deletions core/services/feeds/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import (
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/csakey"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/keystest"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/ocrkey"
"github.com/smartcontractkit/chainlink/v2/core/services/keystore/keys/workflowkey"
ksmocks "github.com/smartcontractkit/chainlink/v2/core/services/keystore/mocks"
"github.com/smartcontractkit/chainlink/v2/core/services/pipeline"
"github.com/smartcontractkit/chainlink/v2/core/services/versioning"
Expand Down Expand Up @@ -146,16 +147,17 @@ chainID = 1337

type TestService struct {
feeds.Service
orm *mocks.ORM
jobORM *jobmocks.ORM
connMgr *mocks.ConnectionsManager
spawner *jobmocks.Spawner
fmsClient *mocks.FeedsManagerClient
csaKeystore *ksmocks.CSA
p2pKeystore *ksmocks.P2P
ocr1Keystore *ksmocks.OCR
ocr2Keystore *ksmocks.OCR2
legacyChains legacyevm.LegacyChainContainer
orm *mocks.ORM
jobORM *jobmocks.ORM
connMgr *mocks.ConnectionsManager
spawner *jobmocks.Spawner
fmsClient *mocks.FeedsManagerClient
csaKeystore *ksmocks.CSA
p2pKeystore *ksmocks.P2P
ocr1Keystore *ksmocks.OCR
ocr2Keystore *ksmocks.OCR2
workflowKeystore *ksmocks.Workflow
legacyChains legacyevm.LegacyChainContainer
}

func setupTestService(t *testing.T) *TestService {
Expand All @@ -168,15 +170,16 @@ func setupTestServiceCfg(t *testing.T, overrideCfg func(c *chainlink.Config, s *
t.Helper()

var (
orm = mocks.NewORM(t)
jobORM = jobmocks.NewORM(t)
connMgr = mocks.NewConnectionsManager(t)
spawner = jobmocks.NewSpawner(t)
fmsClient = mocks.NewFeedsManagerClient(t)
csaKeystore = ksmocks.NewCSA(t)
p2pKeystore = ksmocks.NewP2P(t)
ocr1Keystore = ksmocks.NewOCR(t)
ocr2Keystore = ksmocks.NewOCR2(t)
orm = mocks.NewORM(t)
jobORM = jobmocks.NewORM(t)
connMgr = mocks.NewConnectionsManager(t)
spawner = jobmocks.NewSpawner(t)
fmsClient = mocks.NewFeedsManagerClient(t)
csaKeystore = ksmocks.NewCSA(t)
p2pKeystore = ksmocks.NewP2P(t)
ocr1Keystore = ksmocks.NewOCR(t)
ocr2Keystore = ksmocks.NewOCR2(t)
workflowKeystore = ksmocks.NewWorkflow(t)
)

lggr := logger.TestLogger(t)
Expand All @@ -192,21 +195,23 @@ func setupTestServiceCfg(t *testing.T, overrideCfg func(c *chainlink.Config, s *
keyStore.On("P2P").Return(p2pKeystore)
keyStore.On("OCR").Return(ocr1Keystore)
keyStore.On("OCR2").Return(ocr2Keystore)
keyStore.On("Workflow").Return(workflowKeystore)
svc := feeds.NewService(orm, jobORM, db, spawner, keyStore, gcfg, gcfg.Feature(), gcfg.Insecure(), gcfg.JobPipeline(), gcfg.OCR(), gcfg.OCR2(), legacyChains, lggr, "1.0.0", nil)
svc.SetConnectionsManager(connMgr)

return &TestService{
Service: svc,
orm: orm,
jobORM: jobORM,
connMgr: connMgr,
spawner: spawner,
fmsClient: fmsClient,
csaKeystore: csaKeystore,
p2pKeystore: p2pKeystore,
ocr1Keystore: ocr1Keystore,
ocr2Keystore: ocr2Keystore,
legacyChains: legacyChains,
Service: svc,
orm: orm,
jobORM: jobORM,
connMgr: connMgr,
spawner: spawner,
fmsClient: fmsClient,
csaKeystore: csaKeystore,
p2pKeystore: p2pKeystore,
ocr1Keystore: ocr1Keystore,
ocr2Keystore: ocr2Keystore,
workflowKeystore: workflowKeystore,
legacyChains: legacyChains,
}
}

Expand Down Expand Up @@ -576,6 +581,10 @@ func Test_Service_CreateChainConfig(t *testing.T) {
svc = setupTestService(t)
)

workflowKey, err := workflowkey.New()
require.NoError(t, err)
svc.workflowKeystore.On("GetAll").Return([]workflowkey.Key{workflowKey}, nil)

svc.orm.On("CreateChainConfig", mock.Anything, cfg).Return(int64(1), nil)
svc.orm.On("GetManager", mock.Anything, mgr.ID).Return(&mgr, nil)
svc.connMgr.On("GetClient", mgr.ID).Return(svc.fmsClient, nil)
Expand All @@ -596,6 +605,7 @@ func Test_Service_CreateChainConfig(t *testing.T) {
Ocr2Config: &proto.OCR2Config{Enabled: false},
},
},
WorkflowKey: workflowKey.ID(),
}).Return(&proto.UpdateNodeResponse{}, nil)

actual, err := svc.CreateChainConfig(testutils.Context(t), cfg)
Expand Down Expand Up @@ -640,6 +650,10 @@ func Test_Service_DeleteChainConfig(t *testing.T) {
svc = setupTestService(t)
)

workflowKey, err := workflowkey.New()
require.NoError(t, err)
svc.workflowKeystore.On("GetAll").Return([]workflowkey.Key{workflowKey}, nil)

svc.orm.On("GetChainConfig", mock.Anything, cfg.ID).Return(&cfg, nil)
svc.orm.On("DeleteChainConfig", mock.Anything, cfg.ID).Return(cfg.ID, nil)
svc.orm.On("GetManager", mock.Anything, mgr.ID).Return(&mgr, nil)
Expand All @@ -648,6 +662,7 @@ func Test_Service_DeleteChainConfig(t *testing.T) {
svc.fmsClient.On("UpdateNode", mock.Anything, &proto.UpdateNodeRequest{
Version: nodeVersion.Version,
ChainConfigs: []*proto.ChainConfig{},
WorkflowKey: workflowKey.ID(),
}).Return(&proto.UpdateNodeResponse{}, nil)

actual, err := svc.DeleteChainConfig(testutils.Context(t), cfg.ID)
Expand Down Expand Up @@ -725,6 +740,10 @@ func Test_Service_UpdateChainConfig(t *testing.T) {
svc = setupTestService(t)
)

workflowKey, err := workflowkey.New()
require.NoError(t, err)
svc.workflowKeystore.On("GetAll").Return([]workflowkey.Key{workflowKey}, nil)

svc.orm.On("UpdateChainConfig", mock.Anything, cfg).Return(int64(1), nil)
svc.orm.On("GetChainConfig", mock.Anything, cfg.ID).Return(&cfg, nil)
svc.connMgr.On("GetClient", mgr.ID).Return(svc.fmsClient, nil)
Expand All @@ -745,6 +764,7 @@ func Test_Service_UpdateChainConfig(t *testing.T) {
Ocr2Config: &proto.OCR2Config{Enabled: false},
},
},
WorkflowKey: workflowKey.ID(),
}).Return(&proto.UpdateNodeResponse{}, nil)

actual, err := svc.UpdateChainConfig(testutils.Context(t), cfg)
Expand Down Expand Up @@ -1625,6 +1645,9 @@ func Test_Service_SyncNodeInfo(t *testing.T) {
ocrKey, err := ocrkey.NewV2()
require.NoError(t, err)

workflowKey, err := workflowkey.New()
require.NoError(t, err)

var (
multiaddr = "/dns4/chain.link/tcp/1234/p2p/16Uiu2HAm58SP7UL8zsnpeuwHfytLocaqgnyaYKP8wu7qRdrixLju"
mgr = &feeds.FeedsManager{ID: 1}
Expand Down Expand Up @@ -1672,6 +1695,8 @@ func Test_Service_SyncNodeInfo(t *testing.T) {
svc.p2pKeystore.On("Get", p2pKey.PeerID()).Return(p2pKey, nil)
svc.ocr1Keystore.On("Get", ocrKey.GetID()).Return(ocrKey, nil)

svc.workflowKeystore.On("GetAll").Return([]workflowkey.Key{workflowKey}, nil)

svc.fmsClient.On("UpdateNode", mock.Anything, &proto.UpdateNodeRequest{
Version: nodeVersion.Version,
ChainConfigs: []*proto.ChainConfig{
Expand Down Expand Up @@ -1712,6 +1737,7 @@ func Test_Service_SyncNodeInfo(t *testing.T) {
},
},
},
WorkflowKey: workflowKey.ID(),
}).Return(&proto.UpdateNodeResponse{}, nil)

err = svc.SyncNodeInfo(testutils.Context(t), mgr.ID)
Expand Down
Loading

0 comments on commit 875d583

Please sign in to comment.