From 98fda86fcae7d35f06fe297823d6bfdb9b571fed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Fri, 7 Aug 2020 13:58:51 +0200 Subject: [PATCH 01/10] Revalidate transactions only on latest best block (#6824) * Revalidate transactions only on latest best block We should revalidate transactions only on the latest best block and not on any arbitrary block. The revalidation before failed when there were multiple blocks on the height given to the revalidation function, but no block was imported as best block. * Update test-utils/runtime/transaction-pool/src/lib.rs Co-authored-by: Jaco Greeff * Fix tests * Only process best blocks in the transaction pool Co-authored-by: Jaco Greeff --- bin/node/cli/src/service.rs | 4 +- client/api/src/client.rs | 20 +- .../basic-authorship/src/basic_authorship.rs | 4 +- client/consensus/manual-seal/src/lib.rs | 14 +- client/transaction-pool/src/lib.rs | 17 +- client/transaction-pool/src/revalidation.rs | 21 +- client/transaction-pool/src/testing/pool.rs | 227 +++++++----------- primitives/transaction-pool/src/pool.rs | 8 +- .../runtime/transaction-pool/src/lib.rs | 95 ++++++-- 9 files changed, 205 insertions(+), 205 deletions(-) diff --git a/bin/node/cli/src/service.rs b/bin/node/cli/src/service.rs index 3987645b9c..ed265acf77 100644 --- a/bin/node/cli/src/service.rs +++ b/bin/node/cli/src/service.rs @@ -480,11 +480,9 @@ mod tests { futures::executor::block_on( service.transaction_pool().maintain( - ChainEvent::NewBlock { - is_new_best: true, + ChainEvent::NewBestBlock { hash: parent_header.hash(), tree_route: None, - header: parent_header.clone(), }, ) ); diff --git a/client/api/src/client.rs b/client/api/src/client.rs index 4b947bd817..fe3bf5aafa 100644 --- a/client/api/src/client.rs +++ b/client/api/src/client.rs @@ -16,7 +16,7 @@ //! A set of APIs supported by the client along with their primitives. -use std::{fmt, collections::HashSet, sync::Arc}; +use std::{fmt, collections::HashSet, sync::Arc, convert::TryFrom}; use sp_core::storage::StorageKey; use sp_runtime::{ traits::{Block as BlockT, NumberFor}, @@ -245,13 +245,17 @@ pub struct FinalityNotification { pub header: Block::Header, } -impl From> for sp_transaction_pool::ChainEvent { - fn from(n: BlockImportNotification) -> Self { - Self::NewBlock { - is_new_best: n.is_new_best, - hash: n.hash, - header: n.header, - tree_route: n.tree_route, +impl TryFrom> for sp_transaction_pool::ChainEvent { + type Error = (); + + fn try_from(n: BlockImportNotification) -> Result { + if n.is_new_best { + Ok(Self::NewBestBlock { + hash: n.hash, + tree_route: n.tree_route, + }) + } else { + Err(()) } } } diff --git a/client/basic-authorship/src/basic_authorship.rs b/client/basic-authorship/src/basic_authorship.rs index 2568c7a4d5..fdecabfcdf 100644 --- a/client/basic-authorship/src/basic_authorship.rs +++ b/client/basic-authorship/src/basic_authorship.rs @@ -336,11 +336,9 @@ mod tests { fn chain_event(header: B::Header) -> ChainEvent where NumberFor: From { - ChainEvent::NewBlock { + ChainEvent::NewBestBlock { hash: header.hash(), tree_route: None, - is_new_best: true, - header, } } diff --git a/client/consensus/manual-seal/src/lib.rs b/client/consensus/manual-seal/src/lib.rs index 6dcb42320e..9743536bb5 100644 --- a/client/consensus/manual-seal/src/lib.rs +++ b/client/consensus/manual-seal/src/lib.rs @@ -232,6 +232,7 @@ mod tests { use sc_client::LongestChain; use sp_inherents::InherentDataProviders; use sc_basic_authorship::ProposerFactory; + use sc_client_api::BlockBackend; fn api() -> Arc { Arc::new(TestApi::empty()) @@ -443,15 +444,13 @@ mod tests { } } ); - // assert that there's a new block in the db. - assert!(client.header(&BlockId::Number(0)).unwrap().is_some()); + let block = client.block(&BlockId::Number(1)).unwrap().unwrap().block; + pool_api.add_block(block, true); assert!(pool.submit_one(&BlockId::Number(1), SOURCE, uxt(Alice, 1)).await.is_ok()); let header = client.header(&BlockId::Number(1)).expect("db error").expect("imported above"); - pool.maintain(sp_transaction_pool::ChainEvent::NewBlock { + pool.maintain(sp_transaction_pool::ChainEvent::NewBestBlock { hash: header.hash(), - header, - is_new_best: true, tree_route: None, }).await; @@ -466,10 +465,11 @@ mod tests { rx1.await.expect("should be no error receiving"), Ok(_) ); - assert!(client.header(&BlockId::Number(1)).unwrap().is_some()); + let block = client.block(&BlockId::Number(2)).unwrap().unwrap().block; + pool_api.add_block(block, true); pool_api.increment_nonce(Alice.into()); - assert!(pool.submit_one(&BlockId::Number(2), SOURCE, uxt(Alice, 2)).await.is_ok()); + assert!(pool.submit_one(&BlockId::Number(1), SOURCE, uxt(Alice, 2)).await.is_ok()); let (tx2, rx2) = futures::channel::oneshot::channel(); assert!(sink.send(EngineCommand::SealNewBlock { parent_hash: Some(created_block.hash), diff --git a/client/transaction-pool/src/lib.rs b/client/transaction-pool/src/lib.rs index 51b93094ce..720df50131 100644 --- a/client/transaction-pool/src/lib.rs +++ b/client/transaction-pool/src/lib.rs @@ -34,7 +34,7 @@ pub mod testing; pub use sc_transaction_graph as txpool; pub use crate::api::{FullChainApi, LightChainApi}; -use std::{collections::{HashMap, HashSet}, sync::Arc, pin::Pin}; +use std::{collections::{HashMap, HashSet}, sync::Arc, pin::Pin, convert::TryInto}; use futures::{prelude::*, future::{self, ready}, channel::oneshot}; use parking_lot::Mutex; @@ -468,7 +468,7 @@ impl MaintainedTransactionPool for BasicPool { fn maintain(&self, event: ChainEvent) -> Pin + Send>> { match event { - ChainEvent::NewBlock { hash, tree_route, is_new_best, .. } => { + ChainEvent::NewBestBlock { hash, tree_route } => { let pool = self.pool.clone(); let api = self.api.clone(); @@ -527,10 +527,7 @@ impl MaintainedTransactionPool for BasicPool }) } - // If this is a new best block, we need to prune its transactions from the pool. - if is_new_best { - pruned_log.extend(prune_known_txs_for_block(id.clone(), &*api, &*pool).await); - } + pruned_log.extend(prune_known_txs_for_block(id.clone(), &*api, &*pool).await); metrics.report( |metrics| metrics.block_transactions_pruned.inc_by(pruned_log.len() as u64) @@ -610,9 +607,9 @@ impl MaintainedTransactionPool for BasicPool .map(|tx| tx.hash.clone()) .collect(); revalidation_queue.revalidate_later(block_number, hashes).await; - } - revalidation_strategy.lock().clear(); + revalidation_strategy.lock().clear(); + } }.boxed() } ChainEvent::Finalized { hash } => { @@ -641,7 +638,9 @@ pub async fn notification_future( Client: sc_client_api::BlockchainEvents, Pool: MaintainedTransactionPool, { - let import_stream = client.import_notification_stream().map(Into::into).fuse(); + let import_stream = client.import_notification_stream() + .filter_map(|n| ready(n.try_into().ok())) + .fuse(); let finality_stream = client.finality_notification_stream() .map(Into::into) .fuse(); diff --git a/client/transaction-pool/src/revalidation.rs b/client/transaction-pool/src/revalidation.rs index af9a76c055..7be8688eae 100644 --- a/client/transaction-pool/src/revalidation.rs +++ b/client/transaction-pool/src/revalidation.rs @@ -211,8 +211,7 @@ impl RevalidationWorker { mut self, from_queue: TracingUnboundedReceiver>, interval: R, - ) where R: Send, R::Guard: Send - { + ) where R: Send, R::Guard: Send { let interval = interval.into_stream().fuse(); let from_queue = from_queue.fuse(); futures::pin_mut!(interval, from_queue); @@ -253,7 +252,7 @@ impl RevalidationWorker { if this.members.len() > 0 { log::debug!( target: "txpool", - "Updated revalidation queue at {}. Transactions: {:?}", + "Updated revalidation queue at {:?}. Transactions: {:?}", this.best_block, this.members, ); @@ -298,9 +297,7 @@ where api: Arc, pool: Arc>, interval: R, - ) -> (Self, Pin + Send>>) - where R: Send + 'static, R::Guard: Send - { + ) -> (Self, Pin + Send>>) where R: Send + 'static, R::Guard: Send { let (to_worker, from_queue) = tracing_unbounded("mpsc_revalidation_queue"); let worker = RevalidationWorker::new(api.clone(), pool.clone()); @@ -338,16 +335,22 @@ where /// If queue configured with background worker, this will return immediately. /// If queue configured without background worker, this will resolve after /// revalidation is actually done. - pub async fn revalidate_later(&self, at: NumberFor, transactions: Vec>) { + pub async fn revalidate_later( + &self, + at: NumberFor, + transactions: Vec>, + ) { if transactions.len() > 0 { - log::debug!(target: "txpool", "Sent {} transactions to revalidation queue", transactions.len()); + log::debug!( + target: "txpool", "Sent {} transactions to revalidation queue", + transactions.len(), + ); } if let Some(ref to_worker) = self.background { if let Err(e) = to_worker.unbounded_send(WorkerPayload { at, transactions }) { log::warn!(target: "txpool", "Failed to update background worker: {:?}", e); } - return; } else { let pool = self.pool.clone(); let api = self.api.clone(); diff --git a/client/transaction-pool/src/testing/pool.rs b/client/transaction-pool/src/testing/pool.rs index 5ad79a6f75..819fe83882 100644 --- a/client/transaction-pool/src/testing/pool.rs +++ b/client/transaction-pool/src/testing/pool.rs @@ -106,7 +106,7 @@ fn prune_tags_should_work() { let pending: Vec<_> = pool.validated_pool().ready().map(|a| a.data.transfer().nonce).collect(); assert_eq!(pending, vec![209, 210]); - pool.validated_pool().api().push_block(1, Vec::new()); + pool.validated_pool().api().push_block(1, Vec::new(), true); block_on( pool.prune_tags( &BlockId::number(1), @@ -141,25 +141,14 @@ fn only_prune_on_new_best() { let uxt = uxt(Alice, 209); let _ = block_on( - pool.submit_and_watch(&BlockId::number(1), SOURCE, uxt.clone()) + pool.submit_and_watch(&BlockId::number(0), SOURCE, uxt.clone()) ).expect("1. Imported"); - let header = pool.api.push_block(1, vec![uxt.clone()]); + pool.api.push_block(1, vec![uxt.clone()], true); assert_eq!(pool.status().ready, 1); - let event = ChainEvent::NewBlock { + let header = pool.api.push_block(2, vec![uxt], true); + let event = ChainEvent::NewBestBlock { hash: header.hash(), - is_new_best: false, - header: header.clone(), - tree_route: None, - }; - block_on(pool.maintain(event)); - assert_eq!(pool.status().ready, 1); - - let header = pool.api.push_block(2, vec![uxt]); - let event = ChainEvent::NewBlock { - hash: header.hash(), - is_new_best: true, - header: header.clone(), tree_route: None, }; block_on(pool.maintain(event)); @@ -179,7 +168,7 @@ fn should_correctly_prune_transactions_providing_more_than_one_tag() { // remove the transaction that just got imported. api.increment_nonce(Alice.into()); - api.push_block(1, Vec::new()); + api.push_block(1, Vec::new(), true); block_on(pool.prune_tags(&BlockId::number(1), vec![vec![209]], vec![])).expect("1. Pruned"); assert_eq!(pool.validated_pool().status().ready, 0); // it's re-imported to future @@ -187,7 +176,7 @@ fn should_correctly_prune_transactions_providing_more_than_one_tag() { // so now let's insert another transaction that also provides the 155 api.increment_nonce(Alice.into()); - api.push_block(2, Vec::new()); + api.push_block(2, Vec::new(), true); let xt = uxt(Alice, 211); block_on(pool.submit_one(&BlockId::number(2), SOURCE, xt.clone())).expect("2. Imported"); assert_eq!(pool.validated_pool().status().ready, 1); @@ -197,18 +186,16 @@ fn should_correctly_prune_transactions_providing_more_than_one_tag() { // prune it and make sure the pool is empty api.increment_nonce(Alice.into()); - api.push_block(3, Vec::new()); + api.push_block(3, Vec::new(), true); block_on(pool.prune_tags(&BlockId::number(3), vec![vec![155]], vec![])).expect("2. Pruned"); assert_eq!(pool.validated_pool().status().ready, 0); assert_eq!(pool.validated_pool().status().future, 2); } fn block_event(header: Header) -> ChainEvent { - ChainEvent::NewBlock { + ChainEvent::NewBestBlock { hash: header.hash(), - is_new_best: true, tree_route: None, - header, } } @@ -219,11 +206,9 @@ fn block_event_with_retracted( ) -> ChainEvent { let tree_route = api.tree_route(retracted_start, header.parent_hash).expect("Tree route exists"); - ChainEvent::NewBlock { + ChainEvent::NewBestBlock { hash: header.hash(), - is_new_best: true, tree_route: Some(Arc::new(tree_route)), - header, } } @@ -236,7 +221,7 @@ fn should_prune_old_during_maintenance() { block_on(pool.submit_one(&BlockId::number(0), SOURCE, xt.clone())).expect("1. Imported"); assert_eq!(pool.status().ready, 1); - let header = pool.api.push_block(1, vec![xt.clone()]); + let header = pool.api.push_block(1, vec![xt.clone()], true); block_on(pool.maintain(block_event(header))); assert_eq!(pool.status().ready, 0); @@ -253,7 +238,7 @@ fn should_revalidate_during_maintenance() { assert_eq!(pool.status().ready, 2); assert_eq!(pool.api.validation_requests().len(), 2); - let header = pool.api.push_block(1, vec![xt1.clone()]); + let header = pool.api.push_block(1, vec![xt1.clone()], true); block_on(pool.maintain(block_event(header))); assert_eq!(pool.status().ready, 1); @@ -272,8 +257,8 @@ fn should_resubmit_from_retracted_during_maintenance() { block_on(pool.submit_one(&BlockId::number(0), SOURCE, xt.clone())).expect("1. Imported"); assert_eq!(pool.status().ready, 1); - let header = pool.api.push_block(1, vec![]); - let fork_header = pool.api.push_block(1, vec![]); + let header = pool.api.push_block(1, vec![], true); + let fork_header = pool.api.push_block(1, vec![], false); let event = block_event_with_retracted(header, fork_header.hash(), &*pool.api); @@ -291,8 +276,8 @@ fn should_not_resubmit_from_retracted_during_maintenance_if_tx_is_also_in_enacte block_on(pool.submit_one(&BlockId::number(0), SOURCE, xt.clone())).expect("1. Imported"); assert_eq!(pool.status().ready, 1); - let header = pool.api.push_block(1, vec![xt.clone()]); - let fork_header = pool.api.push_block(1, vec![xt]); + let header = pool.api.push_block(1, vec![xt.clone()], true); + let fork_header = pool.api.push_block(1, vec![xt], false); let event = block_event_with_retracted(header, fork_header.hash(), &*pool.api); @@ -309,8 +294,8 @@ fn should_not_retain_invalid_hashes_from_retracted() { block_on(pool.submit_one(&BlockId::number(0), SOURCE, xt.clone())).expect("1. Imported"); assert_eq!(pool.status().ready, 1); - let header = pool.api.push_block(1, vec![]); - let fork_header = pool.api.push_block(1, vec![xt.clone()]); + let header = pool.api.push_block(1, vec![], true); + let fork_header = pool.api.push_block(1, vec![xt.clone()], false); pool.api.add_invalid(&xt); let event = block_event_with_retracted(header, fork_header.hash(), &*pool.api); @@ -330,14 +315,14 @@ fn should_revalidate_transaction_multiple_times() { block_on(pool.submit_one(&BlockId::number(0), SOURCE, xt.clone())).expect("1. Imported"); assert_eq!(pool.status().ready, 1); - let header = pool.api.push_block(1, vec![xt.clone()]); + let header = pool.api.push_block(1, vec![xt.clone()], true); block_on(pool.maintain(block_event(header))); block_on(pool.submit_one(&BlockId::number(0), SOURCE, xt.clone())).expect("1. Imported"); assert_eq!(pool.status().ready, 1); - let header = pool.api.push_block(2, vec![]); + let header = pool.api.push_block(2, vec![], true); pool.api.add_invalid(&xt); block_on(pool.maintain(block_event(header))); @@ -354,18 +339,18 @@ fn should_revalidate_across_many_blocks() { let (pool, _guard, mut notifier) = maintained_pool(); - block_on(pool.submit_one(&BlockId::number(1), SOURCE, xt1.clone())).expect("1. Imported"); - block_on(pool.submit_one(&BlockId::number(1), SOURCE, xt2.clone())).expect("1. Imported"); + block_on(pool.submit_one(&BlockId::number(0), SOURCE, xt1.clone())).expect("1. Imported"); + block_on(pool.submit_one(&BlockId::number(0), SOURCE, xt2.clone())).expect("1. Imported"); assert_eq!(pool.status().ready, 2); - let header = pool.api.push_block(1, vec![]); + let header = pool.api.push_block(1, vec![], true); block_on(pool.maintain(block_event(header))); block_on(notifier.next()); - block_on(pool.submit_one(&BlockId::number(2), SOURCE, xt3.clone())).expect("1. Imported"); + block_on(pool.submit_one(&BlockId::number(1), SOURCE, xt3.clone())).expect("1. Imported"); assert_eq!(pool.status().ready, 3); - let header = pool.api.push_block(2, vec![xt1.clone()]); + let header = pool.api.push_block(2, vec![xt1.clone()], true); block_on(pool.maintain(block_event(header))); block_on(notifier.next()); @@ -411,7 +396,7 @@ fn should_push_watchers_during_maintaince() { pool.api.add_invalid(&tx4); // clear timer events if any - let header = pool.api.push_block(1, vec![]); + let header = pool.api.push_block(1, vec![], true); block_on(pool.maintain(block_event(header))); block_on(notifier.next()); @@ -429,7 +414,7 @@ fn should_push_watchers_during_maintaince() { ); // when - let header = pool.api.push_block(2, vec![tx0, tx1, tx2]); + let header = pool.api.push_block(2, vec![tx0, tx1, tx2], true); let header_hash = header.hash(); block_on(pool.maintain(block_event(header))); @@ -478,18 +463,16 @@ fn can_track_heap_size() { fn finalization() { let xt = uxt(Alice, 209); let api = TestApi::with_alice_nonce(209); - api.push_block(1, vec![]); + api.push_block(1, vec![], true); let (pool, _background, _) = BasicPool::new_test(api.into()); let watcher = block_on( pool.submit_and_watch(&BlockId::number(1), SOURCE, xt.clone()) ).expect("1. Imported"); - pool.api.push_block(2, vec![xt.clone()]); + pool.api.push_block(2, vec![xt.clone()], true); - let header = pool.api.chain().read().block_by_number.get(&2).unwrap()[0].header().clone(); - let event = ChainEvent::NewBlock { + let header = pool.api.chain().read().block_by_number.get(&2).unwrap()[0].0.header().clone(); + let event = ChainEvent::NewBestBlock { hash: header.hash(), - is_new_best: true, - header: header.clone(), tree_route: None, }; block_on(pool.maintain(event)); @@ -508,7 +491,7 @@ fn finalization() { fn fork_aware_finalization() { let api = TestApi::empty(); // starting block A1 (last finalized.) - api.push_block(1, vec![]); + api.push_block(1, vec![], true); let (pool, _background, _) = BasicPool::new_test(api.into()); let mut canon_watchers = vec![]; @@ -534,14 +517,12 @@ fn fork_aware_finalization() { let watcher = block_on( pool.submit_and_watch(&BlockId::number(1), SOURCE, from_alice.clone()) ).expect("1. Imported"); - let header = pool.api.push_block(2, vec![from_alice.clone()]); + let header = pool.api.push_block(2, vec![from_alice.clone()], true); canon_watchers.push((watcher, header.hash())); assert_eq!(pool.status().ready, 1); - let event = ChainEvent::NewBlock { + let event = ChainEvent::NewBestBlock { hash: header.hash(), - is_new_best: true, - header: header.clone(), tree_route: None, }; b1 = header.hash(); @@ -553,15 +534,13 @@ fn fork_aware_finalization() { // block C2 { - let header = pool.api.push_block_with_parent(b1, vec![from_dave.clone()]); + let header = pool.api.push_block_with_parent(b1, vec![from_dave.clone()], true); from_dave_watcher = block_on( pool.submit_and_watch(&BlockId::number(1), SOURCE, from_dave.clone()) ).expect("1. Imported"); assert_eq!(pool.status().ready, 1); - let event = ChainEvent::NewBlock { + let event = ChainEvent::NewBestBlock { hash: header.hash(), - is_new_best: true, - header: header.clone(), tree_route: None, }; c2 = header.hash(); @@ -575,12 +554,10 @@ fn fork_aware_finalization() { pool.submit_and_watch(&BlockId::number(1), SOURCE, from_bob.clone()) ).expect("1. Imported"); assert_eq!(pool.status().ready, 1); - let header = pool.api.push_block_with_parent(c2, vec![from_bob.clone()]); + let header = pool.api.push_block_with_parent(c2, vec![from_bob.clone()], true); - let event = ChainEvent::NewBlock { + let event = ChainEvent::NewBestBlock { hash: header.hash(), - is_new_best: true, - header: header.clone(), tree_route: None, }; d2 = header.hash(); @@ -594,7 +571,7 @@ fn fork_aware_finalization() { pool.submit_and_watch(&BlockId::number(1), SOURCE, from_charlie.clone()) ).expect("1.Imported"); assert_eq!(pool.status().ready, 1); - let header = pool.api.push_block(3, vec![from_charlie.clone()]); + let header = pool.api.push_block(3, vec![from_charlie.clone()], true); canon_watchers.push((watcher, header.hash())); let event = block_event_with_retracted(header.clone(), d2, &*pool.api); @@ -612,13 +589,11 @@ fn fork_aware_finalization() { pool.submit_and_watch(&BlockId::number(1), SOURCE, xt.clone()) ).expect("1. Imported"); assert_eq!(pool.status().ready, 3); - let header = pool.api.push_block(4, vec![xt.clone()]); + let header = pool.api.push_block(4, vec![xt.clone()], true); canon_watchers.push((w, header.hash())); - let event = ChainEvent::NewBlock { + let event = ChainEvent::NewBestBlock { hash: header.hash(), - is_new_best: true, - header: header.clone(), tree_route: None, }; d1 = header.hash(); @@ -632,12 +607,10 @@ fn fork_aware_finalization() { // block e1 { - let header = pool.api.push_block(5, vec![from_dave, from_bob]); + let header = pool.api.push_block(5, vec![from_dave, from_bob], true); e1 = header.hash(); - let event = ChainEvent::NewBlock { + let event = ChainEvent::NewBestBlock { hash: header.hash(), - is_new_best: true, - header: header.clone(), tree_route: None, }; block_on(pool.maintain(event)); @@ -684,7 +657,7 @@ fn fork_aware_finalization() { fn prune_and_retract_tx_at_same_time() { let api = TestApi::empty(); // starting block A1 (last finalized.) - api.push_block(1, vec![]); + api.push_block(1, vec![], true); let (pool, _background, _) = BasicPool::new_test(api.into()); @@ -697,13 +670,11 @@ fn prune_and_retract_tx_at_same_time() { // Block B1 let b1 = { - let header = pool.api.push_block(2, vec![from_alice.clone()]); + let header = pool.api.push_block(2, vec![from_alice.clone()], true); assert_eq!(pool.status().ready, 1); - let event = ChainEvent::NewBlock { + let event = ChainEvent::NewBestBlock { hash: header.hash(), - is_new_best: true, - header: header.clone(), tree_route: None, }; block_on(pool.maintain(event)); @@ -713,7 +684,7 @@ fn prune_and_retract_tx_at_same_time() { // Block B2 let b2 = { - let header = pool.api.push_block(2, vec![from_alice.clone()]); + let header = pool.api.push_block(2, vec![from_alice.clone()], false); assert_eq!(pool.status().ready, 0); let event = block_event_with_retracted(header.clone(), b1, &*pool.api); @@ -757,7 +728,7 @@ fn prune_and_retract_tx_at_same_time() { fn resubmit_tx_of_fork_that_is_not_part_of_retracted() { let api = TestApi::empty(); // starting block A1 (last finalized.) - api.push_block(1, vec![]); + api.push_block(1, vec![], true); let (pool, _background, _) = BasicPool::new_test(api.into()); @@ -773,13 +744,11 @@ fn resubmit_tx_of_fork_that_is_not_part_of_retracted() { let _ = block_on( pool.submit_and_watch(&BlockId::number(1), SOURCE, tx0.clone()) ).expect("1. Imported"); - let header = pool.api.push_block(2, vec![tx0.clone()]); + let header = pool.api.push_block(2, vec![tx0.clone()], true); assert_eq!(pool.status().ready, 1); - let event = ChainEvent::NewBlock { + let event = ChainEvent::NewBestBlock { hash: header.hash(), - is_new_best: true, - header: header.clone(), tree_route: None, }; d0 = header.hash(); @@ -792,23 +761,13 @@ fn resubmit_tx_of_fork_that_is_not_part_of_retracted() { let _ = block_on( pool.submit_and_watch(&BlockId::number(1), SOURCE, tx1.clone()) ).expect("1. Imported"); - let header = pool.api.push_block(2, vec![tx1.clone()]); - assert_eq!(pool.status().ready, 1); - let event = ChainEvent::NewBlock { - hash: header.hash(), - is_new_best: false, - header: header.clone(), - tree_route: None, - }; - block_on(pool.maintain(event)); - - // Only transactions from new best should be pruned + pool.api.push_block(2, vec![tx1.clone()], false); assert_eq!(pool.status().ready, 1); } // Block D2 { - let header = pool.api.push_block(2, vec![]); + let header = pool.api.push_block(2, vec![], false); let event = block_event_with_retracted(header, d0, &*pool.api); block_on(pool.maintain(event)); assert_eq!(pool.status().ready, 2); @@ -819,7 +778,7 @@ fn resubmit_tx_of_fork_that_is_not_part_of_retracted() { fn resubmit_from_retracted_fork() { let api = TestApi::empty(); // starting block A1 (last finalized.) - api.push_block(1, vec![]); + api.push_block(1, vec![], true); let (pool, _background, _) = BasicPool::new_test(api.into()); @@ -844,16 +803,10 @@ fn resubmit_from_retracted_fork() { let _ = block_on( pool.submit_and_watch(&BlockId::number(1), SOURCE, tx0.clone()) ).expect("1. Imported"); - let header = pool.api.push_block(2, vec![tx0.clone()]); + let header = pool.api.push_block(2, vec![tx0.clone()], true); assert_eq!(pool.status().ready, 1); - let event = ChainEvent::NewBlock { - hash: header.hash(), - is_new_best: true, - header: header.clone(), - tree_route: None, - }; - block_on(pool.maintain(event)); + block_on(pool.maintain(block_event(header))); assert_eq!(pool.status().ready, 0); } @@ -862,14 +815,8 @@ fn resubmit_from_retracted_fork() { let _ = block_on( pool.submit_and_watch(&BlockId::number(1), SOURCE, tx1.clone()) ).expect("1. Imported"); - let header = pool.api.push_block(3, vec![tx1.clone()]); - let event = ChainEvent::NewBlock { - hash: header.hash(), - is_new_best: true, - header: header.clone(), - tree_route: None, - }; - block_on(pool.maintain(event)); + let header = pool.api.push_block(3, vec![tx1.clone()], true); + block_on(pool.maintain(block_event(header))); assert_eq!(pool.status().ready, 0); } @@ -878,14 +825,8 @@ fn resubmit_from_retracted_fork() { let _ = block_on( pool.submit_and_watch(&BlockId::number(1), SOURCE, tx2.clone()) ).expect("1. Imported"); - let header = pool.api.push_block(4, vec![tx2.clone()]); - let event = ChainEvent::NewBlock { - hash: header.hash(), - is_new_best: true, - header: header.clone(), - tree_route: None, - }; - block_on(pool.maintain(event)); + let header = pool.api.push_block(4, vec![tx2.clone()], true); + block_on(pool.maintain(block_event(header.clone()))); assert_eq!(pool.status().ready, 0); header.hash() }; @@ -895,14 +836,7 @@ fn resubmit_from_retracted_fork() { let _ = block_on( pool.submit_and_watch(&BlockId::number(1), SOURCE, tx3.clone()) ).expect("1. Imported"); - let header = pool.api.push_block(2, vec![tx3.clone()]); - let event = ChainEvent::NewBlock { - hash: header.hash(), - is_new_best: false, - header: header.clone(), - tree_route: None, - }; - block_on(pool.maintain(event)); + let header = pool.api.push_block(2, vec![tx3.clone()], true); assert_eq!(pool.status().ready, 1); header.hash() }; @@ -912,14 +846,7 @@ fn resubmit_from_retracted_fork() { let _ = block_on( pool.submit_and_watch(&BlockId::number(1), SOURCE, tx4.clone()) ).expect("1. Imported"); - let header = pool.api.push_block_with_parent(d1.clone(), vec![tx4.clone()]); - let event = ChainEvent::NewBlock { - hash: header.hash(), - is_new_best: false, - header: header.clone(), - tree_route: None, - }; - block_on(pool.maintain(event)); + let header = pool.api.push_block_with_parent(d1.clone(), vec![tx4.clone()], true); assert_eq!(pool.status().ready, 2); header.hash() }; @@ -929,7 +856,7 @@ fn resubmit_from_retracted_fork() { let _ = block_on( pool.submit_and_watch(&BlockId::number(1), SOURCE, tx5.clone()) ).expect("1. Imported"); - let header = pool.api.push_block_with_parent(e1.clone(), vec![tx5.clone()]); + let header = pool.api.push_block_with_parent(e1.clone(), vec![tx5.clone()], true); // Don't announce the block event to the pool directly, because we will // re-org to this block. assert_eq!(pool.status().ready, 3); @@ -953,7 +880,7 @@ fn resubmit_from_retracted_fork() { fn ready_set_should_not_resolve_before_block_update() { let (pool, _guard, _notifier) = maintained_pool(); let xt1 = uxt(Alice, 209); - block_on(pool.submit_one(&BlockId::number(1), SOURCE, xt1.clone())).expect("1. Imported"); + block_on(pool.submit_one(&BlockId::number(0), SOURCE, xt1.clone())).expect("1. Imported"); assert!(pool.ready_at(1).now_or_never().is_none()); } @@ -961,7 +888,7 @@ fn ready_set_should_not_resolve_before_block_update() { #[test] fn ready_set_should_resolve_after_block_update() { let (pool, _guard, _notifier) = maintained_pool(); - let header = pool.api.push_block(1, vec![]); + let header = pool.api.push_block(1, vec![], true); let xt1 = uxt(Alice, 209); @@ -974,7 +901,7 @@ fn ready_set_should_resolve_after_block_update() { #[test] fn ready_set_should_eventually_resolve_when_block_update_arrives() { let (pool, _guard, _notifier) = maintained_pool(); - let header = pool.api.push_block(1, vec![]); + let header = pool.api.push_block(1, vec![], true); let xt1 = uxt(Alice, 209); @@ -1063,7 +990,7 @@ fn import_notification_to_pool_maintain_works() { // Get the notification of the block import and maintain the pool with it, // Now, the pool should not contain any transactions. let evt = import_stream.next().expect("Importing a block leads to an event"); - block_on(pool.maintain(evt.into())); + block_on(pool.maintain(evt.try_into().expect("Imported as new best block"))); assert_eq!(pool.status().ready, 0); } @@ -1075,7 +1002,7 @@ fn pruning_a_transaction_should_remove_it_from_best_transaction() { let xt1 = Extrinsic::IncludeData(Vec::new()); block_on(pool.submit_one(&BlockId::number(0), SOURCE, xt1.clone())).expect("1. Imported"); - let header = pool.api.push_block(1, vec![xt1.clone()]); + let header = pool.api.push_block(1, vec![xt1.clone()], true); // This will prune `xt1`. block_on(pool.maintain(block_event(header))); @@ -1091,3 +1018,23 @@ fn pruning_a_transaction_should_remove_it_from_best_transaction() { // returned a second time by the iterator. assert!(iterator.next().is_none()); } + +#[test] +fn only_revalidate_on_best_block() { + let xt = uxt(Alice, 209); + + let (pool, _guard, mut notifier) = maintained_pool(); + + block_on(pool.submit_one(&BlockId::number(0), SOURCE, xt.clone())).expect("1. Imported"); + assert_eq!(pool.status().ready, 1); + + let header = pool.api.push_block(1, vec![], true); + + pool.api.push_block(2, vec![], false); + pool.api.push_block(2, vec![], false); + + block_on(pool.maintain(block_event(header))); + block_on(notifier.next()); + + assert_eq!(pool.status().ready, 1); +} diff --git a/primitives/transaction-pool/src/pool.rs b/primitives/transaction-pool/src/pool.rs index 2824c96f30..9a338c2102 100644 --- a/primitives/transaction-pool/src/pool.rs +++ b/primitives/transaction-pool/src/pool.rs @@ -247,14 +247,10 @@ pub trait TransactionPool: Send + Sync { /// Events that the transaction pool listens for. pub enum ChainEvent { - /// New blocks have been added to the chain - NewBlock { - /// Is this the new best block. - is_new_best: bool, + /// New best block have been added to the chain + NewBestBlock { /// Hash of the block. hash: B::Hash, - /// Header of the just imported block - header: B::Header, /// Tree route from old best to new best parent that was calculated on import. /// /// If `None`, no re-org happened on import. diff --git a/test-utils/runtime/transaction-pool/src/lib.rs b/test-utils/runtime/transaction-pool/src/lib.rs index a11b13974d..f772ba9b02 100644 --- a/test-utils/runtime/transaction-pool/src/lib.rs +++ b/test-utils/runtime/transaction-pool/src/lib.rs @@ -35,6 +35,7 @@ use substrate_test_runtime_client::{ AccountKeyring::{self, *}, }; use sp_blockchain::CachedHeaderMetadata; +use futures::future::ready; /// Error type used by [`TestApi`]. #[derive(Debug, derive_more::From, derive_more::Display)] @@ -52,9 +53,30 @@ impl std::error::Error for Error { } } +pub enum IsBestBlock { + Yes, + No, +} + +impl IsBestBlock { + pub fn is_best(&self) -> bool { + matches!(self, Self::Yes) + } +} + +impl From for IsBestBlock { + fn from(is_best: bool) -> Self { + if is_best { + Self::Yes + } else { + Self::No + } + } +} + #[derive(Default)] pub struct ChainState { - pub block_by_number: BTreeMap>, + pub block_by_number: BTreeMap>, pub block_by_hash: HashMap, pub nonces: HashMap, pub invalid_hashes: HashSet, @@ -86,7 +108,7 @@ impl TestApi { }; // Push genesis block - api.push_block(0, Vec::new()); + api.push_block(0, Vec::new(), true); api } @@ -97,10 +119,12 @@ impl TestApi { } /// Push block under given number. - /// - /// If multiple blocks exists with the same block number, the first inserted block will be - /// interpreted as part of the canonical chain. - pub fn push_block(&self, block_number: BlockNumber, xts: Vec) -> Header { + pub fn push_block( + &self, + block_number: BlockNumber, + xts: Vec, + is_best_block: bool, + ) -> Header { let parent_hash = { let chain = self.chain.read(); block_number @@ -109,12 +133,12 @@ impl TestApi { chain.block_by_number .get(&num) .map(|blocks| { - blocks[0].header.hash() + blocks[0].0.header.hash() }) }).unwrap_or_default() }; - self.push_block_with_parent(parent_hash, xts) + self.push_block_with_parent(parent_hash, xts, is_best_block) } /// Push a block using the given `parent`. @@ -124,14 +148,14 @@ impl TestApi { &self, parent: Hash, xts: Vec, + is_best_block: bool, ) -> Header { - let mut chain = self.chain.write(); - // `Hash::default()` is the genesis parent hash let block_number = if parent == Hash::default() { 0 } else { - *chain.block_by_hash + *self.chain.read() + .block_by_hash .get(&parent) .expect("`parent` exists") .header() @@ -146,14 +170,21 @@ impl TestApi { state_root: Default::default(), }; - let hash = header.hash(); - let block = Block::new(header.clone(), xts); - chain.block_by_hash.insert(hash, block.clone()); - chain.block_by_number.entry(block_number).or_default().push(block); + self.add_block(Block::new(header.clone(), xts), is_best_block); header } + /// Add a block to the internal state. + pub fn add_block(&self, block: Block, is_best_block: bool) { + let hash = block.header.hash(); + let block_number = block.header.number().clone(); + + let mut chain = self.chain.write(); + chain.block_by_hash.insert(hash, block.clone()); + chain.block_by_number.entry(block_number).or_default().push((block, is_best_block.into())); + } + fn hash_and_length_inner(ex: &Extrinsic) -> (Hash, usize) { let encoded = ex.encode(); (BlakeTwo256::hash(&encoded), encoded.len()) @@ -203,12 +234,36 @@ impl sc_transaction_graph::ChainApi for TestApi { fn validate_transaction( &self, - _at: &BlockId, + at: &BlockId, _source: TransactionSource, uxt: sc_transaction_graph::ExtrinsicFor, ) -> Self::ValidationFuture { self.validation_requests.write().push(uxt.clone()); + match self.block_id_to_number(at) { + Ok(Some(number)) => { + let found_best = self.chain + .read() + .block_by_number + .get(&number) + .map(|blocks| blocks.iter().any(|b| b.1.is_best())) + .unwrap_or(false); + + // If there is no best block, we don't know based on which block we should validate + // the transaction. (This is not required for this test function, but in real + // environment it would fail because of this). + if !found_best { + return ready(Ok( + Err(TransactionValidityError::Invalid(InvalidTransaction::Custom(1)).into()) + )) + } + }, + Ok(None) => return ready(Ok( + Err(TransactionValidityError::Invalid(InvalidTransaction::Custom(2)).into()) + )), + Err(e) => return ready(Err(e)), + } + let (requires, provides) = if let Some(transfer) = uxt.try_transfer() { let chain_nonce = self.chain.read().nonces.get(&transfer.from).cloned().unwrap_or(0); let requires = if chain_nonce == transfer.nonce { @@ -224,7 +279,7 @@ impl sc_transaction_graph::ChainApi for TestApi { }; if self.chain.read().invalid_hashes.contains(&self.hash_and_length(&uxt).0) { - return futures::future::ready(Ok( + return ready(Ok( Err(TransactionValidityError::Invalid(InvalidTransaction::Custom(0)).into()) )) } @@ -239,7 +294,7 @@ impl sc_transaction_graph::ChainApi for TestApi { (self.valid_modifier.read())(&mut validity); - futures::future::ready(Ok(Ok(validity))) + ready(Ok(Ok(validity))) } fn block_id_to_number( @@ -266,7 +321,7 @@ impl sc_transaction_graph::ChainApi for TestApi { .read() .block_by_number .get(num) - .map(|blocks| blocks[0].header().hash()), + .and_then(|blocks| blocks.iter().find(|b| b.1.is_best()).map(|b| b.0.header().hash())), }) } @@ -283,7 +338,7 @@ impl sc_transaction_graph::ChainApi for TestApi { .read() .block_by_number .get(num) - .map(|b| b[0].extrinsics().to_vec()), + .map(|b| b[0].0.extrinsics().to_vec()), BlockId::Hash(hash) => self.chain .read() .block_by_hash From dae6f0851ff428e74383395c0fc1b0fb57b7bae8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Sat, 12 Sep 2020 12:17:26 +0200 Subject: [PATCH 02/10] Fix `storage::read` (#7084) * Fix `storage::read` It should return the length of the storage item after the given offset. Before it returned always the length of the full storage item. * Fix tests --- primitives/io/src/lib.rs | 11 ++++++----- test-utils/runtime/src/lib.rs | 12 ++++-------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/primitives/io/src/lib.rs b/primitives/io/src/lib.rs index 7800658974..7f0700ce73 100644 --- a/primitives/io/src/lib.rs +++ b/primitives/io/src/lib.rs @@ -124,7 +124,7 @@ pub trait Storage { let data = &value[value_offset.min(value.len())..]; let written = std::cmp::min(data.len(), value_out.len()); value_out[..written].copy_from_slice(&data[..written]); - value.len() as u32 + data.len() as u32 }) } @@ -153,7 +153,7 @@ pub trait Storage { let data = &value[value_offset.min(value.len())..]; let written = std::cmp::min(data.len(), value_out.len()); value_out[..written].copy_from_slice(&data[..written]); - value.len() as u32 + data.len() as u32 }) } @@ -972,17 +972,18 @@ mod tests { #[test] fn read_storage_works() { + let value = b"\x0b\0\0\0Hello world".to_vec(); let mut t = BasicExternalities::new(Storage { - top: map![b":test".to_vec() => b"\x0b\0\0\0Hello world".to_vec()], + top: map![b":test".to_vec() => value.clone()], children: map![], }); t.execute_with(|| { let mut v = [0u8; 4]; - assert!(storage::read(b":test", &mut v[..], 0).unwrap() >= 4); + assert_eq!(storage::read(b":test", &mut v[..], 0).unwrap(), value.len() as u32); assert_eq!(v, [11u8, 0, 0, 0]); let mut w = [0u8; 11]; - assert!(storage::read(b":test", &mut w[..], 4).unwrap() >= 11); + assert_eq!(storage::read(b":test", &mut w[..], 4).unwrap(), value.len() as u32 - 4); assert_eq!(&w, b"Hello world"); }); } diff --git a/test-utils/runtime/src/lib.rs b/test-utils/runtime/src/lib.rs index 108180fa80..6b2db82734 100644 --- a/test-utils/runtime/src/lib.rs +++ b/test-utils/runtime/src/lib.rs @@ -951,17 +951,13 @@ fn test_read_storage() { sp_io::storage::set(KEY, b"test"); let mut v = [0u8; 4]; - let r = sp_io::storage::read( - KEY, - &mut v, - 0 - ); + let r = sp_io::storage::read(KEY, &mut v, 0); assert_eq!(r, Some(4)); assert_eq!(&v, b"test"); let mut v = [0u8; 4]; - let r = sp_io::storage::read(KEY, &mut v, 8); - assert_eq!(r, Some(4)); + let r = sp_io::storage::read(KEY, &mut v, 4); + assert_eq!(r, Some(0)); assert_eq!(&v, &[0, 0, 0, 0]); } @@ -998,7 +994,7 @@ fn test_read_child_storage() { &mut v, 8, ); - assert_eq!(r, Some(4)); + assert_eq!(r, Some(0)); assert_eq!(&v, &[0, 0, 0, 0]); } From c0749c15e55d195fd3eda9c281467b38717b9db1 Mon Sep 17 00:00:00 2001 From: Jordan Beauchamp Date: Mon, 14 Sep 2020 12:27:53 +1200 Subject: [PATCH 03/10] unstable sort -> stable sort --- client/authority-discovery/src/addr_cache.rs | 4 ++-- client/network/src/protocol/generic_proto/upgrade/legacy.rs | 2 +- frame/collective/src/lib.rs | 2 +- frame/contracts/src/wasm/runtime.rs | 2 +- frame/staking/src/lib.rs | 2 +- frame/support/src/traits.rs | 2 +- primitives/api/proc-macro/src/decl_runtime_apis.rs | 2 +- primitives/phragmen/src/lib.rs | 2 +- primitives/phragmen/src/mock.rs | 2 +- primitives/state-machine/src/changes_trie/build.rs | 2 +- primitives/trie/src/lib.rs | 2 +- 11 files changed, 12 insertions(+), 12 deletions(-) diff --git a/client/authority-discovery/src/addr_cache.rs b/client/authority-discovery/src/addr_cache.rs index 96f589c5d3..e2911acdd6 100644 --- a/client/authority-discovery/src/addr_cache.rs +++ b/client/authority-discovery/src/addr_cache.rs @@ -64,7 +64,7 @@ where return; } - addresses.sort_unstable_by(|a, b| a.as_ref().cmp(b.as_ref())); + addresses.sort_by(|a, b| a.as_ref().cmp(b.as_ref())); self.cache.insert(id, addresses); } @@ -89,7 +89,7 @@ where .collect::>(); addresses.dedup(); - addresses.sort_unstable_by(|a, b| a.as_ref().cmp(b.as_ref())); + addresses.sort_by(|a, b| a.as_ref().cmp(b.as_ref())); addresses .choose_multiple(&mut rng, MAX_NUM_AUTHORITY_CONN) diff --git a/client/network/src/protocol/generic_proto/upgrade/legacy.rs b/client/network/src/protocol/generic_proto/upgrade/legacy.rs index 311e0b04f9..6289c67946 100644 --- a/client/network/src/protocol/generic_proto/upgrade/legacy.rs +++ b/client/network/src/protocol/generic_proto/upgrade/legacy.rs @@ -53,7 +53,7 @@ impl RegisteredProtocol { id: protocol, supported_versions: { let mut tmp = versions.to_vec(); - tmp.sort_unstable_by(|a, b| b.cmp(&a)); + tmp.sort_by(|a, b| b.cmp(&a)); tmp }, } diff --git a/frame/collective/src/lib.rs b/frame/collective/src/lib.rs index dc5bfe9c66..781c3d3474 100644 --- a/frame/collective/src/lib.rs +++ b/frame/collective/src/lib.rs @@ -383,7 +383,7 @@ impl, I: Instance> ChangeMembers for Module { ) { // remove accounts from all current voting in motions. let mut outgoing = outgoing.to_vec(); - outgoing.sort_unstable(); + outgoing.sort(); for h in Self::proposals().into_iter() { >::mutate(h, |v| if let Some(mut votes) = v.take() { diff --git a/frame/contracts/src/wasm/runtime.rs b/frame/contracts/src/wasm/runtime.rs index fdfdb7897e..9a391129b8 100644 --- a/frame/contracts/src/wasm/runtime.rs +++ b/frame/contracts/src/wasm/runtime.rs @@ -1211,7 +1211,7 @@ where /// the order of items is not preserved. fn has_duplicates>(items: &mut Vec) -> bool { // Sort the vector - items.sort_unstable_by(|a, b| { + items.sort_by(|a, b| { Ord::cmp(a.as_ref(), b.as_ref()) }); // And then find any two consecutive equal elements. diff --git a/frame/staking/src/lib.rs b/frame/staking/src/lib.rs index bca8ffd7d1..73347f8acc 100644 --- a/frame/staking/src/lib.rs +++ b/frame/staking/src/lib.rs @@ -1901,7 +1901,7 @@ impl Module { let mut exposure_clipped = exposure; let clipped_max_len = T::MaxNominatorRewardedPerValidator::get() as usize; if exposure_clipped.others.len() > clipped_max_len { - exposure_clipped.others.sort_unstable_by(|a, b| a.value.cmp(&b.value).reverse()); + exposure_clipped.others.sort_by(|a, b| a.value.cmp(&b.value).reverse()); exposure_clipped.others.truncate(clipped_max_len); } >::insert(¤t_era, &c, exposure_clipped); diff --git a/frame/support/src/traits.rs b/frame/support/src/traits.rs index 80bb256c57..0b4661c4c1 100644 --- a/frame/support/src/traits.rs +++ b/frame/support/src/traits.rs @@ -837,7 +837,7 @@ pub trait ChangeMembers { /// /// This resets any previous value of prime. fn change_members(incoming: &[AccountId], outgoing: &[AccountId], mut new: Vec) { - new.sort_unstable(); + new.sort(); Self::change_members_sorted(incoming, outgoing, &new[..]); } diff --git a/primitives/api/proc-macro/src/decl_runtime_apis.rs b/primitives/api/proc-macro/src/decl_runtime_apis.rs index 459707bdb5..8aae473f85 100644 --- a/primitives/api/proc-macro/src/decl_runtime_apis.rs +++ b/primitives/api/proc-macro/src/decl_runtime_apis.rs @@ -382,7 +382,7 @@ fn generate_call_api_at_calls(decl: &ItemTrait) -> Result { renames.push((version, prefix_function_with_trait(&trait_name, &old_name))); } - renames.sort_unstable_by(|l, r| r.cmp(l)); + renames.sort_by(|l, r| r.cmp(l)); let (versions, old_names) = renames.into_iter().fold( (Vec::new(), Vec::new()), |(mut versions, mut old_names), (version, old_name)| { diff --git a/primitives/phragmen/src/lib.rs b/primitives/phragmen/src/lib.rs index aba714faeb..fdd1111bd0 100644 --- a/primitives/phragmen/src/lib.rs +++ b/primitives/phragmen/src/lib.rs @@ -491,7 +491,7 @@ fn do_equalize( e.1 = 0; }); - elected_edges.sort_unstable_by_key(|e| + elected_edges.sort_by_key(|e| if let Some(e) = support_map.get(&e.0) { e.total } else { Zero::zero() } ); diff --git a/primitives/phragmen/src/mock.rs b/primitives/phragmen/src/mock.rs index 66ef64a6c2..64f82afd22 100644 --- a/primitives/phragmen/src/mock.rs +++ b/primitives/phragmen/src/mock.rs @@ -274,7 +274,7 @@ pub(crate) fn do_equalize_float( e.1 = 0.0; }); - elected_edges.sort_unstable_by(|x, y| + elected_edges.sort_by(|x, y| support_map.get(&x.0) .and_then(|x| support_map.get(&y.0).and_then(|y| x.total.partial_cmp(&y.total))) .unwrap_or(sp_std::cmp::Ordering::Equal) diff --git a/primitives/state-machine/src/changes_trie/build.rs b/primitives/state-machine/src/changes_trie/build.rs index c731d4104b..78f0f9bb21 100644 --- a/primitives/state-machine/src/changes_trie/build.rs +++ b/primitives/state-machine/src/changes_trie/build.rs @@ -190,7 +190,7 @@ fn prepare_extrinsics_input_inner<'a, B, H, Number>( .iter() .cloned() ); - extrinsics.sort_unstable(); + extrinsics.sort(); }, } diff --git a/primitives/trie/src/lib.rs b/primitives/trie/src/lib.rs index 80570a9792..00fb6a9211 100644 --- a/primitives/trie/src/lib.rs +++ b/primitives/trie/src/lib.rs @@ -577,7 +577,7 @@ mod tests { count: 1000, }; let mut d = st.make(); - d.sort_unstable_by(|&(ref a, _), &(ref b, _)| a.cmp(b)); + d.sort_by(|&(ref a, _), &(ref b, _)| a.cmp(b)); let dr = d.iter().map(|v| (&v.0[..], &v.1[..])).collect(); check_equivalent::(&dr); check_iteration::(&dr); From 42242db42f8077f822e26a28b5b5df5b15e0d263 Mon Sep 17 00:00:00 2001 From: Jordan Beauchamp Date: Mon, 14 Sep 2020 12:48:42 +1200 Subject: [PATCH 04/10] Decode recusrions limit on extrinsics --- bin/node/executor/Cargo.toml | 2 +- client/Cargo.toml | 2 +- client/api/Cargo.toml | 2 +- client/authority-discovery/Cargo.toml | 2 +- client/basic-authorship/Cargo.toml | 2 +- client/block-builder/Cargo.toml | 2 +- client/consensus/aura/Cargo.toml | 2 +- client/consensus/babe/Cargo.toml | 2 +- client/consensus/epochs/Cargo.toml | 2 +- client/consensus/pow/Cargo.toml | 2 +- client/consensus/slots/Cargo.toml | 2 +- client/db/Cargo.toml | 2 +- client/executor/Cargo.toml | 2 +- client/executor/common/Cargo.toml | 2 +- client/executor/wasmi/Cargo.toml | 2 +- client/executor/wasmtime/Cargo.toml | 2 +- client/network/Cargo.toml | 2 +- client/offchain/Cargo.toml | 2 +- client/rpc-api/Cargo.toml | 2 +- client/rpc/Cargo.toml | 2 +- client/service/Cargo.toml | 2 +- client/state-db/Cargo.toml | 2 +- client/transaction-pool/Cargo.toml | 2 +- client/transaction-pool/graph/Cargo.toml | 2 +- frame/assets/Cargo.toml | 2 +- frame/aura/Cargo.toml | 2 +- frame/authority-discovery/Cargo.toml | 2 +- frame/authorship/Cargo.toml | 2 +- frame/babe/Cargo.toml | 2 +- frame/balances/Cargo.toml | 2 +- frame/benchmarking/Cargo.toml | 2 +- frame/collective/Cargo.toml | 2 +- frame/contracts/Cargo.toml | 2 +- frame/contracts/common/Cargo.toml | 2 +- frame/contracts/rpc/Cargo.toml | 2 +- frame/contracts/rpc/runtime-api/Cargo.toml | 2 +- frame/democracy/Cargo.toml | 2 +- frame/elections-phragmen/Cargo.toml | 2 +- frame/elections/Cargo.toml | 2 +- frame/evm/Cargo.toml | 2 +- frame/example/Cargo.toml | 2 +- frame/executive/Cargo.toml | 2 +- frame/finality-tracker/Cargo.toml | 2 +- frame/generic-asset/Cargo.toml | 2 +- frame/generic-asset/rpc/Cargo.toml | 2 +- frame/generic-asset/rpc/runtime-api/Cargo.toml | 2 +- frame/grandpa/Cargo.toml | 2 +- frame/identity/Cargo.toml | 2 +- frame/im-online/Cargo.toml | 2 +- frame/membership/Cargo.toml | 2 +- frame/metadata/Cargo.toml | 2 +- frame/nicks/Cargo.toml | 2 +- frame/recovery/Cargo.toml | 2 +- frame/scored-pool/Cargo.toml | 2 +- frame/session/Cargo.toml | 2 +- frame/society/Cargo.toml | 2 +- frame/staking/Cargo.toml | 2 +- frame/staking/fuzz/Cargo.toml | 2 +- frame/sudo/Cargo.toml | 2 +- frame/support/Cargo.toml | 2 +- frame/support/test/Cargo.toml | 2 +- frame/system/Cargo.toml | 2 +- frame/system/rpc/runtime-api/Cargo.toml | 2 +- frame/timestamp/Cargo.toml | 2 +- frame/treasury/Cargo.toml | 2 +- frame/utility/Cargo.toml | 2 +- frame/vesting/Cargo.toml | 2 +- primitives/api/proc-macro/src/decl_runtime_apis.rs | 3 ++- primitives/api/proc-macro/src/impl_runtime_apis.rs | 5 ++++- primitives/api/src/lib.rs | 5 ++++- primitives/application-crypto/Cargo.toml | 2 +- primitives/authority-discovery/Cargo.toml | 2 +- primitives/consensus/aura/Cargo.toml | 2 +- primitives/consensus/babe/Cargo.toml | 2 +- primitives/consensus/common/Cargo.toml | 2 +- primitives/consensus/pow/Cargo.toml | 2 +- primitives/consensus/slots/Cargo.toml | 2 +- primitives/finality-grandpa/Cargo.toml | 2 +- primitives/session/Cargo.toml | 2 +- prml/consortium-permission/Cargo.toml | 2 +- prml/validator-manager/Cargo.toml | 2 +- 81 files changed, 88 insertions(+), 81 deletions(-) diff --git a/bin/node/executor/Cargo.toml b/bin/node/executor/Cargo.toml index 45a43233c0..b40d8f582b 100644 --- a/bin/node/executor/Cargo.toml +++ b/bin/node/executor/Cargo.toml @@ -9,7 +9,7 @@ homepage = "https://substrate.dev" repository = "https://github.com/paritytech/substrate/" [dependencies] -codec = { package = "parity-scale-codec", version = "1.3.0" } +codec = { package = "parity-scale-codec", version = "1.3.5" } node-primitives = { version = "2.0.0-alpha.5", path = "../primitives" } node-runtime = { version = "2.0.0-alpha.5", path = "../runtime" } sc-executor = { version = "0.8.0-alpha.5", path = "../../../client/executor" } diff --git a/client/Cargo.toml b/client/Cargo.toml index b562ed37a5..73fa0f2132 100644 --- a/client/Cargo.toml +++ b/client/Cargo.toml @@ -11,7 +11,7 @@ description = "Substrate Client and associated logic." [dependencies] sc-block-builder = { version = "0.8.0-alpha.5", path = "block-builder" } sc-client-api = { version = "2.0.0-alpha.5", path = "api" } -codec = { package = "parity-scale-codec", version = "1.3.0", features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", features = ["derive"] } sp-consensus = { version = "0.8.0-alpha.5", path = "../primitives/consensus/common" } derive_more = { version = "0.99.2" } sc-executor = { version = "0.8.0-alpha.5", path = "executor" } diff --git a/client/api/Cargo.toml b/client/api/Cargo.toml index 3c3817682f..eec2ed7777 100644 --- a/client/api/Cargo.toml +++ b/client/api/Cargo.toml @@ -11,7 +11,7 @@ documentation = "https://docs.rs/sc-client-api" [dependencies] -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-consensus = { version = "0.8.0-alpha.5", path = "../../primitives/consensus/common" } derive_more = { version = "0.99.2" } sc-executor = { version = "0.8.0-alpha.5", path = "../executor" } diff --git a/client/authority-discovery/Cargo.toml b/client/authority-discovery/Cargo.toml index 09b4fa8391..5fd900e037 100644 --- a/client/authority-discovery/Cargo.toml +++ b/client/authority-discovery/Cargo.toml @@ -14,7 +14,7 @@ prost-build = "0.6.1" [dependencies] bytes = "0.5.0" -codec = { package = "parity-scale-codec", default-features = false, version = "1.3.0" } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false } derive_more = "0.99.2" futures = "0.3.4" futures-timer = "3.0.1" diff --git a/client/basic-authorship/Cargo.toml b/client/basic-authorship/Cargo.toml index 97fb8f2c6c..ec717b9a48 100644 --- a/client/basic-authorship/Cargo.toml +++ b/client/basic-authorship/Cargo.toml @@ -11,7 +11,7 @@ description = "Basic implementation of block-authoring logic." [dependencies] log = "0.4.8" futures = "0.3.4" -codec = { package = "parity-scale-codec", version = "1.3.0" } +codec = { package = "parity-scale-codec", version = "1.3.5" } sp-api = { version = "2.0.0-alpha.5", path = "../../primitives/api" } sp-runtime = { version = "2.0.0-alpha.5", path = "../../primitives/runtime" } sp-core = { version = "2.0.0-alpha.5", path = "../../primitives/core" } diff --git a/client/block-builder/Cargo.toml b/client/block-builder/Cargo.toml index 376d75ef86..db6246babf 100644 --- a/client/block-builder/Cargo.toml +++ b/client/block-builder/Cargo.toml @@ -18,7 +18,7 @@ sp-blockchain = { version = "2.0.0-alpha.5", path = "../../primitives/blockchain sp-core = { version = "2.0.0-alpha.5", path = "../../primitives/core" } sp-block-builder = { version = "2.0.0-alpha.5", path = "../../primitives/block-builder" } sc-client-api = { version = "2.0.0-alpha.5", path = "../api" } -codec = { package = "parity-scale-codec", version = "1.3.0", features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", features = ["derive"] } [dev-dependencies] substrate-test-runtime-client = { path = "../../test-utils/runtime/client" } diff --git a/client/consensus/aura/Cargo.toml b/client/consensus/aura/Cargo.toml index 12513fbbd5..0b9f2e6100 100644 --- a/client/consensus/aura/Cargo.toml +++ b/client/consensus/aura/Cargo.toml @@ -15,7 +15,7 @@ sp-block-builder = { version = "2.0.0-alpha.5", path = "../../../primitives/bloc sc-block-builder = { version = "0.8.0-alpha.5", path = "../../../client/block-builder" } sc-client = { version = "0.8.0-alpha.5", path = "../../" } sc-client-api = { version = "2.0.0-alpha.5", path = "../../api" } -codec = { package = "parity-scale-codec", version = "1.3.0" } +codec = { package = "parity-scale-codec", version = "1.3.5" } sp-consensus = { version = "0.8.0-alpha.5", path = "../../../primitives/consensus/common" } derive_more = "0.99.2" futures = "0.3.4" diff --git a/client/consensus/babe/Cargo.toml b/client/consensus/babe/Cargo.toml index 01347c2919..63c3f015c3 100644 --- a/client/consensus/babe/Cargo.toml +++ b/client/consensus/babe/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/paritytech/substrate/" documentation = "https://docs.rs/sc-consensus-babe" [dependencies] -codec = { package = "parity-scale-codec", version = "1.3.0", features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", features = ["derive"] } sp-consensus-babe = { version = "0.8.0-alpha.5", path = "../../../primitives/consensus/babe" } sp-core = { version = "2.0.0-alpha.5", path = "../../../primitives/core" } sp-application-crypto = { version = "2.0.0-alpha.5", path = "../../../primitives/application-crypto" } diff --git a/client/consensus/epochs/Cargo.toml b/client/consensus/epochs/Cargo.toml index ff9153299c..51e5af63da 100644 --- a/client/consensus/epochs/Cargo.toml +++ b/client/consensus/epochs/Cargo.toml @@ -9,7 +9,7 @@ homepage = "https://substrate.dev" repository = "https://github.com/paritytech/substrate/" [dependencies] -codec = { package = "parity-scale-codec", version = "1.3.0", features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", features = ["derive"] } parking_lot = "0.10.0" fork-tree = { version = "2.0.0-alpha.5", path = "../../../utils/fork-tree" } sp-runtime = { path = "../../../primitives/runtime" , version = "2.0.0-alpha.5"} diff --git a/client/consensus/pow/Cargo.toml b/client/consensus/pow/Cargo.toml index f8ea106d9c..494b8ad7d0 100644 --- a/client/consensus/pow/Cargo.toml +++ b/client/consensus/pow/Cargo.toml @@ -9,7 +9,7 @@ homepage = "https://substrate.dev" repository = "https://github.com/paritytech/substrate/" [dependencies] -codec = { package = "parity-scale-codec", version = "1.3.0", features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", features = ["derive"] } sp-core = { version = "2.0.0-alpha.5", path = "../../../primitives/core" } sp-blockchain = { version = "2.0.0-alpha.5", path = "../../../primitives/blockchain" } sp-runtime = { version = "2.0.0-alpha.5", path = "../../../primitives/runtime" } diff --git a/client/consensus/slots/Cargo.toml b/client/consensus/slots/Cargo.toml index bce01e4174..a6e2087784 100644 --- a/client/consensus/slots/Cargo.toml +++ b/client/consensus/slots/Cargo.toml @@ -10,7 +10,7 @@ homepage = "https://substrate.dev" repository = "https://github.com/paritytech/substrate/" [dependencies] -codec = { package = "parity-scale-codec", version = "1.3.0" } +codec = { package = "parity-scale-codec", version = "1.3.5" } sc-client-api = { version = "2.0.0-alpha.5", path = "../../api" } sp-core = { version = "2.0.0-alpha.5", path = "../../../primitives/core" } sp-blockchain = { version = "2.0.0-alpha.5", path = "../../../primitives/blockchain" } diff --git a/client/db/Cargo.toml b/client/db/Cargo.toml index 6d3389b5f9..5d7a75e627 100644 --- a/client/db/Cargo.toml +++ b/client/db/Cargo.toml @@ -18,7 +18,7 @@ kvdb-memorydb = "0.5.0" linked-hash-map = "0.5.2" hash-db = "0.15.2" parity-util-mem = { version = "0.6.0", default-features = false, features = ["std"] } -codec = { package = "parity-scale-codec", version = "1.3.0", features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", features = ["derive"] } sc-client-api = { version = "2.0.0-alpha.5", path = "../api" } sp-core = { version = "2.0.0-alpha.5", path = "../../primitives/core" } diff --git a/client/executor/Cargo.toml b/client/executor/Cargo.toml index e6a43dd685..9da174c4e1 100644 --- a/client/executor/Cargo.toml +++ b/client/executor/Cargo.toml @@ -11,7 +11,7 @@ documentation = "https://docs.rs/sc-executor" [dependencies] derive_more = "0.99.2" -codec = { package = "parity-scale-codec", version = "1.3.0" } +codec = { package = "parity-scale-codec", version = "1.3.5" } sp-io = { version = "2.0.0-alpha.5", path = "../../primitives/io" } sp-core = { version = "2.0.0-alpha.5", path = "../../primitives/core" } sp-trie = { version = "2.0.0-alpha.5", path = "../../primitives/trie" } diff --git a/client/executor/common/Cargo.toml b/client/executor/common/Cargo.toml index ae89524a49..1e20c73d8a 100644 --- a/client/executor/common/Cargo.toml +++ b/client/executor/common/Cargo.toml @@ -12,7 +12,7 @@ documentation = "https://docs.rs/sc-executor-common/" [dependencies] log = "0.4.8" derive_more = "0.99.2" -codec = { package = "parity-scale-codec", version = "1.3.0" } +codec = { package = "parity-scale-codec", version = "1.3.5" } wasmi = "0.6.2" sp-core = { version = "2.0.0-alpha.5", path = "../../../primitives/core" } sp-allocator = { version = "2.0.0-alpha.5", path = "../../../primitives/allocator" } diff --git a/client/executor/wasmi/Cargo.toml b/client/executor/wasmi/Cargo.toml index 6f5b585258..5138329304 100644 --- a/client/executor/wasmi/Cargo.toml +++ b/client/executor/wasmi/Cargo.toml @@ -13,7 +13,7 @@ documentation = "https://docs.rs/sc-execturo-wasmi" log = "0.4.8" wasmi = "0.6.2" parity-wasm = "0.41.0" -codec = { package = "parity-scale-codec", version = "1.3.0" } +codec = { package = "parity-scale-codec", version = "1.3.5" } sc-executor-common = { version = "0.8.0-alpha.5", path = "../common" } sp-wasm-interface = { version = "2.0.0-alpha.5", path = "../../../primitives/wasm-interface" } sp-runtime-interface = { version = "2.0.0-alpha.5", path = "../../../primitives/runtime-interface" } diff --git a/client/executor/wasmtime/Cargo.toml b/client/executor/wasmtime/Cargo.toml index 6ca17408ef..a8bddef5a6 100644 --- a/client/executor/wasmtime/Cargo.toml +++ b/client/executor/wasmtime/Cargo.toml @@ -12,7 +12,7 @@ description = "Defines a `WasmRuntime` that uses the Wasmtime JIT to execute." log = "0.4.8" scoped-tls = "1.0" parity-wasm = "0.41.0" -codec = { package = "parity-scale-codec", version = "1.3.0" } +codec = { package = "parity-scale-codec", version = "1.3.5" } sc-executor-common = { version = "0.8.0-alpha.5", path = "../common" } sp-wasm-interface = { version = "2.0.0-alpha.5", path = "../../../primitives/wasm-interface" } sp-runtime-interface = { version = "2.0.0-alpha.5", path = "../../../primitives/runtime-interface" } diff --git a/client/network/Cargo.toml b/client/network/Cargo.toml index 1d43b72e37..bc427a864e 100644 --- a/client/network/Cargo.toml +++ b/client/network/Cargo.toml @@ -16,7 +16,7 @@ prost-build = "0.6.1" [dependencies] bitflags = "1.2.0" bytes = "0.5.0" -codec = { package = "parity-scale-codec", version = "1.3.0", features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", features = ["derive"] } derive_more = "0.99.2" either = "1.5.3" erased-serde = "0.3.9" diff --git a/client/offchain/Cargo.toml b/client/offchain/Cargo.toml index 9e5d69a171..1ae728229a 100644 --- a/client/offchain/Cargo.toml +++ b/client/offchain/Cargo.toml @@ -19,7 +19,7 @@ log = "0.4.8" threadpool = "1.7" num_cpus = "1.10" sp-offchain = { version = "2.0.0-alpha.5", path = "../../primitives/offchain" } -codec = { package = "parity-scale-codec", version = "1.3.0", features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", features = ["derive"] } parking_lot = "0.10.0" sp-core = { version = "2.0.0-alpha.5", path = "../../primitives/core" } rand = "0.7.2" diff --git a/client/rpc-api/Cargo.toml b/client/rpc-api/Cargo.toml index e6d448040f..b8c6a19aa1 100644 --- a/client/rpc-api/Cargo.toml +++ b/client/rpc-api/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://github.com/paritytech/substrate/" description = "Substrate RPC interfaces." [dependencies] -codec = { package = "parity-scale-codec", version = "1.3.0" } +codec = { package = "parity-scale-codec", version = "1.3.5" } derive_more = "0.99.2" futures = { version = "0.3.1", features = ["compat"] } jsonrpc-core = "14.0.3" diff --git a/client/rpc/Cargo.toml b/client/rpc/Cargo.toml index 24f3a485a2..e460a0d157 100644 --- a/client/rpc/Cargo.toml +++ b/client/rpc/Cargo.toml @@ -18,7 +18,7 @@ sc-rpc-api = { version = "0.8.0-alpha.5", path = "../rpc-api" } sc-client-api = { version = "2.0.0-alpha.5", path = "../api" } sc-client = { version = "0.8.0-alpha.5", path = "../" } sp-api = { version = "2.0.0-alpha.5", path = "../../primitives/api" } -codec = { package = "parity-scale-codec", version = "1.3.0" } +codec = { package = "parity-scale-codec", version = "1.3.5" } futures = { version = "0.3.1", features = ["compat"] } jsonrpc-pubsub = "14.0.3" log = "0.4.8" diff --git a/client/service/Cargo.toml b/client/service/Cargo.toml index de6b36d4a0..26647bf875 100644 --- a/client/service/Cargo.toml +++ b/client/service/Cargo.toml @@ -47,7 +47,7 @@ sc-client-api = { version = "2.0.0-alpha.5", path = "../api" } sc-client = { version = "0.8.0-alpha.5", path = "../" } sp-api = { version = "2.0.0-alpha.5", path = "../../primitives/api" } sc-client-db = { version = "0.8.0-alpha.5", path = "../db" } -codec = { package = "parity-scale-codec", version = "1.3.0" } +codec = { package = "parity-scale-codec", version = "1.3.5" } sc-executor = { version = "0.8.0-alpha.5", path = "../executor" } sc-transaction-pool = { version = "2.0.0-rc3", path = "../transaction-pool" } sp-transaction-pool = { version = "2.0.0-rc2", path = "../../primitives/transaction-pool" } diff --git a/client/state-db/Cargo.toml b/client/state-db/Cargo.toml index c4b21bd407..c7e1a22e0c 100644 --- a/client/state-db/Cargo.toml +++ b/client/state-db/Cargo.toml @@ -13,7 +13,7 @@ parking_lot = "0.10.0" log = "0.4.8" sc-client-api = { version = "2.0.0-alpha.5", path = "../api" } sp-core = { version = "2.0.0-alpha.5", path = "../../primitives/core" } -codec = { package = "parity-scale-codec", version = "1.3.0", features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", features = ["derive"] } parity-util-mem = "0.6" parity-util-mem-derive = "0.1.0" diff --git a/client/transaction-pool/Cargo.toml b/client/transaction-pool/Cargo.toml index 478227af44..f1976c18e2 100644 --- a/client/transaction-pool/Cargo.toml +++ b/client/transaction-pool/Cargo.toml @@ -12,7 +12,7 @@ description = "Substrate transaction pool implementation." targets = ["x86_64-unknown-linux-gnu"] [dependencies] -codec = { package = "parity-scale-codec", version = "1.3.0" } +codec = { package = "parity-scale-codec", version = "1.3.5" } derive_more = "0.99.2" futures = { version = "0.3.1", features = ["compat"] } futures-diagnose = "1.0" diff --git a/client/transaction-pool/graph/Cargo.toml b/client/transaction-pool/graph/Cargo.toml index d678c65d1d..fb6446371f 100644 --- a/client/transaction-pool/graph/Cargo.toml +++ b/client/transaction-pool/graph/Cargo.toml @@ -28,7 +28,7 @@ linked-hash-map = "0.5.2" [dev-dependencies] assert_matches = "1.3.0" -codec = { package = "parity-scale-codec", version = "1.3.0" } +codec = { package = "parity-scale-codec", version = "1.3.5" } substrate-test-runtime = { version = "2.0.0-alpha.5", path = "../../../test-utils/runtime" } criterion = "0.3" diff --git a/frame/assets/Cargo.toml b/frame/assets/Cargo.toml index 893e595e71..0d42d47742 100644 --- a/frame/assets/Cargo.toml +++ b/frame/assets/Cargo.toml @@ -10,7 +10,7 @@ description = "FRAME asset management pallet" [dependencies] serde = { version = "1.0.101", optional = true } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false } # Needed for various traits. In our case, `OnFinalize`. sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/runtime" } # Needed for type-safe access to storage DB. diff --git a/frame/aura/Cargo.toml b/frame/aura/Cargo.toml index c82d62c049..1473f64508 100644 --- a/frame/aura/Cargo.toml +++ b/frame/aura/Cargo.toml @@ -10,7 +10,7 @@ description = "FRAME AURA consensus pallet" [dependencies] sp-application-crypto = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/application-crypto" } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-inherents = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/inherents" } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } serde = { version = "1.0.101", optional = true } diff --git a/frame/authority-discovery/Cargo.toml b/frame/authority-discovery/Cargo.toml index b6032e93d4..bcd1575679 100644 --- a/frame/authority-discovery/Cargo.toml +++ b/frame/authority-discovery/Cargo.toml @@ -11,7 +11,7 @@ description = "FRAME pallet for authority discovery" [dependencies] sp-authority-discovery = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/authority-discovery" } sp-application-crypto = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/application-crypto" } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-core = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/core" } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } serde = { version = "1.0.101", optional = true } diff --git a/frame/authorship/Cargo.toml b/frame/authorship/Cargo.toml index 05b85ded59..4e0b0ab462 100644 --- a/frame/authorship/Cargo.toml +++ b/frame/authorship/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/paritytech/substrate/" [dependencies] sp-core = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/core" } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-inherents = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/inherents" } sp-authorship = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/authorship" } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } diff --git a/frame/babe/Cargo.toml b/frame/babe/Cargo.toml index 7a24988075..7ab586978d 100644 --- a/frame/babe/Cargo.toml +++ b/frame/babe/Cargo.toml @@ -12,7 +12,7 @@ description = "Consensus extension module for BABE consensus. Collects on-chain targets = ["x86_64-unknown-linux-gnu"] [dependencies] -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } frame-benchmarking = { version = "2.0.0-alpha.5", default-features = false, path = "../benchmarking", optional = true } frame-support = { version = "2.0.0-alpha.5", default-features = false, path = "../support" } frame-system = { version = "2.0.0-alpha.5", default-features = false, path = "../system" } diff --git a/frame/balances/Cargo.toml b/frame/balances/Cargo.toml index 9a5e512aec..e6bc1fae72 100644 --- a/frame/balances/Cargo.toml +++ b/frame/balances/Cargo.toml @@ -10,7 +10,7 @@ description = "FRAME pallet to manage balances" [dependencies] serde = { version = "1.0.101", optional = true } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } sp-io = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/io" } sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/runtime" } diff --git a/frame/benchmarking/Cargo.toml b/frame/benchmarking/Cargo.toml index 26c6f41f09..f5c7e8da2d 100644 --- a/frame/benchmarking/Cargo.toml +++ b/frame/benchmarking/Cargo.toml @@ -10,7 +10,7 @@ description = "Macro for benchmarking a FRAME runtime." [dependencies] linregress = "0.1" -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false } sp-api = { version = "2.0.0-alpha.5", path = "../../primitives/api", default-features = false } sp-runtime-interface = { version = "2.0.0-alpha.5", path = "../../primitives/runtime-interface", default-features = false } sp-runtime = { version = "2.0.0-alpha.5", path = "../../primitives/runtime", default-features = false } diff --git a/frame/collective/Cargo.toml b/frame/collective/Cargo.toml index 12f54e5a65..ea6c879037 100644 --- a/frame/collective/Cargo.toml +++ b/frame/collective/Cargo.toml @@ -10,7 +10,7 @@ description = "Collective system: Members of a set of account IDs can make their [dependencies] serde = { version = "1.0.101", optional = true } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-core = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/core" } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } sp-io = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/io" } diff --git a/frame/contracts/Cargo.toml b/frame/contracts/Cargo.toml index cde9be3105..fc17d2c48f 100644 --- a/frame/contracts/Cargo.toml +++ b/frame/contracts/Cargo.toml @@ -11,7 +11,7 @@ description = "FRAME pallet for WASM contracts" [dependencies] serde = { version = "1.0.101", optional = true, features = ["derive"] } pwasm-utils = { version = "0.12.0", default-features = false } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } parity-wasm = { version = "0.41.0", default-features = false } wasmi-validation = { version = "0.3.0", default-features = false } sp-core = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/core" } diff --git a/frame/contracts/common/Cargo.toml b/frame/contracts/common/Cargo.toml index 9cb136cd43..a276762a5f 100644 --- a/frame/contracts/common/Cargo.toml +++ b/frame/contracts/common/Cargo.toml @@ -10,7 +10,7 @@ description = "A crate that hosts a common definitions that are relevant for the [dependencies] # This crate should not rely on any of the frame primitives. -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../../primitives/std" } sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../../../primitives/runtime" } diff --git a/frame/contracts/rpc/Cargo.toml b/frame/contracts/rpc/Cargo.toml index 3b725bf4cb..62b5df5b2f 100644 --- a/frame/contracts/rpc/Cargo.toml +++ b/frame/contracts/rpc/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://github.com/paritytech/substrate/" description = "Node-specific RPC methods for interaction with contracts." [dependencies] -codec = { package = "parity-scale-codec", version = "1.3.0" } +codec = { package = "parity-scale-codec", version = "1.3.5" } jsonrpc-core = "14.0.3" jsonrpc-core-client = "14.0.3" jsonrpc-derive = "14.0.3" diff --git a/frame/contracts/rpc/runtime-api/Cargo.toml b/frame/contracts/rpc/runtime-api/Cargo.toml index a3c0790f9f..d66147e2f3 100644 --- a/frame/contracts/rpc/runtime-api/Cargo.toml +++ b/frame/contracts/rpc/runtime-api/Cargo.toml @@ -10,7 +10,7 @@ description = "Runtime API definition required by Contracts RPC extensions." [dependencies] sp-api = { version = "2.0.0-alpha.5", default-features = false, path = "../../../../primitives/api" } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../../../primitives/std" } sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../../../../primitives/runtime" } pallet-contracts-primitives = { version = "2.0.0-alpha.5", default-features = false, path = "../../common" } diff --git a/frame/democracy/Cargo.toml b/frame/democracy/Cargo.toml index 3e9eea3eb1..32c57d5706 100644 --- a/frame/democracy/Cargo.toml +++ b/frame/democracy/Cargo.toml @@ -10,7 +10,7 @@ description = "FRAME pallet for democracy" [dependencies] serde = { version = "1.0.101", optional = true, features = ["derive"] } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } sp-io = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/io" } sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/runtime" } diff --git a/frame/elections-phragmen/Cargo.toml b/frame/elections-phragmen/Cargo.toml index 2c958dff2e..3cf493c8a2 100644 --- a/frame/elections-phragmen/Cargo.toml +++ b/frame/elections-phragmen/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://github.com/paritytech/substrate/" description = "FRAME election pallet for PHRAGMEN" [dependencies] -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/runtime" } sp-phragmen = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/phragmen" } frame-support = { version = "2.0.0-alpha.5", default-features = false, path = "../support" } diff --git a/frame/elections/Cargo.toml b/frame/elections/Cargo.toml index c86039a68b..f7fd808879 100644 --- a/frame/elections/Cargo.toml +++ b/frame/elections/Cargo.toml @@ -10,7 +10,7 @@ description = "FRAME pallet for elections" [dependencies] serde = { version = "1.0.101", optional = true } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-core = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/core" } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } sp-io = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/io" } diff --git a/frame/evm/Cargo.toml b/frame/evm/Cargo.toml index bcb7b3ac5e..47d1d600ea 100644 --- a/frame/evm/Cargo.toml +++ b/frame/evm/Cargo.toml @@ -10,7 +10,7 @@ description = "FRAME EVM contracts pallet" [dependencies] serde = { version = "1.0.101", optional = true, features = ["derive"] } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false } frame-support = { version = "2.0.0-alpha.5", default-features = false, path = "../support" } frame-system = { version = "2.0.0-alpha.5", default-features = false, path = "../system" } pallet-timestamp = { version = "2.0.0-alpha.5", default-features = false, path = "../timestamp" } diff --git a/frame/example/Cargo.toml b/frame/example/Cargo.toml index 5025014fba..586a2c887e 100644 --- a/frame/example/Cargo.toml +++ b/frame/example/Cargo.toml @@ -10,7 +10,7 @@ description = "FRAME example pallet" [dependencies] serde = { version = "1.0.101", optional = true } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false } frame-benchmarking = { version = "2.0.0-alpha.5", default-features = false, path = "../benchmarking" } frame-support = { version = "2.0.0-alpha.5", default-features = false, path = "../support" } frame-system = { version = "2.0.0-alpha.5", default-features = false, path = "../system" } diff --git a/frame/executive/Cargo.toml b/frame/executive/Cargo.toml index e5956b9b02..19158bd150 100644 --- a/frame/executive/Cargo.toml +++ b/frame/executive/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://github.com/paritytech/substrate/" description = "FRAME executives engine" [dependencies] -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } frame-support = { version = "2.0.0-alpha.5", default-features = false, path = "../support" } frame-system = { version = "2.0.0-alpha.5", default-features = false, path = "../system" } serde = { version = "1.0.101", optional = true } diff --git a/frame/finality-tracker/Cargo.toml b/frame/finality-tracker/Cargo.toml index a8c1587e53..b9120c0f5e 100644 --- a/frame/finality-tracker/Cargo.toml +++ b/frame/finality-tracker/Cargo.toml @@ -12,7 +12,7 @@ documentation = "https://docs.rs/pallet-finality-tracker" [dependencies] serde = { version = "1.0.101", default-features = false, features = ["derive"] } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false } sp-inherents = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/inherents" } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/runtime" } diff --git a/frame/generic-asset/Cargo.toml b/frame/generic-asset/Cargo.toml index dd4a743c77..2d9684cd95 100644 --- a/frame/generic-asset/Cargo.toml +++ b/frame/generic-asset/Cargo.toml @@ -10,7 +10,7 @@ description = "FRAME pallet for generic asset management" [dependencies] serde = { version = "1.0.101", default-features = false, features = ["derive"], optional = true} -codec = { package = "parity-scale-codec", default-features = false, version = "1.3.0", features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/runtime" } frame-support = { version = "2.0.0-alpha.5", default-features = false, path = "../support" } diff --git a/frame/generic-asset/rpc/Cargo.toml b/frame/generic-asset/rpc/Cargo.toml index 194f7385e6..795cf06433 100644 --- a/frame/generic-asset/rpc/Cargo.toml +++ b/frame/generic-asset/rpc/Cargo.toml @@ -8,7 +8,7 @@ repository = "https://github.com/plugblockchain/plug-blockchain/" description = "RPC interface for the generic asset module." [dependencies] -codec = { package = "parity-scale-codec", version = "1.3.0" } +codec = { package = "parity-scale-codec", version = "1.3.5" } jsonrpc-core = "14.0.3" jsonrpc-core-client = "14.0.3" jsonrpc-derive = "14.0.3" diff --git a/frame/generic-asset/rpc/runtime-api/Cargo.toml b/frame/generic-asset/rpc/runtime-api/Cargo.toml index 040dc9dcc9..d567e1d187 100644 --- a/frame/generic-asset/rpc/runtime-api/Cargo.toml +++ b/frame/generic-asset/rpc/runtime-api/Cargo.toml @@ -11,7 +11,7 @@ description = "Runtime API definition required by Generic Asset RPC extensions." sp-api = { version = "2.0.0-alpha.5", default-features = false, path = "../../../../primitives/api" } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../../../primitives/std" } pallet-generic-asset = { version = "2.0.0-alpha.5", default-features = false, path = "../../../../frame/generic-asset" } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false } [features] default = ["std"] diff --git a/frame/grandpa/Cargo.toml b/frame/grandpa/Cargo.toml index 6344cd211e..6424a61a53 100644 --- a/frame/grandpa/Cargo.toml +++ b/frame/grandpa/Cargo.toml @@ -10,7 +10,7 @@ description = "FRAME pallet for GRANDPA finality gadget" [dependencies] serde = { version = "1.0.101", optional = true, features = ["derive"] } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-core = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/core" } sp-finality-grandpa = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/finality-grandpa" } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } diff --git a/frame/identity/Cargo.toml b/frame/identity/Cargo.toml index 963047405f..56b16f756f 100644 --- a/frame/identity/Cargo.toml +++ b/frame/identity/Cargo.toml @@ -10,7 +10,7 @@ description = "FRAME identity management pallet" [dependencies] serde = { version = "1.0.101", optional = true } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } enumflags2 = { version = "0.6.2" } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } sp-io = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/io" } diff --git a/frame/im-online/Cargo.toml b/frame/im-online/Cargo.toml index c07652dfdb..171a6b285d 100644 --- a/frame/im-online/Cargo.toml +++ b/frame/im-online/Cargo.toml @@ -11,7 +11,7 @@ description = "FRAME's I'm online pallet" [dependencies] sp-application-crypto = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/application-crypto" } pallet-authorship = { version = "2.0.0-alpha.5", default-features = false, path = "../authorship" } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-core = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/core" } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } serde = { version = "1.0.101", optional = true } diff --git a/frame/membership/Cargo.toml b/frame/membership/Cargo.toml index ef3abfbbf6..8d6aabe541 100644 --- a/frame/membership/Cargo.toml +++ b/frame/membership/Cargo.toml @@ -10,7 +10,7 @@ description = "FRAME membership management pallet" [dependencies] serde = { version = "1.0.101", optional = true } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } sp-io = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/io" } frame-support = { version = "2.0.0-alpha.5", default-features = false, path = "../support" } diff --git a/frame/metadata/Cargo.toml b/frame/metadata/Cargo.toml index ce68d3bc31..ac5045cd22 100644 --- a/frame/metadata/Cargo.toml +++ b/frame/metadata/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://github.com/paritytech/substrate/" description = "Decodable variant of the RuntimeMetadata." [dependencies] -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } serde = { version = "1.0.101", optional = true, features = ["derive"] } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } sp-core = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/core" } diff --git a/frame/nicks/Cargo.toml b/frame/nicks/Cargo.toml index 76bc183ca3..123f7b4120 100644 --- a/frame/nicks/Cargo.toml +++ b/frame/nicks/Cargo.toml @@ -10,7 +10,7 @@ description = "FRAME pallet for nick management" [dependencies] serde = { version = "1.0.101", optional = true } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } sp-io = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/io" } sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/runtime" } diff --git a/frame/recovery/Cargo.toml b/frame/recovery/Cargo.toml index 4ac5e45471..a36a61882d 100644 --- a/frame/recovery/Cargo.toml +++ b/frame/recovery/Cargo.toml @@ -10,7 +10,7 @@ description = "FRAME account recovery pallet" [dependencies] serde = { version = "1.0.101", optional = true } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } enumflags2 = { version = "0.6.2" } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } sp-io = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/io" } diff --git a/frame/scored-pool/Cargo.toml b/frame/scored-pool/Cargo.toml index 711bfd4c09..fed1926784 100644 --- a/frame/scored-pool/Cargo.toml +++ b/frame/scored-pool/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://github.com/paritytech/substrate/" description = "FRAME pallet for scored pools" [dependencies] -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } serde = { version = "1.0.101", optional = true } sp-io = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/io" } sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/runtime" } diff --git a/frame/session/Cargo.toml b/frame/session/Cargo.toml index 90646041f9..eff2099f19 100644 --- a/frame/session/Cargo.toml +++ b/frame/session/Cargo.toml @@ -10,7 +10,7 @@ description = "FRAME sessions pallet" [dependencies] serde = { version = "1.0.101", optional = true } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/runtime" } sp-session = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/session" } diff --git a/frame/society/Cargo.toml b/frame/society/Cargo.toml index 11ac8b4912..27232b16ef 100644 --- a/frame/society/Cargo.toml +++ b/frame/society/Cargo.toml @@ -10,7 +10,7 @@ description = "FRAME society pallet" [dependencies] serde = { version = "1.0.101", optional = true } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-io ={ path = "../../primitives/io", default-features = false , version = "2.0.0-alpha.5"} sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/runtime" } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } diff --git a/frame/staking/Cargo.toml b/frame/staking/Cargo.toml index a3431c3eb4..c03b2d323b 100644 --- a/frame/staking/Cargo.toml +++ b/frame/staking/Cargo.toml @@ -10,7 +10,7 @@ description = "FRAME pallet staking" [dependencies] serde = { version = "1.0.101", optional = true } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } sp-phragmen = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/phragmen" } sp-io ={ path = "../../primitives/io", default-features = false , version = "2.0.0-alpha.5"} diff --git a/frame/staking/fuzz/Cargo.toml b/frame/staking/fuzz/Cargo.toml index 12fc919530..f39775aa8e 100644 --- a/frame/staking/fuzz/Cargo.toml +++ b/frame/staking/fuzz/Cargo.toml @@ -10,7 +10,7 @@ cargo-fuzz = true [dependencies] libfuzzer-sys = "0.3" -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } pallet-staking = { version = "2.0.0-alpha.2", path = "..", features = ["testing-utils"] } pallet-staking-reward-curve = { version = "2.0.0-alpha.2", path = "../reward-curve" } pallet-session = { version = "2.0.0-alpha.2", path = "../../session" } diff --git a/frame/sudo/Cargo.toml b/frame/sudo/Cargo.toml index c11d681013..63e034cc98 100644 --- a/frame/sudo/Cargo.toml +++ b/frame/sudo/Cargo.toml @@ -10,7 +10,7 @@ description = "FRAME pallet for sudo" [dependencies] serde = { version = "1.0.101", optional = true } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } sp-io = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/io" } sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/runtime" } diff --git a/frame/support/Cargo.toml b/frame/support/Cargo.toml index 67e47b0ad2..63165d6226 100644 --- a/frame/support/Cargo.toml +++ b/frame/support/Cargo.toml @@ -11,7 +11,7 @@ description = "Support code for the runtime." [dependencies] log = "0.4" serde = { version = "1.0.101", optional = true, features = ["derive"] } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } frame-metadata = { version = "11.0.0-alpha.5", default-features = false, path = "../metadata" } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } sp-io = { path = "../../primitives/io", default-features = false , version = "2.0.0-alpha.5"} diff --git a/frame/support/test/Cargo.toml b/frame/support/test/Cargo.toml index a1edf70f61..1632ff55c2 100644 --- a/frame/support/test/Cargo.toml +++ b/frame/support/test/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/paritytech/substrate/" [dependencies] serde = { version = "1.0.101", default-features = false, features = ["derive"] } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-io ={ path = "../../../primitives/io", default-features = false , version = "2.0.0-alpha.5"} sp-state-machine = { version = "0.8.0-alpha.5", optional = true, path = "../../../primitives/state-machine" } frame-support = { version = "2.0.0-alpha.5", default-features = false, path = "../" } diff --git a/frame/system/Cargo.toml b/frame/system/Cargo.toml index 9a16b50181..98681f6ad9 100644 --- a/frame/system/Cargo.toml +++ b/frame/system/Cargo.toml @@ -10,7 +10,7 @@ description = "FRAME system module" [dependencies] serde = { version = "1.0.101", optional = true, features = ["derive"] } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-core = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/core" } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } sp-io = { path = "../../primitives/io", default-features = false, version = "2.0.0-alpha.5"} diff --git a/frame/system/rpc/runtime-api/Cargo.toml b/frame/system/rpc/runtime-api/Cargo.toml index bdd1c3ad83..286a9b3af3 100644 --- a/frame/system/rpc/runtime-api/Cargo.toml +++ b/frame/system/rpc/runtime-api/Cargo.toml @@ -10,7 +10,7 @@ description = "Runtime API definition required by System RPC extensions." [dependencies] sp-api = { version = "2.0.0-alpha.5", default-features = false, path = "../../../../primitives/api" } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false } [features] default = ["std"] diff --git a/frame/timestamp/Cargo.toml b/frame/timestamp/Cargo.toml index 11b450cff0..ec5e673325 100644 --- a/frame/timestamp/Cargo.toml +++ b/frame/timestamp/Cargo.toml @@ -12,7 +12,7 @@ documentation = "https://docs.rs/pallet-timestamp" [dependencies] serde = { version = "1.0.101", optional = true } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } sp-io = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/io", optional = true } sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/runtime" } diff --git a/frame/treasury/Cargo.toml b/frame/treasury/Cargo.toml index 549dd90672..e2b94d504b 100644 --- a/frame/treasury/Cargo.toml +++ b/frame/treasury/Cargo.toml @@ -10,7 +10,7 @@ description = "FRAME pallet to manage treasury" [dependencies] serde = { version = "1.0.101", optional = true, features = ["derive"] } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/runtime" } frame-support = { version = "2.0.0-alpha.5", default-features = false, path = "../support" } diff --git a/frame/utility/Cargo.toml b/frame/utility/Cargo.toml index fb7bd00978..afdfce2421 100644 --- a/frame/utility/Cargo.toml +++ b/frame/utility/Cargo.toml @@ -10,7 +10,7 @@ description = "FRAME utilities pallet" [dependencies] serde = { version = "1.0.101", optional = true } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false } frame-support = { version = "2.0.0-alpha.5", default-features = false, path = "../support" } frame-system = { version = "2.0.0-alpha.5", default-features = false, path = "../system" } sp-core = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/core" } diff --git a/frame/vesting/Cargo.toml b/frame/vesting/Cargo.toml index e3c85d93f6..4629b058dd 100644 --- a/frame/vesting/Cargo.toml +++ b/frame/vesting/Cargo.toml @@ -10,7 +10,7 @@ description = "FRAME pallet for manage vesting" [dependencies] serde = { version = "1.0.101", optional = true } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } enumflags2 = { version = "0.6.2" } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/std" } sp-io = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/io" } diff --git a/primitives/api/proc-macro/src/decl_runtime_apis.rs b/primitives/api/proc-macro/src/decl_runtime_apis.rs index 8aae473f85..c0412eb71d 100644 --- a/primitives/api/proc-macro/src/decl_runtime_apis.rs +++ b/primitives/api/proc-macro/src/decl_runtime_apis.rs @@ -190,7 +190,8 @@ fn generate_native_call_generators(decl: &ItemTrait) -> Result { input: &I, error_desc: &'static str, ) -> std::result::Result { - ::decode( + ::decode_with_depth_limit( + #crate_::MAX_EXTRINSIC_DEPTH, &mut &#crate_::Encode::encode(input)[..], ).map_err(|e| format!("{} {}", error_desc, e.what())) } diff --git a/primitives/api/proc-macro/src/impl_runtime_apis.rs b/primitives/api/proc-macro/src/impl_runtime_apis.rs index 07d7ae4040..36d03f8443 100644 --- a/primitives/api/proc-macro/src/impl_runtime_apis.rs +++ b/primitives/api/proc-macro/src/impl_runtime_apis.rs @@ -81,7 +81,10 @@ fn generate_impl_call( Ok( quote!( #( - let #pnames : #ptypes = match #c_iter::Decode::decode(&mut #input) { + let #pnames : #ptypes = match #c_iter::DecodeLimit::decode_all_with_depth_limit( + #c_iter::MAX_EXTRINSIC_DEPTH, + &mut #input + ) { Ok(input) => input, Err(e) => panic!("Bad input data provided to {}: {}", #fn_name_str, e.what()), }; diff --git a/primitives/api/src/lib.rs b/primitives/api/src/lib.rs index 0901be5831..3e73009055 100644 --- a/primitives/api/src/lib.rs +++ b/primitives/api/src/lib.rs @@ -64,11 +64,14 @@ pub use sp_std::{slice, mem}; #[cfg(feature = "std")] use sp_std::result; #[doc(hidden)] -pub use codec::{Encode, Decode}; +pub use codec::{Encode, Decode, DecodeLimit}; use sp_core::OpaqueMetadata; #[cfg(feature = "std")] use std::{panic::UnwindSafe, cell::RefCell}; +/// Maximum nesting level for extrinsics. +pub const MAX_EXTRINSIC_DEPTH: u32 = 256; + /// Declares given traits as runtime apis. /// /// The macro will create two declarations, one for using on the client side and one for using diff --git a/primitives/application-crypto/Cargo.toml b/primitives/application-crypto/Cargo.toml index b0df978273..7641b73342 100644 --- a/primitives/application-crypto/Cargo.toml +++ b/primitives/application-crypto/Cargo.toml @@ -12,7 +12,7 @@ documentation = "https://docs.rs/sp-application-crypto" [dependencies] sp-core = { version = "2.0.0-alpha.5", default-features = false, path = "../core" } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } serde = { version = "1.0.101", optional = true, features = ["derive"] } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../std" } sp-io = { version = "2.0.0-alpha.5", default-features = false, path = "../../primitives/io" } diff --git a/primitives/authority-discovery/Cargo.toml b/primitives/authority-discovery/Cargo.toml index a6cea0c51c..75119203ca 100644 --- a/primitives/authority-discovery/Cargo.toml +++ b/primitives/authority-discovery/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/paritytech/substrate/" [dependencies] sp-application-crypto = { version = "2.0.0-alpha.5", default-features = false, path = "../application-crypto" } -codec = { package = "parity-scale-codec", default-features = false, version = "1.3.0" } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../std" } sp-api = { version = "2.0.0-alpha.5", default-features = false, path = "../api" } sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../runtime" } diff --git a/primitives/consensus/aura/Cargo.toml b/primitives/consensus/aura/Cargo.toml index fb29ac49b7..24dc9ef725 100644 --- a/primitives/consensus/aura/Cargo.toml +++ b/primitives/consensus/aura/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/paritytech/substrate/" [dependencies] sp-application-crypto = { version = "2.0.0-alpha.5", default-features = false, path = "../../application-crypto" } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../std" } sp-api = { version = "2.0.0-alpha.5", default-features = false, path = "../../api" } sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../../runtime" } diff --git a/primitives/consensus/babe/Cargo.toml b/primitives/consensus/babe/Cargo.toml index b64000de6d..d858969823 100644 --- a/primitives/consensus/babe/Cargo.toml +++ b/primitives/consensus/babe/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/paritytech/substrate/" [dependencies] sp-application-crypto = { version = "2.0.0-alpha.5", default-features = false, path = "../../application-crypto" } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false } merlin = { version = "2.0", default-features = false } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../std" } sp-api = { version = "2.0.0-alpha.5", default-features = false, path = "../../api" } diff --git a/primitives/consensus/common/Cargo.toml b/primitives/consensus/common/Cargo.toml index b3604363a6..6e8ce528eb 100644 --- a/primitives/consensus/common/Cargo.toml +++ b/primitives/consensus/common/Cargo.toml @@ -23,7 +23,7 @@ futures-diagnose = "1.0" sp-std = { version = "2.0.0-alpha.5", path = "../../std" } sp-version = { version = "2.0.0-alpha.5", path = "../../version" } sp-runtime = { version = "2.0.0-alpha.5", path = "../../runtime" } -codec = { package = "parity-scale-codec", version = "1.3.0", features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", features = ["derive"] } parking_lot = "0.10.0" serde = { version = "1.0", features = ["derive"] } prometheus-endpoint = { package = "substrate-prometheus-endpoint", path = "../../../utils/prometheus", version = "0.8.0-alpha.5"} diff --git a/primitives/consensus/pow/Cargo.toml b/primitives/consensus/pow/Cargo.toml index 14232a506b..98b0466871 100644 --- a/primitives/consensus/pow/Cargo.toml +++ b/primitives/consensus/pow/Cargo.toml @@ -13,7 +13,7 @@ sp-api = { version = "2.0.0-alpha.5", default-features = false, path = "../../ap sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../../std" } sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../../runtime" } sp-core = { version = "2.0.0-alpha.5", default-features = false, path = "../../core" } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } [features] default = ["std"] diff --git a/primitives/consensus/slots/Cargo.toml b/primitives/consensus/slots/Cargo.toml index bb1e76baa7..a6522ec0d6 100644 --- a/primitives/consensus/slots/Cargo.toml +++ b/primitives/consensus/slots/Cargo.toml @@ -12,7 +12,7 @@ repository = "https://github.com/paritytech/substrate/" targets = ["x86_64-unknown-linux-gnu"] [dependencies] -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../../runtime" } [features] diff --git a/primitives/finality-grandpa/Cargo.toml b/primitives/finality-grandpa/Cargo.toml index 17219d9d10..f5424e15fc 100644 --- a/primitives/finality-grandpa/Cargo.toml +++ b/primitives/finality-grandpa/Cargo.toml @@ -12,7 +12,7 @@ documentation = "https://docs.rs/sp-finality-grandpa" [dependencies] sp-application-crypto = { version = "2.0.0-alpha.5", default-features = false, path = "../application-crypto" } -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../std" } serde = { version = "1.0.101", optional = true, features = ["derive"] } sp-api = { version = "2.0.0-alpha.5", default-features = false, path = "../api" } diff --git a/primitives/session/Cargo.toml b/primitives/session/Cargo.toml index 2386c5fcf5..e362382fb8 100644 --- a/primitives/session/Cargo.toml +++ b/primitives/session/Cargo.toml @@ -9,7 +9,7 @@ repository = "https://github.com/paritytech/substrate/" description = "Primitives for sessions" [dependencies] -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } sp-api = { version = "2.0.0-alpha.5", default-features = false, path = "../api" } sp-core = { version = "2.0.0-alpha.5", default-features = false, path = "../core" } sp-std = { version = "2.0.0-alpha.5", default-features = false, path = "../std" } diff --git a/prml/consortium-permission/Cargo.toml b/prml/consortium-permission/Cargo.toml index 125c3c9f37..5da9e4ec4b 100644 --- a/prml/consortium-permission/Cargo.toml +++ b/prml/consortium-permission/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Centrality Developers "] edition = "2018" [dependencies] -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } serde = { version = "1.0.101", optional = true } frame-support = { default-features = false, path = "../../frame/support" } frame-system = { default-features = false, path = "../../frame/system" } diff --git a/prml/validator-manager/Cargo.toml b/prml/validator-manager/Cargo.toml index 3293543f4d..84477cd04e 100644 --- a/prml/validator-manager/Cargo.toml +++ b/prml/validator-manager/Cargo.toml @@ -5,7 +5,7 @@ authors = ["Centrality Developers "] edition = "2018" [dependencies] -codec = { package = "parity-scale-codec", version = "1.3.0", default-features = false, features = ["derive"] } +codec = { package = "parity-scale-codec", version = "1.3.5", default-features = false, features = ["derive"] } serde = { version = "1.0.101", optional = true } frame-support = { default-features = false, path = "../../frame/support" } frame-system = { default-features = false, path = "../../frame/system" } From 01732a5eb1bd972357884338efab6a3be4ac904a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Fri, 12 Jun 2020 00:46:30 +0200 Subject: [PATCH 05/10] Adds support for storage parameter types (#6296) * Adds support for storage parameter types This pr adds a new parameter types type, the storage parameter types. This parameter type supports loading the value from the storage or returning the given default value. * Use twox_128 * Update docs * Update frame/support/src/lib.rs Co-authored-by: Alexander Popiak Co-authored-by: Alexander Popiak --- frame/support/src/lib.rs | 151 +++++++++++++++++++++++++++++++++--- frame/support/src/traits.rs | 6 +- 2 files changed, 145 insertions(+), 12 deletions(-) diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index 58f4e279ed..7988582c82 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -42,7 +42,7 @@ pub use paste; #[doc(hidden)] pub use sp_state_machine::BasicExternalities; #[doc(hidden)] -pub use sp_io::storage::root as storage_root; +pub use sp_io::{storage::root as storage_root, self}; #[doc(hidden)] pub use sp_runtime::RuntimeDebug; @@ -79,19 +79,65 @@ pub use self::storage::{ pub use self::dispatch::{Parameter, Callable, IsSubType}; pub use sp_runtime::{self, ConsensusEngineId, print, traits::Printable}; -/// Macro for easily creating a new implementation of the `Get` trait. Use similarly to -/// how you would declare a `const`: +/// A type that cannot be instantiated. +#[derive(Debug)] +pub enum Never {} + +/// Create new implementations of the [`Get`](crate::traits::Get) trait. +/// +/// The so-called parameter type can be created in three different ways: +/// +/// - Using `const` to create a parameter type that provides a `const` getter. +/// It is required that the `value` is const. +/// +/// - Declare the parameter type without `const` to have more freedom when creating the value. +/// +/// - Using `storage` to create a storage parameter type. This type is special as it tries to +/// load the value from the storage under a fixed key. If the value could not be found in the +/// storage, the given default value will be returned. It is required that the value implements +/// [`Encode`](codec::Encode) and [`Decode`](codec::Decode). The key for looking up the value +/// in the storage is built using the following formula: +/// +/// `twox_128(":" ++ NAME ++ ":")` where `NAME` is the name that is passed as type name. +/// +/// # Examples +/// +/// ``` +/// # use frame_support::traits::Get; +/// # use frame_support::parameter_types; +/// // This function cannot be used in a const context. +/// fn non_const_expression() -> u64 { 99 } /// /// ```no_compile /// parameter_types! { -/// pub const Argument: u64 = 42; +/// pub const Argument: u64 = 42 + FIXED_VALUE; +/// /// Visibility of the type is optional +/// OtherArgument: u64 = non_const_expression(); +/// pub storage StorageArgument: u64 = 5; /// } /// trait Config { -/// type Parameter: Get; +/// type Parameter: Get; +/// type OtherParameter: Get; +/// type StorageParameter: Get; /// } /// struct Runtime; /// impl Config for Runtime { -/// type Parameter = Argument; +/// type Parameter = Argument; +/// type OtherParameter = OtherArgument; +/// type StorageParameter = StorageArgument; +/// } +/// ``` +/// +/// # Invalid example: +/// +/// ```compile_fail +/// # use frame_support::traits::Get; +/// # use frame_support::parameter_types; +/// // This function cannot be used in a const context. +/// fn non_const_expression() -> u64 { 99 } +/// +/// parameter_types! { +/// pub const Argument: u64 = non_const_expression(); /// } /// ``` #[macro_export] @@ -103,21 +149,89 @@ macro_rules! parameter_types { ) => ( $( #[ $attr ] )* $vis struct $name; - $crate::parameter_types!{IMPL $name , $type , $value} - $crate::parameter_types!{ $( $rest )* } + $crate::parameter_types!(IMPL_CONST $name , $type , $value); + $crate::parameter_types!( $( $rest )* ); + ); + ( + $( #[ $attr:meta ] )* + $vis:vis $name:ident: $type:ty = $value:expr; + $( $rest:tt )* + ) => ( + $( #[ $attr ] )* + $vis struct $name; + $crate::parameter_types!(IMPL $name, $type, $value); + $crate::parameter_types!( $( $rest )* ); + ); + ( + $( #[ $attr:meta ] )* + $vis:vis storage $name:ident: $type:ty = $value:expr; + $( $rest:tt )* + ) => ( + $( #[ $attr ] )* + $vis struct $name; + $crate::parameter_types!(IMPL_STORAGE $name, $type, $value); + $crate::parameter_types!( $( $rest )* ); ); () => (); - (IMPL $name:ident , $type:ty , $value:expr) => { + (IMPL_CONST $name:ident, $type:ty, $value:expr) => { + impl $name { + /// Returns the value of this parameter type. + pub const fn get() -> $type { + $value + } + } + + impl> $crate::traits::Get for $name { + fn get() -> I { + I::from($value) + } + } + }; + (IMPL $name:ident, $type:ty, $value:expr) => { impl $name { + /// Returns the value of this parameter type. pub fn get() -> $type { $value } } + impl> $crate::traits::Get for $name { fn get() -> I { I::from($value) } } + }; + (IMPL_STORAGE $name:ident, $type:ty, $value:expr) => { + impl $name { + /// Returns the key for this parameter type. + pub fn key() -> [u8; 16] { + $crate::sp_io::hashing::twox_128( + concat!(":", stringify!($name), ":").as_bytes() + ) + } + + /// Set the value of this parameter type in the storage. + /// + /// This needs to be executed in an externalities provided + /// environment. + pub fn set(value: &$type) { + $crate::storage::unhashed::put(&Self::key(), value); + } + + /// Returns the value of this parameter type. + /// + /// This needs to be executed in an externalities provided + /// environment. + pub fn get() -> $type { + $crate::storage::unhashed::get(&Self::key()).unwrap_or_else(|| $value) + } + } + + impl> $crate::traits::Get for $name { + fn get() -> I { + I::from(Self::get()) + } + } } } @@ -231,6 +345,7 @@ mod tests { StorageEntryModifier, DefaultByteGetter, StorageHasher, }; use sp_std::marker::PhantomData; + use sp_io::TestExternalities; pub trait Trait { type BlockNumber: Codec + EncodeLike + Default; @@ -278,7 +393,7 @@ mod tests { type Origin = u32; } - fn new_test_ext() -> sp_io::TestExternalities { + fn new_test_ext() -> TestExternalities { GenesisConfig::default().build_storage().unwrap().into() } @@ -622,4 +737,20 @@ mod tests { let metadata = Module::::storage_metadata(); pretty_assertions::assert_eq!(EXPECTED_METADATA, metadata); } + + parameter_types! { + storage StorageParameter: u64 = 10; + } + + #[test] + fn check_storage_parameter_type_works() { + TestExternalities::default().execute_with(|| { + assert_eq!(sp_io::hashing::twox_128(b":StorageParameter:"), StorageParameter::key()); + + assert_eq!(10, StorageParameter::get()); + + StorageParameter::set(&300); + assert_eq!(300, StorageParameter::get()); + }) + } } diff --git a/frame/support/src/traits.rs b/frame/support/src/traits.rs index 0b4661c4c1..53a25700b8 100644 --- a/frame/support/src/traits.rs +++ b/frame/support/src/traits.rs @@ -69,9 +69,11 @@ impl Len for T where ::IntoIter: Ex } } -/// A trait for querying a single fixed value from a type. +/// A trait for querying a single value from a type. +/// +/// It is not required that the value is constant. pub trait Get { - /// Return a constant value. + /// Return the current value. fn get() -> T; } From 9487648df7be64d993507a2a91b8ae959b83f425 Mon Sep 17 00:00:00 2001 From: Guillaume Thiolliere Date: Wed, 5 Aug 2020 13:37:01 +0200 Subject: [PATCH 06/10] Remove generation of instance trait by decl_storage. (#6812) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * remove generation of instance trait, no breaking change * doc * doc * Update frame/support/src/traits.rs Co-authored-by: Bastian Köcher * Update frame/support/procedural/src/storage/instance_trait.rs Co-authored-by: Bastian Köcher --- .../src/storage/genesis_config/mod.rs | 9 ++-- .../procedural/src/storage/instance_trait.rs | 42 +++++++++---------- frame/support/procedural/src/storage/parse.rs | 11 ++++- .../procedural/src/storage/storage_struct.rs | 10 ++--- frame/support/src/traits.rs | 11 +++++ frame/support/test/tests/final_keys.rs | 4 +- frame/support/test/tests/instance.rs | 7 ++-- 7 files changed, 54 insertions(+), 40 deletions(-) diff --git a/frame/support/procedural/src/storage/genesis_config/mod.rs b/frame/support/procedural/src/storage/genesis_config/mod.rs index eeeca150d9..af9e0e34c3 100644 --- a/frame/support/procedural/src/storage/genesis_config/mod.rs +++ b/frame/support/procedural/src/storage/genesis_config/mod.rs @@ -19,7 +19,7 @@ use proc_macro2::{TokenStream, Span}; use quote::quote; -use super::{DeclStorageDefExt, instance_trait::DEFAULT_INSTANTIABLE_TRAIT_NAME}; +use super::DeclStorageDefExt; use genesis_config_def::GenesisConfigDef; use builder_def::BuilderDef; @@ -103,10 +103,9 @@ fn impl_build_storage( let name = syn::Ident::new(DEFAULT_INSTANCE_NAME, Span::call_site()); quote!( #name ) }); - let inherent_instance_bound = def.optional_instance_bound.clone().unwrap_or_else(|| { - let bound = syn::Ident::new(DEFAULT_INSTANTIABLE_TRAIT_NAME, Span::call_site()); - quote!( #inherent_instance: #bound ) - }); + let inherent_instance_bound = quote!( + #inherent_instance: #scrate::traits::Instance + ); let build_storage_impl = quote!( <#runtime_generic: #runtime_trait, #inherent_instance_bound> diff --git a/frame/support/procedural/src/storage/instance_trait.rs b/frame/support/procedural/src/storage/instance_trait.rs index b2f0ad9c06..9899da5382 100644 --- a/frame/support/procedural/src/storage/instance_trait.rs +++ b/frame/support/procedural/src/storage/instance_trait.rs @@ -23,7 +23,6 @@ use super::DeclStorageDefExt; const NUMBER_OF_INSTANCE: usize = 16; pub(crate) const INHERENT_INSTANCE_NAME: &str = "__InherentHiddenInstance"; -pub(crate) const DEFAULT_INSTANTIABLE_TRAIT_NAME: &str = "__GeneratedInstantiable"; // Used to generate an instance implementation. struct InstanceDef { @@ -35,7 +34,7 @@ struct InstanceDef { pub fn decl_and_impl(scrate: &TokenStream, def: &DeclStorageDefExt) -> TokenStream { let mut impls = TokenStream::new(); - impls.extend(create_instance_trait(def)); + impls.extend(reexport_instance_trait(scrate, def)); // Implementation of instances. if let Some(module_instance) = &def.module_instance { @@ -69,6 +68,8 @@ pub fn decl_and_impl(scrate: &TokenStream, def: &DeclStorageDefExt) -> TokenStre .and_then(|i| i.instance_default.as_ref()) { impls.extend(quote! { + /// Hidden instance generated to be internally used when module is used without + /// instance. #[doc(hidden)] pub type #inherent_instance = #default_instance; }); @@ -76,7 +77,11 @@ pub fn decl_and_impl(scrate: &TokenStream, def: &DeclStorageDefExt) -> TokenStre let instance_def = InstanceDef { prefix: String::new(), instance_struct: inherent_instance, - doc: quote!(#[doc(hidden)]), + doc: quote!( + /// Hidden instance generated to be internally used when module is used without + /// instance. + #[doc(hidden)] + ), }; impls.extend(create_and_impl_instance_struct(scrate, &instance_def, def)); } @@ -84,27 +89,19 @@ pub fn decl_and_impl(scrate: &TokenStream, def: &DeclStorageDefExt) -> TokenStre impls } -fn create_instance_trait( +fn reexport_instance_trait( + scrate: &TokenStream, def: &DeclStorageDefExt, ) -> TokenStream { - let instance_trait = def.module_instance.as_ref().map(|i| i.instance_trait.clone()) - .unwrap_or_else(|| syn::Ident::new(DEFAULT_INSTANTIABLE_TRAIT_NAME, Span::call_site())); - - let optional_hide = if def.module_instance.is_some() { - quote!() + if let Some(i) = def.module_instance.as_ref() { + let instance_trait = &i.instance_trait; + quote!( + /// Local import of frame_support::traits::Instance + // This import is not strictly needed but made in order not to have breaking change. + use #scrate::traits::Instance as #instance_trait; + ) } else { - quote!(#[doc(hidden)]) - }; - - quote! { - /// Tag a type as an instance of a module. - /// - /// Defines storage prefixes, they must be unique. - #optional_hide - pub trait #instance_trait: 'static { - /// The prefix used by any storage entry of an instance. - const PREFIX: &'static str; - } + quote!() } } @@ -113,8 +110,7 @@ fn create_and_impl_instance_struct( instance_def: &InstanceDef, def: &DeclStorageDefExt, ) -> TokenStream { - let instance_trait = def.module_instance.as_ref().map(|i| i.instance_trait.clone()) - .unwrap_or_else(|| syn::Ident::new(DEFAULT_INSTANTIABLE_TRAIT_NAME, Span::call_site())); + let instance_trait = quote!( #scrate::traits::Instance ); let instance_struct = &instance_def.instance_struct; let prefix = format!("{}{}", instance_def.prefix, def.crate_name.to_string()); diff --git a/frame/support/procedural/src/storage/parse.rs b/frame/support/procedural/src/storage/parse.rs index af568c78cc..32b065483a 100644 --- a/frame/support/procedural/src/storage/parse.rs +++ b/frame/support/procedural/src/storage/parse.rs @@ -323,7 +323,16 @@ fn get_module_instance( instantiable: Option, default_instance: Option, ) -> syn::Result> { - let right_syntax = "Should be $Instance: $Instantiable = $DefaultInstance"; + let right_syntax = "Should be $I: $Instance = $DefaultInstance"; + + if instantiable.as_ref().map_or(false, |i| i != "Instance") { + let msg = format!( + "Instance trait must be named `Instance`, other names are no longer supported, because \ + it is now defined at frame_support::traits::Instance. Expect `Instance` found `{}`", + instantiable.as_ref().unwrap(), + ); + return Err(syn::Error::new(instantiable.span(), msg)); + } match (instance, instantiable, default_instance) { (Some(instance), Some(instantiable), default_instance) => { diff --git a/frame/support/procedural/src/storage/storage_struct.rs b/frame/support/procedural/src/storage/storage_struct.rs index cbd477354e..89c6b6e262 100644 --- a/frame/support/procedural/src/storage/storage_struct.rs +++ b/frame/support/procedural/src/storage/storage_struct.rs @@ -102,7 +102,7 @@ pub fn decl_and_impl(scrate: &TokenStream, def: &DeclStorageDefExt) -> TokenStre type Query = #query_type; fn module_prefix() -> &'static [u8] { - #instance_or_inherent::PREFIX.as_bytes() + <#instance_or_inherent as #scrate::traits::Instance>::PREFIX.as_bytes() } fn storage_prefix() -> &'static [u8] { @@ -126,7 +126,7 @@ pub fn decl_and_impl(scrate: &TokenStream, def: &DeclStorageDefExt) -> TokenStre for #storage_struct #optional_storage_where_clause { fn module_prefix() -> &'static [u8] { - #instance_or_inherent::PREFIX.as_bytes() + <#instance_or_inherent as #scrate::traits::Instance>::PREFIX.as_bytes() } fn storage_prefix() -> &'static [u8] { @@ -141,7 +141,7 @@ pub fn decl_and_impl(scrate: &TokenStream, def: &DeclStorageDefExt) -> TokenStre type Hasher = #scrate::#hasher; fn module_prefix() -> &'static [u8] { - #instance_or_inherent::PREFIX.as_bytes() + <#instance_or_inherent as #scrate::traits::Instance>::PREFIX.as_bytes() } fn storage_prefix() -> &'static [u8] { @@ -166,7 +166,7 @@ pub fn decl_and_impl(scrate: &TokenStream, def: &DeclStorageDefExt) -> TokenStre for #storage_struct #optional_storage_where_clause { fn module_prefix() -> &'static [u8] { - #instance_or_inherent::PREFIX.as_bytes() + <#instance_or_inherent as #scrate::traits::Instance>::PREFIX.as_bytes() } fn storage_prefix() -> &'static [u8] { @@ -184,7 +184,7 @@ pub fn decl_and_impl(scrate: &TokenStream, def: &DeclStorageDefExt) -> TokenStre type Hasher2 = #scrate::#hasher2; fn module_prefix() -> &'static [u8] { - #instance_or_inherent::PREFIX.as_bytes() + <#instance_or_inherent as #scrate::traits::Instance>::PREFIX.as_bytes() } fn storage_prefix() -> &'static [u8] { diff --git a/frame/support/src/traits.rs b/frame/support/src/traits.rs index 53a25700b8..02b1d004f4 100644 --- a/frame/support/src/traits.rs +++ b/frame/support/src/traits.rs @@ -1079,6 +1079,17 @@ pub trait OffchainWorker { fn offchain_worker(_n: BlockNumber) {} } +/// An instance of a pallet in the storage. +/// +/// It is required that these instances are unique, to support multiple instances per pallet in the same runtime! +/// +/// E.g. for module MyModule default instance will have prefix "MyModule" and other instances +/// "InstanceNMyModule". +pub trait Instance: 'static { + /// Unique module prefix. E.g. "InstanceNMyModule" or "MyModule" + const PREFIX: &'static str ; +} + #[cfg(test)] mod tests { use super::*; diff --git a/frame/support/test/tests/final_keys.rs b/frame/support/test/tests/final_keys.rs index ae23c5a64c..a1ae91f42d 100644 --- a/frame/support/test/tests/final_keys.rs +++ b/frame/support/test/tests/final_keys.rs @@ -52,12 +52,12 @@ mod instance { pub trait Trait: super::no_instance::Trait {} frame_support::decl_module! { - pub struct Module, I: Instantiable = DefaultInstance> + pub struct Module, I: Instance = DefaultInstance> for enum Call where origin: T::Origin {} } frame_support::decl_storage!{ - trait Store for Module, I: Instantiable = DefaultInstance> + trait Store for Module, I: Instance = DefaultInstance> as FinalKeysSome { pub Value config(value): u32; diff --git a/frame/support/test/tests/instance.rs b/frame/support/test/tests/instance.rs index ae735c9896..1c4cb5c818 100644 --- a/frame/support/test/tests/instance.rs +++ b/frame/support/test/tests/instance.rs @@ -34,7 +34,6 @@ pub trait Currency {} // Test for: // * No default instance -// * Custom InstantiableTrait // * Origin, Inherent, Event mod module1 { use super::*; @@ -47,7 +46,7 @@ mod module1 { } frame_support::decl_module! { - pub struct Module, I: InstantiableThing> for enum Call where + pub struct Module, I: Instance> for enum Call where origin: ::Origin, ::BlockNumber: From { @@ -63,7 +62,7 @@ mod module1 { } frame_support::decl_storage! { - trait Store for Module, I: InstantiableThing> as Module1 where + trait Store for Module, I: Instance> as Module1 where T::BlockNumber: From + std::fmt::Display { pub Value config(value): T::GenericType; @@ -93,7 +92,7 @@ mod module1 { pub const INHERENT_IDENTIFIER: InherentIdentifier = *b"12345678"; - impl, I: InstantiableThing> ProvideInherent for Module where + impl, I: Instance> ProvideInherent for Module where T::BlockNumber: From { type Call = Call; From 4fc254710fe671c98588980cb57506d190cf5798 Mon Sep 17 00:00:00 2001 From: Jordan Beauchamp Date: Mon, 14 Sep 2020 13:42:07 +1200 Subject: [PATCH 07/10] graft trie root order delta: 64543a3 --- primitives/trie/src/lib.rs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/primitives/trie/src/lib.rs b/primitives/trie/src/lib.rs index 00fb6a9211..989186a707 100644 --- a/primitives/trie/src/lib.rs +++ b/primitives/trie/src/lib.rs @@ -177,6 +177,9 @@ pub fn delta_trie_root( { let mut trie = TrieDBMut::::from_existing(&mut *db, &mut root)?; + let mut delta = delta.into_iter().collect::>(); + delta.sort_by(|l, r| l.0.borrow().cmp(r.0.borrow())); + for (key, change) in delta { match change { Some(val) => trie.insert(key.as_ref(), val.as_ref())?, @@ -253,19 +256,12 @@ pub fn child_delta_trie_root( // root is fetched from DB, not writable by runtime, so it's always valid. root.as_mut().copy_from_slice(root_data.as_ref()); - { - let mut db = KeySpacedDBMut::new(&mut *db, keyspace); - let mut trie = TrieDBMut::::from_existing(&mut db, &mut root)?; - - for (key, change) in delta { - match change { - Some(val) => trie.insert(key.as_ref(), val.as_ref())?, - None => trie.remove(key.as_ref())?, - }; - } - } - - Ok(root) + let mut db = KeySpacedDBMut::new(&mut *db, keyspace); + delta_trie_root::( + &mut db, + root, + delta, + ) } /// Call `f` for all keys in a child trie. From a10d4548fd97a7b64e93d068d5430060794edae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 23 Jun 2020 13:46:16 +0200 Subject: [PATCH 08/10] Fix `sp-api` handling of multiple arguments (#6484) With the switch to `decode_all_with_depth_limit` we silently broken support for functions with multiple arguments. The old generated code tried to decode each parameter separately, which does not play well with `decode_all`. This pr adds a test to ensure that this does not happen again and fixes the bug by decoding everything at once by wrapping it into tuples. --- .../api/proc-macro/src/impl_runtime_apis.rs | 19 ++++++++----------- primitives/api/test/tests/runtime_calls.rs | 11 +++++++++++ test-utils/runtime/src/lib.rs | 16 ++++++++++++++++ 3 files changed, 35 insertions(+), 11 deletions(-) diff --git a/primitives/api/proc-macro/src/impl_runtime_apis.rs b/primitives/api/proc-macro/src/impl_runtime_apis.rs index 36d03f8443..7b1b39e574 100644 --- a/primitives/api/proc-macro/src/impl_runtime_apis.rs +++ b/primitives/api/proc-macro/src/impl_runtime_apis.rs @@ -32,7 +32,7 @@ use syn::{ fold::{self, Fold}, parse_quote, }; -use std::{collections::HashSet, iter}; +use std::collections::HashSet; /// Unique identifier used to make the hidden includes unique for this macro. const HIDDEN_INCLUDES_ID: &str = "IMPL_RUNTIME_APIS"; @@ -69,10 +69,8 @@ fn generate_impl_call( let params = extract_parameter_names_types_and_borrows(signature)?; let c = generate_crate_access(HIDDEN_INCLUDES_ID); - let c_iter = iter::repeat(&c); let fn_name = &signature.ident; - let fn_name_str = iter::repeat(fn_name.to_string()); - let input = iter::repeat(input); + let fn_name_str = fn_name.to_string(); let pnames = params.iter().map(|v| &v.0); let pnames2 = params.iter().map(|v| &v.0); let ptypes = params.iter().map(|v| &v.1); @@ -80,15 +78,14 @@ fn generate_impl_call( Ok( quote!( - #( - let #pnames : #ptypes = match #c_iter::DecodeLimit::decode_all_with_depth_limit( - #c_iter::MAX_EXTRINSIC_DEPTH, - &mut #input + let (#( #pnames ),*) : ( #( #ptypes ),* ) = + match #c::DecodeLimit::decode_all_with_depth_limit( + #c::MAX_EXTRINSIC_DEPTH, + &mut #input, ) { - Ok(input) => input, + Ok(res) => res, Err(e) => panic!("Bad input data provided to {}: {}", #fn_name_str, e.what()), }; - )* #[allow(deprecated)] <#runtime as #impl_trait>::#fn_name(#( #pborrow #pnames2 ),*) @@ -177,7 +174,7 @@ fn generate_impl_calls( /// Generate the dispatch function that is used in native to call into the runtime. fn generate_dispatch_function(impls: &[ItemImpl]) -> Result { - let data = Ident::new("data", Span::call_site()); + let data = Ident::new("__sp_api__input_data", Span::call_site()); let c = generate_crate_access(HIDDEN_INCLUDES_ID); let impl_calls = generate_impl_calls(impls, &data)? .into_iter() diff --git a/primitives/api/test/tests/runtime_calls.rs b/primitives/api/test/tests/runtime_calls.rs index a907ac8095..3d8635e8b8 100644 --- a/primitives/api/test/tests/runtime_calls.rs +++ b/primitives/api/test/tests/runtime_calls.rs @@ -206,3 +206,14 @@ fn record_proof_works() { &runtime_code, ).expect("Executes block while using the proof backend"); } + +#[test] +fn call_runtime_api_with_multiple_arguments() { + let client = TestClientBuilder::new().set_execution_strategy(ExecutionStrategy::Both).build(); + + let data = vec![1, 2, 4, 5, 6, 7, 8, 8, 10, 12]; + let block_id = BlockId::Number(client.chain_info().best_number); + client.runtime_api() + .test_multiple_arguments(&block_id, data.clone(), data.clone(), data.len() as u32) + .unwrap(); +} diff --git a/test-utils/runtime/src/lib.rs b/test-utils/runtime/src/lib.rs index 6b2db82734..1bf5d7c802 100644 --- a/test-utils/runtime/src/lib.rs +++ b/test-utils/runtime/src/lib.rs @@ -311,6 +311,9 @@ cfg_if! { fn test_sr25519_crypto() -> (sr25519::AppSignature, sr25519::AppPublic); /// Run various tests against storage. fn test_storage(); + /// Test that ensures that we can call a function that takes multiple + /// arguments. + fn test_multiple_arguments(data: Vec, other: Vec, num: u32); } } } else { @@ -353,6 +356,9 @@ cfg_if! { fn test_sr25519_crypto() -> (sr25519::AppSignature, sr25519::AppPublic); /// Run various tests against storage. fn test_storage(); + /// Test that ensures that we can call a function that takes multiple + /// arguments. + fn test_multiple_arguments(data: Vec, other: Vec, num: u32); } } } @@ -632,6 +638,11 @@ cfg_if! { test_read_storage(); test_read_child_storage(); } + + fn test_multiple_arguments(data: Vec, other: Vec, num: u32) { + assert_eq!(&data[..], &other[..]); + assert_eq!(data.len(), num as usize); + } } impl sp_consensus_aura::AuraApi for Runtime { @@ -842,6 +853,11 @@ cfg_if! { test_read_storage(); test_read_child_storage(); } + + fn test_multiple_arguments(data: Vec, other: Vec, num: u32) { + assert_eq!(&data[..], &other[..]); + assert_eq!(data.len(), num as usize); + } } impl sp_consensus_aura::AuraApi for Runtime { From b2c01ddf7c5b7d8e3b60ae96b3881fb2311f5472 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20K=C3=B6cher?= Date: Tue, 30 Jun 2020 11:02:46 +0200 Subject: [PATCH 09/10] Fix tx-pool returning the same transaction multiple times (#6535) * Fix tx-pool returning the same transaction multiple times This fixes a bug that lead to returning the same transaction multiple times when iterating the `ready` iterator. Internally the transaction was kept in the `best` list and could be duplicated in that list be re-inserting it again. This `best` list is using a `TransactionRef` which internally uses a `insertion_id`. This `insertion_id` could lead to the same transaction being inserted multiple times into the `best` list. * Update client/transaction-pool/src/testing/pool.rs Co-authored-by: Nikolay Volf Co-authored-by: Nikolay Volf --- client/transaction-pool/src/testing/pool.rs | 22 +---------------- .../runtime/transaction-pool/src/lib.rs | 24 ------------------- 2 files changed, 1 insertion(+), 45 deletions(-) diff --git a/client/transaction-pool/src/testing/pool.rs b/client/transaction-pool/src/testing/pool.rs index 819fe83882..29d07debca 100644 --- a/client/transaction-pool/src/testing/pool.rs +++ b/client/transaction-pool/src/testing/pool.rs @@ -1002,7 +1002,7 @@ fn pruning_a_transaction_should_remove_it_from_best_transaction() { let xt1 = Extrinsic::IncludeData(Vec::new()); block_on(pool.submit_one(&BlockId::number(0), SOURCE, xt1.clone())).expect("1. Imported"); - let header = pool.api.push_block(1, vec![xt1.clone()], true); + let header = pool.api.push_block(1, vec![xt1.clone()]); // This will prune `xt1`. block_on(pool.maintain(block_event(header))); @@ -1018,23 +1018,3 @@ fn pruning_a_transaction_should_remove_it_from_best_transaction() { // returned a second time by the iterator. assert!(iterator.next().is_none()); } - -#[test] -fn only_revalidate_on_best_block() { - let xt = uxt(Alice, 209); - - let (pool, _guard, mut notifier) = maintained_pool(); - - block_on(pool.submit_one(&BlockId::number(0), SOURCE, xt.clone())).expect("1. Imported"); - assert_eq!(pool.status().ready, 1); - - let header = pool.api.push_block(1, vec![], true); - - pool.api.push_block(2, vec![], false); - pool.api.push_block(2, vec![], false); - - block_on(pool.maintain(block_event(header))); - block_on(notifier.next()); - - assert_eq!(pool.status().ready, 1); -} diff --git a/test-utils/runtime/transaction-pool/src/lib.rs b/test-utils/runtime/transaction-pool/src/lib.rs index f772ba9b02..6b5d8b6fab 100644 --- a/test-utils/runtime/transaction-pool/src/lib.rs +++ b/test-utils/runtime/transaction-pool/src/lib.rs @@ -240,30 +240,6 @@ impl sc_transaction_graph::ChainApi for TestApi { ) -> Self::ValidationFuture { self.validation_requests.write().push(uxt.clone()); - match self.block_id_to_number(at) { - Ok(Some(number)) => { - let found_best = self.chain - .read() - .block_by_number - .get(&number) - .map(|blocks| blocks.iter().any(|b| b.1.is_best())) - .unwrap_or(false); - - // If there is no best block, we don't know based on which block we should validate - // the transaction. (This is not required for this test function, but in real - // environment it would fail because of this). - if !found_best { - return ready(Ok( - Err(TransactionValidityError::Invalid(InvalidTransaction::Custom(1)).into()) - )) - } - }, - Ok(None) => return ready(Ok( - Err(TransactionValidityError::Invalid(InvalidTransaction::Custom(2)).into()) - )), - Err(e) => return ready(Err(e)), - } - let (requires, provides) = if let Some(transfer) = uxt.try_transfer() { let chain_nonce = self.chain.read().nonces.get(&transfer.from).cloned().unwrap_or(0); let requires = if chain_nonce == transfer.nonce { From e9ed13eebb744cab04fb850af05843568c864078 Mon Sep 17 00:00:00 2001 From: Jordan Beauchamp Date: Sat, 26 Sep 2020 09:54:36 +1200 Subject: [PATCH 10/10] Merge/test fix --- Cargo.lock | 3 +- client/transaction-pool/src/testing/pool.rs | 2 +- frame/support/src/lib.rs | 3 +- frame/support/test/Cargo.toml | 5 +- frame/system/src/lib.rs | 2 +- primitives/arithmetic/src/per_things.rs | 36 ++++++++++- primitives/phragmen/src/lib.rs | 4 ++ primitives/phragmen/src/tests.rs | 60 +++++++++++++++++++ primitives/trie/src/lib.rs | 35 ++++++++++- primitives/trie/test-res/invalid-delta-order | Bin 0 -> 3476 bytes primitives/trie/test-res/proof | Bin 0 -> 4680 bytes primitives/trie/test-res/storage_root | 1 + primitives/trie/test-res/valid-delta-order | Bin 0 -> 3476 bytes 13 files changed, 140 insertions(+), 11 deletions(-) create mode 100644 primitives/trie/test-res/invalid-delta-order create mode 100644 primitives/trie/test-res/proof create mode 100644 primitives/trie/test-res/storage_root create mode 100644 primitives/trie/test-res/valid-delta-order diff --git a/Cargo.lock b/Cargo.lock index 8e04967ecc..d7aa360980 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1589,6 +1589,7 @@ dependencies = [ name = "frame-support-test" version = "2.0.0-dev" dependencies = [ + "ed25519-dalek", "frame-support", "parity-scale-codec", "pretty_assertions", @@ -8880,7 +8881,7 @@ version = "1.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3bfd5b7557925ce778ff9b9ef90e3ade34c524b5ff10e239c69a42d546d2af56" dependencies = [ - "rand 0.7.3", + "rand 0.3.23", ] [[package]] diff --git a/client/transaction-pool/src/testing/pool.rs b/client/transaction-pool/src/testing/pool.rs index 29d07debca..ba00b222d8 100644 --- a/client/transaction-pool/src/testing/pool.rs +++ b/client/transaction-pool/src/testing/pool.rs @@ -1002,7 +1002,7 @@ fn pruning_a_transaction_should_remove_it_from_best_transaction() { let xt1 = Extrinsic::IncludeData(Vec::new()); block_on(pool.submit_one(&BlockId::number(0), SOURCE, xt1.clone())).expect("1. Imported"); - let header = pool.api.push_block(1, vec![xt1.clone()]); + let header = pool.api.push_block(1, vec![xt1.clone()], true); // This will prune `xt1`. block_on(pool.maintain(block_event(header))); diff --git a/frame/support/src/lib.rs b/frame/support/src/lib.rs index 7988582c82..f3955b4f31 100644 --- a/frame/support/src/lib.rs +++ b/frame/support/src/lib.rs @@ -102,13 +102,12 @@ pub enum Never {} /// /// # Examples /// -/// ``` +/// ```no_compile /// # use frame_support::traits::Get; /// # use frame_support::parameter_types; /// // This function cannot be used in a const context. /// fn non_const_expression() -> u64 { 99 } /// -/// ```no_compile /// parameter_types! { /// pub const Argument: u64 = 42 + FIXED_VALUE; /// /// Visibility of the type is optional diff --git a/frame/support/test/Cargo.toml b/frame/support/test/Cargo.toml index 1632ff55c2..34227c515e 100644 --- a/frame/support/test/Cargo.toml +++ b/frame/support/test/Cargo.toml @@ -17,8 +17,11 @@ frame-support = { version = "2.0.0-alpha.5", default-features = false, path = ". sp-inherents = { version = "2.0.0-alpha.5", default-features = false, path = "../../../primitives/inherents" } sp-runtime = { version = "2.0.0-alpha.5", default-features = false, path = "../../../primitives/runtime" } sp-core = { version = "2.0.0-alpha.5", default-features = false, path = "../../../primitives/core" } -trybuild = "1.0.17" +trybuild = "1.0.24" pretty_assertions = "0.6.1" +# pin ed25519-dalek to 1.0.0-pre.3 +# otherwise cargo will resolve 1.0.0-pre.4 which is breaking. +ed25519-dalek = "=1.0.0-pre.3" [features] default = ["std"] diff --git a/frame/system/src/lib.rs b/frame/system/src/lib.rs index d0e61fd523..730f1e58b2 100644 --- a/frame/system/src/lib.rs +++ b/frame/system/src/lib.rs @@ -1380,7 +1380,7 @@ mod tests { pub const MaximumBlockWeight: Weight = 1024; pub const AvailableBlockRatio: Perbill = Perbill::from_percent(75); pub const MaximumBlockLength: u32 = 1024; - pub const Version: RuntimeVersion = RuntimeVersion { + pub Version: RuntimeVersion = RuntimeVersion { spec_name: sp_version::create_runtime_str!("test"), impl_name: sp_version::create_runtime_str!("system-test"), authoring_version: 1, diff --git a/primitives/arithmetic/src/per_things.rs b/primitives/arithmetic/src/per_things.rs index de295e9df2..471a04b3c4 100644 --- a/primitives/arithmetic/src/per_things.rs +++ b/primitives/arithmetic/src/per_things.rs @@ -121,9 +121,28 @@ macro_rules! implement_per_thing { /// #[doc = $title] #[cfg_attr(feature = "std", derive(Serialize, Deserialize))] - #[derive(Encode, Decode, Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, RuntimeDebug, CompactAs)] + #[derive(Encode, Decode, Copy, Clone, Default, PartialEq, Eq, PartialOrd, Ord, RuntimeDebug)] pub struct $name($type); + /// Implementation makes any compact encoding of `PerThing::Inner` valid, + /// when decoding it will saturate up to `PerThing::ACCURACY`. + impl CompactAs for $name { + type As = $type; + fn encode_as(&self) -> &Self::As { + &self.0 + } + fn decode_from(x: Self::As) -> Self { + // Saturates if `x` is more than `$max` internally. + Self::from_parts(x) + } + } + + impl From> for $name { + fn from(x: codec::Compact<$name>) -> $name { + x.0 + } + } + impl PerThing for $name { type Inner = $type; type Upper = $upper_type; @@ -261,8 +280,8 @@ macro_rules! implement_per_thing { } /// See [`PerThing::one`]. - pub fn one() -> Self { - ::one() + pub const fn one() -> Self { + Self::from_parts($max) } /// See [`PerThing::zero`]. @@ -714,6 +733,17 @@ macro_rules! implement_per_thing { ); } + #[test] + fn compact_decoding_saturate_when_beyond_accuracy() { + use num_traits::Bounded; + use codec::Compact; + + let p = Compact::<$name>::decode(&mut &Compact(<$type>::max_value()).encode()[..]) + .unwrap(); + assert_eq!((p.0).0, $max); + assert_eq!($name::from(p), $name::max_value()); + } + #[test] fn per_things_div_works() { // normal diff --git a/primitives/phragmen/src/lib.rs b/primitives/phragmen/src/lib.rs index fdd1111bd0..835d610d9e 100644 --- a/primitives/phragmen/src/lib.rs +++ b/primitives/phragmen/src/lib.rs @@ -192,6 +192,10 @@ pub fn elect( voters.extend(initial_voters.into_iter().map(|(who, voter_stake, votes)| { let mut edges: Vec> = Vec::with_capacity(votes.len()); for v in votes { + if edges.iter().any(|e| e.who == v) { + // duplicate edge. + continue; + } if let Some(idx) = c_idx_cache.get(&v) { // This candidate is valid + already cached. candidates[*idx].approval_stake = candidates[*idx].approval_stake diff --git a/primitives/phragmen/src/tests.rs b/primitives/phragmen/src/tests.rs index 8bcf007c7b..3efe2f1aa3 100644 --- a/primitives/phragmen/src/tests.rs +++ b/primitives/phragmen/src/tests.rs @@ -486,3 +486,63 @@ fn self_votes_should_be_kept() { &Support { total: 20u128, voters: vec![(20u64, 20u128)] }, ); } + +#[test] +fn duplicate_target_is_ignored() { + let candidates = vec![1, 2, 3]; + let voters = vec![ + (10, 100, vec![1, 1, 2, 3]), + (20, 100, vec![2, 3]), + (30, 50, vec![1, 1, 2]), + ]; + + let PhragmenResult { winners, assignments } = elect::<_, _, TestCurrencyToVote, Output>( + 2, + 2, + candidates, + voters, + ).unwrap(); + let (winners, _): (Vec, Vec<_>) = winners.into_iter().unzip(); + + assert_eq!(winners, vec![(2), (3)]); + assert_eq!( + assignments + .into_iter() + .map(|x| (x.0, x.1.into_iter().map(|(w, _)| w).collect::>())) + .collect::>(), + vec![ + (10, vec![2, 3]), + (20, vec![2, 3]), + (30, vec![2]), + ], + ); +} + +#[test] +fn duplicate_target_is_ignored_when_winner() { + let candidates = vec![1, 2, 3]; + let voters = vec![ + (10, 100, vec![1, 1, 2, 3]), + (20, 100, vec![1, 2]), + ]; + + let PhragmenResult { winners, assignments } = elect::<_, _, TestCurrencyToVote, Output>( + 2, + 2, + candidates, + voters, + ).unwrap(); + let (winners, _): (Vec, Vec<_>) = winners.into_iter().unzip(); + + assert_eq!(winners, vec![1, 2]); + assert_eq!( + assignments + .into_iter() + .map(|x| (x.0, x.1.into_iter().map(|(w, _)| w).collect::>())) + .collect::>(), + vec![ + (10, vec![1, 2]), + (20, vec![1, 2]), + ], + ); +} diff --git a/primitives/trie/src/lib.rs b/primitives/trie/src/lib.rs index 989186a707..8beb3bd9cb 100644 --- a/primitives/trie/src/lib.rs +++ b/primitives/trie/src/lib.rs @@ -25,6 +25,7 @@ mod storage_proof; mod trie_stream; use sp_std::boxed::Box; +use sp_std::borrow::Borrow; use sp_std::marker::PhantomData; use sp_std::vec::Vec; use hash_db::{Hasher, Prefix}; @@ -257,7 +258,7 @@ pub fn child_delta_trie_root( root.as_mut().copy_from_slice(root_data.as_ref()); let mut db = KeySpacedDBMut::new(&mut *db, keyspace); - delta_trie_root::( + delta_trie_root::( &mut db, root, delta, @@ -464,7 +465,7 @@ mod trie_constants { #[cfg(test)] mod tests { use super::*; - use codec::{Encode, Compact}; + use codec::{Encode, Decode, Compact}; use sp_core::Blake2Hasher; use hash_db::{HashDB, Hasher}; use trie_db::{DBValue, TrieMut, Trie, NodeCodec as NodeCodecT}; @@ -852,4 +853,34 @@ mod tests { ).is_err() ); } + + #[test] + fn generate_storage_root_with_proof_works_independently_from_the_delta_order() { + let proof = StorageProof::decode(&mut &include_bytes!("../test-res/proof")[..]).unwrap(); + let storage_root = sp_core::H256::decode( + &mut &include_bytes!("../test-res/storage_root")[..], + ).unwrap(); + // Delta order that is "invalid" so that it would require a different proof. + let invalid_delta = Vec::<(Vec, Option>)>::decode( + &mut &include_bytes!("../test-res/invalid-delta-order")[..], + ).unwrap(); + // Delta order that is "valid" + let valid_delta = Vec::<(Vec, Option>)>::decode( + &mut &include_bytes!("../test-res/valid-delta-order")[..], + ).unwrap(); + + let proof_db = proof.into_memory_db::(); + let first_storage_root = delta_trie_root::( + &mut proof_db.clone(), + storage_root, + valid_delta, + ).unwrap(); + let second_storage_root = delta_trie_root::( + &mut proof_db.clone(), + storage_root, + invalid_delta, + ).unwrap(); + + assert_eq!(first_storage_root, second_storage_root); + } } diff --git a/primitives/trie/test-res/invalid-delta-order b/primitives/trie/test-res/invalid-delta-order new file mode 100644 index 0000000000000000000000000000000000000000..e46f280dc29bb2cbc3a28faeabe51efc747ba4af GIT binary patch literal 3476 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 X{$X-{*oOa#KRSO|AL_rmKdS!#%te!7 literal 0 HcmV?d00001 diff --git a/primitives/trie/test-res/proof b/primitives/trie/test-res/proof new file mode 100644 index 0000000000000000000000000000000000000000..278bea0bfbbc7fb16364eddbded70c884dd7ab71 GIT binary patch literal 4680 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 literal 0 HcmV?d00001 diff --git a/primitives/trie/test-res/storage_root b/primitives/trie/test-res/storage_root new file mode 100644 index 0000000000..758626802e --- /dev/null +++ b/primitives/trie/test-res/storage_root @@ -0,0 +1 @@ +‡=Ô[Á42%áJP ¢Áh¦Kwé)Rª 0¤Ô­u¿Ã \ No newline at end of file diff --git a/primitives/trie/test-res/valid-delta-order b/primitives/trie/test-res/valid-delta-order new file mode 100644 index 0000000000000000000000000000000000000000..4df6e62ec133b05cab2b53f00c8a4286eef70865 GIT binary patch literal 3476 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 See7x1`&!Nf0HpZQ^gjVW