-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enha: remove mutex that keeps transactions from executing while a blo…
…ck is being commited
- Loading branch information
1 parent
e2f0684
commit 0fd86c8
Showing
11 changed files
with
136 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.0; | ||
|
||
contract TestEvmInput { | ||
uint256 public executions; | ||
uint256 public result; | ||
|
||
// Define the event for logging | ||
event ComputationStarted(uint256 blockNumber, bool isSlow); | ||
|
||
function heavyComputation() public { | ||
// Emit event with current block number | ||
// Check if this is the first execution | ||
if (block.number < 1000) { | ||
emit ComputationStarted(block.number, true); | ||
|
||
// Perform a time-consuming loop | ||
uint256 temp = 0; | ||
for(uint i = 0; i < 10000; i++) { | ||
for(uint j = 0; j < 100; j++) { | ||
temp += i * j; | ||
temp = temp % 1000000; // Prevent overflow | ||
} | ||
} | ||
result = temp; | ||
} else { | ||
emit ComputationStarted(block.number, false); | ||
result = 42; | ||
} | ||
executions += 1; | ||
} | ||
|
||
// View function to get current block number (for testing) | ||
function getCurrentBlock() public view returns (uint256) { | ||
return block.number; | ||
} | ||
|
||
// View function to get result | ||
function getExecutions() public view returns (uint256) { | ||
return executions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { expect } from "chai"; | ||
|
||
import { | ||
deployTestEvmInput, | ||
sendReset, | ||
} from "../helpers/rpc"; | ||
import { ContractTransactionReceipt, Result } from "ethers"; | ||
|
||
// This test needs to be ran with stratus on a very fast block production rate (around 10ms is fast enough) | ||
describe("Evm Input", () => { | ||
describe("Transaction Execution", () => { | ||
it("should not be executed in one block but added to another", async () => { | ||
await sendReset(); | ||
const contract = await deployTestEvmInput(); | ||
await contract.waitForDeployment(); | ||
let tx = await contract.heavyComputation() | ||
let receipt = await tx.wait() as ContractTransactionReceipt; | ||
const event = receipt.logs[0]; | ||
const logs = contract.interface.parseLog({ | ||
topics: event.topics, | ||
data: event.data, | ||
})?.args as Result; | ||
|
||
expect(receipt.blockNumber).to.eq(logs.blockNumber); | ||
expect(logs.blockNumber).gt(1000); | ||
expect(logs.isSlow).to.be.false; | ||
expect(await contract.getExecutions()).to.eq(1); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters