Skip to content

Conversation

sdaftuar
Copy link
Member

Fixes #9586

The use of mocktime in test logic means that comparisons between
GetTime() and GetTimeMicros()/1000000 are unreliable since the former
can use mocktime values while the latter always gets the system clock;
this changes the networking code's inactivity checks to consistently
use the system clock for inactivity comparisons.

Also remove some hacks from setmocktime() that are no longer needed,
now that we're using the system clock for nLastSend and nLastRecv.

Please tag for 0.14.

ping @theuni

@fanquake fanquake added this to the 0.14.0 milestone Jan 20, 2017
@theuni
Copy link
Member

theuni commented Jan 21, 2017

Concept ACK. This is non-obvious, but I think it's the way to go for 0.14. Going forward, we really want to use a steady_clock for the net, so we'll need to rethink timing sources altogether.

@maflcko maflcko added the P2P label Jan 21, 2017
@laanwj
Copy link
Member

laanwj commented Jan 23, 2017

utACK

Going forward, we really want to use a steady_clock for the net, so we'll need to rethink timing sources altogether.

There too it helps to use a single timing function everywhere, as preparation.

Also the separation between mock-able and nonmock-able time functions should ideally be made clearer. It's just weird and arbitrary, that GetTime can be mocked and GetTimeMicroseconds is not. I understand why, but it doesn't reflect in the names of the functions at least.

@laanwj
Copy link
Member

laanwj commented Jan 23, 2017

As I understand it on a higher level we (should) have multiple times:

  • System wallclock time: GetTimeMillis() GetTimeMicroseconds() Plain gettimeofday. Should be used for logging, and presenting time to the user anywhere. This could be mockable, rolling it into the next one.
  • Mockable time: GetTime(). gettimeofday, but mockable for testing. Maybe used in network for ban expiration and such, so that that can be tested.
  • Consensus time: GetAdjustedTime() =Mockable time with offset based on clocks of other nodes. Used for block handling/validation.
  • Steady time: (Not yet implemented) Monotonic time to be used for timeouts, time differences, benchmarking, etc. Absolute value has no meaning, only differences have.

One step would be to consistently sort these out. Not based on the unit used (microseconds, milliseconds, seconds) but on the semantic.
(not in this pull of course)

@TheBlueMatt
Copy link
Contributor

Technically this breaks qt's rpcconsole.cpp - it subtracts nLastSend/Recv/nTimeConnected from GetTime(), though I'm not sure it matters.

Add this to the list of things we need to rethink bottom-up for 0.15, but this seems like a sufficient bugfix for 0.14.

@morcos
Copy link
Contributor

morcos commented Jan 23, 2017

utACK modulo addressing Matt's comment about rpcconsole.cpp.
Trivial to just change to GetTimeMicros()/100000 in those 3 locations.

@laanwj
Copy link
Member

laanwj commented Jan 24, 2017

This is repeating ourselves a lot. Why not... hey, let's add a function to do GetTimeMicros()/100000 ! :-)

@sdaftuar
Copy link
Member Author

Added a fixup commit to address the bug in qt/rpcconsole.cpp, and added a wrapper for GetTimeMicros()/1000000.

The use of mocktime in test logic means that comparisons between
GetTime() and GetTimeMicros()/1000000 are unreliable since the former
can use mocktime values while the latter always gets the system clock;
this changes the networking code's inactivity checks to consistently
use the system clock for inactivity comparisons.

Also remove some hacks from setmocktime() that are no longer needed,
now that we're using the system clock for nLastSend and nLastRecv.
@morcos
Copy link
Contributor

morcos commented Jan 25, 2017

utACK 33306c2

@sdaftuar sdaftuar force-pushed the 2017-01-net-time-comparisons branch from 33306c2 to 99464bc Compare January 25, 2017 15:08
@sdaftuar
Copy link
Member Author

Squashed 33306c2 -> 99464bc

@TheBlueMatt
Copy link
Contributor

utACK 99464bc

1 similar comment
@theuni
Copy link
Member

theuni commented Jan 25, 2017

utACK 99464bc

@laanwj laanwj merged commit 99464bc into bitcoin:master Jan 26, 2017
laanwj added a commit that referenced this pull request Jan 26, 2017
99464bc net: Consistently use GetTimeMicros() for inactivity checks (Suhas Daftuar)
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bip68-sequence.py failing on master after recent net changes, due to mocktime interaction
7 participants