Skip to content

Change block time to millisecond precision in Env #244

Closed
@webmaster128

Description

@webmaster128

We get millisecond precision BFT time from Tendermint (if documentation is correct), which is hopefully propagated without precision loss through Cosmos SDK. To the contract we currently expose second precision, which is a somewhat random choice. It has the drawback that it is very well possible to have two blocks at the same time (in seconds).

I suggest exposing millisecond precision to the contract, that is explicitely truncated from the nanosecond time.Time we have:

	blockTime := time.Date(2009, 11, 17, 20, 34, 58, 651787237, time.UTC)
	fmt.Println(blockTime)
	// 2009-11-17 20:34:58.651787237 +0000 UTC
	
	nsec := blockTime.UnixNano()
	fmt.Println(nsec)
	// 1258490098651787237
	
	msec := blockTime.UnixNano() / 1_000_000
	fmt.Println(msec)
	// 1258490098651

https://play.golang.org/p/KAD-F2mc5aX

Unix time in milliseconds is a common time format, e.g. used as the only native time in JavaScript.

I think it would be nice to include that in some kind of breaking change to make it hard for contract developers to create bugs by this change.

ping @ethanfrey

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already existson holdLet's pause this and come back in a week...

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions