Skip to content

Commit e7d5569

Browse files
committed
log gas usage
1 parent 0ce6061 commit e7d5569

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

target_chains/ethereum/contracts/contracts/entropy/Entropy.sol

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -669,23 +669,6 @@ abstract contract Entropy is IEntropy, EntropyState {
669669
}
670670
} else {
671671
// This case uses the checks-effects-interactions pattern to avoid reentry attacks
672-
emit RevealedWithCallback(
673-
EntropyStructConverter.toV1Request(req),
674-
userRandomNumber,
675-
providerRevelation,
676-
randomNumber
677-
);
678-
emit EntropyEventsV2.Revealed(
679-
provider,
680-
req.requester,
681-
req.sequenceNumber,
682-
randomNumber,
683-
false,
684-
bytes(""),
685-
0, // gas usage not tracked in the old no-gas-limit flow.
686-
bytes("")
687-
);
688-
689672
clearRequest(provider, sequenceNumber);
690673

691674
// Check if the requester is a contract account.
@@ -694,13 +677,32 @@ abstract contract Entropy is IEntropy, EntropyState {
694677
assembly {
695678
len := extcodesize(callAddress)
696679
}
680+
uint256 startingGas = gasleft();
697681
if (len != 0) {
698682
IEntropyConsumer(callAddress)._entropyCallback(
699683
sequenceNumber,
700684
provider,
701685
randomNumber
702686
);
703687
}
688+
uint32 gasUsed = SafeCast.toUint32(startingGas - gasleft());
689+
690+
emit RevealedWithCallback(
691+
EntropyStructConverter.toV1Request(req),
692+
userRandomNumber,
693+
providerRevelation,
694+
randomNumber
695+
);
696+
emit EntropyEventsV2.Revealed(
697+
provider,
698+
req.requester,
699+
req.sequenceNumber,
700+
randomNumber,
701+
false,
702+
bytes(""),
703+
gasUsed,
704+
bytes("")
705+
);
704706
}
705707
}
706708

target_chains/ethereum/contracts/forge-test/Entropy.t.sol

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,12 +1866,10 @@ contract EntropyTest is Test, EntropyTestUtils, EntropyEvents, EntropyEventsV2 {
18661866

18671867
// callback gas usage is approximate and only triggered when the provider has set a gas limit.
18681868
// Note: this condition is somewhat janky, but we hit the stack limit so can't put in any more local variables :(
1869-
assertTrue(
1870-
random.getProviderInfoV2(provider1).defaultGasLimit == 0 ||
1869+
assertTrue(
18711870
((callbackGasUsage * 90) / 100 < callbackGasUsed)
18721871
);
1873-
assertTrue(
1874-
random.getProviderInfoV2(provider1).defaultGasLimit == 0 ||
1872+
assertTrue(
18751873
(callbackGasUsed < (callbackGasUsage * 110) / 100)
18761874
);
18771875
assertEq(extraArgs, bytes(""));

0 commit comments

Comments
 (0)