Skip to content

Commit

Permalink
Merge pull request #60 from dforsten/hbbft-pending-contribution
Browse files Browse the repository at this point in the history
Potential fix for 0-tx blocks.
I could confirm that this potential fix really solves the error.
#58
  • Loading branch information
SurfingNerd authored Jan 9, 2022
2 parents 4c462ed + c723baf commit 4faa279
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 6 deletions.
2 changes: 1 addition & 1 deletion crates/ethcore/src/client/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3084,7 +3084,7 @@ impl super::traits::EngineClient for Client {
}

fn queued_transactions(&self) -> Vec<Arc<VerifiedTransaction>> {
self.importer.miner.queued_transactions()
self.importer.miner.queued_transactions(self)
}

fn create_pending_block_at(
Expand Down
2 changes: 1 addition & 1 deletion crates/ethcore/src/client/test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,7 @@ impl super::traits::EngineClient for TestBlockChainClient {
}

fn queued_transactions(&self) -> Vec<Arc<VerifiedTransaction>> {
self.miner.queued_transactions()
self.miner.queued_transactions(self)
}

fn create_pending_block_at(
Expand Down
2 changes: 1 addition & 1 deletion crates/ethcore/src/engines/hbbft/test/hbbft_test_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ impl HbbftTestClient {
pub fn sync_transactions_to(&self, other: &mut Self) {
let transactions = self
.miner
.queued_transactions()
.all_transactions()
//.transactions_to_propagate()
.iter()
.map(|i| i.signed().deref().clone())
Expand Down
41 changes: 39 additions & 2 deletions crates/ethcore/src/miner/miner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1072,6 +1072,11 @@ impl Miner {
}
}
}

/// Return all transactions currently in the transaction queue.
pub fn all_transactions(&self) -> Vec<Arc<VerifiedTransaction>> {
self.transaction_queue.all_transactions()
}
}

const SEALING_TIMEOUT_IN_BLOCKS: u64 = 5;
Expand Down Expand Up @@ -1251,8 +1256,40 @@ impl miner::MinerService for Miner {
self.transaction_queue.local_transactions()
}

fn queued_transactions(&self) -> Vec<Arc<VerifiedTransaction>> {
self.transaction_queue.all_transactions()
fn queued_transactions<C>(&self, chain: &C) -> Vec<Arc<VerifiedTransaction>>
where
C: BlockChain + CallContract + Nonce + Sync,
{
let client = self.pool_client(chain);
let chain_info = chain.chain_info();
let min_tx_gas: U256 = self
.engine
.schedule(chain_info.best_block_number)
.tx_gas
.into();

let status = self.queue_status();

// we will never need more transactions than limit divided by min gas
let max_transactions = if min_tx_gas.is_zero() {
usize::MAX
} else {
MAX_SKIPPED_TRANSACTIONS.saturating_add(
cmp::min(status.options.block_gas_limit / min_tx_gas, u64::MAX.into()).as_u64()
as usize,
)
};

self.transaction_queue.pending(
client.clone(),
pool::PendingSettings {
block_number: chain_info.best_block_number,
current_timestamp: chain_info.best_block_timestamp,
nonce_cap: None,
max_len: max_transactions,
ordering: miner::PendingOrdering::Priority,
},
)
}

fn queued_transaction_hashes(&self) -> Vec<H256> {
Expand Down
4 changes: 3 additions & 1 deletion crates/ethcore/src/miner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,9 @@ pub trait MinerService: Send + Sync {
}

/// Get a list of all transactions in the pool (some of them might not be ready for inclusion yet).
fn queued_transactions(&self) -> Vec<Arc<VerifiedTransaction>>;
fn queued_transactions<C>(&self, chain: &C) -> Vec<Arc<VerifiedTransaction>>
where
C: BlockChain + CallContract + Nonce + Sync;

/// Get a list of all transaction hashes in the pool (some of them might not be ready for inclusion yet).
fn queued_transaction_hashes(&self) -> Vec<H256>;
Expand Down

0 comments on commit 4faa279

Please sign in to comment.