Skip to content

Commit

Permalink
fix a bug
Browse files Browse the repository at this point in the history
  • Loading branch information
dantaik committed Jan 13, 2025
1 parent bcba67d commit 61a4c8b
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 90 deletions.
10 changes: 6 additions & 4 deletions packages/protocol/contracts/layer1/based/TaikoInbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ abstract contract TaikoInbox is EssentialContract, ITaikoInbox, ITaiko {
blockHash = ts.blockHash;

if (batchId % _config.stateRootSyncInternal == 0) {
synced.batchId = batchId;
synced.blockId = batch.lastBlockId;
synced.tid = tid;
synced.stateRoot = ts.stateRoot;
Expand All @@ -517,15 +518,15 @@ abstract contract TaikoInbox is EssentialContract, ITaikoInbox, ITaiko {
batch.verifiedTransitionId = tid;
emit BatchesVerified(_stats2.lastVerifiedBatchId, blockHash);

if (synced.blockId != 0) {
if (synced.blockId != _stats2.lastVerifiedBatchId) {
if (synced.batchId != 0) {
if (synced.batchId != _stats2.lastVerifiedBatchId) {
// We write the synced batch's verifiedTransitionId to storage
batch = state.batches[synced.blockId % _config.batchRingBufferSize];
batch = state.batches[synced.batchId % _config.batchRingBufferSize];
batch.verifiedTransitionId = synced.tid;
}

Stats1 memory stats1 = state.stats1;
stats1.lastSyncedBatchId = synced.blockId;
stats1.lastSyncedBatchId = batch.batchId;
stats1.lastSyncedAt = uint64(block.timestamp);
state.stats1 = stats1;

Expand Down Expand Up @@ -655,6 +656,7 @@ abstract contract TaikoInbox is EssentialContract, ITaikoInbox, ITaiko {
}

struct SyncBlock {
uint64 batchId;
uint64 blockId;
uint24 tid;
bytes32 stateRoot;
Expand Down
4 changes: 4 additions & 0 deletions packages/protocol/snapshots/InboxTest_ProposeAndProve.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"proposeBatch": "1920492",
"proveBatches": "297825"
}
2 changes: 1 addition & 1 deletion packages/protocol/test/layer1/based/InBoxTest_Params.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity ^0.8.24;

import "./InboxTestBase.sol";

contract InBoxTest_Params is InboxTestBase {
contract InboxTest_Params is InboxTestBase {
function getConfig() internal pure override returns (ITaikoInbox.Config memory) {
return ITaikoInbox.Config({
chainId: LibNetwork.TAIKO_MAINNET,
Expand Down
11 changes: 10 additions & 1 deletion packages/protocol/test/layer1/based/InboxTestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ abstract contract InboxTestBase is Layer1Test {
SignalService internal signalService;
uint256 genesisBlockProposedAt;
uint256 genesisBlockProposedIn;
uint256 private __blocksPerBatch;

function getConfig() internal view virtual returns (ITaikoInbox.Config memory);

Expand All @@ -32,6 +33,8 @@ abstract contract InboxTestBase is Layer1Test {
genesisBlockProposedAt = block.timestamp;
genesisBlockProposedIn = block.number;

__blocksPerBatch = 1;

inbox = deployInbox(correctBlockhash(0), getConfig());

signalService = deploySignalService(address(new SignalService()));
Expand All @@ -44,6 +47,11 @@ abstract contract InboxTestBase is Layer1Test {
mineOneBlockAndWrap(12 seconds);
}

modifier WhenEachBatchHasMultipleBlocks(uint256 _blocksPerBatch) {
__blocksPerBatch = _blocksPerBatch;
_;
}

modifier WhenLogAllBatchesAndTransitions() {
_logAllBatchesAndTransitions();
_;
Expand Down Expand Up @@ -103,7 +111,7 @@ abstract contract InboxTestBase is Layer1Test {
returns (uint64[] memory batchIds)
{
ITaikoInbox.BatchParams memory batchParams;
batchParams.blocks = new ITaikoInbox.BlockParams[](1);
batchParams.blocks = new ITaikoInbox.BlockParams[](__blocksPerBatch);

batchIds = new uint64[](numBatchesToPropose);

Expand Down Expand Up @@ -172,6 +180,7 @@ abstract contract InboxTestBase is Layer1Test {
}
console2.log(unicode"β”‚ |── metahash:", Strings.toHexString(uint256(batch.metaHash)));
console2.log(unicode"β”‚ |── timestamp:", batch.timestamp);
console2.log(unicode"β”‚ |── lastBlockId:", batch.lastBlockId);
console2.log(unicode"β”‚ |── anchorBlockId:", batch.anchorBlockId);
console2.log(unicode"β”‚ |── nextTransitionId:", batch.nextTransitionId);
console2.log(unicode"β”‚ |── verifiedTransitionId:", batch.verifiedTransitionId);
Expand Down
Loading

0 comments on commit 61a4c8b

Please sign in to comment.