Skip to content
This repository has been archived by the owner on Jul 27, 2022. It is now read-only.

Commit

Permalink
Merge #442 #460 #463
Browse files Browse the repository at this point in the history
442: Problem: (CRO-145) no HD-wallet support r=tomtau a=leejw51crypto

Solution: add bip 39, 44 cargo, and modify to use it


connect hdwallet


connect basic key service


choose hdkey


hd wallet works


add mnemonics functions


add wallet kind in constructing wallet


hdwallet & mnemonics works


decouple wallet kind to setup first


client-cli now works


refactoring


process basic wallet


hide logs


tidy up


fix clippy issues


fix clippy issue



460: Bump jsonrpc-derive from 13.2.0 to 14.0.0 r=tomtau a=dependabot-preview[bot]

Bumps [jsonrpc-derive](https://github.com/paritytech/jsonrpc) from 13.2.0 to 14.0.0.
<details>
<summary>Commits</summary>

- [`7b94363`](paritytech/jsonrpc@7b94363) Bump to 14.0 ([#496](https://github-redirect.dependabot.com/paritytech/jsonrpc/issues/496))
- [`3b790c6`](paritytech/jsonrpc@3b790c6) Fix threading and closing of servers ([#495](https://github-redirect.dependabot.com/paritytech/jsonrpc/issues/495))
- [`d8cfec5`](paritytech/jsonrpc@d8cfec5) Run format only on stable @ linux. ([#494](https://github-redirect.dependabot.com/paritytech/jsonrpc/issues/494))
- [`77d7fb6`](paritytech/jsonrpc@77d7fb6) fix for [#490](https://github-redirect.dependabot.com/paritytech/jsonrpc/issues/490), related to [paritytech/parity-tokio-ipc#15](https://github-redirect.dependabot.com/NikVolf/parity-tokio-ipc/issues/15) ([#491](https://github-redirect.dependabot.com/paritytech/jsonrpc/issues/491))
- See full diff in [compare view](paritytech/jsonrpc@v13.2.0...v14.0.0)
</details>
<br />

[![Dependabot compatibility score](https://api.dependabot.com/badges/compatibility_score?dependency-name=jsonrpc-derive&package-manager=cargo&previous-version=13.2.0&new-version=14.0.0)](https://dependabot.com/compatibility-score.html?dependency-name=jsonrpc-derive&package-manager=cargo&previous-version=13.2.0&new-version=14.0.0)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
- `@dependabot use these labels` will set the current labels as the default for future PRs for this repo and language
- `@dependabot use these reviewers` will set the current reviewers as the default for future PRs for this repo and language
- `@dependabot use these assignees` will set the current assignees as the default for future PRs for this repo and language
- `@dependabot use this milestone` will set the current milestone as the default for future PRs for this repo and language
- `@dependabot badge me` will comment on this PR with code to add a "Dependabot enabled" badge to your readme

Additionally, you can set the following in your Dependabot [dashboard](https://app.dependabot.com):
- Update frequency (including time of day and day of week)
- Pull request limits (per update run and/or open at any time)
- Out-of-range updates (receive only lockfile updates, if desired)
- Security updates (receive only security updates, if desired)



</details>

463: Problem: (CRO-452) Byzantine validators are not jailed r=tomtau a=devashishdxt

Solution: Jail byzantine validators in begin block

Co-authored-by: Jongwhan Lee <jonghwan@crypto.com>
Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Devashish Dixit <devashish@crypto.com>
  • Loading branch information
4 people authored Oct 10, 2019
4 parents 9d3e5fb + c0887ed + 35c33fd + 5f31161 commit 227ce89
Show file tree
Hide file tree
Showing 20 changed files with 883 additions and 54 deletions.
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

191 changes: 191 additions & 0 deletions chain-abci/src/app/jail_account.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
use chain_core::state::account::StakedStateAddress;
use chain_core::state::tendermint::TendermintVotePower;
use chain_tx_validation::Error;

use crate::app::{update_account, ChainNodeApp};
use crate::enclave_bridge::EnclaveProxy;
use crate::storage::tx::get_account;

impl<T: EnclaveProxy> ChainNodeApp<T> {
/// Jails staking account with given address
pub fn jail_account(&mut self, staking_address: StakedStateAddress) -> Result<(), Error> {
let mut account = get_account(
&staking_address,
&self.uncommitted_account_root_hash,
&self.accounts,
)?;

let last_state = self
.last_state
.as_ref()
.expect("Last state not found. Init chain was not called.");

let block_time = last_state.block_time;
let jail_duration: i64 = last_state.jailing_config.jail_duration.into();

account.jail_until(block_time + jail_duration);

let (new_root, _) = update_account(
account,
&self.uncommitted_account_root_hash,
&mut self.accounts,
);
self.uncommitted_account_root_hash = new_root;
self.power_changed_in_block
.insert(staking_address, TendermintVotePower::zero());

Ok(())
}
}

#[cfg(test)]
mod tests {
use super::*;

use std::collections::BTreeMap;
use std::sync::Arc;

use abci::{Application, PubKey, RequestInitChain};
use kvdb_memorydb::create;
use protobuf::well_known_types::Timestamp;
use secp256k1::{key::PublicKey, key::SecretKey, Secp256k1};

use chain_core::common::MerkleTree;
use chain_core::compute_app_hash;
use chain_core::init::address::RedeemAddress;
use chain_core::init::coin::Coin;
use chain_core::init::config::{
AccountType, InitConfig, InitNetworkParameters, InitialValidator, JailingParameters,
ValidatorKeyType,
};
use chain_core::tx::fee::{LinearFee, Milli};

use crate::enclave_bridge::mock::MockClient;
use crate::storage::account::{AccountStorage, AccountWrapper};
use crate::storage::tx::StarlingFixedKey;
use crate::storage::{Storage, NUM_COLUMNS};

const TEST_CHAIN_ID: &str = "test-00";

#[test]
fn check_successful_jailing() {
let storage = Storage::new_db(Arc::new(create(NUM_COLUMNS.unwrap())));
let mut account_storage =
AccountStorage::new(Storage::new_db(Arc::new(create(1))), 20).expect("account db");

let secp = Secp256k1::new();
let secret_key = SecretKey::from_slice(&[0xcd; 32]).expect("32 bytes, within curve order");
let public_key = PublicKey::from_secret_key(&secp, &secret_key);
let address = RedeemAddress::from(&public_key);
let staking_account_address = StakedStateAddress::BasicRedeem(address);

let mut validator_pubkey = PubKey::new();
validator_pubkey.field_type = "Ed25519".to_string();
validator_pubkey.data =
base64::decode("EIosObgfONUsnWCBGRpFlRFq5lSxjGIChRlVrVWVkcE=").unwrap();

let mut validator_voting_power = BTreeMap::new();
validator_voting_power.insert(staking_account_address, TendermintVotePower::zero());

let mut distribution = BTreeMap::new();
distribution.insert(address, (Coin::max(), AccountType::ExternallyOwnedAccount));
distribution.insert(
RedeemAddress::default(),
(Coin::zero(), AccountType::Contract),
);

let init_network_params = InitNetworkParameters {
initial_fee_policy: LinearFee::new(Milli::new(0, 0), Milli::new(0, 0)),
required_council_node_stake: Coin::max(),
unbonding_period: 1,
jailing_config: JailingParameters {
jail_duration: 60,
block_signing_window: 5,
missed_block_threshold: 1,
},
};

let init_config = InitConfig::new(
distribution,
RedeemAddress::default(),
RedeemAddress::default(),
RedeemAddress::default(),
init_network_params,
vec![InitialValidator {
staking_account_address: address,
consensus_pubkey_type: ValidatorKeyType::Ed25519,
consensus_pubkey_b64: "EIosObgfONUsnWCBGRpFlRFq5lSxjGIChRlVrVWVkcE=".to_string(),
}],
);

let timestamp = Timestamp::new();

let (accounts, rewards_pool_state, _) = init_config
.validate_config_get_genesis(timestamp.get_seconds())
.expect("Error while validating distribution");

let mut keys: Vec<StarlingFixedKey> =
accounts.iter().map(|account| account.key()).collect();
let mut wrapped: Vec<AccountWrapper> = accounts
.iter()
.map(|account| AccountWrapper(account.clone()))
.collect();

let new_account_root = account_storage
.insert(None, &mut keys, &mut wrapped)
.expect("initial insert");

let transaction_tree = MerkleTree::empty();

let genesis_app_hash =
compute_app_hash(&transaction_tree, &new_account_root, &rewards_pool_state);

let mut app = ChainNodeApp::new_with_storage(
MockClient::new(0),
&hex::encode_upper(genesis_app_hash),
TEST_CHAIN_ID,
storage,
account_storage,
);

// Init Chain

let mut request_init_chain = RequestInitChain::default();
request_init_chain.set_time(timestamp);
request_init_chain.set_app_state_bytes(serde_json::to_vec(&init_config).unwrap());
request_init_chain.set_chain_id(String::from(TEST_CHAIN_ID));
let response_init_chain = app.init_chain(&request_init_chain);

let validators = response_init_chain.validators.to_vec();

assert_eq!(1, validators.len());
assert_eq!(
100000000000,
i64::from(
*app.validator_voting_power
.get(&staking_account_address)
.unwrap()
)
);

// Check jailing

app.jail_account(staking_account_address)
.expect("Unable to jail account");

let account = get_account(
&staking_account_address,
&app.uncommitted_account_root_hash,
&app.accounts,
)
.unwrap();

assert!(account.is_jailed());
assert_eq!(
TendermintVotePower::zero(),
*app.power_changed_in_block
.get(&staking_account_address)
.unwrap()
);
}
}
45 changes: 33 additions & 12 deletions chain-abci/src/app/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod app_init;
mod commit;
mod jail_account;
mod query;
mod validate_tx;

Expand All @@ -26,7 +27,7 @@ use enclave_protocol::{EnclaveRequest, EnclaveResponse};
use kvdb::{DBTransaction, KeyValueDB};
use protobuf::RepeatedField;
use std::collections::BTreeMap;
use std::convert::TryInto;
use std::convert::{TryFrom, TryInto};
use std::sync::Arc;

/// Given a db and a DB transaction, it will go through TX inputs and mark them as spent
Expand Down Expand Up @@ -129,22 +130,42 @@ impl<T: EnclaveProxy> abci::Application for ChainNodeApp<T> {
),
};

let last_state = self
{
let last_state = self
.last_state
.as_mut()
.expect("executing begin block, but no app state stored (i.e. no initchain or recovery was executed)");

last_state.block_time = block_time;
last_state.block_time = block_time;

if block_height > 1 {
if let Some(last_commit_info) = req.last_commit_info.as_ref() {
// liveness will always be updated for previous block, i.e., `block_height - 1`
update_validator_liveness(last_state, block_height - 1, last_commit_info);
} else {
panic!(
"No last commit info in begin block request for height: {}",
block_height
);
if block_height > 1 {
if let Some(last_commit_info) = req.last_commit_info.as_ref() {
// liveness will always be updated for previous block, i.e., `block_height - 1`
update_validator_liveness(last_state, block_height - 1, last_commit_info);
} else {
panic!(
"No last commit info in begin block request for height: {}",
block_height
);
}
}
}

for evidence in req.byzantine_validators.iter() {
if let Some(validator) = evidence.validator.as_ref() {
let validator_address =
TendermintValidatorAddress::try_from(validator.address.as_slice())
.expect("Invalid validator address in begin block request");
let account_address = self
.last_state
.as_ref()
.unwrap()
.validator_liveness
.get(&validator_address)
.expect("Validator not found in liveness tracker")
.address();
self.jail_account(account_address)
.expect("Unable to jail account in begin block");
}
}

Expand Down
6 changes: 6 additions & 0 deletions chain-abci/src/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ impl LivenessTracker {
let zero_count = self.liveness.iter().filter(|x| !x).count();
zero_count < missed_block_threshold as usize
}

/// Returns staking address of current tracker
#[inline]
pub fn address(&self) -> StakedStateAddress {
self.address
}
}

impl Encode for LivenessTracker {
Expand Down
Loading

0 comments on commit 227ce89

Please sign in to comment.