Skip to content
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

Merged
merged 13 commits into from
Jun 15, 2022
Merged

Timestamp to block number #183

merged 13 commits into from
Jun 15, 2022

Conversation

Orland0x
Copy link
Contributor

@Orland0x Orland0x commented Jun 14, 2022

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:

  • When a proposal is created, the snapshot timestamp is passed to the single slot voting strategy.
  • Fossil is then queried for the latest ethereum block number stored within it, and this number is returned to the voting strategy and stored in a mapping timestamp_to_eth_block_number.
  • When a user casts a vote, again the same snapshot timestamp is passed to the single slot voting strategy.
  • The timestamp_to_eth_block_numbermapping 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.

Orland0x and others added 10 commits June 8, 2022 12:37
* 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>
@Orland0x Orland0x marked this pull request as ready for review June 15, 2022 10:16
@Orland0x Orland0x requested a review from pscott June 15, 2022 10:17
# 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
Copy link
Contributor Author

@Orland0x Orland0x Jun 15, 2022

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.

Copy link
Contributor

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 🤝

Copy link
Contributor Author

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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

@pscott pscott left a 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 :)

contracts/starknet/Space.cairo Show resolved Hide resolved
contracts/starknet/lib/timestamp.cairo Show resolved Hide resolved
# 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
Copy link
Contributor

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?

Copy link
Contributor Author

@Orland0x Orland0x Jun 15, 2022

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

test/shared/parseRPCData.ts Outdated Show resolved Hide resolved
test/shared/setup.ts Show resolved Hide resolved
@Orland0x Orland0x merged commit b8cb0c4 into develop Jun 15, 2022
@Orland0x Orland0x deleted the timestamp_to_block_number branch July 25, 2022 09:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants