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

refactor(experimental): refactor the default subscriptions transport with pipe to make it more readable #1624

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
1 change: 1 addition & 0 deletions packages/library/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
],
"dependencies": {
"@solana/addresses": "workspace:*",
"@solana/functional": "workspace:*",
"@solana/instructions": "workspace:*",
"@solana/keys": "workspace:*",
"@solana/rpc-core": "workspace:*",
Expand Down
5 changes: 3 additions & 2 deletions packages/library/src/rpc-transport.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { pipe } from '@solana/functional';
import { createHttpTransport } from '@solana/rpc-transport';
import { IRpcTransport } from '@solana/rpc-transport/dist/types/transports/transport-types';

Expand All @@ -18,7 +19,7 @@ function normalizeHeaders<T extends Record<string, string>>(
}

export function createDefaultRpcTransport(config: Parameters<typeof createHttpTransport>[0]): IRpcTransport {
return getRpcTransportWithRequestCoalescing(
return pipe(
createHttpTransport({
...config,
headers: {
Expand All @@ -29,6 +30,6 @@ export function createDefaultRpcTransport(config: Parameters<typeof createHttpTr
} as { [overrideHeader: string]: string }),
},
}),
getSolanaRpcPayloadDeduplicationKey
transport => getRpcTransportWithRequestCoalescing(transport, getSolanaRpcPayloadDeduplicationKey)
);
}
31 changes: 19 additions & 12 deletions packages/library/src/rpc-websocket-transport.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { pipe } from '@solana/functional';
import { createWebSocketTransport } from '@solana/rpc-transport';
import { IRpcWebSocketTransport } from '@solana/rpc-transport/dist/types/transports/transport-types';

Expand All @@ -17,17 +18,23 @@ export function createDefaultRpcSubscriptionsTransport(
}
): IRpcWebSocketTransport {
const { getShard, intervalMs, ...rest } = config;
return getWebSocketTransportWithAutoping({
intervalMs: intervalMs ?? 5_000,
transport: getWebSocketTransportWithConnectionSharding({
getShard,
transport: createWebSocketTransport({
...rest,
sendBufferHighWatermark:
config.sendBufferHighWatermark ??
// Let 128KB of data into the WebSocket buffer before buffering it in the app.
131_072,
}),
return pipe(
createWebSocketTransport({
...rest,
sendBufferHighWatermark:
config.sendBufferHighWatermark ??
// Let 128KB of data into the WebSocket buffer before buffering it in the app.
131_072,
}),
});
transport =>
getWebSocketTransportWithAutoping({
intervalMs: intervalMs ?? 5_000,
transport,
}),
transport =>
getWebSocketTransportWithConnectionSharding({
getShard,
transport,
})
);
}
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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