Recover transaction pool on light client (#3833)

* recover tx pool on light client

* revert local tests fix

* removed import renamings

* futures03::Future -> std::future::Future

* Update core/transaction-pool/graph/src/error.rs

Co-Authored-By: Tomasz Drwięga <tomusdrw@users.noreply.github.com>

* replace remove_from_ready with remove_invalid

* avoid excess hashing

* debug -> warn

* TransactionPool + BasicTransactionPool

* pause future tx reject when resubmitting

* bump impl_version to make CI happy

* and revert back local test fixes

* alter doc to restart CI

* Transaction::clone() -> Transaction::duplicate()

* transactions -> updated_tranasctions

* remove explicit consensus-common ref

* ::std:: -> std::

* manual set/unset flag -> calling clusore with given flag value

* removed comments

* removed force argument

* BestIterator -> Box<Iterator>

* separate crate for TxPool + Maintainer trait

* long line fix

* pos-merge fix

* fix benches compilation

* Rename txpoolapi to txpool_api

* Clean up.

* Finalize merge.

* post-merge fix

* Move transaction pool api to primitives directly.

* Consistent naming for txpool-runtime-api

* Warn about missing docs.

* Move  abstraction for offchain calls to tx-pool-api.

* Merge RPC instantiation.

* Update cargo.lock

* Post merge fixes.

* Avoid depending on client.

* Fix build
This commit is contained in:
Svyatoslav Nikolsky
2019-11-28 03:00:54 +03:00
committed by Gavin Wood
parent 3e26fceda4
commit a782021ee8
64 changed files with 2370 additions and 667 deletions
@@ -20,34 +20,14 @@ use futures::{
Stream,
channel::mpsc,
};
use serde::{Serialize, Deserialize};
/// Possible extrinsic status events
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub enum Status<H, H2> {
/// Extrinsic is part of the future queue.
Future,
/// Extrinsic is part of the ready queue.
Ready,
/// Extrinsic has been finalized in block with given hash.
Finalized(H2),
/// Some state change (perhaps another extrinsic was included) rendered this extrinsic invalid.
Usurped(H),
/// The extrinsic has been broadcast to the given peers.
Broadcast(Vec<String>),
/// Extrinsic has been dropped from the pool because of the limit.
Dropped,
/// Extrinsic was detected as invalid.
Invalid,
}
use txpool_api::TransactionStatus;
/// Extrinsic watcher.
///
/// Represents a stream of status updates for particular extrinsic.
#[derive(Debug)]
pub struct Watcher<H, H2> {
receiver: mpsc::UnboundedReceiver<Status<H, H2>>,
receiver: mpsc::UnboundedReceiver<TransactionStatus<H, H2>>,
hash: H,
}
@@ -60,7 +40,7 @@ impl<H, H2> Watcher<H, H2> {
/// Pipe the notifications to given sink.
///
/// Make sure to drive the future to completion.
pub fn into_stream(self) -> impl Stream<Item=Status<H, H2>> {
pub fn into_stream(self) -> impl Stream<Item=TransactionStatus<H, H2>> {
self.receiver
}
}
@@ -68,7 +48,7 @@ impl<H, H2> Watcher<H, H2> {
/// Sender part of the watcher. Exposed only for testing purposes.
#[derive(Debug)]
pub struct Sender<H, H2> {
receivers: Vec<mpsc::UnboundedSender<Status<H, H2>>>,
receivers: Vec<mpsc::UnboundedSender<TransactionStatus<H, H2>>>,
finalized: bool,
}
@@ -94,49 +74,48 @@ impl<H: Clone, H2: Clone> Sender<H, H2> {
/// Transaction became ready.
pub fn ready(&mut self) {
self.send(Status::Ready)
self.send(TransactionStatus::Ready)
}
/// Transaction was moved to future.
pub fn future(&mut self) {
self.send(Status::Future)
self.send(TransactionStatus::Future)
}
/// Some state change (perhaps another extrinsic was included) rendered this extrinsic invalid.
pub fn usurped(&mut self, hash: H) {
self.send(Status::Usurped(hash))
self.send(TransactionStatus::Usurped(hash))
}
/// Extrinsic has been finalized in block with given hash.
pub fn finalized(&mut self, hash: H2) {
self.send(Status::Finalized(hash));
self.send(TransactionStatus::Finalized(hash));
self.finalized = true;
}
/// Extrinsic has been marked as invalid by the block builder.
pub fn invalid(&mut self) {
self.send(Status::Invalid);
self.send(TransactionStatus::Invalid);
// we mark as finalized as there are no more notifications
self.finalized = true;
}
/// Transaction has been dropped from the pool because of the limit.
pub fn dropped(&mut self) {
self.send(Status::Dropped);
self.send(TransactionStatus::Dropped);
}
/// The extrinsic has been broadcast to the given peers.
pub fn broadcast(&mut self, peers: Vec<String>) {
self.send(Status::Broadcast(peers))
self.send(TransactionStatus::Broadcast(peers))
}
/// Returns true if the are no more listeners for this extrinsic or it was finalized.
pub fn is_done(&self) -> bool {
self.finalized || self.receivers.is_empty()
}
fn send(&mut self, status: Status<H, H2>) {
fn send(&mut self, status: TransactionStatus<H, H2>) {
self.receivers.retain(|sender| sender.unbounded_send(status.clone()).is_ok())
}
}