Skip to content

Commit

Permalink
restore internal can prune at time
Browse files Browse the repository at this point in the history
  • Loading branch information
just-mitch committed Nov 1, 2024
1 parent e7ec1b5 commit 7b88b9d
Showing 1 changed file with 24 additions and 18 deletions.
42 changes: 24 additions & 18 deletions l1-contracts/src/core/Rollup.sol
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,8 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Leonidas, IRollup, ITestRollup {
Slot slot = getSlotAt(_ts);

// Consider if a prune will hit in this slot
uint256 pendingBlockNumber = canPrune() ? tips.provenBlockNumber : tips.pendingBlockNumber;
uint256 pendingBlockNumber =
_canPruneAtTime(_ts) ? tips.provenBlockNumber : tips.pendingBlockNumber;

Slot lastSlot = blocks[pendingBlockNumber].slotNumber;

Expand Down Expand Up @@ -775,14 +776,33 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Leonidas, IRollup, ITestRollup {
}

function canPrune() public view override(IRollup) returns (bool) {
return _canPruneAtTime(Timestamp.wrap(block.timestamp));
}

function _prune() internal {
// TODO #8656
delete proofClaim;

uint256 pending = tips.pendingBlockNumber;

// @note We are not deleting the blocks, but we are "winding back" the pendingTip to the last block that was proven.
// We can do because any new block proposed will overwrite a previous block in the block log,
// so no values should "survive".
// People must therefore read the chain using the pendingTip as a boundary.
tips.pendingBlockNumber = tips.provenBlockNumber;

emit PrunedPending(tips.provenBlockNumber, pending);
}

function _canPruneAtTime(Timestamp _ts) internal view returns (bool) {
if (
tips.pendingBlockNumber == tips.provenBlockNumber
|| tips.pendingBlockNumber <= assumeProvenThroughBlockNumber
) {
return false;
}

Slot currentSlot = getCurrentSlot();
Slot currentSlot = getSlotAt(_ts);
Epoch oldestPendingEpoch = getEpochForBlock(tips.provenBlockNumber + 1);
Slot startSlotOfPendingEpoch = oldestPendingEpoch.toSlots();

Expand All @@ -803,21 +823,6 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Leonidas, IRollup, ITestRollup {
return true;
}

function _prune() internal {
// TODO #8656
delete proofClaim;

uint256 pending = tips.pendingBlockNumber;

// @note We are not deleting the blocks, but we are "winding back" the pendingTip to the last block that was proven.
// We can do because any new block proposed will overwrite a previous block in the block log,
// so no values should "survive".
// People must therefore read the chain using the pendingTip as a boundary.
tips.pendingBlockNumber = tips.provenBlockNumber;

emit PrunedPending(tips.provenBlockNumber, pending);
}

/**
* @notice Validates the header for submission
*
Expand All @@ -836,7 +841,8 @@ contract Rollup is EIP712("Aztec Rollup", "1"), Leonidas, IRollup, ITestRollup {
bytes32 _txEffectsHash,
DataStructures.ExecutionFlags memory _flags
) internal view {
uint256 pendingBlockNumber = canPrune() ? tips.provenBlockNumber : tips.pendingBlockNumber;
uint256 pendingBlockNumber =
_canPruneAtTime(_currentTime) ? tips.provenBlockNumber : tips.pendingBlockNumber;
_validateHeaderForSubmissionBase(
_header, _currentTime, _txEffectsHash, pendingBlockNumber, _flags
);
Expand Down

0 comments on commit 7b88b9d

Please sign in to comment.