package
0.4.1
Repository: https://github.com/goplugin/plugin-common.git
Documentation: pkg.go.dev

# README

LOOP Plugins Go Reference

Local out of process (LOOP) plugins using github.com/hashicorp/go-plugin.

Packages

flowchart
    subgraph plugin-common/pkg
        loop
        internal[loop/internal]
        pb[loop/internal/pb]
        test[loop/internal/test]

        internal --> pb
        test --> internal
        loop --> internal
        loop --> test
    end
    
    grpc[google.golang.org/grpc]
    hashicorp[hashicorp/go-plugin]

    loop ---> hashicorp
    loop ---> grpc
    test ---> grpc
    internal ---> grpc
    pb ---> grpc
    hashicorp --> grpc

package loop

Public API and hashicorp/go-plugin integration.

package test

Testing utilities.

package internal

GRPC client & server implementations.

package pb

Protocol buffer definitions & generated code.

Communication

GRPC client/server pairs are used to communicated between the host and each plugin. Plugins cannot communicate directly with one another, but the host can proxy a connection between them.

Here are the main components for the case of Median:

sequenceDiagram
    autonumber
    participant relayer as Relayer (plugin)
    participant core as Plugin (host)
    participant median as Median (plugin)

    Note over core: KeystoreServer
    core->>+relayer: NewRelayer(Config, Keystore)
    Note over relayer: KeystoreClient
    Note over relayer: RelayerServer
    relayer->>-core: Relayer ID 
    Note over core: RelayerClient

    core->>+relayer: NewMedianProvider(RelayArgs, PluginArgs)
    Note over relayer: MedianProviderServer
    relayer->>-core: MedianProvider ID
    Note over core: MedianProvider (Proxy)

    Note over core:  DataSourceServer
    Note over core:  ErrorLogServer

    core->>+median: NewMedianFactory(MedianProvider, DataSource, ErrorLog)
    Note over median: MedianProviderClient
    Note over median: DataSourceClient
    Note over median: ErrorLogClient
    Note over median: MedianFactoryServer
    median->>-core: MedianFactory ID
    Note over core: MedianFactoryClient

    core->>+median: NewReportingPlugin(ReportingPluginConfig)
    Note over median: ReportingPluginServer
    median->>-core: ReportingPlugin ID
    Note over core: ReportingPluginClient

Note: MedianProvider includes multiple component services on the same connection.

sequenceDiagram
    autonumber
    participant relayer as Relayer (plugin)
    participant core as Plugin (host)
    participant median as Median (plugin)

    core->>+relayer: NewMedianProvider(RelayArgs, PluginArgs)
    Note over relayer: OffchainConfigDigesterServer
    Note over relayer: ContractConfigTrackerServer
    Note over relayer: ContractTransmitterServer
    Note over relayer: ReportCodecServer
    Note over relayer: MedianContractServer
    Note over relayer: OnchainConfigCodecServer
    
    relayer->>-core: MedianProvider ID
    Note over core: MedianProvider (Proxy)
    
    Note over core: OffchainConfigDigesterClient
    Note over core: ContractConfigTrackerClient
    Note over core: ContractTransmitterClient
    
    core->>+median: NewMedianFactory(MedianProvider, DataSource, ErrorLog)
    Note over median: ReportCodecClient
    Note over median: MedianContractClient
    Note over median: OnchainConfigCodecClient

Auto-Recovery

The pluginService type contains reusable automatic recovery code.

type pluginService[P grpcPlugin, S services.Service] struct

Each plugin implements their own interface (Relayer, Median, etc.) with a new type that also embeds a pluginService. This new service type implements the original interface, but internally manages re-starting and re-connecting to the plugin as an implementation detail. So there is one long-lived instance of each plugin service and client, and whenever the plugin process (along with its server) crashes, the service restarts the plugin process and re-establishes the client's connection to the new server.

sequenceDiagram
    participant core as Plugin (host)
    participant relayer as Process 1 (plugin)
    participant relayer2 as Process 2 (plugin)
    
    Note over core: RelayerService
    
    core->>+relayer: exec.Cmd
    core->>relayer: NewRelayerServer
    Note over relayer: RelayerServer
    relayer->>core: RelayerID
    Note over core: RelayerClient.init()
    
    loop
        core->>relayer: Alive?
        relayer->>core: Yes
    end
    core->>relayer: Alive?
    relayer->>-core: No

    core->>+relayer2: exec.Cmd
    core->>relayer2: NewRelayerServer
    Note over relayer2: RelayerServer
    relayer2->>core: RelayerID
    Note over core: RelayerClient.update()

    loop
        core->>relayer2: Alive?
        relayer2->>-core: Yes
    end

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author

# Functions

HCLogLogger returns an [hclog.Logger] backed by the given [logger.Logger].
ManagedGRPCClientConfig return a Managed plugin and set grpc config values from the BrokerConfig.
MustNewStartedServer returns a new started Server like NewStartedServer, but logs and exits in the event of error.
NewCommitService returns a new [*CommitFactoryService].
NewExecutionService returns a new [*ExecutionFactoryService].
NewGRPCOpts initializes open telemetry and returns GRPCOpts with telemetry interceptors.
No description provided by the author
NewLogger returns a new [logger.Logger] configured to encode [hclog] compatible JSON.
NewMedianService returns a new [*MedianService].
NewMercuryV1Service returns a new [*MercuryV1Service].
NewMercuryV2Service returns a new [*MercuryV2Service].
NewMercuryV3Service returns a new [*MercuryV3Service].
NewMercuryV4Service returns a new [*MercuryV4Service].
No description provided by the author
No description provided by the author
NewRelayerService returns a new [*RelayerService].
No description provided by the author
NewStartedServer returns a started Server.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
SetupTracing initializes open telemetry with the provided config.
No description provided by the author

# Constants

CCIPCommitLOOPName is the name for [types.CCIPCommitFactoryGenerator]/[NewCommitLOOP].
CCIPExecutionLOOPName is the name for [types.CCIPExecutionFactoryGenerator]/[NewExecutionLOOP].
PluginKeystoreName is the name for keystore.Keystore.
PluginMedianName is the name for [types.PluginMedian]/[NewGRPCPluginMedian].
PluginMercurynName is the name for [types.PluginMercury]/[NewGRPCPluginMercury].
PluginRelayerName is the name for [types.PluginRelayer]/[NewGRPCPluginRelayer].
No description provided by the author

# Variables

No description provided by the author

# Structs

CommitFactoryService is a [types.Service] that maintains an internal [types.CCIPCommitFactoryGenerator].
No description provided by the author
ContextValues is a helper for passing values via a [context.Context].
EnvConfig is the configuration between the application and the LOOP executable.
ExecutionFactoryService is a [types.Service] that maintains an internal [types.CCIPExecutionFactoryGenerator].
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
GRPCPluginRelayer implements [plugin.GRPCPlugin] for [types.PluginRelayer].
KeystoreService is a [types.Service] that maintains an internal [keystore.Keystore].
LogMessageExtraArgs is a key value pair within the Output payload.
MedianService is a [types.Service] that maintains an internal [types.PluginMedian].
MercuryV1Service is a [types.Service] that maintains an internal [types.PluginMedian].
MercuryV2Service is a [types.Service] that maintains an internal [types.PluginMedian].
MercuryV3Service is a [types.Service] that maintains an internal [types.PluginMedian].
MercuryV4Service is a [types.Service] that maintains an internal [types.PluginMedian].
Plugin is a base layer for plugins to easily manage sub-[types.Service]s.
No description provided by the author
No description provided by the author
RelayerService is a [types.Service] that maintains an internal [Relayer].
Server holds common plugin server fields.
No description provided by the author
No description provided by the author
No description provided by the author

# Interfaces

No description provided by the author
No description provided by the author

# Type aliases

No description provided by the author
Deprecated.
No description provided by the author
Deprecated.
No description provided by the author
Deprecated.
No description provided by the author
No description provided by the author
Deprecated.