telemetry

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2025 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Represents the initialize device latency samples instruction
	InitializeDeviceLatencySamplesInstructionIndex TelemetryInstructionType = 0
	// Represents the write device latency samples instruction
	WriteDeviceLatencySamplesInstructionIndex TelemetryInstructionType = 1
	// Represents the initialize internet latency samples instruction
	InitializeInternetLatencySamplesInstructionIndex TelemetryInstructionType = 2
	// Represents the write internet latency samples instruction
	WriteInternetLatencySamplesInstructionIndex TelemetryInstructionType = 3

	// InstructionErrorAccountSamplesAccountFull is the error code that the telemetry program returns
	// when the given PDA has reached maximum capacity for samples.
	InstructionErrorAccountSamplesAccountFull = 1006

	// InstructionErrorAccountDoesNotExist is the error code that the telemetry program returns
	// when the given PDA does not exist.
	InstructionErrorAccountDoesNotExist = 1011

	// MaxSamplesPerBatch is the maximum number of samples that can be written in a single batch.
	//
	// Messages transmitted to Solana validators must not exceed the IPv6 MTU size to ensure fast
	// and reliable network transmission of cluster info over UDP. Solana's networking stack uses a
	// conservative MTU size of 1280 bytes which, after accounting for headers, leaves 1232 bytes
	// for packet data like serialized transactions.
	// https://docs.anza.xyz/proposals/versioned-transactions#problem
	MaxSamplesPerBatch = 245 // 980 bytes

	// MaxDeviceLatencySamplesPerAccount is the maximum number of samples that can be written to a single device latency samples account.
	// This provides space for just over 12 samples per minute, or 1 sample every 5 seconds.
	MaxDeviceLatencySamplesPerAccount = 35_000

	// MaxInternetLatencySamplesPerAccount is the maximum number of samples that can be written to an internet latency samples account.
	// This provides space for just over 1 sample per minute.
	MaxInternetLatencySamplesPerAccount = 3000

	// MaxInternetLatencyDataProviderNameLength is the maximum length of a data provider name.
	MaxInternetLatencyDataProviderNameLength = 32
)
View Source
const (
	// Instruction index for initializing device latency samples
	INITIALIZE_DEVICE_LATENCY_SAMPLES_INSTRUCTION_INDEX = 0
	// Instruction index for writing device latency samples
	WRITE_DEVICE_LATENCY_SAMPLES_INSTRUCTION_INDEX = 1
)

Instruction discriminators for telemetry program

View Source
const (
	// Pefix for all telemetry PDAs
	TelemetrySeedPrefix = "telemetry"
	// Seed for device latency samples PDAs
	DeviceLatencySamplesSeed = "dzlatency"
	// Seed for internet latency samples PDAs
	InternetLatencySamplesSeed = "inetlatency"
)

PDA seeds for telemetry program

Variables

View Source
var (
	ErrAccountNotFound      = errors.New("account not found")
	ErrSamplesBatchTooLarge = fmt.Errorf("samples batch too large, must not exceed %d samples", MaxSamplesPerBatch)
	ErrSamplesAccountFull   = errors.New("samples account is full")
)
View Source
var (
	// ErrNoPrivateKey is returned when a transaction signing operation is attempted without a configured private key.
	ErrNoPrivateKey = errors.New("no private key configured")

	// ErrNoProgramID is returned when a transaction signing operation is attempted without a configured program ID.
	ErrNoProgramID = errors.New("no program ID configured")
)

Functions

func BuildInitializeDeviceLatencySamplesInstruction

func BuildInitializeDeviceLatencySamplesInstruction(
	programID solana.PublicKey,
	config InitializeDeviceLatencySamplesInstructionConfig,
) (solana.Instruction, error)

func BuildInitializeInternetLatencySamplesInstruction

func BuildInitializeInternetLatencySamplesInstruction(
	programID solana.PublicKey,
	signerPK solana.PublicKey,
	config InitializeInternetLatencySamplesInstructionConfig,
) (solana.Instruction, error)

