basic processing
This commit is contained in:
parent
e50402fb14
commit
891f5e8e3f
|
@ -54,6 +54,14 @@ pub enum Chain {
|
||||||
Orphan,
|
Orphan,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// block status within the queue
|
||||||
|
pub enum BlockStatus {
|
||||||
|
Valid,
|
||||||
|
Invalid,
|
||||||
|
Pending,
|
||||||
|
Absent,
|
||||||
|
}
|
||||||
|
|
||||||
/// Verification result
|
/// Verification result
|
||||||
pub type VerificationResult = Result<Chain, Error>;
|
pub type VerificationResult = Result<Chain, Error>;
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
use chain::{Block, BlockHeader};
|
use chain::{Block, BlockHeader};
|
||||||
use primitives::hash::H256;
|
use primitives::hash::H256;
|
||||||
use super::{Chain, Verify};
|
use super::{Chain, Verify, BlockStatus};
|
||||||
use linked_hash_map::LinkedHashMap;
|
use linked_hash_map::LinkedHashMap;
|
||||||
use parking_lot::RwLock;
|
use parking_lot::RwLock;
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
|
@ -18,6 +18,7 @@ impl VerifiedBlock {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Verification queue
|
||||||
pub struct Queue {
|
pub struct Queue {
|
||||||
verifier: Box<Verify>,
|
verifier: Box<Verify>,
|
||||||
items: RwLock<LinkedHashMap<H256, Block>>,
|
items: RwLock<LinkedHashMap<H256, Block>>,
|
||||||
|
@ -26,6 +27,7 @@ pub struct Queue {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Queue {
|
impl Queue {
|
||||||
|
/// Process one block in the queue
|
||||||
pub fn process(&self) {
|
pub fn process(&self) {
|
||||||
let (hash, block) = {
|
let (hash, block) = {
|
||||||
let mut items = self.items.write();
|
let mut items = self.items.write();
|
||||||
|
@ -48,4 +50,12 @@ impl Queue {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Query block status
|
||||||
|
pub fn block_status(&self, hash: &H256) {
|
||||||
|
if self.invalid.read().contains_key(hash) { BlockStatus::Invalid }
|
||||||
|
else if self.verified.read().contains_key(hash) { BlockStatus::Valid }
|
||||||
|
else if self.items.read().contains_key(hash) { BlockStatus::Pending }
|
||||||
|
else { BlockStatus::Absent }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue