-
Notifications
You must be signed in to change notification settings - Fork 72
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
Timestamp to block number #183
Conversation
* Bump @types/node from 17.0.38 to 17.0.40 (#169) Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 17.0.38 to 17.0.40. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) --- updated-dependencies: - dependency-name: "@types/node" dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump ts-node from 10.8.0 to 10.8.1 (#167) Bumps [ts-node](https://github.com/TypeStrong/ts-node) from 10.8.0 to 10.8.1. - [Release notes](https://github.com/TypeStrong/ts-node/releases) - [Commits](TypeStrong/ts-node@v10.8.0...v10.8.1) --- updated-dependencies: - dependency-name: ts-node dependency-type: direct:development update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * Bump ethereumjs-util from 7.1.4 to 7.1.5 (#168) Bumps [ethereumjs-util](https://github.com/ethereumjs/ethereumjs-monorepo) from 7.1.4 to 7.1.5. - [Release notes](https://github.com/ethereumjs/ethereumjs-monorepo/releases) - [Commits](https://github.com/ethereumjs/ethereumjs-monorepo/compare/ethereumjs-util@7.1.4...ethereumjs-util@7.1.5) --- updated-dependencies: - dependency-name: ethereumjs-util dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
# In the current implementation, we cant store arrays with a zero as the last element because the read function would just treat | ||
# the array is 1 element shorter. Hence, we offset the slot_index by 1 so that it is never zero. | ||
# Probably worth changing our array handling so this is not necessary. | ||
let slot_index = params[1] - 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this isnt ideal. we could change how we store arrays.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah didn't comment on that since I saw this comment. Def agree 🤝
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
opened an issue: #188
let (fact_registry_addr) = fact_registry_store.read() | ||
|
||
let (eth_block_number) = get_eth_block_number(timestamp) | ||
let eth_block_number = eth_block_number - 1 # temp shift - waiting for Fossil fix |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yup, good work man :) Quite some code to review but it's well written :)
# This branch will be taken whenever a vote is cast as the mapping value would be set at proposal creation. | ||
return (number) | ||
else: | ||
# The timestamp has not yet been queried in fossil. Therefore we must query Fossil for the latest eth block |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This means a proposer can't create a proposal with a snapshot that was BEFORE the creation of the proposal right? Like if I create a proposal on second of Jan and I want the snapshot to be taken on the 1st of Jan (one day before), that's not possible, correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well technically you could if the latest block number stored in Fossil was on the 1st. This shouldnt happen though as I expect block hashes to be sent hourly.
The ethereum block number snapshot will always be sometime before the proposal creation, the length of which depends on the regularity of block hashes being sent from L1
With this update, the snapshot of a proposal is made using a timestamp rather than a block number. Specifically, the snapshot is given by the block timestamp at proposal creation obtained via
get_block_timestamp()
. This allows SX to be natively multi-chain as timestamps are universal whereas block numbers are chain dependent.Certain voting strategies do however require a block number, such as the single slot proof strategy. This resolution between timestamp and block number should occur at the voting strategy level and is up to the strategy creator to ensure the validity of the conversion.
For the single slot proof strategy, we provide this functionality within
lib/timestamp.cairo
. It works as follows:timestamp_to_eth_block_number
.timestamp_to_eth_block_number
mapping is then queried with this timestamp which will return the same ethereum block number as before. We therefore ensure that the snapshot block number of the proposal remains constant even if later block hashes are sent to fossil during the period of the proposal.We also add more extensive testing of the single slot proof strategy in this PR.