factomd icon indicating copy to clipboard operation
factomd copied to clipboard

Timestamp millisecond conversion to time.Time

Open WhoSoup opened this issue 4 years ago • 0 comments

Just came across this bug: when converting a factom Timestamp to a Golang time.Time, the milliseconds are not converted correctly. Example:

	fmt.Println(time.Now())
	ts := primitives.NewTimestampNow()
	fmt.Println(ts.GetTime())

Output:

2020-06-29 14:56:43.556323 +0200 CEST m=+0.002009801
2020-06-29 14:56:43.000556 +0200 CEST

The milliseconds shifted from milliseconds to being microseconds. Fortunately, factomd is mostly using Timestamp internally and doesn't convert to time.Time except for a few cases:

  • The Live API for admin block event ServerFault, DBlock headers, DBlock anchors, Entry Reveals, and Transactions
  • The HoldingList for testing if messages are stale (no major ramifications as long as it's consistent)
  • Processlist checking if messages are out of date (no major ramifications as long as it's consistent)
  • Message filter (no major ramifications as long as it's consistent)

The fix is incredibly simple: https://github.com/FactomProject/factomd/commit/6b9fde5f9c4e316c5d8dce230ed2421f54dbb7aa

However, this might need to wait for a hard fork to be updated. Some nodes accepting messages that are less than 1ms away from being timed out and other nodes rejecting them could be an attack vector.

WhoSoup avatar Jun 29 '20 13:06 WhoSoup