Giter VIP home page Giter VIP logo

bch-devsuite's Introduction

Getting started

Prerequisites

To run this node, you must have the follow software installed on your local machine:

  • Docker (including docker-compose)
  • Python 3
  • Virtualenv (sudo apt install python3-venv)
  • Openssl
  • Git

Cloning this repository

# Clone repository
git clone https://github.com/ActorForth/bch-devsuite.git
cd ./bch-devsuite

# Setup virtualenv
python3 -m venv venv
source ./venv/bin/activate

# Install script dependencies
pip install -r requirements.txt

Setup infrastructure

This will check that the necessary software is installed, and then it will download and prepare the docker containers. For a full list of options, run ./setup with no arguments to see its usage.

NOTE: If you wish to have any custom changes applied to the Bitcoin Unlimited, or REST API services, be sure to apply those changes within the bitcoin.conf, fulcrum-config.conf, or restapi-config.sh files, respectively, before executing the setup script. Bitcoin Cash Node can alternatively be used with fulcrum, by commenting out bitcoin unlimited and uncommenting bitcoin cash node and fulcrum. These can not currently run simultaneously, and one or the other must be used.

./bch-devsuite init
# First we select a network, which must be regtest, mainnet or testnet
# Next we specify the node, bitcoin unlimited or bitcoincash node
# Next we select a rest interface, bchrest is a fork of the rest.bitcoin.com api, while bchapi is a rest utilized with the bch-js library
# Slp is optional, selecting this option enables slpdb, slpserve and mongodb
# Smartbch is optional, if the network is regtest, this also generate 10 test keys.

NOTE: A RPC password and username prompt will appear for the node, these values will be stored in generated docker-compose.yml file.

NOTE: The SLP option will prompt the user to input a MONGODB username and password, this is to prevent external parties from modifying your database if the ports are exposed.

Running infrastructure

Execute the services script to start the node, indexer, rest API, and/or SLPDB (depending which ones chose in the setup script).

./bch-devsuite start

Testing

./bitcoin-cli getblockchaininfo

Expected result

{
  "chain": "regtest",
  "blocks": 200,
  "headers": 200,
  "bestblockhash": "0714183b15ac3757e35152fadbc0fd2d73ec97c4d9e1ee486882b18da8b256ca",
  "difficulty": 4.656542373906925e-10,
  "mediantime": 1614598375,
  "verificationprogress": 1,
  "initialblockdownload": false,
  "chainwork": "0000000000000000000000000000000000000000000000000000000000000192",
  "size_on_disk": 48350,
  "pruned": false,
  "softforks": [
    {
      "id": "bip34",
      "version": 2,
      "reject": {
        "status": false
      }
    },
    {
      "id": "bip66",
      "version": 3,
      "reject": {
        "status": false
      }
    },
    {
      "id": "bip65",
      "version": 4,
      "reject": {
        "status": false
      }
    }
  ],
  "bip9_softforks": {
  },
  "bip135_forks": {
  }
}

Stop infrastructure

Once you decide to call it a day, you can shut down your local environment by executing:

./bch-devsuite stop

Cleaning Up

If you experience any issues, or would like to completely erase the current wallet and node containers, run the following script:

./clean

NOTE: this command may need to be ran with sudo while on linux

WARNING: The 'clean' script is very destructive, so make sure you only use it when you want to completely erase the entire current instance of nodes and the wallet.

Setup Option Reference

Network

  • Regtest
  • Testnet
  • Mainnet

