Skip to content

Commit

Permalink
dont override the commitment level
Browse files Browse the repository at this point in the history
  • Loading branch information
barnjamin committed Jan 3, 2024
1 parent 15ca3fc commit d31e27e
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
6 changes: 2 additions & 4 deletions platforms/solana/src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,11 @@ export class SolanaPlatform<N extends Network> extends PlatformContext<
rpc: Connection,
commitment?: Commitment,
): Promise<{ blockhash: string; lastValidBlockHeight: number }> {
// Use finalized to prevent blockhash not found errors
// Note: this may mean we have less time to submit transactions?
return rpc.getLatestBlockhash(commitment ?? 'finalized');
return rpc.getLatestBlockhash(commitment ?? rpc.commitment);
}

static async getLatestBlock(rpc: Connection): Promise<number> {
const { lastValidBlockHeight } = await this.latestBlock(rpc, 'confirmed');
const { lastValidBlockHeight } = await this.latestBlock(rpc);
return lastValidBlockHeight;
}

Expand Down
16 changes: 14 additions & 2 deletions platforms/solana/src/testing/sendSigner.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
ComputeBudgetProgram,
Connection,
Keypair,
SendOptions,
Expand Down Expand Up @@ -26,6 +27,7 @@ export class SolanaSendSigner<
private _keypair: Keypair,
private _debug: boolean = false,
private _sendOpts?: SendOptions,
private _priotifyFeeAmount?: bigint,
) {
this._sendOpts = this._sendOpts ?? {
preflightCommitment: this._rpc.commitment,
Expand All @@ -42,6 +44,7 @@ export class SolanaSendSigner<

// Handles retrying a Transaction if the error is deemed to be
// recoverable. Currently handles:
// - Transaction expired
// - Blockhash not found
// - Not enough bytes (storage account not seen yet)
private retryable(e: any): boolean {
Expand Down Expand Up @@ -75,7 +78,6 @@ export class SolanaSendSigner<
async signAndSend(tx: UnsignedTransaction[]): Promise<any[]> {
let { blockhash, lastValidBlockHeight } = await SolanaPlatform.latestBlock(
this._rpc,
'finalized',
);

const txids: string[] = [];
Expand All @@ -86,6 +88,13 @@ export class SolanaSendSigner<
} = txn as SolanaUnsignedTransaction<N, C>;
console.log(`Signing: ${description} for ${this.address()}`);

if (this._priotifyFeeAmount)
transaction.add(
ComputeBudgetProgram.setComputeUnitPrice({
microLamports: this._priotifyFeeAmount,
}),
);

if (this._debug) logTxDetails(transaction);

// Try to send the transaction up to 5 times
Expand All @@ -103,9 +112,12 @@ export class SolanaSendSigner<
} catch (e) {
if (!this.retryable(e)) throw e;

// TODO: check that the previous one is expired before
// re-signing

// If it is retryable, we should grab a new block hash
({ blockhash, lastValidBlockHeight } =
await SolanaPlatform.latestBlock(this._rpc, 'finalized'));
await SolanaPlatform.latestBlock(this._rpc));
}
}
}
Expand Down
5 changes: 1 addition & 4 deletions platforms/solana/src/testing/signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,7 @@ export class SolanaSigner<N extends Network, C extends SolanaChains = 'Solana'>
}

async sign(tx: UnsignedTransaction[]): Promise<any[]> {
const { blockhash } = await SolanaPlatform.latestBlock(
this._rpc,
'finalized',
);
const { blockhash } = await SolanaPlatform.latestBlock(this._rpc);

const signed = [];
for (const txn of tx) {
Expand Down

0 comments on commit d31e27e

Please sign in to comment.