This repository has been archived by the owner on Aug 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 312
Reset the puller when the chain has reorgenaized #161
Merged
dangershony
merged 1 commit into
stratisproject:master
from
dangershony:notification-reset-on-reorg
Jun 15, 2017
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ namespace Stratis.Bitcoin.Notifications | |
public class BlockNotification | ||
{ | ||
private readonly ISignals signals; | ||
private ChainedBlock tip; | ||
|
||
public BlockNotification(ConcurrentChain chain, ILookaheadBlockPuller puller, ISignals signals) | ||
{ | ||
|
@@ -22,7 +23,7 @@ public BlockNotification(ConcurrentChain chain, ILookaheadBlockPuller puller, IS | |
this.Chain = chain; | ||
this.Puller = puller; | ||
this.signals = signals; | ||
this.CointinueOnReorg = true; | ||
} | ||
|
||
public ILookaheadBlockPuller Puller { get; } | ||
|
@@ -32,6 +33,7 @@ public BlockNotification(ConcurrentChain chain, ILookaheadBlockPuller puller, IS | |
public uint256 StartHash { get; private set; } | ||
|
||
private bool reSync; | ||
public bool CointinueOnReorg { get; set; } | ||
|
||
public void SyncFrom(uint256 startHash) | ||
{ | ||
|
@@ -43,6 +45,7 @@ public void SyncFrom(uint256 startHash) | |
{ | ||
// sets the location of the puller to the latest hash that was broadcasted | ||
this.Puller.SetLocation(startBlock); | ||
this.tip = startBlock; | ||
} | ||
|
||
} | ||
|
@@ -73,6 +76,7 @@ public virtual void Notify(CancellationToken cancellationToken) | |
|
||
// sets the location of the puller to the latest hash that was broadcasted | ||
this.Puller.SetLocation(startBlock); | ||
this.tip = startBlock; | ||
|
||
// send notifications for all the following blocks | ||
while (!this.reSync) | ||
|
@@ -83,10 +87,23 @@ public virtual void Notify(CancellationToken cancellationToken) | |
{ | ||
// broadcast the block to the registered observers | ||
this.signals.Blocks.Broadcast(block); | ||
this.tip = this.Chain.GetBlock(block.GetHash()); | ||
} | ||
else | ||
{ | ||
break; | ||
// in reorg we reset the puller to the fork | ||
// when a reorg happens the puller is pushed | ||
// back and continues from the current fork | ||
|
||
// find the fork | ||
while (this.Chain.GetBlock(this.tip.HashBlock) == null) | ||
this.tip = this.tip.Previous; | ||
|
||
// set the puller to the fork location | ||
this.Puller.SetLocation(this.tip); | ||
|
||
if (!this.CointinueOnReorg) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. not sure this is necessary |
||
break; | ||
} | ||
} | ||
|
||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there is an extra i in cointinue..