Linux Pos Helping Scripts

Discussion in 'Proof-of-stake Mining' started by brencelj, Mar 14, 2016.

  1. 2017/12/15 - Decred v1.1.2 released! → Release Notes  → Downloads
  1. brencelj

    brencelj New Member

    Jan 10, 2016
    49
    17
    #1 brencelj, Mar 14, 2016
    Last edited: Apr 8, 2016
    I have created 2 scripts for Linux PoS miners. One is a start-up script and second one is a report one.

    I would like to thank @Kandiru, @drunkenmugsy and @root for a few better hacks.
    Special thanks to @karamble who's code I added to my script because it was a good add-on :).
    If I forgot to mention anyone I'm sorry and pleas do tell me so I will add you.

    Adding username and password in config files in .dcrd, .dcrwallet and .dcrctl folders. you have to run it as a user that runs dcrd, dcrwallet and dcrctl. You need nano in you Linux most of them do.

    Config:
    nano ~/.dcrctl/dcrctl.conf
    Code:
    [Application Options]
    
    rpcuser=USER
    rpcpass=PASS
    
    nano ~/.dcrd/dcrd.conf
    Code:
    [Application Options]
    
    rpcuser=USER
    rpcpass=PASS
    
    nano ~/.dcrwallet/dcrwallet.conf
    Code:
    [Application Options]
    
    username=USER
    password=PASS
    

    Auto-start script (UPDATED 30.03.2016):
    Code:
    #! /bin/sh
    # Set all the paths and DCR values for ticket price, fee and how much to maintain
    homeFolder="<YOUR HOME FOLDER>"
    decredFolder="$homeFolder/<YOUR FOLDER>"
    dcrdFolder="$homeFolder/<YOUR FOLDER>"
    dcrwalletFolder="$homeFolder/<YOUR FOLDER>"
    walletPassPhrase="<YOUR PASSWORD>"
    balanceToMaintain="<YOUR BALANCE>"
    ticketMaxPrice="<YOUR PRICE>"
    maxFee="<YOUR PRICE>" # Original is 0.05
    
    noConfig="false"
    runInScreen="no"
    configText=""
    printf "Starting decred PoS mining!\n"
    printf "Checking if you have config files for dcrd, dcrwallet and dcrctl ........ "
    
    if [ ! -f "$homeFolder/.dcrd/dcrd.conf" ]; then
      configText="\nPleas create dcrd.conf."
      noConfig="true"
    fi
    
    if [ ! -f "$homeFolder/.dcrwallet/dcrwallet.conf" ]; then
      configtext="$configText\nPleas create dcrwallet.conf."
      noConfig="true"
    fi
    
    if [ ! -f "$homeFolder/.dcrctl/dcrctl.conf" ]; then
      configText="$configText\nPleas create dcrctl.conf."
      noConfig="true"
    fi
    if [[ "$noConfig" == "true"  ]]; then
      printf "failed"
      printf "$configText"
      exit
    fi
    printf "OK\n"
    
    if type "screen" > /dev/null; then
      printf "Do you want to run it in screen yes | no (no): "
      read runInScreen
    else
      printf "Install 'screen' if you want to run in it."
    fi
    
    printf "\nStarting dcrd ........ "
    if [ "$runInScreen" == "y" ] ||  [ "$runInScreen" == "yes"  ] || [ "$runInScreen" == "Yes"  ] || [ "$runInScreen" == "Y"  ]; then
      screen -dmS decred
      screen -S decred -p 0 -X exec $decredFolder/dcrd
      printf "OK\n"
      printf "Starting wallet ........ "
      while true; do
      dcrdLog=`tail $dcrdFolder/dcrd.log | grep -c "DNS seed"`
      if [[ $dcrdLog -gt 0 ]]; then
      screen -S decred -X screen $decredFolder/dcrwallet --enablestakemining --balancetomaintain=$balanceToMaintain --ticketmaxprice=$ticketMaxPrice
      printf "OK\n"
      break
      else
      sleep 1
      fi
      done
    else
      $decredFolder/dcrd > /dev/null &
      disown
      printf "OK\n"
      printf "Starting wallet ........ "
      while true; do
      dcrdLog=`tail $dcrdFolder/dcrd.log | grep -c "DNS seed"`
      if [[ $dcrdLog -gt 0 ]]; then
      $decredFolder/dcrwallet --enablestakemining --balancetomaintain=$balanceToMaintain --ticketmaxprice=$ticketMaxPrice > /dev/null &
      disown
      printf "OK\n"
      break
      else
      sleep 1
      fi
      done
    fi
    
    printf "Unlocking wallet ........ "
    while true; do
      dcrwalletLog=`tail $dcrwalletFolder/dcrwallet.log | grep -c "PLEASE ENSURE YOUR WALLET"`
      if [[ $dcrwalletLog -gt 0 ]]; then
      $decredFolder/dcrctl --wallet walletpassphrase $walletPassPhrase 0
      printf "OK\n"
      break
      else
      sleep 1
      fi
    done
    
    printf "Cleaning missed / revoked tickets ........ "
    $decredFolder/dcrctl rebroadcastmissed
    printf "OK\n"
    
    printf "Setting a fee ........ "
    $decredFolder/dcrctl --wallet settxfee $maxFee > /dev/null
    $decredFolder/dcrctl --wallet setticketfee $maxFee > /dev/null
    printf "OK\n"
    printf "PoS mining succefully started!\n"

    Report script (UPDATED 16.03.2016):
    Code:
    #! /bin/sh
    
    dcrwalletLogFolder="/home/brencelj/.dcrwallet/logs/mainnet/"
    decredFolder="/home/brencelj/decred/"
    
    cd $decredFolder
    balanceAll=`./dcrctl --wallet getbalance 'default' 0 all`
    balanceLocked=`./dcrctl --wallet getbalance 'default' 0 locked`
    balanceSpendable=`./dcrctl --wallet getbalance 'default' 0 spendable`
    stakeInfo=`./dcrctl --wallet getstakeinfo`
    maxPrice=`./dcrctl --wallet getticketmaxprice`
    ticketFee=`./dcrctl --wallet getticketfee`
    blockcount=`./dcrctl getblockcount`
    
    balanceWon=`echo $stakeInfo | grep -aEo '"totalsubsidy": [0-9\.]*,' | sed -ne 's/,//p' | sed -ne 's/\"totalsubsidy\":.//p'`
    votesCount=`echo $stakeInfo | grep -aEo '"voted": [0-9\.]*,' | sed -ne 's/,//p' | sed -ne 's/\"voted\":.//p'`
    missedVotesCount=`echo $stakeInfo | grep -aEo '"missed": [0-9\.]*,' | sed -ne 's/,//p' | sed -n -e 's/\"missed\":.//p'`
    revokedVotesCount=`echo $stakeInfo | grep -aEo '"revoked": [0-9\.]*' | sed -n -e 's/\"revoked\":.//p'`
    ticketPrice=`echo $stakeInfo | grep -aEo '"difficulty": [0-9\.]*,'| sed -ne 's/,//p' | sed -n -e 's/\"difficulty\":.//p'`
    ticketsImatureCount=`echo $stakeInfo | grep -aEo '"immature": [0-9\.]*,' | sed -ne 's/,//p' | sed -n -e 's/\"immature\":.//p'`
    ticketsMatureCount=`echo $stakeInfo | grep -aEo '"live": [0-9\.]*,' | sed -ne 's/,//p' | sed -n -e 's/\"live\":.//p'`
    
    cd $dcrwalletLogFolder
    votedTicketsPerDay=`cat dcrwallet.log | grep -a Voted | grep -ao "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]" | uniq -c | tr -d '\n' | sed 's/\s\{3,\}/  |  /g'`
    buyCount=`cat dcrwallet.log | grep -a SStx | wc -l`
    boughtTicketsPerDay=`cat dcrwallet.log | grep -a SStx | grep -ao "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]" | uniq -c | tr -d '\n' | sed 's/\s\{3,\}/  |  /g'`
    revokedTicketsPerDay=`cat dcrwallet.log | grep -a Revoked | grep -ao "[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]" | uniq -c | tr -d '\n' | sed 's/\s\{3,\}/  |  /g'`
    dateNow=`date +"%d-%b-%Y %X"`
    imatureFunds=`awk -va=$balanceAll -vl=$balanceLocked -vs=$balanceSpendable 'BEGIN{printf "%.8f" , a-l-s}'`
    rewardblock=`cat dcrwallet.log | grep -a Voted  | cut -d "(" -f2 | cut -d ")" -f1 | sed -e 's/height / /g' | tr -d "\n" |{
      read line;
      for i in $line; do
      payblock="$((i +256))";
      if [ $payblock -gt $blockcount ]; then
      echo -n "$payblock ";
      fi
      done;
      echo
    }`
    
    echo ""
    echo "########## Decred report ##########"
    echo ""
    echo "  $dateNow"
    echo ""
    echo "  **Money**"
    echo "  All:  $balanceAll"
    echo "  Locked:  $balanceLocked"
    echo "  Spendable:  $balanceSpendable"
    echo "  Immature:  $imatureFunds"
    echo "  Won:  $balanceWon"
    echo ""
    echo "  **Tickets**"
    echo "  All:  $(($ticketsImatureCount+$ticketsMatureCount))"
    echo "  Mature:  $ticketsMatureCount"
    echo "  Immature:  $ticketsImatureCount"
    echo "  Price Now:  $ticketPrice"
    echo "  My Price:  $maxPrice"
    echo "  My Fee:  $ticketFee"
    echo ""
    echo "  **Bought Tickets Per Day**"
    echo "  $boughtTicketsPerDay  |"
    echo ""
    echo "  **Votes**"
    echo "  Done:  $votesCount"
    echo "  Missed:  $(($missedVotesCount-$revokedVotesCount))"
    echo "  Revoked:  $revokedVotesCount"
    echo "  Bought:  $buyCount"
    echo "  Failed:  $missedVotesCount"
    echo ""
    echo "  **Voted Tickets Per Day**"
    echo "  $votedTicketsPerDay  |"
    echo ""
    echo "  **Reward Paying Block**"
    echo "  Current Block: $blockcount"
    echo "  Upcoming Reward Blocks: $rewardblock"
    echo ""
    echo "###################################"
    echo ""
    UPDATED 15.03.2016 (Auto-start script)
    - added dcrctl rebroadcastmissed as suggested by @root

    UPDATED 16.03.2016 (Report script)
    - added immature funds or funds that aren't yet received because of 254 block wait or something else suggested by @sambiohazard in other topic

    UPDATED 18.03.2016 (Config part)
    - added how to create config files for username and password for dcred, dcrwallet and dcrctl on a request of @ImpellitterI

    UPDATED 20.03.2016 (Auto-start script)
    - added setting a fee

    UPDATED 30.3.2016 (Auto-start script)
    - added option for rung it in a screen
    - added checking if you have screen installed
    - added checking if you have config files for dcrd, dcrwallet and dcrctl
    - changed text preview
     
  2. root

    root Member

    Feb 3, 2016
    381
    76
    Nice !
    Added
    # dcrctl rebroadcastmissed
    to clean missed / revoked
     
    brencelj likes this.
  3. brencelj

    brencelj New Member

    Jan 10, 2016
    49
    17
    added to the first post code :) Thank you
     
  4. brencelj

    brencelj New Member

    Jan 10, 2016
    49
    17
  5. sambiohazard

    sambiohazard Sr. Member

    Jan 21, 2016
    844
    372
    No problem, i hope others will donate too. I am not using your scripts but i think "Donation is motivation".
     
    ClokworkGremlin and brencelj like this.
  6. ImpellitterI

    ImpellitterI New Member

    Jan 11, 2016
    57
    2
    Male
    nice scripts.
    how can i hidden my -u and -P ?
    can u explain step-by-step ?
    tks
     
  7. brencelj

    brencelj New Member

    Jan 10, 2016
    49
    17
    Aha you don't hide it you put it in a config file will do that in first post :D
     
  8. ImpellitterI

    ImpellitterI New Member

    Jan 11, 2016
    57
    2
    Male
    thank you very much :D
    i need to stop my daemons ?
     
  9. brencelj

    brencelj New Member

    Jan 10, 2016
    49
    17
    well if you started them with -u and -p in them than you can leave them on and crate this files for next restart of daemons which will be today after version 0.0.8. But you can create this files while they are running it shouldn't create any problems. or you can wait until the new relese and do all than :)
     
  10. vhaigent

    vhaigent New Member

    Apr 11, 2016
    9
    0
    Male
    China
    Tested on v0.0.10

    I think that rebroadcastmissed and getblockcount should be called with --wallet.
     
  11. brencelj

    brencelj New Member

    Jan 10, 2016
    49
    17
    May I ask where did you see that because for me my two commands work as they should
     
  12. root

    root Member

    Feb 3, 2016
    381
    76
    I can call any command through --wallet (only 'stop' has to be called with daemon / wallet respectively).
    It seems to be working just fine.
     
  13. brencelj

    brencelj New Member

    Jan 10, 2016
    49
    17
    Can you elaborate this a bit more. I'm confuse what you wanted to say.
     
  14. root

    root Member

    Feb 3, 2016
    381
    76
    I am sorry for my English. I mean you have daemon commands and wallet commands. I was able to call all through dcrctl --wallet CMD to get the result. For example dcrctl getinfo prints the result,
    but can be called as dcrctl --wallet getinfo to get even more details.
    Or even validateaddress etc...
     
  15. brencelj

    brencelj New Member

    Jan 10, 2016
    49
    17
    Aha OK yeah well I thought that rebroadcastmissed and getblockcount need now --wallet now so that is why I asked and since for me it works without it I didn't change anything
     
  16. Ealves

    Ealves New Member

    Apr 28, 2016
    4
    1
    Male
    Brazil
    How calculate expire tickets
     
  17. Ealves

    Ealves New Member

    Apr 28, 2016
    4
    1
    Male
    Brazil
  18. brencelj

    brencelj New Member

    Jan 10, 2016
    49
    17
    @Ealves It is all recorded in your log file but if you don't have log file it won't show the correct number.
     
  19. Ivan Orellana

    Ivan Orellana New Member

    Jul 6, 2016
    1
    0
    Male
    Caracas
    Hi @brencelj have you used the report script lately? I think it is not working with vers 0.8.2.

    Looks like the getbalance command syntax has changed and broke the script:
    getbalance ("account" minconf=1)
    getbalance command: wrong number of params (expected between 0 and 2, received 3) (code: ErrNumParams)
     

Share This Page