diff --git a/chain/src/chain.rs b/chain/src/chain.rs
index 5d359b5133..ca5311595b 100644
--- a/chain/src/chain.rs
+++ b/chain/src/chain.rs
@@ -254,15 +254,18 @@ impl Chain {
let is_more_work = head.is_some();
let mut is_next_block = false;
+ let mut reorg_depth = None;
if let Some(head) = head {
if head.prev_block_h == prev_head.last_block_h {
is_next_block = true;
+ } else {
+ reorg_depth = Some(prev_head.height.saturating_sub(head.height) + 1);
}
}
match (is_more_work, is_next_block) {
(true, true) => BlockStatus::Next,
- (true, false) => BlockStatus::Reorg,
+ (true, false) => BlockStatus::Reorg(reorg_depth.unwrap_or(0)),
(false, _) => BlockStatus::Fork,
}
}
diff --git a/chain/src/types.rs b/chain/src/types.rs
index 27895e7c46..b3f7b782bb 100644
--- a/chain/src/types.rs
+++ b/chain/src/types.rs
@@ -169,5 +169,5 @@ pub enum BlockStatus {
Fork,
/// Block updates the chain head via a (potentially disruptive) "reorg".
/// Previous block was not our previous chain head.
- Reorg,
+ Reorg(u64),
}
diff --git a/chain/tests/mine_simple_chain.rs b/chain/tests/mine_simple_chain.rs
index 80da3b0ef3..a0d31f5220 100644
--- a/chain/tests/mine_simple_chain.rs
+++ b/chain/tests/mine_simple_chain.rs
@@ -26,9 +26,11 @@ use self::keychain::{ExtKeychain, ExtKeychainPath, Keychain};
use self::util::{RwLock, StopState};
use chrono::Duration;
use grin_chain as chain;
+use grin_chain::{BlockStatus, ChainAdapter, Options};
use grin_core as core;
use grin_keychain as keychain;
use grin_util as util;
+use std::cell::RefCell;
use std::fs;
use std::sync::Arc;
@@ -51,6 +53,41 @@ fn setup(dir_name: &str, genesis: Block) -> Chain {
.unwrap()
}
+/// Adapter to retrieve last status
+pub struct StatusAdapter {
+ pub last_status: RwLock