lbcd

command module
v0.22.119 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 23, 2022 License: ISC Imports: 75 Imported by: 0

README

lbcd

Build Status Coverage Status ISC License

lbcd is a full node implementation of LBRY's blockchain written in Go (golang).

Software stack developed by LBRY teams has been all migrated to lbcd.

We're working with exchanges and pool oerators to migrate from lbrycrd to lbcd.

If you're integrating with lbcd+lbcwallet, please check the Wiki for current supported RPCs.

Note: lbcd does NOT include wallet functionality. That functionality is provided by the lbcwallet and the LBRY SDK.

Requirements

All common operating systems are supported. lbcd requires at least 8GB of RAM and at least 100GB of disk storage. Both RAM and disk requirements increase slowly over time. Using a fast NVMe disk is recommended.

Installation

Acquire binary files from releases

For compilation, Go 1.19 or newer is required. Install Go according to its installation instructions.

# lbcd (full node)
$ go install github.com/lbryio/lbcd@latest

# lbcctl (rpc client utility)
$ go install github.com/lbryio/lbcd/cmd/lbcctl@latest

Usage

Default application folder ${LBCDDIR}:

  • Linux: ~/.lbcd/
  • MacOS: /Users/<username>/Library/Application Support/Lbcd/
Start the lbcd
./lbcd

lbcd loads config file at "${LBCDDIR}/lbcd.conf".

If no config is found, it creates a default one, which includes all available options with default settings except randomly generated RPC credentials (see below).

RPC server

RPC credentials (rpcuser and rpcpass) is required to enable RPC server. It can be specify in the "${LBCDDIR}/lbcd.conf", using command line options:

./lbcd --rpcuser=rpcuser --rpcpass=rpcpass

2022-07-28 12:28:19.627 [INF] RPCS: RPC server listening on 0.0.0.0:9245
2022-07-28 12:28:19.627 [INF] RPCS: RPC server listening on [::]:9245
Working with TLS (Default)

By default, lbcd runs RPC server with TLS enabled, and generates the rpc.cert and rpc.key under ${LBCDDIR}, if not exist already.

To interact with the RPC server, a client has to either specify the rpc.cert, or disable the certification verification for TLS.

Interact with lbcd RPC using lbcctl

$ ./lbcctl --rpccert "${LBCDDIR}/rpc.cert" getblockcount

# or disable the certificate verification
$ ./lbcctl --skipverify getblockcount

1200062

Interact with lbcd RPC using curl

$ curl --user rpcuser:rpcpass \
        --cacert "${LBCDDIR}/rpc.cert" \
        --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getblockcount", "params": []}' \
        -H 'content-type: text/plain;' \
        https://127.0.0.1:9245/

# or disable the certificate verification
$ curl --user rpcuser:rpcpass \
        --insecure \
        --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getblockcount", "params": []}' \
        -H 'content-type: text/plain;' \
        https://127.0.0.1:9245/
{"jsonrpc":"1.0","result":1200062,"error":null,"id":"curltest"}
Working without TLS

TLS can be disabled using the --notls option:

$ ./lbcd --notls
$ ./lbcctl --notls getblockcount

1200062
$ curl --user rpcuser:rpcpass \
        --data-binary '{"jsonrpc": "1.0", "id": "curltest", "method": "getblockcount", "params": []}' \
        -H 'content-type: text/plain;' \
        http://127.0.0.1:9245/
{"jsonrpc":"1.0","result":1200062,"error":null,"id":"curltest"}

Using Snapshots (optional)

Snapshots are created bi-weekly to help new users catch up current block height.

The snapshots are archived and compressed in zstd format for it's compression ratio and speed.

Download the snapshot, and uncompress it:

time curl -O https://snapshots.lbry.com/blockchain/lbcd_snapshot_1199527_v0.22.105_2022-07-27.tar.zst
zstd -d --stdout lbcd_snapshot_1199527_v0.22.105_2022-07-27.tar.zst | tar xf - -C "${LBCDDIR}"

