From de1f0c3ef824fca91036875a22c9afc6ab44e4d2 Mon Sep 17 00:00:00 2001 From: Gav Date: Mon, 14 May 2018 17:52:12 +0200 Subject: [PATCH] Balance is 128-bit value. --- Cargo.lock | 2 +- polkadot/primitives/src/lib.rs | 19 +++++++++++++------ substrate/codec/src/slicable.rs | 2 +- substrate/runtime/primitives/src/traits.rs | 4 ++-- 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 84210a9849164..7dab36dd0285d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -797,7 +797,7 @@ dependencies = [ [[package]] name = "integer-sqrt" version = "0.1.0" -source = "git+https://github.com/paritytech/integer-sqrt-rs.git#f4cf61482096dc98c1273f46a10849d182b4c23c" +source = "git+https://github.com/paritytech/integer-sqrt-rs.git#886e9cb983c46498003878afe965d55caa762025" [[package]] name = "interleaved-ordered" diff --git a/polkadot/primitives/src/lib.rs b/polkadot/primitives/src/lib.rs index 012cf57b3d21a..f9438c4dc5d5b 100644 --- a/polkadot/primitives/src/lib.rs +++ b/polkadot/primitives/src/lib.rs @@ -50,7 +50,8 @@ pub use primitives::block::Id as BlockId; pub use primitives::block::Log as Log; /// An index to a block. -pub type BlockNumber = u64; +/// 32-bits will allow for 136 years of blocks assuming 1 block per second. +pub type BlockNumber = u32; /// Alias to Ed25519 pubkey that identifies an account on the relay chain. This will almost /// certainly continue to be the same as the substrate's `AuthorityId`. @@ -60,11 +61,11 @@ pub type AccountId = primitives::AuthorityId; /// exactly equivalent to what the substrate calls an "authority". pub type SessionKey = primitives::AuthorityId; -/// Indentifier for a chain. -pub type ChainId = u64; +/// Indentifier for a chain. 32-bit should be plenty. +pub type ChainId = u32; -/// Index of a transaction in the relay chain. -pub type Index = u64; +/// Index of a transaction in the relay chain. 32-bit should be plenty. +pub type Index = u32; /// A hash of some data used by the relay chain. pub type Hash = primitives::H256; @@ -76,4 +77,10 @@ pub type Signature = runtime_primitives::Ed25519Signature; pub type Timestamp = u64; /// The balance of an account. -pub type Balance = u64; +/// 128-bits (or 38 significant decimal figures) will allow for 10m currency (10^7) at a resolution +/// to all for one second's worth of an annualised 50% reward be paid to a unit holder (10^11 unit +/// denomination), or 10^18 total atomic units, to grow at 50%/year for 51 years (10^9 multiplier) +/// for an eventual total of 10^27 units (27 significant decimal figures). +/// We round denomination to 10^12 (12 sdf), and leave the other redundancy at the upper end so +/// that 32 bits may be multiplied with a balance in 128 bits without worrying about overflow. +pub type Balance = u128; diff --git a/substrate/codec/src/slicable.rs b/substrate/codec/src/slicable.rs index 8c3d8f4330dce..4054b5ef5eccb 100644 --- a/substrate/codec/src/slicable.rs +++ b/substrate/codec/src/slicable.rs @@ -344,7 +344,7 @@ macro_rules! impl_non_endians { )* } } -impl_endians!(u16, u32, u64, usize, i16, i32, i64, isize); +impl_endians!(u16, u32, u64, u128, usize, i16, i32, i64, i128, isize); impl_non_endians!(i8, [u8; 1], [u8; 2], [u8; 3], [u8; 4], [u8; 5], [u8; 6], [u8; 7], [u8; 8], [u8; 10], [u8; 12], [u8; 14], [u8; 16], [u8; 20], [u8; 24], [u8; 28], [u8; 32], [u8; 40], [u8; 48], [u8; 56], [u8; 64], [u8; 80], [u8; 96], [u8; 112], [u8; 128], bool); diff --git a/substrate/runtime/primitives/src/traits.rs b/substrate/runtime/primitives/src/traits.rs index bcd5707f1fd83..4b7530e6db70c 100644 --- a/substrate/runtime/primitives/src/traits.rs +++ b/substrate/runtime/primitives/src/traits.rs @@ -61,7 +61,7 @@ pub trait As { macro_rules! impl_numerics { ( $( $t:ty ),* ) => { $( - impl_numerics!($t: u8, u16, u32, u64, usize, i8, i16, i32, i64, isize,); + impl_numerics!($t: u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize,); )* }; ( $f:ty : $t:ty, $( $rest:ty, )* ) => { @@ -74,7 +74,7 @@ macro_rules! impl_numerics { ( $f:ty : ) => {} } -impl_numerics!(u8, u16, u32, u64, usize, i8, i16, i32, i64, isize); +impl_numerics!(u8, u16, u32, u64, u128, usize, i8, i16, i32, i64, i128, isize); pub struct Identity; impl Convert for Identity {