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
Conversation
resolved |
…stain in future version without breaking backwards compatibility
/// * vote_amount: Balance locked for vote | ||
/// * conviction: Conviction multiplier for length of vote lock | ||
#[precompile::public("voteNo(uint32,uint256,uint8)")] | ||
fn vote_no( |
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.
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).
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.
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
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.
We need to anticipate for the future vote with "abstain" making vote support 3 possibilities.
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.
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.
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.
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
for file in ["Preimage.sol"] { | ||
for solidity_fn in solidity::get_selectors(file) { |
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.
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)?
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.
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())?; |
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.
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 :)
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.
Indeed, tracks info are static hardcoded data, I think we should not account any gas cost here
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.
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
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.
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())?; |
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.
Same as above
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.
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.
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.
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
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.
Left some nits, but LGTM otherwise
* 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>
MOON-1966
Follow ups