If preferred, a user can download and uncompress the snapshot on the fly: By the time the download is finished, the snapshots should be almost uncompressed already.

mkdir -p "${LBCDDIR}"

time curl https://snapshots.lbry.com/blockchain/lbcd_snapshot_1199527_v0.22.105_2022-07-27.tar.zst | zstd -d --stdout | tar xf - -C "${LBCDDIR}"

#  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
#                                 Dload  Upload   Total   Spent    Left  Speed
# 100 64.9G  100 64.9G    0     0  37.0M      0  0:29:49  0:29:49 --:--:-- 33.0M
#
# real    29m49.962s
# user    6m53.710s
# sys     8m56.545s

Working with RPCs

Using lbcctl -l to list available RPCs:

$ lbcctl -l

Chain Server Commands:
addnode "addr" "add|remove|onetry"
createrawtransaction [{"txid":"value","vout":n},...] {"address":amount,...} (locktime)
debuglevel "levelspec"
decoderawtransaction "hextx"
decodescript "hexscript"
deriveaddresses "descriptor" ({"value":value})
fundrawtransaction "hextx" {"changeaddress":changeaddress,"changeposition":changeposition,"changetype":changetype,"includewatching":includewatching,"lockunspents":lockunspents,"feerate":feerate,"subtractfeefromoutputs":[subtractfeefromoutput,...],"replaceable":replaceable,"conftarget":conftarget,"estimatemode":estimatemode} (iswitness)
generate numblocks

[skipped]

Wallet Server Commands (--wallet):
addmultisigaddress nrequired ["key",...] ("account")
addwitnessaddress "address"
backupwallet "destination"
createmultisig nrequired ["key",...]
createnewaccount "account"
createwallet "walletname" (disableprivatekeys=false blank=false passphrase="" avoidreuse=false)
dumpprivkey "address"
dumpwallet "filename"
encryptwallet "passphrase"
estimatefee numblocks
estimatepriority numblocks
estimatesmartfee conftarget (estimatemode="CONSERVATIVE")
getaccount "address"
getaccountaddress "account"
getaddressesbyaccount "account"

[skipped]

Using lbcctl help rpcname to show the RPC spec:

$ lbcctl help getblock

getblock "hash" (verbosity=1)

Returns information about a block given its hash.

Arguments:
1. hash      (string, required)             The hash of the block
2. verbosity (numeric, optional, default=1) Specifies whether the block data should be returned as a hex-encoded string (0), as parsed data with a slice of TXIDs (1), or as parsed data with parsed transaction data (2)

Result (verbosity=0):
"value" (string) Hex-encoded bytes of the serialized block

Result (verbosity=1):
{
 "getblockverboseresultbase": { (object)
  "hash": "value",              (string)          The hash of the block (same as provided)
  "confirmations": n,           (numeric)         The number of confirmations
  "strippedsize": n,            (numeric)         The size of the block without witness data
  "size": n,                    (numeric)         The size of the block
  "weight": n,                  (numeric)         The weight of the block
  "height": n,                  (numeric)         The height of the block in the block chain
  "version": n,                 (numeric)         The block version
  "versionHex": "value",        (string)          The block version in hexadecimal
  "merkleroot": "value",        (string)          Root hash of the merkle tree
  "time": n,                    (numeric)         The block time in seconds since 1 Jan 1970 GMT
  "mediantime": n,              (numeric)         The median block time in seconds since 1 Jan 1970 GMT
  "nonce": n,                   (numeric)         The block nonce
  "bits": "value",              (string)          The bits which represent the block difficulty
  "difficulty": n.nnn,          (numeric)         The proof-of-work difficulty as a multiple of the minimum difficulty
  "chainwork": "value",         (string)          Expected number of hashes required to produce the chain up to this block (in hex)
  "previousblockhash": "value", (string)          The hash of the previous block
  "nextblockhash": "value",     (string)          The hash of the next block (only if there is one)
  "nameclaimroot": "value",     (string)          Root hash of the claim trie
  "nTx": n,                     (numeric)         The number of transactions (aka, count of TX)
 },
 "tx": ["value",...],           (array of string) The transaction hashes (only when verbosity=1)
}

