Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NONEVM-916] main LogPoller loop #974

Draft
wants to merge 24 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e95832b
logpoller db models
dhaidashenko Nov 8, 2024
8990bec
Replace solana types with custom to support db read/write
dhaidashenko Nov 13, 2024
36d20b6
remove redundant file
dhaidashenko Nov 13, 2024
e05cdd4
improve tests coverage & ensure subkey naming is consistent
dhaidashenko Nov 14, 2024
2b8d934
drop redundant constraint
dhaidashenko Nov 14, 2024
31d6be1
implement register unregister filter operations
dhaidashenko Nov 21, 2024
1ed6787
move filters management into separate struct & allow update of non pr…
dhaidashenko Nov 25, 2024
2f6e071
fix comments
dhaidashenko Nov 25, 2024
b8f17a9
MatchingFilters tests
dhaidashenko Nov 25, 2024
7a8a438
remove redundant time offset
dhaidashenko Nov 25, 2024
dadecca
switch to mapByID instead of slice
dhaidashenko Nov 25, 2024
9161021
linter fixes
dhaidashenko Nov 26, 2024
75d5f3f
rename filters
dhaidashenko Nov 26, 2024
a408c79
tests improvements
dhaidashenko Nov 26, 2024
5fae0d4
Add client & collector to LogPoller struct
reductionista Dec 10, 2024
4399fde
Re-generate RPClient & ReaderWriter mocks
reductionista Dec 11, 2024
825d56f
Update loader tests for interface
reductionista Dec 11, 2024
0590366
Add ILogpoller interface and call NewLogPoller() from NewChain()
reductionista Dec 12, 2024
73265d3
fix orm_test.go
reductionista Dec 12, 2024
9b85a0d
Fix lints in log_poller.go & types.go
reductionista Dec 12, 2024
794c695
Fix lints in log_poller.go
reductionista Dec 12, 2024
0c8284c
Add BlockTime & Program to Event data passed to Process()
reductionista Dec 17, 2024
e98d76b
WIP
reductionista Dec 16, 2024
71159c3
Use EventTypeProvider interface to represent a codec function for ret…
reductionista Dec 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions pkg/solana/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
mn "github.com/smartcontractkit/chainlink-solana/pkg/solana/client/multinode"
"github.com/smartcontractkit/chainlink-solana/pkg/solana/config"
"github.com/smartcontractkit/chainlink-solana/pkg/solana/internal"
"github.com/smartcontractkit/chainlink-solana/pkg/solana/logpoller"
"github.com/smartcontractkit/chainlink-solana/pkg/solana/monitor"
"github.com/smartcontractkit/chainlink-solana/pkg/solana/txm"
)
Expand All @@ -37,6 +38,7 @@ type Chain interface {

ID() string
Config() config.Config
LogPoller() logpoller.ILogPoller
TxManager() TxManager
// Reader returns a new Reader from the available list of nodes (if there are multiple, it will randomly select one)
Reader() (client.Reader, error)
Expand Down Expand Up @@ -89,6 +91,7 @@ type chain struct {
services.StateMachine
id string
cfg *config.TOMLConfig
lp logpoller.ILogPoller
txm *txm.Txm
balanceMonitor services.Service
lggr logger.Logger
Expand Down Expand Up @@ -235,6 +238,7 @@ func newChain(id string, cfg *config.TOMLConfig, ks core.Keystore, lggr logger.L
clientCache: map[string]*verifiedCachedClient{},
}

var lc internal.Loader[client.Reader] = utils.NewLazyLoad(func() (client.Reader, error) { return ch.getClient() })
var tc internal.Loader[client.ReaderWriter] = utils.NewLazyLoad(func() (client.ReaderWriter, error) { return ch.getClient() })
var bc internal.Loader[monitor.BalanceClient] = utils.NewLazyLoad(func() (monitor.BalanceClient, error) { return ch.getClient() })

Expand Down Expand Up @@ -303,10 +307,14 @@ func newChain(id string, cfg *config.TOMLConfig, ks core.Keystore, lggr logger.L
return result.Signature(), result.Error()
}

tc = internal.NewLoader[client.ReaderWriter](func() (client.ReaderWriter, error) { return ch.multiNode.SelectRPC() })
bc = internal.NewLoader[monitor.BalanceClient](func() (monitor.BalanceClient, error) { return ch.multiNode.SelectRPC() })
// TODO: Can we just remove these? They nullify the lazy loaders initialized earlier, don't they?
//lc = internal.NewLoader[client.Reader](func() (client.Reader, error) { return ch.multiNode.SelectRPC() })
//tc = internal.NewLoader[client.ReaderWriter](func() (client.ReaderWriter, error) { return ch.multiNode.SelectRPC() })
//bc = internal.NewLoader[monitor.BalanceClient](func() (monitor.BalanceClient, error) { return ch.multiNode.SelectRPC() })
}

// TODO: import typeProvider function from codec package and pass to constructor
ch.lp = logpoller.NewLogPoller(logger.Sugared(logger.Named(lggr, "LogPoller")), logpoller.NewORM(ch.ID(), ds, lggr), lc, nil)
ch.txm = txm.NewTxm(ch.id, tc, sendTx, cfg, ks, lggr)
ch.balanceMonitor = monitor.NewBalanceMonitor(ch.id, cfg, lggr, ks, bc)
return &ch, nil
Expand Down Expand Up @@ -396,6 +404,10 @@ func (c *chain) Config() config.Config {
return c.cfg
}

func (c *chain) LogPoller() logpoller.ILogPoller {
return c.lp
}

func (c *chain) TxManager() TxManager {
return c.txm
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/solana/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Reader interface {
GetTransaction(ctx context.Context, txHash solana.Signature, opts *rpc.GetTransactionOpts) (*rpc.GetTransactionResult, error)
GetBlocks(ctx context.Context, startSlot uint64, endSlot *uint64) (rpc.BlocksResult, error)
GetBlocksWithLimit(ctx context.Context, startSlot uint64, limit uint64) (*rpc.BlocksResult, error)
GetBlockWithOpts(context.Context, uint64, *rpc.GetBlockOpts) (*rpc.GetBlockResult, error)
GetBlock(ctx context.Context, slot uint64) (*rpc.GetBlockResult, error)
GetSignaturesForAddressWithOpts(ctx context.Context, addr solana.PublicKey, opts *rpc.GetSignaturesForAddressOpts) ([]*rpc.TransactionSignature, error)
}
Expand Down Expand Up @@ -331,6 +332,15 @@ func (c *Client) GetLatestBlock(ctx context.Context) (*rpc.GetBlockResult, error
return v.(*rpc.GetBlockResult), err
}

func (c *Client) GetBlockWithOpts(ctx context.Context, slot uint64, opts *rpc.GetBlockOpts) (*rpc.GetBlockResult, error) {
// get block based on slot with custom options set
done := c.latency("get_block_with_opts")
defer done()
ctx, cancel := context.WithTimeout(ctx, c.txTimeout)
defer cancel()
return c.rpc.GetBlockWithOpts(ctx, slot, opts)
}

func (c *Client) GetBlock(ctx context.Context, slot uint64) (*rpc.GetBlockResult, error) {
// get block based on slot
done := c.latency("get_block")
Expand Down
60 changes: 60 additions & 0 deletions pkg/solana/client/mocks/reader_writer.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions pkg/solana/codec/solana_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@ func TestNewIDLCodec_CircularDependency(t *testing.T) {
assert.ErrorIs(t, err, types.ErrInvalidConfig)
}

func TestNewIDLInstructionCodec(t *testing.T) {
t.Parallel()

var idl codec.IDL

}

func newTestIDLAndCodec(t *testing.T, account bool) (string, codec.IDL, types.RemoteCodec) {
t.Helper()

Expand Down
Loading
Loading