Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
7 changes: 5 additions & 2 deletions controlplane/telemetry/internal/telemetry/submitter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,11 @@ func TestAgentTelemetry_Submitter(t *testing.T) {
mu.Lock()
defer mu.Unlock()

require.Equal(t, 3, calls, "expected 3 submission calls for 5500 samples with max 2560 per call")
assert.Equal(t, []int{sdktelemetry.MaxSamplesPerBatch, sdktelemetry.MaxSamplesPerBatch, 380}, samplesPerCall, "each call should contain at most 2560 samples")
require.Equal(t, 23, calls, "expected 23 submission calls for 5500 samples with max 245 per call")
for i := range 22 {
assert.Equal(t, sdktelemetry.MaxSamplesPerBatch, samplesPerCall[i])
}
assert.Equal(t, 110, samplesPerCall[22], "last call should contain 110 samples")
})

t.Run("negative_rtts_are_submitted_as_one", func(t *testing.T) {
Expand Down
39 changes: 39 additions & 0 deletions e2e/sdk_telemetry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ func TestE2E_SDK_Telemetry(t *testing.T) {
900000,
1000000,
}

t.Run("write second device latency samples", func(t *testing.T) {
ctx, cancel := context.WithDeadline(t.Context(), time.Now().Add(30*time.Second))
defer cancel()
Expand Down Expand Up @@ -309,6 +310,44 @@ func TestE2E_SDK_Telemetry(t *testing.T) {
require.Equal(t, uint32(len(combinedSamples)), deviceLatencySamples.NextSampleIndex)
require.Equal(t, combinedSamples, deviceLatencySamples.Samples)
})

t.Run("write largest possible batch of samples per transaction", func(t *testing.T) {
ctx, cancel := context.WithDeadline(t.Context(), time.Now().Add(30*time.Second))
defer cancel()
start := time.Now()
log.Info("==> Writing largest possible batch of samples per transaction")
sig, res, err := la2AgentTelemetryClient.WriteDeviceLatencySamples(ctx, telemetry.WriteDeviceLatencySamplesInstructionConfig{
AgentPK: la2DeviceAgentPrivateKey.PublicKey(),
OriginDevicePK: la2DevicePK,
TargetDevicePK: ny5DevicePK,
LinkPK: la2ToNy5LinkPK,
Epoch: epoch,
StartTimestampMicroseconds: secondStartTimestampMicroseconds,
Samples: make([]uint32, telemetry.MaxSamplesPerBatch),
})
require.NoError(t, err)
for _, msg := range res.Meta.LogMessages {
log.Debug("solana log message", "msg", msg)
}
require.Nil(t, res.Meta.Err, "transaction failed: %+v", res.Meta.Err)
log.Info("==> Wrote largest possible batch of samples per transaction", "sig", sig, "tx", res, "duration", time.Since(start))
})

t.Run("write largest possible batch of samples per transaction +1 (should fail)", func(t *testing.T) {
ctx, cancel := context.WithDeadline(t.Context(), time.Now().Add(30*time.Second))
defer cancel()
log.Info("==> Writing largest possible batch of samples per transaction +1 (should fail)")
_, _, err := la2AgentTelemetryClient.WriteDeviceLatencySamples(ctx, telemetry.WriteDeviceLatencySamplesInstructionConfig{
AgentPK: la2DeviceAgentPrivateKey.PublicKey(),
OriginDevicePK: la2DevicePK,
TargetDevicePK: ny5DevicePK,
LinkPK: la2ToNy5LinkPK,
Epoch: epoch,
StartTimestampMicroseconds: secondStartTimestampMicroseconds,
Samples: make([]uint32, telemetry.MaxSamplesPerBatch+1),
})
require.ErrorIs(t, err, telemetry.ErrSamplesBatchTooLarge)
})
}

func airdropAndWait(ctx context.Context, client *solanarpc.Client, pubkey solana.PublicKey, lamports uint64) error {
Expand Down
13 changes: 7 additions & 6 deletions smartcontract/sdk/go/telemetry/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ const (
// when the given PDA does not exist.
InstructionErrorAccountDoesNotExist = 1011

// SolanaMaxPermittedDataIncrease is the maximum number of bytes a program may add to an
// account during a single realloc.
// This is the samples batch size limit in bytes.
SolanaMaxPermittedDataIncrease = 10_240

// MaxSamplesPerBatch is the maximum number of samples that can be written in a single batch.
MaxSamplesPerBatch = SolanaMaxPermittedDataIncrease / 4
//
// 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

Comment thread
snormore marked this conversation as resolved.
// MaxSamples is the maximum number of samples that can be written to a single account.
MaxSamples = 35_000
Expand Down
Loading