-
Notifications
You must be signed in to change notification settings - Fork 400
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
Change block time to millisecond precision in Env #244
Comments
I agree with the argument. We can add that to 0.11 / 1.0 I would change the field name from |
This is blocked on changes to cosmwasm and go-cosmwasm and then coordinate an upgrade |
@marbar3778 Can you tell us if the BFT time documentation Tendermint is up-to-date with respect to precision: is it still milliseconds? I remember working with higher precision in the Tendermint RPC client. |
I don't recall any changes to this. If we did make any changes it would reflect in the docs prior to the release |
At least in Tendermint 0.32 and 0.33 the block headers have 9 fractional digits in their time. Cosmos Hub
Coralnet
So if this is the BFT time (which I am not sure about), then the docs are outdated. Assuming Tendermint provides nanosecond BTF times, I think a better API for CosmWasm would be to keep the time in seconds simple and provide the nanos separately: pub struct BlockInfo {
pub height: u64,
/// Absolute time of the block creation in seconds since the UNIX epoch (00:00:00 on 1970-01-01 UTC).
///
/// The source of this is the [BFT Time in Tendermint](https://docs.tendermint.com/master/spec/consensus/bft-time.html),
/// converted from nanoseconds to second precision by truncating the fractioal part.
pub time: u64,
/// The fractional part of the block time in nanoseconds since `time` (0 to 999999999).
/// Add this to `time` if you need a high precision block time.
///
/// Using chrono:
///
/// ```
/// use chrono::{NaiveDateTime, NaiveDate};
/// let dt = NaiveDateTime::from_timestamp(env.block.time, env.block.time_nanos);
/// ```
///
/// Creating a simple millisecond-precision timestamp (as used in JavaScript):
///
/// ```
/// let millis = (env.block.time * 1_000) + (env.block.time_nanos / 1_000_000)
/// ```
pub time_nanos: u64,
pub chain_id: String,
} |
This is also more backwards compatible. Contracts compiled with the old format would run in a newer chain |
Here is how this change can look for contract developers: CosmWasm/cosmwasm#506 |
VM implementation is done. Blocked by CosmWasm/wasmvm#137. Should be done as part of the 0.11 release. |
Replaced by #271 |
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:
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
The text was updated successfully, but these errors were encountered: