observer

package
v0.0.0-...-1329066 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 9, 2024 License: MIT Imports: 28 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// SolanaTransactionFee is the static fee per transaction, 5k lamports.
	SolanaTransactionFee = 5000

	// MicroLamportsPerLamport is the number of micro lamports in a lamport.
	MicroLamportsPerLamport = 1_000_000

	// SolanaDefaultComputeBudget is the default compute budget for a transaction.
	SolanaDefaultComputeBudget = 200_000

	// Solana uses micro lamports (0.000001 lamports) as the smallest unit of gas price.
	// The gas fee formula 'gasFee = gasPrice * gasLimit' won't fit Solana in the ZRC20 SOL contract.
	// We could use lamports as the unit of gas price and 10K CU as the smallest unit of compute units.
	// SolanaDefaultGasPrice10KCUs is the default gas price (in lamports) per 10K compute units.
	SolanaDefaultGasPrice10KCUs = 100

	// SolanaDefaultGasLimit is the default compute units (in 10K CU) for a transaction.
	SolanaDefaultGasLimit10KCU = 50
)
View Source
const (
	// MaxSignaturesPerTicker is the maximum number of signatures to process on a ticker
	MaxSignaturesPerTicker = 100
)

Variables

This section is empty.

Functions

func ParseGatewayInstruction

func ParseGatewayInstruction(
	txResult *rpc.GetTransactionResult,
	gatewayID solana.PublicKey,
	coinType coin.CoinType,
) (contracts.OutboundInstruction, error)

ParseGatewayInstruction parses the outbound instruction from tx result

Types

type Observer

type Observer struct {
	// base.Observer implements the base chain observer
	base.Observer
	// contains filtered or unexported fields
}

Observer is the observer for the Solana chain

func NewObserver

func NewObserver(
	chain chains.Chain,
	solClient interfaces.SolanaRPCClient,
	chainParams observertypes.ChainParams,
	zetacoreClient interfaces.ZetacoreClient,
	tss interfaces.TSSSigner,
	rpcAlertLatency int64,
	db *db.DB,
	logger base.Logger,
	ts *metrics.TelemetryServer,
) (*Observer, error)

NewObserver returns a new Solana chain observer

func (*Observer) BuildInboundVoteMsgFromEvent

func (ob *Observer) BuildInboundVoteMsgFromEvent(event *clienttypes.InboundEvent) *crosschaintypes.MsgVoteInbound

BuildInboundVoteMsgFromEvent builds a MsgVoteInbound from an inbound event

func (*Observer) CheckFinalizedTx

func (ob *Observer) CheckFinalizedTx(
	ctx context.Context,
	txHash string,
	nonce uint64,
	coinType coin.CoinType,
) (*rpc.GetTransactionResult, bool)

CheckFinalizedTx checks if a txHash is finalized for given nonce and coinType returns (tx result, true) if finalized or (nil, false) otherwise

func (*Observer) CreateMsgVoteOutbound

func (ob *Observer) CreateMsgVoteOutbound(
	cctxIndex string,
	outboundHash string,
	txResult *rpc.GetTransactionResult,
	valueReceived *big.Int,
	status chains.ReceiveStatus,
	nonce uint64,
	coinType coin.CoinType,
) *crosschaintypes.MsgVoteOutbound

CreateMsgVoteOutbound creates a vote outbound message for Solana chain

func (*Observer) FilterInboundEvents

func (ob *Observer) FilterInboundEvents(txResult *rpc.GetTransactionResult) ([]*clienttypes.InboundEvent, error)

FilterInboundEvents filters inbound events from a tx result. Note: for consistency with EVM chains, this method

  • takes at one event (the first) per token (SOL or SPL) per transaction.
  • takes at most two events (one SOL + one SPL) per transaction.
  • ignores exceeding events.

func (*Observer) FilterInboundEventsAndVote

func (ob *Observer) FilterInboundEventsAndVote(ctx context.Context, txResult *rpc.GetTransactionResult) error

FilterInboundEventsAndVote filters inbound events from a txResult and post a vote.

func (*Observer) GetTxResult

func (ob *Observer) GetTxResult(nonce uint64) *rpc.GetTransactionResult

GetTxResult returns the tx result for the given nonce

func (*Observer) IsEventProcessable

func (ob *Observer) IsEventProcessable(event clienttypes.InboundEvent) bool

IsEventProcessable checks if the inbound event is processable

func (*Observer) IsTxFinalized

func (ob *Observer) IsTxFinalized(nonce uint64) bool

IsTxFinalized returns true if there is a finalized tx for nonce

func (*Observer) LoadLastTxScanned

func (ob *Observer) LoadLastTxScanned() error

LoadLastTxScanned loads the last scanned tx from the database.

func (*Observer) ObserveInbound

func (ob *Observer) ObserveInbound(ctx context.Context) error

ObserveInbound observes the Solana chain for inbounds and post votes to zetacore.

func (*Observer) PostGasPrice

func (ob *Observer) PostGasPrice(ctx context.Context) error

PostGasPrice posts gas price to zetacore

func (*Observer) PostVoteOutbound

func (ob *Observer) PostVoteOutbound(
	ctx context.Context,
	cctxIndex string,
	outboundHash string,
	txResult *rpc.GetTransactionResult,
	valueReceived *big.Int,
	status chains.ReceiveStatus,
	nonce uint64,
	coinType coin.CoinType,
)

PostVoteOutbound posts vote to zetacore for the finalized outbound

func (*Observer) ProcessInboundTrackers

func (ob *Observer) ProcessInboundTrackers(ctx context.Context) error

ProcessInboundTrackers processes inbound trackers

func (*Observer) ProcessOutboundTrackers

func (ob *Observer) ProcessOutboundTrackers(ctx context.Context) error

ProcessOutboundTrackers processes Solana outbound trackers

func (*Observer) SetTxResult

func (ob *Observer) SetTxResult(nonce uint64, result *rpc.GetTransactionResult)

SetTxResult sets the tx result for the given nonce

func (*Observer) SolClient

func (ob *Observer) SolClient() interfaces.SolanaRPCClient

SolClient returns the solana rpc client

func (*Observer) Start

func (ob *Observer) Start(ctx context.Context)

Start starts the Go routine processes to observe the Solana chain

func (*Observer) VoteOutboundIfConfirmed

func (ob *Observer) VoteOutboundIfConfirmed(ctx context.Context, cctx *crosschaintypes.CrossChainTx) (bool, error)

VoteOutboundIfConfirmed checks outbound status and returns (continueKeysign, error)

func (*Observer) WatchGasPrice

func (ob *Observer) WatchGasPrice(ctx context.Context) error

WatchGasPrice watches the gas price of the chain and posts it to the zetacore

func (*Observer) WatchInbound

func (ob *Observer) WatchInbound(ctx context.Context) error

WatchInbound watches Solana chain for inbounds on a ticker.

func (*Observer) WatchInboundTracker

func (ob *Observer) WatchInboundTracker(ctx context.Context) error

WatchInboundTracker watches zetacore for Solana inbound trackers

func (*Observer) WatchOutbound

func (ob *Observer) WatchOutbound(ctx context.Context) error

WatchOutbound watches solana chain for outgoing txs status TODO(revamp): move ticker function to ticker file

func (*Observer) WithSolClient

func (ob *Observer) WithSolClient(client interfaces.SolanaRPCClient)

WithSolClient attaches a new solana rpc client to the observer

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL