Skip to content

Commit

Permalink
Russian Bitcoin hacks
Browse files Browse the repository at this point in the history
  • Loading branch information
National Bitcoiner committed Jun 21, 2020
1 parent 5b74928 commit 027ffa9
Show file tree
Hide file tree
Showing 101 changed files with 130 additions and 3,702 deletions.
175 changes: 0 additions & 175 deletions CONTRIBUTING.md

This file was deleted.

41 changes: 4 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,42 +1,21 @@
[![Go Report Card](https://goreportcard.com/badge/nbcorg/blockbook)](https://goreportcard.com/report/nbcorg/blockbook)
# Blockbook/RUBTC

# Blockbook

**Blockbook** is back-end service for Trezor wallet. Main features of **Blockbook** are:
This is a fork of back-end service for Trezor wallet. Main features are:

- index of addresses and address balances of the connected block chain
- fast searches in the indexes
- simple blockchain explorer
- websocket, API and legacy Bitcore Insight compatible socket.io interfaces
- support of multiple coins (Bitcoin and Ethereum type), with easy extensibility for other coins
- scripts for easy creation of debian packages for backend and blockbook

## Build and installation instructions

Officially supported platform is **Debian Linux** and **AMD64** architecture.

Memory and disk requirements for initial synchronization of **Bitcoin mainnet** are around 32 GB RAM and over 180 GB of disk space. After initial synchronization, fully synchronized instance uses about 10 GB RAM.
Other coins should have lower requirements, depending on the size of their block chain. Note that fast SSD disks are highly
recommended.

User installation guide is [here](https://wiki.trezor.io/User_manual:Running_a_local_instance_of_Trezor_Wallet_backend_(Blockbook)).

Developer build guide is [here](/docs/build.md).

Contribution guide is [here](CONTRIBUTING.md).

## Implemented coins

Blockbook currently supports over 30 coins. The Trezor team implemented

- Bitcoin, Bitcoin Cash, Zcash, Dash, Litecoin, Bitcoin Gold, Ethereum, Ethereum Classic, Dogecoin, Namecoin, Vertcoin, DigiByte, Liquid

the rest of coins were implemented by the community.

Testnets for some coins are also supported, for example:
- Bitcoin Testnet, Bitcoin Cash Testnet, ZCash Testnet, Ethereum Testnet Ropsten

List of all implemented coins is in [the registry of ports](/docs/ports.md).
This fork is focused on Russian Bitcoin support. No other coins are implemented.

## Common issues when running Blockbook or implementing additional coins

Expand All @@ -47,23 +26,11 @@ How to reduce memory footprint of the initial sync:
- disable rocksdb cache by parameter `-dbcache=0`, the default size is 500MB
- run blockbook with parameter `-workers=1`. This disables bulk import mode, which caches a lot of data in memory (not in rocksdb cache). It will run about twice as slowly but especially for smaller blockchains it is no problem at all.

Please add your experience to this [issue](https://github.com/nbcorg/blockbook/issues/43).

#### Error `internalState: database is in inconsistent state and cannot be used`

Blockbook was killed during the initial import, most commonly by OOM killer. By default, Blockbook performs the initial import in bulk import mode, which for performance reasons does not store all the data immediately to the database. If Blockbook is killed during this phase, the database is left in an inconsistent state.

See above how to reduce the memory footprint, delete the database files and run the import again.

Check [this](https://github.com/nbcorg/blockbook/issues/89) or [this](https://github.com/nbcorg/blockbook/issues/147) issue for more info.

#### Running on Ubuntu

[This issue](https://github.com/nbcorg/blockbook/issues/45) discusses how to run Blockbook on Ubuntu. If you have some additional experience with Blockbook on Ubuntu, please add it to [this issue](https://github.com/nbcorg/blockbook/issues/45).

#### My coin implementation is reporting parse errors when importing blockchain

Your coin's block/transaction data may not be compatible with `BitcoinParser` `ParseBlock`/`ParseTx`, which is used by default. In that case, implement your coin in a similar way we used in case of [zcash](https://github.com/nbcorg/blockbook/tree/master/bchain/coins/zec) and some other coins. The principle is not to parse the block/transaction data in Blockbook but instead to get parsed transactions as json from the backend.
See above how to reduce the memory footprint, delete the database files and run the import again.

## Data storage in RocksDB

Expand Down
2 changes: 1 addition & 1 deletion api/text.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var Text struct {
}

func init() {
box := packr.NewBox("../build/text")
box := packr.NewBox("../config/text")
if about, err := box.MustString("about"); err == nil {
Text.BlockbookAbout = strings.TrimSpace(about)
} else {
Expand Down
6 changes: 3 additions & 3 deletions bchain/coins/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/juju/errors"
"github.com/nbcorg/blockbook/bchain"
"github.com/nbcorg/blockbook/bchain/coins/btc"
"github.com/nbcorg/blockbook/bchain/coins/russianbitcoin"
"github.com/nbcorg/blockbook/common"
)

Expand All @@ -22,8 +21,9 @@ type blockChainFactory func(config json.RawMessage, pushHandler func(bchain.Noti
var BlockChainFactories = make(map[string]blockChainFactory)

func init() {
BlockChainFactories["Bitcoin"] = btc.NewBitcoinRPC
BlockChainFactories["RussianBitcoin"] = russianbitcoin.NewRussianBitcoinRPC
BlockChainFactories["Russian Bitcoin"] = btc.NewBitcoinRPC
BlockChainFactories["TestNet"] = btc.NewBitcoinRPC
BlockChainFactories["Regtest"] = btc.NewBitcoinRPC
}

// GetCoinNameFromConfig gets coin name and coin shortcut from config file
Expand Down
58 changes: 50 additions & 8 deletions bchain/coins/btc/bitcoinparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,40 @@ import (
"github.com/nbcorg/blockbook/bchain"
)

// magic numbers
const (
MainnetMagic wire.BitcoinNet = 0xd8b4bef8
TestnetMagic wire.BitcoinNet = 0x0809110c
RegtestMagic wire.BitcoinNet = 0xdbd5bffb
)

// chain parameters
var (
MainNetParams chaincfg.Params
TestNetParams chaincfg.Params
RegtestParams chaincfg.Params
)

func init() {
MainNetParams = chaincfg.MainNetParams
MainNetParams.Net = MainnetMagic
MainNetParams.PubKeyHashAddrID = []byte{102}
MainNetParams.ScriptHashAddrID = []byte{11}
MainNetParams.Bech32HRPSegwit = "rubtcm"

TestNetParams = chaincfg.TestNet3Params
TestNetParams.Net = TestnetMagic
TestNetParams.PubKeyHashAddrID = []byte{105}
TestNetParams.ScriptHashAddrID = []byte{13}
TestNetParams.Bech32HRPSegwit = "rubtct"

RegtestParams = chaincfg.RegressionNetParams
RegtestParams.Net = RegtestMagic
RegtestParams.PubKeyHashAddrID = []byte{105}
RegtestParams.ScriptHashAddrID = []byte{13}
RegtestParams.Bech32HRPSegwit = "rubtct"
}

// OutputScriptToAddressesFunc converts ScriptPubKey to bitcoin addresses
type OutputScriptToAddressesFunc func(script []byte) ([]string, bool, error)

Expand All @@ -41,20 +75,28 @@ func NewBitcoinParser(params *chaincfg.Params, c *Configuration) *BitcoinParser
return p
}

// GetChainParams contains network parameters for the main Bitcoin network,
// the regression test Bitcoin network, the test Bitcoin network and
// the simulation test Bitcoin network, in this order
// GetChainParams contains network parameters for the main Russian Bitcoin network,
// the regression test Russian Bitcoin network and the test Bitcoin network and
func GetChainParams(chain string) *chaincfg.Params {
if !chaincfg.IsRegistered(&chaincfg.MainNetParams) {
chaincfg.RegisterBitcoinParams()
if !chaincfg.IsRegistered(&MainNetParams) {
err := chaincfg.Register(&MainNetParams)
if err == nil {
err = chaincfg.Register(&TestNetParams)
}
if err == nil {
err = chaincfg.Register(&RegtestParams)
}
if err != nil {
panic(err)
}
}
switch chain {
case "test":
return &chaincfg.TestNet3Params
return &TestNetParams
case "regtest":
return &chaincfg.RegressionNetParams
return &RegtestParams
}
return &chaincfg.MainNetParams
return &MainNetParams
}

// GetAddrDescFromVout returns internal address representation (descriptor) of given transaction output
Expand Down
Loading

0 comments on commit 027ffa9

Please sign in to comment.