FreeBSD Crypto - Setup BTCD Full Node Bitcoin With Go Lang

btcd is an alternative full node bitcoin implementation written in the Go programming language (Go Lang). The btcd project is under active development and is in Beta status. The stability of btcd is no less than Bitcoin Core, and has been used in production since October 2013.

When you are using Bitcoin Core or any other implementation of the Bitcoin protocol, you are trusting the software to implement the protocol correctly and handle all operations correctly. One of the most amazing advantages about the Bitcoin network is that it can protect itself from malicious or badly behaved nodes. The first and still popular full-node client implementation today was Bitcoin. Bitcoin core is the original client released by Satoshi Nakamoto. The Bitcoin project is open source and actively maintained by the Bitcoin community. Installable binaries are at bitcoin.org for any platform of choice.

Apart from Bitcoin core, another well-known client is BTCD by Conformal Systems. Btcd implements most of the core functions of a node except wallet and chain functions. The team instead separated the wallet functionality into a separate wallet application called btcwallet. The btcd Client App also has minor differences from Bitcoin core, such as enabling TLS for RPC connections by default and accepting HTTP and Websockets requests. btcWallet is a hierarchical deterministic (HD) bitcoin wallet client for a single user. It acts as an RPC client for btcd and an RPC server for wallet clients and legacy RPC applications. btcWAllet uses the HD path for BIP0044 address derivation and encrypts the private key and public data.

Btcd can download, validate and serve the block chain correctly using the proper rules for block acceptance as Bitcoin Core. In working on this project, the development team was very careful to avoid btcd causing forks in the block chain. This work includes a full block validation testing framework containing all the 'official' block acceptance tests (and some additional tests) that are run on each pull request to help ensure it follows consensus correctly. Additionally, Btcd can pass all JSON test data in Bitcoin Core code.

The advantages of Btcd are not only that, Btcd clients can convey newly mined blocks correctly, maintain a collection of transactions, and convey individual transactions that have not yet been included in the block. All of this can ensure all individual transactions accepted into the pool follow the rules required by the blockchain and also include stricter checks by filtering transactions based on miner requirements.


1. Btcd installation

One of the basic differences between Btcd and Bitcoin Core is that Btcd does NOT include a wallet function and this was the decision of the Btcd developers, to differentiate between Bitcoin core and Btcd. With no wallet function, you cannot make or receive payments directly with Btcd. The functionality is provided by the btcwallet and Paymetheus projects (Windows only) which are both under active development.

Because Btcd is written in the Go language, the main requirement for installing it is that Go must be installed on the FreeBSD server. You can read our previous article about the Go lang installation process on FreeBSSD


For those of you who are used to installing Bitcoin core, it will definitely be very easy to install Btcd. Even though there are many feature abstractions, the configuration process is almost the same as Bitcoin Core. Btcd also has an RPC interface that is compatible with Bitcoin core. Apart from the wallet and blockchain features, everything is almost the same as Bitcoin core.

FreeBSD does not provide a PKG package or port system for Btcd, you have to download it from the official Btcd repository on Github. Follow the instructions below to start Btcd configuration.
root@ns7:~ # cd /usr/local/etc
root@ns7:/usr/local/etc # git clone https://github.com/btcsuite/btcd.git
root@ns7:/usr/local/etc # cd btcd
root@ns7:/usr/local/etc/btcd #
Run the following command to update btcd, all dependencies, and install it on FreeBSD.
root@ns7:/usr/local/etc/btcd # mkdir -p bin
root@ns7:/usr/local/etc/btcd # git pull
Already up to date.
root@ns7:/usr/local/etc/btcd # go install -v . ./cmd/...
The above install command will create a bin executable file. On FreeBSD the location of the Btcd bin file is /root/go/bin. It's up to you whether you want to move the bin file or not. We recommend moving the file to the Btcd folder.
root@ns7:/usr/local/etc/btcd # mv /root/go/bin/* /usr/local/etc/btcd/bin


2. Btcd Configuration

Because Btcd and Bitcoin core are in the same family, the configuration method is almost the same. In FreeBSD the location of the Btcd data file is "/root/.btcd". Copy the "/usr/local/etc/btcd/sample-btcd.conf" file, to the "/root/.btcd" folder. Follow these commands to copy it.
root@ns7:/usr/local/etc/btcd # mkdir -p /root/.btcd
root@ns7:/usr/local/etc/btcd # mkdir -p /root/.btcd/data
root@ns7:/usr/local/etc/btcd # cp /usr/local/etc/btcd/sample-btcd.conf /root/.btcd/btcd.conf
The command above is used to create a .btcd folder and copy and rename the sample-btcd.conf file to btcd.conf.

