test storage proper projection
This commit is contained in:
parent
33b4143e74
commit
a77c986e11
|
@ -151,8 +151,14 @@ impl Store for TestStorage {
|
|||
unimplemented!();
|
||||
}
|
||||
|
||||
fn accepted_location(&self, _header: &chain::BlockHeader) -> Option<BlockLocation> {
|
||||
unimplemented!();
|
||||
// supports only main chain in test storage
|
||||
fn accepted_location(&self, header: &chain::BlockHeader) -> Option<BlockLocation> {
|
||||
if self.best_block().is_none() { return Some(BlockLocation::Main(0)); }
|
||||
|
||||
let best = self.best_block().unwrap();
|
||||
if best.hash == header.previous_header_hash { return Some(BlockLocation::Main(best.number + 1)); }
|
||||
|
||||
None
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use std::sync::Arc;
|
||||
|
||||
use db::{self, BlockRef};
|
||||
use db::{self, BlockRef, BlockLocation};
|
||||
use chain::{self, RepresentH256};
|
||||
use super::{Verify, VerificationResult, Chain, Error, TransactionError, ContinueVerify};
|
||||
use utils;
|
||||
|
@ -18,6 +18,10 @@ impl ChainVerifier {
|
|||
ChainVerifier { store: store }
|
||||
}
|
||||
|
||||
fn ordered_verify(&self, block: &chain::Block, at_height: u32) -> Result<(), Error> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn verify_transaction(&self, block: &chain::Block, transaction: &chain::Transaction) -> Result<(), TransactionError> {
|
||||
use script::{
|
||||
TransactionInputSigner,
|
||||
|
@ -98,12 +102,20 @@ impl Verify for ChainVerifier {
|
|||
try!(self.verify_transaction(block, transaction).map_err(|e| Error::Transaction(idx, e)));
|
||||
}
|
||||
|
||||
let _parent = match self.store.block(BlockRef::Hash(block.header().previous_header_hash.clone())) {
|
||||
Some(b) => b,
|
||||
None => { return Ok(Chain::Orphan); }
|
||||
};
|
||||
|
||||
Ok(Chain::Main)
|
||||
// todo: pre-process projected block number once verification is parallel!
|
||||
match self.store.accepted_location(block.header()) {
|
||||
None => {
|
||||
Ok(Chain::Orphan)
|
||||
},
|
||||
Some(BlockLocation::Main(block_number)) => {
|
||||
try!(self.ordered_verify(block, block_number));
|
||||
Ok(Chain::Main)
|
||||
},
|
||||
Some(BlockLocation::Side(block_number)) => {
|
||||
try!(self.ordered_verify(block, block_number));
|
||||
Ok(Chain::Side)
|
||||
},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -46,12 +46,30 @@ pub fn age(protocol_time: u32) -> i64 {
|
|||
::time::get_time().sec - protocol_time as i64
|
||||
}
|
||||
|
||||
pub fn block_reward_satoshi(block_height: u32) -> u64 {
|
||||
let mut res = 50 * 100 * 1000 * 1000;
|
||||
for _ in 0..block_height / 210000 { res = res / 2 }
|
||||
res
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
use super::check_nbits;
|
||||
use super::{block_reward_satoshi, check_nbits};
|
||||
use primitives::hash::H256;
|
||||
|
||||
#[test]
|
||||
fn reward() {
|
||||
assert_eq!(block_reward_satoshi(0), 5000000000);
|
||||
assert_eq!(block_reward_satoshi(209999), 5000000000);
|
||||
assert_eq!(block_reward_satoshi(210000), 2500000000);
|
||||
assert_eq!(block_reward_satoshi(420000), 1250000000);
|
||||
assert_eq!(block_reward_satoshi(420001), 1250000000);
|
||||
assert_eq!(block_reward_satoshi(629999), 1250000000);
|
||||
assert_eq!(block_reward_satoshi(630000), 625000000);
|
||||
assert_eq!(block_reward_satoshi(630001), 625000000);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nbits() {
|
||||
// strictly equal
|
||||
|
|
Loading…
Reference in New Issue