From 57d4cca5f9b98a3acbe1763c98bf13dd204534b8 Mon Sep 17 00:00:00 2001 From: Ryan Tinianov Date: Mon, 23 Nov 2026 11:02:10 -0500 Subject: [PATCH 1/2] Add an OCR dependency --- libs/capability/internal/docgen/main.go | 2 + libs/capability/ocr/dependency.go | 77 ++ libs/capability/ocr/dependency_test.go | 37 + libs/capability/ocr/doccomments_gen.go | 13 + libs/capability/ocr/embed.go | 49 ++ libs/capability/ocr/embed_test.go | 292 ++++++++ libs/capability/ocr/inproc.go | 148 ++++ libs/capability/ocr/memorydb.go | 169 +++++ libs/capability/ocr/memorydb_test.go | 78 ++ libs/capability/ocr/network_test.go | 91 +++ libs/capability/ocr/remote/client.go | 204 +++++ .../ocr/remote/internal/pb/generate.go | 2 + .../ocr/remote/internal/pb/network.pb.go | 705 ++++++++++++++++++ .../ocr/remote/internal/pb/network.proto | 65 ++ .../ocr/remote/internal/pb/network_grpc.pb.go | 125 ++++ libs/capability/ocr/remote/remote_test.go | 231 ++++++ libs/capability/ocr/remote/server.go | 162 ++++ libs/go.mod | 7 +- libs/go.sum | 12 + 19 files changed, 2468 insertions(+), 1 deletion(-) create mode 100644 libs/capability/ocr/dependency.go create mode 100644 libs/capability/ocr/dependency_test.go create mode 100644 libs/capability/ocr/doccomments_gen.go create mode 100644 libs/capability/ocr/embed.go create mode 100644 libs/capability/ocr/embed_test.go create mode 100644 libs/capability/ocr/inproc.go create mode 100644 libs/capability/ocr/memorydb.go create mode 100644 libs/capability/ocr/memorydb_test.go create mode 100644 libs/capability/ocr/network_test.go create mode 100644 libs/capability/ocr/remote/client.go create mode 100644 libs/capability/ocr/remote/internal/pb/generate.go create mode 100644 libs/capability/ocr/remote/internal/pb/network.pb.go create mode 100644 libs/capability/ocr/remote/internal/pb/network.proto create mode 100644 libs/capability/ocr/remote/internal/pb/network_grpc.pb.go create mode 100644 libs/capability/ocr/remote/remote_test.go create mode 100644 libs/capability/ocr/remote/server.go diff --git a/libs/capability/internal/docgen/main.go b/libs/capability/internal/docgen/main.go index 1ca938f3d..a1c19927f 100644 --- a/libs/capability/internal/docgen/main.go +++ b/libs/capability/internal/docgen/main.go @@ -13,6 +13,7 @@ import ( breaking "github.com/smartcontractkit/capabilities/libs/capability/cmd/protobreaking/options" "github.com/smartcontractkit/capabilities/libs/capability/internal/example/capability/service" "github.com/smartcontractkit/capabilities/libs/capability/keystore" + "github.com/smartcontractkit/capabilities/libs/capability/ocr" ) func main() { @@ -28,6 +29,7 @@ func main() { &breaking.Options{}, &service.Config{}, &keystore.Config{}, + &ocr.Config{}, }, Tool: "github.com/smartcontractkit/capabilities/libs/capability/internal/docgen", LocalPrefix: "github.com/smartcontractkit", diff --git a/libs/capability/ocr/dependency.go b/libs/capability/ocr/dependency.go new file mode 100644 index 000000000..f836cd72e --- /dev/null +++ b/libs/capability/ocr/dependency.go @@ -0,0 +1,77 @@ +package ocr + +import ( + "errors" + "fmt" + + "github.com/samber/do/v2" + + "github.com/smartcontractkit/libocr/commontypes" + ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types" + + "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink-common/pkg/loop" + + "github.com/smartcontractkit/capabilities/libs/capability" + "github.com/smartcontractkit/capabilities/libs/capability/ocr/remote" +) + +// ConfigNamespace is the namespace Config is set under. +const ConfigNamespace = "ocr" + +// Config points this process at the node's OCR networking. +type Config struct { + // URL is the gRPC target the node serves its peer's networking on (e.g. localhost:9001). Unset means the node lends + // this process no networking. + URL string + // PeerID is the node's peer ID (e.g. 12D3KooWKh28EhBVfiiFh39w3zqtBxzYJhmGfBZNmoL4tRjMWSor). + PeerID string + // Bootstrappers are the DON's bootstrap peers (e.g. 12D3KooWFirst@127.0.0.1:6690). + Bootstrappers []commontypes.BootstrapperLocator +} + +// Network is the node's networking, which a capability's oracles talk to each other over. +type Network struct { + BinaryNetworkEndpointFactory ocrtypes.BinaryNetworkEndpointFactory + V2Bootstrappers []commontypes.BootstrapperLocator +} + +// init provides the node's networking however the capability is run: from the node at Config.URL for run and compat, +// and over the in-process network for each instance of embed. +func init() { + capability.RunInjector.MustProvideConfig(ConfigNamespace, &Config{}) + capability.RunInjector.MustProvide(newNodeNetwork) + capability.EmbedInjector.MustProvide(newEmbeddedNetwork) +} + +// newNodeNetwork connects to the node's networking. The connection lives as long as the process. +func newNodeNetwork(i do.Injector) (Network, error) { + cfg, err := do.Invoke[*Config](i) + if err != nil { + return Network{}, err + } + + if cfg.URL == "" || cfg.PeerID == "" { + return Network{}, errors.New("ocr.url and ocr.peer-id are not set, so the node lends this process no networking") + } + + lggr, err := do.Invoke[logger.Logger](i) + if err != nil { + return Network{}, err + } + + grpcOpts, err := do.Invoke[loop.GRPCOpts](i) + if err != nil { + return Network{}, err + } + + conn, err := capability.Dial(grpcOpts, cfg.URL) + if err != nil { + return Network{}, fmt.Errorf("failed to create OCR network client for %s: %w", cfg.URL, err) + } + + return Network{ + BinaryNetworkEndpointFactory: remote.NewClient(lggr, conn, cfg.PeerID), + V2Bootstrappers: cfg.Bootstrappers, + }, nil +} diff --git a/libs/capability/ocr/dependency_test.go b/libs/capability/ocr/dependency_test.go new file mode 100644 index 000000000..9d3781989 --- /dev/null +++ b/libs/capability/ocr/dependency_test.go @@ -0,0 +1,37 @@ +package ocr + +import ( + "testing" + + "github.com/samber/do/v2" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/smartcontractkit/libocr/commontypes" + + "github.com/smartcontractkit/chainlink-common/pkg/logger" + "github.com/smartcontractkit/chainlink-common/pkg/loop" +) + +func TestNewNodeNetwork(t *testing.T) { + t.Parallel() + newInjector := func(cfg *Config) do.Injector { + i := do.New() + do.ProvideValue(i, cfg) + do.ProvideValue(i, logger.Test(t)) + do.ProvideValue(i, loop.GRPCOpts{}) + return i + } + + _, err := newNodeNetwork(newInjector(&Config{PeerID: "12D3KooWPeer"})) + require.ErrorContains(t, err, "ocr.url and ocr.peer-id are not set") + + _, err = newNodeNetwork(newInjector(&Config{URL: "localhost:9001"})) + require.ErrorContains(t, err, "ocr.url and ocr.peer-id are not set") + + bootstrappers := []commontypes.BootstrapperLocator{{PeerID: "12D3KooWBoot", Addrs: []string{"127.0.0.1:6690"}}} + network, err := newNodeNetwork(newInjector(&Config{URL: "localhost:9001", PeerID: "12D3KooWPeer", Bootstrappers: bootstrappers})) + require.NoError(t, err) + assert.Equal(t, "12D3KooWPeer", network.BinaryNetworkEndpointFactory.PeerID()) + assert.Equal(t, bootstrappers, network.V2Bootstrappers) +} diff --git a/libs/capability/ocr/doccomments_gen.go b/libs/capability/ocr/doccomments_gen.go new file mode 100644 index 000000000..d6ca5bd6a --- /dev/null +++ b/libs/capability/ocr/doccomments_gen.go @@ -0,0 +1,13 @@ +// Code generated by github.com/smartcontractkit/capabilities/libs/capability/internal/docgen, DO NOT EDIT. + +package ocr + +import "github.com/smartcontractkit/chainlink-common/x/config/commentparsing" + +func (Config) DocComments() map[string]commentparsing.FieldDoc { + return map[string]commentparsing.FieldDoc{ + "Bootstrappers": {Comment: "Bootstrappers are the DON's bootstrap peers (e.g. 12D3KooWFirst@127.0.0.1:6690)."}, + "PeerID": {Comment: "PeerID is the node's peer ID (e.g. 12D3KooWKh28EhBVfiiFh39w3zqtBxzYJhmGfBZNmoL4tRjMWSor)."}, + "URL": {Comment: "URL is the gRPC target the node serves its peer's networking on (e.g. localhost:9001). Unset means the node lends\nthis process no networking."}, + } +} diff --git a/libs/capability/ocr/embed.go b/libs/capability/ocr/embed.go new file mode 100644 index 000000000..d0829fea0 --- /dev/null +++ b/libs/capability/ocr/embed.go @@ -0,0 +1,49 @@ +package ocr + +import ( + "crypto/ed25519" + "crypto/sha256" + "fmt" + "strconv" + + "github.com/samber/do/v2" + + ragetypes "github.com/smartcontractkit/libocr/ragep2p/types" + + "github.com/smartcontractkit/capabilities/libs/capability" +) + +func newEmbeddedNetwork(i do.Injector) (Network, error) { + info, err := do.Invoke[capability.InstanceInfo](i) + if err != nil { + return Network{}, err + } + + return embeddedNetwork(embedNetwork, info.ID) +} + +func embeddedNetwork(net *network, id int) (Network, error) { + peerID, err := EmbeddedPeerID(id) + if err != nil { + return Network{}, err + } + + return Network{BinaryNetworkEndpointFactory: ocr2Factory{net: net, peerID: peerID, bufferSize: defaultBufferSize}}, nil +} + +func EmbeddedPeerID(id int) (string, error) { + peerSeed := seed("peer", id) + peerID, err := ragetypes.PeerIDFromPublicKey(ed25519.NewKeyFromSeed(peerSeed[:]).Public().(ed25519.PublicKey)) + if err != nil { + return "", fmt.Errorf("failed to derive the peer ID of instance %d: %w", id, err) + } + + return peerID.String(), nil +} + +// seedPrefix separates the keys derived here from any other keys derived from an index. +const seedPrefix = "cre/capability/embed/ocr/" + +func seed(purpose string, i int) [32]byte { + return sha256.Sum256([]byte(seedPrefix + purpose + "/" + strconv.Itoa(i))) +} diff --git a/libs/capability/ocr/embed_test.go b/libs/capability/ocr/embed_test.go new file mode 100644 index 000000000..1c2975c86 --- /dev/null +++ b/libs/capability/ocr/embed_test.go @@ -0,0 +1,292 @@ +package ocr + +import ( + "context" + "crypto/ed25519" + "crypto/sha256" + "encoding/binary" + "encoding/hex" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "golang.org/x/crypto/curve25519" + + "github.com/smartcontractkit/libocr/offchainreporting2plus/confighelper" + "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3confighelper" + "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types" + ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types" +) + +const testInstances = 4 + +func TestEmbeddedOraclesReachConsensus(t *testing.T) { + t.Parallel() + inproc := newNetwork() + testOraclesReachConsensus(t, func(id int) ocrtypes.BinaryNetworkEndpointFactory { + network, err := embeddedNetwork(inproc, id) + require.NoError(t, err) + return network.BinaryNetworkEndpointFactory + }) +} + +func TestEmbeddedPeerIDsDiffer(t *testing.T) { + t.Parallel() + first, err := EmbeddedPeerID(0) + require.NoError(t, err) + again, err := EmbeddedPeerID(0) + require.NoError(t, err) + second, err := EmbeddedPeerID(1) + require.NoError(t, err) + + assert.Equal(t, first, again, "an instance's peer is derived from its index") + assert.NotEqual(t, first, second) +} + +func testLocalConfig() ocrtypes.LocalConfig { + return ocrtypes.LocalConfig{ + BlockchainTimeout: time.Second, + ContractConfigConfirmations: 1, + SkipContractConfigConfirmations: true, + ContractConfigTrackerPollInterval: time.Second, + ContractTransmitterTransmitTimeout: time.Second, + DatabaseTimeout: time.Second, + ContractConfigLoadTimeout: time.Second, + DefaultMaxDurationInitialization: time.Second, + } +} + +// testConfig is the config of a DON of the first testInstances embedded instances, with keys derived as their peers are. +func testConfig(t *testing.T) ocrtypes.ContractConfig { + t.Helper() + identities := make([]confighelper.OracleIdentityExtra, testInstances) + for i := range identities { + k := testKeysOf(t, i) + identities[i] = confighelper.OracleIdentityExtra{ + OffchainPublicKey: k.OffchainPublicKey(), + OnchainPublicKey: k.PublicKey(), + PeerID: k.peerID, + TransmitAccount: k.transmitAccount(), + ConfigEncryptionPublicKey: k.ConfigEncryptionPublicKey(), + } + } + + sharedSecret := seed("shared-secret", 0) + signers, transmitters, f, onchainConfig, offchainConfigVersion, offchainConfig, err := ocr3confighelper.ContractSetConfigArgsDeterministic( + sha256.Sum256([]byte(seedPrefix+"ephemeral")), [16]byte(sharedSecret[:16]), + 5*time.Second, // DeltaProgress + 2*time.Second, // DeltaResend + 500*time.Millisecond, // DeltaInitial + time.Second, // DeltaRound + 500*time.Millisecond, // DeltaGrace + 500*time.Millisecond, // DeltaCertifiedCommitRequest + 5*time.Second, // DeltaStage + 20, // RMax + []int{testInstances}, + identities, + nil, + nil, + 300*time.Millisecond, // MaxDurationQuery + 300*time.Millisecond, // MaxDurationObservation + 300*time.Millisecond, // MaxDurationShouldAcceptAttestedReport + 300*time.Millisecond, // MaxDurationShouldTransmitAcceptedReport + (testInstances-1)/3, + nil, + ) + require.NoError(t, err) + + config := ocrtypes.ContractConfig{ + ConfigCount: 1, + Signers: signers, + Transmitters: transmitters, + F: f, + OnchainConfig: onchainConfig, + OffchainConfigVersion: offchainConfigVersion, + OffchainConfig: offchainConfig, + } + config.ConfigDigest = sha256.Sum256(offchainConfig) + binary.BigEndian.PutUint16(config.ConfigDigest[:2], uint16(ocrtypes.ConfigDigestPrefixKeystoneOCR3Capability)) + return config +} + +// staticConfig is a config that never changes. +type staticConfig struct { + config ocrtypes.ContractConfig +} + +func (c staticConfig) Notify() <-chan struct{} { return nil } + +func (c staticConfig) LatestConfigDetails(context.Context) (uint64, ocrtypes.ConfigDigest, error) { + return 0, c.config.ConfigDigest, nil +} + +func (c staticConfig) LatestConfig(context.Context, uint64) (ocrtypes.ContractConfig, error) { + return c.config, nil +} + +func (c staticConfig) LatestBlockHeight(context.Context) (uint64, error) { return 0, nil } + +func (c staticConfig) ConfigDigest(context.Context, ocrtypes.ContractConfig) (ocrtypes.ConfigDigest, error) { + return c.config.ConfigDigest, nil +} + +func (c staticConfig) ConfigDigestPrefix(context.Context) (ocrtypes.ConfigDigestPrefix, error) { + return ocrtypes.ConfigDigestPrefixKeystoneOCR3Capability, nil +} + +// testKeys are a test oracle's keys, derived from its index, under the peer embedded instances derive. +type testKeys struct { + peerID string + offchain ed25519.PrivateKey + offchainPublic ocrtypes.OffchainPublicKey + configSecret [32]byte + configPublic ocrtypes.ConfigEncryptionPublicKey + onchain ed25519.PrivateKey +} + +func testKeysOf(t *testing.T, i int) *testKeys { + t.Helper() + peerID, err := EmbeddedPeerID(i) + require.NoError(t, err) + + offchainSeed := seed("offchain", i) + onchainSeed := seed("onchain", i) + k := &testKeys{ + peerID: peerID, + offchain: ed25519.NewKeyFromSeed(offchainSeed[:]), + configSecret: seed("config", i), + onchain: ed25519.NewKeyFromSeed(onchainSeed[:]), + } + configPublic, err := curve25519.X25519(k.configSecret[:], curve25519.Basepoint) + require.NoError(t, err) + copy(k.configPublic[:], configPublic) + copy(k.offchainPublic[:], k.offchain.Public().(ed25519.PublicKey)) + return k +} + +func (k *testKeys) transmitAccount() ocrtypes.Account { + return ocrtypes.Account(hex.EncodeToString(k.PublicKey())) +} + +func (k *testKeys) OffchainSign(msg []byte) ([]byte, error) { + return ed25519.Sign(k.offchain, msg), nil +} + +func (k *testKeys) ConfigDiffieHellman(point [32]byte) ([32]byte, error) { + var shared [32]byte + secret, err := curve25519.X25519(k.configSecret[:], point[:]) + if err != nil { + return shared, err + } + + copy(shared[:], secret) + return shared, nil +} + +func (k *testKeys) OffchainPublicKey() ocrtypes.OffchainPublicKey { return k.offchainPublic } + +func (k *testKeys) ConfigEncryptionPublicKey() ocrtypes.ConfigEncryptionPublicKey { + return k.configPublic +} + +func (k *testKeys) PublicKey() ocrtypes.OnchainPublicKey { + return ocrtypes.OnchainPublicKey(k.onchain.Public().(ed25519.PublicKey)) +} + +func (k *testKeys) Sign(digest ocrtypes.ConfigDigest, seqNr uint64, report ocr3types.ReportWithInfo[string]) ([]byte, error) { + return ed25519.Sign(k.onchain, reportHash(digest, seqNr, report.Report)), nil +} + +func (k *testKeys) Verify(key ocrtypes.OnchainPublicKey, digest ocrtypes.ConfigDigest, seqNr uint64, + report ocr3types.ReportWithInfo[string], signature []byte) bool { + return len(key) == ed25519.PublicKeySize && ed25519.Verify(ed25519.PublicKey(key), reportHash(digest, seqNr, report.Report), signature) +} + +func (k *testKeys) MaxSignatureLength() int { return ed25519.SignatureSize } + +func reportHash(digest ocrtypes.ConfigDigest, seqNr uint64, report []byte) []byte { + h := sha256.New() + h.Write(digest[:]) + _ = binary.Write(h, binary.BigEndian, seqNr) + h.Write(report) + return h.Sum(nil) +} + +type transmission struct { + id int + report []byte + signatures int +} + +type recordingTransmitter struct { + id int + account ocrtypes.Account + transmitted chan<- transmission +} + +func (r *recordingTransmitter) Transmit(_ context.Context, _ ocrtypes.ConfigDigest, _ uint64, + report ocr3types.ReportWithInfo[string], sigs []ocrtypes.AttributedOnchainSignature) error { + select { + case r.transmitted <- transmission{id: r.id, report: report.Report, signatures: len(sigs)}: + default: + } + + return nil +} + +func (r *recordingTransmitter) FromAccount(context.Context) (ocrtypes.Account, error) { + return r.account, nil +} + +// echoPluginFactory makes a plugin that reports the same thing every round. +type echoPluginFactory struct{} + +func (echoPluginFactory) NewReportingPlugin(context.Context, ocr3types.ReportingPluginConfig) (ocr3types.ReportingPlugin[string], ocr3types.ReportingPluginInfo, error) { + return echoPlugin{}, ocr3types.ReportingPluginInfo{ + Name: "echo", + Limits: ocr3types.ReportingPluginLimits{ + MaxQueryLength: 10, + MaxObservationLength: 10, + MaxOutcomeLength: 10, + MaxReportLength: 10, + MaxReportCount: 1, + }, + }, nil +} + +type echoPlugin struct{} + +func (echoPlugin) Query(context.Context, ocr3types.OutcomeContext) (ocrtypes.Query, error) { + return nil, nil +} + +func (echoPlugin) Observation(context.Context, ocr3types.OutcomeContext, ocrtypes.Query) (ocrtypes.Observation, error) { + return ocrtypes.Observation("obs"), nil +} + +func (echoPlugin) ValidateObservation(context.Context, ocr3types.OutcomeContext, ocrtypes.Query, ocrtypes.AttributedObservation) error { + return nil +} + +func (echoPlugin) ObservationQuorum(_ context.Context, _ ocr3types.OutcomeContext, _ ocrtypes.Query, aos []ocrtypes.AttributedObservation) (bool, error) { + return len(aos) >= 2, nil +} + +func (echoPlugin) Outcome(context.Context, ocr3types.OutcomeContext, ocrtypes.Query, []ocrtypes.AttributedObservation) (ocr3types.Outcome, error) { + return ocr3types.Outcome("outcome"), nil +} + +func (echoPlugin) Reports(context.Context, uint64, ocr3types.Outcome) ([]ocr3types.ReportPlus[string], error) { + return []ocr3types.ReportPlus[string]{{ReportWithInfo: ocr3types.ReportWithInfo[string]{Report: []byte("report"), Info: "evm"}}}, nil +} + +func (echoPlugin) ShouldAcceptAttestedReport(context.Context, uint64, ocr3types.ReportWithInfo[string]) (bool, error) { + return true, nil +} + +func (echoPlugin) ShouldTransmitAcceptedReport(context.Context, uint64, ocr3types.ReportWithInfo[string]) (bool, error) { + return true, nil +} + +func (echoPlugin) Close() error { return nil } diff --git a/libs/capability/ocr/inproc.go b/libs/capability/ocr/inproc.go new file mode 100644 index 000000000..9ab2411f5 --- /dev/null +++ b/libs/capability/ocr/inproc.go @@ -0,0 +1,148 @@ +package ocr + +import ( + "fmt" + "math" + "slices" + "sync" + + "github.com/smartcontractkit/libocr/commontypes" + ocr2types "github.com/smartcontractkit/libocr/offchainreporting2plus/types" +) + +type network struct { + mu sync.Mutex + ocr2 map[endpointKey]*ocr2Endpoint +} + +// embedNetwork is the process's in-process network. It is package-level for the same reason +// prometheus.DefaultRegisterer is: there is exactly one process, so there is exactly one network +// inside it, and every instance resolving its factories has to find the same one. +var embedNetwork = newNetwork() + +func newNetwork() *network { + return &network{ocr2: map[endpointKey]*ocr2Endpoint{}} +} + +// endpointKey identifies one peer's endpoint for one OCR instance. The digest is part of the key +// because a peer runs one endpoint per config digest, as it does over rage networking. +type endpointKey struct { + digest ocr2types.ConfigDigest + peerID string +} + +// senderIndex is the oracle ID the receiver knows sender by. The two ends of a link index oracles +// by their own copy of the OCR config's peer IDs, so a message carries the sender's position in +// the receiver's list, not in the sender's. +func senderIndex(receiverPeerIDs []string, senderPeerID string) (commontypes.OracleID, bool) { + i := slices.Index(receiverPeerIDs, senderPeerID) + // An oracle ID is a uint8, so an oracle beyond the 256th cannot be named in a message at all - + // there is no such DON, and truncating the index would attribute the message to another oracle. + if i < 0 || i > math.MaxUint8 { + return 0, false + } + + return commontypes.OracleID(i), true +} + +// defaultBufferSize is used when neither the caller nor the config asks for a size. +const defaultBufferSize = 100 + +type ocr2Factory struct { + net *network + peerID string + bufferSize int +} + +var _ ocr2types.BinaryNetworkEndpointFactory = ocr2Factory{} + +func (f ocr2Factory) PeerID() string { return f.peerID } + +func (f ocr2Factory) NewEndpoint( + digest ocr2types.ConfigDigest, + peerIDs []string, + _ []commontypes.BootstrapperLocator, + _ int, + _ ocr2types.BinaryNetworkEndpointLimits, +) (commontypes.BinaryNetworkEndpoint, error) { + if !slices.Contains(peerIDs, f.peerID) { + return nil, fmt.Errorf("peer %s is not one of the oracles of config digest %s", f.peerID, digest) + } + + e := &ocr2Endpoint{ + net: f.net, + key: endpointKey{digest: digest, peerID: f.peerID}, + peerIDs: slices.Clone(peerIDs), + in: make(chan commontypes.BinaryMessageWithSender, f.bufferSize), + closed: make(chan struct{}), + } + + f.net.mu.Lock() + defer f.net.mu.Unlock() + if _, exists := f.net.ocr2[e.key]; exists { + return nil, fmt.Errorf("peer %s already has an OCR2 endpoint for config digest %s", f.peerID, digest) + } + + f.net.ocr2[e.key] = e + return e, nil +} + +type ocr2Endpoint struct { + net *network + key endpointKey + peerIDs []string + in chan commontypes.BinaryMessageWithSender + + closeOnce sync.Once + closed chan struct{} +} + +var _ commontypes.BinaryNetworkEndpoint = (*ocr2Endpoint)(nil) + +func (e *ocr2Endpoint) Start() error { return nil } + +func (e *ocr2Endpoint) SendTo(payload []byte, to commontypes.OracleID) { + if int(to) >= len(e.peerIDs) { + return + } + + e.deliver(payload, e.peerIDs[to]) +} +func (e *ocr2Endpoint) Broadcast(payload []byte) { + for _, peerID := range e.peerIDs { + e.deliver(payload, peerID) + } +} + +func (e *ocr2Endpoint) deliver(payload []byte, peerID string) { + e.net.mu.Lock() + peer := e.net.ocr2[endpointKey{digest: e.key.digest, peerID: peerID}] + e.net.mu.Unlock() + if peer == nil { + return + } + + sender, ok := senderIndex(peer.peerIDs, e.key.peerID) + if !ok { + return + } + + msg := commontypes.BinaryMessageWithSender{Msg: slices.Clone(payload), Sender: sender} + select { + case <-peer.closed: + case peer.in <- msg: + default: + } +} + +func (e *ocr2Endpoint) Receive() <-chan commontypes.BinaryMessageWithSender { return e.in } + +func (e *ocr2Endpoint) Close() error { + e.closeOnce.Do(func() { + close(e.closed) + e.net.mu.Lock() + delete(e.net.ocr2, e.key) + e.net.mu.Unlock() + }) + return nil +} diff --git a/libs/capability/ocr/memorydb.go b/libs/capability/ocr/memorydb.go new file mode 100644 index 000000000..fe2a81563 --- /dev/null +++ b/libs/capability/ocr/memorydb.go @@ -0,0 +1,169 @@ +package ocr + +import ( + "context" + "encoding/json" + "fmt" + "sync" + "time" + + "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3types" + ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types" + + "github.com/smartcontractkit/chainlink-common/pkg/logger" +) + +// MemoryDB is an OCR database that holds an oracle's state in memory, for oracles whose state need not outlive their +// process: one that restarts rejoins from the current config, and loses only its in-flight rounds. +type MemoryDB struct { + // name identifies the oracle in logs and errors. + name string + lggr logger.SugaredLogger + config *ocrtypes.ContractConfig + states map[ocrtypes.ConfigDigest]*ocrtypes.PersistentState + pendingTransmissions map[ocrtypes.ReportTimestamp]ocrtypes.PendingTransmission + protocolStates map[ocrtypes.ConfigDigest]map[string][]byte + + mu sync.Mutex +} + +var ( + _ ocrtypes.Database = &MemoryDB{} + _ ocr3types.Database = &MemoryDB{} +) + +func NewMemoryDB(name string, lggr logger.Logger) *MemoryDB { + return &MemoryDB{ + name: name, + lggr: logger.Sugared(lggr).Named("MemoryDB"), + states: make(map[ocrtypes.ConfigDigest]*ocrtypes.PersistentState), + pendingTransmissions: make(map[ocrtypes.ReportTimestamp]ocrtypes.PendingTransmission), + protocolStates: make(map[ocrtypes.ConfigDigest]map[string][]byte), + } +} + +func (db *MemoryDB) ReadState(ctx context.Context, cd ocrtypes.ConfigDigest) (ps *ocrtypes.PersistentState, err error) { + db.mu.Lock() + defer db.mu.Unlock() + + ps, ok := db.states[cd] + if !ok { + return nil, fmt.Errorf("state not found for oracle %s, config digest %s", db.name, cd) + } + + return ps, nil +} + +func (db *MemoryDB) WriteState(ctx context.Context, cd ocrtypes.ConfigDigest, state ocrtypes.PersistentState) error { + db.mu.Lock() + defer db.mu.Unlock() + + db.states[cd] = &state + return nil +} + +func (db *MemoryDB) ReadConfig(ctx context.Context) (c *ocrtypes.ContractConfig, err error) { + db.mu.Lock() + defer db.mu.Unlock() + + if db.config == nil { + // Returning nil, nil because this is a cache miss + return nil, nil + } + return db.config, nil +} + +func (db *MemoryDB) WriteConfig(ctx context.Context, c ocrtypes.ContractConfig) error { + db.mu.Lock() + defer db.mu.Unlock() + + db.config = &c + + cBytes, err := json.Marshal(c) + if err != nil { + return fmt.Errorf("MemoryDB: WriteConfig failed to marshal config: %w", err) + } + + db.lggr.Debugw("MemoryDB: WriteConfig", "ocrtypes.ContractConfig", string(cBytes)) + + return nil +} + +func (db *MemoryDB) StorePendingTransmission(ctx context.Context, t ocrtypes.ReportTimestamp, tx ocrtypes.PendingTransmission) error { + db.mu.Lock() + defer db.mu.Unlock() + + db.pendingTransmissions[t] = tx + return nil +} + +func (db *MemoryDB) PendingTransmissionsWithConfigDigest(ctx context.Context, cd ocrtypes.ConfigDigest) (map[ocrtypes.ReportTimestamp]ocrtypes.PendingTransmission, error) { + db.mu.Lock() + defer db.mu.Unlock() + + m := make(map[ocrtypes.ReportTimestamp]ocrtypes.PendingTransmission) + for k, v := range db.pendingTransmissions { + if k.ConfigDigest == cd { + m[k] = v + } + } + + return m, nil +} + +func (db *MemoryDB) DeletePendingTransmission(ctx context.Context, t ocrtypes.ReportTimestamp) error { + db.mu.Lock() + defer db.mu.Unlock() + + delete(db.pendingTransmissions, t) + return nil +} + +func (db *MemoryDB) DeletePendingTransmissionsOlderThan(_ context.Context, t time.Time) error { + db.mu.Lock() + defer db.mu.Unlock() + + for k, v := range db.pendingTransmissions { + if v.Time.Before(t) { + delete(db.pendingTransmissions, k) + } + } + + return nil +} + +func (db *MemoryDB) ReadProtocolState( + _ context.Context, + configDigest ocrtypes.ConfigDigest, + key string, +) ([]byte, error) { + db.mu.Lock() + defer db.mu.Unlock() + + value, ok := db.protocolStates[configDigest][key] + if !ok { + // Previously implementation returned nil if the state is not found + return nil, nil + } + return value, nil +} + +func (db *MemoryDB) WriteProtocolState( + _ context.Context, + configDigest ocrtypes.ConfigDigest, + key string, + value []byte, +) error { + db.mu.Lock() + defer db.mu.Unlock() + + if value == nil { + delete(db.protocolStates[configDigest], key) + } else { + if db.protocolStates[configDigest] == nil { + db.protocolStates[configDigest] = make(map[string][]byte) + } + db.protocolStates[configDigest][key] = value + } + return nil +} diff --git a/libs/capability/ocr/memorydb_test.go b/libs/capability/ocr/memorydb_test.go new file mode 100644 index 000000000..4fbc88008 --- /dev/null +++ b/libs/capability/ocr/memorydb_test.go @@ -0,0 +1,78 @@ +package ocr + +import ( + "maps" + "slices" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types" + + "github.com/smartcontractkit/chainlink-common/pkg/logger" +) + +func TestMemoryDB(t *testing.T) { + db := NewMemoryDB("test", logger.Test(t)) + digest := ocrtypes.ConfigDigest{1} + + _, err := db.ReadState(t.Context(), digest) + require.ErrorContains(t, err, "state not found for oracle test") + + require.NoError(t, db.WriteState(t.Context(), digest, ocrtypes.PersistentState{Epoch: 3})) + state, err := db.ReadState(t.Context(), digest) + require.NoError(t, err) + assert.Equal(t, uint32(3), state.Epoch) + + config, err := db.ReadConfig(t.Context()) + require.NoError(t, err) + assert.Nil(t, config) + + require.NoError(t, db.WriteConfig(t.Context(), ocrtypes.ContractConfig{ConfigCount: 2})) + config, err = db.ReadConfig(t.Context()) + require.NoError(t, err) + assert.Equal(t, uint64(2), config.ConfigCount) + + value, err := db.ReadProtocolState(t.Context(), digest, "key") + require.NoError(t, err) + assert.Nil(t, value) + + require.NoError(t, db.WriteProtocolState(t.Context(), digest, "key", []byte("value"))) + value, err = db.ReadProtocolState(t.Context(), digest, "key") + require.NoError(t, err) + assert.Equal(t, []byte("value"), value) + + require.NoError(t, db.WriteProtocolState(t.Context(), digest, "key", nil)) + value, err = db.ReadProtocolState(t.Context(), digest, "key") + require.NoError(t, err) + assert.Nil(t, value) +} + +func TestMemoryDB_PendingTransmissions(t *testing.T) { + db := NewMemoryDB("test", logger.Test(t)) + digest := ocrtypes.ConfigDigest{1} + old := ocrtypes.ReportTimestamp{ConfigDigest: digest, Epoch: 1} + recent := ocrtypes.ReportTimestamp{ConfigDigest: digest, Epoch: 2} + other := ocrtypes.ReportTimestamp{ConfigDigest: ocrtypes.ConfigDigest{2}, Epoch: 1} + now := time.Now() + + require.NoError(t, db.StorePendingTransmission(t.Context(), old, ocrtypes.PendingTransmission{Time: now.Add(-time.Hour)})) + require.NoError(t, db.StorePendingTransmission(t.Context(), recent, ocrtypes.PendingTransmission{Time: now})) + require.NoError(t, db.StorePendingTransmission(t.Context(), other, ocrtypes.PendingTransmission{Time: now})) + + pending, err := db.PendingTransmissionsWithConfigDigest(t.Context(), digest) + require.NoError(t, err) + assert.Len(t, pending, 2) + + require.NoError(t, db.DeletePendingTransmissionsOlderThan(t.Context(), now.Add(-time.Minute))) + pending, err = db.PendingTransmissionsWithConfigDigest(t.Context(), digest) + require.NoError(t, err) + assert.Equal(t, []ocrtypes.ReportTimestamp{recent}, slices.Collect(maps.Keys(pending))) + + require.NoError(t, db.DeletePendingTransmission(t.Context(), recent)) + pending, err = db.PendingTransmissionsWithConfigDigest(t.Context(), digest) + require.NoError(t, err) + assert.Empty(t, pending) +} diff --git a/libs/capability/ocr/network_test.go b/libs/capability/ocr/network_test.go new file mode 100644 index 000000000..7af2af235 --- /dev/null +++ b/libs/capability/ocr/network_test.go @@ -0,0 +1,91 @@ +package ocr + +import ( + "context" + "fmt" + "net" + "testing" + "time" + + "github.com/prometheus/client_golang/prometheus" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + "google.golang.org/grpc/test/bufconn" + + libocr "github.com/smartcontractkit/libocr/offchainreporting2plus" + "github.com/smartcontractkit/libocr/offchainreporting2plus/ocr3shims" + ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types" + + "github.com/smartcontractkit/chainlink-common/pkg/logger" + + "github.com/smartcontractkit/capabilities/libs/capability/ocr/remote" +) + +// TestRemoteOraclesReachConsensus serves each instance's in-process networking the way a node serves its peer, so the +// oracles run over the network client. +func TestRemoteOraclesReachConsensus(t *testing.T) { + t.Parallel() + inproc := newNetwork() + testOraclesReachConsensus(t, func(id int) ocrtypes.BinaryNetworkEndpointFactory { + network, err := embeddedNetwork(inproc, id) + require.NoError(t, err) + + lis := bufconn.Listen(1024 * 1024) + s := grpc.NewServer(grpc.MaxRecvMsgSize(remote.MaxMessageSize)) + require.NoError(t, remote.RegisterServer(s, logger.Test(t), func(context.Context) (ocrtypes.BinaryNetworkEndpointFactory, error) { + return network.BinaryNetworkEndpointFactory, nil + })) + go func() { _ = s.Serve(lis) }() + t.Cleanup(s.Stop) + + conn, err := grpc.NewClient("passthrough:///bufnet", + grpc.WithTransportCredentials(insecure.NewCredentials()), + grpc.WithContextDialer(func(ctx context.Context, _ string) (net.Conn, error) { return lis.DialContext(ctx) }), + ) + require.NoError(t, err) + t.Cleanup(func() { _ = conn.Close() }) + return remote.NewClient(logger.Test(t), conn, network.BinaryNetworkEndpointFactory.PeerID()) + }) +} + +// testOraclesReachConsensus runs a DON of testInstances oracles, each over the networking newFactory returns, and +// checks every one transmits an attested report. +func testOraclesReachConsensus(t *testing.T, newFactory func(id int) ocrtypes.BinaryNetworkEndpointFactory) { + config := testConfig(t) + transmitted := make(chan transmission, 100) + for id := range testInstances { + lggr := logger.Test(t) + k := testKeysOf(t, id) + oracle, err := libocr.NewOracle(libocr.OCR3OracleArgs2[string]{ + BinaryNetworkEndpointFactory: newFactory(id), + ContractConfigTracker: staticConfig{config: config}, + OffchainConfigDigester: staticConfig{config: config}, + OffchainKeyring: k, + OnchainKeyring: ocr3shims.OnchainKeyringAsOnchainKeyring2[string](k), + LocalConfig: testLocalConfig(), + ReportingPluginFactory: echoPluginFactory{}, + ContractTransmitter: &recordingTransmitter{id: id, account: k.transmitAccount(), transmitted: transmitted}, + Database: NewMemoryDB(fmt.Sprint(id), lggr), + Logger: logger.NewOCRWrapper(lggr, true, func(string) {}), + MetricsRegisterer: prometheus.NewRegistry(), + }) + require.NoError(t, err) + require.NoError(t, oracle.Start()) + t.Cleanup(func() { assert.NoError(t, oracle.Close()) }) + } + + seen := map[int]bool{} + timeout := time.After(30 * time.Second) + for len(seen) < testInstances { + select { + case tr := <-transmitted: + assert.Equal(t, []byte("report"), tr.report) + assert.GreaterOrEqual(t, tr.signatures, 2, "a report is attested by more than f oracles") + seen[tr.id] = true + case <-timeout: + require.FailNow(t, "timed out waiting for every instance to transmit", "transmitted: %v", seen) + } + } +} diff --git a/libs/capability/ocr/remote/client.go b/libs/capability/ocr/remote/client.go new file mode 100644 index 000000000..3a8627017 --- /dev/null +++ b/libs/capability/ocr/remote/client.go @@ -0,0 +1,204 @@ +package remote + +import ( + "context" + "errors" + "fmt" + "sync" + + ragetypes "github.com/smartcontractkit/libocr/ragep2p/types" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/smartcontractkit/libocr/commontypes" + ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types" + + "github.com/smartcontractkit/chainlink-common/pkg/logger" + + "github.com/smartcontractkit/capabilities/libs/capability/ocr/remote/internal/pb" +) + +// MaxMessageSize is the largest gRPC message between a node and a process: an OCR message as large as libocr allows, +// with room for its framing. gRPC's 4 MiB default would break an endpoint's stream on a large message, such as a +// leader's proposal carrying many observations; the endpoint on the node still enforces the oracle's own limits. The +// server [RegisterServer] serves on must receive messages this large. +const MaxMessageSize = ragetypes.MaxMessageLength + 1024 + +// NewClient is the BinaryNetworkEndpointFactory served by RegisterServer on conn, for the node whose peer +// is peerID. +func NewClient(lggr logger.Logger, conn grpc.ClientConnInterface, peerID string) ocrtypes.BinaryNetworkEndpointFactory { + return &endpointFactory{lggr: logger.Named(lggr, "OCRNetworkClient"), client: pb.NewNetworkClient(conn), peerID: peerID} +} + +// outboundBufferSize is how many messages an endpoint holds for the host before dropping the oldest. +const outboundBufferSize = 1024 + +var _ ocrtypes.BinaryNetworkEndpointFactory = (*endpointFactory)(nil) + +type endpointFactory struct { + lggr logger.Logger + client pb.NetworkClient + peerID string +} + +func (f *endpointFactory) PeerID() string { return f.peerID } + +func (f *endpointFactory) NewEndpoint(digest ocrtypes.ConfigDigest, peerIDs []string, + bootstrappers []commontypes.BootstrapperLocator, failureThreshold int, + limits ocrtypes.BinaryNetworkEndpointLimits) (commontypes.BinaryNetworkEndpoint, error) { + ctx, cancel := context.WithCancel(context.Background()) + stream, err := f.client.Connect(ctx, grpc.MaxCallRecvMsgSize(MaxMessageSize)) + if err != nil { + cancel() + return nil, fmt.Errorf("failed to connect endpoint: %w", err) + } + + err = stream.Send(&pb.EndpointRequest{Request: &pb.EndpointRequest_Open{Open: &pb.OpenRequest{ + ConfigDigest: digest[:], + PeerIds: peerIDs, + Bootstrappers: bootstrappersToPB(bootstrappers), + F: int64(failureThreshold), + Limits: limitsToPB(limits), + }}}) + if err != nil { + cancel() + return nil, fmt.Errorf("failed to open endpoint: %w", err) + } + + reply, err := stream.Recv() + if err != nil { + cancel() + return nil, fmt.Errorf("failed to open endpoint: %w", err) + } + + if reply.GetOpened() == nil { + cancel() + return nil, fmt.Errorf("expected the endpoint to be opened, got %T", reply.Reply) + } + + return &endpoint{ + lggr: logger.With(f.lggr, "configDigest", digest), + done: ctx.Done(), + cancel: cancel, + stream: stream, + outbound: make(chan *pb.EndpointRequest, outboundBufferSize), + received: make(chan commontypes.BinaryMessageWithSender), + }, nil +} + +var _ commontypes.BinaryNetworkEndpoint = (*endpoint)(nil) + +// endpoint is a BinaryNetworkEndpoint on the host, for the life of one stream. +type endpoint struct { + lggr logger.Logger + done <-chan struct{} + cancel context.CancelFunc + stream pb.Network_ConnectClient + outbound chan *pb.EndpointRequest + received chan commontypes.BinaryMessageWithSender + + startOnce sync.Once + closeOnce sync.Once + wg sync.WaitGroup +} + +func (e *endpoint) Start() error { + e.startOnce.Do(func() { + e.wg.Go(e.sendLoop) + e.wg.Go(e.receiveLoop) + }) + + return nil +} + +func (e *endpoint) Close() error { + e.closeOnce.Do(func() { + e.cancel() + e.wg.Wait() + }) + + return nil +} + +func (e *endpoint) SendTo(payload []byte, to commontypes.OracleID) { + e.enqueue(&pb.EndpointRequest{Request: &pb.EndpointRequest_SendTo{SendTo: &pb.SendToRequest{ + Payload: payload, + To: uint32(to), + }}}) +} + +func (e *endpoint) Broadcast(payload []byte) { + e.enqueue(&pb.EndpointRequest{Request: &pb.EndpointRequest_Broadcast{Broadcast: &pb.BroadcastRequest{Payload: payload}}}) +} + +func (e *endpoint) Receive() <-chan commontypes.BinaryMessageWithSender { return e.received } + +func (e *endpoint) enqueue(req *pb.EndpointRequest) { + for { + select { + case e.outbound <- req: + return + default: + } + + select { + case <-e.outbound: + e.lggr.Warn("Dropped the oldest outbound OCR message, the buffer is full") + default: + } + } +} + +func (e *endpoint) sendLoop() { + for { + select { + case <-e.done: + return + case req := <-e.outbound: + if err := e.stream.Send(req); err != nil { + e.logStreamErr("Failed to send OCR message", err) + return + } + } + } +} + +func (e *endpoint) receiveLoop() { + for { + reply, err := e.stream.Recv() + if err != nil { + e.logStreamErr("Failed to receive OCR message", err) + return + } + + msg := reply.GetMessage() + if msg == nil { + e.lggr.Warnw("Ignoring unexpected reply", "reply", fmt.Sprintf("%T", reply.Reply)) + continue + } + + select { + case <-e.done: + return + case e.received <- commontypes.BinaryMessageWithSender{Msg: msg.Payload, Sender: commontypes.OracleID(msg.Sender)}: //nolint:gosec // oracle IDs fit in a uint8 + } + } +} + +func (e *endpoint) logStreamErr(msg string, err error) { + if e.closed() || errors.Is(err, context.Canceled) || status.Code(err) == codes.Canceled { + return + } + + e.lggr.Errorw(msg+", the endpoint is closed", "err", err) +} + +func (e *endpoint) closed() bool { + select { + case <-e.done: + return true + default: + return false + } +} diff --git a/libs/capability/ocr/remote/internal/pb/generate.go b/libs/capability/ocr/remote/internal/pb/generate.go new file mode 100644 index 000000000..0d5aefe08 --- /dev/null +++ b/libs/capability/ocr/remote/internal/pb/generate.go @@ -0,0 +1,2 @@ +//go:generate protoc --go_out=. --go_opt=paths=source_relative --go-grpc_out=. --go-grpc_opt=paths=source_relative network.proto +package pb diff --git a/libs/capability/ocr/remote/internal/pb/network.pb.go b/libs/capability/ocr/remote/internal/pb/network.pb.go new file mode 100644 index 000000000..24ac96a93 --- /dev/null +++ b/libs/capability/ocr/remote/internal/pb/network.pb.go @@ -0,0 +1,705 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.36.11 +// protoc v5.29.3 +// source: network.proto + +package pb + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" + unsafe "unsafe" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type BootstrapperLocator struct { + state protoimpl.MessageState `protogen:"open.v1"` + PeerId string `protobuf:"bytes,1,opt,name=peer_id,json=peerId,proto3" json:"peer_id,omitempty"` + Addrs []string `protobuf:"bytes,2,rep,name=addrs,proto3" json:"addrs,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *BootstrapperLocator) Reset() { + *x = BootstrapperLocator{} + mi := &file_network_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *BootstrapperLocator) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BootstrapperLocator) ProtoMessage() {} + +func (x *BootstrapperLocator) ProtoReflect() protoreflect.Message { + mi := &file_network_proto_msgTypes[0] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BootstrapperLocator.ProtoReflect.Descriptor instead. +func (*BootstrapperLocator) Descriptor() ([]byte, []int) { + return file_network_proto_rawDescGZIP(), []int{0} +} + +func (x *BootstrapperLocator) GetPeerId() string { + if x != nil { + return x.PeerId + } + return "" +} + +func (x *BootstrapperLocator) GetAddrs() []string { + if x != nil { + return x.Addrs + } + return nil +} + +type EndpointRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + // Types that are valid to be assigned to Request: + // + // *EndpointRequest_Open + // *EndpointRequest_SendTo + // *EndpointRequest_Broadcast + Request isEndpointRequest_Request `protobuf_oneof:"request"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *EndpointRequest) Reset() { + *x = EndpointRequest{} + mi := &file_network_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *EndpointRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EndpointRequest) ProtoMessage() {} + +func (x *EndpointRequest) ProtoReflect() protoreflect.Message { + mi := &file_network_proto_msgTypes[1] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use EndpointRequest.ProtoReflect.Descriptor instead. +func (*EndpointRequest) Descriptor() ([]byte, []int) { + return file_network_proto_rawDescGZIP(), []int{1} +} + +func (x *EndpointRequest) GetRequest() isEndpointRequest_Request { + if x != nil { + return x.Request + } + return nil +} + +func (x *EndpointRequest) GetOpen() *OpenRequest { + if x != nil { + if x, ok := x.Request.(*EndpointRequest_Open); ok { + return x.Open + } + } + return nil +} + +func (x *EndpointRequest) GetSendTo() *SendToRequest { + if x != nil { + if x, ok := x.Request.(*EndpointRequest_SendTo); ok { + return x.SendTo + } + } + return nil +} + +func (x *EndpointRequest) GetBroadcast() *BroadcastRequest { + if x != nil { + if x, ok := x.Request.(*EndpointRequest_Broadcast); ok { + return x.Broadcast + } + } + return nil +} + +type isEndpointRequest_Request interface { + isEndpointRequest_Request() +} + +type EndpointRequest_Open struct { + Open *OpenRequest `protobuf:"bytes,1,opt,name=open,proto3,oneof"` +} + +type EndpointRequest_SendTo struct { + SendTo *SendToRequest `protobuf:"bytes,2,opt,name=send_to,json=sendTo,proto3,oneof"` +} + +type EndpointRequest_Broadcast struct { + Broadcast *BroadcastRequest `protobuf:"bytes,3,opt,name=broadcast,proto3,oneof"` +} + +func (*EndpointRequest_Open) isEndpointRequest_Request() {} + +func (*EndpointRequest_SendTo) isEndpointRequest_Request() {} + +func (*EndpointRequest_Broadcast) isEndpointRequest_Request() {} + +type OpenRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + ConfigDigest []byte `protobuf:"bytes,1,opt,name=config_digest,json=configDigest,proto3" json:"config_digest,omitempty"` + PeerIds []string `protobuf:"bytes,2,rep,name=peer_ids,json=peerIds,proto3" json:"peer_ids,omitempty"` + Bootstrappers []*BootstrapperLocator `protobuf:"bytes,3,rep,name=bootstrappers,proto3" json:"bootstrappers,omitempty"` + F int64 `protobuf:"varint,4,opt,name=f,proto3" json:"f,omitempty"` + Limits *EndpointLimits `protobuf:"bytes,5,opt,name=limits,proto3" json:"limits,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *OpenRequest) Reset() { + *x = OpenRequest{} + mi := &file_network_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *OpenRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OpenRequest) ProtoMessage() {} + +func (x *OpenRequest) ProtoReflect() protoreflect.Message { + mi := &file_network_proto_msgTypes[2] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use OpenRequest.ProtoReflect.Descriptor instead. +func (*OpenRequest) Descriptor() ([]byte, []int) { + return file_network_proto_rawDescGZIP(), []int{2} +} + +func (x *OpenRequest) GetConfigDigest() []byte { + if x != nil { + return x.ConfigDigest + } + return nil +} + +func (x *OpenRequest) GetPeerIds() []string { + if x != nil { + return x.PeerIds + } + return nil +} + +func (x *OpenRequest) GetBootstrappers() []*BootstrapperLocator { + if x != nil { + return x.Bootstrappers + } + return nil +} + +func (x *OpenRequest) GetF() int64 { + if x != nil { + return x.F + } + return 0 +} + +func (x *OpenRequest) GetLimits() *EndpointLimits { + if x != nil { + return x.Limits + } + return nil +} + +type EndpointLimits struct { + state protoimpl.MessageState `protogen:"open.v1"` + MaxMessageLength int64 `protobuf:"varint,1,opt,name=max_message_length,json=maxMessageLength,proto3" json:"max_message_length,omitempty"` + MessagesRatePerOracle float64 `protobuf:"fixed64,2,opt,name=messages_rate_per_oracle,json=messagesRatePerOracle,proto3" json:"messages_rate_per_oracle,omitempty"` + MessagesCapacityPerOracle int64 `protobuf:"varint,3,opt,name=messages_capacity_per_oracle,json=messagesCapacityPerOracle,proto3" json:"messages_capacity_per_oracle,omitempty"` + BytesRatePerOracle float64 `protobuf:"fixed64,4,opt,name=bytes_rate_per_oracle,json=bytesRatePerOracle,proto3" json:"bytes_rate_per_oracle,omitempty"` + BytesCapacityPerOracle int64 `protobuf:"varint,5,opt,name=bytes_capacity_per_oracle,json=bytesCapacityPerOracle,proto3" json:"bytes_capacity_per_oracle,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *EndpointLimits) Reset() { + *x = EndpointLimits{} + mi := &file_network_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *EndpointLimits) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EndpointLimits) ProtoMessage() {} + +func (x *EndpointLimits) ProtoReflect() protoreflect.Message { + mi := &file_network_proto_msgTypes[3] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use EndpointLimits.ProtoReflect.Descriptor instead. +func (*EndpointLimits) Descriptor() ([]byte, []int) { + return file_network_proto_rawDescGZIP(), []int{3} +} + +func (x *EndpointLimits) GetMaxMessageLength() int64 { + if x != nil { + return x.MaxMessageLength + } + return 0 +} + +func (x *EndpointLimits) GetMessagesRatePerOracle() float64 { + if x != nil { + return x.MessagesRatePerOracle + } + return 0 +} + +func (x *EndpointLimits) GetMessagesCapacityPerOracle() int64 { + if x != nil { + return x.MessagesCapacityPerOracle + } + return 0 +} + +func (x *EndpointLimits) GetBytesRatePerOracle() float64 { + if x != nil { + return x.BytesRatePerOracle + } + return 0 +} + +func (x *EndpointLimits) GetBytesCapacityPerOracle() int64 { + if x != nil { + return x.BytesCapacityPerOracle + } + return 0 +} + +type SendToRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Payload []byte `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"` + To uint32 `protobuf:"varint,2,opt,name=to,proto3" json:"to,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *SendToRequest) Reset() { + *x = SendToRequest{} + mi := &file_network_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *SendToRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*SendToRequest) ProtoMessage() {} + +func (x *SendToRequest) ProtoReflect() protoreflect.Message { + mi := &file_network_proto_msgTypes[4] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use SendToRequest.ProtoReflect.Descriptor instead. +func (*SendToRequest) Descriptor() ([]byte, []int) { + return file_network_proto_rawDescGZIP(), []int{4} +} + +func (x *SendToRequest) GetPayload() []byte { + if x != nil { + return x.Payload + } + return nil +} + +func (x *SendToRequest) GetTo() uint32 { + if x != nil { + return x.To + } + return 0 +} + +type BroadcastRequest struct { + state protoimpl.MessageState `protogen:"open.v1"` + Payload []byte `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *BroadcastRequest) Reset() { + *x = BroadcastRequest{} + mi := &file_network_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *BroadcastRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BroadcastRequest) ProtoMessage() {} + +func (x *BroadcastRequest) ProtoReflect() protoreflect.Message { + mi := &file_network_proto_msgTypes[5] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use BroadcastRequest.ProtoReflect.Descriptor instead. +func (*BroadcastRequest) Descriptor() ([]byte, []int) { + return file_network_proto_rawDescGZIP(), []int{5} +} + +func (x *BroadcastRequest) GetPayload() []byte { + if x != nil { + return x.Payload + } + return nil +} + +type EndpointReply struct { + state protoimpl.MessageState `protogen:"open.v1"` + // Types that are valid to be assigned to Reply: + // + // *EndpointReply_Opened + // *EndpointReply_Message + Reply isEndpointReply_Reply `protobuf_oneof:"reply"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *EndpointReply) Reset() { + *x = EndpointReply{} + mi := &file_network_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *EndpointReply) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*EndpointReply) ProtoMessage() {} + +func (x *EndpointReply) ProtoReflect() protoreflect.Message { + mi := &file_network_proto_msgTypes[6] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use EndpointReply.ProtoReflect.Descriptor instead. +func (*EndpointReply) Descriptor() ([]byte, []int) { + return file_network_proto_rawDescGZIP(), []int{6} +} + +func (x *EndpointReply) GetReply() isEndpointReply_Reply { + if x != nil { + return x.Reply + } + return nil +} + +func (x *EndpointReply) GetOpened() *Opened { + if x != nil { + if x, ok := x.Reply.(*EndpointReply_Opened); ok { + return x.Opened + } + } + return nil +} + +func (x *EndpointReply) GetMessage() *Message { + if x != nil { + if x, ok := x.Reply.(*EndpointReply_Message); ok { + return x.Message + } + } + return nil +} + +type isEndpointReply_Reply interface { + isEndpointReply_Reply() +} + +type EndpointReply_Opened struct { + Opened *Opened `protobuf:"bytes,1,opt,name=opened,proto3,oneof"` +} + +type EndpointReply_Message struct { + Message *Message `protobuf:"bytes,2,opt,name=message,proto3,oneof"` +} + +func (*EndpointReply_Opened) isEndpointReply_Reply() {} + +func (*EndpointReply_Message) isEndpointReply_Reply() {} + +type Opened struct { + state protoimpl.MessageState `protogen:"open.v1"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *Opened) Reset() { + *x = Opened{} + mi := &file_network_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Opened) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Opened) ProtoMessage() {} + +func (x *Opened) ProtoReflect() protoreflect.Message { + mi := &file_network_proto_msgTypes[7] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Opened.ProtoReflect.Descriptor instead. +func (*Opened) Descriptor() ([]byte, []int) { + return file_network_proto_rawDescGZIP(), []int{7} +} + +type Message struct { + state protoimpl.MessageState `protogen:"open.v1"` + Payload []byte `protobuf:"bytes,1,opt,name=payload,proto3" json:"payload,omitempty"` + Sender uint32 `protobuf:"varint,2,opt,name=sender,proto3" json:"sender,omitempty"` + unknownFields protoimpl.UnknownFields + sizeCache protoimpl.SizeCache +} + +func (x *Message) Reset() { + *x = Message{} + mi := &file_network_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) +} + +func (x *Message) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Message) ProtoMessage() {} + +func (x *Message) ProtoReflect() protoreflect.Message { + mi := &file_network_proto_msgTypes[8] + if x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use Message.ProtoReflect.Descriptor instead. +func (*Message) Descriptor() ([]byte, []int) { + return file_network_proto_rawDescGZIP(), []int{8} +} + +func (x *Message) GetPayload() []byte { + if x != nil { + return x.Payload + } + return nil +} + +func (x *Message) GetSender() uint32 { + if x != nil { + return x.Sender + } + return 0 +} + +var File_network_proto protoreflect.FileDescriptor + +const file_network_proto_rawDesc = "" + + "\n" + + "\rnetwork.proto\x12#capabilities.ocr.remote.internal.pb\"D\n" + + "\x13BootstrapperLocator\x12\x17\n" + + "\apeer_id\x18\x01 \x01(\tR\x06peerId\x12\x14\n" + + "\x05addrs\x18\x02 \x03(\tR\x05addrs\"\x8a\x02\n" + + "\x0fEndpointRequest\x12F\n" + + "\x04open\x18\x01 \x01(\v20.capabilities.ocr.remote.internal.pb.OpenRequestH\x00R\x04open\x12M\n" + + "\asend_to\x18\x02 \x01(\v22.capabilities.ocr.remote.internal.pb.SendToRequestH\x00R\x06sendTo\x12U\n" + + "\tbroadcast\x18\x03 \x01(\v25.capabilities.ocr.remote.internal.pb.BroadcastRequestH\x00R\tbroadcastB\t\n" + + "\arequest\"\x88\x02\n" + + "\vOpenRequest\x12#\n" + + "\rconfig_digest\x18\x01 \x01(\fR\fconfigDigest\x12\x19\n" + + "\bpeer_ids\x18\x02 \x03(\tR\apeerIds\x12^\n" + + "\rbootstrappers\x18\x03 \x03(\v28.capabilities.ocr.remote.internal.pb.BootstrapperLocatorR\rbootstrappers\x12\f\n" + + "\x01f\x18\x04 \x01(\x03R\x01f\x12K\n" + + "\x06limits\x18\x05 \x01(\v23.capabilities.ocr.remote.internal.pb.EndpointLimitsR\x06limits\"\xa6\x02\n" + + "\x0eEndpointLimits\x12,\n" + + "\x12max_message_length\x18\x01 \x01(\x03R\x10maxMessageLength\x127\n" + + "\x18messages_rate_per_oracle\x18\x02 \x01(\x01R\x15messagesRatePerOracle\x12?\n" + + "\x1cmessages_capacity_per_oracle\x18\x03 \x01(\x03R\x19messagesCapacityPerOracle\x121\n" + + "\x15bytes_rate_per_oracle\x18\x04 \x01(\x01R\x12bytesRatePerOracle\x129\n" + + "\x19bytes_capacity_per_oracle\x18\x05 \x01(\x03R\x16bytesCapacityPerOracle\"9\n" + + "\rSendToRequest\x12\x18\n" + + "\apayload\x18\x01 \x01(\fR\apayload\x12\x0e\n" + + "\x02to\x18\x02 \x01(\rR\x02to\",\n" + + "\x10BroadcastRequest\x12\x18\n" + + "\apayload\x18\x01 \x01(\fR\apayload\"\xa9\x01\n" + + "\rEndpointReply\x12E\n" + + "\x06opened\x18\x01 \x01(\v2+.capabilities.ocr.remote.internal.pb.OpenedH\x00R\x06opened\x12H\n" + + "\amessage\x18\x02 \x01(\v2,.capabilities.ocr.remote.internal.pb.MessageH\x00R\amessageB\a\n" + + "\x05reply\"\b\n" + + "\x06Opened\";\n" + + "\aMessage\x12\x18\n" + + "\apayload\x18\x01 \x01(\fR\apayload\x12\x16\n" + + "\x06sender\x18\x02 \x01(\rR\x06sender2\x82\x01\n" + + "\aNetwork\x12w\n" + + "\aConnect\x124.capabilities.ocr.remote.internal.pb.EndpointRequest\x1a2.capabilities.ocr.remote.internal.pb.EndpointReply(\x010\x01BQZOgithub.com/smartcontractkit/capabilities/libs/capability/ocr/remote/internal/pbb\x06proto3" + +var ( + file_network_proto_rawDescOnce sync.Once + file_network_proto_rawDescData []byte +) + +func file_network_proto_rawDescGZIP() []byte { + file_network_proto_rawDescOnce.Do(func() { + file_network_proto_rawDescData = protoimpl.X.CompressGZIP(unsafe.Slice(unsafe.StringData(file_network_proto_rawDesc), len(file_network_proto_rawDesc))) + }) + return file_network_proto_rawDescData +} + +var file_network_proto_msgTypes = make([]protoimpl.MessageInfo, 9) +var file_network_proto_goTypes = []any{ + (*BootstrapperLocator)(nil), // 0: capabilities.ocr.remote.internal.pb.BootstrapperLocator + (*EndpointRequest)(nil), // 1: capabilities.ocr.remote.internal.pb.EndpointRequest + (*OpenRequest)(nil), // 2: capabilities.ocr.remote.internal.pb.OpenRequest + (*EndpointLimits)(nil), // 3: capabilities.ocr.remote.internal.pb.EndpointLimits + (*SendToRequest)(nil), // 4: capabilities.ocr.remote.internal.pb.SendToRequest + (*BroadcastRequest)(nil), // 5: capabilities.ocr.remote.internal.pb.BroadcastRequest + (*EndpointReply)(nil), // 6: capabilities.ocr.remote.internal.pb.EndpointReply + (*Opened)(nil), // 7: capabilities.ocr.remote.internal.pb.Opened + (*Message)(nil), // 8: capabilities.ocr.remote.internal.pb.Message +} +var file_network_proto_depIdxs = []int32{ + 2, // 0: capabilities.ocr.remote.internal.pb.EndpointRequest.open:type_name -> capabilities.ocr.remote.internal.pb.OpenRequest + 4, // 1: capabilities.ocr.remote.internal.pb.EndpointRequest.send_to:type_name -> capabilities.ocr.remote.internal.pb.SendToRequest + 5, // 2: capabilities.ocr.remote.internal.pb.EndpointRequest.broadcast:type_name -> capabilities.ocr.remote.internal.pb.BroadcastRequest + 0, // 3: capabilities.ocr.remote.internal.pb.OpenRequest.bootstrappers:type_name -> capabilities.ocr.remote.internal.pb.BootstrapperLocator + 3, // 4: capabilities.ocr.remote.internal.pb.OpenRequest.limits:type_name -> capabilities.ocr.remote.internal.pb.EndpointLimits + 7, // 5: capabilities.ocr.remote.internal.pb.EndpointReply.opened:type_name -> capabilities.ocr.remote.internal.pb.Opened + 8, // 6: capabilities.ocr.remote.internal.pb.EndpointReply.message:type_name -> capabilities.ocr.remote.internal.pb.Message + 1, // 7: capabilities.ocr.remote.internal.pb.Network.Connect:input_type -> capabilities.ocr.remote.internal.pb.EndpointRequest + 6, // 8: capabilities.ocr.remote.internal.pb.Network.Connect:output_type -> capabilities.ocr.remote.internal.pb.EndpointReply + 8, // [8:9] is the sub-list for method output_type + 7, // [7:8] is the sub-list for method input_type + 7, // [7:7] is the sub-list for extension type_name + 7, // [7:7] is the sub-list for extension extendee + 0, // [0:7] is the sub-list for field type_name +} + +func init() { file_network_proto_init() } +func file_network_proto_init() { + if File_network_proto != nil { + return + } + file_network_proto_msgTypes[1].OneofWrappers = []any{ + (*EndpointRequest_Open)(nil), + (*EndpointRequest_SendTo)(nil), + (*EndpointRequest_Broadcast)(nil), + } + file_network_proto_msgTypes[6].OneofWrappers = []any{ + (*EndpointReply_Opened)(nil), + (*EndpointReply_Message)(nil), + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: unsafe.Slice(unsafe.StringData(file_network_proto_rawDesc), len(file_network_proto_rawDesc)), + NumEnums: 0, + NumMessages: 9, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_network_proto_goTypes, + DependencyIndexes: file_network_proto_depIdxs, + MessageInfos: file_network_proto_msgTypes, + }.Build() + File_network_proto = out.File + file_network_proto_goTypes = nil + file_network_proto_depIdxs = nil +} diff --git a/libs/capability/ocr/remote/internal/pb/network.proto b/libs/capability/ocr/remote/internal/pb/network.proto new file mode 100644 index 000000000..1e4a8771e --- /dev/null +++ b/libs/capability/ocr/remote/internal/pb/network.proto @@ -0,0 +1,65 @@ +syntax = "proto3"; + +package capabilities.ocr.remote.internal.pb; + +option go_package = "github.com/smartcontractkit/capabilities/libs/capability/ocr/remote/internal/pb"; + +// Network lends a process that runs an OCR oracle rage networking over the node's peer. +service Network { + // Connect is the life of one BinaryNetworkEndpoint. The first request must be open. The node answers with opened + // once the endpoint is started, then with each message the endpoint receives. The endpoint is closed when the + // stream ends. + rpc Connect(stream EndpointRequest) returns (stream EndpointReply); +} + +message BootstrapperLocator { + string peer_id = 1; + repeated string addrs = 2; +} + +message EndpointRequest { + oneof request { + OpenRequest open = 1; + SendToRequest send_to = 2; + BroadcastRequest broadcast = 3; + } +} + +message OpenRequest { + bytes config_digest = 1; + repeated string peer_ids = 2; + repeated BootstrapperLocator bootstrappers = 3; + int64 f = 4; + EndpointLimits limits = 5; +} + +message EndpointLimits { + int64 max_message_length = 1; + double messages_rate_per_oracle = 2; + int64 messages_capacity_per_oracle = 3; + double bytes_rate_per_oracle = 4; + int64 bytes_capacity_per_oracle = 5; +} + +message SendToRequest { + bytes payload = 1; + uint32 to = 2; +} + +message BroadcastRequest { + bytes payload = 1; +} + +message EndpointReply { + oneof reply { + Opened opened = 1; + Message message = 2; + } +} + +message Opened {} + +message Message { + bytes payload = 1; + uint32 sender = 2; +} diff --git a/libs/capability/ocr/remote/internal/pb/network_grpc.pb.go b/libs/capability/ocr/remote/internal/pb/network_grpc.pb.go new file mode 100644 index 000000000..fca0bdbc0 --- /dev/null +++ b/libs/capability/ocr/remote/internal/pb/network_grpc.pb.go @@ -0,0 +1,125 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.5.1 +// - protoc v5.29.3 +// source: network.proto + +package pb + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 + +const ( + Network_Connect_FullMethodName = "/capabilities.ocr.remote.internal.pb.Network/Connect" +) + +// NetworkClient is the client API for Network service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +// +// Network lends a process that runs an OCR oracle rage networking over the node's peer. +type NetworkClient interface { + // Connect is the life of one BinaryNetworkEndpoint. The first request must be open. The node answers with opened + // once the endpoint is started, then with each message the endpoint receives. The endpoint is closed when the + // stream ends. + Connect(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[EndpointRequest, EndpointReply], error) +} + +type networkClient struct { + cc grpc.ClientConnInterface +} + +func NewNetworkClient(cc grpc.ClientConnInterface) NetworkClient { + return &networkClient{cc} +} + +func (c *networkClient) Connect(ctx context.Context, opts ...grpc.CallOption) (grpc.BidiStreamingClient[EndpointRequest, EndpointReply], error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + stream, err := c.cc.NewStream(ctx, &Network_ServiceDesc.Streams[0], Network_Connect_FullMethodName, cOpts...) + if err != nil { + return nil, err + } + x := &grpc.GenericClientStream[EndpointRequest, EndpointReply]{ClientStream: stream} + return x, nil +} + +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type Network_ConnectClient = grpc.BidiStreamingClient[EndpointRequest, EndpointReply] + +// NetworkServer is the server API for Network service. +// All implementations must embed UnimplementedNetworkServer +// for forward compatibility. +// +// Network lends a process that runs an OCR oracle rage networking over the node's peer. +type NetworkServer interface { + // Connect is the life of one BinaryNetworkEndpoint. The first request must be open. The node answers with opened + // once the endpoint is started, then with each message the endpoint receives. The endpoint is closed when the + // stream ends. + Connect(grpc.BidiStreamingServer[EndpointRequest, EndpointReply]) error + mustEmbedUnimplementedNetworkServer() +} + +// UnimplementedNetworkServer must be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedNetworkServer struct{} + +func (UnimplementedNetworkServer) Connect(grpc.BidiStreamingServer[EndpointRequest, EndpointReply]) error { + return status.Errorf(codes.Unimplemented, "method Connect not implemented") +} +func (UnimplementedNetworkServer) mustEmbedUnimplementedNetworkServer() {} +func (UnimplementedNetworkServer) testEmbeddedByValue() {} + +// UnsafeNetworkServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to NetworkServer will +// result in compilation errors. +type UnsafeNetworkServer interface { + mustEmbedUnimplementedNetworkServer() +} + +func RegisterNetworkServer(s grpc.ServiceRegistrar, srv NetworkServer) { + // If the following call pancis, it indicates UnimplementedNetworkServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } + s.RegisterService(&Network_ServiceDesc, srv) +} + +func _Network_Connect_Handler(srv interface{}, stream grpc.ServerStream) error { + return srv.(NetworkServer).Connect(&grpc.GenericServerStream[EndpointRequest, EndpointReply]{ServerStream: stream}) +} + +// This type alias is provided for backwards compatibility with existing code that references the prior non-generic stream type by name. +type Network_ConnectServer = grpc.BidiStreamingServer[EndpointRequest, EndpointReply] + +// Network_ServiceDesc is the grpc.ServiceDesc for Network service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var Network_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "capabilities.ocr.remote.internal.pb.Network", + HandlerType: (*NetworkServer)(nil), + Methods: []grpc.MethodDesc{}, + Streams: []grpc.StreamDesc{ + { + StreamName: "Connect", + Handler: _Network_Connect_Handler, + ServerStreams: true, + ClientStreams: true, + }, + }, + Metadata: "network.proto", +} diff --git a/libs/capability/ocr/remote/remote_test.go b/libs/capability/ocr/remote/remote_test.go new file mode 100644 index 000000000..9eb8c9b87 --- /dev/null +++ b/libs/capability/ocr/remote/remote_test.go @@ -0,0 +1,231 @@ +package remote + +import ( + "context" + "errors" + "net" + "strings" + "sync" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + "google.golang.org/grpc/test/bufconn" + + "github.com/smartcontractkit/libocr/commontypes" + ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types" + + "github.com/smartcontractkit/chainlink-common/pkg/logger" + + "github.com/smartcontractkit/capabilities/libs/capability/ocr/remote/internal/pb" +) + +func TestNewNetworkClient(t *testing.T) { + t.Parallel() + factory := NewClient(logger.Test(t), serve(t, newFakeHost()), "12D3KooWPeer") + assert.Equal(t, "12D3KooWPeer", factory.PeerID()) +} + +func TestEndpoint(t *testing.T) { + t.Parallel() + host := newFakeHost() + factory := connect(t, serve(t, host)) + + digest := ocrtypes.ConfigDigest{2} + limits := ocrtypes.BinaryNetworkEndpointLimits{MaxMessageLength: 10, MessagesRatePerOracle: 1.5} + endpoint, err := factory.NewEndpoint(digest, []string{"a", "b"}, nil, 1, limits) + require.NoError(t, err) + require.NoError(t, endpoint.Start()) + + hosted := host.endpoint(t, digest) + assert.Equal(t, []string{"a", "b"}, hosted.peerIDs) + assert.Equal(t, limits, hosted.limits) + + endpoint.SendTo([]byte("to-1"), 1) + endpoint.Broadcast([]byte("all")) + assert.Equal(t, sent{payload: "to-1", to: 1}, receiveWithin(t, hosted.sent)) + assert.Equal(t, sent{payload: "all", broadcast: true}, receiveWithin(t, hosted.sent)) + + hosted.received <- commontypes.BinaryMessageWithSender{Msg: []byte("from-2"), Sender: 2} + assert.Equal(t, commontypes.BinaryMessageWithSender{Msg: []byte("from-2"), Sender: 2}, receiveWithin(t, endpoint.Receive())) + + require.NoError(t, endpoint.Close()) + require.NoError(t, endpoint.Close()) + receiveWithin(t, hosted.closed) +} + +// TestEndpoint_LargeMessages checks messages past gRPC's 4 MiB default cross both ways, as a leader's proposal can. +func TestEndpoint_LargeMessages(t *testing.T) { + t.Parallel() + host := newFakeHost() + factory := connect(t, serve(t, host)) + + digest := ocrtypes.ConfigDigest{6} + endpoint, err := factory.NewEndpoint(digest, nil, nil, 1, ocrtypes.BinaryNetworkEndpointLimits{}) + require.NoError(t, err) + require.NoError(t, endpoint.Start()) + t.Cleanup(func() { _ = endpoint.Close() }) + hosted := host.endpoint(t, digest) + + large := strings.Repeat("x", 5*1024*1024) + endpoint.SendTo([]byte(large), 1) + assert.Equal(t, sent{payload: large, to: 1}, receiveWithin(t, hosted.sent)) + + hosted.received <- commontypes.BinaryMessageWithSender{Msg: []byte(large), Sender: 2} + assert.Equal(t, commontypes.BinaryMessageWithSender{Msg: []byte(large), Sender: 2}, receiveWithin(t, endpoint.Receive())) +} + +func TestEndpoint_HostErrorsAreReturnedByNewEndpoint(t *testing.T) { + t.Parallel() + host := newFakeHost() + host.newEndpointErr = errors.New("already open") + factory := connect(t, serve(t, host)) + + _, err := factory.NewEndpoint(ocrtypes.ConfigDigest{3}, nil, nil, 1, ocrtypes.BinaryNetworkEndpointLimits{}) + require.ErrorContains(t, err, "already open") +} + +func TestEndpoint_HostClosesEndpointWhenStreamBreaks(t *testing.T) { + t.Parallel() + host := newFakeHost() + conn := serve(t, host) + factory := connect(t, conn) + + digest := ocrtypes.ConfigDigest{4} + _, err := factory.NewEndpoint(digest, nil, nil, 1, ocrtypes.BinaryNetworkEndpointLimits{}) + require.NoError(t, err) + hosted := host.endpoint(t, digest) + + require.NoError(t, conn.Close()) + receiveWithin(t, hosted.closed) +} + +func TestEndpoint_SendDropsOldestWhenFull(t *testing.T) { + t.Parallel() + e := &endpoint{lggr: logger.Test(t), outbound: make(chan *pb.EndpointRequest, 2)} + + e.Broadcast([]byte("1")) + e.Broadcast([]byte("2")) + e.Broadcast([]byte("3")) + + assert.Equal(t, []byte("2"), (<-e.outbound).GetBroadcast().GetPayload()) + assert.Equal(t, []byte("3"), (<-e.outbound).GetBroadcast().GetPayload()) +} + +func connect(t *testing.T, conn *grpc.ClientConn) ocrtypes.BinaryNetworkEndpointFactory { + t.Helper() + return NewClient(logger.Test(t), conn, "12D3KooWPeer") +} + +func serve(t *testing.T, host ocrtypes.BinaryNetworkEndpointFactory) *grpc.ClientConn { + t.Helper() + lis := bufconn.Listen(1024 * 1024) + s := grpc.NewServer(grpc.MaxRecvMsgSize(MaxMessageSize)) + require.NoError(t, RegisterServer(s, logger.Test(t), func(context.Context) (ocrtypes.BinaryNetworkEndpointFactory, error) { + return host, nil + })) + go func() { _ = s.Serve(lis) }() + t.Cleanup(s.Stop) + + conn, err := grpc.NewClient("passthrough:///bufnet", + grpc.WithTransportCredentials(insecure.NewCredentials()), + grpc.WithContextDialer(func(ctx context.Context, _ string) (net.Conn, error) { return lis.DialContext(ctx) }), + ) + require.NoError(t, err) + t.Cleanup(func() { _ = conn.Close() }) + return conn +} + +func receiveWithin[T any](t *testing.T, ch <-chan T) T { + t.Helper() + select { + case v := <-ch: + return v + case <-time.After(5 * time.Second): + require.FailNow(t, "timed out waiting to receive") + var zero T + return zero + } +} + +// fakeHost is a host whose endpoints record what they are given. +type fakeHost struct { + peerID string + newEndpointErr error + + mu sync.Mutex + endpoints map[ocrtypes.ConfigDigest]*fakeEndpoint + opened chan ocrtypes.ConfigDigest +} + +func newFakeHost() *fakeHost { + return &fakeHost{ + peerID: "12D3KooWPeer", + endpoints: map[ocrtypes.ConfigDigest]*fakeEndpoint{}, + opened: make(chan ocrtypes.ConfigDigest, 10), + } +} + +func (h *fakeHost) endpoint(t *testing.T, digest ocrtypes.ConfigDigest) *fakeEndpoint { + t.Helper() + require.Equal(t, digest, receiveWithin(t, h.opened)) + h.mu.Lock() + defer h.mu.Unlock() + return h.endpoints[digest] +} + +func (h *fakeHost) PeerID() string { return h.peerID } + +func (h *fakeHost) NewEndpoint(digest ocrtypes.ConfigDigest, peerIDs []string, _ []commontypes.BootstrapperLocator, + _ int, limits ocrtypes.BinaryNetworkEndpointLimits) (commontypes.BinaryNetworkEndpoint, error) { + if h.newEndpointErr != nil { + return nil, h.newEndpointErr + } + + e := &fakeEndpoint{ + peerIDs: peerIDs, + limits: limits, + sent: make(chan sent, 10), + received: make(chan commontypes.BinaryMessageWithSender, 10), + closed: make(chan struct{}, 1), + } + h.mu.Lock() + h.endpoints[digest] = e + h.mu.Unlock() + h.opened <- digest + return e, nil +} + +type sent struct { + payload string + to commontypes.OracleID + broadcast bool +} + +type fakeEndpoint struct { + peerIDs []string + limits ocrtypes.BinaryNetworkEndpointLimits + sent chan sent + received chan commontypes.BinaryMessageWithSender + closed chan struct{} +} + +func (e *fakeEndpoint) SendTo(payload []byte, to commontypes.OracleID) { + e.sent <- sent{payload: string(payload), to: to} +} + +func (e *fakeEndpoint) Broadcast(payload []byte) { + e.sent <- sent{payload: string(payload), broadcast: true} +} + +func (e *fakeEndpoint) Receive() <-chan commontypes.BinaryMessageWithSender { return e.received } + +func (e *fakeEndpoint) Start() error { return nil } + +func (e *fakeEndpoint) Close() error { + e.closed <- struct{}{} + return nil +} diff --git a/libs/capability/ocr/remote/server.go b/libs/capability/ocr/remote/server.go new file mode 100644 index 000000000..c0bab1a47 --- /dev/null +++ b/libs/capability/ocr/remote/server.go @@ -0,0 +1,162 @@ +package remote + +import ( + "context" + "errors" + "io" + + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + + "github.com/smartcontractkit/libocr/commontypes" + ocrtypes "github.com/smartcontractkit/libocr/offchainreporting2plus/types" + + "github.com/smartcontractkit/chainlink-common/pkg/logger" + + "github.com/smartcontractkit/capabilities/libs/capability/ocr/remote/internal/pb" +) + +// RegisterServer serves the BinaryNetworkEndpointFactory factory returns as the Network service on s. +func RegisterServer(s grpc.ServiceRegistrar, lggr logger.Logger, + factory func(context.Context) (ocrtypes.BinaryNetworkEndpointFactory, error)) error { + pb.RegisterNetworkServer(s, &networkServer{lggr: logger.Named(lggr, "OCRNetworkServer"), factory: factory}) + return nil +} + +type networkServer struct { + pb.UnimplementedNetworkServer + lggr logger.Logger + factory func(context.Context) (ocrtypes.BinaryNetworkEndpointFactory, error) +} + +func (s *networkServer) Connect(stream pb.Network_ConnectServer) error { + ctx := stream.Context() + first, err := stream.Recv() + if err != nil { + return err + } + + open := first.GetOpen() + if open == nil { + return status.Error(codes.InvalidArgument, "the first request must open the endpoint") + } + + digest, err := ocrtypes.BytesToConfigDigest(open.ConfigDigest) + if err != nil { + return status.Errorf(codes.InvalidArgument, "invalid config digest: %v", err) + } + + factory, err := s.factory(ctx) + if err != nil { + return status.Errorf(codes.Unavailable, "failed to get the node's OCR network: %v", err) + } + + endpoint, err := factory.NewEndpoint(digest, open.PeerIds, + bootstrappersFromPB(open.Bootstrappers), int(open.F), limitsFromPB(open.Limits)) + if err != nil { + return status.Errorf(codes.FailedPrecondition, "failed to create endpoint: %v", err) + } + + defer func() { + if cerr := endpoint.Close(); cerr != nil { + s.lggr.Warnw("Failed to close endpoint", "configDigest", digest, "err", cerr) + } + }() + + if err = endpoint.Start(); err != nil { + return status.Errorf(codes.FailedPrecondition, "failed to start endpoint: %v", err) + } + + if err = stream.Send(&pb.EndpointReply{Reply: &pb.EndpointReply_Opened{Opened: &pb.Opened{}}}); err != nil { + return err + } + + ctx, cancel := context.WithCancel(ctx) + received := make(chan error, 1) + go func() { received <- forwardReceived(ctx, endpoint, stream) }() + err = forwardSent(endpoint, stream) + cancel() + return errors.Join(err, <-received) +} + +func forwardSent(endpoint commontypes.BinaryNetworkEndpoint, stream pb.Network_ConnectServer) error { + for { + req, err := stream.Recv() + if err != nil { + if errors.Is(err, io.EOF) || errors.Is(err, context.Canceled) || status.Code(err) == codes.Canceled { + return nil + } + + return err + } + + switch r := req.Request.(type) { + case *pb.EndpointRequest_SendTo: + endpoint.SendTo(r.SendTo.Payload, commontypes.OracleID(r.SendTo.To)) //nolint:gosec // oracle IDs fit in a uint8 + case *pb.EndpointRequest_Broadcast: + endpoint.Broadcast(r.Broadcast.GetPayload()) + default: + return status.Errorf(codes.InvalidArgument, "unexpected request %T after the endpoint is open", req.Request) + } + } +} + +func forwardReceived(ctx context.Context, endpoint commontypes.BinaryNetworkEndpoint, stream pb.Network_ConnectServer) error { + for { + select { + case <-ctx.Done(): + return nil + case msg, ok := <-endpoint.Receive(): + if !ok { + return nil + } + + err := stream.Send(&pb.EndpointReply{Reply: &pb.EndpointReply_Message{Message: &pb.Message{ + Payload: msg.Msg, + Sender: uint32(msg.Sender), + }}}) + if err != nil { + return err + } + } + } +} + +func bootstrappersToPB(locators []commontypes.BootstrapperLocator) []*pb.BootstrapperLocator { + out := make([]*pb.BootstrapperLocator, len(locators)) + for i, l := range locators { + out[i] = &pb.BootstrapperLocator{PeerId: l.PeerID, Addrs: l.Addrs} + } + + return out +} + +func bootstrappersFromPB(locators []*pb.BootstrapperLocator) []commontypes.BootstrapperLocator { + out := make([]commontypes.BootstrapperLocator, len(locators)) + for i, l := range locators { + out[i] = commontypes.BootstrapperLocator{PeerID: l.PeerId, Addrs: l.Addrs} + } + + return out +} + +func limitsToPB(l ocrtypes.BinaryNetworkEndpointLimits) *pb.EndpointLimits { + return &pb.EndpointLimits{ + MaxMessageLength: int64(l.MaxMessageLength), + MessagesRatePerOracle: l.MessagesRatePerOracle, + MessagesCapacityPerOracle: int64(l.MessagesCapacityPerOracle), + BytesRatePerOracle: l.BytesRatePerOracle, + BytesCapacityPerOracle: int64(l.BytesCapacityPerOracle), + } +} + +func limitsFromPB(l *pb.EndpointLimits) ocrtypes.BinaryNetworkEndpointLimits { + return ocrtypes.BinaryNetworkEndpointLimits{ + MaxMessageLength: int(l.GetMaxMessageLength()), + MessagesRatePerOracle: l.GetMessagesRatePerOracle(), + MessagesCapacityPerOracle: int(l.GetMessagesCapacityPerOracle()), + BytesRatePerOracle: l.GetBytesRatePerOracle(), + BytesCapacityPerOracle: int(l.GetBytesCapacityPerOracle()), + } +} diff --git a/libs/go.mod b/libs/go.mod index 4de9605f4..aa4a324ba 100644 --- a/libs/go.mod +++ b/libs/go.mod @@ -25,6 +25,7 @@ require ( go.opentelemetry.io/otel/sdk/metric v1.47.0 go.opentelemetry.io/otel/trace v1.47.0 go.uber.org/zap v1.28.0 + golang.org/x/crypto v0.55.0 golang.org/x/mod v0.38.0 google.golang.org/genproto/googleapis/rpc v0.0.0-20260819154853-08b0e4226688 google.golang.org/grpc v1.83.2 @@ -33,6 +34,7 @@ require ( require ( github.com/Masterminds/semver/v3 v3.4.0 // indirect + github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20251001021608-1fe7b43fc4d6 // indirect github.com/XSAM/otelsql v0.37.0 // indirect github.com/bahlo/generic-list-go v0.2.0 // indirect github.com/beorn7/perks v1.0.1 // indirect @@ -41,6 +43,8 @@ require ( github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/cloudevents/sdk-go/binding/format/protobuf/v2 v2.16.1 // indirect github.com/cloudevents/sdk-go/v2 v2.16.1 // indirect + github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect + github.com/ethereum/go-ethereum v1.17.4 // indirect github.com/fatih/color v1.18.0 // indirect github.com/fsnotify/fsnotify v1.9.0 // indirect github.com/fxamacker/cbor/v2 v2.9.0 // indirect @@ -53,6 +57,7 @@ require ( github.com/go-playground/validator/v10 v10.26.0 // indirect github.com/go-viper/mapstructure/v2 v2.5.0 // indirect github.com/golang/protobuf v1.5.4 // indirect + github.com/google/btree v1.1.3 // indirect github.com/grafana/otel-profiling-go v0.5.1 // indirect github.com/grafana/pyroscope-go v1.2.8 // indirect github.com/grafana/pyroscope-go/godeltaprof v0.1.9 // indirect @@ -61,6 +66,7 @@ require ( github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0 // indirect github.com/hashicorp/go-hclog v1.6.3 // indirect github.com/hashicorp/yamux v0.1.2 // indirect + github.com/holiman/uint256 v1.3.2 // indirect github.com/huandu/go-clone v1.7.3 // indirect github.com/iancoleman/strcase v0.3.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect @@ -125,7 +131,6 @@ require ( go.uber.org/multierr v1.11.0 // indirect go.yaml.in/yaml/v2 v2.4.4 // indirect go.yaml.in/yaml/v3 v3.0.5 // indirect - golang.org/x/crypto v0.55.0 // indirect golang.org/x/exp v0.0.0-20260508232706-74f9aab9d74a // indirect golang.org/x/net v0.58.0 // indirect golang.org/x/sync v0.22.0 // indirect diff --git a/libs/go.sum b/libs/go.sum index 9c38900d5..09a8430fb 100644 --- a/libs/go.sum +++ b/libs/go.sum @@ -4,6 +4,8 @@ filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4 github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/Masterminds/semver/v3 v3.4.0 h1:Zog+i5UMtVoCU8oKka5P7i9q9HgrJeGzI9SA1Xbatp0= github.com/Masterminds/semver/v3 v3.4.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM= +github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20251001021608-1fe7b43fc4d6 h1:1zYrtlhrZ6/b6SAjLSfKzWtdgqK0U+HtH/VcBWh1BaU= +github.com/ProjectZKM/Ziren/crates/go-runtime/zkvm_runtime v0.0.0-20251001021608-1fe7b43fc4d6/go.mod h1:ioLG6R+5bUSO1oeGSDxOV3FADARuMoytZCSX6MEMQkI= github.com/XSAM/otelsql v0.37.0 h1:ya5RNw028JW0eJW8Ma4AmoKxAYsJSGuNVbC7F1J457A= github.com/XSAM/otelsql v0.37.0/go.mod h1:LHbCu49iU8p255nCn1oi04oX2UjSoRcUMiKEHo2a5qM= github.com/apache/arrow-go/v18 v18.3.1 h1:oYZT8FqONiK74JhlH3WKVv+2NKYoyZ7C2ioD4Dj3ixk= @@ -32,10 +34,16 @@ github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/decred/dcrd/crypto/blake256 v1.0.1 h1:7PltbUIQB7u/FfZ39+DGa/ShuMyJ5ilcvdfma9wOH6Y= +github.com/decred/dcrd/crypto/blake256 v1.0.1/go.mod h1:2OfgNZ5wDpcsFmHmCK5gZTPcCXqlm2ArzUIkw9czNJo= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 h1:rpfIENRNNilwHwZeG5+P150SMrnNEcHYvcCuK6dPZSg= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0/go.mod h1:v57UDF4pDQJcEfFUCRop3lJL149eHGSe9Jvczhzjo/0= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/ethereum/go-ethereum v1.17.4 h1:uA4q+qiLp7QImBsjdRbINu8iX6OEVmj4DPc5/E5Fsxc= +github.com/ethereum/go-ethereum v1.17.4/go.mod h1:qMdgwqqRAen+aT8P7KKQKi0Qt6RzG4cfejVAbCpJgqA= github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk= github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM= github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU= @@ -83,6 +91,8 @@ github.com/golang/protobuf v1.5.1/go.mod h1:DopwsBzvsk0Fs44TXzsVbJyPhcCPeIwnvohx github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= +github.com/google/btree v1.1.3 h1:CVpQJjYgC4VbzxeGVHfvZrv1ctoYCAI8vbl07Fcxlyg= +github.com/google/btree v1.1.3/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4= github.com/google/flatbuffers v25.2.10+incompatible h1:F3vclr7C3HpB1k9mxCGRMXq6FdUalZ6H/pNX4FP1v0Q= github.com/google/flatbuffers v25.2.10+incompatible/go.mod h1:1AeVuKshWv4vARoZatz6mlQ0JxURH0Kv5+zNeJKJCa8= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= @@ -116,6 +126,8 @@ github.com/hashicorp/go-plugin v1.8.0 h1:ie8S6RRY8RvB2usYZv+AAZ/wBvx2AU5p5QeP5j/ github.com/hashicorp/go-plugin v1.8.0/go.mod h1:BExt6KEaIYx804z8k4gRzRLEvxKVb+kn0NMcihqOqb8= github.com/hashicorp/yamux v0.1.2 h1:XtB8kyFOyHXYVFnwT5C3+Bdo8gArse7j2AQ0DA0Uey8= github.com/hashicorp/yamux v0.1.2/go.mod h1:C+zze2n6e/7wshOZep2A70/aQU6QBRWJO/G6FT1wIns= +github.com/holiman/uint256 v1.3.2 h1:a9EgMPSC1AAaj1SZL5zIQD3WbwTuHrMGOerLjGmM/TA= +github.com/holiman/uint256 v1.3.2/go.mod h1:EOMSn4q6Nyt9P6efbI3bueV4e1b3dGlUCXeiRV4ng7E= github.com/huandu/go-assert v1.1.5 h1:fjemmA7sSfYHJD7CUqs9qTwwfdNAx7/j2/ZlHXzNB3c= github.com/huandu/go-assert v1.1.5/go.mod h1:yOLvuqZwmcHIC5rIzrBhT7D3Q9c3GFnd0JrPVhn/06U= github.com/huandu/go-clone v1.7.3 h1:rtQODA+ABThEn6J5LBTppJfKmZy/FwfpMUWa8d01TTQ= From d48afe7977d33fb1b2e9b6aad50675d4fddce141 Mon Sep 17 00:00:00 2001 From: "gati-app[bot]" <326096268+gati-app[bot]@users.noreply.github.com> Date: Mon, 23 Nov 2026 16:52:04 +0000 Subject: [PATCH 2/2] chore: format, generate, and tidy Autofix: true --- libs/capability/ocr/remote/internal/pb/network.pb.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/capability/ocr/remote/internal/pb/network.pb.go b/libs/capability/ocr/remote/internal/pb/network.pb.go index 24ac96a93..a740174cc 100644 --- a/libs/capability/ocr/remote/internal/pb/network.pb.go +++ b/libs/capability/ocr/remote/internal/pb/network.pb.go @@ -1,6 +1,6 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.36.11 +// protoc-gen-go v1.36.10 // protoc v5.29.3 // source: network.proto