Renaming bad blocks as retracted
This commit is contained in:
parent
8a13e87cbe
commit
b9a6a70ced
@ -410,7 +410,7 @@ impl<V> Client<V> where V: Verifier {
|
|||||||
if !good_blocks.is_empty() && block_queue.queue_info().is_empty() {
|
if !good_blocks.is_empty() && block_queue.queue_info().is_empty() {
|
||||||
io.send(NetworkIoMessage::User(SyncMessage::NewChainBlocks {
|
io.send(NetworkIoMessage::User(SyncMessage::NewChainBlocks {
|
||||||
good: good_blocks,
|
good: good_blocks,
|
||||||
bad: bad_blocks,
|
retracted: bad_blocks,
|
||||||
})).unwrap();
|
})).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ pub enum SyncMessage {
|
|||||||
/// Hashes of blocks imported to blockchain
|
/// Hashes of blocks imported to blockchain
|
||||||
good: Vec<H256>,
|
good: Vec<H256>,
|
||||||
/// Hashes of blocks not imported to blockchain
|
/// Hashes of blocks not imported to blockchain
|
||||||
bad: Vec<H256>,
|
retracted: Vec<H256>,
|
||||||
},
|
},
|
||||||
/// A block is ready
|
/// A block is ready
|
||||||
BlockVerified,
|
BlockVerified,
|
||||||
|
@ -1265,10 +1265,11 @@ impl ChainSync {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// called when block is imported to chain, updates transactions queue
|
/// called when block is imported to chain, updates transactions queue
|
||||||
pub fn chain_new_blocks(&mut self, io: &SyncIo, good: &[H256], bad: &[H256]) {
|
pub fn chain_new_blocks(&mut self, io: &SyncIo, good: &[H256], retracted: &[H256]) {
|
||||||
fn fetch_transactions(chain: &BlockChainClient, hash: &H256) -> Vec<SignedTransaction> {
|
fn fetch_transactions(chain: &BlockChainClient, hash: &H256) -> Vec<SignedTransaction> {
|
||||||
let block = chain
|
let block = chain
|
||||||
.block(BlockId::Hash(hash.clone()))
|
.block(BlockId::Hash(hash.clone()))
|
||||||
|
// Client should send message after commit to db and inserting to chain.
|
||||||
.expect("Expected in-chain blocks.");
|
.expect("Expected in-chain blocks.");
|
||||||
let block = BlockView::new(&block);
|
let block = BlockView::new(&block);
|
||||||
block.transactions()
|
block.transactions()
|
||||||
@ -1277,14 +1278,14 @@ impl ChainSync {
|
|||||||
|
|
||||||
let chain = io.chain();
|
let chain = io.chain();
|
||||||
let good = good.par_iter().map(|h| fetch_transactions(chain, h));
|
let good = good.par_iter().map(|h| fetch_transactions(chain, h));
|
||||||
let bad = bad.par_iter().map(|h| fetch_transactions(chain, h));
|
let retracted = retracted.par_iter().map(|h| fetch_transactions(chain, h));
|
||||||
|
|
||||||
good.for_each(|txs| {
|
good.for_each(|txs| {
|
||||||
let mut transaction_queue = self.transaction_queue.lock().unwrap();
|
let mut transaction_queue = self.transaction_queue.lock().unwrap();
|
||||||
let hashes = txs.iter().map(|tx| tx.hash()).collect::<Vec<H256>>();
|
let hashes = txs.iter().map(|tx| tx.hash()).collect::<Vec<H256>>();
|
||||||
transaction_queue.remove_all(&hashes, |a| chain.nonce(a));
|
transaction_queue.remove_all(&hashes, |a| chain.nonce(a));
|
||||||
});
|
});
|
||||||
bad.for_each(|txs| {
|
retracted.for_each(|txs| {
|
||||||
// populate sender
|
// populate sender
|
||||||
for tx in &txs {
|
for tx in &txs {
|
||||||
let _sender = tx.sender();
|
let _sender = tx.sender();
|
||||||
@ -1628,7 +1629,7 @@ mod tests {
|
|||||||
let mut sync = dummy_sync_with_peer(client.block_hash_delta_minus(5));
|
let mut sync = dummy_sync_with_peer(client.block_hash_delta_minus(5));
|
||||||
|
|
||||||
let good_blocks = vec![client.block_hash_delta_minus(2)];
|
let good_blocks = vec![client.block_hash_delta_minus(2)];
|
||||||
let bad_blocks = vec![client.block_hash_delta_minus(1)];
|
let retracted_blocks = vec![client.block_hash_delta_minus(1)];
|
||||||
|
|
||||||
let mut queue = VecDeque::new();
|
let mut queue = VecDeque::new();
|
||||||
let io = TestIo::new(&mut client, &mut queue, None);
|
let io = TestIo::new(&mut client, &mut queue, None);
|
||||||
@ -1637,7 +1638,7 @@ mod tests {
|
|||||||
sync.chain_new_blocks(&io, &[], &good_blocks);
|
sync.chain_new_blocks(&io, &[], &good_blocks);
|
||||||
assert_eq!(sync.transaction_queue.lock().unwrap().status().future, 0);
|
assert_eq!(sync.transaction_queue.lock().unwrap().status().future, 0);
|
||||||
assert_eq!(sync.transaction_queue.lock().unwrap().status().pending, 1);
|
assert_eq!(sync.transaction_queue.lock().unwrap().status().pending, 1);
|
||||||
sync.chain_new_blocks(&io, &good_blocks, &bad_blocks);
|
sync.chain_new_blocks(&io, &good_blocks, &retracted_blocks);
|
||||||
|
|
||||||
// then
|
// then
|
||||||
let status = sync.transaction_queue.lock().unwrap().status();
|
let status = sync.transaction_queue.lock().unwrap().status();
|
||||||
|
@ -157,9 +157,9 @@ impl NetworkProtocolHandler<SyncMessage> for EthSync {
|
|||||||
SyncMessage::BlockVerified => {
|
SyncMessage::BlockVerified => {
|
||||||
self.sync.write().unwrap().chain_blocks_verified(&mut NetSyncIo::new(io, self.chain.deref()));
|
self.sync.write().unwrap().chain_blocks_verified(&mut NetSyncIo::new(io, self.chain.deref()));
|
||||||
},
|
},
|
||||||
SyncMessage::NewChainBlocks { ref good, ref bad } => {
|
SyncMessage::NewChainBlocks { ref good, ref retracted } => {
|
||||||
let sync_io = NetSyncIo::new(io, self.chain.deref());
|
let sync_io = NetSyncIo::new(io, self.chain.deref());
|
||||||
self.sync.write().unwrap().chain_new_blocks(&sync_io, good, bad);
|
self.sync.write().unwrap().chain_new_blocks(&sync_io, good, retracted);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user