To better understand how to configure Btcd, run the command btcd -help to see where we will place our configuration options.

root@ns7:/usr/local/etc/btcd # cd bin
root@ns7:/usr/local/etc/btcd/bin # ./btcd -h
Usage:
  btcd [OPTIONS]

Application Options:
      --addcheckpoint=        Add a custom checkpoint.  Format: '<height>:<hash>'
  -a, --addpeer=              Add a peer to connect with at startup
      --addrindex             Maintain a full address-based transaction index which makes the searchrawtransactions RPC available
      --agentblacklist=       A comma separated list of user-agent substrings which will cause btcd to reject any peers whose user-agent contains any of the blacklisted
                              substrings.
      --agentwhitelist=       A comma separated list of user-agent substrings which will cause btcd to require all peers' user-agents to contain one of the whitelisted
                              substrings. The blacklist is applied before the blacklist, and an empty whitelist will allow all agents that do not fail the blacklist.
      --banduration=          How long to ban misbehaving peers.  Valid time units are {s, m, h}.  Minimum 1 second (default: 24h0m0s)
      --banthreshold=         Maximum allowed ban score before disconnecting and banning misbehaving peers. (default: 100)
      --blockmaxsize=         Maximum block size in bytes to be used when creating a block (default: 750000)
      --blockminsize=         Minimum block size in bytes to be used when creating a block
      --blockmaxweight=       Maximum block weight to be used when creating a block (default: 3000000)
      --blockminweight=       Minimum block weight to be used when creating a block
      --blockprioritysize=    Size in bytes for high-priority/low-fee transactions when creating a block (default: 50000)
      --blocksonly            Do not accept transactions from remote peers.
  -C, --configfile=           Path to configuration file (default: /root/.btcd/btcd.conf)
      --connect=              Connect only to the specified peers at startup
      --cpuprofile=           Write CPU profile to the specified file
      --memprofile=           Write memory profile to the specified file
  -b, --datadir=              Directory to store data (default: /root/.btcd/data)
      --dbtype=               Database backend to use for the Block Chain (default: ffldb)
  -d, --debuglevel=           Logging level for all subsystems {trace, debug, info, warn, error, critical} -- You may also specify <subsystem>=<level>,<subsystem2>=<level>,...
                              to set the log level for individual subsystems -- Use show to list available subsystems (default: info)
      --dropaddrindex         Deletes the address-based transaction index from the database on start up and then exits.
      --dropcfindex           Deletes the index used for committed filtering (CF) support from the database on start up and then exits.
      --droptxindex           Deletes the hash-based transaction index from the database on start up and then exits.
      --externalip=           Add an ip to the list of local addresses we claim to listen on to peers
      --generate              Generate (mine) bitcoins using the CPU
      --limitfreerelay=       Limit relay of transactions with no transaction fee to the given amount in thousands of bytes per minute (default: 15)
      --listen=               Add an interface/port to listen for connections (default all interfaces port: 8333, testnet: 18333)
      --logdir=               Directory to log output. (default: /root/.btcd/logs)
      --maxorphantx=          Max number of orphan transactions to keep in memory (default: 100)
      --maxpeers=             Max number of inbound and outbound peers (default: 125)
      --miningaddr=           Add the specified payment address to the list of addresses to use for generated blocks -- At least one address is required if the generate option
                              is set
      --minrelaytxfee=        The minimum transaction fee in BTC/kB to be considered a non-zero fee. (default: 1e-05)
      --nobanning             Disable banning of misbehaving peers
      --nocfilters            Disable committed filtering (CF) support
      --nocheckpoints         Disable built-in checkpoints.  Don't do this unless you know what you're doing.
      --nodnsseed             Disable DNS seeding for peers
      --nolisten              Disable listening for incoming connections -- NOTE: Listening is automatically disabled if the --connect or --proxy options are used without also
                              specifying listen interfaces via --listen
      --noonion               Disable connecting to tor hidden services
      --nopeerbloomfilters    Disable bloom filtering support
      --norelaypriority       Do not require free or low-fee transactions to have high priority for relaying
      --nowinservice          Do not start as a background service on Windows -- NOTE: This flag only works on the command line, not in the config file
      --norpc                 Disable built-in RPC server -- NOTE: The RPC server is disabled by default if no rpcuser/rpcpass or rpclimituser/rpclimitpass is specified
      --nostalldetect         Disables the stall handler system for each peer, useful in simnet/regtest integration tests frameworks
      --notls                 Disable TLS for the RPC server -- NOTE: This is only allowed if the RPC server is bound to localhost
      --onion=                Connect to tor hidden services via SOCKS5 proxy (eg. 127.0.0.1:9050)
      --onionpass=            Password for onion proxy server
      --onionuser=            Username for onion proxy server
      --profile=              Enable HTTP profiling on given port -- NOTE port must be between 1024 and 65536
      --proxy=                Connect via SOCKS5 proxy (eg. 127.0.0.1:9050)
      --proxypass=            Password for proxy server
      --proxyuser=            Username for proxy server
      --prune=                Prune already validated blocks from the database. Must specify a target size in MiB (minimum value of 1536, default value of 0 will disable
                              pruning)
      --regtest               Use the regression test network
      --rejectnonstd          Reject non-standard transactions regardless of the default settings for the active network.
      --rejectreplacement     Reject transactions that attempt to replace existing transactions within the mempool through the Replace-By-Fee (RBF) signaling policy.
      --relaynonstd           Relay non-standard transactions regardless of the default settings for the active network.
      --rpccert=              File containing the certificate file (default: /root/.btcd/rpc.cert)
      --rpckey=               File containing the certificate key (default: /root/.btcd/rpc.key)
      --rpclimitpass=         Password for limited RPC connections
      --rpclimituser=         Username for limited RPC connections
      --rpclisten=            Add an interface/port to listen for RPC connections (default port: 8334, testnet: 18334)
      --rpcmaxclients=        Max number of RPC clients for standard connections (default: 10)
      --rpcmaxconcurrentreqs= Max number of concurrent RPC requests that may be processed concurrently (default: 20)
      --rpcmaxwebsockets=     Max number of RPC websocket connections (default: 25)
      --rpcquirks             Mirror some JSON-RPC quirks of Bitcoin Core -- NOTE: Discouraged unless interoperability issues need to be worked around
  -P, --rpcpass=              Password for RPC connections
  -u, --rpcuser=              Username for RPC connections
      --sigcachemaxsize=      The maximum number of entries in the signature verification cache (default: 100000)
      --simnet                Use the simulation test network
      --signet                Use the signet test network
      --signetchallenge=      Connect to a custom signet network defined by this challenge instead of using the global default signet test network -- Can be specified multiple
                              times
      --signetseednode=       Specify a seed node for the signet network instead of using the global default signet network seed nodes
      --testnet               Use the test network
      --torisolation          Enable Tor stream isolation by randomizing user credentials for each connection.
      --trickleinterval=      Minimum time between attempts to send new inventory to a connected peer (default: 10s)
      --utxocachemaxsize=     The maximum size in MiB of the UTXO cache (default: 250)
      --txindex               Maintain a full hash-based transaction index which makes all transactions available via the getrawtransaction RPC
      --uacomment=            Comment to add to the user agent -- See BIP 14 for more information.
      --upnp                  Use UPnP to map our listening port outside of NAT
  -V, --version               Display version information and exit
      --whitelist=            Add an IP network or IP that will not be banned. (eg. 192.168.1.0/24 or ::1)

Help Options:
  -h, --help                  Show this help message

Now you can edit the btcd.conf file. Adjust the configuration to your computer equipment and FreeBSD server specifications.

After everything is configured, run Btcd with the command "./btcd"
root@ns7:/usr/local/etc/btcd/bin # ./btcd --configfile=/root/.btcd/btcd.conf
2024-01-11 17:21:32.586 [INF] BTCD: RPC service is disabled
2024-01-11 17:21:32.586 [INF] BTCD: Version 0.24.0-beta
2024-01-11 17:21:32.586 [INF] BTCD: Loading block database from '/root/.btcd/data/mainnet/blocks_ffldb'
2024-01-11 17:21:32.647 [INF] BTCD: Block database loaded
2024-01-11 17:21:32.673 [INF] INDX: Committed filter index is enabled
2024-01-11 17:21:32.673 [INF] CHAN: Pre-alloacting for 251 MiB:
2024-01-11 17:21:32.805 [INF] INDX: Catching up indexes from height -1 to 0
2024-01-11 17:21:32.805 [INF] INDX: Indexes caught up to height 0
2024-01-11 17:21:32.805 [INF] CHAN: Chain state (height 0, hash 000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f, totaltx 1, work 4295032833)
2024-01-11 17:21:32.806 [INF] AMGR: Loaded 0 addresses from file '/root/.btcd/data/mainnet/peers.json'
2024-01-11 17:21:32.806 [INF] CMGR: Server listening on [::]:8333
2024-01-11 17:21:32.807 [INF] CMGR: Server listening on 0.0.0.0:8333
2024-01-11 17:21:33.065 [INF] CMGR: 40 addresses found from DNS seed seed.bitnodes.io
2024-01-11 17:21:33.178 [INF] CMGR: 37 addresses found from DNS seed seed.bitcoinstats.com
2024-01-11 17:21:33.345 [INF] CMGR: 37 addresses found from DNS seed seed.btc.petertodd.net
2024-01-11 17:21:33.480 [INF] CMGR: 37 addresses found from DNS seed seed.bitcoin.jonasschnelli.ch
2024-01-11 17:21:34.456 [INF] CMGR: 39 addresses found from DNS seed seed.bitcoin.sipa.be
2024-01-11 17:21:34.643 [INF] CMGR: 31 addresses found from DNS seed dnsseed.bluematt.me
2024-01-11 17:21:37.933 [INF] SYNC: New valid peer 155.137.251.136:8333 (outbound) (/Satoshi:25.0.0/)
2024-01-11 17:21:37.933 [INF] SYNC: Syncing to block height 825278 from peer 155.137.251.136:8333
2024-01-11 17:21:37.933 [INF] SYNC: Downloading headers for blocks 1 to 11111 from peer 155.137.251.136:8333
2024-01-11 17:21:38.174 [INF] SYNC: New valid peer 93.176.165.238:8333 (outbound) (/Satoshi:25.0.0/)
2024-01-11 17:21:38.196 [INF] SYNC: New valid peer 89.149.200.202:8333 (outbound) (/Satoshi:24.0.1/)
2024-01-11 17:21:38.217 [INF] SYNC: New valid peer 81.106.103.172:8333 (outbound) (/Satoshi:25.1.0/)
2024-01-11 17:21:38.245 [INF] SYNC: New valid peer 65.21.199.219:8333 (outbound) (/Satoshi:24.0.1/)
2024-01-11 17:21:38.530 [INF] SYNC: Verified downloaded block header against checkpoint at height 11111/hash 0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d
2024-01-11 17:21:38.530 [INF] SYNC: Received 11111 block headers: Fetching blocks
2024-01-11 17:21:38.641 [INF] SYNC: Lost peer 81.106.103.172:8333 (outbound)
2024-01-11 17:21:39.161 [INF] SYNC: New valid peer 131.188.40.47:8333 (outbound) (/Satoshi:26.0.0/)
2024-01-11 17:21:39.169 [INF] SYNC: Lost peer 89.149.200.202:8333 (outbound)
2024-01-11 17:21:42.374 [INF] CHAN: Verified checkpoint at height 11111/block 0000000069e244f73d78e8fd29ba2fd2ed618bd6fa2ee92559f542fdb26e7c1d
2024-01-11 17:21:42.374 [INF] SYNC: Downloading headers for blocks 11112 to 33333 from peer 155.137.251.136:8333
2024-01-11 17:21:42.891 [INF] CMGR: 1 addresses found from DNS seed dnsseed.bitcoin.dashjr.org
2024-01-11 17:21:43.222 [INF] SYNC: Verified downloaded block header against checkpoint at height 33333/hash 000000002dd5588a74784eaa7ab0507a18ad16a236e7b1ce69f00d7ddfb5d0a6
2024-01-11 17:21:43.222 [INF] SYNC: Received 22222 block headers: Fetching blocks
^C2024-01-11 17:21:43.577 [INF] BTCD: Received signal (interrupt).  Shutting down...
2024-01-11 17:21:43.578 [INF] BTCD: Gracefully shutting down the server...
2024-01-11 17:21:43.578 [WRN] SRVR: Server shutting down
2024-01-11 17:21:43.578 [INF] SYNC: Lost peer 155.137.251.136:8333 (outbound)
2024-01-11 17:21:43.578 [INF] SYNC: Sync manager shutting down
2024-01-11 17:21:43.581 [INF] SYNC: Syncing to block height 825279 from peer 65.21.199.219:8333
2024-01-11 17:21:43.581 [INF] SYNC: Downloading headers for blocks 11112 to 33333 from peer 65.21.199.219:8333
2024-01-11 17:21:43.581 [INF] CHAN: Flushing UTXO cache of 98 MiB with 10594 entries to disk. For large sizes, this can take up to several minutes...
The sync process may take 3-4 days, depending on your internet connection and machine specifications. But you can start testing the blockchain data beforehand while it is synchronizing. Use bitcoin testnet by adding the --testnet flag to btcd. This way you can easily test transactions with testnet coins.
Iwan Setiawan

I Like Adventure: Mahameru Mount, Rinjani Mount I Like Writer FreeBSD

Post a Comment

Previous Post Next Post