Weight annotation. (#3157)

* Make extrinsics extensible.

Also Remove old extrinsic types.

* Rest of mockup. Add tips.

* Fix some build issues

* Runtiem builds :)

* Substrate builds.

* Fix a doc test

* Compact encoding

* Extract out the era logic into an extension

* Weight Check signed extension. (#3115)

* Weight signed extension.

* Revert a bit + test for check era.

* Update Cargo.toml

* Update node/cli/src/factory_impl.rs

* Update node/executor/src/lib.rs

* Update node/executor/src/lib.rs

* Don't use len for weight - use data.

* Operational Transaction; second attempt (#3138)

* working poc added.

* some fixes.

* Update doc.

* Fix all tests + final logic.

* more refactoring.

* nits.

* System block limit in bytes.

* Silent the storage macro warnings.

* More logic more tests.

* Fix import.

* Refactor names.

* Fix build.

* Update srml/balances/src/lib.rs

* Final refactor.

* Bump transaction version

* Fix weight mult test.

* Fix more tests and improve doc.

* Bump.

* Make some tests work again.

* Fix subkey.

* Remove todos + bump.

* First draft of annotating weights.

* Refactor weight to u64.

* More refactoring and tests.

* New convert for weight to fee

* more tests.

* remove merge redundancy.

* Fix system test.

* Bring back subkey stuff.

* a few stress tests.

* fix some of the grumbles.

* Final nits.

* Update srml/system/src/lib.rs

Co-Authored-By: DemiMarie-parity <48690212+DemiMarie-parity@users.noreply.github.com>

* Scale weights by 1000.

* Bump.

* Fix decl_storage test.
This commit is contained in:
Kian Peymani
2019-07-25 11:58:47 +02:00
committed by Bastian Köcher
parent 80472956f8
commit 002acb9373
44 changed files with 844 additions and 259 deletions
+15 -9
View File
@@ -108,6 +108,7 @@ mod internal {
fn from(d: DispatchError) -> Self {
match d {
DispatchError::Payment => ApplyError::CantPay,
DispatchError::Resource => ApplyError::FullBlock,
DispatchError::NoPermission => ApplyError::CantPay,
DispatchError::BadState => ApplyError::CantPay,
DispatchError::Stale => ApplyError::Stale,
@@ -357,10 +358,12 @@ mod tests {
use runtime_io::with_externalities;
use substrate_primitives::{H256, Blake2Hasher};
use primitives::generic::Era;
use primitives::traits::{Header as HeaderT, BlakeTwo256, IdentityLookup};
use primitives::Perbill;
use primitives::weights::Weight;
use primitives::traits::{Header as HeaderT, BlakeTwo256, IdentityLookup, ConvertInto};
use primitives::testing::{Digest, Header, Block};
use srml_support::{impl_outer_event, impl_outer_origin, parameter_types};
use srml_support::traits::{Currency, LockIdentifier, LockableCurrency, WithdrawReasons, WithdrawReason, Get};
use srml_support::traits::{Currency, LockIdentifier, LockableCurrency, WithdrawReasons, WithdrawReason};
use system;
use hex_literal::hex;
@@ -382,6 +385,7 @@ mod tests {
pub const BlockHashCount: u64 = 250;
pub const MaximumBlockWeight: u32 = 1024;
pub const MaximumBlockLength: u32 = 2 * 1024;
pub const AvailableBlockRatio: Perbill = Perbill::one();
}
impl system::Trait for Runtime {
type Origin = Origin;
@@ -396,6 +400,7 @@ mod tests {
type BlockHashCount = BlockHashCount;
type WeightMultiplierUpdate = ();
type MaximumBlockWeight = MaximumBlockWeight;
type AvailableBlockRatio = AvailableBlockRatio;
type MaximumBlockLength = MaximumBlockLength;
}
parameter_types! {
@@ -418,6 +423,7 @@ mod tests {
type CreationFee = CreationFee;
type TransactionBaseFee = TransactionBaseFee;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = ConvertInto;
}
impl ValidateUnsigned for Runtime {
@@ -457,7 +463,7 @@ mod tests {
fn balance_transfer_dispatch_works() {
let mut t = system::GenesisConfig::default().build_storage::<Runtime>().unwrap();
balances::GenesisConfig::<Runtime> {
balances: vec![(1, 111)],
balances: vec![(1, 211)],
vesting: vec![],
}.assimilate_storage(&mut t.0, &mut t.1).unwrap();
let xt = primitives::testing::TestXt(sign_extra(1, 0, 0), Call::transfer(2, 69));
@@ -473,7 +479,7 @@ mod tests {
));
let r = Executive::apply_extrinsic(xt);
assert_eq!(r, Ok(ApplyOutcome::Success));
assert_eq!(<balances::Module<Runtime>>::total_balance(&1), 42 - 10 - weight);
assert_eq!(<balances::Module<Runtime>>::total_balance(&1), 142 - 10 - weight);
assert_eq!(<balances::Module<Runtime>>::total_balance(&2), 69);
});
}
@@ -561,8 +567,8 @@ mod tests {
// given: TestXt uses the encoded len as fixed Len:
let xt = primitives::testing::TestXt(sign_extra(1, 0, 0), Call::transfer::<Runtime>(33, 0));
let encoded = xt.encode();
let encoded_len = encoded.len() as u32;
let limit = <MaximumBlockWeight as Get<u32>>::get() / 4;
let encoded_len = encoded.len() as Weight;
let limit = AvailableBlockRatio::get() * MaximumBlockWeight::get();
let num_to_exhaust_block = limit / encoded_len;
with_externalities(&mut t, || {
Executive::initialize_block(&Header::new(
@@ -580,9 +586,9 @@ mod tests {
if nonce != num_to_exhaust_block {
assert_eq!(res.unwrap(), ApplyOutcome::Success);
assert_eq!(<system::Module<Runtime>>::all_extrinsics_weight(), encoded_len * (nonce + 1));
assert_eq!(<system::Module<Runtime>>::extrinsic_index(), Some(nonce + 1));
assert_eq!(<system::Module<Runtime>>::extrinsic_index(), Some(nonce as u32 + 1));
} else {
assert_eq!(res, Err(ApplyError::CantPay));
assert_eq!(res, Err(ApplyError::FullBlock));
}
}
});
@@ -604,7 +610,7 @@ mod tests {
assert_eq!(Executive::apply_extrinsic(x2.clone()).unwrap(), ApplyOutcome::Success);
// default weight for `TestXt` == encoded length.
assert_eq!( <system::Module<Runtime>>::all_extrinsics_weight(), 3 * len);
assert_eq!(<system::Module<Runtime>>::all_extrinsics_weight(), (3 * len).into());
assert_eq!(<system::Module<Runtime>>::all_extrinsics_len(), 3 * len);
let _ = <system::Module<Runtime>>::finalize();