lbcd & lbcwallet

Wallet related functianlities and RPCs are provided by a separate programe - lbcwallet.

Once setup, lbcwallet can serve wallet related RPCs as well as proxy lbcd RPCs to an assocated lbcd now. It's sufficient for user to connect just the lbcwallet instead of both.

sequenceDiagram
    actor C as lbcctl
    participant W as lbcwallet (port: 9244)
    participant D as lbcd (port: 9245)

    rect rgb(200,200,200)
    Note over C,D: lbcctl getblockcount
    C ->>+ D: getblockcount
    D -->>- C: response
    end

    rect rgb(200,200,200)
    Note over C,W: lbcctl --wallet balance
    C ->>+ W: getbalance
    W -->>- C: response
    end

    rect rgb(200,200,200)
    Note over C,D: lbcctl --wallet getblockcount (lbcd RPC service proxied by lbcwallet)
    C ->>+ W: getblockcount
    W ->>+ D: getblockcount
    D -->>- W: response
    W -->>- C: response
    end

While lbcd can run standalone as a full node, lbcwallet requires an associated lbcd instance for scanning and sync'ing block data.

sequenceDiagram
    participant W as lbcwallet (RPC port: 9244)
    participant D as lbcd (RPC port: 9245, P2P port: 9246)
    participant D2 as other lbcd node(s) (P2P port: 9246)

    rect rgb(200,200,200)
    Note over W,D: Asynchronous websocket notifications
    W ->> D: subscribe to notifications
    D -->> W: notification
    D -->> W: notification
    end

    rect rgb(200,200,200)
    Note over W,D: lbcd RPCs
    W ->>+ D: getblockheader
    D ->>- W: response
    end

    rect rgb(200,200,200)
    Note over D,D2: P2P messages over port 9246
    D -->> D2: P2P message
    D2 -->> D: P2P message
    end

Data integrity

lbcd is not immune to data loss. It expects a clean shutdown via SIGINT or SIGTERM. SIGKILL, immediate VM kills, and sudden power loss can cause data corruption, thus requiring chain resynchronization for recovery.

Security

We take security seriously. Please contact security regarding any security issues. Our PGP key is here if you need it.

We maintain a mailing list for notifications of upgrades, security issues, and soft/hard forks. To join, visit fork list

Contributing

Contributions to this project are welcome, encouraged, and compensated. The integrated github issue tracker is used for this project. All pull requests will be considered.

License

lbcd is licensed under the copyfree ISC License.

Documentation

Overview

lbcd is a full-node bitcoin implementation written in Go.

The default options are sane for most users. This means lbcd will work 'out of the box' for most users. However, there are also a wide variety of flags that can be used to control it.

The following section provides a usage overview which enumerates the flags. An interesting point to note is that the long form of all of these options (except -C) can be specified in a configuration file that is automatically parsed when lbcd starts up. By default, the configuration file is located at ~/.lbcd/lbcd.conf on POSIX-style operating systems and %LOCALAPPDATA%\lbcd\lbcd.conf on Windows. The -C (--configfile) flag, as shown below, can be used to override this location.

Usage:

