Skip to content

Commit

Permalink
[CAPPL-332] Persist the workflow key in the database (#15475)
Browse files Browse the repository at this point in the history
* [CAPPL-332] Actually store the workflow key in the database

* More debug logging

* Fix tests
  • Loading branch information
cedric-cordenier authored Dec 3, 2024
1 parent f6dfb4e commit 9deaaf5
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 244 deletions.
2 changes: 2 additions & 0 deletions core/capabilities/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ func (w *launcher) Name() string {
}

func (w *launcher) Launch(ctx context.Context, state *registrysyncer.LocalRegistry) error {
w.lggr.Debug("CapabilitiesLauncher triggered...")
w.registry.SetLocalRegistry(state)

allDONIDs := []registrysyncer.DonID{}
Expand Down Expand Up @@ -222,6 +223,7 @@ func (w *launcher) Launch(ctx context.Context, state *registrysyncer.LocalRegist
return errors.New("invariant violation: node is part of more than one workflowDON")
}

w.lggr.Debug("Notifying DON set...")
w.workflowDonNotifier.NotifyDonSet(myDON.DON)

for _, rcd := range remoteCapabilityDONs {
Expand Down
10 changes: 4 additions & 6 deletions core/cmd/shell_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,14 +469,12 @@ func (s *Shell) runNode(c *cli.Context) error {
}
}

if s.Config.Capabilities().WorkflowRegistry().Address() != "" {
err2 := app.GetKeyStore().Workflow().EnsureKey(rootCtx)
if err2 != nil {
return errors.Wrap(err2, "failed to ensure workflow key")
}
err2 := app.GetKeyStore().Workflow().EnsureKey(rootCtx)
if err2 != nil {
return errors.Wrap(err2, "failed to ensure workflow key")
}

err2 := app.GetKeyStore().CSA().EnsureKey(rootCtx)
err2 = app.GetKeyStore().CSA().EnsureKey(rootCtx)
if err2 != nil {
return errors.Wrap(err2, "failed to ensure CSA key")
}
Expand Down
253 changes: 15 additions & 238 deletions core/scripts/keystone/src/05_deploy_initialize_capabilities_registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@ import (
"log"
"os"
"strings"
"time"

"github.com/ethereum/go-ethereum/common"
"google.golang.org/protobuf/proto"
"google.golang.org/protobuf/types/known/durationpb"

ragetypes "github.com/smartcontractkit/libocr/ragep2p/types"

Expand All @@ -34,126 +32,24 @@ type peer struct {
var (
workflowDonPeers = []peer{
{
PeerID: "12D3KooWBCF1XT5Wi8FzfgNCqRL76Swv8TRU3TiD4QiJm8NMNX7N",
Signer: "0x9639dCc7D0ca4468B5f684ef89F12F0B365c9F6d",
EncryptionPublicKey: "0xe7f44e3eedf3527199efec7334183b5384ba0e7c7c57b390b63a3de5a10cd53c",
PeerID: "12D3KooWQXfwA26jysiKKPXKuHcJtWTbGSwzoJxj4rYtEJyQTnFj",
Signer: "0xC44686106b85687F741e1d6182a5e2eD2211a115",
EncryptionPublicKey: "0x0f8b6629bc26321b39dfb7e2bc096584fe43dccfda54b67c24f53fd827efbc72",
},
{
PeerID: "12D3KooWG1AyvwmCpZ93J8pBQUE1SuzrjDXnT4BeouncHR3jWLCG",
Signer: "0x8f0fAE64f5f75067833ed5deDC2804B62b21383d",
EncryptionPublicKey: "0x315c6097f89baef3c3ae1503b801aaabf411134ffec66bbe8d1d184540588728",
PeerID: "12D3KooWGCRg5wNKoRFUAypA68ZkwXz8dT5gyF3VdQpEH3FtLqHZ",
Signer: "0x0ee7C8Aa7F8cb5E08415C57B79d7d387F2665E8b",
EncryptionPublicKey: "0x4cb8a297d524469e63e8d8a15c7682891126987acaa39bc4f1db78c066f7af63",
},
{
PeerID: "12D3KooWGeUKZBRMbx27FUTgBwZa9Ap9Ym92mywwpuqkEtz8XWyv",
Signer: "0xf09A863D920840c13277e76F43CFBdfB22b8FB7C",
EncryptionPublicKey: "0xa7a5e118213552a939f310e19167f49e9ad952cfe9d51eaae1ad37d92d9f0583",
PeerID: "12D3KooWHggbPfMcSSAwpBZHvwpo2UHzkf1ij3qjTnRiWQ7S5p4g",
Signer: "0xEd850731Be048afE986DaA90Bb482BC3b0f78aec",
EncryptionPublicKey: "0x7a9be509ace5f004fa397b7013893fed13a135dd273f7293dc3c7b6e57f1764e",
},
{
PeerID: "12D3KooW9zYWQv3STmDeNDidyzxsJSTxoCTLicafgfeEz9nhwhC4",
Signer: "0x7eD90b519bC3054a575C464dBf39946b53Ff90EF",
EncryptionPublicKey: "0x75f75a86910eed0259e3107b3c368f72c0ad0301bac696fd340916e2437194c3",
},
{
PeerID: "12D3KooWG1AeBnSJH2mdcDusXQVye2jqodZ6pftTH98HH6xvrE97",
Signer: "0x8F572978673d711b2F061EB7d514BD46EAD6668A",
EncryptionPublicKey: "0xd032f1e884a22fd05151f59565f05a4ccbf984afccbbee13469fc25947e69360",
},
{
PeerID: "12D3KooWBf3PrkhNoPEmp7iV291YnPuuTsgEDHTscLajxoDvwHGA",
Signer: "0x21eF07Dfaf8f7C10CB0d53D18b641ee690541f9D",
EncryptionPublicKey: "0xed64ed4a2c2954f7390bfdf41a714934c0e55693ad1c0b91505d51f4eb9e4c06",
},
{
PeerID: "12D3KooWP3FrMTFXXRU2tBC8aYvEBgUX6qhcH9q2JZCUi9Wvc2GX",
Signer: "0x7Fa21F6f716CFaF8f249564D72Ce727253186C89",
EncryptionPublicKey: "0xed64ed4a2c2954f7390bfdf41a714934c0e55693ad1c0b91505d51f4eb9e4c06",
},
}
triggerDonPeers = []peer{
{
PeerID: "12D3KooWBaiTbbRwwt2fbNifiL7Ew9tn3vds9AJE3Nf3eaVBX36m",
Signer: "0x9CcE7293a4Cc2621b61193135A95928735e4795F",
EncryptionPublicKey: "0xed64ed4a2c2954f7390bfdf41a714934c0e55693ad1c0b91505d51f4eb9e4c06",
},
{
PeerID: "12D3KooWS7JSY9fzSfWgbCE1S3W2LNY6ZVpRuun74moVBkKj6utE",
Signer: "0x3c775F20bCB2108C1A818741Ce332Bb5fe0dB925",
EncryptionPublicKey: "0xed64ed4a2c2954f7390bfdf41a714934c0e55693ad1c0b91505d51f4eb9e4c06",
},
{
PeerID: "12D3KooWMMTDXcWhpVnwrdAer1jnVARTmnr3RyT3v7Djg8ZuoBh9",
Signer: "0x50314239e2CF05555ceeD53E7F47eB2A8Eab0dbB",
EncryptionPublicKey: "0xce0e88d12d568653757f1db154f9c503db3d3d7b37cb03d84b61f39f09824cc0",
},
{
PeerID: "12D3KooWGzVXsKxXsF4zLgxSDM8Gzx1ywq2pZef4PrHMKuVg4K3P",
Signer: "0xd76A4f98898c3b9A72b244476d7337b50D54BCd8",
EncryptionPublicKey: "0xce0e88d12d568653757f1db154f9c503db3d3d7b37cb03d84b61f39f09824cc0",
},
{
PeerID: "12D3KooWSyjmmzjVtCzwN7bXzZQFmWiJRuVcKBerNjVgL7HdLJBW",
Signer: "0x656A873f6895b8a03Fb112dE927d43FA54B2c92A",
EncryptionPublicKey: "0x91f11910104ff55209d6d344a15eef6a222a54d4973aaebd301807444b555e3f",
},
{
PeerID: "12D3KooWLGz9gzhrNsvyM6XnXS3JRkZoQdEzuAvysovnSChNK5ZK",
Signer: "0x5d1e87d87bF2e0cD4Ea64F381a2dbF45e5f0a553",
EncryptionPublicKey: "0x20ff771215e567cf7e9a1fea8f2d4df90adc8303794175f79893037ff8808b51",
},
{
PeerID: "12D3KooWAvZnvknFAfSiUYjATyhzEJLTeKvAzpcLELHi4ogM3GET",
Signer: "0x91d9b0062265514f012Eb8fABA59372fD9520f56",
EncryptionPublicKey: "0x54176f154052068943569b676fa7eec7dc836e17bbe743ce56b1c7e205191d9c",
},
}
targetDonPeers = []peer{
{
PeerID: "12D3KooWJrthXtnPHw7xyHFAxo6NxifYTvc8igKYaA6wRRRqtsMb",
Signer: "0x3F82750353Ea7a051ec9bA011BC628284f9a5327",
EncryptionPublicKey: "0x1a746e0fcaf3e50db87bcc765fbbaee7d24a28166ea1461338a03fcbffb088cf",
},
{
PeerID: "12D3KooWFQekP9sGex4XhqEJav5EScjTpDVtDqJFg1JvrePBCEGJ",
Signer: "0xc23545876A208AA0443B1b8d552c7be4FF4b53F0",
EncryptionPublicKey: "0x1a746e0fcaf3e50db87bcc765fbbaee7d24a28166ea1461338a03fcbffb088cf",
},
{
PeerID: "12D3KooWFLEq4hYtdyKWwe47dXGEbSiHMZhmr5xLSJNhpfiEz8NF",
Signer: "0x82601Fa43d8B1dC1d4eB640451aC86a7CDA37011",
EncryptionPublicKey: "0x1a746e0fcaf3e50db87bcc765fbbaee7d24a28166ea1461338a03fcbffb088cf",
},
{
PeerID: "12D3KooWN2hztiXNNS1jMQTTvvPRYcarK1C7T3Mdqk4x4gwyo5WS",
Signer: "0x1a684B3d8f917fe496b7B1A8b29EDDAED64F649f",
EncryptionPublicKey: "0x1a746e0fcaf3e50db87bcc765fbbaee7d24a28166ea1461338a03fcbffb088cf",
},
}

aptosTargetDonPeers = []peer{
{
PeerID: "12D3KooWNBr1AD3vD3dzSLgg1tK56qyJoenDx7EYNnZpbr1g4jD6",
Signer: "a41f9a561ff2266d94240996a76f9c2b3b7d8184",
EncryptionPublicKey: "0xf28fcfaf2933289b3a98d387f6edf85853df32528c094dee9e737f4ca63e5a30",
},
{
PeerID: "12D3KooWRRgWiZGw5GYsPa62CkwFNKJb5u4hWo4DinnvjG6GE6Nj",
Signer: "e4f3c7204776530fb7833db6f9dbfdb8bd0ec96892965324a71c20d6776f67f0",
EncryptionPublicKey: "0x49c837675372d8f430e69ccd91c43029600c2c6469a2f933c4a1c4bbbc974c6d",
},
{
PeerID: "12D3KooWKwzgUHw5YbqUsYUVt3yiLSJcqc8ANofUtqHX6qTm7ox2",
Signer: "4071ea00e2e2c76b3406018ba9f66bf6b9aee3a6762e62ac823b1ee91ba7d7b0",
EncryptionPublicKey: "0x8fe005ef16d57091160c0b4373232e7389c321dff971fc0251a39e360d9ac34a",
},
{
PeerID: "12D3KooWBRux5o2bw1j3SQwEHzCspjkt7Xe3Y3agRUuab2SUnExj",
Signer: "6f5180c7d276876dbe413bf9b0efff7301d1367f39f4bac64180090cab70989b",
EncryptionPublicKey: "0x90dd41db21351c06396761dd683a82c791cd71e536fce246e582a4ef058091ae",
},
{
PeerID: "12D3KooWFqvDaMSDGa6eMSTF9en6G2c3ZbGLmaA5Xs3AgxVBPb8B",
Signer: "dbce9a6df8a04d54e52a109d01ee9b5d32873b1d2436cf7b7fae61fd6eca46f8",
EncryptionPublicKey: "0x87cf298dd236a307ea887cd5d81eb0b708e3dd48c984c0700bb26c072e427942",
PeerID: "12D3KooWC44picK3WvVkP1oufHYu1mB18xUg6mF2sNKM8Hc3EmdW",
Signer: "0xD3400B75f2016878dC2013ff2bC2Cf03bD5F19f5",
EncryptionPublicKey: "0x66dcec518809c1dd4ec5c094f651061b974d3cdbf5388cf4f47740c76fb58616",
},
}

Expand Down Expand Up @@ -304,7 +200,7 @@ func (c *deployAndInitializeCapabilitiesRegistryCommand) Run(args []string) {
Version: "1.0.0",
CapabilityType: uint8(0), // trigger
}
sid, err := reg.GetHashedCapabilityId(&bind.CallOpts{}, streamsTrigger.LabelledName, streamsTrigger.Version)
_, err = reg.GetHashedCapabilityId(&bind.CallOpts{}, streamsTrigger.LabelledName, streamsTrigger.Version)
if err != nil {
panic(err)
}
Expand Down Expand Up @@ -334,7 +230,7 @@ func (c *deployAndInitializeCapabilitiesRegistryCommand) Run(args []string) {
Version: "1.0.0",
CapabilityType: uint8(3), // target
}
wid, err := reg.GetHashedCapabilityId(&bind.CallOpts{}, writeChain.LabelledName, writeChain.Version)
_, err = reg.GetHashedCapabilityId(&bind.CallOpts{}, writeChain.LabelledName, writeChain.Version)
if err != nil {
log.Printf("failed to call GetHashedCapabilityId: %s", err)
}
Expand All @@ -344,7 +240,7 @@ func (c *deployAndInitializeCapabilitiesRegistryCommand) Run(args []string) {
Version: "1.0.0",
CapabilityType: uint8(3), // target
}
awid, err := reg.GetHashedCapabilityId(&bind.CallOpts{}, aptosWriteChain.LabelledName, aptosWriteChain.Version)
_, err = reg.GetHashedCapabilityId(&bind.CallOpts{}, aptosWriteChain.LabelledName, aptosWriteChain.Version)
if err != nil {
log.Printf("failed to call GetHashedCapabilityId: %s", err)
}
Expand Down Expand Up @@ -402,36 +298,6 @@ func (c *deployAndInitializeCapabilitiesRegistryCommand) Run(args []string) {
nodes = append(nodes, n)
}

for _, triggerPeer := range triggerDonPeers {
n, innerErr := peerToNode(nopID, triggerPeer)
if innerErr != nil {
panic(innerErr)
}

n.HashedCapabilityIds = [][32]byte{sid}
nodes = append(nodes, n)
}

for _, targetPeer := range targetDonPeers {
n, innerErr := peerToNode(nopID, targetPeer)
if innerErr != nil {
panic(innerErr)
}

n.HashedCapabilityIds = [][32]byte{wid}
nodes = append(nodes, n)
}

for _, targetPeer := range aptosTargetDonPeers {
n, innerErr := peerToNode(nopID, targetPeer)
if innerErr != nil {
panic(innerErr)
}

n.HashedCapabilityIds = [][32]byte{awid}
nodes = append(nodes, n)
}

tx, err = reg.AddNodes(env.Owner, nodes)
if err != nil {
log.Printf("failed to AddNodes: %s", err)
Expand Down Expand Up @@ -476,95 +342,6 @@ func (c *deployAndInitializeCapabilitiesRegistryCommand) Run(args []string) {
log.Printf("workflowDON: failed to AddDON: %s", err)
}

// trigger DON
ps, err = peers(triggerDonPeers)
if err != nil {
panic(err)
}

config := &capabilitiespb.CapabilityConfig{
DefaultConfig: values.Proto(values.EmptyMap()).GetMapValue(),
RemoteConfig: &capabilitiespb.CapabilityConfig_RemoteTriggerConfig{
RemoteTriggerConfig: &capabilitiespb.RemoteTriggerConfig{
RegistrationRefresh: durationpb.New(20 * time.Second),
RegistrationExpiry: durationpb.New(60 * time.Second),
// F + 1
MinResponsesToAggregate: uint32(1) + 1,
},
},
}
configb, err := proto.Marshal(config)
if err != nil {
panic(err)
}
cfgs = []kcr.CapabilitiesRegistryCapabilityConfiguration{
{
CapabilityId: sid,
Config: configb,
},
}
_, err = reg.AddDON(env.Owner, ps, cfgs, true, false, 1)
if err != nil {
log.Printf("triggerDON: failed to AddDON: %s", err)
}

// target DON
ps, err = peers(targetDonPeers)
if err != nil {
panic(err)
}

targetCapabilityConfig := newCapabilityConfig()
targetCapabilityConfig.RemoteConfig = &capabilitiespb.CapabilityConfig_RemoteTargetConfig{
RemoteTargetConfig: &capabilitiespb.RemoteTargetConfig{
RequestHashExcludedAttributes: []string{"signed_report.Signatures"},
},
}

remoteTargetConfigBytes, err := proto.Marshal(targetCapabilityConfig)
if err != nil {
panic(err)
}

cfgs = []kcr.CapabilitiesRegistryCapabilityConfiguration{
{
CapabilityId: wid,
Config: remoteTargetConfigBytes,
},
}
_, err = reg.AddDON(env.Owner, ps, cfgs, true, false, 1)
if err != nil {
log.Printf("targetDON: failed to AddDON: %s", err)
}

// Aptos target DON
ps, err = peers(aptosTargetDonPeers)
if err != nil {
panic(err)
}

targetCapabilityConfig = newCapabilityConfig()
targetCapabilityConfig.RemoteConfig = &capabilitiespb.CapabilityConfig_RemoteTargetConfig{
RemoteTargetConfig: &capabilitiespb.RemoteTargetConfig{
RequestHashExcludedAttributes: []string{"signed_report.Signatures"},
},
}

remoteTargetConfigBytes, err = proto.Marshal(targetCapabilityConfig)
if err != nil {
panic(err)
}

cfgs = []kcr.CapabilitiesRegistryCapabilityConfiguration{
{
CapabilityId: awid,
Config: remoteTargetConfigBytes,
},
}
_, err = reg.AddDON(env.Owner, ps, cfgs, true, false, 1)
if err != nil {
log.Printf("targetDON: failed to AddDON: %s", err)
}
}

func deployCapabilitiesRegistry(env helpers.Environment) *kcr.CapabilitiesRegistry {
Expand Down
1 change: 1 addition & 0 deletions core/services/chainlink/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,7 @@ func NewApplication(opts ApplicationOpts) (Application, error) {
return relayer.NewContractReader(ctx, bytes)
}, eventHandler)

globalLogger.Debugw("Creating WorkflowRegistrySyncer")
wfSyncer := syncer.NewWorkflowRegistry(globalLogger, func(ctx context.Context, bytes []byte) (syncer.ContractReader, error) {
return relayer.NewContractReader(ctx, bytes)
}, cfg.Capabilities().WorkflowRegistry().Address(),
Expand Down
1 change: 1 addition & 0 deletions core/services/keystore/keystoretest.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,5 +75,6 @@ func NewInMemory(ds sqlutil.DataSource, scryptParams utils.ScryptParams, lggr lo
starknet: newStarkNetKeyStore(km),
aptos: newAptosKeyStore(km),
vrf: newVRFKeyStore(km),
workflow: newWorkflowKeyStore(km),
}
}
Loading

0 comments on commit 9deaaf5

Please sign in to comment.