Skip to content

Commit

Permalink
refactor(solana): remove dummy ws connection in SolanaClient
Browse files Browse the repository at this point in the history
  • Loading branch information
swimthor committed Oct 9, 2022
1 parent b00b957 commit 2bd05a3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 57 deletions.
4 changes: 2 additions & 2 deletions apps/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@
"@swim-io/evm": "^0.36.0",
"@swim-io/evm-contracts": "^0.36.0",
"@swim-io/pool-math": "^0.36.0",
"@swim-io/solana": "^0.36.0",
"@swim-io/solana": "workspace:^",
"@swim-io/solana-contracts": "^0.36.0",
"@swim-io/token-projects": "^0.36.0",
"@swim-io/utils": "^0.36.0",
"@swim-io/wormhole": "^0.36.0",
"@swim-io/wormhole": "workspace:^",
"bn.js": "^5.2.1",
"classnames": "^2.3.1",
"decimal.js": "^10.3.1",
Expand Down
15 changes: 0 additions & 15 deletions packages/solana/src/SolanaClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ export class SolanaClient implements Client<SolanaWalletAdapter> {
private readonly parsedTxCache: Map<string, ParsedTransactionWithMeta>;
private rpcIndex: number;
private readonly endpoints: readonly string[];
// TODO: Check if this is still necessary.
// The websocket library solana/web3.js closes its websocket connection when the subscription list
// is empty after opening its first time, preventing subsequent subscriptions from receiving responses.
// This is a hack to prevent the list from ever getting empty
private dummySubscriptionId?: number;

public constructor(
chainConfig: SolanaChainConfig,
Expand Down Expand Up @@ -490,22 +485,12 @@ export class SolanaClient implements Client<SolanaWalletAdapter> {
// and it is not being called in the constructor (when this.rawConnection is still undefined)
return;
}
if (this.dummySubscriptionId !== undefined) {
// Remove old dummy subscription if it has been initialized.
this.connection
.removeAccountChangeListener(this.dummySubscriptionId)
.catch(console.error);
}
this.rpcIndex = (this.rpcIndex + 1) % this.endpoints.length;
this.connection = new CustomConnection(this.endpoints[this.rpcIndex], {
commitment: DEFAULT_COMMITMENT_LEVEL,
confirmTransactionInitialTimeout: 60 * 1000,
disableRetryOnRateLimit: true,
});
this.dummySubscriptionId = this.connection.onAccountChange(
Keypair.generate().publicKey,
() => {},
);
}

private async callWithRetry<T>(
Expand Down
43 changes: 3 additions & 40 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7134,27 +7134,6 @@ __metadata:
languageName: node
linkType: hard

"@swim-io/solana@npm:^0.36.0":
version: 0.36.0
resolution: "@swim-io/solana@npm:0.36.0"
dependencies:
"@certusone/wormhole-sdk": ^0.6.2
"@ledgerhq/hw-transport": ^6.27.1
"@ledgerhq/hw-transport-webusb": ^6.0.2
"@project-serum/borsh": ^0.2.5
"@project-serum/sol-wallet-adapter": 0.2.2
"@solana/spl-token": ^0.3.4
"@solana/web3.js": ^1.62.0
"@swim-io/core": ^0.36.0
"@swim-io/token-projects": ^0.36.0
"@swim-io/utils": ^0.36.0
bn.js: ^5.2.1
decimal.js: ^10.3.1
ethers: ^5.7.0
checksum: b6511fddbd5d776f234cb6d7e1debcfb18ce21ad45e372d9ce6eb33e5568491943c0d9ba5777ddc5ad8e47aa2034d44aaf246a3890d72cf79de96013901c362b
languageName: node
linkType: hard

"@swim-io/solana@workspace:^, @swim-io/solana@workspace:packages/solana":
version: 0.0.0-use.local
resolution: "@swim-io/solana@workspace:packages/solana"
Expand Down Expand Up @@ -7309,12 +7288,12 @@ __metadata:
"@swim-io/evm": ^0.36.0
"@swim-io/evm-contracts": ^0.36.0
"@swim-io/pool-math": ^0.36.0
"@swim-io/solana": ^0.36.0
"@swim-io/solana": "workspace:^"
"@swim-io/solana-contracts": ^0.36.0
"@swim-io/token-projects": ^0.36.0
"@swim-io/tsconfig": "workspace:^"
"@swim-io/utils": ^0.36.0
"@swim-io/wormhole": ^0.36.0
"@swim-io/wormhole": "workspace:^"
"@testing-library/jest-dom": ^5.16.4
"@testing-library/react": ^12.1.5
"@testing-library/react-hooks": ^7.0.2
Expand Down Expand Up @@ -7412,23 +7391,7 @@ __metadata:
languageName: unknown
linkType: soft

"@swim-io/wormhole@npm:^0.36.0":
version: 0.36.0
resolution: "@swim-io/wormhole@npm:0.36.0"
dependencies:
"@certusone/wormhole-sdk": ^0.6.0
"@solana/spl-token": ^0.3.4
"@solana/web3.js": ^1.62.0
"@swim-io/core": ^0.36.0
"@swim-io/solana": ^0.36.0
"@swim-io/utils": ^0.36.0
ethers: ^5.6.9
grpc-web: ^1.3.1
checksum: d39146491a0d9ce64e88554c4f7bd4328bc2fded3613478dc1d4d6b5a04e02f713ec1abef9b7c838a7518540f32c2084703fddb17e64b69d597cc2fc70be35e2
languageName: node
linkType: hard

"@swim-io/wormhole@workspace:packages/wormhole":
"@swim-io/wormhole@workspace:^, @swim-io/wormhole@workspace:packages/wormhole":
version: 0.0.0-use.local
resolution: "@swim-io/wormhole@workspace:packages/wormhole"
dependencies:
Expand Down

0 comments on commit 2bd05a3

Please sign in to comment.