Skip to content
This repository has been archived by the owner on Nov 15, 2023. It is now read-only.

bugfix: balances::transfer for new_account issue#722 #731

Merged
merged 9 commits into from
Sep 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
323 changes: 102 additions & 221 deletions Cargo.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions core/cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ substrate-client = { path = "../../core/client" }
substrate-network = { path = "../../core/network" }
substrate-network-libp2p = { path = "../../core/network-libp2p" }
sr-primitives = { path = "../../core/sr-primitives" }
substrate-primitives = { path = "../../core/primitives" }
substrate-service = { path = "../../core/service" }
substrate-telemetry = { path = "../../core/telemetry" }
names = "0.11.0"
Expand Down
7 changes: 5 additions & 2 deletions core/cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ extern crate substrate_network as network;
extern crate substrate_network_libp2p as network_libp2p;
extern crate sr_primitives as runtime_primitives;
extern crate substrate_service as service;
extern crate substrate_primitives as primitives;
#[macro_use]
extern crate slog; // needed until we can reexport `slog_info` from `substrate_telemetry`
#[macro_use]
Expand All @@ -64,13 +65,15 @@ use service::{
FactoryGenesis, PruningMode, ChainSpec,
};
use network::NonReservedPeerMode;
use primitives::H256;

use std::io::{Write, Read, stdin, stdout};
use std::iter;
use std::fs;
use std::fs::File;
use std::net::{Ipv4Addr, SocketAddr};
use std::path::{Path, PathBuf};
use std::str::FromStr;
use names::{Generator, Name};
use regex::Regex;

Expand Down Expand Up @@ -311,8 +314,8 @@ where
config.network.public_addresses = Vec::new();

