Skip to content

Commit

Permalink
immediate batch seal flag for counter overflows (#1415)
Browse files Browse the repository at this point in the history
  • Loading branch information
hexoscott authored Nov 5, 2024
1 parent eefe88a commit 1ce7d81
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 11 deletions.
5 changes: 5 additions & 0 deletions cmd/utils/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,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
7 changes: 4 additions & 3 deletions eth/ethconfig/config_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,10 @@ type Zk struct {

TxPoolRejectSmartContractDeployments bool

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

var DefaultZkConfig = &Zk{}
Expand Down
2 changes: 1 addition & 1 deletion turbo/cli/default_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ var DefaultFlags = []cli.Flag{
&utils.DisableVirtualCounters,
&utils.DAUrl,
&utils.VirtualCountersSmtReduction,


&utils.ACLPrintHistory,
&utils.InfoTreeUpdateInterval,
&utils.BadBatches,
&utils.SealBatchImmediatelyOnOverflow,
}
9 changes: 5 additions & 4 deletions turbo/cli/flags_zkevm.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,11 @@ func ApplyFlagsForZkConfig(ctx *cli.Context, cfg *ethconfig.Config) {
DataStreamWriteTimeout: ctx.Duration(utils.DataStreamWriteTimeout.Name),
DataStreamInactivityTimeout: ctx.Duration(utils.DataStreamInactivityTimeout.Name),
VirtualCountersSmtReduction: ctx.Float64(utils.VirtualCountersSmtReduction.Name),

ACLPrintHistory: ctx.Int(utils.ACLPrintHistory.Name),
InfoTreeUpdateInterval: ctx.Duration(utils.InfoTreeUpdateInterval.Name),
BadBatches: badBatches,

ACLPrintHistory: ctx.Int(utils.ACLPrintHistory.Name),
InfoTreeUpdateInterval: ctx.Duration(utils.InfoTreeUpdateInterval.Name),
BadBatches: badBatches,
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 @@ -18,7 +18,8 @@
"erc20Revert:local": "npx hardhat compile && npx hardhat run scripts/ERC20-revert.js --network local",
"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"
"chainCall:sepolia": "npx hardhat compile && npx hardhat run scripts/chain-call.js --network sepolia",
"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 @@ -324,8 +324,8 @@ func SpawnSequencingStage(
} else {
batchState.newOverflowTransaction()
log.Info(fmt.Sprintf("[%s] transaction %s overflow counters", logPrefix, txHash), "count", batchState.overflowTransactions)
if batchState.reachedOverflowTransactionLimit() {
log.Info(fmt.Sprintf("[%s] closing batch due to counters", logPrefix), "count", batchState.overflowTransactions)
if batchState.reachedOverflowTransactionLimit() || cfg.zk.SealBatchImmediatelyOnOverflow {
log.Info(fmt.Sprintf("[%s] closing batch due to counters", logPrefix), "count", batchState.overflowTransactions, "immediate", cfg.zk.SealBatchImmediatelyOnOverflow)
runLoopBlocks = false
break LOOP_TRANSACTIONS
}
Expand Down

0 comments on commit 1ce7d81

Please sign in to comment.