lbcd [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
    --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=         Mininum 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=       Mininum 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
    --connect=              Connect only to the specified peers at startup
    --cpuprofile=           Write CPU profile to the specified file
-b, --datadir=              Directory to store 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: 9246, testnet:
                            19246, regtest: 29246, signet: 39246)
    --logdir=               Directory to log output
    --maxorphantx=          Max number of orphan transactions to keep in
                            memory (default: 100)
    --maxpeers=             Max number of inbound and outbound peers
                            (default: 125)
    --memprofile=           Write memory profile to the specified file
    --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
    --norpc                 Disable built-in RPC server -- NOTE: The RPC
                            server is disabled by default if no
                            rpcuser/rpcpass or rpclimituser/rpclimitpass is
                            specified
    --notls                 Disable TLS for the RPC server
    --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
    --regtest               Use the regression test network
    --rejectnonstd          Reject non-standard transactions regardless of
                            the default settings for the active network.
    --relaynonstd           Relay non-standard transactions regardless of the
                            default settings for the active network.
    --rpccert=              File containing the certificate file
    --rpckey=               File containing the certificate 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: 9245, testnet: 19245, regtest: 29245)
    --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
    --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)
    --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

Directories

Path Synopsis
Package addrmgr implements concurrency safe Bitcoin address manager.
Package addrmgr implements concurrency safe Bitcoin address manager.
Package blockchain implements bitcoin block handling and chain selection rules.
Package blockchain implements bitcoin block handling and chain selection rules.
fullblocktests
Package fullblocktests provides a set of block consensus validation tests.
Package fullblocktests provides a set of block consensus validation tests.
indexers
Package indexers implements optional block chain indexes.
Package indexers implements optional block chain indexes.
Package btcec implements support for the elliptic curves needed for bitcoin.
Package btcec implements support for the elliptic curves needed for bitcoin.
Package btcjson provides primitives for working with the bitcoin JSON-RPC API.
Package btcjson provides primitives for working with the bitcoin JSON-RPC API.
Package chaincfg defines chain configuration parameters.
Package chaincfg defines chain configuration parameters.
chainhash
Package chainhash provides abstracted hash functionality.
Package chainhash provides abstracted hash functionality.
cmd
cmd
Package connmgr implements a generic Bitcoin network connection manager.
Package connmgr implements a generic Bitcoin network connection manager.
Package database provides a block and metadata storage database.
Package database provides a block and metadata storage database.
ffldb
Package ffldb implements a driver for the database package that uses leveldb for the backing metadata and flat files for block storage.
Package ffldb implements a driver for the database package that uses leveldb for the backing metadata and flat files for block storage.
internal/treap
Package treap implements a treap data structure that is used to hold ordered key/value pairs using a combination of binary search tree and heap semantics.
Package treap implements a treap data structure that is used to hold ordered key/value pairs using a combination of binary search tree and heap semantics.
Package fees provides decred-specific methods for tracking and estimating fee rates for new transactions to be mined into the network.
Package fees provides decred-specific methods for tracking and estimating fee rates for new transactions to be mined into the network.
cmd/dumpfeedb
Tool dumpfeedb can be used to dump the internal state of the buckets of an estimator's feedb so that it can be externally analyzed.
Tool dumpfeedb can be used to dump the internal state of the buckets of an estimator's feedb so that it can be externally analyzed.
rpctest
Package rpctest provides a btcd-specific RPC testing harness crafting and executing integration tests by driving a `btcd` instance via the `RPC` interface.
Package rpctest provides a btcd-specific RPC testing harness crafting and executing integration tests by driving a `btcd` instance via the `RPC` interface.
Package mempool provides a policy-enforced pool of unmined bitcoin transactions.
Package mempool provides a policy-enforced pool of unmined bitcoin transactions.
Package netsync implements a concurrency safe block syncing protocol.
Package netsync implements a concurrency safe block syncing protocol.
Package peer provides a common base for creating and managing Bitcoin network peers.
Package peer provides a common base for creating and managing Bitcoin network peers.
Package rpcclient implements a websocket-enabled Bitcoin JSON-RPC client.
Package rpcclient implements a websocket-enabled Bitcoin JSON-RPC client.
Package txscript implements the bitcoin transaction script language.
Package txscript implements the bitcoin transaction script language.
Package wire implements the bitcoin wire protocol.
Package wire implements the bitcoin wire protocol.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL