Skip to content

Commit

Permalink
bump libocr; add context
Browse files Browse the repository at this point in the history
  • Loading branch information
jmank88 committed Apr 25, 2024
1 parent 5a8659f commit b77da61
Show file tree
Hide file tree
Showing 16 changed files with 106 additions and 95 deletions.
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ module github.com/smartcontractkit/chainlink-solana

go 1.21

replace github.com/smartcontractkit/libocr => github.com/jmank88/libocr v0.0.0-20240425103000-0eed0c09969e

require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc
github.com/gagliardetto/binary v0.7.7
Expand All @@ -15,7 +17,7 @@ require (
github.com/pelletier/go-toml/v2 v2.1.1
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.17.0
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240422215914-3b758c48e596
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240425103110-dbf028ff5724
github.com/smartcontractkit/libocr v0.0.0-20240326191951-2bbe9382d052
github.com/stretchr/testify v1.9.0
go.uber.org/multierr v1.11.0
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,8 @@ github.com/invopop/jsonschema v0.12.0/go.mod h1:ffZ5Km5SWWRAIN6wbDXItl95euhFz2uO
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
github.com/jhump/protoreflect v1.15.1 h1:HUMERORf3I3ZdX05WaQ6MIpd/NJ434hTp5YiKgfCL6c=
github.com/jhump/protoreflect v1.15.1/go.mod h1:jD/2GMKKE6OqX8qTjhADU1e6DShO+gavG9e0Q693nKo=
github.com/jmank88/libocr v0.0.0-20240425103000-0eed0c09969e h1:gswd1U2Jht2eq230MMRq1E9+XMUiiTvm/30KGaOfuvA=
github.com/jmank88/libocr v0.0.0-20240425103000-0eed0c09969e/go.mod h1:fb1ZDVXACvu4frX3APHZaEBp0xi1DIm34DcA0CwTsZM=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
Expand Down Expand Up @@ -456,14 +458,12 @@ github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeV
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
github.com/sirupsen/logrus v1.9.3/go.mod h1:naHLuLoDiP4jHNo9R0sCBMtWGeIprob74mVsIT4qYEQ=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240422215914-3b758c48e596 h1:Wo+i2cPSO8eBQ3wgJFi1rBuh01n4yHcVZTkb1hYXti4=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240422215914-3b758c48e596/go.mod h1:GTDBbovHUSAUk+fuGIySF2A/whhdtHGaWmU61BoERks=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240425103110-dbf028ff5724 h1:1qpCBUyjYP7nTYi2mdN27ZmOB9r7kA0GFww4M6VYbBA=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240425103110-dbf028ff5724/go.mod h1:2BbaKM4DOcZCH+x1SNAPq1+X/1BCMOJNx12u/OzLlNk=
github.com/smartcontractkit/go-plugin v0.0.0-20231003134350-e49dad63b306 h1:ko88+ZznniNJZbZPWAvHQU8SwKAdHngdDZ+pvVgB5ss=
github.com/smartcontractkit/go-plugin v0.0.0-20231003134350-e49dad63b306/go.mod h1:w1sAEES3g3PuV/RzUrgow20W2uErMly84hhD3um1WL4=
github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f h1:hgJif132UCdjo8u43i7iPN1/MFnu49hv7lFGFftCHKU=
github.com/smartcontractkit/grpc-proxy v0.0.0-20230731113816-f1be6620749f/go.mod h1:MvMXoufZAtqExNexqi4cjrNYE9MefKddKylxjS+//n0=
github.com/smartcontractkit/libocr v0.0.0-20240326191951-2bbe9382d052 h1:1WFjrrVrWoQ9UpVMh7Mx4jDpzhmo1h8hFUKd9awIhIU=
github.com/smartcontractkit/libocr v0.0.0-20240326191951-2bbe9382d052/go.mod h1:SJEZCHgMCAzzBvo9vMV2DQ9onfEcIJCYSViyP4JI6c4=
github.com/smartystreets/assertions v0.0.0-20180927180507-b2de0cb4f26d/go.mod h1:OnSkiWE9lh6wB0YB77sQom3nweQdgAjqCqsofrRNTgc=
github.com/smartystreets/goconvey v1.6.4/go.mod h1:syvi0/a8iFYH4r/RixwvyeAJjdLS9QV7WQ/tjFTllLA=
github.com/soheilhy/cmux v0.1.4/go.mod h1:IM3LyeVVIOuxMH7sFAkER9+bJ4dT7Ms6E4xg4kGIyLM=
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ require (
github.com/lib/pq v1.10.9
github.com/onsi/gomega v1.30.0
github.com/rs/zerolog v1.30.0
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240424132620-add4946c1c73
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240425103110-dbf028ff5724
github.com/smartcontractkit/chainlink-solana v1.0.3-0.20240422172640-59d47c73ba58
github.com/smartcontractkit/chainlink-testing-framework v1.28.4
github.com/smartcontractkit/chainlink/integration-tests v0.0.0-20240424234616-7ec1d5b7abb5
Expand Down
4 changes: 2 additions & 2 deletions integration-tests/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1412,8 +1412,8 @@ github.com/smartcontractkit/chain-selectors v1.0.10 h1:t9kJeE6B6G+hKD0GYR4kGJSCq
github.com/smartcontractkit/chain-selectors v1.0.10/go.mod h1:d4Hi+E1zqjy9HqMkjBE5q1vcG9VGgxf5VxiRHfzi2kE=
github.com/smartcontractkit/chainlink-automation v1.0.3 h1:h/ijT0NiyV06VxYVgcNfsE3+8OEzT3Q0Z9au0z1BPWs=
github.com/smartcontractkit/chainlink-automation v1.0.3/go.mod h1:RjboV0Qd7YP+To+OrzHGXaxUxoSONveCoAK2TQ1INLU=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240424132620-add4946c1c73 h1:54hM3/SrOM166it2K35hGb5K7gQ49/Op0aHp9WkqpqU=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240424132620-add4946c1c73/go.mod h1:GTDBbovHUSAUk+fuGIySF2A/whhdtHGaWmU61BoERks=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240425103110-dbf028ff5724 h1:1qpCBUyjYP7nTYi2mdN27ZmOB9r7kA0GFww4M6VYbBA=
github.com/smartcontractkit/chainlink-common v0.1.7-0.20240425103110-dbf028ff5724/go.mod h1:2BbaKM4DOcZCH+x1SNAPq1+X/1BCMOJNx12u/OzLlNk=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240419213354-ea34a948e2ee h1:eFuBKyEbL2b+eyfgV/Eu9+8HuCEev+IcBi+K9l1dG7g=
github.com/smartcontractkit/chainlink-cosmos v0.4.1-0.20240419213354-ea34a948e2ee/go.mod h1:uATrrJ8IsuBkOBJ46USuf73gz9gZy5k5bzGE5/ji/rc=
github.com/smartcontractkit/chainlink-data-streams v0.0.0-20240220203239-09be0ea34540 h1:xFSv8561jsLtF6gYZr/zW2z5qUUAkcFkApin2mnbYTo=
Expand Down
2 changes: 1 addition & 1 deletion pkg/monitoring/source_envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func (s *envelopeSource) Fetch(ctx context.Context) (interface{}, error) {
if err != nil {
return nil, fmt.Errorf("failed to fetch state from on-chain: %w", err)
}
contractConfig, err := pkgSolana.ConfigFromState(state)
contractConfig, err := pkgSolana.ConfigFromState(ctx, state)
if err != nil {
return nil, fmt.Errorf("failed to decode ContractConfig from on-chain state: %w", err)
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/solana/cmd/chainlink-solana/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func (c *pluginRelayer) NewRelayer(ctx context.Context, config string, keystore
if err != nil {
return nil, fmt.Errorf("failed to create chain: %w", err)
}
ra := &loop.RelayerAdapter{Relayer: solana.NewRelayer(c.Logger, chain), RelayerExt: chain}
ra := solana.NewRelayer(c.Logger, chain)

c.SubService(ra)

Expand Down
7 changes: 4 additions & 3 deletions pkg/solana/config_digester.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package solana

import (
"context"
"crypto/sha256"
"encoding/binary"
"fmt"
Expand All @@ -22,7 +23,7 @@ type OffchainConfigDigester struct {
}

// ConfigDigest is meant to do the same thing as config_digest_from_data from the program.
func (d OffchainConfigDigester) ConfigDigest(cfg types.ContractConfig) (types.ConfigDigest, error) {
func (d OffchainConfigDigester) ConfigDigest(ctx context.Context, cfg types.ContractConfig) (types.ConfigDigest, error) {
digest := types.ConfigDigest{}
buf := sha256.New()

Expand Down Expand Up @@ -87,7 +88,7 @@ func (d OffchainConfigDigester) ConfigDigest(cfg types.ContractConfig) (types.Co
return digest, fmt.Errorf("incorrect hash size %d, expected %d", n, len(digest))
}

pre, err := d.ConfigDigestPrefix()
pre, err := d.ConfigDigestPrefix(ctx)
if err != nil {
return digest, err
}
Expand All @@ -97,6 +98,6 @@ func (d OffchainConfigDigester) ConfigDigest(cfg types.ContractConfig) (types.Co
}

// This should return the same constant value on every invocation
func (OffchainConfigDigester) ConfigDigestPrefix() (types.ConfigDigestPrefix, error) {
func (OffchainConfigDigester) ConfigDigestPrefix(ctx context.Context) (types.ConfigDigestPrefix, error) {
return types.ConfigDigestPrefixSolana, nil
}
6 changes: 4 additions & 2 deletions pkg/solana/config_digester_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
bin "github.com/gagliardetto/binary"
"github.com/gagliardetto/solana-go"
"github.com/stretchr/testify/require"

"github.com/smartcontractkit/chainlink-common/pkg/utils/tests"
)

func TestConfigDigester(t *testing.T) {
Expand All @@ -22,10 +24,10 @@ func TestConfigDigester(t *testing.T) {
var state State
err = bin.NewBorshDecoder(mockState.Raw).Decode(&state)
require.NoError(t, err)
config, err := ConfigFromState(state)
config, err := ConfigFromState(tests.Context(t), state)
require.NoError(t, err)

actualDigest, err := digester.ConfigDigest(config)
actualDigest, err := digester.ConfigDigest(tests.Context(t), config)
require.NoError(t, err)

expectedDigest := mockState.ConfigDigestHex
Expand Down
6 changes: 3 additions & 3 deletions pkg/solana/config_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func (c *ConfigTracker) LatestConfigDetails(ctx context.Context) (changedInBlock
return state.Config.LatestConfigBlockNumber, state.Config.LatestConfigDigest, err
}

func ConfigFromState(state State) (types.ContractConfig, error) {
func ConfigFromState(ctx context.Context, state State) (types.ContractConfig, error) {
pubKeys := []types.OnchainPublicKey{}
accounts := []types.Account{}
oracles, err := state.Oracles.Data()
Expand All @@ -43,7 +43,7 @@ func ConfigFromState(state State) (types.ContractConfig, error) {
Max: state.Config.MaxAnswer.BigInt(),
}

onchainConfig, err := median.StandardOnchainConfigCodec{}.Encode(onchainConfigStruct)
onchainConfig, err := median.StandardOnchainConfigCodec{}.Encode(ctx, onchainConfigStruct)
if err != nil {
return types.ContractConfig{}, err
}
Expand All @@ -70,7 +70,7 @@ func (c *ConfigTracker) LatestConfig(ctx context.Context, changedInBlock uint64)
if err != nil {
return types.ContractConfig{}, err
}
return ConfigFromState(state)
return ConfigFromState(ctx, state)
}

// LatestBlockHeight returns the height of the most recent block in the chain.
Expand Down
4 changes: 2 additions & 2 deletions pkg/solana/monitor/balance.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ func (b *balanceMonitor) Name() string {
}

func (b *balanceMonitor) Start(context.Context) error {
return b.StartOnce("SolanaBalanceMonitor", func() error {
return b.StartOnce("BalanceMonitor", func() error {
go b.monitor()
return nil
})
}

func (b *balanceMonitor) Close() error {
return b.StopOnce("SolanaBalanceMonitor", func() error {
return b.StopOnce("BalanceMonitor", func() error {
close(b.stop)
<-b.done
return nil
Expand Down
65 changes: 35 additions & 30 deletions pkg/solana/relay.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@ package solana
import (
"context"
"encoding/json"
"math/big"

"github.com/gagliardetto/solana-go"
"github.com/pkg/errors"

"github.com/smartcontractkit/libocr/offchainreporting2/reportingplugin/median"
"github.com/smartcontractkit/libocr/offchainreporting2/types"

relaylogger "github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/logger"
"github.com/smartcontractkit/chainlink-common/pkg/services"
relaytypes "github.com/smartcontractkit/chainlink-common/pkg/types"

"github.com/smartcontractkit/chainlink-solana/pkg/solana/client"
"github.com/smartcontractkit/chainlink-solana/pkg/solana/logger"
"github.com/smartcontractkit/chainlink-solana/pkg/solana/txm"
)

Expand All @@ -28,20 +28,15 @@ type TxManager interface {
var _ relaytypes.Relayer = &Relayer{}

type Relayer struct {
lggr logger.Logger
chain Chain
ctx context.Context
cancel func()
lggr logger.Logger
chain Chain
}

// Note: constructed in core
func NewRelayer(lggr logger.Logger, chain Chain) *Relayer {
ctx, cancel := context.WithCancel(context.Background())
return &Relayer{
lggr: lggr,
chain: chain,
ctx: ctx,
cancel: cancel,
lggr: logger.Named(lggr, "Relayer"),
chain: chain,
}
}

Expand All @@ -50,51 +45,61 @@ func (r *Relayer) Name() string {
}

// Start starts the relayer respecting the given context.
func (r *Relayer) Start(context.Context) error {
func (r *Relayer) Start(ctx context.Context) error {
// No subservices started on relay start, but when the first job is started
if r.chain == nil {
return errors.New("Solana unavailable")
}
return nil
return r.chain.Start(ctx)
}

// Close will close all open subservices
func (r *Relayer) Close() error {
r.cancel()
return nil
}
func (r *Relayer) Close() error { return r.chain.Close() }

func (r *Relayer) Ready() error {
return r.chain.Ready()
}

// Healthy only if all subservices are healthy
func (r *Relayer) Healthy() error { return nil }

func (r *Relayer) HealthReport() map[string]error {
return map[string]error{r.Name(): r.Healthy()}
hp := map[string]error{r.Name(): r.Healthy()}
services.CopyHealth(hp, r.chain.HealthReport())
return hp
}

func (r *Relayer) GetChainStatus(ctx context.Context) (relaytypes.ChainStatus, error) {
return r.chain.GetChainStatus(ctx)
}

func (r *Relayer) ListNodeStatuses(ctx context.Context, pageSize int32, pageToken string) (stats []relaytypes.NodeStatus, nextPageToken string, total int, err error) {
return r.chain.ListNodeStatuses(ctx, pageSize, pageToken)
}

func (r *Relayer) Transact(ctx context.Context, from, to string, amount *big.Int, balanceCheck bool) error {
return r.chain.Transact(ctx, from, to, amount, balanceCheck)
}

func (r *Relayer) NewMercuryProvider(rargs relaytypes.RelayArgs, pargs relaytypes.PluginArgs) (relaytypes.MercuryProvider, error) {
func (r *Relayer) NewMercuryProvider(ctx context.Context, rargs relaytypes.RelayArgs, pargs relaytypes.PluginArgs) (relaytypes.MercuryProvider, error) {
return nil, errors.New("mercury is not supported for solana")
}

func (r *Relayer) NewLLOProvider(rargs relaytypes.RelayArgs, pargs relaytypes.PluginArgs) (relaytypes.LLOProvider, error) {
func (r *Relayer) NewLLOProvider(ctx context.Context, rargs relaytypes.RelayArgs, pargs relaytypes.PluginArgs) (relaytypes.LLOProvider, error) {
return nil, errors.New("data streams is not supported for solana")
}

func (r *Relayer) NewConfigProvider(args relaytypes.RelayArgs) (relaytypes.ConfigProvider, error) {
configWatcher, err := newConfigProvider(r.ctx, r.lggr, r.chain, args)
func (r *Relayer) NewConfigProvider(ctx context.Context, args relaytypes.RelayArgs) (relaytypes.ConfigProvider, error) {
configWatcher, err := newConfigProvider(ctx, r.lggr, r.chain, args)
if err != nil {
// Never return (*configProvider)(nil)
return nil, err
}
return configWatcher, err
}

func (r *Relayer) NewMedianProvider(rargs relaytypes.RelayArgs, pargs relaytypes.PluginArgs) (relaytypes.MedianProvider, error) {
lggr := relaylogger.Named(r.lggr, "MedianProvider")
configWatcher, err := newConfigProvider(r.ctx, lggr, r.chain, rargs)
func (r *Relayer) NewMedianProvider(ctx context.Context, rargs relaytypes.RelayArgs, pargs relaytypes.PluginArgs) (relaytypes.MedianProvider, error) {
lggr := logger.Named(r.lggr, "MedianProvider")
configWatcher, err := newConfigProvider(ctx, lggr, r.chain, rargs)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -140,11 +145,11 @@ func (r *Relayer) NewMedianProvider(rargs relaytypes.RelayArgs, pargs relaytypes
}, nil
}

func (r *Relayer) NewFunctionsProvider(rargs relaytypes.RelayArgs, pargs relaytypes.PluginArgs) (relaytypes.FunctionsProvider, error) {
func (r *Relayer) NewFunctionsProvider(ctx context.Context, rargs relaytypes.RelayArgs, pargs relaytypes.PluginArgs) (relaytypes.FunctionsProvider, error) {
return nil, errors.New("functions are not supported for solana")
}

func (r *Relayer) NewAutomationProvider(rargs relaytypes.RelayArgs, pargs relaytypes.PluginArgs) (relaytypes.AutomationProvider, error) {
func (r *Relayer) NewAutomationProvider(ctx context.Context, rargs relaytypes.RelayArgs, pargs relaytypes.PluginArgs) (relaytypes.AutomationProvider, error) {
return nil, errors.New("automation is not supported for solana")
}

Expand All @@ -162,7 +167,7 @@ type configProvider struct {
}

func newConfigProvider(ctx context.Context, lggr logger.Logger, chain Chain, args relaytypes.RelayArgs) (*configProvider, error) {
lggr = relaylogger.Named(lggr, "ConfigProvider")
lggr = logger.Named(lggr, "ConfigProvider")
var relayConfig RelayConfig
err := json.Unmarshal(args.RelayConfig, &relayConfig)
if err != nil {
Expand Down Expand Up @@ -289,6 +294,6 @@ func (p *medianProvider) Codec() relaytypes.Codec {
return nil
}

func (r *Relayer) NewPluginProvider(rargs relaytypes.RelayArgs, pargs relaytypes.PluginArgs) (relaytypes.PluginProvider, error) {
func (r *Relayer) NewPluginProvider(ctx context.Context, rargs relaytypes.RelayArgs, pargs relaytypes.PluginArgs) (relaytypes.PluginProvider, error) {
return nil, errors.New("plugin provider is not supported for solana")
}
7 changes: 4 additions & 3 deletions pkg/solana/report.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package solana

import (
"context"
"encoding/binary"
"fmt"
"math/big"
Expand All @@ -15,7 +16,7 @@ var _ median.ReportCodec = (*ReportCodec)(nil)

type ReportCodec struct{}

func (c ReportCodec) BuildReport(oo []median.ParsedAttributedObservation) (types.Report, error) {
func (c ReportCodec) BuildReport(ctx context.Context, oo []median.ParsedAttributedObservation) (types.Report, error) {
n := len(oo)
if n == 0 {
return nil, fmt.Errorf("cannot build report from empty attributed observations")
Expand Down Expand Up @@ -78,7 +79,7 @@ func (c ReportCodec) BuildReport(oo []median.ParsedAttributedObservation) (types
return types.Report(report), nil
}

func (c ReportCodec) MedianFromReport(report types.Report) (*big.Int, error) {
func (c ReportCodec) MedianFromReport(ctx context.Context, report types.Report) (*big.Int, error) {
// report should contain timestamp + observers + median + juels per eth
if len(report) != int(ReportLen) {
return nil, fmt.Errorf("report length mismatch: %d (received), %d (expected)", len(report), ReportLen)
Expand All @@ -91,7 +92,7 @@ func (c ReportCodec) MedianFromReport(report types.Report) (*big.Int, error) {
return bigbigendian.DeserializeSigned(int(MedianLen), median)
}

func (c ReportCodec) MaxReportLength(n int) (int, error) {
func (c ReportCodec) MaxReportLength(ctx context.Context, n int) (int, error) {
return int(ReportLen), nil
}

Expand Down

0 comments on commit b77da61

Please sign in to comment.