From c410771ed4a3c9c529f656e7748e3956c9ca7e86 Mon Sep 17 00:00:00 2001 From: Alexis Hernandez Date: Sat, 23 Jun 2018 10:28:00 -0500 Subject: [PATCH] server: Run the BackwardsSynchronizerTask after replacing a block by height (#30) --- .../com/xsn/explorer/processors/BlockEventsProcessor.scala | 4 ++-- server/app/com/xsn/explorer/tasks/PollingSeederTask.scala | 3 +++ server/app/com/xsn/explorer/tasks/SQSSeederTask.scala | 3 ++- .../xsn/explorer/processors/BlockEventsProcessorSpec.scala | 2 +- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/server/app/com/xsn/explorer/processors/BlockEventsProcessor.scala b/server/app/com/xsn/explorer/processors/BlockEventsProcessor.scala index 406a0a4..cf1032e 100644 --- a/server/app/com/xsn/explorer/processors/BlockEventsProcessor.scala +++ b/server/app/com/xsn/explorer/processors/BlockEventsProcessor.scala @@ -117,7 +117,7 @@ class BlockEventsProcessor @Inject() ( .createBlock(newBlock, newTransactions) .map { case Good(BlockOps.Result.BlockCreated) => Good(MissingBlockProcessed(newBlock)) - case Good(BlockOps.Result.BlockReplacedByHeight) => Good(ReplacedByBlockHeight) + case Good(BlockOps.Result.BlockReplacedByHeight) => Good(ReplacedByBlockHeight(newBlock)) case Bad(errors) => Bad(errors) } @@ -171,5 +171,5 @@ object BlockEventsProcessor { case class NewBlockAppended(block: Block) extends Result case class RechainDone(orphanBlock: Block, newBlock: Block) extends Result case object MissingBlockIgnored extends Result - case object ReplacedByBlockHeight extends Result + case class ReplacedByBlockHeight(newBlock: Block) extends Result } \ No newline at end of file diff --git a/server/app/com/xsn/explorer/tasks/PollingSeederTask.scala b/server/app/com/xsn/explorer/tasks/PollingSeederTask.scala index 1606bdb..f0cd338 100644 --- a/server/app/com/xsn/explorer/tasks/PollingSeederTask.scala +++ b/server/app/com/xsn/explorer/tasks/PollingSeederTask.scala @@ -56,6 +56,9 @@ class PollingSeederTask @Inject() ( case BlockEventsProcessor.MissingBlockProcessed(block) => backwardsSynchronizerTask.sync(block) + case BlockEventsProcessor.ReplacedByBlockHeight(newBlock) => + backwardsSynchronizerTask.sync(newBlock) + case _ => () } } diff --git a/server/app/com/xsn/explorer/tasks/SQSSeederTask.scala b/server/app/com/xsn/explorer/tasks/SQSSeederTask.scala index 28d16d6..461007f 100644 --- a/server/app/com/xsn/explorer/tasks/SQSSeederTask.scala +++ b/server/app/com/xsn/explorer/tasks/SQSSeederTask.scala @@ -106,6 +106,7 @@ class SQSSeederTask @Inject() ( backwardsSynchronizerTask.sync(block) case BlockEventsProcessor.MissingBlockIgnored => () - case BlockEventsProcessor.ReplacedByBlockHeight => () + case BlockEventsProcessor.ReplacedByBlockHeight(newBlock) => + backwardsSynchronizerTask.sync(newBlock) } } diff --git a/server/test/com/xsn/explorer/processors/BlockEventsProcessorSpec.scala b/server/test/com/xsn/explorer/processors/BlockEventsProcessorSpec.scala index 8514629..4ab1e45 100644 --- a/server/test/com/xsn/explorer/processors/BlockEventsProcessorSpec.scala +++ b/server/test/com/xsn/explorer/processors/BlockEventsProcessorSpec.scala @@ -261,7 +261,7 @@ class BlockEventsProcessorSpec extends PostgresDataHandlerSpec with ScalaFutures .foreach { whenReady(_) { _.isGood mustEqual true } } whenReady(processor.processBlock(block3.hash)) { result => - result mustEqual Good(ReplacedByBlockHeight) + result mustEqual Good(ReplacedByBlockHeight(block3)) val blocks = List(block1.copy(nextBlockhash = Some(block3.hash)), block3) verifyBlockchain(blocks)