From b37820bd407b220db541f0729fbea8b279169cef Mon Sep 17 00:00:00 2001
From: AntiochP <30642645+antiochp@users.noreply.github.com>
Date: Mon, 18 Dec 2017 16:18:36 -0500
Subject: [PATCH] broadcast all accepted blocks, main chain or fork (#515)
(#517)
tweak logging to be more consistent
---
chain/src/chain.rs | 22 ++++++++++++++++++++--
chain/src/pipe.rs | 15 +++++++++------
p2p/src/peers.rs | 12 ++++++++++--
3 files changed, 39 insertions(+), 10 deletions(-)
diff --git a/chain/src/chain.rs b/chain/src/chain.rs
index ec1ace81f..cf4c1a428 100644
--- a/chain/src/chain.rs
+++ b/chain/src/chain.rs
@@ -157,8 +157,26 @@ impl Chain {
adapter.block_accepted(&b);
}
self.check_orphans();
- }
- Ok(None) => {}
+ },
+ Ok(None) => {
+ // block got accepted but we did not extend the head
+ // so its on a fork (or is the start of a new fork)
+ // broadcast the block out so everyone knows about the fork
+ //
+ // TODO - This opens us to an amplification attack on blocks
+ // mined at a low difficulty. We should suppress really old blocks
+ // or less relevant blocks somehow.
+ // We should also probably consider banning nodes that send us really old blocks.
+ //
+ if !opts.intersects(SYNC) {
+ // broadcast the block
+ let adapter = self.adapter.clone();
+ adapter.block_accepted(&b);
+ }
+ // We accepted a block here so there is a chance we can now accept
+ // one or more orphans.
+ self.check_orphans();
+ },
Err(Error::Orphan) => {
// TODO - Do we want to check that orphan height is > current height?
// TODO - Just check heights here? Or should we be checking total_difficulty as well?
diff --git a/chain/src/pipe.rs b/chain/src/pipe.rs
index 8188d957d..da217dd28 100644
--- a/chain/src/pipe.rs
+++ b/chain/src/pipe.rs
@@ -50,7 +50,7 @@ pub struct BlockContext {
/// chain head if updated.
pub fn process_block(b: &Block, mut ctx: BlockContext) -> Result