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

Seconds to milliseconds #918

Merged
merged 27 commits into from
Jul 22, 2019
Merged

Seconds to milliseconds #918

merged 27 commits into from
Jul 22, 2019

Conversation

vncoelho
Copy link
Member

closes #651

Let's review this with careful.
I believe it will be a great chance, in particular, for very lightweight local neo privatenets.

  • There are some formulas and shift operations that probably needed to be adjusted.
    • I went directly in the straight modification, but, perhaps, I surely missed some necessary adjustments.
  • There are also some functions that I believe are obsolete, maybe we can also remove them

@@ -27,7 +27,7 @@ public static PingPayload Create(uint height, uint nonce)
return new PingPayload
{
LastBlockIndex = height,
Timestamp = DateTime.UtcNow.ToTimestamp(),
Timestamp = DateTime.UtcNow.ToTimestampMS(),
Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe we can leave the Ping in seconds.

Copy link
Contributor

Choose a reason for hiding this comment

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

It is better to leave everything using the same "unit", what do you think?

@@ -31,7 +31,7 @@ public static VersionPayload Create(uint nonce, string userAgent, params NodeCap
{
Magic = ProtocolSettings.Default.Magic,
Version = LocalNode.ProtocolVersion,
Timestamp = DateTime.Now.ToTimestamp(),
Timestamp = DateTime.Now.ToTimestampMS(),
Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe we can leave the version payload in seconds as well.

@vncoelho vncoelho added this to the NEO 3.0 milestone Jul 12, 2019
neo/IO/Json/JNumber.cs Outdated Show resolved Hide resolved
neo/Helper.cs Outdated Show resolved Hide resolved
neo/Helper.cs Outdated Show resolved Hide resolved
@codecov-io
Copy link

codecov-io commented Jul 12, 2019

Codecov Report

Merging #918 into master will decrease coverage by 0.05%.
The diff coverage is 64.15%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #918      +/-   ##
==========================================
- Coverage   45.53%   45.47%   -0.06%     
==========================================
  Files         178      178              
  Lines       12635    12639       +4     
==========================================
- Hits         5753     5748       -5     
- Misses       6882     6891       +9
Impacted Files Coverage Δ
neo/IO/Json/JNumber.cs 84.26% <ø> (+4.48%) ⬆️
neo/Consensus/RecoveryRequest.cs 45.45% <0%> (ø) ⬆️
neo/ProtocolSettings.cs 94% <100%> (ø) ⬆️
neo/Consensus/PrepareRequest.cs 95.23% <100%> (ø) ⬆️
neo/Helper.cs 51.74% <100%> (+2.23%) ⬆️
neo/Consensus/ChangeView.cs 93.33% <100%> (ø) ⬆️
neo/Ledger/MemoryPool.cs 77.94% <100%> (ø) ⬆️
neo/Network/P2P/Payloads/BlockBase.cs 72% <100%> (+2.88%) ⬆️
neo/Consensus/ConsensusService.cs 15.7% <12.5%> (ø) ⬆️
neo/SmartContract/ApplicationEngine.cs 68.47% <28.57%> (-20.16%) ⬇️
... and 4 more

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 98e6d1c...6cc6b9b. Read the comment docs.

neo.UnitTests/protocol.json Outdated Show resolved Hide resolved
@vncoelho vncoelho marked this pull request as ready for review July 13, 2019 14:50
@vncoelho vncoelho requested a review from shargon July 13, 2019 15:03
@vncoelho vncoelho dismissed shargon’s stale review July 13, 2019 15:03

Slower now...aheuahuea

@@ -79,7 +79,7 @@ public void ConsensusService_Primary_Sends_PrepareRequest_After_OnStart()

Console.WriteLine($"header {header} hash {header.Hash} timstamp {timestampVal}");

timestampVal.Should().Be(4244941696); //1968-06-01 00:00:00
timestampVal.Should().Be(1514007552); //1968-06-01 00:00:00
Copy link
Member Author

@vncoelho vncoelho Jul 13, 2019

Choose a reason for hiding this comment

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

@igormcoelho, can you check this adjustment on these tests? I just copied the new generated timestamp.

Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't look right... it should increase, never decrease 😂 probably, it is overflowing some int32 size (should be int64 or long, at least).

Copy link
Member Author

Choose a reason for hiding this comment

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

kkkkkkkkkkk
I knew that....
Things need all be long for us. Ram never was a problem when things have vallgrind.

Copy link
Contributor

Choose a reason for hiding this comment

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

What is this date?
How did you guys manage to make 4244941696 be 1968-06-01 00:00:00? Seems weird to me. Maybe the tests were broken all this time?

private void ExtendTimerByFactor(int maxDelayInBlockTimes)
{
TimeSpan nextDelay = expected_delay - (TimeProvider.Current.UtcNow - clock_started) + TimeSpan.FromMilliseconds(maxDelayInBlockTimes * Blockchain.SecondsPerBlock * 1000.0 / context.M);
TimeSpan nextDelay = expected_delay - (TimeProvider.Current.UtcNow - clock_started) + TimeSpan.FromMilliseconds(maxDelayInBlockTimes * Blockchain.MillisecondsPerBlock * 1000 / context.M);
Copy link
Member Author

Choose a reason for hiding this comment

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

Does we need to include this .0 for forcing to float?

Copy link
Contributor

@igormcoelho igormcoelho left a comment

Choose a reason for hiding this comment

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

TimePerBlock ?

neo/Helper.cs Outdated Show resolved Hide resolved
Copy link
Contributor

@lock9 lock9 left a comment

Choose a reason for hiding this comment

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

Fix the dates - We should use 01/01/1970 00:00:00 instead of 01/06/1968 00:00
Use ulong instead of uint.

neo.UnitTests/TestUtils.cs Outdated Show resolved Hide resolved
neo.UnitTests/UT_Block.cs Outdated Show resolved Hide resolved
@@ -79,7 +79,7 @@ public void ConsensusService_Primary_Sends_PrepareRequest_After_OnStart()

Console.WriteLine($"header {header} hash {header.Hash} timstamp {timestampVal}");

timestampVal.Should().Be(4244941696); //1968-06-01 00:00:00
timestampVal.Should().Be(1514007552); //1968-06-01 00:00:00
Copy link
Contributor

Choose a reason for hiding this comment

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

What is this date?
How did you guys manage to make 4244941696 be 1968-06-01 00:00:00? Seems weird to me. Maybe the tests were broken all this time?

neo/Consensus/ConsensusService.cs Show resolved Hide resolved
neo/SmartContract/ApplicationEngine.cs Outdated Show resolved Hide resolved
neo.UnitTests/UT_Header.cs Show resolved Hide resolved
neo/Helper.cs Outdated Show resolved Hide resolved
neo/IO/Json/JNumber.cs Outdated Show resolved Hide resolved
@@ -27,7 +27,7 @@ public static PingPayload Create(uint height, uint nonce)
return new PingPayload
{
LastBlockIndex = height,
Timestamp = DateTime.UtcNow.ToTimestamp(),
Timestamp = DateTime.UtcNow.ToTimestampMS(),
Copy link
Contributor

Choose a reason for hiding this comment

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

It is better to leave everything using the same "unit", what do you think?

neo/ProtocolSettings.cs Show resolved Hide resolved
@lock9 lock9 mentioned this pull request Jul 15, 2019
@vncoelho
Copy link
Member Author

Thanks, @lock9, I am thinking about still waiting a little bit more until @erikzhang and @shargon can give another last check.

neo/Helper.cs Outdated Show resolved Hide resolved
@@ -283,7 +283,10 @@ private RelayResultReason OnNewBlock(Block block)
block_cache_unverified.Remove(blockToPersist.Index);
Persist(blockToPersist);

if (blocksPersisted++ < blocksToPersistList.Count - (2 + Math.Max(0, (15 - SecondsPerBlock)))) continue;
// 15000 is the default among of seconds per block, while MilliSecondsPerBlock is the current
uint extraBlocks = (15000 - MillisecondsPerBlock) / 1000;
Copy link
Member

Choose a reason for hiding this comment

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

15000 is a hardcoded value, you should take this from the config

Copy link
Member Author

Choose a reason for hiding this comment

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

That is right, it has been like this. I just adjusted to ms.
We can do that in another PR, for avoiding other possible mistakes.

Furthermore, I am not good with this config until nowdays...

Copy link
Member

Choose a reason for hiding this comment

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

This, should take the value from the configuration

Copy link
Member

Choose a reason for hiding this comment

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

I don't understand this logic very well ... why it used this?

Copy link
Member Author

Choose a reason for hiding this comment

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

As faster the network is (privatenets with 1s) more blocks are rebroadcasted each time you Persist, limitted to 2+15.

Copy link
Member

@shargon shargon left a comment

Choose a reason for hiding this comment

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

Is possible to store it in 6 bytes instead of 8.

  • 4 for seconds, and 2 more for milliseconds.

We can save 2 bytes.

@vncoelho
Copy link
Member Author

It is possible, @shargon, however, the timestamp in seconds will also expire in 27 years...kkkkkkkk

I think that it is ok as ulong, it will be more clear.

Co-Authored-By: Shargon <shargon@gmail.com>
lock9
lock9 previously approved these changes Jul 19, 2019
@shargon
Copy link
Member

shargon commented Jul 19, 2019

i will review it tomorrow

@shargon shargon self-requested a review July 19, 2019 22:41
This was already from milliseconds, thus, just removing the multiplier
neo/Helper.cs Show resolved Hide resolved
@vncoelho vncoelho merged commit 00f9c27 into master Jul 22, 2019
@vncoelho vncoelho deleted the seconds-to-milliseconds branch July 22, 2019 17:21
@vncoelho
Copy link
Member Author

🚀 aheuaheuaea
It needs tests, but here we go! When the client is ready we gonna be make it happen.

@shargon
Copy link
Member

shargon commented Jul 22, 2019

We should merge it when the tests come

@vncoelho
Copy link
Member Author

vncoelho commented Jul 22, 2019

The basic UTs were accomplished.
But if we do not merge this we will not merge anything, because all other PRs are also missing tests until we have the client, @shargon.

Furthermore, each time more we gonna have to work double because of conflicts between PRs, and after merged we can focused on the next idea.
In fact, we are in a hard situation. But I believe we are close to what we are looking for, my friend.

Thacryba pushed a commit to simplitech/neo that referenced this pull request Feb 17, 2020
Tommo-L pushed a commit to Tommo-L/neo that referenced this pull request Jun 22, 2020
* Seconds to milliseconds

* Sending unsaved files

* fixing formula of consensus bonification

* Refactoring milliseconds

* Refactoring milliseconds from capeslock

* Refactoring milliseconds from capeslock II

* Adjusting UT

* Adjusting UT II

* Super fast protocol to 2s

* Fixing timestamps to long and tests

* Minor adjusts

* Change view deserialization fix

* Timestamp to ulong

* Update neo/Helper.cs

Co-Authored-By: Shargon <shargon@gmail.com>

* Update JNumber.cs

* Optimize and remove TODO

* Update ApplicationEngine.cs

* Fixing ExtendTimerByFactor 

This was already from milliseconds, thus, just removing the multiplier
roman-khimov added a commit to nspcc-dev/dbft that referenced this pull request Jul 11, 2020
Follow-up for 6604647 and
15a7927 to provide Neo 3 compatibility. Neo
PR: neo-project/neo#918.
roman-khimov added a commit to nspcc-dev/dbft that referenced this pull request Jul 11, 2020
Follow-up for 6604647 and
15a7927 to provide Neo 3 compatibility. Neo
PR: neo-project/neo#918.
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.

MSPerBlock / Block Timestamps in ms
6 participants