further tweaks to block_accepted logs for clarity (#3379)

* further tweaks to block_accepted logs for clarity

* fix tests

* depth based off prev_head
This commit is contained in:
Antioch Peverell
2020-08-20 17:28:35 +01:00
committed by GitHub
parent 1cff387f61
commit caa6b8c747
4 changed files with 51 additions and 21 deletions
+18 -4
View File
@@ -306,21 +306,29 @@ impl Chain {
})
}
fn determine_status(&self, head: Option<Tip>, prev_head: Tip, fork_point: Tip) -> BlockStatus {
fn determine_status(
&self,
head: Option<Tip>,
prev: Tip,
prev_head: Tip,
fork_point: Tip,
) -> BlockStatus {
// If head is updated then we are either "next" block or we just experienced a "reorg" to new head.
// Otherwise this is a "fork" off the main chain.
if let Some(head) = head {
if head.prev_block_h == prev_head.last_block_h {
BlockStatus::Next { prev_head }
BlockStatus::Next { prev }
} else {
BlockStatus::Reorg {
prev,
prev_head,
fork_point,
}
}
} else {
BlockStatus::Fork {
prev_head,
prev,
head: prev_head,
fork_point,
}
}
@@ -416,7 +424,13 @@ impl Chain {
match maybe_new_head {
Ok((head, fork_point)) => {
let status = self.determine_status(head, prev_head, Tip::from_header(&fork_point));
let prev = self.get_previous_header(&b.header)?;
let status = self.determine_status(
head,
Tip::from_header(&prev),
prev_head,
Tip::from_header(&fork_point),
);
// notifying other parts of the system of the update
self.adapter.block_accepted(&b, status, opts);
+8 -4
View File
@@ -448,19 +448,23 @@ impl ChainAdapter for NoopAdapter {
pub enum BlockStatus {
/// Block is the "next" block, updating the chain head.
Next {
/// Previous chain head.
prev_head: Tip,
/// Previous block (previous chain head).
prev: Tip,
},
/// Block does not update the chain head and is a fork.
Fork {
/// Previous chain head.
prev_head: Tip,
/// Previous block on this fork.
prev: Tip,
/// Current chain head.
head: Tip,
/// Fork point for rewind.
fork_point: Tip,
},
/// Block updates the chain head via a (potentially disruptive) "reorg".
/// Previous block was not our previous chain head.
Reorg {
/// Previous block on this fork.
prev: Tip,
/// Previous chain head.
prev_head: Tip,
/// Fork point for rewind.