@@ -8,9 +8,10 @@ import hre = require("hardhat");
8
8
const { ethers } = hre ;
9
9
const MAX_DRAW_ITERATIONS = 30 ;
10
10
const MAX_EXECUTE_ITERATIONS = 20 ;
11
+ const MAX_DELAYED_STAKES_ITERATIONS = 50 ;
11
12
const WAIT_FOR_RNG_DURATION = 5 * 1000 ; // 5 seconds
12
- const ITERATIONS_COOLDOWN_PERIOD = 20 * 1000 ; // 20 seconds
13
- const HIGH_GAS_LIMIT = { gasLimit : 50000000 } ; // 50M gas
13
+ const ITERATIONS_COOLDOWN_PERIOD = 10 * 1000 ; // 10 seconds
14
+ const HIGH_GAS_LIMIT = { gasLimit : 50_000_000 } ; // 50M gas
14
15
const HEARTBEAT_URL = env . optionalNoDefault ( "HEARTBEAT_URL_KEEPER_BOT" ) ;
15
16
const SUBGRAPH_URL = env . require ( "SUBGRAPH_URL" ) ;
16
17
const MAX_JURORS_PER_DISPUTE = 1000 ; // Skip disputes with more than this number of jurors
@@ -219,7 +220,7 @@ const drawJurors = async (dispute: { id: string; currentRoundIndex: string }, it
219
220
try {
220
221
await core . callStatic . draw ( dispute . id , iterations , HIGH_GAS_LIMIT ) ;
221
222
} catch ( e ) {
222
- logger . info ( `Draw: will fail for ${ dispute . id } , skipping` ) ;
223
+ logger . error ( `Draw: will fail for ${ dispute . id } , skipping` ) ;
223
224
return success ;
224
225
}
225
226
try {
@@ -241,7 +242,7 @@ const executeRepartitions = async (dispute: { id: string; currentRoundIndex: str
241
242
try {
242
243
await core . callStatic . execute ( dispute . id , dispute . currentRoundIndex , iterations , HIGH_GAS_LIMIT ) ;
243
244
} catch ( e ) {
244
- logger . info ( `Execute: will fail for ${ dispute . id } , skipping` ) ;
245
+ logger . error ( `Execute: will fail for ${ dispute . id } , skipping` ) ;
245
246
return success ;
246
247
}
247
248
try {
@@ -260,7 +261,7 @@ const executeRuling = async (dispute: { id: string }) => {
260
261
try {
261
262
await core . callStatic . executeRuling ( dispute . id ) ;
262
263
} catch ( e ) {
263
- logger . info ( `ExecuteRuling: will fail for ${ dispute . id } , skipping` ) ;
264
+ logger . error ( `ExecuteRuling: will fail for ${ dispute . id } , skipping` ) ;
264
265
return success ;
265
266
}
266
267
try {
@@ -290,7 +291,7 @@ const withdrawAppealContribution = async (
290
291
contribution . choice
291
292
) ;
292
293
} catch ( e ) {
293
- logger . info (
294
+ logger . warn (
294
295
`WithdrawFeesAndRewards: will fail for dispute #${ disputeId } , round #${ roundId } , choice ${ contribution . choice } and beneficiary ${ contribution . contributor . id } , skipping`
295
296
) ;
296
297
return success ;
@@ -323,6 +324,40 @@ const withdrawAppealContribution = async (
323
324
return success ;
324
325
} ;
325
326
327
+ const executeDelayedStakes = async ( ) => {
328
+ const { sortition } = await getContracts ( ) ;
329
+
330
+ // delayedStakes = 1 + delayedStakeWriteIndex - delayedStakeReadIndex
331
+ const delayedStakesRemaining = BigNumber . from ( 1 )
332
+ . add ( await sortition . delayedStakeWriteIndex ( ) )
333
+ . sub ( await sortition . delayedStakeReadIndex ( ) ) ;
334
+
335
+ const delayedStakes = delayedStakesRemaining . lt ( MAX_DELAYED_STAKES_ITERATIONS )
336
+ ? delayedStakesRemaining
337
+ : BigNumber . from ( MAX_DELAYED_STAKES_ITERATIONS ) ;
338
+
339
+ if ( delayedStakes . eq ( 0 ) ) {
340
+ logger . info ( "No delayed stakes to execute" ) ;
341
+ return true ;
342
+ }
343
+ logger . info ( `Executing ${ delayedStakes } delayed stakes, ${ delayedStakesRemaining } remaining` ) ;
344
+ let success = false ;
345
+ try {
346
+ await sortition . callStatic . executeDelayedStakes ( delayedStakes ) ;
347
+ } catch ( e ) {
348
+ logger . error ( `executeDelayedStakes: will fail because of ${ JSON . stringify ( e ) } ` ) ;
349
+ return success ;
350
+ }
351
+ try {
352
+ const gas = ( await sortition . estimateGas . executeDelayedStakes ( delayedStakes ) ) . mul ( 150 ) . div ( 100 ) ; // 50% extra gas
353
+ const tx = await ( await sortition . executeDelayedStakes ( delayedStakes , { gasLimit : gas } ) ) . wait ( ) ;
354
+ logger . info ( `executeDelayedStakes txID: ${ tx ?. transactionHash } ` ) ;
355
+ } catch ( e ) {
356
+ handleError ( e ) ;
357
+ }
358
+ return success ;
359
+ } ;
360
+
326
361
const getMissingJurors = async ( dispute : { id : string ; currentRoundIndex : string } ) => {
327
362
const { core } = await getContracts ( ) ;
328
363
const { nbVotes, drawnJurors } = await core . getRoundInfo ( dispute . id , dispute . currentRoundIndex ) ;
@@ -594,18 +629,9 @@ async function main() {
594
629
// ----------------------------------------------- //
595
630
// EXECUTE DELAYED STAKES //
596
631
// ----------------------------------------------- //
597
- // delayedStakes = 1 + delayedStakeWriteIndex - delayedStakeReadIndex
598
- const delayedStakes = BigNumber . from ( 1 )
599
- . add ( await sortition . delayedStakeWriteIndex ( ) )
600
- . sub ( await sortition . delayedStakeReadIndex ( ) ) ;
601
632
602
633
if ( await isPhaseStaking ( ) ) {
603
- if ( delayedStakes . gt ( 0 ) ) {
604
- logger . info ( "Executing delayed stakes" ) ;
605
- await sortition . executeDelayedStakes ( delayedStakes ) ;
606
- } else {
607
- logger . info ( "No delayed stakes to execute" ) ;
608
- }
634
+ await executeDelayedStakes ( ) ;
609
635
}
610
636
611
637
await sendHeartbeat ( ) ;
0 commit comments