@@ -16,18 +16,17 @@ import {LibKeccak256} from "cartesi-rollups-contracts-3.0.0/src/library/LibKecca
1616import {LibMath} from "cartesi-rollups-contracts-3.0.0/src/library/LibMath.sol " ;
1717
1818import {IDataProvider} from "prt-contracts/IDataProvider.sol " ;
19- import {ITournament } from "prt-contracts/ITournament .sol " ;
20- import {ITournamentFactory } from "prt-contracts/ITournamentFactory .sol " ;
19+ import {ITask } from "prt-contracts/ITask .sol " ;
20+ import {ITaskSpawner } from "prt-contracts/ITaskSpawner .sol " ;
2121
2222import {Machine} from "prt-contracts/types/Machine.sol " ;
23- import {Tree} from "prt-contracts/types/Tree.sol " ;
2423
2524import {EmulatorConstants} from "step/src/EmulatorConstants.sol " ;
2625import {Memory} from "step/src/Memory.sol " ;
2726
2827import {IDaveConsensus} from "./IDaveConsensus.sol " ;
2928
30- /// @notice Consensus contract with Dave tournaments .
29+ /// @notice Consensus contract with Dave tasks .
3130///
3231/// @notice This contract validates only one application,
3332/// which read inputs from the InputBox contract.
@@ -60,8 +59,8 @@ contract DaveConsensus is IDaveConsensus, ERC165, ApplicationChecker {
6059 /// @notice The application contract
6160 address immutable _APP_CONTRACT;
6261
63- /// @notice The contract used to instantiate tournaments
64- ITournamentFactory immutable _TOURNAMENT_FACTORY ;
62+ /// @notice The contract used to instantiate tasks
63+ ITaskSpawner immutable _TASK_SPAWNER ;
6564
6665 /// @notice Deployment block number
6766 uint256 immutable _DEPLOYMENT_BLOCK_NUMBER = block .number ;
@@ -75,8 +74,8 @@ contract DaveConsensus is IDaveConsensus, ERC165, ApplicationChecker {
7574 /// @notice Input index (exclusive) upper bound of the current sealed epoch
7675 uint256 _inputIndexUpperBound;
7776
78- /// @notice Current sealed epoch tournament
79- ITournament _tournament ;
77+ /// @notice Current sealed epoch task
78+ ITask _task ;
8079
8180 /// @notice Settled output trees' merkle root hash
8281 mapping (bytes32 => bool ) _outputsMerkleRoots;
@@ -87,30 +86,30 @@ contract DaveConsensus is IDaveConsensus, ERC165, ApplicationChecker {
8786 constructor (
8887 IInputBox inputBox ,
8988 address appContract ,
90- ITournamentFactory tournamentFactory ,
89+ ITaskSpawner taskSpawner ,
9190 Machine.Hash initialMachineStateHash
9291 ) {
9392 // Initialize immutable variables
9493 _INPUT_BOX = inputBox;
9594 _APP_CONTRACT = appContract;
96- _TOURNAMENT_FACTORY = tournamentFactory ;
97- emit ConsensusCreation (inputBox, appContract, tournamentFactory );
95+ _TASK_SPAWNER = taskSpawner ;
96+ emit ConsensusCreation (inputBox, appContract, taskSpawner );
9897
9998 // Initialize first sealed epoch
10099 uint256 inputIndexUpperBound = inputBox.getNumberOfInputs (appContract);
101100 _inputIndexUpperBound = inputIndexUpperBound;
102- ITournament tournament = tournamentFactory. instantiate (initialMachineStateHash, this );
103- _tournament = tournament ;
104- emit EpochSealed (0 , 0 , inputIndexUpperBound, initialMachineStateHash, bytes32 (0 ), tournament );
101+ ITask task = taskSpawner. spawn (initialMachineStateHash, this );
102+ _task = task ;
103+ emit EpochSealed (0 , 0 , inputIndexUpperBound, initialMachineStateHash, bytes32 (0 ), task );
105104 }
106105
107106 function canSettle ()
108107 external
109108 view
110109 override
111- returns (bool isFinished , uint256 epochNumber , Tree.Node winnerCommitment )
110+ returns (bool isFinished , uint256 epochNumber , Machine.Hash finalState )
112111 {
113- (isFinished, winnerCommitment, ) = _tournament. arbitrationResult ();
112+ (isFinished, finalState ) = _task. result ();
114113 epochNumber = _epochNumber;
115114 }
116115
@@ -119,14 +118,14 @@ contract DaveConsensus is IDaveConsensus, ERC165, ApplicationChecker {
119118 override
120119 notForeclosed (_APP_CONTRACT)
121120 {
122- // Check tournament settlement
121+ // Check task settlement
123122 require (epochNumber == _epochNumber, IncorrectEpochNumber (epochNumber, _epochNumber));
124123
125- // Check tournament finished
126- (bool isFinished ,, Machine.Hash finalMachineStateHash ) = _tournament. arbitrationResult ();
124+ // Check task finished
125+ (bool isFinished , Machine.Hash finalMachineStateHash ) = _task. result ();
127126 require (isFinished, TournamentNotFinishedYet ());
128- ITournament oldTournament = _tournament ;
129- _tournament = ITournament (address (0 ));
127+ ITask oldTask = _task ;
128+ _task = ITask (address (0 ));
130129
131130 // Check outputs Merkle root
132131 _validateOutputTree (finalMachineStateHash, outputsMerkleRoot, proof);
@@ -138,36 +137,26 @@ contract DaveConsensus is IDaveConsensus, ERC165, ApplicationChecker {
138137 _outputsMerkleRoots[outputsMerkleRoot] = true ;
139138 _lastFinalizedMachineStateHash = finalMachineStateHash;
140139
141- // Start new tournament
142- _tournament = _TOURNAMENT_FACTORY. instantiate (finalMachineStateHash, this );
140+ // Start new task
141+ _task = _TASK_SPAWNER. spawn (finalMachineStateHash, this );
143142
144143 emit EpochSealed (
145- _epochNumber,
146- _inputIndexLowerBound,
147- _inputIndexUpperBound,
148- finalMachineStateHash,
149- outputsMerkleRoot,
150- _tournament
144+ _epochNumber, _inputIndexLowerBound, _inputIndexUpperBound, finalMachineStateHash, outputsMerkleRoot, _task
151145 );
152146
153- oldTournament. tryRecoveringBond ( );
147+ _tryCleanup (oldTask );
154148 }
155149
156150 function getCurrentSealedEpoch ()
157151 external
158152 view
159153 override
160- returns (
161- uint256 epochNumber ,
162- uint256 inputIndexLowerBound ,
163- uint256 inputIndexUpperBound ,
164- ITournament tournament
165- )
154+ returns (uint256 epochNumber , uint256 inputIndexLowerBound , uint256 inputIndexUpperBound , ITask task )
166155 {
167156 epochNumber = _epochNumber;
168157 inputIndexLowerBound = _inputIndexLowerBound;
169158 inputIndexUpperBound = _inputIndexUpperBound;
170- tournament = _tournament ;
159+ task = _task ;
171160 }
172161
173162 function getInputBox () external view override returns (IInputBox) {
@@ -178,8 +167,8 @@ contract DaveConsensus is IDaveConsensus, ERC165, ApplicationChecker {
178167 return _APP_CONTRACT;
179168 }
180169
181- function getTournamentFactory () external view override returns (ITournamentFactory ) {
182- return _TOURNAMENT_FACTORY ;
170+ function getTaskSpawner () external view override returns (ITaskSpawner ) {
171+ return _TASK_SPAWNER ;
183172 }
184173
185174 function provideMerkleRootOfInput (uint256 inputIndexWithinEpoch , bytes calldata input )
@@ -250,6 +239,12 @@ contract DaveConsensus is IDaveConsensus, ERC165, ApplicationChecker {
250239 require (machineStateHash == allegedStateHash, InvalidOutputsMerkleRootProof (finalMachineStateHash));
251240 }
252241
242+ /// @dev Best-effort: settlement must never be blocked by a task whose
243+ /// cleanup reverts.
244+ function _tryCleanup (ITask task ) internal {
245+ try task.cleanup () returns (bool ) {} catch {}
246+ }
247+
253248 modifier onlyValidAppContract (address appContract ) {
254249 _ensureAppContractIsValid (appContract);
255250 _;
0 commit comments