@solana/web3.js 1.70.1 → 1.70.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/web3.js",
3
- "version": "1.70.1",
3
+ "version": "1.70.2",
4
4
  "description": "Solana Javascript API",
5
5
  "keywords": [
6
6
  "api",
@@ -62,6 +62,7 @@
62
62
  "@noble/hashes": "^1.1.2",
63
63
  "@noble/secp256k1": "^1.6.3",
64
64
  "@solana/buffer-layout": "^4.0.0",
65
+ "agentkeepalive": "^4.2.1",
65
66
  "bigint-buffer": "^1.1.5",
66
67
  "bn.js": "^5.0.0",
67
68
  "borsh": "^0.7.0",
package/src/connection.ts CHANGED
@@ -1,9 +1,12 @@
1
+ import HttpKeepAliveAgent, {
2
+ HttpsAgent as HttpsKeepAliveAgent,
3
+ } from 'agentkeepalive';
1
4
  import bs58 from 'bs58';
2
5
  import {Buffer} from 'buffer';
3
6
  // @ts-ignore
4
7
  import fastStableStringify from 'fast-stable-stringify';
5
- import type {Agent as HttpAgent} from 'http';
6
- import {Agent as HttpsAgent} from 'https';
8
+ import type {Agent as NodeHttpAgent} from 'http';
9
+ import {Agent as NodeHttpsAgent} from 'https';
7
10
  import {
8
11
  type as pick,
9
12
  number,
@@ -27,7 +30,6 @@ import {Client as RpcWebSocketClient} from 'rpc-websockets';
27
30
  import RpcClient from 'jayson/lib/client/browser';
28
31
  import {JSONRPCError} from 'jayson';
29
32
 
30
- import {AgentManager} from './agent-manager';
31
33
  import {EpochSchedule} from './epoch-schedule';
32
34
  import {SendTransactionError, SolanaJSONRPCError} from './errors';
33
35
  import fetchImpl, {Response} from './fetch-impl';
@@ -1452,12 +1454,10 @@ function createRpcClient(
1452
1454
  customFetch?: FetchFn,
1453
1455
  fetchMiddleware?: FetchMiddleware,
1454
1456
  disableRetryOnRateLimit?: boolean,
1455
- httpAgent?: HttpAgent | HttpsAgent | false,
1457
+ httpAgent?: NodeHttpAgent | NodeHttpsAgent | false,
1456
1458
  ): RpcClient {
1457
1459
  const fetch = customFetch ? customFetch : fetchImpl;
1458
- let agentManager:
1459
- | {requestEnd(): void; requestStart(): HttpAgent | HttpsAgent}
1460
- | undefined;
1460
+ let agent: NodeHttpAgent | NodeHttpsAgent | undefined;
1461
1461
  if (process.env.BROWSER) {
1462
1462
  if (httpAgent != null) {
1463
1463
  console.warn(
@@ -1468,21 +1468,30 @@ function createRpcClient(
1468
1468
  } else {
1469
1469
  if (httpAgent == null) {
1470
1470
  if (process.env.NODE_ENV !== 'test') {
1471
- agentManager = new AgentManager(
1472
- url.startsWith('https:') /* useHttps */,
1473
- );
1471
+ const agentOptions = {
1472
+ // One second fewer than the Solana RPC's keepalive timeout.
1473
+ // Read more: https://github.com/solana-labs/solana/issues/27859#issuecomment-1340097889
1474
+ freeSocketTimeout: 19000,
1475
+ keepAlive: true,
1476
+ maxSockets: 25,
1477
+ };
1478
+ if (url.startsWith('https:')) {
1479
+ agent = new HttpsKeepAliveAgent(agentOptions);
1480
+ } else {
1481
+ agent = new HttpKeepAliveAgent(agentOptions);
1482
+ }
1474
1483
  }
1475
1484
  } else {
1476
1485
  if (httpAgent !== false) {
1477
1486
  const isHttps = url.startsWith('https:');
1478
- if (isHttps && !(httpAgent instanceof HttpsAgent)) {
1487
+ if (isHttps && !(httpAgent instanceof NodeHttpsAgent)) {
1479
1488
  throw new Error(
1480
1489
  'The endpoint `' +
1481
1490
  url +
1482
1491
  '` can only be paired with an `https.Agent`. You have, instead, supplied an ' +
1483
1492
  '`http.Agent` through `httpAgent`.',
1484
1493
  );
1485
- } else if (!isHttps && httpAgent instanceof HttpsAgent) {
1494
+ } else if (!isHttps && httpAgent instanceof NodeHttpsAgent) {
1486
1495
  throw new Error(
1487
1496
  'The endpoint `' +
1488
1497
  url +
@@ -1490,7 +1499,7 @@ function createRpcClient(
1490
1499
  '`https.Agent` through `httpAgent`.',
1491
1500
  );
1492
1501
  }
1493
- agentManager = {requestEnd() {}, requestStart: () => httpAgent};
1502
+ agent = httpAgent;
1494
1503
  }
1495
1504
  }
1496
1505
  }
@@ -1515,7 +1524,6 @@ function createRpcClient(
1515
1524
  }
1516
1525
 
1517
1526
  const clientBrowser = new RpcClient(async (request, callback) => {
1518
- const agent = agentManager ? agentManager.requestStart() : undefined;
1519
1527
  const options = {
1520
1528
  method: 'POST',
1521
1529
  body: request,
@@ -1565,8 +1573,6 @@ function createRpcClient(
1565
1573
  }
1566
1574
  } catch (err) {
1567
1575
  if (err instanceof Error) callback(err);
1568
- } finally {
1569
- agentManager && agentManager.requestEnd();
1570
1576
  }
1571
1577
  }, {});
1572
1578
 
@@ -2898,7 +2904,7 @@ export type ConnectionConfig = {
2898
2904
  * persistence). Set this to `false` to create a connection that uses no agent. This applies to
2899
2905
  * Node environments only.
2900
2906
  */
2901
- httpAgent?: HttpAgent | HttpsAgent | false;
2907
+ httpAgent?: NodeHttpAgent | NodeHttpsAgent | false;
2902
2908
  /** Optional commitment level */
2903
2909
  commitment?: Commitment;
2904
2910
  /** Optional endpoint URL to the fullnode JSON RPC PubSub WebSocket Endpoint */
package/src/publickey.ts CHANGED
@@ -109,14 +109,14 @@ export class PublicKey extends Struct {
109
109
  }
110
110
 
111
111
  /**
112
- * Return the byte array representation of the public key
112
+ * Return the byte array representation of the public key in big endian
113
113
  */
114
114
  toBytes(): Uint8Array {
115
115
  return this.toBuffer();
116
116
  }
117
117
 
118
118
  /**
119
- * Return the Buffer representation of the public key
119
+ * Return the Buffer representation of the public key in big endian
120
120
  */
121
121
  toBuffer(): Buffer {
122
122
  const b = this._bn.toArrayLike(Buffer);
@@ -1,44 +0,0 @@
1
- import http from 'http';
2
- import https from 'https';
3
-
4
- export const DESTROY_TIMEOUT_MS = 5000;
5
-
6
- export class AgentManager {
7
- _agent: http.Agent | https.Agent;
8
- _activeRequests = 0;
9
- _destroyTimeout: ReturnType<typeof setTimeout> | null = null;
10
- _useHttps: boolean;
11
-
12
- static _newAgent(useHttps: boolean): http.Agent | https.Agent {
13
- const options = {keepAlive: true, maxSockets: 25};
14
- if (useHttps) {
15
- return new https.Agent(options);
16
- } else {
17
- return new http.Agent(options);
18
- }
19
- }
20
-
21
- constructor(useHttps?: boolean) {
22
- this._useHttps = useHttps === true;
23
- this._agent = AgentManager._newAgent(this._useHttps);
24
- }
25
-
26
- requestStart(): http.Agent | https.Agent {
27
- this._activeRequests++;
28
- if (this._destroyTimeout !== null) {
29
- clearTimeout(this._destroyTimeout);
30
- this._destroyTimeout = null;
31
- }
32
- return this._agent;
33
- }
34
-
35
- requestEnd() {
36
- this._activeRequests--;
37
- if (this._activeRequests === 0 && this._destroyTimeout === null) {
38
- this._destroyTimeout = setTimeout(() => {
39
- this._agent.destroy();
40
- this._agent = AgentManager._newAgent(this._useHttps);
41
- }, DESTROY_TIMEOUT_MS);
42
- }
43
- }
44
- }