Tutorial: Getting A Dedicated Chain Server Set Up On Your Raspberry Pi 2

Discussion in 'Technical Support' started by ClokworkGremlin, Jan 30, 2016.

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

    ClokworkGremlin Sr. Member

    Jan 10, 2016
    535
    381
    Male
    Whatever I want.
    #1 ClokworkGremlin, Jan 30, 2016
    Last edited: Jul 22, 2017
    ****ANNOUNCEMENT!****
    Due to software updates since Decred was initially launched, this tutorial won't work 100% anymore. I will be updating it to work with DCRD v1.0.1 and later soon.

    Tutorial
    One of the neat things about the Raspberry Pi, beyond the whole "fully functional Linux computer for under $100 US," is that since it takes all its power from a USB port, keeping one running 24/7 is super cheap. I have one I bought to use as a Mumble server, but it turns out Mumble consumes so few resources that it may as well not even be running for all the rest of the system cares. So here I am with a computer that I need to keep running all the time, but the CPU is pretty much idle, and the 32GB micro-SD card I bought for it is pretty much empty.

    Hey, let's use it as a Decred full node.

    Step 1: Setting up dcrd to listen to foreign ports
    So I'm going to assume you've already followed the quick reference guide to get everything running on the Pi. You're starting dcrd with the command
    Code:
    ./dcrd --testnet -u user -P pass
    or maybe you've got a shell script to do that for you, so you just have to type
    Code:
    ./start_dcrd.sh
    If you're really advanced, maybe you have a config file that takes care of the username and password for you. If not, we're going to cover that.

    Q: Why should I use a config file

    A: There are a few reasons. One is security: using a config file lets you put the server's username and password there, so you aren't typing it in every time, which means it doesn't appear in your command history, and it isn't visible in the window title(for some operating systems). Another is convenience. Instead of having to make a shell script or batch file, or remember the whole list of command-line parameters, you can pack all of them into the config file and just run dcrd directly.

    Download pi_dcrd.conf.txt from the attached files, rename it dcrd.conf, and put it in the dcrd system directory.(that's .dcrd, in the home directory. If you can't see it, go to View in the file explorer's menu and make sure "Show Hidden" is checked.)
    Open the config file in your favorite text editor. Inside, it should look like this:
    Code:
    rpcuser=[dcrd_username]
    rpcpass=[dcrd_password]
    testnet=1
    rpclisten=:19109
    
    The first thing you'll want to do is change [username] and [password] to your chosen username and password. You can use [user] and [password] like the Quick Reference shows, and since we're just on the testnet right now there's nothing wrong with that, but you may want to change them to something a little more secure later.
    The second thing you'll want to do is check that last line. The one that says "rpclisten." That's where the magic happens. By default, dcrd is set up to only listen to localhost on port 19109(for the testnet. Mainnet will have a different port.) by adding a blank in there, we've told dcrd that we want it to listen to all incoming addresses. Like the other machine we're going to be running a wallet from at the end of this tutorial.
    [edit]
    February 8, 2016(Mainnet launch date) is now in the past instead of the future, so it's time to make sure you're set to run on the Mainnet instead of the Testnet!
    This is easy: change the testnet value from 1 to 0, then change the rpclisten value from 19109 to 9109, then run the Mainnet binaries instead of the Testnet binaries.
    [/edit]
    While we're here, grab the rpc.cert file
    rpc_cert.png and copy it to a safe place. We'll need it later.

    Now you should be able to start your chain server by just running the dcrd executable file.

    Step 2: (optional) Setting up the wallet on the Raspberry Pi

    Since we've got a host that's going to be running 24/7, why don't we also have a wallet running so we can stake and earn some credits off of this endeavor? This part is super easy. Do the same thing we just did to add the config file to dcrd, except we're doing it for dcrwallet. so download pi_dcrwallet.conf.txt, rename it to dcrwallet.conf, and put it in the .dcrwallet directory(which should now be visible right next to .dcrd, since you have hidden files turned on.)

    Inside of dcrwallet.conf, you'll find the following:
    Code:
    username=[wallet_username]
    password=[wallet_password]
    dcrdusername=[dcrd_username]
    dcrdpassword=[dcrd_password]
    enablestakemining=1
    balancetomaintain=100
    ticketmaxprice=50
    
    What's this? Two usernames and two passwords? What's real? I DON'T KNOW WHAT'S GOING ON ANYMORE!
    Well, it's actually easy. [wallet_username] and [wallet_password] are the username and password that you want to use to connect to the wallet via dcrdctl. [dcrd_username] and [dcrd_password] are the username and password you used when starting up dcrd, and are provided so that the wallet can connect to the chain server(dcrd) when it needs to.
    Note that dcrdusername and dcrdpassword are optional. If they are missing, dcrwallet will attempt to use [wallet_username] and [wallet_password] in their stead. Which is perfectly fine, but if you want to use a different(more secure, or just not re-use the same password for everything) password for your chain server, then the option is there.
    Code:
    enablestakemining=1
    [edit]As of wallet version 8.2, enablestakemining does nothing, and the correct lines should be:
    Code:
    enablevoting=1
    enableticketbuyer=1
    
    [/edit]
    This is what tells the wallet you want to be buying Proof of Stake tickets. If you don't want to buy those tickets, set enableticketbuyer to 0.
    Code:
    balancetomaintain=100
    This is the minimum number of credits you want the wallet to keep available for spending. When you buy a staking ticket, you don't actually lose any credits, but the credits used to "buy" that ticket become locked and unusable. This could be a problem if you wanted to buy, say, some silver bullion or fancy vinyl stickers.(Note that nobody will be accepting testnet credits, that's just silly.) If you set a balancetomaintain value, then the wallet will not buy any staking tickets if it would reduce your available funds below that level. Set this value to 0 if you don't care and just want to invest every penny you've got into earning interest.
    Code:
    ticketmaxprice=50
    This is the maximum number of credits the wallet will spend when buying a Proof of Stake ticket. The higher the value, the more tickets you'll be able to bid on, but the more of your credits will be tied up in buying tickets. Set this to 0 if you don't want to buy any staking tickets.

    Well that was easy! Now you can start the wallet by invoking dcrwallet directly, as well! Alright, now for the last step.

    Step 3: Setting up the second wallet to connect to the chain server remotely
    We're done with the Raspberry Pi now, switch to the computer you'll be using for everyday work. Mine is running MS Windows 8.1, so I will be referring to it as the "Windows" computer, but this last stage should work just fine on pretty much anything.

    This step assumes you already have a wallet running on your Windows computer which was generated using the same seed used to generate the one in step 2(if you followed step 2, anyway).

    You'll need 2 things for this step. 1 is that last config file, win_dcrwallet.conf.txt. Download it, rename it to dcrwallet.conf, and put it in the application directory on your Windows computer(%appdata%/local/Dcrwallet on Windows).

    Inside of that one, you'll see the following lines:
    Code:
    username=[wallet_username]
    password=[wallet_password]
    dcrdusername=[dcrd_username]
    dcrdpassword=[dcrd_password]
    rpcconnect=[pi_ip_address]:19109
    cafile=rpc.cert
    
    Same as before, [wallet_username] and [wallet_password] are what you use to connect to the wallet with dcrctl, [dcrd_username] and [dcrd_password] should be set to whatever you used all the way back in step 1. For [pi_ip_address], you want to use the IP address of your raspberry pi as it appears from your Windows computer. Mine is at 192.168.0.128(that's a LAN address, don't even bother trying), so for me, that line ends up looking like this:
    Code:
    rpcconnect=192.168.0.128:19109
    
    Finally, there's that last line. You remember in step 1, were we grabbed rpc.cert from the .dcrd directory? This is the certificate that tells the wallet it's connecting to the RIGHT chain server. It doesn't really matter where you put it on your Windows machine, as long as you set this to the relative path from dcrwallet.exe to rpc.cert, or the absolute path to rpc.cert. In my case, I've renamed it to "pidrpc.cert" and dropped it in the same directory, so for me, the line looks like this:
    Code:
    cafile=pidrpc.cert
    using a relative path, since those are usually shorter.
    [edit]Once again, if you're running on the Mainnet, you'll want the port to be 9109 instead of 19109.[/edit]

    That's it! You can now start up your wallet by executing it directly, and you can use it as a proxy to manage your chain server and wallet via dcrctl locally.

    [edit]Added information for the dcrdusename and dcrdpassword commands.
     

    Attached Files:

  2. davecgh

    davecgh Hero Member
    Developer Organizer

    Dec 31, 2015
    642
    788
    Male
    United States
    Excellent guide. Thank you for putting so much effort into it. A couple of minor things I noted are:

    • I think it's a bit unclear that step 2 and step 3 refer to two different wallets. The wallet in step 2 will be running on the pi while the wallet in step 3 is a separate one running on your desktop. The both need to be configured with the same seed so they generate the same addresses.
    • The final steps that talks about the relative path is only partially true. It can be either a relative or an absolute path.
    Another alternative to running two wallets is simply to configure dcrctl on your desktop to talk to the remote wallet on the rpi.
     
    David, ClokworkGremlin and tacotime like this.
  3. ClokworkGremlin

    ClokworkGremlin Sr. Member

    Jan 10, 2016
    535
    381
    Male
    Whatever I want.
    Thanks, I've made some changes that I hope will make your points clearer.
     
  4. davecgh

    davecgh Hero Member
    Developer Organizer

    Dec 31, 2015
    642
    788
    Male
    United States
    Nice updates. That makes it clear. Something else that might be worth mentioning is the I noticed in the config files you're not specifying the dcrdusername and dcrdpassword. This is fine if you want both the dcrd and dcrwallet RPC servers to use the same password since dcrwallet is smart enough to figure out this is what you want, but if you have a different username or password, you need to specify both the drcd credentials (--dcrdusername, --dcrdpassword) and the dcrwallet RPC server credentals (--username, --password).
     
    ClokworkGremlin likes this.
  5. anondran

    anondran Full Member
    Advocate (Reddit)

    Jan 13, 2016
    131
    119
    Male
    #5 anondran, Jan 30, 2016
    Last edited by a moderator: Jan 30, 2016
    ClokworkGremlin likes this.
  6. anondran

    anondran Full Member
    Advocate (Reddit)

    Jan 13, 2016
    131
    119
    Male
    @ClokworkGremlin I have some doubts,
    What's a chain server?Is chain server the same as running a full node?
    Can this be used to do PoS mining?
     
  7. davecgh

    davecgh Hero Member
    Developer Organizer

    Dec 31, 2015
    642
    788
    Male
    United States
    Well I'm sure Clokwork will be around to answer, but I'll answer in the mean time.

    The decred code base is split into two parts. The first is the chain server (dcrd). It handles everything related to the block chain, such as the consensus rules and the peer to peer networking aspects needed to sync it. Effectively it is the backbone and work horse of the entire network. Yes, running dcrd is running a full node.

    The second part is the wallet. This is what handles coins, private keys, deterministic key chains, etc.. Unlike with Bitcoin Core where it has all of the core chain functionality intermingled with the wallet functionality, in Decred, it is completely separate. While currently dcrwallet (and soon web-based copay) is the only wallet, I fully expect there to ultimately be a large variety of wallets just like there are in Bitcoin.

    Currently dcrwallet is implemented such that it asks dcrd for chain-related information it needs to maintain balances via the RPC server. This is why it needs to talk to dcrd via RPC. In the future an SPV style mode will be added where it no longer requires a full node to be running in order to perform its job. At that point, it will be able to connect to the Decred peer-to-peer network directly and make use of all of the dcrd nodes (full nodes) on the network.

    I know that currently it is a bit tedious to set things up with them split out, but there really are a lot of great properties about having them separated out for the long term. I suspect over time as more development happens those properties will become more apparent and there will be graphical front ends that handle all of the grunt work for you.
     
  8. anondran

    anondran Full Member
    Advocate (Reddit)

    Jan 13, 2016
    131
    119
    Male
    Thanks for the answer. Became a little more genius :)
    Many are interested in building GUI wallets and stuff.. Hoping to see them around soon
     
  9. ClokworkGremlin

    ClokworkGremlin Sr. Member

    Jan 10, 2016
    535
    381
    Male
    Whatever I want.
    Your post answered any questions better than I could anyway. I'm chiefly a graphics nerd, only just learning exactly how much I don't know about cryptography. I was just using the term "chain server" because that's what I've seen applied to the dcrd executable elsewhere. Actually, it's worth noting that this tutorial could not exist without @davecgh. Not only did he ask me to post it, but he provided almost all of the technical information while I was busy going through the motions.

    As for whether this setup can be used for PoS mining...
    tickets.png
    Outlook positive.

    (By the way, should I be careful about flashing around ticket hashes once the mainnet starts?)
     
    davecgh and anondran like this.
  10. davecgh

    davecgh Hero Member
    Developer Organizer

    Dec 31, 2015
    642
    788
    Male
    United States
    From a privacy standpoint, yes. This is because it's trivial for me to do this:

    Code:
    $ dcrctl getrawtransaction 225378f532811541448eecd03f49350380e96b27837273a2d94a9ec07b2baa09 1 | grep -C 1 addresses
      "type": "stakesubmission",
      "addresses": [
      "TsjsVA1Y1KYirjgPGANMnwt6N2nUETRapB6"
    --
      "type": "sstxchange",
      "addresses": [
      "TsigSF9ddn35ko3i2EZPdis7e3yYSxbyCpn"
    
    And now I know where your reward and change are going. From there I can keep following things and seeing what other addresses are associated with your transactions and figure out your balances with a pretty high degree of confidence.

    However, nobody can steal anything, so you don't have to worry about it from that standpoint.
     
  11. ClokworkGremlin

    ClokworkGremlin Sr. Member

    Jan 10, 2016
    535
    381
    Male
    Whatever I want.
    Good information. I wasn't worried in this case in part because I've seen them posted here already, and in part because they're testnet addresses. If doing something could lead to credits being stolen, we should be publicizing and testing it so that it can be documented and fixed.

    I actually did go through the trouble of obfuscating several columns of characters before I came to those conclusions, though.
     
  12. sambiohazard

    sambiohazard Sr. Member

    Jan 21, 2016
    844
    372
    @davecgh don't we have to open correct ports in the router to run a fullnode & accept incoming connections, apart from running dcrd?
     
  13. davecgh

    davecgh Hero Member
    Developer Organizer

    Dec 31, 2015
    642
    788
    Male
    United States
    Correct. If you want accept incoming connections you do need to open the appropriate ports (or use --upnp if you have a uPnP router). This is obviously ideal to help the network out and enable SPV nodes to exist.

    However, you're still running a full node even if you don't, you just aren't helping the network. A full node just means the block chain is being fully verified by the software (i.e every transaction, block, and script). Compare that with an SPV node where only the headers are validated to form a valid chain and transactions are checked for membership in the merkle root.
     
    chappjc likes this.
  14. sambiohazard

    sambiohazard Sr. Member

    Jan 21, 2016
    844
    372
    so by just including --upnp in dcrd command, i dont have to mess with my router settings? How can i find out if my router has uPnP?
     
  15. davecgh

    davecgh Hero Member
    Developer Organizer

    Dec 31, 2015
    642
    788
    Male
    United States
    Correct. Most home routers support it, but it might be disabled by default. You'd have to consult your router's documentation. That said, it sounds like you already know how to map the ports manually, so I'd suggest going that route.

    I'm not really a huge fan of uPnP in general since it essentially allows anything inside the network to programatically punch holes in the firewall. It's great from an end-user simplicity standpoint as it allow automatic mapping of external ports to internal ports without the user having to do anything.

    However, since I'm huge on proper security, the thought of allowing arbitrary apps (say that executable you downloaded to view your cat pictures!) to punch holes in the firewall doesn't sit well with me. That's why I always make sure to disable it if I have a router that supports it.
     
    Lee Sharp and sambiohazard like this.
  16. sambiohazard

    sambiohazard Sr. Member

    Jan 21, 2016
    844
    372
    I agree with you on security. I run a bitcoin full node so i learned about ports there. I will see if i can run both bitcoin & decred on same Pi.
     
    ClokworkGremlin likes this.
  17. ClokworkGremlin

    ClokworkGremlin Sr. Member

    Jan 10, 2016
    535
    381
    Male
    Whatever I want.
    My experience so far has been that the chain server and wallet combined take up fairly little CPU power and about 100MB of memory, so I assume it would work.
     
    sambiohazard likes this.
  18. Lee Sharp

    Lee Sharp Sr. Member

    Dec 28, 2015
    308
    217
    Male
    Independent Consultant
    Houston, Texas
    So... I write firewall software, so I am a bit biased. But as far as upnp goes; WHAT THE HELL ARE YOU THINKING? :eek:

    It is massively insecure, and the really bad malware and hacks are all upnp aware. Just use nat to pinnhome the needed ports and no others. I also log things like this, and review the logs. I have also been known to look for wordpress scans and bulk ban full ANs for it. Not to name names or anything...
    Code:
    58.17.30.0/23     Block China - ShangHai Shelian commpany
    59.69.128.0/19     Block China - Nanyang Institute of Technology
    61.164.145.0/24    Block China - Wenzhou Telecom Co.,ltd
    81.196.20.0/23     Block Romania - RCS & RDS S.A.
    82.213.64.0/19     Block Italy - MIPIACE.COM SPA
    111.0.0.0/10     Block China - China Mobile Communications Corporation
    125.23.218.0/24    Block India - Bharti Tele-Ventures Limited
    183.129.128.0/17    Block China - Zhejiang Telecom
    200.105.224.0/20    Block Ecuadore - PUNTONET S.A.
    203.99.130.0/23    Block Indonisa - PT. Varnion Technology Semesta
    210.83.84.64/26    Block China - China Unicom CncNet
    222.96.0.0/19    Block Korea - Korea Telcom
    24.117.106.66/19    Block Hostile Actor
    Paranoid by profession... :)
     
  19. davecgh

    davecgh Hero Member
    Developer Organizer

    Dec 31, 2015
    642
    788
    Male
    United States
    @Lee Sharp I agree about uPnP and said as much :)

     
    Lee Sharp likes this.
  20. Lee Sharp

    Lee Sharp Sr. Member

    Dec 28, 2015
    308
    217
    Male
    Independent Consultant
    Houston, Texas
    Sorry... But when anyone mentions upnp I start to get an uncontrollable tic and begin foaming at the mouth... :) And there is a special place in hell for the Microsoft and Sony support script writers that say "Just turn on upnp!"
     
    Fleshwound, .m. and drunkenmugsy like this.

Share This Page