mirror of
https://github.com/mimblewimble/grin.git
synced 2025-02-01 08:51:08 +03:00
Capture options with orphan block, fix #83
This commit is contained in:
parent
b3e224b439
commit
c994c7cba2
2 changed files with 6 additions and 9 deletions
|
@ -53,7 +53,7 @@ pub struct Chain {
|
||||||
|
|
||||||
head: Arc<Mutex<Tip>>,
|
head: Arc<Mutex<Tip>>,
|
||||||
block_process_lock: Arc<Mutex<bool>>,
|
block_process_lock: Arc<Mutex<bool>>,
|
||||||
orphans: Arc<Mutex<VecDeque<Block>>>,
|
orphans: Arc<Mutex<VecDeque<(Options, Block)>>>,
|
||||||
|
|
||||||
test_mode: bool,
|
test_mode: bool,
|
||||||
}
|
}
|
||||||
|
@ -134,7 +134,7 @@ impl Chain {
|
||||||
}
|
}
|
||||||
Err(Error::Orphan) => {
|
Err(Error::Orphan) => {
|
||||||
let mut orphans = self.orphans.lock().unwrap();
|
let mut orphans = self.orphans.lock().unwrap();
|
||||||
orphans.push_front(b);
|
orphans.push_front((opts, b));
|
||||||
orphans.truncate(MAX_ORPHANS);
|
orphans.truncate(MAX_ORPHANS);
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
@ -182,17 +182,13 @@ impl Chain {
|
||||||
}
|
}
|
||||||
|
|
||||||
// pop each orphan and retry, if still orphaned, will be pushed again
|
// pop each orphan and retry, if still orphaned, will be pushed again
|
||||||
let mut opts = NONE;
|
|
||||||
if self.test_mode {
|
|
||||||
opts = opts | EASY_POW;
|
|
||||||
}
|
|
||||||
for _ in 0..orphan_count {
|
for _ in 0..orphan_count {
|
||||||
let mut popped = None;
|
let mut popped = None;
|
||||||
{
|
{
|
||||||
let mut orphans = self.orphans.lock().unwrap();
|
let mut orphans = self.orphans.lock().unwrap();
|
||||||
popped = orphans.pop_back();
|
popped = orphans.pop_back();
|
||||||
}
|
}
|
||||||
if let Some(orphan) = popped {
|
if let Some((opts, orphan)) = popped {
|
||||||
self.process_block(orphan, opts);
|
self.process_block(orphan, opts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,8 +47,6 @@ pub enum Error {
|
||||||
DifficultyTooLow,
|
DifficultyTooLow,
|
||||||
/// Addition of difficulties on all previous block is wrong
|
/// Addition of difficulties on all previous block is wrong
|
||||||
WrongTotalDifficulty,
|
WrongTotalDifficulty,
|
||||||
/// Size of the Cuckoo graph in block header doesn't match PoW requirements
|
|
||||||
WrongCuckooSize,
|
|
||||||
/// The proof of work is invalid
|
/// The proof of work is invalid
|
||||||
InvalidPow,
|
InvalidPow,
|
||||||
/// The block doesn't sum correctly or a tx signature is invalid
|
/// The block doesn't sum correctly or a tx signature is invalid
|
||||||
|
@ -59,7 +57,9 @@ pub enum Error {
|
||||||
InvalidBlockHeight,
|
InvalidBlockHeight,
|
||||||
/// Internal issue when trying to save or load data from store
|
/// Internal issue when trying to save or load data from store
|
||||||
StoreErr(grin_store::Error),
|
StoreErr(grin_store::Error),
|
||||||
|
/// Error serializing or deserializing a type
|
||||||
SerErr(ser::Error),
|
SerErr(ser::Error),
|
||||||
|
/// Anything else
|
||||||
Other(String),
|
Other(String),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,6 +199,7 @@ pub trait ChainAdapter {
|
||||||
fn block_accepted(&self, b: &Block);
|
fn block_accepted(&self, b: &Block);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Dummy adapter used as a placeholder for real implementations
|
||||||
pub struct NoopAdapter {}
|
pub struct NoopAdapter {}
|
||||||
impl ChainAdapter for NoopAdapter {
|
impl ChainAdapter for NoopAdapter {
|
||||||
fn block_accepted(&self, b: &Block) {}
|
fn block_accepted(&self, b: &Block) {}
|
||||||
|
|
Loading…
Reference in a new issue