Component

  • Local node (Bitcoin Unlimited node or Bitcoin Cash Node)
  • REST service (A rest.bitcoin.com-compatible or Bch-API)
  • SLP services (SLPDB, slpserve)
  • SmartBCH (https://smartbch.org/ Currently only support regtest)

Local node

  • Bitcoin Unlimited Node
  • Bitcoin Cash Node

REST Service

Architecture

Two REST APIs can be run: rest.bitcoin.com and bch-api.

1. rest.bitcoin.com tech stack

rest.bitcoin.com Tech Stack

All these components work together in a stack, which means that if the lower part is missing then some of the API in rest.bitcoin.com might not function properly.

The main reason why you should use all of our fork stacks is because we maintain and guarantee that all of the components will work well with the Regtest address format. Allowing you to test locally more easily.

The blue part is the node that you choose. The default node is Bitcoin unlimited and there is Bitcoin Cash node as an option as well. Currently, this node is always required.

The red part is an indexer. ElectrsCash is for indexing Bitcoin cash transactions and aggregate BCH balance per address. Without these, you won't be able to query the amount of BCH you own in a particular address. OpenSight is a shim micro service to make ElectrsCash compatible with rest.bitcoin.com API interface. SLPDB is an indexer for SLP token, color coin on top of Bitcoin Cash, this will be verified if the data relate to the color coin is valid and checks if the coin follows the SLP off-chain consensus.

The orange part is rest.bitcoin.com API, a unified interface for anyone to interact with all of these complex services through REST API interface uniformly

The green part is the client SDK that will interact with rest.bitcoin.com interface. Bitcash is written in Python and Bitbox is written in typescript.

2. Chris Troutner JS tech stack

Chris Troutner JS Tech Stack

The main difference is the rest interface. bch-api has a different API from rest.bitcoin.com and can talk directly to Electrscash without requiring the shim.

Sponsorship

provide a way to funding us

Roadmap

Contribution Guide

Archived

About

This repo intends to be a toolkit for running a local version of a Bitcoin Unlimited for development and testing purposes. Currently it provides a self-hosted local node, indexer (Electrs), a drop-in Ninsight replacement (Opensight), a regtest version of the rest.bitcoin.com REST APIs, an instance of SLPDB for token querying.

Known Issues

There are a few issues with this setup that could use improvement in the future.

  • Currently, this setup relies on the built-in Electrscash indexing server included in the Bitcoin Unlimited node. This isn't an issue per se, but to test with other nodes (such as Bitcoin ABC, Bitcoin Cash Node, or bchd) it will be necessary to seperate the indexing server into a seperate container.
  • Currently blocks must be generated manually after transactions are made in order to mine them into blocks. The possibility of adding an automation to generate a block every few minutes could be a consideration to look into.

bch-devsuite's People

Contributors

codewithcats avatar litvinof avatar merc1er avatar nexerino avatar nicolaiskye avatar siraben avatar supercipher avatar tleekkul avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

bch-devsuite's Issues

Dump and restore SLPDB

re: #22

SLPDB is relatively straightforward

Need to run these from a machine/container that has mongodb installed, and can talk to mongodb-slpdb.

We should stop slpdb and slpserve containers prior to doing a restore. Not sure if there is any need to stop these while dumping.

Dump

mongodump -d slpdb_test --archive=/tmp/slpdb_test.mongo.gz --authenticationDatabase admin --gzip mongodb://mongouser:mongopass@mongodb-slpdb:27017

Restore

mongorestore  --drop  --authenticationDatabase admin --archive=/tmp/slpdb_test.mongo.gz --gzip   mongodb://mongouser:mongopass@mongodb-slpdb:27017

Disable wallet functionality of bch node

Currently when I run bchn node, the wallet functions are enabled by default. This might lead me to expect that I can use this deployment for storing my BCH keys. If this is the intended usage then we should have ways for user to backup and preserve and provide their wallet file, if not then we should run the node with -disablewallet argument.

Init script improvement

Instead of using bash script, use Python with Jinja2 for templating and Typer (https://typer.tiangolo.com/) for command line interface builder. This changes should be compatibled with ./services start.

Proposed command:

Example

❯ ./bch-devsuite init
[?] Which components do you want to install?: 
 > X Local node (Bitcoin Unlimited node or Bitcoin Cash Node)
   X REST service (A rest.bitcoin.com-compatible or Bch-API)
   X SLP services (SLPDB, slpserve)

[?] Local node?: Bitcoin Unlimited Node
 > Bitcoin Unlimited Node
   Bitcoin Cash Node

[?] Network?: regtest
 > regtest
   testnet
   mainnet

[?] Please enter a username for the node RPC connection: tle
[?] Please enter a password for the node RPC connection: alpine
[?] Please enter number of initial blocks for regtest: 200
[?] REST Service?: bchrest
 > bchrest
   bchapi

SLPDB uses mongodb, a username and password is recommended.
[?] Please enter a username for mongodb: tle
[?] Please enter a password for mongodb: alpine
[?] docker network: bch-devsuite-network
[?] Exposed port? (Y/n): 
{
  "local_node": {
    "node": "bu",
    "network": "regtest",
    "rpc_conf": {
      "username": "tle",
      "password": "alpine"
    },
    "regtest_blocks": "200",
    "wait_time": 6
  },
  "rest_service": "bchrest",
  "slp": {
    "username": "tle",
    "password": "alpine"
  },
  "exposed_ports": true,
  "docker_network": "bch-devsuite-network"
}
Confirm? [y/N]: y

#########################
# VALIDATE DEPENDENCIES #
#########################
docker...✓✓
docker-compose...✓

##############
# SETTING UP #
##############
Creating docker network...ALREADY CREATED, SKIPPED
Setting up Bitcoin Unlimited node...✓
Generate docker-compose file...✓
Pull the Docker images...
Pulling bch-node      ... done
Pulling bchrest       ... done
Pulling opensight     ... done
Pulling mongodb-slpdb ... done
Pulling slpdb         ... done
Pulling slpserve      ... done
✓
Generating 200 initial blocks for regtest...
Creating bch-node ... done
[
  "20662918c049525e62ff72f84709981e6ea25ab6d4197256f94dfceb798ac2c2",
  ...,
  "1b52bf703cbdce2a8bcfbaabf0bfedf8599fff775143c51c9124337c882cb714"
]
✓
Stopping local node...Bitcoin server stopping
✓


Finished. Please use './bch-devsuite start' to run your new regtest node.

This version will be running on the local machine, not in Docker and we will improve by put it in a docker image later on.

Add parameters to ./clean script to specify options

It would be quite useful to add argument parsing capabilities to the ./clean script so it can preform only specific operations that the users wishes. For example:

./clean wallet  # removes only user's wallet files
./clean node  # removes only the current bitcoind+nginx services
./clean all  # preforms every cleaning operation

Running the script without any arguments should display a usage message of possible arguments

Dump and restore smartbch

re: #22

To make a dump (make sure the donor smartbchd is stopped)

sudo tar --exclude=priv_validator_state.json --use-compress-program=pigz -cvf /tmp/smartbch.tar.gz -C data/smartbchd data

To restore (make sure the recipient smartbchd is stopped and clean)

sudo tar --use-compress-program=pigz -xvf  /tmp/smartbch.tar.gz -C data/smartbchd/

bch-devsuite script Dockerization

To make it easier for users to adopt our devsuite, instead of having them install python3-venv, and pip install libraries, we ship everything in a docker image instead.

Support config file

User can supply a config file instead of having to go through init wizard, this will make deployment easier on their end.

Dump and restore Bitcoin Cash Node

re: #22

Provide an automated way to bootstrap testnet and mainnet Bitcoin Cash Node from a block file instead of waiting on network.

Bitcoin Cash Node enables us to provide it with a block file bootstrap.dat which it uses for the initial sync instead of fetching the blocks over the network.

How to generate bootstrap.dat?

  1. Prepare python scripts, specifically linearize-data.py and linearize-hashes.py from https://gitlab.com/bitcoin-cash-node/bitcoin-cash-node/-/tree/master/contrib/linearize
  2. Patch linearize-data.py with this upstream commit
  3. create linearize.cfg
# bitcoind RPC settings (linearize-hashes)
rpcuser=FIXME
rpcpassword=FIXME
host=<ip of bchd container>
port=<port>

max_height=<current height of blockchain, optionally round it to something nice>

netmagic=0b110907
genesis=000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943
input=/path/to/bch-toolkit/data/bitcoind/testnet3/blocks/
output_file=/tmp/bootstrap.dat
hashlist=/tmp/hashlist.txt

out_of_order_cache_sz = 100000000
rev_hash_bytes = False
file_timestamp = 0
split_timestamp = 0
debug_output = False
  1. Generate hashlist
./linearize-hashes.py linearize.cfg > /tmp/hashlist.txt
  1. Generate bootstrap.dat
./linearize-data.py linearize.cfg

This results in a 40GB file /tmp/bootstrap.dat

How to restore bootstrap.dat using?

  1. Copy the file into correct place before starting bchd container
cp /tmp/bootstrap.dat data/bitcoind/testnet3/
  1. Start bchd container
  2. Once sync is complete, bchd renames the file to bootstrap.dat.old. This file is safe to delete.

It should take about 40 minutes(on my laptop) to sync testnet.

Action items.

  • Figure out how and where do we store the dumps
  • Figure out automation for restore process
  • Figure out cleanup step to delete bootstrap.dat.old

Better shell interaction message

After setup is complete should have a message to show what endpoint to connect, summarize all the port.
Inspire by create-react-app

Dump and restore Bitcoin Unlimited

re: #22

Commands below require pigz to be installed. If its not then remove --use-compress-program=pigz from the tar commands and add z argument.

Generate dump

BU node must be stopped

sudo tar --exclude=debug.log --exclude=mempool.dat --exclude=wallet.dat --exclude=.lock --exclude=peers.dat --exclude=orphanpool.dat --use-compress-program=pigz -cvf /tmp/bu.tar.gz -C data/bitcoind testnet3

Restore dump

Put the files in the directory before creating the container

mkdir -p data/bitcoind/testnet3
tar --use-compress-program=pigz -xvf  /tmp/bu.tar.gz -C data/bitcoind/

Do not reindex BCHN each time

When running Bitcoin Cash Node, the config file configs/bitcoincashnode.conf contains reindex=1

We should remove it, since this makes container restart incredibly slow. A reindex should only be used manually if the user knows the data got corrupted.

Cant init without smartbch selected

use-case: Run devsuite without smartbch

In current master, if I build-config without selecting smartbch, I get following error

  File "/home/biggestfan/bch-devsuite/./bch-devsuite", line 349, in setup_docker_compose
    if config.smartbch.enabled:
AttributeError: 'NoneType' object has no attribute 'enabled'

Work-around is to select smartbch in wizard, but hand-edit the generated toml to say enabled=false in [smartbch] section.

The wizard should have generated a valid config in the first place.

Add support for using 'conda' python manager

Currently the included scripts expect that the virtualenv python package should be available. Anaconda manages its virtual environments in a slightly different way, and support can be added to the scripts so that users who prefer Anaconda can still run them.

resource specification

Adding documentation on how what resource they should expect and also the load test result.

Docs website

Create and deploy docs website for bch-toolkit

  • generate from readme
  • auto build and deploy using CI

Update the README's structure

I propose the following structure:

  • Name of project (rebrand to DevSuite)
  • Badges (Tests, container deployment, coding style and so on..)
  • Getting started/quickstart
  • Advanced usage (or just link to the docs after QuickStart)
  • Architecture
  • Contribution guide (maybe just link to CONTRIBUTING.md)

Support remote BCH RPC

Currently the devsuite need local BCH RPC deployed via devsuite script, it should be configurable to connect to any remote BCH node.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.