func BuildWriteDeviceLatencySamplesInstruction

func BuildWriteDeviceLatencySamplesInstruction(
	programID solana.PublicKey,
	config WriteDeviceLatencySamplesInstructionConfig,
) (solana.Instruction, error)

Builds the instruction for writing device latency samples.

func BuildWriteInternetLatencySamplesInstruction

func BuildWriteInternetLatencySamplesInstruction(
	programID solana.PublicKey,
	signerPK solana.PublicKey,
	config WriteInternetLatencySamplesInstructionConfig,
) (solana.Instruction, error)

Builds the instruction for writing internet latency samples.

func DeriveDeviceLatencySamplesPDA

func DeriveDeviceLatencySamplesPDA(
	programID solana.PublicKey,
	originDevicePK solana.PublicKey,
	targetDevicePK solana.PublicKey,
	linkPK solana.PublicKey,
	epoch uint64,
) (solana.PublicKey, uint8, error)

Derives the PDA for device latency samples account

func DeriveInternetLatencySamplesPDA

func DeriveInternetLatencySamplesPDA(
	programID solana.PublicKey,
	collectorOraclePK solana.PublicKey,
	dataProviderName string,
	originLocationPK solana.PublicKey,
	targetLocationPK solana.PublicKey,
	epoch uint64,
) (solana.PublicKey, uint8, error)

Derives the PDA for internet latency samples account

func NewExecutor

func NewExecutor(log *slog.Logger, rpc RPCClient, signer *solana.PrivateKey, programID solana.PublicKey, opts ...ExecutorOption) *executor

Types

type AccountType

type AccountType uint8
const (
	AccountTypeDeviceLatencySamplesV0 AccountType = iota + 1
	AccountTypeInternetLatencySamplesV0
	AccountTypeDeviceLatencySamples
	AccountTypeInternetLatencySamples
)

type Client

type Client struct {
	// contains filtered or unexported fields
}

func New

func New(log *slog.Logger, rpc RPCClient, signer *solana.PrivateKey, programID solana.PublicKey) *Client

func (*Client) GetDeviceLatencySamples

func (c *Client) GetDeviceLatencySamples(
	ctx context.Context,
	originDevicePK solana.PublicKey,
	targetDevicePK solana.PublicKey,
	linkPK solana.PublicKey,
	epoch uint64,
) (*DeviceLatencySamples, error)

func (*Client) GetInternetLatencySamples

func (c *Client) GetInternetLatencySamples(
	ctx context.Context,
	dataProviderName string,
	originLocationPK solana.PublicKey,
	targetLocationPK solana.PublicKey,
	agentPK solana.PublicKey,
	epoch uint64,
) (*InternetLatencySamples, error)

func (*Client) ProgramID

func (c *Client) ProgramID() solana.PublicKey

func (*Client) Signer

func (c *Client) Signer() *solana.PrivateKey

type DeviceLatencySamples

type DeviceLatencySamples struct {
	DeviceLatencySamplesHeader
	Samples []uint32 // 4 + n*4 (RTT values in microseconds)
}

func (*DeviceLatencySamples) Deserialize

func (d *DeviceLatencySamples) Deserialize(data []byte) error

func (*DeviceLatencySamples) Serialize

func (d *DeviceLatencySamples) Serialize(w io.Writer) error

type DeviceLatencySamplesHeader

type DeviceLatencySamplesHeader struct {
	// Used to distinguish this account type during deserialization
	AccountType AccountType // 1

	// Epoch number in which samples were collected
	Epoch uint64 // 8

	// Agent authorized to write RTT samples (must match signer)
	OriginDeviceAgentPK solana.PublicKey // 32

	// Device initiating sampling
	OriginDevicePK solana.PublicKey // 32

	// Destination device in RTT path
	TargetDevicePK solana.PublicKey // 32

	// Cached location of origin device for query/UI optimization
	OriginDeviceLocationPK solana.PublicKey // 32

	// Cached location of target device
	TargetDeviceLocationPK solana.PublicKey // 32

	// Link over which the RTT samples were taken
	LinkPK solana.PublicKey // 32

	// Sampling interval configured by the agent (in microseconds)
	SamplingIntervalMicroseconds uint64 // 8

	// Timestamp of the first written sample (µs since UNIX epoch).
	// Set on the first write, remains unchanged after.
	StartTimestampMicroseconds uint64 // 8

	// Tracks how many samples have been appended.
	NextSampleIndex uint32 // 4

	// Reserved for future use.
	Unused [128]uint8 // 128
}

type DeviceLatencySamplesHeaderOnlyAccountType

type DeviceLatencySamplesHeaderOnlyAccountType struct {
	AccountType AccountType // 1
}

func (*DeviceLatencySamplesHeaderOnlyAccountType) Deserialize

func (d *DeviceLatencySamplesHeaderOnlyAccountType) Deserialize(data []byte) error

func (*DeviceLatencySamplesHeaderOnlyAccountType) Serialize

type DeviceLatencySamplesHeaderV0

type DeviceLatencySamplesHeaderV0 struct {
	// Used to distinguish this account type during deserialization
	AccountType AccountType // 1

	// Required for recreating the PDA (seed authority)
	BumpSeed uint8 // 1

	// Epoch number in which samples were collected
	Epoch uint64 // 8

	// Agent authorized to write RTT samples (must match signer)
	OriginDeviceAgentPK solana.PublicKey // 32

	// Device initiating sampling
	OriginDevicePK solana.PublicKey // 32

	// Destination device in RTT path
	TargetDevicePK solana.PublicKey // 32

	// Cached location of origin device for query/UI optimization
	OriginDeviceLocationPK solana.PublicKey // 32

	// Cached location of target device
	TargetDeviceLocationPK solana.PublicKey // 32

	// Link over which the RTT samples were taken
	LinkPK solana.PublicKey // 32

	// Sampling interval configured by the agent (in microseconds)
	SamplingIntervalMicroseconds uint64 // 8

	// Timestamp of the first written sample (µs since UNIX epoch).
	// Set on the first write, remains unchanged after.
	StartTimestampMicroseconds uint64 // 8

	// Tracks how many samples have been appended.
	NextSampleIndex uint32 // 4

	// Reserved for future use.
	Unused [128]uint8 // 128
}

type DeviceLatencySamplesV0

type DeviceLatencySamplesV0 struct {
	DeviceLatencySamplesHeaderV0
	Samples []uint32 // 4 + n*4 (RTT values in microseconds)
}

func (*DeviceLatencySamplesV0) Deserialize

func (d *DeviceLatencySamplesV0) Deserialize(data []byte) error

func (*DeviceLatencySamplesV0) Serialize

func (d *DeviceLatencySamplesV0) Serialize(w io.Writer) error

func (*DeviceLatencySamplesV0) ToV1

type ExecuteTransactionOptions

type ExecuteTransactionOptions struct {
	SkipPreflight bool
}

type ExecutorOption

type ExecutorOption func(*executor)

func WithWaitForVisibleTimeout

func WithWaitForVisibleTimeout(timeout time.Duration) ExecutorOption

type InitializeDeviceLatencySamplesInstructionConfig

type InitializeDeviceLatencySamplesInstructionConfig struct {
	AgentPK                      solana.PublicKey
	OriginDevicePK               solana.PublicKey
	TargetDevicePK               solana.PublicKey
	LinkPK                       solana.PublicKey
	Epoch                        *uint64
	SamplingIntervalMicroseconds uint64
}

func (*InitializeDeviceLatencySamplesInstructionConfig) Validate

type InitializeInternetLatencySamplesInstructionConfig

