Skip to content

Commit

Permalink
Merge pull request #106 from gregdhill/refactor/btc-parachain
Browse files Browse the repository at this point in the history
refactor: refresh readmes, use --btc-parachain-url for connection
  • Loading branch information
gregdhill authored May 26, 2021
2 parents faca655 + 227be8a commit e7a13a4
Show file tree
Hide file tree
Showing 17 changed files with 177 additions and 175 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Download and start [Bitcoin Core](https://bitcoin.org/en/bitcoin-core/):
bitcoind -regtest -server
```

Build and run the [PolkaBTC Parachain](https://github.com/interlay/btc-parachain):
Build and run the [BTC Parachain](https://github.com/interlay/btc-parachain):

```
git clone [email protected]:interlay/btc-parachain.git
Expand Down Expand Up @@ -56,7 +56,7 @@ rustup default nightly-2021-03-15

### Oracle

PolkaBTC requires a price oracle to calculate collateralization rates, for local development we can run this client
The BTC Parachain requires a price oracle to calculate collateralization rates, for local development we can run this client
to automatically update the exchange rate at a pre-determined time interval.

```bash
Expand All @@ -65,7 +65,7 @@ cargo run --bin oracle

### Staked Relayer

The [Staked Relayer](./staked-relayer/README.md) client is responsible for submitting Bitcoin block headers to PolkaBTC and reporting on various error states.
The [Staked Relayer](./staked-relayer/README.md) client is responsible for submitting Bitcoin block headers to the BTC Parachain.

```bash
source .env
Expand All @@ -74,7 +74,7 @@ cargo run --bin staked-relayer -- --http-addr '[::0]:3030'

### Testdata

To interact with PolkaBTC directly, use the [testdata-gen](./testdata-gen/README.md) client.
To interact with the BTC Parachain directly, use the [testdata-gen](./testdata-gen/README.md) client.

```bash
source .env
Expand All @@ -83,7 +83,7 @@ cargo run --bin testdata-gen -- --keyring bob set-exchange-rate --exchange-rate

### Vault

The [Vault](./vault/README.md) client is used to intermediate assets between Bitcoin and PolkaBTC.
The [Vault](./vault/README.md) client is used to intermediate assets between Bitcoin and the BTC Parachain.

```bash
source .env
Expand Down
2 changes: 1 addition & 1 deletion faucet/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "faucet"
version = "0.7.0"
authors = ["Interlay <[email protected]>"]
edition = "2018"
description = "DOT faucet for enabling users to test PolkaBTC."
description = "Collateral faucet for the BTC Parachain."

[dependencies]
log = "0.4.6"
Expand Down
37 changes: 27 additions & 10 deletions faucet/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PolkaBTC Faucet Client
# Faucet Client

Transfer DOT to users.
Transfer collateral (e.g. DOT/KSM) to users.

## Responsibilities

Expand All @@ -26,27 +26,44 @@ cargo run -- --help
For convenience, a copy of this output is included below.
```
USAGE:
cargo run -- [OPTIONS]
faucet [OPTIONS]
FLAGS:
-h, --help Prints help information
-V, --version Prints version information
OPTIONS:
--btc-parachain-url <btc-parachain-url>
Parachain websocket URL [default: ws://127.0.0.1:9944]
--http-addr <http-addr>
Address to listen on for JSON-RPC requests [default: [::0]:3033]
--keyfile <keyfile>
Path to the json file containing key pairs in a map. Valid content of this file is e.g.
`{ "MyUser1": "<Polkadot Account Mnemonic>", "MyUser2": "<Polkadot Account Mnemonic>" }`
--keyname <keyname> The name of the account from the keyfile to use
--keyring <keyring> Keyring to use, mutually exclusive with keyfile
--polka-btc-url <polka-btc-url>
Parachain URL, can be over WebSockets or HTTP [default: ws://127.0.0.1:9944]
--keyname <keyname>
The name of the account from the keyfile to use
--keyring <keyring>
Keyring to use, mutually exclusive with keyfile
--max-concurrent-requests <max-concurrent-requests>
Maximum number of concurrent requests
--max-notifs-per-subscription <max-notifs-per-subscription>
Maximum notification capacity for each subscription
--btc-parachain-connection-timeout-ms <btc-parachain-connection-timeout-ms>
Timeout in milliseconds to wait for connection to btc-parachain [default: 60000]
--rpc-cors-domain <rpc-cors-domain>
Comma separated list of allowed origins [default: *]
--rpc-cors-domain <rpc-cors-domain> Comma separated list of allowed origins [default: *]
--user-allowance <user-allowance>
DOT allowance per request for regular users [default: 1]
Allowance per request for regular users [default: 1]
--vault-allowance <vault-allowance> DOT allowance per request for vaults [default: 500]
--vault-allowance <vault-allowance>
Allowance per request for vaults [default: 500]
```
6 changes: 3 additions & 3 deletions faucet/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ struct Opts {
#[clap(flatten)]
account_info: runtime::cli::ProviderUserOpts,

/// Connection settings for the BTC-Parachain.
/// Connection settings for the BTC Parachain.
#[clap(flatten)]
parachain: runtime::cli::ConnectionOpts,

Expand All @@ -39,11 +39,11 @@ pub struct FaucetConfig {
#[clap(long, default_value = "*")]
rpc_cors_domain: String,

/// DOT allowance per request for regular users.
/// Allowance per request for regular users.
#[clap(long, default_value = "1")]
user_allowance: u128,

/// DOT allowance per request for vaults.
/// Allowance per request for vaults.
#[clap(long, default_value = "500")]
vault_allowance: u128,
}
Expand Down
21 changes: 14 additions & 7 deletions oracle/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# PolkaBTC Oracle
# Oracle

Automated price feeder for the BTC-Parachain.
Automated price feeder for the BTC Parachain.

## Examples

Expand Down Expand Up @@ -28,6 +28,12 @@ FLAGS:
-V, --version Prints version information
OPTIONS:
--btc-parachain-url <btc-parachain-url>
Parachain URL, can be over WebSockets or HTTP [default: ws://127.0.0.1:9944]
--connection-timeout-ms <connection-timeout-ms>
Timeout in milliseconds to wait for connection to btc-parachain [default: 60000]
--exchange-rate <exchange-rate>
Exchange rate from Planck to Satoshi. hardcoded to 1 BTC = 3855.23187 DOT at granularity
of 5 [default: 385523187]
Expand All @@ -36,11 +42,12 @@ OPTIONS:
Path to the json file containing key pairs in a map. Valid content of this file is e.g.
`{ "MyUser1": "<Polkadot Account Mnemonic>", "MyUser2": "<Polkadot Account Mnemonic>" }`
--keyname <keyname> The name of the account from the keyfile to use
--keyring <keyring> Keyring to use, mutually exclusive with keyfile
--polka-btc-url <polka-btc-url>
Parachain URL, can be over WebSockets or HTTP [default: ws://127.0.0.1:9944]
--keyname <keyname>
The name of the account from the keyfile to use
--keyring <keyring>
Keyring to use, mutually exclusive with keyfile
--timeout-ms <timeout-ms>
Timeout for exchange rate setter, default 30 minutes [default: 1800000]
Timeout for exchange rate setter, default 25 minutes [default: 1500000]
```
4 changes: 2 additions & 2 deletions oracle/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ async fn get_exchange_rate_from_coingecko() -> Result<u128, Error> {
struct Opts {
/// Parachain URL, can be over WebSockets or HTTP.
#[clap(long, default_value = "ws://127.0.0.1:9944")]
polka_btc_url: String,
btc_parachain_url: String,

/// Exchange rate from Planck to Satoshi.
/// hardcoded to 1 BTC = 3855.23187 DOT
Expand Down Expand Up @@ -100,7 +100,7 @@ async fn main() -> Result<(), Error> {
);

let result = PolkaBtcProvider::from_url_with_retry(
&opts.polka_btc_url.clone(),
&opts.btc_parachain_url.clone(),
signer.clone(),
Duration::from_millis(opts.connection_timeout_ms),
)
Expand Down
8 changes: 4 additions & 4 deletions runtime/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@ pub fn parse_duration_ms(src: &str) -> Result<Duration, ParseIntError> {
pub struct ConnectionOpts {
/// Parachain websocket URL.
#[clap(long, default_value = "ws://127.0.0.1:9944")]
pub polka_btc_url: String,
pub btc_parachain_url: String,

/// Timeout in milliseconds to wait for connection to btc-parachain.
#[clap(long, parse(try_from_str = parse_duration_ms), default_value = "60000")]
pub polka_btc_connection_timeout_ms: Duration,
pub btc_parachain_connection_timeout_ms: Duration,

/// Maximum number of concurrent requests
#[clap(long)]
Expand All @@ -80,11 +80,11 @@ pub struct ConnectionOpts {
impl ConnectionOpts {
pub async fn try_connect(&self, signer: PolkaBtcSigner) -> Result<PolkaBtcProvider, Error> {
PolkaBtcProvider::from_url_and_config_with_retry(
&self.polka_btc_url,
&self.btc_parachain_url,
signer,
self.max_concurrent_requests,
self.max_notifs_per_subscription,
self.polka_btc_connection_timeout_ms,
self.btc_parachain_connection_timeout_ms,
)
.await
}
Expand Down
4 changes: 2 additions & 2 deletions service/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ impl<Config: Clone + Send + 'static, S: Service<Config>> ConnectionManager<Confi
// only open connection to parachain after bitcoind sync to prevent timeout
let signer = self.signer.clone();
let btc_parachain = BtcParachain::from_url_and_config_with_retry(
&self.parachain_config.polka_btc_url,
&self.parachain_config.btc_parachain_url,
signer,
self.parachain_config.max_concurrent_requests,
self.parachain_config.max_notifs_per_subscription,
self.parachain_config.polka_btc_connection_timeout_ms,
self.parachain_config.btc_parachain_connection_timeout_ms,
)
.await?;

Expand Down
2 changes: 1 addition & 1 deletion staked-relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "staked-relayer"
version = "0.7.0"
authors = ["Interlay <[email protected]>"]
edition = "2018"
description = "The Staked Relayer client intermediates between Bitcoin Core and the PolkaBTC Parachain."
description = "The Staked Relayer client intermediates between Bitcoin Core and the BTC Parachain."

[dependencies]
parity-scale-codec = "2.0.0"
Expand Down
82 changes: 33 additions & 49 deletions staked-relayer/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# PolkaBTC Staked Relayer
# Staked Relayer

## Responsibilities

- Receive block headers from [Bitcoin Core](https://github.com/bitcoin/bitcoin)
- Submit block headers to the [PolkaBTC Parachain](https://github.com/interlay/BTC-Parachain)
- Submit block headers to the [BTC Parachain](https://github.com/interlay/btc-parachain)
- Monitor the BTC addresses of vaults to report BTC thefts

## Prerequisites
Expand All @@ -14,7 +14,7 @@ Download and start [Bitcoin Core](https://bitcoin.org/en/bitcoin-core/):
bitcoind -regtest -server
```

Build and run the [PolkaBTC Parachain](https://github.com/interlay/btc-parachain):
Build and run the [BTC Parachain](https://github.com/interlay/btc-parachain):

```
git clone [email protected]:interlay/btc-parachain.git
Expand Down Expand Up @@ -50,12 +50,15 @@ FLAGS:
-V, --version Prints version information
OPTIONS:
--auto-register-with-faucet-url <auto-register-with-faucet-url>
Automatically register the staked relayer with collateral received from the faucet and a
--auto-fund-with-faucet-url <auto-fund-with-faucet-url>
Automatically fund the staked relayer with collateral received from the faucet and a
newly generated address. The parameter is the URL of the faucet
--auto-register-with-stake <auto-register-with-stake>
Automatically register the relayer with the given stake (in Planck)
--bitcoin-connection-timeout-ms <bitcoin-connection-timeout-ms>
Timeout in milliseconds to wait for connection to bitcoin-core [default: 60000]
--bitcoin-poll-timeout-ms <bitcoin-poll-timeout-ms>
Timeout in milliseconds to poll Bitcoin [default: 6000]
--bitcoin-relay-start-height <bitcoin-relay-start-height>
Starting height to relay block headers, if not defined use the best height as reported
Expand All @@ -74,8 +77,8 @@ OPTIONS:
Starting height for vault theft checks, if not defined automatically start from the
chain tip
--bitcoin-timeout-ms <bitcoin-timeout-ms>
Timeout in milliseconds to poll Bitcoin [default: 6000]
--btc-parachain-url <btc-parachain-url>
Parachain websocket URL [default: ws://127.0.0.1:9944]
--keyfile <keyfile>
Path to the json file containing key pairs in a map. Valid content of this file is e.g.
Expand All @@ -87,23 +90,34 @@ OPTIONS:
--keyring <keyring>
Keyring to use, mutually exclusive with keyfile
--logging-format <logging-format>
Logging output format [default: full]
--max-batch-size <max-batch-size>
Max batch size for combined block header submission [default: 16]
--oracle-timeout-ms <oracle-timeout-ms>
Timeout in milliseconds to repeat oracle liveness check [default: 5000]
--max-concurrent-requests <max-concurrent-requests>
Maximum number of concurrent requests
--polka-btc-url <polka-btc-url>
Parachain URL, can be over WebSockets or HTTP [default: ws://127.0.0.1:9944]
--max-notifs-per-subscription <max-notifs-per-subscription>
Maximum notification capacity for each subscription
--rpc-cors-domain <rpc-cors-domain>
Comma separated list of allowed origins [default: *]
--network <network>
Bitcoin network type for address encoding [default: regtest]
--status-update-deposit <status-update-deposit>
Default deposit for all automated status proposals [default: 100]
--btc-parachain-connection-timeout-ms <btc-parachain-connection-timeout-ms>
Timeout in milliseconds to wait for connection to btc-parachain [default: 60000]
--required-btc-confirmations: <required-btc-confirmations:>
--required-btc-confirmations <required-btc-confirmations>
Number of confirmations a block needs to have before it is submitted [default: 0]
--restart-policy <restart-policy>
Restart or stop on error [default: always]
--rpc-cors-domain <rpc-cors-domain>
Comma separated list of allowed origins [default: *]
--telemetry-url <telemetry-url> Telemetry endpoint
```

## Example
Expand All @@ -113,34 +127,4 @@ First, ensure you have a running Bitcoin node and a `keyfile.json` as specified
{
"relayer": "car timber smoke zone west involve board success norm inherit door road"
}
```

To register your stake, you can either use your own DOT or request some from our faucet service.


**Using your own DOT**
First, run the staked relayer as in the example below:
```
cargo run -- \
--bitcoin-rpc-url http://localhost:18332 \
--bitcoin-rpc-user rpcuser \
--bitcoin-rpc-pass rpcpass \
--keyfile /path/to/keyfile.json \
--keyname relayer \
--polka-btc-url 'wss://beta.polkabtc.io/api/parachain'
```

Then, once the staked relayer is running, go to https://beta.polkabtc.io to the Relayer page and register by locking some DOT. The relayer client can contribute to the running of PolkaBTC without locking DOT, but interest is only earned if the relayer is registered. You can check its status on the Dashboard page.

**Using DOT from the faucet**
With funding from the faucet, you can run the command below to register your staked relayer with ~1 DOT and also receive ~500DOT to pay for transaction fees:
```
cargo run -- \
--bitcoin-rpc-url http://localhost:18332 \
--bitcoin-rpc-user rpcuser \
--bitcoin-rpc-pass rpcpass \
--keyfile /path/to/keyfile.json \
--keyname relayer \
--polka-btc-url 'wss://beta.polkabtc.io/api/parachain'
--auto-register-with-faucet-url https://beta.polkabtc.io/api/faucet
```
```
2 changes: 1 addition & 1 deletion staked-relayer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct Opts {
#[clap(flatten)]
account_info: runtime::cli::ProviderUserOpts,

/// Connection settings for the BTC-Parachain.
/// Connection settings for the BTC Parachain.
#[clap(flatten)]
parachain: runtime::cli::ConnectionOpts,

Expand Down
2 changes: 1 addition & 1 deletion testdata-gen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "testdata-gen"
version = "0.7.0"
authors = ["Interlay <[email protected]>"]
edition = "2018"
description = "Toolkit for generating testdata on the local BTC-Parachain."
description = "Toolkit for generating testdata on the local BTC Parachain."

[features]
default = ["bitcoin/regtest-mine-on-tx"]
Expand Down
Loading

0 comments on commit e7a13a4

Please sign in to comment.