From a454b321de96e38810eeda366a2560e2b28be3cb Mon Sep 17 00:00:00 2001 From: Domino Valdano <2644901+reductionista@users.noreply.github.com> Date: Tue, 5 Nov 2024 13:35:04 -0800 Subject: [PATCH] Add DataSource to ChainOpts and pass down to tx mgr from NewChain --- pkg/solana/chain.go | 12 ++++++++---- pkg/solana/txm/txm.go | 5 ++++- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/pkg/solana/chain.go b/pkg/solana/chain.go index c47e1cf1b..dd599ef56 100644 --- a/pkg/solana/chain.go +++ b/pkg/solana/chain.go @@ -18,8 +18,8 @@ import ( "github.com/smartcontractkit/chainlink-common/pkg/chains" "github.com/smartcontractkit/chainlink-common/pkg/logger" - "github.com/smartcontractkit/chainlink-common/pkg/loop" "github.com/smartcontractkit/chainlink-common/pkg/services" + "github.com/smartcontractkit/chainlink-common/pkg/sqlutil" "github.com/smartcontractkit/chainlink-common/pkg/types" "github.com/smartcontractkit/chainlink-common/pkg/types/core" "github.com/smartcontractkit/chainlink-common/pkg/utils" @@ -49,6 +49,7 @@ const DefaultRequestTimeout = 30 * time.Second type ChainOpts struct { Logger logger.Logger KeyStore core.Keystore + DS sqlutil.DataSource } func (o *ChainOpts) Validate() (err error) { @@ -61,6 +62,9 @@ func (o *ChainOpts) Validate() (err error) { if o.KeyStore == nil { err = errors.Join(err, required("KeyStore")) } + if o.DS == nil { + err = errors.Join(err, required("DataSource")) + } return } @@ -72,7 +76,7 @@ func NewChain(cfg *config.TOMLConfig, opts ChainOpts) (Chain, error) { if !cfg.IsEnabled() { return nil, fmt.Errorf("cannot create new chain with ID %s: chain is disabled", *cfg.ChainID) } - c, err := newChain(*cfg.ChainID, cfg, opts.KeyStore, opts.Logger) + c, err := newChain(*cfg.ChainID, cfg, opts.KeyStore, opts.Logger, opts.DS) if err != nil { return nil, err } @@ -222,7 +226,7 @@ func (v *verifiedCachedClient) GetAccountInfoWithOpts(ctx context.Context, addr return v.ReaderWriter.GetAccountInfoWithOpts(ctx, addr, opts) } -func newChain(id string, cfg *config.TOMLConfig, ks loop.Keystore, lggr logger.Logger) (*chain, error) { +func newChain(id string, cfg *config.TOMLConfig, ks core.Keystore, lggr logger.Logger, ds sqlutil.DataSource) (*chain, error) { lggr = logger.With(lggr, "chainID", id, "chain", "solana") var ch = chain{ id: id, @@ -306,7 +310,7 @@ func newChain(id string, cfg *config.TOMLConfig, ks loop.Keystore, lggr logger.L bc = internal.NewLoader[monitor.BalanceClient](func() (monitor.BalanceClient, error) { return ch.multiNode.SelectRPC() }) } - ch.txm = txm.NewTxm(ch.id, tc, sendTx, cfg, ks, lggr) + ch.txm = txm.NewTxm(ch.id, tc, sendTx, cfg, ks, lggr, ds) ch.balanceMonitor = monitor.NewBalanceMonitor(ch.id, cfg, lggr, ks, bc) return &ch, nil } diff --git a/pkg/solana/txm/txm.go b/pkg/solana/txm/txm.go index 7cd09cf5e..acb2fdc0c 100644 --- a/pkg/solana/txm/txm.go +++ b/pkg/solana/txm/txm.go @@ -13,6 +13,7 @@ import ( solanaGo "github.com/gagliardetto/solana-go" "github.com/gagliardetto/solana-go/rpc" "github.com/google/uuid" + "github.com/smartcontractkit/chainlink-common/pkg/sqlutil" "github.com/smartcontractkit/chainlink-common/pkg/logger" "github.com/smartcontractkit/chainlink-common/pkg/loop" @@ -55,6 +56,7 @@ type Txm struct { cfg config.Config txs PendingTxContext ks SimpleKeystore + ds sqlutil.DataSource client internal.Loader[client.ReaderWriter] fee fees.Estimator // sendTx is an override for sending transactions rather than using a single client @@ -85,7 +87,7 @@ type pendingTx struct { // NewTxm creates a txm. Uses simulation so should only be used to send txes to trusted contracts i.e. OCR. func NewTxm(chainID string, client internal.Loader[client.ReaderWriter], sendTx func(ctx context.Context, tx *solanaGo.Transaction) (solanaGo.Signature, error), - cfg config.Config, ks SimpleKeystore, lggr logger.Logger) *Txm { + cfg config.Config, ks SimpleKeystore, lggr logger.Logger, ds sqlutil.DataSource) *Txm { if sendTx == nil { // default sendTx using a single RPC sendTx = func(ctx context.Context, tx *solanaGo.Transaction) (solanaGo.Signature, error) { @@ -105,6 +107,7 @@ func NewTxm(chainID string, client internal.Loader[client.ReaderWriter], cfg: cfg, txs: newPendingTxContextWithProm(chainID), ks: ks, + ds: ds, client: client, sendTx: sendTx, }