Skip to content

Commit

Permalink
fix(validator): process transaction if enough gas is left (#678)
Browse files Browse the repository at this point in the history
* check gas left

* emoty commit
  • Loading branch information
sebastijankuzner authored Aug 7, 2024
1 parent b02cad2 commit 4ae8724
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions packages/validator/source/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,22 +155,17 @@ export class Validator implements Contracts.Validator.Validator {
}

try {
const gasLimit = transaction.data.asset?.evmCall?.gasLimit || 0;

if (gasLeft - gasLimit < 0) {
break;
}

const result = await validator.validate(
{ commitKey, gasLimit: milestone.block.maxGasLimit, generatorPublicKey, timestamp },
transaction,
);

// We received transactions from the pool without taking gas usage into account yet.
// Therefore only include transactions that fit into the block.
if (gasLeft - result.gasUsed < 0) {
if (gasLeft >= 21_000) {
continue; // another transaction potentially still fits
}

// block is full
break;
}

gasLeft -= result.gasUsed;

transaction.data.gasUsed = result.gasUsed;
Expand Down

0 comments on commit 4ae8724

Please sign in to comment.