Problem
The SpaceCraft SDK currently offers access to block timestamps in both seconds and milliseconds. They are easy to mix up, which leads to bugs, sometimes hard to track down.
Especially if there will be a mass migration towards millisecond-based management. The most elegant solution is to use stronger typing to distinguish between the two.
Specifically, to use something like TimestampSeconds vs. TimestampMillis. Both are simple wrappers around u64, with no performance penalty. But importantly, they should not be convertible to each other except explicitly. Same for Duration: DurationSeconds vs. DurationMillis.
Note: timestamps and duration are similar, but not identical. The first measures moments in time, the second time intervals. Timestamps cannot be added, but one can add a duration to a timestamp. Subtracting timestamps yields a duration, etc.
Implementation details
We would need 4 types: TimestampSeconds, TimestampMillis, DurationSeconds, DurationMillis.
They are all newtype wrappers around u64. All conversions between them should be explicit.
Operators need to be overloaded for all cases that make sense.
All these types are serializable, identically to u64. This makes the transition from u64 to these types backwards compatible.
In the ABI they should show up as timestamp/duration, not u64, to make it clearer what they represent.
The block timestamp API should switch to new methods, and we should deprecate the existing ones.
Alternative implementation options
I searched for other implementation of timestamp and duration types, but nothing I found fits our needs perfectly. Alternatives include: embedded-time, fugit
Additional considerations
We have a TimelockMapper, which uses seconds. We might want to have a millisecond version in the future.