Skip to content

Commit

Permalink
feat: added zero-gas-tx-pool-timeout parameter (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielMartinezRodriguez authored Dec 14, 2023
1 parent f469228 commit b045bdb
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 8 deletions.
27 changes: 19 additions & 8 deletions client/authorship/src/authorship.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ pub struct ProposerFactory<A, B, C, PR> {
/// HTTP URL of the private pool from which the node will retrieve zero-gas transactions
zero_gas_tx_pool: Option<String>,

/// Timeout in milliseconds for the zero-gas transaction pool
/// (default: 1000)
zero_gas_tx_pool_timeout: u64,

/// Prometheus Link,
metrics: PrometheusMetrics,
/// The default block size limit.
Expand Down Expand Up @@ -115,6 +119,7 @@ impl<A, B, C> ProposerFactory<A, B, C, DisableProofRecording> {
transaction_pool: Arc<A>,
keystore: KeystorePtr,
zero_gas_tx_pool: Option<String>,
zero_gas_tx_pool_timeout: u64,
prometheus: Option<&PrometheusRegistry>,
telemetry: Option<TelemetryHandle>,
) -> Self {
Expand All @@ -123,6 +128,7 @@ impl<A, B, C> ProposerFactory<A, B, C, DisableProofRecording> {
transaction_pool,
keystore,
zero_gas_tx_pool,
zero_gas_tx_pool_timeout,
metrics: PrometheusMetrics::new(prometheus),
default_block_size_limit: DEFAULT_BLOCK_SIZE_LIMIT,
soft_deadline_percent: DEFAULT_SOFT_DEADLINE_PERCENT,
Expand All @@ -147,6 +153,7 @@ impl<A, B, C> ProposerFactory<A, B, C, EnableProofRecording> {
transaction_pool: Arc<A>,
keystore: KeystorePtr,
zero_gas_tx_pool: Option<String>,
zero_gas_tx_pool_timeout: u64,
prometheus: Option<&PrometheusRegistry>,
telemetry: Option<TelemetryHandle>,
) -> Self {
Expand All @@ -156,6 +163,7 @@ impl<A, B, C> ProposerFactory<A, B, C, EnableProofRecording> {
transaction_pool,
keystore,
zero_gas_tx_pool,
zero_gas_tx_pool_timeout,
metrics: PrometheusMetrics::new(prometheus),
default_block_size_limit: DEFAULT_BLOCK_SIZE_LIMIT,
soft_deadline_percent: DEFAULT_SOFT_DEADLINE_PERCENT,
Expand Down Expand Up @@ -234,6 +242,7 @@ where
transaction_pool: self.transaction_pool.clone(),
keystore: self.keystore.clone(),
zero_gas_tx_pool: self.zero_gas_tx_pool.clone(),
zero_gas_tx_pool_timeout: self.zero_gas_tx_pool_timeout,
now,
metrics: self.metrics.clone(),
default_block_size_limit: self.default_block_size_limit,
Expand Down Expand Up @@ -285,6 +294,7 @@ pub struct Proposer<B, Block: BlockT, C, A: TransactionPool, PR> {
transaction_pool: Arc<A>,
keystore: KeystorePtr,
zero_gas_tx_pool: Option<String>,
zero_gas_tx_pool_timeout: u64,
now: Box<dyn Fn() -> time::Instant + Send + Sync>,
metrics: PrometheusMetrics,
default_block_size_limit: usize,
Expand Down Expand Up @@ -444,7 +454,7 @@ where

let http_client = reqwest::Client::new();
let mut request = Box::pin(http_client.post(zero_gas_tx_pool).send().fuse());
let mut timeout = Box::pin(futures_timer::Delay::new(std::time::Duration::from_millis(500)).fuse());
let mut timeout = Box::pin(futures_timer::Delay::new(std::time::Duration::from_millis(self.zero_gas_tx_pool_timeout)).fuse());

let result_response_raw_zero = select! {
res = request => {
Expand Down Expand Up @@ -874,7 +884,7 @@ mod tests {
.expect("Creates authority key");

let mut proposer_factory =
ProposerFactory::new(spawner.clone(), client.clone(), txpool.clone(),keystore_container.keystore(), None, None, None);
ProposerFactory::new(spawner.clone(), client.clone(), txpool.clone(), keystore_container.keystore(), None, 1000, None, None);

let cell = Mutex::new((false, time::Instant::now()));
let proposer = proposer_factory.init_with_now(
Expand Down Expand Up @@ -929,7 +939,7 @@ mod tests {
.expect("Creates authority key");

let mut proposer_factory =
ProposerFactory::new(spawner.clone(), client.clone(), txpool.clone(), keystore_container.keystore(), None, None, None);
ProposerFactory::new(spawner.clone(), client.clone(), txpool.clone(), keystore_container.keystore(), None, 1000, None, None);

let cell = Mutex::new((false, time::Instant::now()));
let proposer = proposer_factory.init_with_now(
Expand Down Expand Up @@ -989,7 +999,7 @@ mod tests {
.expect("Creates authority key");

let mut proposer_factory =
ProposerFactory::new(spawner.clone(), client.clone(), txpool.clone(), keystore_container.keystore(), None, None, None);
ProposerFactory::new(spawner.clone(), client.clone(), txpool.clone(), keystore_container.keystore(), None, 1000, None, None);

let proposer = proposer_factory.init_with_now(
&client.header(genesis_hash).unwrap().unwrap(),
Expand Down Expand Up @@ -1059,7 +1069,7 @@ mod tests {
.expect("Creates authority key");

let mut proposer_factory =
ProposerFactory::new(spawner.clone(), client.clone(), txpool.clone(),keystore_container.keystore(), None, None, None);
ProposerFactory::new(spawner.clone(), client.clone(), txpool.clone(),keystore_container.keystore(), None, 1000, None, None);
let mut propose_block = |client: &TestClient,
parent_number,
expected_block_extrinsics,
Expand Down Expand Up @@ -1190,7 +1200,7 @@ mod tests {
.expect("Creates authority key");

let mut proposer_factory =
ProposerFactory::new(spawner.clone(), client.clone(), txpool.clone(), keystore_container.keystore(), None, None, None);
ProposerFactory::new(spawner.clone(), client.clone(), txpool.clone(), keystore_container.keystore(), None, 1000, None, None);

let proposer = block_on(proposer_factory.init(&genesis_header)).unwrap();

Expand Down Expand Up @@ -1234,6 +1244,7 @@ mod tests {
txpool.clone(),
keystore_container.keystore(),
None,
1000,
None,
None,
);
Expand Down Expand Up @@ -1320,7 +1331,7 @@ mod tests {


let mut proposer_factory =
ProposerFactory::new(spawner.clone(), client.clone(), txpool.clone(), keystore_container.keystore(), None, None, None);
ProposerFactory::new(spawner.clone(), client.clone(), txpool.clone(), keystore_container.keystore(), None, 1000, None, None);

let cell = Mutex::new(time::Instant::now());
let proposer = proposer_factory.init_with_now(
Expand Down Expand Up @@ -1404,7 +1415,7 @@ mod tests {
.expect("Creates authority key");

let mut proposer_factory =
ProposerFactory::new(spawner.clone(), client.clone(), txpool.clone(), keystore_container.keystore(), None, None, None);
ProposerFactory::new(spawner.clone(), client.clone(), txpool.clone(), keystore_container.keystore(), None, 1000, None, None);

let deadline = time::Duration::from_secs(600);
let cell = Arc::new(Mutex::new((0, time::Instant::now())));
Expand Down
1 change: 1 addition & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ Optional environment variables:
- BOOTNODES: This environment variable allows specifying the bootnodes to use, separated by commas. If not specified, the node will use the default bootnodes for the chain spec.
- MODE: This environment variable allows the node to run in different pruning modes. Possible values are "full_node" or "archive". The default value is "full_node".
- ZERO_GAS_TX_POOL: This environment variable allows the node to run with a zero gas price transaction pool. By default the feature is disabled. The expected value is a string containing an URL. Check the [Zero Gas Transaction Pool](../docs/ZERO-GAS-TRANSACTIONS.md) document for more information.
- ZERO_GAS_TX_POOL_TIMEOUT: This environment variable allows specifying the timeout for the zero gas transaction in millisecond. If not specified, the node will use the default timeout (1000ms).

To set an environment variable in the docker run, use the flag -e NAME=VALUE

Expand Down
4 changes: 4 additions & 0 deletions docker/client/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ if [ -n "$ZERO_GAS_TX_POOL" ]; then
START_COMMAND="$START_COMMAND --zero-gas-tx-pool $ZERO_GAS_TX_POOL"
fi

if [ -n "$ZERO_GAS_TX_POOL_TIMEOUT"]; then
START_COMMAND="$START_COMMAND --zero-gas-tx-pool-timeout $ZERO_GAS_TX_POOL_TIMEOUT"
fi

if [ -n "$CUSTOM_ETH_APIS" ]; then
START_COMMAND="$START_COMMAND --ethapi=$CUSTOM_ETH_APIS"
else
Expand Down
2 changes: 2 additions & 0 deletions node/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,7 @@ where
transaction_pool,
keystore_container.keystore(),
stability_config.zero_gas_tx_pool.clone(),
stability_config.zero_gas_tx_pool_timeout.clone(),
prometheus_registry.as_ref(),
telemetry.as_ref().map(|x| x.handle()),
);
Expand Down Expand Up @@ -636,6 +637,7 @@ where
transaction_pool.clone(),
keystore.keystore(),
stability_config.zero_gas_tx_pool.clone(),
stability_config.zero_gas_tx_pool_timeout.clone(),
prometheus_registry,
telemetry.as_ref().map(|x| x.handle()),
);
Expand Down
5 changes: 5 additions & 0 deletions node/src/stability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,9 @@ pub struct StabilityConfiguration {
/// HTTP URL of the private pool from which the node will retrieve zero-gas transactions
#[arg(long, value_name = "URL")]
pub zero_gas_tx_pool: Option<String>,

/// Timeout in milliseconds for the zero-gas transaction pool
/// (default: 1000)
#[arg(long, value_name = "MILLISECONDS", default_value = "1000")]
pub zero_gas_tx_pool_timeout: u64,
}

0 comments on commit b045bdb

Please sign in to comment.