config.network.client_version = config.client_id();
config.network.use_secret = match matches.value_of("node-key").map(|s| s.parse()) {
Some(Ok(secret)) => Some(secret),
config.network.use_secret = match matches.value_of("node-key").map(H256::from_str) {
Some(Ok(secret)) => Some(secret.into()),
Some(Err(err)) => return Err(format!("Error parsing node key: {}", err).into()),
None => None,
};
Expand Down
6 changes: 1 addition & 5 deletions core/network-libp2p/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ bytes = "0.4"
error-chain = { version = "0.12", default-features = false }
fnv = "1.0"
futures = "0.1"
libp2p = { git = "https://github.com/libp2p/rust-libp2p", rev = "304e9c72c88bc97824f2734dc19d1b5f4556d346", default-features = false, features = ["libp2p-secio", "libp2p-secio-secp256k1"] }
ethcore-io = { git = "https://github.com/paritytech/parity.git" }
ethkey = { git = "https://github.com/paritytech/parity.git" }
libp2p = { git = "https://github.com/libp2p/rust-libp2p", rev = "5980a4538ef6fc8af450893acb01290eaed136de", default-features = false, features = ["libp2p-secio", "libp2p-secio-secp256k1"] }
ethereum-types = "0.3"
parking_lot = "0.5"
libc = "0.2"
Expand All @@ -30,5 +28,3 @@ unsigned-varint = { version = "0.2.1", features = ["codec"] }
[dev-dependencies]
assert_matches = "1.2"
parity-bytes = "0.1"
ethcore-io = { git = "https://github.com/paritytech/parity.git" }
ethcore-logger = { git = "https://github.com/paritytech/parity.git" }
17 changes: 0 additions & 17 deletions core/network-libp2p/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

use std::{io, net, fmt};
use libc::{ENFILE, EMFILE};
use io::IoError;
use ethkey;

#[derive(Debug, Copy, Clone, PartialEq, Eq)]
pub enum DisconnectReason
Expand Down Expand Up @@ -82,10 +80,6 @@ impl fmt::Display for DisconnectReason {
}

error_chain! {
foreign_links {
SocketIo(IoError) #[doc = "Socket IO error."];
}

errors {
#[doc = "Error concerning the network address parsing subsystem."]
AddressParse {
Expand Down Expand Up @@ -171,17 +165,6 @@ impl From<io::Error> for Error {
}
}

impl From<ethkey::Error> for Error {
fn from(_err: ethkey::Error) -> Self {
ErrorKind::Auth.into()
}
}

impl From<ethkey::crypto::Error> for Error {
fn from(_err: ethkey::crypto::Error) -> Self {
ErrorKind::Auth.into()
}
}

impl From<net::AddrParseError> for Error {
fn from(_err: net::AddrParseError) -> Self { ErrorKind::AddressParse.into() }
Expand Down
5 changes: 2 additions & 3 deletions core/network-libp2p/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ extern crate futures;
extern crate tokio;
extern crate tokio_io;
extern crate tokio_timer;
extern crate ethkey;
extern crate libc;
extern crate libp2p;
extern crate rand;
Expand All @@ -38,7 +37,6 @@ extern crate serde_json;
extern crate bytes;
extern crate unsigned_varint;

extern crate ethcore_io as io;
extern crate ethereum_types;

#[macro_use]
Expand All @@ -49,11 +47,12 @@ extern crate log;
extern crate assert_matches;

pub use connection_filter::{ConnectionFilter, ConnectionDirection};
pub use io::TimerToken;
pub use error::{Error, ErrorKind, DisconnectReason};
pub use libp2p::{Multiaddr, multiaddr::AddrComponent};
pub use traits::*;

pub type TimerToken = usize;

mod connection_filter;
mod custom_proto;
mod error;
Expand Down
6 changes: 4 additions & 2 deletions core/network-libp2p/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,9 @@ use std::iter;
use std::net::Ipv4Addr;
use std::str;
use std::time::Duration;
use io::TimerToken;
use TimerToken;
use libp2p::{multiaddr::AddrComponent, Multiaddr};
use error::Error;
use ethkey::Secret;
use ethereum_types::H512;

/// Protocol handler level packet id
Expand All @@ -37,6 +36,9 @@ pub type NodeId = H512;
/// Local (temporary) peer session ID.
pub type NodeIndex = usize;

/// secio secret key;
pub type Secret = [u8; 32];

/// Shared session information
#[derive(Debug, Clone)]
pub struct SessionInfo {
Expand Down
4 changes: 1 addition & 3 deletions core/network-libp2p/src/transport.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,7 @@ pub fn build_transport(
mplex_config.max_buffer_len(usize::MAX);

let base = libp2p::CommonTransport::new()
.with_upgrade(secio::SecioConfig {
key: local_private_key,
})
.with_upgrade(secio::SecioConfig::new(local_private_key))
.and_then(move |out, endpoint, client_addr| {
let upgrade = upgrade::or(
upgrade::map(mplex_config, either::EitherOutput::First),
Expand Down
8 changes: 1 addition & 7 deletions core/network-libp2p/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@

extern crate parking_lot;
extern crate parity_bytes;
extern crate ethcore_io as io;
extern crate ethcore_logger;
extern crate substrate_network_libp2p;
extern crate ethkey;

use std::sync::atomic::{AtomicBool, Ordering as AtomicOrdering};
use std::sync::Arc;
Expand All @@ -28,8 +25,7 @@ use std::time::*;
use parking_lot::Mutex;
use parity_bytes::Bytes;
use substrate_network_libp2p::*;
use ethkey::{Random, Generator};
use io::TimerToken;
use TimerToken;

pub struct TestProtocol {
drop_session: bool,
Expand Down Expand Up @@ -102,9 +98,7 @@ fn net_service() {
#[test]
#[ignore] // TODO: how is this test even supposed to work?
fn net_disconnect() {
let key1 = Random.generate().unwrap();
let mut config1 = NetworkConfiguration::new_local();
config1.use_secret = Some(key1.secret().clone());
config1.boot_nodes = vec![ ];
let handler1 = Arc::new(TestProtocol::new(false));
let service1 = NetworkService::new(config1, vec![(handler1.clone(), *b"tst", &[(42u8, 1), (43u8, 1)])]).unwrap();
Expand Down
1 change: 0 additions & 1 deletion core/network/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ bitflags = "1.0"
futures = "0.1.17"
linked-hash-map = "0.5"
rustc-hex = "1.0"
ethcore-io = { git = "https://github.com/paritytech/parity.git" }
substrate-primitives = { path = "../../core/primitives" }
substrate-client = { path = "../../core/client" }
sr-primitives = { path = "../../core/sr-primitives" }
Expand Down
1 change: 0 additions & 1 deletion core/network/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
//! Allows attachment of an optional subprotocol for chain-specific requests.
// end::description[]

extern crate ethcore_io as core_io;
extern crate linked_hash_map;
extern crate parking_lot;
extern crate substrate_primitives as primitives;
Expand Down
3 changes: 2 additions & 1 deletion core/network/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use futures::sync::{oneshot, mpsc};
use network_libp2p::{NetworkProtocolHandler, NetworkContext, NodeIndex, ProtocolId,
NetworkConfiguration , NonReservedPeerMode, ErrorKind};
use network_libp2p::{NetworkService};
use core_io::{TimerToken};
use io::NetSyncIo;
use protocol::{Protocol, ProtocolContext, Context, ProtocolStatus, PeerInfo as ProtocolPeerInfo};
use config::{ProtocolConfig};
Expand All @@ -39,6 +38,8 @@ pub type FetchFuture = oneshot::Receiver<Vec<u8>>;
/// Type that represents bft messages stream.
pub type BftMessageStream<B> = mpsc::UnboundedReceiver<LocalizedBftMessage<B>>;

type TimerToken = usize;

const TICK_TOKEN: TimerToken = 0;
const TICK_TIMEOUT: Duration = Duration::from_millis(1000);

Expand Down
6 changes: 6 additions & 0 deletions node/executor/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ mod tests {
twox_128(<balances::TransactionBaseFee<Runtime>>::key()).to_vec() => vec![70u8; 8],
twox_128(<balances::TransactionByteFee<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::ExistentialDeposit<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::CreationFee<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::TransferFee<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::NextEnumSet<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(&<system::BlockHash<Runtime>>::key_for(0)).to_vec() => vec![0u8; 32]
Expand All @@ -141,6 +142,7 @@ mod tests {
twox_128(<balances::TransactionBaseFee<Runtime>>::key()).to_vec() => vec![70u8; 8],
twox_128(<balances::TransactionByteFee<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::ExistentialDeposit<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::CreationFee<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::TransferFee<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::NextEnumSet<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(&<system::BlockHash<Runtime>>::key_for(0)).to_vec() => vec![0u8; 32]
Expand All @@ -161,6 +163,7 @@ mod tests {
twox_128(<balances::TransactionBaseFee<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::TransactionByteFee<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::ExistentialDeposit<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::CreationFee<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::TransferFee<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::NextEnumSet<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(&<system::BlockHash<Runtime>>::key_for(0)).to_vec() => vec![0u8; 32]
Expand All @@ -185,6 +188,7 @@ mod tests {
twox_128(<balances::TransactionBaseFee<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::TransactionByteFee<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::ExistentialDeposit<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::CreationFee<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::TransferFee<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::NextEnumSet<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(&<system::BlockHash<Runtime>>::key_for(0)).to_vec() => vec![0u8; 32]
Expand Down Expand Up @@ -483,6 +487,7 @@ mod tests {
twox_128(<balances::TransactionBaseFee<Runtime>>::key()).to_vec() => vec![70u8; 8],
twox_128(<balances::TransactionByteFee<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::ExistentialDeposit<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::CreationFee<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::TransferFee<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::NextEnumSet<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(&<system::BlockHash<Runtime>>::key_for(0)).to_vec() => vec![0u8; 32]
Expand All @@ -504,6 +509,7 @@ mod tests {
twox_128(<balances::TransactionBaseFee<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::TransactionByteFee<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::ExistentialDeposit<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::CreationFee<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::TransferFee<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(<balances::NextEnumSet<Runtime>>::key()).to_vec() => vec![0u8; 8],
twox_128(&<system::BlockHash<Runtime>>::key_for(0)).to_vec() => vec![0u8; 32]
Expand Down
4 changes: 2 additions & 2 deletions srml/balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,8 @@ impl<T: Trait> Module<T> {

let dest = Self::lookup(dest)?;
let from_balance = Self::free_balance(&transactor);
let would_create = from_balance.is_zero();
let to_balance = Self::free_balance(&dest);
let would_create = to_balance.is_zero();
let fee = if would_create { Self::creation_fee() } else { Self::transfer_fee() };
let liability = value + fee;

Expand All @@ -297,7 +298,6 @@ impl<T: Trait> Module<T> {
}
T::EnsureAccountLiquid::ensure_account_liquid(&transactor)?;

let to_balance = Self::free_balance(&dest);
// NOTE: total stake being stored in the same type means that this could never overflow
// but better to be safe than sorry.
let new_to_balance = match to_balance.checked_add(&value) {
Expand Down
23 changes: 23 additions & 0 deletions srml/balances/src/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,28 @@ pub fn new_test_ext(ext_deposit: u64, monied: bool) -> runtime_io::TestExternali
t.into()
}

pub fn new_test_ext2(ext_deposit: u64, monied: bool) -> runtime_io::TestExternalities<Blake2Hasher> {
let mut t = system::GenesisConfig::<Runtime>::default().build_storage().unwrap();
let balance_factor = if ext_deposit > 0 {
256
} else {
1
};
t.extend(GenesisConfig::<Runtime>{
balances: if monied {
vec![(1, 10 * balance_factor), (2, 20 * balance_factor), (3, 30 * balance_factor), (4, 40 * balance_factor)]
} else {
vec![(10, balance_factor), (20, balance_factor)]
},
transaction_base_fee: 0,
transaction_byte_fee: 0,
existential_deposit: ext_deposit,
transfer_fee: 10, // transfer_fee not zero
creation_fee: 50, // creation_fee not zero
reclaim_rebate: 0,
}.build_storage().unwrap());
t.into()
}

pub type System = system::Module<Runtime>;
pub type Balances = Module<Runtime>;
Loading