Skip to content

Commit

Permalink
wip: slot height tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
aalu1418 committed Apr 16, 2024
1 parent 7b14e1a commit 65f8a77
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/monitoring/chain_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type ChainReader interface {
GetBalance(ctx context.Context, account solana.PublicKey, commitment rpc.CommitmentType) (out *rpc.GetBalanceResult, err error)
GetSignaturesForAddressWithOpts(ctx context.Context, account solana.PublicKey, opts *rpc.GetSignaturesForAddressOpts) (out []*rpc.TransactionSignature, err error)
GetTransaction(ctx context.Context, txSig solana.Signature, opts *rpc.GetTransactionOpts) (out *rpc.GetTransactionResult, err error)
GetSlot(ctx context.Context) (slot uint64, err error)
}

func NewChainReader(client *rpc.Client) ChainReader {
Expand Down Expand Up @@ -50,3 +51,7 @@ func (c *chainReader) GetSignaturesForAddressWithOpts(ctx context.Context, accou
func (c *chainReader) GetTransaction(ctx context.Context, txSig solana.Signature, opts *rpc.GetTransactionOpts) (out *rpc.GetTransactionResult, err error) {
return c.client.GetTransaction(ctx, txSig, opts)
}

func (c *chainReader) GetSlot(ctx context.Context) (uint64, error) {
return c.client.GetSlot(ctx, rpc.CommitmentProcessed) // get latest height
}
24 changes: 24 additions & 0 deletions pkg/monitoring/mocks/ChainReader.go

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

43 changes: 43 additions & 0 deletions pkg/monitoring/source_slotheight.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package monitoring

import (
"context"

commonMonitoring "github.com/smartcontractkit/chainlink-common/pkg/monitoring"

"github.com/smartcontractkit/chainlink-solana/pkg/monitoring/types"
)

func NewSlotHeightSourceFactory(
client ChainReader,
log commonMonitoring.Logger,
) commonMonitoring.NetworkSourceFactory {
return &slotHeightSourceFactory{
client,
log,
}
}

type slotHeightSourceFactory struct {
client ChainReader
log commonMonitoring.Logger
}

func (s *slotHeightSourceFactory) NewSource(
_ commonMonitoring.ChainConfig,
_ []commonMonitoring.NodeConfig,
) (commonMonitoring.Source, error) {
return &slotHeightSource{s.client}, nil
}

func (s *slotHeightSourceFactory) GetType() string {
return types.SlotHeightType
}

type slotHeightSource struct {
client ChainReader
}

func (t *slotHeightSource) Fetch(ctx context.Context) (interface{}, error) {
return t.client.GetSlot(ctx) // TODO: wrap the type to make it clear which type it is?
}
5 changes: 5 additions & 0 deletions pkg/monitoring/types/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package types

const (
SlotHeightType = "slot_height"
)

0 comments on commit 65f8a77

Please sign in to comment.