Exonum Anchoring Service to Bitcoin

Build Status

This crate implements a service for [Exonum] blockchain that provides a protocol for anchoring onto the Bitcoin blockchain that utilizes the native Bitcoin capabilities of creating multisig transactions.

Prerequisites

Installation

Just follow Exonum installation guide to install dependencies.

Bitcoin Node Deployment

First of all install bitcoind via your package manager and ensure that you use the latest stable version. You may visit official Bitcoin site for more information about installation.

Then create bitcoind configuration file according to this tutorial.

For correct work of the service, the bitcoind configuration file should contain the following settings:

```ini

Run the node in the test network instead of the real Bitcoin network.

If you want to use the main network comment the line bellow:

testnet=1

server=1 tells Bitcoin-Qt and bitcoind to accept JSON-RPC commands.

server=1

Maintain a full transaction index, used by the getrawtransaction RPC call.

An arbitrary bitcoind daemon is not required to respond to a request for

information about an arbitrary transaction, thus you should uncomment the

line bellow if you want to use the daemon in an existing Exonum network.

txindex=1

Bind to the given address to listen to JSON-RPC connections.

Use [host]:port notation for IPv6.

This option can be specified multiple times (default: bind to all interfaces)

rpcbind=

You must specify rpcuser and rpcpassword to secure the JSON-RPC API

rpcuser=

rpcpassword=YourSuperGreatPasswordNumberDONOTUSETHISORYOUWILLGETROBBED385593

```

These RPC settings will be used by the service.

After creating configuration file, launch bitcoind daemon via command:

shell bitcoind --daemon

Note! Downloading and indexing of the Bitcoin blockchain may take a lot of time, especially for the mainnet.

Usage

Include exonum-btc-anchoring as a dependency into your Cargo.toml:

toml [dependencies] exonum-btc-anchoring = "0.10"

Add the BTC anchoring service to the blockchain in the main project file:

```rust extern crate exonum; extern crate exonumbtcanchoring as anchoring;

use exonum::helpers; use exonum::helpers::fabric::NodeBuilder;

fn main() { exonum::crypto::init(); helpers::initlogger().unwrap(); let node = NodeBuilder::new() .withservice(Box::new(anchoring::ServiceFactory)); node.run(); }

```

Configuration Parameters

For the generate-template subcommand

For the generate-config subcommand

For the finalize subcommand

For adjusting the running blockchain configuration

Variables that you can modify

Warning! The network parameter shouldn't be changed otherwise the service will come to a halt.

Deployment

Example of the Anchoring Service Installation

For the fast anchoring demonstration you can use a built-in anchoring example.

bash cargo install --example btc_anchoring

For example, create a BTC anchoring configuration template for the testnet Bitcoin network. In our case we create a template for the network with several validators.

bash btc_anchoring generate-template template.toml \ --validators-count 2 \ --btc-anchoring-network testnet \ --btc-anchoring-fee 100 \ --btc-anchoring-utxo-confirmations 0

Each node generates its own public and secret node configuration files.

bash btc_anchoring generate-config template.toml 0/pub.toml 0/sec.toml \ --consensus-path 0/.keys/consensus.toml --service-path 0/.keys/service.toml --peer-address 127.0.0.0:7000 \ --btc-anchoring-rpc-host http://localhost:18332 \ --btc-anchoring-rpc-user user \ --btc-anchoring-rpc-password password

Participants need to send some bitcoins to the anchoring address in order to enable Bitcoin anchoring. For this:

Launch Node

Launch all the Exonum nodes in the given Exonum network. To launch a particular node just execute:

bash btc_anchoring run --node-config <destdir>/<N>.toml --db-path <destdir>/db/<N>

If you want to see additional information you may specify the log level by an environment variable RUST_LOG="exonum_btc_anchoring=info".

Maintenance

As a maintainer you can perform the following actions.

Modify Configuration Parameters

You can safely change the following parameters: transaction_fee and anchoring_interval.

Add Funds

Send some Bitcoins to the current anchoring wallet and save a raw transaction body hex. Wait until transaction gets enough confirmations. Then replace the funding_tx variable by the saved hex.

Note! If the current anchoring chain becomes unusable, you may start a new chain by adding a corresponding funding transaction.

Modify List of Validators

Important warning! After change of the validators list the anchoring address also changes, thus, there is no possibility to sign anchoring transactions addressed to the old anchoring address.

So please make sure that:

And then perform the following steps:

Note! If the transferring transaction has been lost, you need to establish a new anchoring chain by a new funding transaction.

Licence

Exonum core library is licensed under the Apache License (Version 2.0). See LICENSE for details.