New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement catch-up phase #80
Conversation
Also this only implements catch-up during booting up. The other definitions of done in the Catchup Phase Issue need to be solved. |
source/agora/test/Ledger.d
Outdated
import std.algorithm; | ||
import std.conv; | ||
import std.format; | ||
import std.digest.sha; |
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.
Should be removed
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.
damn where did that sneak in from lol
I've atomic'ed (atomized?) the commits, it should look much nicer now. I probably need to think of edge cases to add to the unittests. |
source/agora/test/Base.d
Outdated
/// | ||
public this (Config config) | ||
{ | ||
this.mem_metadata = new MemMetadata; | ||
this.ledger = new Ledger; |
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.
That code doesn't make sense to me. You instantiate a new Ledger
just to override it with itself in the parent constructor. You also shadow the parent ledger
variable ?
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.
The shadowing was an oversight. I'll simplify this a bit tomorrow.
3cba60a
to
ce985fb
Compare
Update: Added periodic catch-up phase, and added a network test for it. This completes all of the tasks and should cover everything in the definition of done. |
I would merge the last two commits. Also, do you want the ability to arbitrarily delay a node ? Because I can give you that power easily in LocalRest
.
source/agora/test/Base.d
Outdated
@@ -175,6 +177,9 @@ public interface TestAPI : API | |||
|
|||
/// | |||
public abstract void metaAddPeer(string peer); | |||
|
|||
/// | |||
public abstract void addBlockToLedger (Block block); |
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.
Why do you need this ? I don't see an override anywhere ?
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.
Well, the question is how do you get access to the Ledger from the unittest. As it's required right now. edit: reworded
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.
You never access the internals of a node at the moment.
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.
Well the first test is:
Instantiate the nodes. Don't start networking yet. One node (node A) needs to have 100 blocks, the 3 are empty.
Then, make them connect to each other. The 3 other nodes will retrieve blocks from the 1st node on boot.
But to make this work, I need to add those blocks to node A before it connects to the 3 other nodes.
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.
To be more specific here. I can't just use the sendTransaction
API here because this will trigger the gossip protocol to send the transaction over the whole network, and then each node will create their own block. So by the time the node tries to retrieve the blocks from the other nodes, it will already have all the blocks.
Delaying the node might not help. I would need some way to temporarily disable the gossip protocol, but then this becomes very messy to have all these special cases for unittesting.
The more features the node has, the more complicated it is to test a specific feature in the node without triggering an avalanche of other features.
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.
I will be able to replace this code once LocalRest has the ability to filter requests. Then I can do something like:
- Use the sendTransaction API to one node
- Make the other nodes ignore transaction gossiping
- The other nodes will then catch-up using the periodic
getBlocksFrom
call.
This is way nicer than messing with Node's internals.
source/agora/test/Ledger.d
Outdated
{ | ||
import core.thread; | ||
import std.conv; | ||
import vibe.core.log; |
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.
Two leftover imports
f2ec64b
to
2636b48
Compare
I've squashed the two commits. I'm thinking about how to get rid of those methods in the TestAPI now. |
Hmm.. that might be very useful. |
All the Mac builds fail. Hmm.. |
It's a timing issue. |
dc1e472
to
0cd569a
Compare
Ok I made a more stable version of the tests that shouldn't suffer too much from timing issues. I added polling and a timeout of 4 seconds. |
c29d528
to
3ea3762
Compare
Very peculiar that macOS dmd 2.085.1 seems to consistently be failing now.. |
~@Geod24 I'm having consistent time-outs in the MacOS build: https://travis-ci.com/bpfkorea/agora/jobs/214998228 It seems it gets stuck trying to install DMD & Dub.~ And it's green. |
I guess you want to rebase ? |
Ah I thought this one was rebased. |
I mean merged. |
Rebased. |
source/agora/node/Network.d
Outdated
// periodic task | ||
while (1) | ||
{ | ||
logInfo("Retrieving latest blocks.."); |
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.
I think this logging should only happen if we are actually catching up
source/agora/node/RemoteNode.d
Outdated
|
||
***************************************************************************/ | ||
|
||
public ulong getBlockHeight ( ) |
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.
public ulong getBlockHeight ( ) | |
public ulong getBlockHeight () |
source/agora/test/Ledger.d
Outdated
@@ -22,13 +23,24 @@ import agora.common.Hash; | |||
import agora.common.Transaction; | |||
import agora.test.Base; | |||
|
|||
/// Returns: true if all node's block heights are equal to the provided height | |||
private bool allHeightsEqual ( TestAPI[] nodes, size_t height ) |
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.
private bool allHeightsEqual ( TestAPI[] nodes, size_t height ) | |
private bool allHeightsEqual (TestAPI[] nodes, size_t height) |
Fixed the suggested changes. |
It will be used to add blocks received from other nodes.
Rebased to use new LocalRest sleep() feature. However it's a bit ugly because now I have to store |
source/agora/node/Network.d
Outdated
***************************************************************************/ | ||
|
||
private void getBlocksFrom (ulong block_height, | ||
void delegate(Block[]) @safe onReceivedBlocks) |
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.
void delegate(Block[]) @safe onReceivedBlocks) | |
scope void delegate(Block[]) @safe onReceivedBlocks) |
source/agora/node/Node.d
Outdated
|
||
protected Ledger getLedger () | ||
{ | ||
return new Ledger(); |
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.
I don't think you need this anymore ?
source/agora/test/Ledger.d
Outdated
{ | ||
import core.thread; | ||
import std.algorithm; | ||
import std.format; |
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.
Those 2 imports are not necessary anymore
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.
I need each
still.
source/agora/test/Ledger.d
Outdated
@@ -22,13 +23,24 @@ import agora.common.Hash; | |||
import agora.common.Transaction; | |||
import agora.test.Base; | |||
|
|||
/// Returns: true if all node's block heights are equal to the provided height | |||
private bool allHeightsEqual (API)(API[] nodes, size_t height) |
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.
Suggestion: isConsistent
and check the block headers for equality ?
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.
Ok.
Updated with suggested changes. |
source/agora/test/Ledger.d
Outdated
import core.thread; | ||
import std.algorithm; | ||
import std.conv; | ||
import std.format; |
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.
conv and format superfluous
After a node connects to all its peers, it will retrieve the latest blocks and apply them to its ledger. The node will keep periodically trying to retrieve the latest blocks from its connected peers.
Pushed a small update. |
It's not ready for merging yet, but it can be looked at.
This still needs a bit of refactoring, separating atomic changes into their own commits.