#!/bin/bash # @Author Rockyang # check all running jobs and find the sectors TicketEpoch # if a sector's TicketEpoch < ticketEarliest # then abort the task and remove this sector # ticketEarliest = EpochsInDay(2880) + SealRandomnessLookback(900) if [ "$1" != "really-do-it" ]; then echo "Usage: $0 [really-do-it]" exit 0 fi loger() { if [ "$2" == "true" ];then echo -n `date '+%Y-%m-%d %H:%M:%S'` $1 else echo `date '+%Y-%m-%d %H:%M:%S'` $1 fi } height=$(/usr/local/bin/yy_lotus chain list --count=1 |awk -F ':' '{print $1}') pc1_expire=3780 # PC1 task expired epochs pc2_expire=3700 # PC2 task expired epochs if [ ! $height ]; then log "Can not get the current chain height." exit 1 fi loger "Current chain height: $height." counter=1 /usr/local/bin/yy_lotus-miner sealing jobs |grep -E "PC1|PC2" |grep run |while read line do job_id=`echo "$line" | awk -F ' ' '{print $1}'` sector_id=`echo "$line" | awk -F ' ' '{print $2}'` task=`echo "$line" | awk -F ' ' '{print $5}'` #echo $job_id, $sector_id # get sector's ticket epoch ticket_epoch=$(/usr/local/bin/yy_lotus-miner sectors status --log $sector_id |grep TicketEpoch |awk -F ',' 'END {print $2}' |awk -F ':|}' '{print $2}') diff=$[$height-$ticket_epoch] expire=$pc1_expire # if the jobs is PC1, then delay 4h if [ $task == "PC1" ]; then expire=$pc2_expire fi if [ $diff -gt $expire ]; then loger "Sector $sector_id ticket expired, task: $task, height diff: $diff, ticketEpoch: $ticket_epoch, counter: $counter" loger "Try to abort task $job_id ..." /usr/local/bin/yy_lotus-miner sealing abort $job_id sleep 2 loger "Try to remove sector $sector_id ..." true /usr/local/bin/yy_lotus-miner sectors remove --really-do-it=true $sector_id echo " [OK]." let counter+=1 fi done loger "All task done."