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

Implement OpenGov Precompiles #1885

Merged
merged 61 commits into from Jan 18, 2023
Merged

Implement OpenGov Precompiles #1885

merged 61 commits into from Jan 18, 2023

Conversation

4meta5
Copy link
Contributor

@4meta5 4meta5 commented Oct 20, 2022

MOON-1966

  • referenda precompile
  • conviction-voting precompile
  • preimage precompile
  • solidity interfaces
  • update track configs based on wikis

Follow ups

  • rust precompile unit tests
  • TS test with smart contracts
  • Add more constants, storage items, not included
  • Add events

@4meta5 4meta5 added the A3-inprogress Pull request is in progress. No review needed at this stage. label Oct 20, 2022
@4meta5
Copy link
Contributor Author

4meta5 commented Jan 4, 2023

resolved

@librelois librelois mentioned this pull request Jan 17, 2023
19 tasks
@4meta5 4meta5 added A8-mergeoncegreen Pull request is reviewed well. and removed A0-pleasereview Pull request needs code review. labels Jan 17, 2023
/// * vote_amount: Balance locked for vote
/// * conviction: Conviction multiplier for length of vote lock
#[precompile::public("voteNo(uint32,uint256,uint8)")]
fn vote_no(
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this is very repetitive with vote_yes. I'm not sure why we made this two fns at the solidity interface level, but they don't have to be two fns here (less code duplication).

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think having two separate functions is fine (a boolean is less of an intuitive thing IMHO). But what I do agree with is that the code should be merged for both

Copy link
Collaborator

Choose a reason for hiding this comment

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

We need to anticipate for the future vote with "abstain" making vote support 3 possibilities.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I agree with @girazoki, the best is to create a inner_vote function that takes as parameter the nature of the vote in order to factorize the code.

Copy link
Contributor Author

@4meta5 4meta5 Jan 17, 2023

Choose a reason for hiding this comment

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

We need to anticipate for the future vote with "abstain" making vote support 3 possibilities.

The backwards compatible way is to add a new voteAbstain function when this is exposed.

I think having two separate functions is fine (a boolean is less of an intuitive thing IMHO). But what I do agree with is that the code should be merged for both

Agreed, done

Comment on lines +21 to +22
for file in ["Preimage.sol"] {
for solidity_fn in solidity::get_selectors(file) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Whenever I see for loops in unit tests, my first thought is always about what the test would do if the loops stopped running as intended.

For example, if Preimage.sol were renamed, would this test silently stop doing its job (succeeding even though it started running 0 iterations)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if renamed, would test silently fail

Not sure but I used this test and all tests like this to get the Solidity selectors so I know it's not failing now. This sounds like a reasonable follow up for all precompiles with this test...

#[precompile::view]
fn track_ids(handle: &mut impl PrecompileHandle) -> EvmResult<Vec<u16>> {
// Fetch data from runtime
handle.record_cost(RuntimeHelper::<Runtime>::db_read_gas_cost())?;
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think this comes from storage. Also, it would not account for the scaling per number of tracks.

But maybe those two things cancel each other out, at least for now :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Indeed, tracks info are static hardcoded data, I think we should not account any gas cost here

Copy link
Contributor

Choose a reason for hiding this comment

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

We need to account for some, otherwise you could have a malicious contract do a loop over track_ids() to create spam. But it probably doesn't need to be much

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, it would not account for the scaling per number of tracks. But maybe those two things cancel each other out, at least for now :)

Yes iterating over tracks has some cost. I'll make a follow up ticket. The accurate approach is to benchmark the iteration and charge that weight => gas instead of charging 1 db read.

UnboundedBytes,
)> {
// Fetch data from runtime
handle.record_cost(RuntimeHelper::<Runtime>::db_read_gas_cost())?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Iterating over tracks has some cost. I'll make a follow up ticket. The accurate approach is to benchmark the iteration and charge that weight => gas instead of charging 1 db read.

Copy link
Collaborator

@girazoki girazoki left a comment

Choose a reason for hiding this comment

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

LGTM, I think there might be some left-overs regarding ts-tests and a bit of refactoring but I think thes can be tackled on a follow-up

Copy link
Contributor

@notlesh notlesh left a comment

Choose a reason for hiding this comment

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

Left some nits, but LGTM otherwise

@crystalin crystalin merged commit f680485 into master Jan 18, 2023
@crystalin crystalin deleted the amar-gov2-precompiles branch January 18, 2023 08:59
@crystalin crystalin changed the title Gov2 Precompiles Implement OpenGov Precompiles Jan 20, 2023
@notlesh notlesh added D1-audited👍 PR contains changes to fund-managing logic that has been properly reviewed and externally audited and removed D5-nicetohaveaudit⚠️ PR contains trivial changes to logic that should be properly reviewed. labels Feb 8, 2023
imstar15 pushed a commit to OAK-Foundation/moonbeam that referenced this pull request May 16, 2023
* stash precompile changes in other branch and push pallet changes leaking std librar

* still leaking std

* using sp std phantomdata did not fix

* ty @nanocryk for std leak fix

* init referenda precompile needs tryfrom u8 for origins

* referenda submit precompile fn

* signed extrinsics for referenda precompile

* preimage precompile

* init conviction voting precompile

* referenda delegate undelegate unlock

* fixes

* fix

* clean

* improve revert reasons for class and index inputs

* clean

* init accessors and clean

* referenda precompile

* clean

* clean and init referenda precompile interface

* fix merge

* try mock referenda precompile but did not succeed

* save

* fix referenda mock

* add dot sol files for preimage and voting

* add to moonbase precompiles

* fix

* precompile existence test fix

* update solidity addresses as per moonbase config

* rename standard vote to vote in conviction voting pallet

* start moving origins out of pallet and using additional generic instead

* fix finish moving pallet custom origins back into runtime

* add opengov precompiles in proxy evm filter

* SolidityConvert no longer necessary

Co-authored-by: Éloïs <c@elo.tf>
Co-authored-by: Stephen Shelton <steve@brewcraft.org>

* rm SolidityConvert and add Conviction enum

* use trackId as input for submit instead of origin and convert from trackId to origin based on mapping

* camelCase error msgs

Co-authored-by: Éloïs <c@elo.tf>

* Update precompiles/referenda/src/lib.rs

Co-authored-by: Éloïs <c@elo.tf>

* fix conviction precompile interface

* fix referenda precompile interface

* test to ensure all tracks have min enactment period less than vote locking period

* update tracks based on wiki

* revert accidental commit

* fix referenda precompile unit tests

* update config based on polkadot 6372 gov2 config tweaks

* fix

* Configure moonriver OpenGov (moonbeam-foundation#2038)

* configure opengov for movr

* Staking precompile: candidateAutoCompoundingDelegationCount (moonbeam-foundation#2037)

* candidateAutoCompoundingDelegationCount

* Remove unecessary `.into()`

Co-authored-by: Amar Singh <asinghchrony@protonmail.com>

* typo

Co-authored-by: Stephen Shelton <steve@brewcraft.org>

Co-authored-by: Amar Singh <asinghchrony@protonmail.com>
Co-authored-by: Stephen Shelton <steve@brewcraft.org>

* precompiles

* address some review todos not done yet

* Fixes balance smoke test (moonbeam-foundation#2040)

Co-authored-by: Crystalin None <crystalin@Crystalins-MacBook-Pro.local>

* trackIds getter and full TrackInfo impl with Curves

* patch evm version (moonbeam-foundation#2026)

* Removes treasurer in Moonriver

* Update eth contract code smoke test (moonbeam-foundation#2043)

Change account limit

* Adds OpenGov to Moonriver (moonbeam-foundation#2041)

* Adds OpenGov to Moonriver

* Updates Moonbase

* fmt

* fixes test

* fix impoty

Co-authored-by: nanocryk <6422796+nanocryk@users.noreply.github.com>
Co-authored-by: Stephen Shelton <steve@brewcraft.org>
Co-authored-by: Alan Sapede <alan@purestake.com>
Co-authored-by: Crystalin None <crystalin@Crystalins-MacBook-Pro.local>
Co-authored-by: Crystalin <alan.sapede@gmail.com>
Co-authored-by: Tim B <79199034+timbrinded@users.noreply.github.com>

* remove TryFrom u8 impl for Origin unused

* split convictionVoting vote into voteYes and voteNo so can add voteAbstain in future version without breaking backwards compatibility

* fix consistent conversion test

* follow suggestions

* add doc note to removeOtherVote

* fix

Co-authored-by: nanocryk <6422796+nanocryk@users.noreply.github.com>
Co-authored-by: librelois <c@elo.tf>
Co-authored-by: Stephen Shelton <steve@brewcraft.org>
Co-authored-by: Alan Sapede <alan@purestake.com>
Co-authored-by: Crystalin None <crystalin@Crystalins-MacBook-Pro.local>
Co-authored-by: Crystalin <alan.sapede@gmail.com>
Co-authored-by: Tim B <79199034+timbrinded@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A8-mergeoncegreen Pull request is reviewed well. B7-runtimenoteworthy Changes should be noted in any runtime-upgrade release notes breaking Needs to be mentioned in breaking changes D1-audited👍 PR contains changes to fund-managing logic that has been properly reviewed and externally audited
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants