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

enable democracy #366

Merged
merged 13 commits into from
Mar 24, 2024
Merged
6 changes: 3 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "encointer-client-notee"
authors = ["encointer.org <[email protected]>"]
edition = "2021"
#keep with node version. major, minor and patch
version = "1.8.1"
version = "1.8.2"

[dependencies]
# todo migrate to clap >=3 https://github.com/encointer/encointer-node/issues/107
Expand Down
2 changes: 1 addition & 1 deletion client/bootstrap_demo_community.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,7 @@ def test_democracy(client, cid):

@click.command()
@click.option('--client', default='../target/release/encointer-client-notee', help='Client binary to communicate with the chain.')
@click.option('--signer', help='optional account keypair creating the community')
@click.option('--signer', default='//Bob', help='optional account keypair creating the community')
@click.option('-u', '--url', default='ws://127.0.0.1', help='URL of the chain.')
@click.option('-p', '--port', default='9944', help='ws-port of the chain.')
@click.option('-l', '--ipfs-local', is_flag=True, help='if set, local ipfs node is used.')
Expand Down
17 changes: 17 additions & 0 deletions client/src/cli_args.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use clap::{App, Arg, ArgMatches};
use encointer_primitives::balances::BalanceType;
use sp_core::{bytes, H256 as Hash};

const ACCOUNT_ARG: &str = "accountid";
Expand Down Expand Up @@ -32,6 +33,7 @@ const PROPOSAL_ID_ARG: &str = "proposal-id";
const VOTE_ARG: &str = "vote";
const REPUTATION_VEC_ARG: &str = "reputation-vec";
const INACTIVITY_TIMEOUT_ARG: &str = "inactivity-timeout";
const NOMINAL_INCOME_ARG: &str = "nominal-income";

pub trait EncointerArgs<'b> {
fn account_arg(self) -> Self;
Expand Down Expand Up @@ -67,6 +69,7 @@ pub trait EncointerArgs<'b> {
fn vote_arg(self) -> Self;
fn reputation_vec_arg(self) -> Self;
fn inactivity_timeout_arg(self) -> Self;
fn nominal_income_arg(self) -> Self;
}

pub trait EncointerArgsExtractor {
Expand Down Expand Up @@ -102,6 +105,7 @@ pub trait EncointerArgsExtractor {
fn vote_arg(&self) -> Option<&str>;
fn reputation_vec_arg(&self) -> Option<Vec<&str>>;
fn inactivity_timeout_arg(&self) -> Option<u32>;
fn nominal_income_arg(&self) -> Option<BalanceType>;
}

impl<'a, 'b> EncointerArgs<'b> for App<'a, 'b> {
Expand Down Expand Up @@ -419,6 +423,15 @@ impl<'a, 'b> EncointerArgs<'b> for App<'a, 'b> {
.help("inactivity timeout"),
)
}
fn nominal_income_arg(self) -> Self {
self.arg(
Arg::with_name(NOMINAL_INCOME_ARG)
.takes_value(true)
.required(true)
.value_name("NOMINAL_INCOME")
.help("nominal income"),
)
}
}

impl<'a> EncointerArgsExtractor for ArgMatches<'a> {
Expand Down Expand Up @@ -536,4 +549,8 @@ impl<'a> EncointerArgsExtractor for ArgMatches<'a> {
fn inactivity_timeout_arg(&self) -> Option<u32> {
self.value_of(INACTIVITY_TIMEOUT_ARG).map(|v| v.parse().unwrap())
}
fn nominal_income_arg(&self) -> Option<BalanceType> {
self.value_of(NOMINAL_INCOME_ARG)
.map(|v| BalanceType::from_num(v.parse::<u128>().unwrap()))
}
}
60 changes: 60 additions & 0 deletions client/src/commands/encointer_democracy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,36 @@ pub fn submit_set_inactivity_timeout_proposal(
})
.into()
}

pub fn submit_update_nominal_income_proposal(
_args: &str,
matches: &ArgMatches<'_>,
) -> Result<(), clap::Error> {
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
let who = matches.account_arg().map(get_pair_from_str).unwrap();
let mut api = get_chain_api(matches).await;
api.set_signer(ParentchainExtrinsicSigner::new(sr25519_core::Pair::from(who.clone())));
let cid =
verify_cid(&api, matches.cid_arg().expect("please supply argument --cid"), None).await;
let new_income = matches.nominal_income_arg().unwrap();
let tx_payment_cid_arg = matches.tx_payment_cid_arg();
set_api_extrisic_params_builder(&mut api, tx_payment_cid_arg).await;

let xt: EncointerXt<_> = compose_extrinsic!(
api,
"EncointerDemocracy",
"submit_proposal",
ProposalAction::UpdateNominalIncome(cid, new_income)
)
.unwrap();
ensure_payment(&api, &xt.encode().into(), tx_payment_cid_arg).await;
let _result = api.submit_and_watch_extrinsic_until(xt, XtStatus::InBlock).await;
println!("Proposal Submitted: Update nominal income for cid {cid} to {new_income}");
Ok(())
})
.into()
}
pub fn list_proposals(_args: &str, matches: &ArgMatches<'_>) -> Result<(), clap::Error> {
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
Expand Down Expand Up @@ -77,6 +107,36 @@ pub fn list_proposals(_args: &str, matches: &ArgMatches<'_>) -> Result<(), clap:
})
.into()
}