type InitializeInternetLatencySamplesInstructionConfig struct {
	OriginExchangePK             solana.PublicKey
	TargetExchangePK             solana.PublicKey
	DataProviderName             string
	Epoch                        uint64
	SamplingIntervalMicroseconds uint64
}

func (*InitializeInternetLatencySamplesInstructionConfig) Validate

type InternetLatencySamples

type InternetLatencySamples struct {
	InternetLatencySamplesHeader
	Samples []uint32 // 4 + n*4 (RTT values in microseconds)
}

func (*InternetLatencySamples) Deserialize

func (d *InternetLatencySamples) Deserialize(data []byte) error

func (*InternetLatencySamples) Serialize

func (d *InternetLatencySamples) Serialize(w io.Writer) error

type InternetLatencySamplesHeader

type InternetLatencySamplesHeader struct {
	// AccountType is used to distinguish this account type during deserialization.
	AccountType AccountType // 1

	// Epoch is the epoch number in which samples were collected.
	Epoch uint64 // 8

	// DataProviderName is the name of the data provider.
	DataProviderName string // 4 + len

	// OracleAgentPK authorized to write latency samples (must match signer)
	OracleAgentPK solana.PublicKey // 32

	// OriginExchangePK is the dz exchange of the origin for sample collection.
	OriginExchangePK solana.PublicKey // 32

	// TargetExchangePK is the dz exchange of the target for sample collection.
	TargetExchangePK solana.PublicKey // 32

	// SamplingIntervalMicroseconds is the interval between samples (in microseconds).
	SamplingIntervalMicroseconds uint64 // 8

	// StartTimestampMicroseconds is the timestamp of the first written sample (µs since UNIX epoch).
	// Set on the first write, remains unchanged after.
	StartTimestampMicroseconds uint64 // 8

	// NextSampleIndex tracks how many samples have been appended.
	NextSampleIndex uint32 // 4

	// Unused is reserved for future use.
	Unused [128]uint8 // 128
}

type RPCClient

type RPCClient interface {
	SendTransaction(context.Context, *solana.Transaction) (solana.Signature, error)
	SendTransactionWithOpts(context.Context, *solana.Transaction, solanarpc.TransactionOpts) (solana.Signature, error)
	GetLatestBlockhash(context.Context, solanarpc.CommitmentType) (*solanarpc.GetLatestBlockhashResult, error)
	GetSignatureStatuses(ctx context.Context, searchTransactionHistory bool, transactionSignatures ...solana.Signature) (out *solanarpc.GetSignatureStatusesResult, err error)
	GetTransaction(ctx context.Context, txSig solana.Signature, opts *solanarpc.GetTransactionOpts) (*solanarpc.GetTransactionResult, error)
	GetAccountInfo(ctx context.Context, account solana.PublicKey) (out *solanarpc.GetAccountInfoResult, err error)
}

RPCClient is an interface for interacting with the Solana RPC server.

type TelemetryInstructionType

type TelemetryInstructionType uint8

Represents the type of telemetry instruction

type WriteDeviceLatencySamplesInstructionConfig

type WriteDeviceLatencySamplesInstructionConfig struct {
	AgentPK                    solana.PublicKey
	OriginDevicePK             solana.PublicKey
	TargetDevicePK             solana.PublicKey
	LinkPK                     solana.PublicKey
	Epoch                      *uint64
	StartTimestampMicroseconds uint64
	Samples                    []uint32
}

func (*WriteDeviceLatencySamplesInstructionConfig) Validate

type WriteInternetLatencySamplesInstructionConfig

type WriteInternetLatencySamplesInstructionConfig struct {
	OriginExchangePK           solana.PublicKey
	TargetExchangePK           solana.PublicKey
	DataProviderName           string
	Epoch                      uint64
	StartTimestampMicroseconds uint64
	Samples                    []uint32
}

func (*WriteInternetLatencySamplesInstructionConfig) Validate

Jump to

Keyboard shortcuts

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