Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added flags to speed up local debugging for certain edge cases #1198

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sdk/src/dev/flags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// 🚨 :: These should all always be false in any committed code.
export const DEV_FLAGS = {
TEST_COMPUTE_UNITS_OK_DURING_SIMULATION_BUT_FAIL_AT_RUNTIME: false, // Recreates the edge case where when sending a transaction the CU's are OK during simulation but fail at runtime.
};
5 changes: 5 additions & 0 deletions sdk/src/tx/txHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { CachedBlockhashFetcher } from './blockhashFetcher/cachedBlockhashFetche
import { BaseBlockhashFetcher } from './blockhashFetcher/baseBlockhashFetcher';
import { BlockhashFetcher } from './blockhashFetcher/types';
import { isVersionedTransaction } from './utils';
import { DEV_FLAGS } from '../dev/flags';

/**
* Explanation for SIGNATURE_BLOCK_AND_EXPIRY:
Expand Down Expand Up @@ -489,6 +490,10 @@ export class TxHandler {
};
}

if (DEV_FLAGS.TEST_COMPUTE_UNITS_OK_DURING_SIMULATION_BUT_FAIL_AT_RUNTIME) {
baseTxParams.computeUnits = 1000; // force low compute units to recreate the edge case where the CU's are OK during simulation but fail at runtime.
}

const instructionsArray = Array.isArray(instructions)
? instructions
: [instructions];
Expand Down
6 changes: 6 additions & 0 deletions sdk/src/tx/whileValidTxSender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { BaseTxSender } from './baseTxSender';
import bs58 from 'bs58';
import { TxHandler } from './txHandler';
import { IWallet } from '../types';
import { DEV_FLAGS } from '../dev/flags';

const DEFAULT_RETRY = 2000;

Expand Down Expand Up @@ -174,6 +175,11 @@ export class WhileValidTxSender extends BaseTxSender {
rawTransaction: Buffer | Uint8Array,
opts: ConfirmOptions
): Promise<TxSigAndSlot> {

if (DEV_FLAGS.TEST_COMPUTE_UNITS_OK_DURING_SIMULATION_BUT_FAIL_AT_RUNTIME) {
opts.skipPreflight = true; // Skip preflight to recreate the edge case where the CU's are OK during simulation but fail at runtime.
}

const startTime = this.getTimestamp();

const txid = await this.connection.sendRawTransaction(rawTransaction, opts);
Expand Down
Loading