Skip to content

Commit

Permalink
Release/1.5.0 dusty (#223)
Browse files Browse the repository at this point in the history
* Upgrade to substrate 2.0.0-rc6

* Fork contracts pallet from rc4 and fix build on rc6
* Implemented claim_to method for pallet-plasm-lockdrop
* Limited price oracle calls by filter expiration latency
* Optimized oracle web3 transport by using shared state

* Bump version

* Code format fixes

* plasm-lockdrop: price oracle fixes
  • Loading branch information
akru authored Aug 24, 2020
1 parent f19c08f commit 4f41ba2
Show file tree
Hide file tree
Showing 65 changed files with 13,453 additions and 1,089 deletions.
1,747 changes: 1,123 additions & 624 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ Install additional build tools:

Install the Plasm node from git source:

cargo +nightly install --locked --force --git https://github.com/staketechnologies/Plasm --tag v1.4.0-dusty plasm-cli
cargo +nightly install --locked --force --git https://github.com/staketechnologies/Plasm --tag v1.5.0-dusty plasm-cli

Run node on [Dusty Network](https://telemetry.polkadot.io/#list/Dusty):

Expand Down
64 changes: 31 additions & 33 deletions bin/node/cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "plasm-cli"
version = "1.4.0"
version = "1.5.0"
authors = ["Stake Technologies <[email protected]>"]
description = "Plasm node implementation in Rust."
build = "build.rs"
Expand All @@ -20,7 +20,8 @@ crate-type = ["cdylib", "rlib"]
codec = { package = "parity-scale-codec", version = "1.3" }
serde = { version = "1.0", features = [ "derive" ] }
structopt = { version = "0.3.8", optional = true }
jsonrpc-core = "14.0.3"
jsonrpc-core = "14.2.0"
jsonrpc-pubsub = "14.2.0"
hex-literal = "0.2.1"
serde_json = "1.0"
futures = "0.3.4"
Expand All @@ -29,29 +30,29 @@ log = "0.4.8"
hex = "0.4"

# primitives
sp-core = "2.0.0-rc5"
sp-runtime = "2.0.0-rc5"
sp-inherents = "2.0.0-rc5"
sp-consensus = "0.8.0-rc5"
sp-consensus-babe = "0.8.0-rc5"
sp-finality-grandpa = "2.0.0-rc5"
sp-transaction-pool = "2.0.0-rc5"
sp-core = "2.0.0-rc6"
sp-runtime = "2.0.0-rc6"
sp-inherents = "2.0.0-rc6"
sp-consensus = "0.8.0-rc6"
sp-consensus-babe = "0.8.0-rc6"
sp-finality-grandpa = "2.0.0-rc6"
sp-transaction-pool = "2.0.0-rc6"

# client dependencies
sc-client-api = "2.0.0-rc5"
sc-chain-spec = "2.0.0-rc5"
sc-consensus = "0.8.0-rc5"
sc-executor = "0.8.0-rc5"
sc-transaction-pool = "2.0.0-rc5"
sc-network = "0.8.0-rc5"
sc-finality-grandpa = "0.8.0-rc5"
sc-offchain = "2.0.0-rc5"
sc-client-db = { version = "0.8.0-rc5", default-features = false }
sc-rpc = "2.0.0-rc5"
sc-basic-authorship = "0.8.0-rc5"
sc-service = "0.8.0-rc5"
sc-telemetry = "2.0.0-rc5"
sc-consensus-babe = "0.8.0-rc5"
sc-client-api = "2.0.0-rc6"
sc-chain-spec = "2.0.0-rc6"
sc-consensus = "0.8.0-rc6"
sc-executor = "0.8.0-rc6"
sc-transaction-pool = "2.0.0-rc6"
sc-network = "0.8.0-rc6"
sc-finality-grandpa = "0.8.0-rc6"
sc-offchain = "2.0.0-rc6"
sc-client-db = { version = "0.8.0-rc6", default-features = false }
sc-rpc = "2.0.0-rc6"
sc-basic-authorship = "0.8.0-rc6"
sc-service = "0.8.0-rc6"
sc-telemetry = "2.0.0-rc6"
sc-consensus-babe = "0.8.0-rc6"

# plasm-specific dependencies
lockdrop-oracle = { path = "./lockdrop-oracle" }
Expand All @@ -60,22 +61,20 @@ plasm-runtime = { path = "../runtime" }
plasm-rpc = { path = "../rpc" }

# frame dependencies
frame-system = "2.0.0-rc5"
pallet-contracts = { version = "=2.0.0-rc4", default-features = false }
pallet-transaction-payment = "2.0.0-rc5"
pallet-finality-tracker = "2.0.0-rc5"
frame-system = "2.0.0-rc6"
pallet-transaction-payment = "2.0.0-rc6"
pallet-finality-tracker = "2.0.0-rc6"
pallet-contracts = { path = "../../../frame/contracts", default-features = false }
pallet-dapps-staking = { path = "../../../frame/dapps-staking" }
pallet-plasm-lockdrop = { path = "../../../frame/plasm-lockdrop" }
pallet-ovm = { path = "../../../frame/ovm" }

# CLI-specific dependencies
sc-cli = { version = "0.8.0-rc5", optional = true }
frame-benchmarking-cli = { version = "2.0.0-rc5", optional = true }
sc-cli = { version = "0.8.0-rc6", optional = true }

[build-dependencies]
sc-cli = "0.8.0-rc5"
frame-benchmarking-cli = { version = "2.0.0-rc5", optional = true }
build-script-utils = { package = "substrate-build-script-utils", version = "2.0.0-rc5" }
sc-cli = "0.8.0-rc6"
build-script-utils = { package = "substrate-build-script-utils", version = "2.0.0-rc6" }
lockdrop-oracle = { path = "./lockdrop-oracle" }
structopt = { version = "0.3.8", optional = true }
vergen = { version = "3.0.4", optional = true }
Expand All @@ -84,7 +83,6 @@ vergen = { version = "3.0.4", optional = true }
default = ["cli"]
cli = [
"sc-cli",
"frame-benchmarking-cli",
"sc-service/db",
"structopt",
"vergen",
Expand Down
4 changes: 2 additions & 2 deletions bin/node/cli/lockdrop-oracle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ pallet-plasm-lockdrop = { path = "../../../../frame/plasm-lockdrop" }
reqwest = { version = "0.10", default-features = false, features = ["rustls-tls", "json", "blocking"] }
web3 = { version = "0.11", default-features = false, features = ["http","tls"] }
ethabi = "12.0"
sp-core = "2.0.0-rc5"
sc-service = "0.8.0-rc5"
sp-core = "2.0.0-rc6"
sc-service = "0.8.0-rc6"
bitcoin-script = "0.1.1"
bitcoin = "0.23.0"
libsecp256k1 = "0.3.5"
Expand Down
12 changes: 5 additions & 7 deletions bin/node/cli/lockdrop-oracle/src/chainlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ use web3::types::Address;
const ETHUSD: &str = "5f4eC3Df9cbd43714FE2740f5E3616155c5b8419";
const BTCUSD: &str = "F4030086522a5bEEa4988F8cA5B36dbC97BeE88c";

pub fn query(endpoint: &str, contract: Address) -> u128 {
let (_eloop, transport) = web3::transports::Http::new(endpoint).unwrap();
let web3 = web3::Web3::new(transport);
pub fn query<T: web3::Transport>(web3: web3::Web3<T>, contract: Address) -> u128 {
let contract = Contract::from_json(
web3.eth(),
contract,
Expand All @@ -21,10 +19,10 @@ pub fn query(endpoint: &str, contract: Address) -> u128 {
.unwrap()
}

pub fn eth_usd(endpoint: &str) -> u128 {
query(endpoint, ETHUSD.parse().unwrap())
pub fn eth_usd<T: web3::Transport>(web3: web3::Web3<T>) -> u128 {
query(web3, ETHUSD.parse().unwrap())
}

pub fn btc_usd(endpoint: &str) -> u128 {
query(endpoint, BTCUSD.parse().unwrap())
pub fn btc_usd<T: web3::Transport>(web3: web3::Web3<T>) -> u128 {
query(web3, BTCUSD.parse().unwrap())
}
2 changes: 2 additions & 0 deletions bin/node/cli/lockdrop-oracle/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ use structopt::StructOpt;

#[derive(Debug, Clone, StructOpt)]
pub struct Config {
/*
/// Bitcoin node endpoint.
#[structopt(long, default_value = "https://api.blockcypher.com/v1/btc/test3/txs")]
pub bitcoin_endpoint: String,
/// Bitcoin minimum transaction confirmations.
#[structopt(long, default_value = "8")]
pub safe_btc_confirmations: u64,
*/
/// Ethereum node endpoint.
#[structopt(long, default_value = "https://ropsten.infura.io/v3")]
pub ethereum_endpoint: String,
Expand Down
50 changes: 34 additions & 16 deletions bin/node/cli/lockdrop-oracle/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,35 @@ mod eth_utils;

pub use cli::Config;

struct ServerState {
pub feeds_transport: web3::transports::Http,
pub ethereum_transport: web3::transports::Http,
pub lockdrop_contract: web3::types::Address,
pub safe_eth_confirmations: u64,
}

pub async fn start(config: Config) {
let mut app = tide::with_state(config);
let (_eloop, feeds_transport) =
web3::transports::Http::new(config.feeds_endpoint.as_str()).unwrap();
let (_eloop, ethereum_transport) =
web3::transports::Http::new(config.ethereum_endpoint.as_str()).unwrap();
let lockdrop_contract = config.lockdrop_contract.parse().unwrap();
let safe_eth_confirmations = config.safe_eth_confirmations;
let mut app = tide::with_state(ServerState {
feeds_transport,
ethereum_transport,
lockdrop_contract,
safe_eth_confirmations,
});

app.at("/btc/ticker")
.get(|req: tide::Request<Config>| async move {
let endpoint = req.state().feeds_endpoint.as_str();
let usd_price = chainlink::btc_usd(endpoint) / 10_u128.pow(8);
Ok(usd_price.to_string())
});

app.at("/eth/ticker")
.get(|req: tide::Request<Config>| async move {
let endpoint = req.state().feeds_endpoint.as_str();
let usd_price = chainlink::eth_usd(endpoint) / 10_u128.pow(8);
.get(|req: tide::Request<ServerState>| async move {
let web3 = web3::Web3::new(req.state().feeds_transport.clone());
let usd_price = chainlink::btc_usd(web3) / 10_u128.pow(8);
Ok(usd_price.to_string())
});

/*
app.at("/btc/lock")
.post(|mut req: tide::Request<Config>| async move {
let body = req.body_bytes().await?;
Expand Down Expand Up @@ -84,19 +96,25 @@ pub async fn start(config: Config) {
log::debug!(target: "lockdrop-oracle", "transaction output (recipient and value) mismatch");
Ok(Response::new(StatusCode::BadRequest))
});
*/

app.at("/eth/ticker")
.get(|req: tide::Request<ServerState>| async move {
let web3 = web3::Web3::new(req.state().feeds_transport.clone());
let usd_price = chainlink::eth_usd(web3) / 10_u128.pow(8);
Ok(usd_price.to_string())
});

app.at("/eth/lock")
.post(|mut req: tide::Request<Config>| async move {
.post(|mut req: tide::Request<ServerState>| async move {
let body = req.body_bytes().await?;
let lock = LockCheck::decode(&mut &body[..])?;
log::debug!(
target: "lockdrop-oracle",
"ETH lock check request: {:#?}", lock
);

let (_eloop, transport) =
web3::transports::Http::new(req.state().ethereum_endpoint.as_str()).unwrap();
let web3 = web3::Web3::new(transport);
let web3 = web3::Web3::new(req.state().ethereum_transport.clone());
let block_number = web3.eth().block_number().wait()?;
let tx = web3
.eth()
Expand Down Expand Up @@ -143,7 +161,7 @@ pub async fn start(config: Config) {
}

// check that destination is lockdrop smart contract
if tx.to != Some(req.state().lockdrop_contract.parse()?) {
if tx.to != Some(req.state().lockdrop_contract) {
log::debug!(target: "lockdrop-oracle", "contract address mismatch");
return Ok(Response::new(StatusCode::BadRequest));
}
Expand Down
10 changes: 5 additions & 5 deletions bin/node/cli/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,12 @@ fn make_genesis(
pallet_plasm_lockdrop: Some(PlasmLockdropConfig {
// Alpha2: 0.44698108660714747
alpha: Perbill::from_parts(446_981_087),
// Price in cents: BTC $9100, ETH $230
dollar_rate: (9_100, 230),
vote_threshold: 0,
positive_votes: 0,
// Price in dollars: BTC $11000, ETH $400
dollar_rate: (11_000, 400),
vote_threshold: 1,
positive_votes: 1,
// Start from launch for testing purposes
lockdrop_bounds: (0, 0),
lockdrop_bounds: (0, 1_000),
keys: vec![],
}),
pallet_session: Some(SessionConfig {
Expand Down
3 changes: 0 additions & 3 deletions bin/node/cli/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ pub enum Subcommand {
/// A set of base subcommands handled by `sc_cli`.
#[structopt(flatten)]
Base(sc_cli::Subcommand),
/// The custom benchmark subcommmand benchmarking runtime pallets.
#[structopt(name = "benchmark", about = "Benchmark runtime pallets.")]
Benchmark(frame_benchmarking_cli::BenchmarkCmd),
/// Plasm Lockdrop oracle authority support module.
#[structopt(name = "oracle", about = "Launch lockdrop oracle module.")]
LockdropOracle(lockdrop_oracle::Config),
Expand Down
38 changes: 11 additions & 27 deletions bin/node/cli/src/command.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use crate::service::new_partial;
///! Node command handler.
use crate::{chain_spec, service, Cli, Subcommand};
use plasm_runtime::Block;
use sc_cli::{ChainSpec, Role, RuntimeVersion, SubstrateCli};
use sc_service::ServiceParams;
use sc_service::PartialComponents;

impl SubstrateCli for Cli {
fn impl_name() -> String {
Expand Down Expand Up @@ -57,39 +58,22 @@ pub fn run() -> sc_cli::Result<()> {
_ => service::new_full(config),
})
}
Some(Subcommand::Benchmark(cmd)) => {
if cfg!(feature = "runtime-benchmarks") {
let runner = cli.create_runner(cmd)?;

runner.sync_run(|config| cmd.run::<Block, service::Executor>(config))
} else {
println!(
"Benchmarking wasn't enabled when building the node. \
You can enable it with `--features runtime-benchmarks`."
);
Ok(())
}
}
Some(Subcommand::Base(subcommand)) => {
let runner = cli.create_runner(subcommand)?;

runner.run_subcommand(subcommand, |config| {
let (
ServiceParams {
client,
backend,
import_queue,
task_manager,
..
},
..,
) = service::new_full_params(config)?;
let PartialComponents {
client,
backend,
task_manager,
import_queue,
..
} = new_partial(&config)?;
Ok((client, backend, import_queue, task_manager))
})
}
Some(Subcommand::LockdropOracle(config)) => {
sc_cli::init_logger("");
log::info!("Plasm Lockdrop oracle launched.");
log::info!("Plasm Lockdrop oracle launch...");
Ok(futures::executor::block_on(lockdrop_oracle::start(
config.clone(),
)))
Expand Down
Loading

0 comments on commit 4f41ba2

Please sign in to comment.