Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
50562c0
stash precompile changes in other branch and push pallet changes leak…
peektism Oct 20, 2022
9395e66
still leaking std
peektism Oct 20, 2022
8ed14e7
using sp std phantomdata did not fix
peektism Oct 21, 2022
315116a
ty @nanocryk for std leak fix
peektism Oct 21, 2022
8f24362
init referenda precompile needs tryfrom u8 for origins
peektism Oct 23, 2022
d83be8e
referenda submit precompile fn
peektism Oct 23, 2022
21ffc60
signed extrinsics for referenda precompile
peektism Oct 23, 2022
0eb6dc3
preimage precompile
peektism Oct 24, 2022
09e90db
init conviction voting precompile
peektism Oct 24, 2022
138a848
referenda delegate undelegate unlock
peektism Oct 25, 2022
8e1a709
fixes
peektism Oct 26, 2022
276d8a4
fix
peektism Oct 26, 2022
a940199
clean
peektism Oct 26, 2022
a9ab0e3
improve revert reasons for class and index inputs
peektism Oct 26, 2022
9067ba0
clean
peektism Oct 26, 2022
467e845
init accessors and clean
peektism Nov 3, 2022
c6c8d1b
Merge branch 'master' into amar-gov2-precompiles
peektism Nov 7, 2022
4d8f70a
referenda precompile
peektism Nov 16, 2022
a234655
clean
peektism Nov 16, 2022
def4e70
Merge branch 'master' into amar-gov2-precompiles
peektism Nov 21, 2022
e86512c
clean and init referenda precompile interface
peektism Nov 21, 2022
66e5164
into master
peektism Jan 2, 2023
c389722
fix merge
peektism Jan 4, 2023
5bb1673
try mock referenda precompile but did not succeed
peektism Jan 4, 2023
e7c765b
save
peektism Jan 6, 2023
c5e2220
fix referenda mock
nanocryk Jan 9, 2023
d05803f
add dot sol files for preimage and voting
peektism Jan 9, 2023
b784aca
add to moonbase precompiles
peektism Jan 9, 2023
f1c55b5
fix
peektism Jan 10, 2023
58620ed
precompile existence test fix
peektism Jan 10, 2023
6ed417f
update solidity addresses as per moonbase config
peektism Jan 10, 2023
2fcef74
rename standard vote to vote in conviction voting pallet
peektism Jan 11, 2023
8723589
start moving origins out of pallet and using additional generic instead
peektism Jan 11, 2023
a1f469e
fix finish moving pallet custom origins back into runtime
peektism Jan 11, 2023
3e4e868
into master
peektism Jan 11, 2023
72f78a1
Merge branch 'master' into amar-gov2-precompiles
librelois Jan 12, 2023
e1f84ca
add opengov precompiles in proxy evm filter
librelois Jan 12, 2023
6064e97
SolidityConvert no longer necessary
peektism Jan 12, 2023
19c2914
rm SolidityConvert and add Conviction enum
peektism Jan 12, 2023
046a7ac
use trackId as input for submit instead of origin and convert from tr…
peektism Jan 12, 2023
7839709
camelCase error msgs
peektism Jan 12, 2023
3357394
Update precompiles/referenda/src/lib.rs
peektism Jan 12, 2023
5efa9d5
fix conviction precompile interface
peektism Jan 12, 2023
145f6f9
fix referenda precompile interface
peektism Jan 12, 2023
694378d
test to ensure all tracks have min enactment period less than vote lo…
peektism Jan 12, 2023
9bfd9ff
update tracks based on wiki
peektism Jan 12, 2023
a11ee95
revert accidental commit
peektism Jan 12, 2023
a1941ec
fix referenda precompile unit tests
peektism Jan 12, 2023
6e99180
update config based on polkadot 6372 gov2 config tweaks
peektism Jan 12, 2023
83e5a1c
fix
peektism Jan 12, 2023
362fef7
Configure moonriver OpenGov (#2038)
peektism Jan 17, 2023
af079a9
into master
peektism Jan 17, 2023
db81510
remove TryFrom u8 impl for Origin unused
peektism Jan 17, 2023
d3a8bda
split convictionVoting vote into voteYes and voteNo so can add voteAb…
peektism Jan 17, 2023
4c3e81b
fix consistent conversion test
peektism Jan 17, 2023
fd381a7
Merge branch 'master' into amar-gov2-precompiles
peektism Jan 17, 2023
be79f7c
follow suggestions
peektism Jan 17, 2023
dea9998
add doc note to removeOtherVote
peektism Jan 17, 2023
052a56e
into master
peektism Jan 17, 2023
d4782eb
fix
peektism Jan 17, 2023
3cccdb4
Merge branch 'master' into amar-gov2-precompiles
crystalin Jan 18, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
init accessors and clean
  • Loading branch information
peektism committed Nov 3, 2022
commit 467e845e74e025e9a70c6e29099fe44bad0bbf65
22 changes: 9 additions & 13 deletions precompiles/conviction-voting/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,7 @@ where
) -> EvmResult {
let poll_index = Self::u32_to_index(poll_index.converted()).in_field("poll_index")?;
let vote_amount = Self::u256_to_amount(vote_amount).in_field("voteAmount")?;
Comment thread
notlesh marked this conversation as resolved.

let conviction: Conviction = conviction.converted().try_into().map_err(|_| {
RevertReason::custom("Must be an integer between 0 and 6 included")
.in_field("conviction")
})?;
let conviction = Self::u8_to_conviction(conviction.converted()).in_field("conviction")?;
Copy link
Copy Markdown
Collaborator

@girazoki girazoki Jan 11, 2023

Choose a reason for hiding this comment

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

What does conviction represent in solidity? a multiplier? an enum? Perhaps it would be good if u use a u8 that represents an enum instead of asking for a u256? (similar yo what we use in substrate)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

An enum, u8 works but was following the pallet-democracy conventions here https://github.com/PureStake/moonbeam/blob/master/precompiles/pallet-democracy/src/lib.rs#L111

I believe the reason to use U256 is because either way it is U256 in the EVM because this is the smallest variable size. @nanocryk is it something like that

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

The reason I was making the suggestion is because there are other precompiles (like proxy) where the enum is defined in the solidity file, hence developers might have a better notion on what to put: https://github.com/PureStake/moonbeam/blob/6924ede17db074c4d5d530294bc0ff2eb484c674/precompiles/proxy/Proxy.sol#L17


let vote = AccountVote::Standard {
vote: Vote { aye, conviction },
Expand Down Expand Up @@ -138,8 +134,7 @@ where
class: SolidityConvert<U256, u16>,
poll_index: SolidityConvert<U256, u32>,
) -> EvmResult {
let class: Option<ClassOf<Runtime>> =
Some(Self::u16_to_class(class.converted()).in_field("class")?);
let class = Some(Self::u16_to_class(class.converted()).in_field("class")?);
let index = Self::u32_to_index(poll_index.converted()).in_field("poll_index")?;

log::trace!(
Expand Down Expand Up @@ -196,11 +191,7 @@ where
) -> EvmResult {
let class = Self::u16_to_class(class.converted()).in_field("class")?;
let amount = Self::u256_to_amount(amount).in_field("amount")?;

let conviction: Conviction = conviction.converted().try_into().map_err(|_| {
RevertReason::custom("Must be an integer between 0 and 6 included")
.in_field("conviction")
})?;
let conviction = Self::u8_to_conviction(conviction.converted()).in_field("conviction")?;

log::trace!(target: "conviction-voting-precompile",
"Delegating vote to {:?} with balance {:?} and conviction {:?}",
Expand Down Expand Up @@ -241,7 +232,7 @@ where
class: SolidityConvert<U256, u16>,
target: Address,
) -> EvmResult {
let class: ClassOf<Runtime> = Self::u16_to_class(class.converted()).in_field("class")?;
let class = Self::u16_to_class(class.converted()).in_field("class")?;
let target: H160 = target.into();
let target = Runtime::AddressMapping::into_account_id(target);
let target: <Runtime::Lookup as StaticLookup>::Source =
Expand All @@ -259,6 +250,11 @@ where

Ok(())
}
fn u8_to_conviction(conviction: u8) -> MayRevert<Conviction> {
conviction
.try_into()
.map_err(|_| RevertReason::custom("Must be an integer between 0 and 6 included").into())
}
fn u32_to_index(index: u32) -> MayRevert<IndexOf<Runtime>> {
index
.try_into()
Expand Down
92 changes: 89 additions & 3 deletions precompiles/referenda/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,28 @@

use fp_evm::PrecompileHandle;
use frame_support::dispatch::{Dispatchable, GetDispatchInfo, PostDispatchInfo};
use frame_support::traits::{schedule::DispatchTime, OriginTrait};
use frame_support::traits::{schedule::DispatchTime, Currency, OriginTrait};
use pallet_evm::AddressMapping;
use pallet_referenda::Call as ReferendaCall;
use pallet_referenda::{
Call as ReferendaCall, DecidingCount, ReferendumCount, ReferendumInfoFor, TracksInfo,
};
use precompile_utils::prelude::*;
use sp_core::H256;
use sp_core::{H256, U256};
use sp_std::marker::PhantomData;

// #[cfg(test)]
// mod mock;
// #[cfg(test)]
// mod tests;

type BalanceOf<Runtime> = <<Runtime as pallet_referenda::Config>::Currency as Currency<
<Runtime as frame_system::Config>::AccountId,
>>::Balance;
type TrackIdOf<Runtime> = <<Runtime as pallet_referenda::Config>::Tracks as TracksInfo<
BalanceOf<Runtime>,
<Runtime as frame_system::Config>::BlockNumber,
>>::Id;

type OriginOf<Runtime> = <<Runtime as frame_system::Config>::Origin as OriginTrait>::PalletsOrigin;

/// A precompile to wrap the functionality from pallet-referenda.
Expand All @@ -49,7 +59,83 @@ where
<<Runtime as frame_system::Config>::Call as Dispatchable>::Origin:
From<Option<Runtime::AccountId>>,
<Runtime as frame_system::Config>::Call: From<ReferendaCall<Runtime>>,
TrackIdOf<Runtime>: TryFrom<u16>,
{
// The accessors are first. They directly return their result.
#[precompile::public("referendumCount()")]
#[precompile::view]
fn referendum_count(handle: &mut impl PrecompileHandle) -> EvmResult<U256> {
// Fetch data from pallet
handle.record_cost(RuntimeHelper::<Runtime>::db_read_gas_cost())?;
let ref_count = ReferendumCount::<Runtime>::get();
log::trace!(target: "referendum-precompile", "Referendum count from pallet is {:?}", ref_count);

Ok(ref_count.into())
}

#[precompile::public("decidingCount(uint256)")]
#[precompile::view]
fn deciding_count(
handle: &mut impl PrecompileHandle,
track_id: SolidityConvert<U256, u16>,
) -> EvmResult<U256> {
// Fetch data from pallet
handle.record_cost(RuntimeHelper::<Runtime>::db_read_gas_cost())?;
let track_id: TrackIdOf<Runtime> = track_id
.converted()
.try_into()
.map_err(|_| RevertReason::value_is_too_large("Track id type").into())
.in_field("track")?;
let deciding_count = DecidingCount::<Runtime>::get(track_id);
log::trace!(
target: "referendum-precompile", "Track {:?} deciding count is {:?}",
track_id,
deciding_count
);

Ok(deciding_count.into())
}

// #[precompile::public("referendumStatus(uint256)")]
// #[precompile::view]
// fn referendum_status(
// handle: &mut impl PrecompileHandle,
// ref_index: SolidityConvert<U256, u32>,
// ) -> EvmResult<U256> {
// // Fetch data from pallet
// handle.record_cost(RuntimeHelper::<Runtime>::db_read_gas_cost())?;
// let referendum_info = ReferendumInfoFor::<Runtime>::get(ref_index.converted());
// // log::trace!(
// // target: "referendum-precompile", "Track {:?} deciding count is {:?}",
// // track_id,
// // deciding_count
// // );

// // TODO:
// Ok(ref_index.into())
// }

// TODO: function per status variant

#[precompile::public("ongoingReferendumInfoFor(uint256)")]
#[precompile::view]
fn ongoing_referendum_info(
handle: &mut impl PrecompileHandle,
ref_index: SolidityConvert<U256, u32>,
) -> EvmResult<U256> {
// Fetch data from pallet
handle.record_cost(RuntimeHelper::<Runtime>::db_read_gas_cost())?;
Copy link
Copy Markdown
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
Copy Markdown
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.

let referendum_info = ReferendumInfoFor::<Runtime>::get(ref_index.converted());
// log::trace!(
// target: "referendum-precompile", "Track {:?} deciding count is {:?}",
// track_id,
// deciding_count
// );

// TODO:
Ok(ref_index.into())
}

/// Propose a referendum on a privileged action.
///
/// Parameters:
Expand Down