Skip to content

Commit

Permalink
Algod: Simulation run with extra budget per transaction group (algora…
Browse files Browse the repository at this point in the history
  • Loading branch information
ahangsu authored and joe-p committed Apr 11, 2024
1 parent de23acf commit 9cd4fc6
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 8 deletions.
22 changes: 22 additions & 0 deletions src/client/v2/algod/models/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3318,31 +3318,41 @@ export class SimulateRequest extends BaseModel {
*/
public allowMoreLogging?: boolean;

/**
* Applies extra opcode budget during simulation for each transaction group.
*/
public extraOpcodeBudget?: number | bigint;

/**
* Creates a new `SimulateRequest` object.
* @param txnGroups - The transaction groups to simulate.
* @param allowEmptySignatures - Allow transactions without signatures to be simulated as if they had correct
* signatures.
* @param allowMoreLogging - Lifts limits on log opcode usage during simulation.
* @param extraOpcodeBudget - Applies extra opcode budget during simulation for each transaction group.
*/
constructor({
txnGroups,
allowEmptySignatures,
allowMoreLogging,
extraOpcodeBudget,
}: {
txnGroups: SimulateRequestTransactionGroup[];
allowEmptySignatures?: boolean;
allowMoreLogging?: boolean;
extraOpcodeBudget?: number | bigint;
}) {
super();
this.txnGroups = txnGroups;
this.allowEmptySignatures = allowEmptySignatures;
this.allowMoreLogging = allowMoreLogging;
this.extraOpcodeBudget = extraOpcodeBudget;

this.attribute_map = {
txnGroups: 'txn-groups',
allowEmptySignatures: 'allow-empty-signatures',
allowMoreLogging: 'allow-more-logging',
extraOpcodeBudget: 'extra-opcode-budget',
};
}

Expand All @@ -3359,6 +3369,7 @@ export class SimulateRequest extends BaseModel {
),
allowEmptySignatures: data['allow-empty-signatures'],
allowMoreLogging: data['allow-more-logging'],
extraOpcodeBudget: data['extra-opcode-budget'],
});
/* eslint-enable dot-notation */
}
Expand Down Expand Up @@ -3672,6 +3683,11 @@ export class SimulationEvalOverrides extends BaseModel {
*/
public allowEmptySignatures?: boolean;

/**
* The extra opcode budget added to each transaction group during simulation
*/
public extraOpcodeBudget?: number | bigint;

/**
* The maximum log calls one can make during simulation
*/
Expand All @@ -3686,25 +3702,30 @@ export class SimulationEvalOverrides extends BaseModel {
* Creates a new `SimulationEvalOverrides` object.
* @param allowEmptySignatures - If true, transactions without signatures are allowed and simulated as if they
* were properly signed.
* @param extraOpcodeBudget - The extra opcode budget added to each transaction group during simulation
* @param maxLogCalls - The maximum log calls one can make during simulation
* @param maxLogSize - The maximum byte number to log during simulation
*/
constructor({
allowEmptySignatures,
extraOpcodeBudget,
maxLogCalls,
maxLogSize,
}: {
allowEmptySignatures?: boolean;
extraOpcodeBudget?: number | bigint;
maxLogCalls?: number | bigint;
maxLogSize?: number | bigint;
}) {
super();
this.allowEmptySignatures = allowEmptySignatures;
this.extraOpcodeBudget = extraOpcodeBudget;
this.maxLogCalls = maxLogCalls;
this.maxLogSize = maxLogSize;

this.attribute_map = {
allowEmptySignatures: 'allow-empty-signatures',
extraOpcodeBudget: 'extra-opcode-budget',
maxLogCalls: 'max-log-calls',
maxLogSize: 'max-log-size',
};
Expand All @@ -3717,6 +3738,7 @@ export class SimulationEvalOverrides extends BaseModel {
/* eslint-disable dot-notation */
return new SimulationEvalOverrides({
allowEmptySignatures: data['allow-empty-signatures'],
extraOpcodeBudget: data['extra-opcode-budget'],
maxLogCalls: data['max-log-calls'],
maxLogSize: data['max-log-size'],
});
Expand Down
1 change: 1 addition & 0 deletions tests/cucumber/integration.tags
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
@send.keyregtxn
@simulate
@simulate.lift_log_limits
@simulate.extra_opcode_budget
28 changes: 20 additions & 8 deletions tests/cucumber/steps/steps.js
Original file line number Diff line number Diff line change
Expand Up @@ -4791,14 +4791,26 @@ module.exports = function getSteps(options) {
Then(
'I check the simulation result has power packs allow-more-logging.',
async function () {
assert.notDeepStrictEqual(undefined, this.simulateResponse.evalOverrides);
assert.notDeepStrictEqual(
undefined,
this.simulateResponse.evalOverrides.maxLogCalls
);
assert.notDeepStrictEqual(
undefined,
this.simulateResponse.evalOverrides.maxLogSize
assert.ok(this.simulateResponse.evalOverrides);
assert.ok(this.simulateResponse.evalOverrides.maxLogCalls);
assert.ok(this.simulateResponse.evalOverrides.maxLogSize);
}
);

Then(
'I allow {int} more budget on that simulate request.',
async function (budget) {
this.simulateRequest.extraOpcodeBudget = budget;
}
);

Then(
'I check the simulation result has power packs extra-opcode-budget with extra budget {int}.',
async function (budget) {
assert.ok(this.simulateResponse.evalOverrides);
assert.strictEqual(
budget,
this.simulateResponse.evalOverrides.extraOpcodeBudget
);
}
);
Expand Down

0 comments on commit 9cd4fc6

Please sign in to comment.