pub fn list_enactment_queue(_args: &str, matches: &ArgMatches<'_>) -> Result<(), clap::Error> {
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
let api = get_chain_api(matches).await;
let maybe_at = matches.at_block_arg();
let key_prefix = api
.get_storage_map_key_prefix("EncointerDemocracy", "EnactmentQueue")
.await
.unwrap();
let max_keys = 1000;
let storage_keys = api
.get_storage_keys_paged(Some(key_prefix), max_keys, None, maybe_at)
.await
.unwrap();
if storage_keys.len() == max_keys as usize {
error!("results can be wrong because max keys reached for query")
}
for storage_key in storage_keys.iter() {
let maybe_proposal_id: Option<ProposalIdType> =
api.get_storage_by_key(storage_key.clone(), maybe_at).await.unwrap();
if let Some(proposal_id) = maybe_proposal_id {
println!("{}", proposal_id);
}
}
Ok(())
})
.into()
}

pub fn vote(_args: &str, matches: &ArgMatches<'_>) -> Result<(), clap::Error> {
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
Expand Down
19 changes: 19 additions & 0 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,16 @@ fn main() {
})
.runner(commands::encointer_democracy::submit_set_inactivity_timeout_proposal),
)
.add_cmd(
Command::new("submit-update-nominal-income-proposal")
.description("Submit update nominal income proposal for specified community")
.options(|app| {
app.setting(AppSettings::ColoredHelp)
.account_arg()
.nominal_income_arg()
})
.runner(commands::encointer_democracy::submit_update_nominal_income_proposal),
)
.add_cmd(
Command::new("list-proposals")
.description("list all proposals.")
Expand All @@ -571,6 +581,15 @@ fn main() {
})
.runner(commands::encointer_democracy::list_proposals),
)
.add_cmd(
Command::new("list-enactment-queue")
.description("list queued proposal enactments")
.options(|app| {
app.setting(AppSettings::ColoredHelp)
.at_block_arg()
})
.runner(commands::encointer_democracy::list_enactment_queue),
)
.add_cmd(
Command::new("vote")
.description("Submit vote for porposal. Vote is either ay or nay. Reputation vec to be specified as cid1_cindex1,cid2_cindex2,...")
Expand Down
2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repository = "https://github.com/encointer/encointer-node"
# * Align major and minor version with polkadot-sdk major.minor.
# * Bump patch version for new releases, and make it the release tag.
# * The client should follow this version.
version = "1.8.1"
version = "1.8.2"

[[bin]]
name = "encointer-node-notee"
Expand Down
2 changes: 1 addition & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ name = "encointer-node-notee-runtime"
repository = "https://github.com/encointer/encointer-node/"
# minor revision must match node/client
# patch revision must match runtime spec_version
version = "1.8.31"
version = "1.8.32"

[dependencies]
parity-scale-codec = { workspace = true }
Expand Down
7 changes: 4 additions & 3 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("encointer-node-notee"),
impl_name: create_runtime_str!("encointer-node-notee"),
authoring_version: 0,
spec_version: 31,
spec_version: 32,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 5,
Expand Down Expand Up @@ -408,7 +408,8 @@ parameter_types! {

impl pallet_encointer_scheduler::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type OnCeremonyPhaseChange = pallet_encointer_ceremonies::Pallet<Runtime>;
type OnCeremonyPhaseChange =
(pallet_encointer_ceremonies::Pallet<Runtime>, pallet_encointer_democracy::Pallet<Runtime>);
Comment on lines +411 to +412
Copy link
Member Author

Choose a reason for hiding this comment

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

this finally enacts approved proposals upon Registering start

type MomentsPerDay = MomentsPerDay;
type CeremonyMaster = EnsureRoot<AccountId>;
type WeightInfo = weights::pallet_encointer_scheduler::WeightInfo<Runtime>;
Expand Down Expand Up @@ -525,7 +526,7 @@ impl pallet_encointer_faucet::Config for Runtime {
}

parameter_types! {
pub const ConfirmationPeriod:BlockNumber = 20;
pub const ConfirmationPeriod: Moment = 5 * 60 * 1000; // [ms]
pub const ProposalLifetime: Moment = 20 * 60 * 1000; // [ms]
Comment on lines +529 to 530
Copy link
Member Author

Choose a reason for hiding this comment

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

5min confirmation and 20min lifetime seem appropriate for Gesell testing

}

Expand Down
Loading