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 * A connection to a fullnode JSON RPC endpoint
*/ */
export class Connection { export class Connection {
_rpcEndpoint: string;
_rpcRequest: RpcRequest; _rpcRequest: RpcRequest;
_rpcWebSocket: RpcWebSocketClient; _rpcWebSocket: RpcWebSocketClient;
_rpcWebSocketConnected: boolean = false; _rpcWebSocketConnected: boolean = false;
@ -1487,6 +1488,8 @@ export class Connection {
* @param commitment optional default commitment level * @param commitment optional default commitment level
*/ */
constructor(endpoint: string, commitment: ?Commitment) { constructor(endpoint: string, commitment: ?Commitment) {
this._rpcEndpoint = endpoint;
let url = urlParse(endpoint); let url = urlParse(endpoint);
const useHttps = url.protocol === 'https:'; 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 // Fetch program account info to check if it has already been created
const programInfo = await connection.getAccountInfo( const programInfo = await connection.getAccountInfo(
program.publicKey, program.publicKey,
'single', 'singleGossip',
); );
let transaction: Transaction | null = null; let transaction: Transaction | null = null;
@ -127,7 +127,7 @@ export class Loader {
transaction, transaction,
[payer, program], [payer, program],
{ {
commitment: 'single', commitment: 'singleGossip',
skipPreflight: true, skipPreflight: true,
}, },
); );
@ -169,22 +169,15 @@ export class Loader {
}); });
transactions.push( transactions.push(
sendAndConfirmTransaction(connection, transaction, [payer, program], { sendAndConfirmTransaction(connection, transaction, [payer, program], {
commitment: 'single', commitment: 'singleGossip',
skipPreflight: true, skipPreflight: true,
}), }),
); );
// Delay between sends in an attempt to reduce rate limit errors // Delay between sends in an attempt to reduce rate limit errors
const REQUESTS_PER_SECOND = 4; if (connection._rpcEndpoint.includes('solana.com')) {
await sleep(1000 / REQUESTS_PER_SECOND); 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 = [];
} }
offset += chunkSize; offset += chunkSize;
@ -217,7 +210,7 @@ export class Loader {
transaction, transaction,
[payer, program], [payer, program],
{ {
commitment: 'single', commitment: 'singleGossip',
skipPreflight: true, skipPreflight: true,
}, },
); );

View File

@ -27,7 +27,7 @@ test('load BPF C program', async () => {
const data = await fs.readFile('test/fixtures/noop-c/noop.so'); const data = await fs.readFile('test/fixtures/noop-c/noop.so');
const connection = new Connection(url, 'recent'); const connection = new Connection(url, 'singleGossip');
const {feeCalculator} = await connection.getRecentBlockhash(); const {feeCalculator} = await connection.getRecentBlockhash();
const fees = const fees =
feeCalculator.lamportsPerSignature * feeCalculator.lamportsPerSignature *
@ -53,7 +53,7 @@ test('load BPF C program', async () => {
programId: program.publicKey, programId: program.publicKey,
}); });
await sendAndConfirmTransaction(connection, transaction, [from], { await sendAndConfirmTransaction(connection, transaction, [from], {
commitment: 'single', commitment: 'singleGossip',
skipPreflight: true, skipPreflight: true,
}); });
}); });
@ -64,7 +64,7 @@ describe('load BPF Rust program', () => {
return; return;
} }
const connection = new Connection(url, 'recent'); const connection = new Connection(url, 'singleGossip');
let program: Account; let program: Account;
let signature: string; let signature: string;

View File

@ -30,7 +30,7 @@ export async function newAccountWithLamports(
account.publicKey, account.publicKey,
lamports, lamports,
); );
await connection.confirmTransaction(signature, 'single'); await connection.confirmTransaction(signature, 'singleGossip');
return account; return account;
} }