Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Epoch boundaries in terms of L1 blocks #95

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cartesi-rollups/contracts/lib/rollups-contracts
45 changes: 29 additions & 16 deletions cartesi-rollups/contracts/src/DaveConsensus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,20 @@ contract DaveConsensus is IDataProvider {
/// @notice Current sealed epoch number
uint256 _epochNumber;

/// @notice Block number (inclusive) lower bound of the current sealed epoch
/// @dev Initialized with 0
uint256 _blockNumberLowerBound;

/// @notice Block number (exclusive) upper bound of the current sealed epoch
/// @dev Initialized with the deployment block number
uint256 _blockNumberUpperBound;

/// @notice Input index (inclusive) lower bound of the current sealed epoch
/// @dev Initialized with 0
uint256 _inputIndexLowerBound;

/// @notice Input index (exclusive) upper bound of the current sealed epoch
/// @dev Initialized with the number of inputs before the deployment block
uint256 _inputIndexUpperBound;

/// @notice Current sealed epoch tournament
Expand All @@ -66,14 +76,14 @@ contract DaveConsensus is IDataProvider {

/// @notice An epoch was sealed
/// @param epochNumber the sealed epoch number
/// @param inputIndexLowerBound the input index (inclusive) lower bound in the sealed epoch
/// @param inputIndexUpperBound the input index (exclusive) upper bound in the sealed epoch
/// @param blockNumberLowerBound the block number (inclusive) lower bound in the sealed epoch
/// @param blockNumberUpperBound the block number (exclusive) upper bound in the sealed epoch
/// @param initialMachineStateHash the initial machine state hash
/// @param tournament the sealed epoch tournament contract
event EpochSealed(
uint256 epochNumber,
uint256 inputIndexLowerBound,
uint256 inputIndexUpperBound,
uint256 blockNumberLowerBound,
uint256 blockNumberUpperBound,
Machine.Hash initialMachineStateHash,
ITournament tournament
);
Expand Down Expand Up @@ -104,11 +114,12 @@ contract DaveConsensus is IDataProvider {
emit ConsensusCreation(inputBox, appContract, tournamentFactory);

// Initialize first sealed epoch
uint256 inputIndexUpperBound = inputBox.getNumberOfInputs(appContract);
_inputIndexUpperBound = inputIndexUpperBound;
uint256 blockNumberUpperBound = block.number;
_blockNumberUpperBound = blockNumberUpperBound;
_inputIndexUpperBound = inputBox.getNumberOfInputsBeforeCurrentBlock(appContract);
ITournament tournament = tournamentFactory.instantiate(initialMachineStateHash, this);
_tournament = tournament;
emit EpochSealed(0, 0, inputIndexUpperBound, initialMachineStateHash, tournament);
emit EpochSealed(0, 0, blockNumberUpperBound, initialMachineStateHash, tournament);
}

function canSettle() external view returns (bool isFinished, uint256 epochNumber) {
Expand All @@ -125,28 +136,30 @@ contract DaveConsensus is IDataProvider {

// Seal current accumulating epoch
_epochNumber = ++epochNumber;
uint256 inputIndexLowerBound = _inputIndexUpperBound;
_inputIndexLowerBound = inputIndexLowerBound;
uint256 inputIndexUpperBound = _inputBox.getNumberOfInputs(_appContract);
_inputIndexUpperBound = inputIndexUpperBound;
uint256 blockNumberLowerBound = _blockNumberUpperBound;
_blockNumberLowerBound = blockNumberLowerBound;
uint256 blockNumberUpperBound = block.number;
_blockNumberUpperBound = blockNumberUpperBound;
_inputIndexLowerBound = _inputIndexUpperBound;
_inputIndexUpperBound = _inputBox.getNumberOfInputsBeforeCurrentBlock(_appContract);
ITournament tournament = _tournamentFactory.instantiate(finalMachineStateHash, this);
_tournament = tournament;
emit EpochSealed(epochNumber, inputIndexLowerBound, inputIndexUpperBound, finalMachineStateHash, tournament);
emit EpochSealed(epochNumber, blockNumberLowerBound, blockNumberUpperBound, finalMachineStateHash, tournament);
}

function getCurrentSealedEpoch()
external
view
returns (
uint256 epochNumber,
uint256 inputIndexLowerBound,
uint256 inputIndexUpperBound,
uint256 blockNumberLowerBound,
uint256 blockNumberUpperBound,
ITournament tournament
)
{
epochNumber = _epochNumber;
inputIndexLowerBound = _inputIndexLowerBound;
inputIndexUpperBound = _inputIndexUpperBound;
blockNumberLowerBound = _blockNumberLowerBound;
blockNumberUpperBound = _blockNumberUpperBound;
tournament = _tournament;
}

Expand Down
6 changes: 5 additions & 1 deletion prt/contracts/src/ITournament.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ interface ITournament {
function arbitrationResult()
external
view
returns (bool, Tree.Node, Machine.Hash);
returns (
bool isFinished,
Tree.Node winningCommitment,
Machine.Hash finalMachineStateHash
);
}