Skip to content

Commit

Permalink
immediate batch seal flag for counter overflows (erigontech#1417)
Browse files Browse the repository at this point in the history
# Conflicts:
#	eth/ethconfig/config_zkevm.go
#	turbo/cli/default_flags.go
#	turbo/cli/flags_zkevm.go
#	zk/debug_tools/test-contracts/package.json
#	zk/stages/stage_sequence_execute.go
  • Loading branch information
hexoscott authored Nov 6, 2024
1 parent 26fd344 commit 8cc6d54
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 7 deletions.
5 changes: 5 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,11 @@ var (
Usage: "The interval at which the sequencer checks the L1 for new GER information",
Value: 1 * time.Minute,
}
SealBatchImmediatelyOnOverflow = cli.BoolFlag{
Name: "zkevm.seal-batch-immediately-on-overflow",
Usage: "Seal the batch immediately when detecting a counter overflow",
Value: false,
}
ACLPrintHistory = cli.IntFlag{
Name: "acl.print-history",
Usage: "Number of entries to print from the ACL history on node start up",
Expand Down
9 changes: 5 additions & 4 deletions eth/ethconfig/config_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,11 @@ type Zk struct {

TxPoolRejectSmartContractDeployments bool

InitialBatchCfgFile string
ACLPrintHistory int
InfoTreeUpdateInterval time.Duration
BadBatches []uint64
InitialBatchCfgFile string
ACLPrintHistory int
InfoTreeUpdateInterval time.Duration
BadBatches []uint64
SealBatchImmediatelyOnOverflow bool
}

var DefaultZkConfig = &Zk{}
Expand Down
1 change: 1 addition & 0 deletions turbo/cli/default_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,4 +286,5 @@ var DefaultFlags = []cli.Flag{

&utils.ACLPrintHistory,
&utils.InfoTreeUpdateInterval,
&utils.SealBatchImmediatelyOnOverflow,
}
1 change: 1 addition & 0 deletions turbo/cli/flags_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ func ApplyFlagsForZkConfig(ctx *cli.Context, cfg *ethconfig.Config) {
InitialBatchCfgFile: ctx.String(utils.InitialBatchCfgFile.Name),
ACLPrintHistory: ctx.Int(utils.ACLPrintHistory.Name),
InfoTreeUpdateInterval: ctx.Duration(utils.InfoTreeUpdateInterval.Name),
SealBatchImmediatelyOnOverflow: ctx.Bool(utils.SealBatchImmediatelyOnOverflow.Name),
}

utils2.EnableTimer(cfg.DebugTimers)
Expand Down
10 changes: 10 additions & 0 deletions zk/debug_tools/test-contracts/contracts/KeccakLoop.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
pragma solidity >=0.8.10;

// 1616 for legacy, 226 for erigon -> 1198 -> 246
contract KeccakLoop {
constructor () {
for(uint256 i = 0; i < 200; i++) {
keccak256(new bytes(i));
}
}
}
3 changes: 2 additions & 1 deletion zk/debug_tools/test-contracts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
"erc20Revert:sepolia": "npx hardhat compile && npx hardhat run scripts/ERC20-revert.js --network sepolia",
"chainCall:local": "npx hardhat compile && npx hardhat run scripts/chain-call.js --network local",
"chainCall:sepolia": "npx hardhat compile && npx hardhat run scripts/chain-call.js --network sepolia",
"create:local": "npx hardhat compile && npx hardhat run scripts/create.js --network local"
"create:local": "npx hardhat compile && npx hardhat run scripts/create.js --network local",
"keccak:local": "npx hardhat compile && npx hardhat run scripts/keccak-loop.js --network local"
},
"keywords": [],
"author": "",
Expand Down
26 changes: 26 additions & 0 deletions zk/debug_tools/test-contracts/scripts/keccak-loop.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
async function main() {
try {
// Get the ContractFactory of your KeccakLoopContract
const KeccakLoopContract = await hre.ethers.getContractFactory("KeccakLoop");

// Deploy the contract
const contract = await KeccakLoopContract.deploy();
// Wait for the deployment transaction to be mined
await contract.waitForDeployment();

console.log(`KeccakLoop deployed to: ${await contract.getAddress()}`);

// const result = await contract.bigLoop(10000);
// console.log(result);
} catch (error) {
console.error(error);
process.exit(1);
}
}

main()
.then(() => process.exit(0))
.catch(error => {
console.error(error);
process.exit(1);
});
4 changes: 2 additions & 2 deletions zk/stages/stage_sequence_execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,8 +440,8 @@ func sequencingBatchStep(
ocs, _ := batchCounters.CounterStats(l1TreeUpdateIndex != 0)
// was not included in this batch because it overflowed: counter x, counter y
log.Info(transactionNotAddedText, "Counters context:", ocs, "overflow transactions", batchState.overflowTransactions)
if batchState.reachedOverflowTransactionLimit() {
log.Info(fmt.Sprintf("[%s] closing batch due to counters", logPrefix), "counters: ", batchState.overflowTransactions)
if batchState.reachedOverflowTransactionLimit() || cfg.zk.SealBatchImmediatelyOnOverflow {
log.Info(fmt.Sprintf("[%s] closing batch due to counters", logPrefix), "counters: ", batchState.overflowTransactions, "immediate", cfg.zk.SealBatchImmediatelyOnOverflow)
runLoopBlocks = false
break LOOP_TRANSACTIONS
}
Expand Down

0 comments on commit 8cc6d54

Please sign in to comment.