mirror of
https://github.com/pezkuwichain/pezkuwi-subxt.git
synced 2026-05-01 18:17:56 +00:00
Make transaction pool prune transactions only of canonical blocks (#6123)
* Make tx pool aware of retracted fork blocks * Make it compile * Update client/transaction-pool/src/lib.rs Co-authored-by: Nikolay Volf <nikvolf@gmail.com> * Fix doc test * Simplify the implementation * Send tree route as arc to prevent heavy clones * Switch to use `ExtrinsicHash` to make it more clear * Fix benchmark Co-authored-by: Nikolay Volf <nikvolf@gmail.com>
This commit is contained in:
@@ -16,16 +16,17 @@
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
use crate::{Service, NetworkStatus, NetworkState, error::Error, DEFAULT_PROTOCOL_ID, MallocSizeOfWasm};
|
||||
use crate::{start_rpc_servers, build_network_future, TransactionPoolAdapter, TaskManager, SpawnTaskHandle};
|
||||
use crate::status_sinks;
|
||||
use crate::config::{Configuration, KeystoreConfig, PrometheusConfig, OffchainWorkerConfig};
|
||||
use crate::metrics::MetricsService;
|
||||
use sc_client_api::{
|
||||
self, BlockchainEvents, backend::RemoteBackend, light::RemoteBlockchain, execution_extensions::ExtensionsFactory,
|
||||
ExecutorProvider, CallExecutor, ForkBlocks, BadBlocks, CloneableSpawn, UsageProvider,
|
||||
use crate::{
|
||||
Service, NetworkStatus, NetworkState, error::Error, DEFAULT_PROTOCOL_ID, MallocSizeOfWasm,
|
||||
start_rpc_servers, build_network_future, TransactionPoolAdapter, TaskManager, SpawnTaskHandle,
|
||||
status_sinks, metrics::MetricsService, client::{Client, ClientConfig},
|
||||
config::{Configuration, KeystoreConfig, PrometheusConfig, OffchainWorkerConfig},
|
||||
};
|
||||
use sc_client_api::{
|
||||
BlockchainEvents, backend::RemoteBackend, light::RemoteBlockchain,
|
||||
execution_extensions::ExtensionsFactory, ExecutorProvider, CallExecutor, ForkBlocks, BadBlocks,
|
||||
CloneableSpawn, UsageProvider,
|
||||
};
|
||||
use crate::client::{Client, ClientConfig};
|
||||
use sp_utils::mpsc::{tracing_unbounded, TracingUnboundedSender};
|
||||
use sc_chain_spec::get_extension;
|
||||
use sp_consensus::{
|
||||
@@ -55,7 +56,6 @@ use std::{
|
||||
use wasm_timer::SystemTime;
|
||||
use sc_telemetry::{telemetry, SUBSTRATE_INFO};
|
||||
use sp_transaction_pool::{MaintainedTransactionPool, ChainEvent};
|
||||
use sp_blockchain;
|
||||
use prometheus_endpoint::Registry;
|
||||
use sc_client_db::{Backend, DatabaseSettings};
|
||||
use sp_core::traits::CodeExecutor;
|
||||
@@ -452,8 +452,29 @@ impl ServiceBuilder<(), (), (), (), (), (), (), (), (), (), ()> {
|
||||
}
|
||||
|
||||
impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
|
||||
ServiceBuilder<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp,
|
||||
TExPool, TRpc, Backend> {
|
||||
ServiceBuilder<
|
||||
TBl,
|
||||
TRtApi,
|
||||
TCl,
|
||||
TFchr,
|
||||
TSc,
|
||||
TImpQu,
|
||||
TFprb,
|
||||
TFpp,
|
||||
TExPool,
|
||||
TRpc,
|
||||
Backend
|
||||
>
|
||||
{
|
||||
/// Returns a reference to the configuration that was stored in this builder.
|
||||
pub fn config(&self) -> &Configuration {
|
||||
&self.config
|
||||
}
|
||||
|
||||
/// Returns a reference to the optional prometheus registry that was stored in this builder.
|
||||
pub fn prometheus_registry(&self) -> Option<&Registry> {
|
||||
self.config.prometheus_config.as_ref().map(|config| &config.registry)
|
||||
}
|
||||
|
||||
/// Returns a reference to the client that was stored in this builder.
|
||||
pub fn client(&self) -> &Arc<TCl> {
|
||||
@@ -698,20 +719,12 @@ impl<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp, TExPool, TRpc, Backend>
|
||||
pub fn with_transaction_pool<UExPool>(
|
||||
self,
|
||||
transaction_pool_builder: impl FnOnce(
|
||||
sc_transaction_pool::txpool::Options,
|
||||
Arc<TCl>,
|
||||
Option<TFchr>,
|
||||
Option<&Registry>,
|
||||
) -> Result<(UExPool, Option<BackgroundTask>), Error>
|
||||
&Self,
|
||||
) -> Result<(UExPool, Option<BackgroundTask>), Error>,
|
||||
) -> Result<ServiceBuilder<TBl, TRtApi, TCl, TFchr, TSc, TImpQu, TFprb, TFpp,
|
||||
UExPool, TRpc, Backend>, Error>
|
||||
where TSc: Clone, TFchr: Clone {
|
||||
let (transaction_pool, background_task) = transaction_pool_builder(
|
||||
self.config.transaction_pool.clone(),
|
||||
self.client.clone(),
|
||||
self.fetcher.clone(),
|
||||
self.config.prometheus_config.as_ref().map(|config| &config.registry),
|
||||
)?;
|
||||
let (transaction_pool, background_task) = transaction_pool_builder(&self)?;
|
||||
|
||||
if let Some(background_task) = background_task{
|
||||
self.task_manager.spawn_handle().spawn("txpool-background", background_task);
|
||||
@@ -1032,7 +1045,7 @@ ServiceBuilder<
|
||||
let mut import_stream = client.import_notification_stream().map(|n| ChainEvent::NewBlock {
|
||||
id: BlockId::Hash(n.hash),
|
||||
header: n.header,
|
||||
retracted: n.retracted,
|
||||
tree_route: n.tree_route,
|
||||
is_new_best: n.is_new_best,
|
||||
}).fuse();
|
||||
let mut finality_stream = client.finality_notification_stream()
|
||||
@@ -1349,7 +1362,7 @@ ServiceBuilder<
|
||||
_telemetry_on_connect_sinks: telemetry_connection_sinks.clone(),
|
||||
keystore,
|
||||
marker: PhantomData::<TBl>,
|
||||
prometheus_registry: config.prometheus_config.map(|config| config.registry)
|
||||
prometheus_registry: config.prometheus_config.map(|config| config.registry),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user