feat: disable loader rate limiter for non solana endpoints (#13018)

This commit is contained in:
Justin Starry
2020-10-21 16:19:51 +08:00
committed by GitHub
parent e4231d1028
commit 8863b773c1
4 changed files with 14 additions and 18 deletions

View File

@@ -1446,6 +1446,7 @@ export type ConfirmedSignatureInfo = {
* A connection to a fullnode JSON RPC endpoint
*/
export class Connection {
_rpcEndpoint: string;
_rpcRequest: RpcRequest;
_rpcWebSocket: RpcWebSocketClient;
_rpcWebSocketConnected: boolean = false;
@@ -1487,6 +1488,8 @@ export class Connection {
* @param commitment optional default commitment level
*/
constructor(endpoint: string, commitment: ?Commitment) {
this._rpcEndpoint = endpoint;
let url = urlParse(endpoint);
const useHttps = url.protocol === 'https:';

View File

@@ -67,7 +67,7 @@ export class Loader {
// Fetch program account info to check if it has already been created
const programInfo = await connection.getAccountInfo(
program.publicKey,
'single',
'singleGossip',
);
let transaction: Transaction | null = null;
@@ -127,7 +127,7 @@ export class Loader {
transaction,
[payer, program],
{
commitment: 'single',
commitment: 'singleGossip',
skipPreflight: true,
},
);
@@ -169,22 +169,15 @@ export class Loader {
});
transactions.push(
sendAndConfirmTransaction(connection, transaction, [payer, program], {
commitment: 'single',
commitment: 'singleGossip',
skipPreflight: true,
}),
);
// Delay between sends in an attempt to reduce rate limit errors
const REQUESTS_PER_SECOND = 4;
await sleep(1000 / REQUESTS_PER_SECOND);
// Run up to 8 Loads in parallel to prevent too many parallel transactions from
// getting retried due to AccountInUse errors.
//
// TODO: 8 was selected empirically and should probably be revisited
if (transactions.length === 8) {
await Promise.all(transactions);
transactions = [];
if (connection._rpcEndpoint.includes('solana.com')) {
const REQUESTS_PER_SECOND = 4;
await sleep(1000 / REQUESTS_PER_SECOND);
}
offset += chunkSize;
@@ -217,7 +210,7 @@ export class Loader {
transaction,
[payer, program],
{
commitment: 'single',
commitment: 'singleGossip',
skipPreflight: true,
},
);