Skip to content

Commit

Permalink
Try #342:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] committed Mar 19, 2019
2 parents a1e3938 + 097132b commit 036df4e
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 22 deletions.
8 changes: 5 additions & 3 deletions rpc/src/module/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,11 @@ impl<CI: ChainIndex + 'static> TraceRpc for TraceRpcImpl<CI> {
fn trace_transaction(&self, tx: Transaction) -> Result<H256> {
let tx: CoreTransaction = tx.into();
let tx_hash = tx.hash().clone();
let mut chain_state = self.shared.chain_state().lock();
let tx_pool = chain_state.mut_tx_pool();
tx_pool.trace_tx(tx.clone());
{
let mut chain_state = self.shared.chain_state().lock();
let tx_pool = chain_state.mut_tx_pool();
tx_pool.trace_tx(tx.clone());
}

let fbb = &mut FlatBufferBuilder::new();
let message = RelayMessage::build_transaction(fbb, &tx);
Expand Down
18 changes: 10 additions & 8 deletions sync/src/relayer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -221,16 +221,18 @@ where
let mut pending_proposals_request = self.state.pending_proposals_request.lock();
let mut peer_txs = FnvHashMap::default();
let mut remove_ids = Vec::new();
let chain_state = self.shared.chain_state().lock();
let tx_pool = chain_state.tx_pool();
for (id, peers) in pending_proposals_request.iter() {
if let Some(tx) = tx_pool.get_tx(id) {
for peer in peers {
let tx_set = peer_txs.entry(*peer).or_insert_with(Vec::new);
tx_set.push(tx.clone());
{
let chain_state = self.shared.chain_state().lock();
let tx_pool = chain_state.tx_pool();
for (id, peers) in pending_proposals_request.iter() {
if let Some(tx) = tx_pool.get_tx(id) {
for peer in peers {
let tx_set = peer_txs.entry(*peer).or_insert_with(Vec::new);
tx_set.push(tx.clone());
}
}
remove_ids.push(*id);
}
remove_ids.push(*id);
}

for id in remove_ids {
Expand Down
13 changes: 7 additions & 6 deletions sync/src/relayer/transaction_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ where

pub fn execute(self) {
let tx: Transaction = (*self.message).into();
let chain_state = self.relayer.shared.chain_state().lock();
let max_block_cycles = self.relayer.shared.consensus().max_block_cycles();
if chain_state
.add_tx_to_pool(tx.clone(), max_block_cycles)
.is_ok()
{
let ret = {
let chain_state = self.relayer.shared.chain_state().lock();
let max_block_cycles = self.relayer.shared.consensus().max_block_cycles();
chain_state.add_tx_to_pool(tx.clone(), max_block_cycles)
};

if ret.is_ok() {
let fbb = &mut FlatBufferBuilder::new();
let message = RelayMessage::build_transaction(fbb, &tx);
fbb.finish(message, None);
Expand Down
15 changes: 10 additions & 5 deletions sync/src/synchronizer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -549,9 +549,15 @@ impl<CI: ChainIndex> Synchronizer<CI> {
if !state.chain_sync.protect && is_outbound {
let best_known_header = best_known_headers.get(peer);

let chain_state = self.shared.chain_state().lock();
let (tip_header, local_total_difficulty) = {
let chain_state = self.shared.chain_state().lock();
(
chain_state.tip_header().clone(),
chain_state.total_difficulty().clone(),
)
};
if best_known_header.map(|h| h.total_difficulty())
>= Some(chain_state.total_difficulty())
>= Some(&local_total_difficulty)
{
if state.chain_sync.timeout != 0 {
state.chain_sync.timeout = 0;
Expand All @@ -569,9 +575,8 @@ impl<CI: ChainIndex> Synchronizer<CI> {
// where we checked against our tip.
// Either way, set a new timeout based on current tip.
state.chain_sync.timeout = now + CHAIN_SYNC_TIMEOUT;
state.chain_sync.work_header = Some(chain_state.tip_header().clone());
state.chain_sync.total_difficulty =
Some(chain_state.total_difficulty().clone());
state.chain_sync.work_header = Some(tip_header);
state.chain_sync.total_difficulty = Some(local_total_difficulty);
state.chain_sync.sent_getheaders = false;
} else if state.chain_sync.timeout > 0 && now > state.chain_sync.timeout {
// No evidence yet that our peer has synced to a chain with work equal to that
Expand Down

0 comments on commit 036df4e

Please sign in to comment.