Skip to content
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

Use setTimer on Network.discover #919

Merged
merged 1 commit into from Jun 3, 2020

Conversation

TrustHenry
Copy link
Member

@TrustHenry TrustHenry commented Jun 3, 2020

Two improvements are needed here.

Taskmanager.setTimer is wait and call action.

So I call first to eliminate the delay in the first run.

Currently, this kind of movement causes the error as below.

Second Validator.startPeriodicDiscovery
This is unnecessary repetitive behavior of buildRequiredKeys

Relates #872

@TrustHenry
Copy link
Member Author

source/agora/test/NetworkDiscovery.d(51): Node logs:

Log for node: FullNode #0
======================================================================
2020-06-03 14:28:02,595 Info [agora.network.NetworkManager] - Doing network discovery..
2020-06-03 14:28:02,605 Info [agora.network.NetworkManager] - Found new FullNode: FullNode #3
2020-06-03 14:28:02,708 Info [agora.network.NetworkManager] - Found new FullNode: FullNode #1
======================================================================

Log for node: FullNode #1
======================================================================
2020-06-03 14:28:02,595 Info [agora.network.NetworkManager] - Doing network discovery..
2020-06-03 14:28:02,605 Info [agora.network.NetworkManager] - Found new FullNode: FullNode #0
2020-06-03 14:28:02,708 Info [agora.network.NetworkManager] - Found new FullNode: FullNode #2
======================================================================

Log for node: FullNode #2
======================================================================
2020-06-03 14:28:02,595 Info [agora.network.NetworkManager] - Doing network discovery..
2020-06-03 14:28:02,605 Info [agora.network.NetworkManager] - Found new FullNode: FullNode #1
2020-06-03 14:28:02,708 Info [agora.network.NetworkManager] - Found new FullNode: FullNode #3
======================================================================

Log for node: FullNode #3
======================================================================
2020-06-03 14:28:02,595 Info [agora.network.NetworkManager] - Doing network discovery..
2020-06-03 14:28:02,605 Info [agora.network.NetworkManager] - Found new FullNode: FullNode #2
2020-06-03 14:28:02,708 Info [agora.network.NetworkManager] - Found new FullNode: FullNode #0
======================================================================

Module tests failed: agora.test.NetworkDiscovery
core.exception.AssertError@source/agora/test/NetworkDiscovery.d(52): Check condition failed after timeout of 5 secs and 50 attempts: Node FullNode #0 has not completed discovery after 5 secs.
----------------
??:? void agora.utils.Test.retryFor!(core.exception.AssertError).retryFor(lazy bool, core.time.Duration, lazy immutable(char)[], immutable(char)[], ulong) [0x10cd95bee]
??:? void agora.test.Base.TestAPIManager.waitForDiscovery(immutable(char)[], ulong).__lambda3!(agora.test.Base.NodePair).__lambda3(agora.test.Base.NodePair) [0x10cde6172]
??:? std.typecons.Flag!("each").Flag std.algorithm.iteration.each!(agora.test.Base.TestAPIManager.waitForDiscovery(immutable(char)[], ulong).__lambda3).each!(agora.test.Base.NodePair[]).each(ref agora.test.Base.NodePair[]) [0x10cdc9df5]
??:? void agora.test.Base.TestAPIManager.waitForDiscovery(immutable(char)[], ulong) [0x10cdb7526]
??:? void agora.test.NetworkDiscovery.__unittest_L39_C1() [0x10cdbcf57]
??:? agora.test.NetworkDiscovery.__unittest [0x10cdbd63a]
??:? void agora.test.Base.customModuleUnitTester().runTest(agora.test.Base.customModuleUnitTester().ModTest) [0x10cdc8981]
??:? int agora.test.Base.customModuleUnitTester().__foreachbody4(ref agora.test.Base.customModuleUnitTester().ModTest) [0x10cdc8cc0]
??:? void std.parallelism.ParallelForeach!(agora.test.Base.customModuleUnitTester().ModTest[]).ParallelForeach.opApply(scope int delegate(ref agora.test.Base.customModuleUnitTester().ModTest)).doIt() [0x10d163611]
??:? void std.parallelism.TaskPool.doJob(std.parallelism.AbstractTask*) [0x10d6a65a0]
??:? void std.parallelism.TaskPool.startWorkLoop() [0x10d6a674a]
??:? thread_entryPoint [0x10d72c684]
??:? _pthread_start [0x7fff6347ae64]

@TrustHenry TrustHenry marked this pull request as draft June 3, 2020 05:35
@TrustHenry TrustHenry changed the title Use setimer on startPeriodicDiscovery Use setTimer on startPeriodicDiscovery Jun 3, 2020
@TrustHenry TrustHenry force-pushed the usesettimer branch 3 times, most recently from 687d753 to b498e04 Compare June 3, 2020 07:25
@TrustHenry TrustHenry changed the title Use setTimer on startPeriodicDiscovery Use setTimer on Network.discover Jun 3, 2020
@TrustHenry TrustHenry force-pushed the usesettimer branch 2 times, most recently from 86aeb98 to 0dfc8e0 Compare June 3, 2020 07:28
@TrustHenry TrustHenry marked this pull request as ready for review June 3, 2020 07:35
@TrustHenry
Copy link
Member Author

I applied @AndrejMitrovic suggestions.

this.taskman.wait(5.seconds);
}
});
scope void discover () { this.network.discover(); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong. It should not be a scope delegate. If it's scope, it will be allocated on the stack. So when start() returns and the timer tries to call discover, it may crash.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, I was worried.

this.network.discover(required_peer_keys);
this.taskman.wait(5.seconds);
}
scope void discover () { this.network.discover(required_peer_keys); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also make it non-scope.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's removed.

this.taskman.wait(5.seconds);
}
});
void discover () { this.network.discover(); }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the startPeriodicDiscovery function anymore. And also:

Sorry I thought that we don't need the runTask, but actually it would make sense to run it inside a task to make it non blocking.

How about we use the same technique which you did in the Validator?

So startPeriodicDiscovery with a runTask inside, and start would call it first and then startPeriodicCatchup. Inside startPeriodicDiscovery you would have this void discover and the setting up of the timer.

Do you see what I mean?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good to make the FullNode and Validator consistent.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's good to be consistent. It's been applied.

@@ -154,7 +154,7 @@ public class FullNode : API

public void start ()
{
this.startPeriodicDiscovery();
startPeriodicDiscovery();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just missing this. and then it's ready to go.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The catch is too fast!

These need to be replaced to use setTimer once TaskManager is fixed to use it.
@codecov
Copy link

codecov bot commented Jun 3, 2020

Codecov Report

Merging #919 into v0.x.x will increase coverage by 0.17%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           v0.x.x     #919      +/-   ##
==========================================
+ Coverage   90.24%   90.42%   +0.17%     
==========================================
  Files          71       71              
  Lines        5650     5669      +19     
==========================================
+ Hits         5099     5126      +27     
+ Misses        551      543       -8     
Flag Coverage Δ
#integration 54.69% <66.66%> (-0.50%) ⬇️
#unittests 88.78% <100.00%> (+0.18%) ⬆️
Impacted Files Coverage Δ
source/agora/node/FullNode.d 84.84% <100.00%> (ø)
source/agora/node/Validator.d 74.19% <100.00%> (ø)
source/agora/node/Ledger.d 97.34% <0.00%> (-0.17%) ⬇️
source/agora/consensus/validation/Enrollment.d 98.59% <0.00%> (-0.02%) ⬇️
source/agora/common/Amount.d 100.00% <0.00%> (ø)
source/agora/consensus/UTXOSet.d 92.66% <0.00%> (+8.25%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7a2e4de...0c6be76. Read the comment docs.

Copy link
Contributor

@linked0 linked0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@AndrejMitrovic AndrejMitrovic merged commit f1cd919 into bosagora:v0.x.x Jun 3, 2020
@TrustHenry TrustHenry deleted the usesettimer branch June 3, 2020 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants