This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from gavofyork/verification
Block Verification (no tests yet)
- Loading branch information
Showing
9 changed files
with
325 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,41 @@ | ||
use std::sync::Arc; | ||
use util::*; | ||
use blockchain::BlockChain; | ||
use client::{QueueStatus, ImportResult}; | ||
use views::{BlockView}; | ||
use verification::*; | ||
use error::*; | ||
use engine::Engine; | ||
|
||
/// A queue of blocks. Sits between network or other I/O and the BlockChain. | ||
/// Sorts them ready for blockchain insertion. | ||
pub struct BlockQueue; | ||
pub struct BlockQueue { | ||
bc: Arc<RwLock<BlockChain>>, | ||
engine: Arc<Box<Engine>>, | ||
} | ||
|
||
impl BlockQueue { | ||
/// Creates a new queue instance. | ||
pub fn new() -> BlockQueue { | ||
pub fn new(bc: Arc<RwLock<BlockChain>>, engine: Arc<Box<Engine>>) -> BlockQueue { | ||
BlockQueue { | ||
bc: bc, | ||
engine: engine, | ||
} | ||
} | ||
|
||
/// Clear the queue and stop verification activity. | ||
pub fn clear(&mut self) { | ||
} | ||
|
||
/// Add a block to the queue. | ||
pub fn import_block(&mut self, bytes: &[u8], bc: &mut BlockChain) -> ImportResult { | ||
//TODO: verify block | ||
{ | ||
let block = BlockView::new(bytes); | ||
let header = block.header_view(); | ||
let hash = header.sha3(); | ||
if self.chain.is_known(&hash) { | ||
return ImportResult::Bad; | ||
} | ||
pub fn import_block(&mut self, bytes: &[u8]) -> ImportResult { | ||
let header = BlockView::new(bytes).header(); | ||
if self.bc.read().unwrap().is_known(&header.hash()) { | ||
return Err(ImportError::AlreadyInChain); | ||
} | ||
bc.insert_block(bytes); | ||
ImportResult::Queued(QueueStatus::Known) | ||
try!(verify_block_basic(bytes, self.engine.deref().deref())); | ||
try!(verify_block_unordered(bytes, self.engine.deref().deref())); | ||
try!(verify_block_final(bytes, self.engine.deref().deref(), self.bc.read().unwrap().deref())); | ||
self.bc.write().unwrap().insert_block(bytes); | ||
Ok(()) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.