Skip to content

Commit

Permalink
[encointer] introduce democracy and community treasuries (#456)
Browse files Browse the repository at this point in the history
Over the past few months, Encointer has developed a democracy pallet
with one-person-one-vote governance for local communities. We think
we're ready to experiment with our real communities on mainnet.

The governance scope of local democracy is restricted to 

* properties of the local community itself (like amount of [basic
community-issued income](https://book.encointer.org/economics-ubi.html))
* spending of its own treasury funds (currently restricted to KSM). see
[towards
sustainability](https://forum.polkadot.network/t/towards-encointer-self-sustainability/4195)
* petitions (`system.remark`)

Therefore, no special `Origin` is granted which could affect the KSM
token or other parts of Kusama.

In contrast to token voting on *OpenGov*, Encointer democracy aims at
**one-person-one-vote**, enabled by its sybil-resilient
proof-of-personhood protocol. In practice, it will be
one-cycle-attendance-one-vote, which is a pretty decent approximation
with some additional weight given to those who participate in the
protocol more actively

Relevant pallet code
* https://github.com/encointer/pallets/tree/master/democracy
* work partially funded by a [w3f
grant](https://grants.web3.foundation/applications/democratic-governance-1)
* https://github.com/encointer/pallets/tree/master/treasuries / [initial
MVP PR](encointer/pallets#401)

Design documents:
* https://book.encointer.org/protocol-democracy.html
* initial forum post introducing the design:
https://forum.polkadot.network/t/encointers-grassroots-democracy-prototype/9009

Testing on Testnet Gesell
* https://book.encointer.org/tutorials-democracy.html
* https://book.encointer.org/tutorials-treasuries.html

Testing with bot communities (check CI logs)
* encointer/encointer-node#370
  • Loading branch information
brenzi authored Sep 26, 2024
1 parent 12505bb commit 1651f41
Show file tree
Hide file tree
Showing 8 changed files with 249 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- Allow signed origins to send arbitrary XCMs from some system chains ([polkadot-fellows/runtimes#407](https://github.com/polkadot-fellows/runtimes/pull/407))
- Include the Core and Salary pallets into the Fellowship proxy ([polkadot-fellows/runtimes#454](https://github.com/polkadot-fellows/runtimes/pull/454))
- Add new community democracy and treasuries pallets to Encointer ([polkadot-fellows/runtimes#456](https://github.com/polkadot-fellows/runtimes/pull/456))

### Fixed

Expand Down
68 changes: 66 additions & 2 deletions Cargo.lock

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

5 changes: 4 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ emulated-integration-tests-common = { version = "11.0.0" }
encointer-balances-tx-payment = { version = "~13.1.0", default-features = false }
encointer-balances-tx-payment-rpc-runtime-api = { version = "~13.1.0", default-features = false }
encointer-kusama-runtime = { path = "system-parachains/encointer" }
encointer-primitives = { version = "~13.2.0", default-features = false }
encointer-primitives = { version = "~13.3.0", default-features = false }
enumflags2 = { version = "0.7.7" }
frame-benchmarking = { version = "36.0.0", default-features = false }
frame-election-provider-support = { version = "36.0.0", default-features = false }
Expand Down Expand Up @@ -114,9 +114,12 @@ pallet-encointer-ceremonies = { version = "~13.1.0", default-features = false }
pallet-encointer-ceremonies-rpc-runtime-api = { version = "~13.1.0", default-features = false }
pallet-encointer-communities = { version = "~13.1.0", default-features = false }
pallet-encointer-communities-rpc-runtime-api = { version = "~13.1.0", default-features = false }
pallet-encointer-democracy = { version = "~13.3.2", default-features = false }
pallet-encointer-faucet = { version = "~13.2.0", default-features = false }
pallet-encointer-reputation-commitments = { version = "~13.1.0", default-features = false }
pallet-encointer-scheduler = { version = "~13.1.0", default-features = false }
pallet-encointer-treasuries = { version = "~13.3.0", default-features = false }
pallet-encointer-treasuries-rpc-runtime-api = { version = "~13.3.0", default-features = false }
pallet-fast-unstake = { version = "35.0.0", default-features = false }
pallet-glutton = { version = "22.0.0", default-features = false }
pallet-grandpa = { version = "36.0.0", default-features = false }
Expand Down
10 changes: 10 additions & 0 deletions system-parachains/encointer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,12 @@ pallet-encointer-ceremonies = { workspace = true }
pallet-encointer-ceremonies-rpc-runtime-api = { workspace = true }
pallet-encointer-communities = { workspace = true }
pallet-encointer-communities-rpc-runtime-api = { workspace = true }
pallet-encointer-democracy = { workspace = true }
pallet-encointer-faucet = { workspace = true }
pallet-encointer-reputation-commitments = { workspace = true }
pallet-encointer-scheduler = { workspace = true }
pallet-encointer-treasuries = { workspace = true }
pallet-encointer-treasuries-rpc-runtime-api = { workspace = true }


# Substrate
Expand Down Expand Up @@ -132,9 +135,11 @@ runtime-benchmarks = [
"pallet-encointer-bazaar/runtime-benchmarks",
"pallet-encointer-ceremonies/runtime-benchmarks",
"pallet-encointer-communities/runtime-benchmarks",
"pallet-encointer-democracy/runtime-benchmarks",
"pallet-encointer-faucet/runtime-benchmarks",
"pallet-encointer-reputation-commitments/runtime-benchmarks",
"pallet-encointer-scheduler/runtime-benchmarks",
"pallet-encointer-treasuries/runtime-benchmarks",
"pallet-membership/runtime-benchmarks",
"pallet-message-queue/runtime-benchmarks",
"pallet-proxy/runtime-benchmarks",
Expand Down Expand Up @@ -188,9 +193,12 @@ std = [
"pallet-encointer-ceremonies/std",
"pallet-encointer-communities-rpc-runtime-api/std",
"pallet-encointer-communities/std",
"pallet-encointer-democracy/std",
"pallet-encointer-faucet/std",
"pallet-encointer-reputation-commitments/std",
"pallet-encointer-scheduler/std",
"pallet-encointer-treasuries-rpc-runtime-api/std",
"pallet-encointer-treasuries/std",
"pallet-insecure-randomness-collective-flip/std",
"pallet-membership/std",
"pallet-message-queue/std",
Expand Down Expand Up @@ -253,9 +261,11 @@ try-runtime = [
"pallet-encointer-bazaar/try-runtime",
"pallet-encointer-ceremonies/try-runtime",
"pallet-encointer-communities/try-runtime",
"pallet-encointer-democracy/try-runtime",
"pallet-encointer-faucet/try-runtime",
"pallet-encointer-reputation-commitments/try-runtime",
"pallet-encointer-scheduler/try-runtime",
"pallet-encointer-treasuries/try-runtime",
"pallet-insecure-randomness-collective-flip/try-runtime",
"pallet-membership/try-runtime",
"pallet-message-queue/try-runtime",
Expand Down
30 changes: 30 additions & 0 deletions system-parachains/encointer/src/genesis_config_presets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,36 @@ fn encointer_kusama_genesis(
"polkadotXcm": {
"safeXcmVersion": Some(SAFE_XCM_VERSION),
},
"encointerScheduler": {
"currentPhase": CeremonyPhaseType::Registering,
"currentCeremonyIndex": 1,
"phaseDurations": vec![
(CeremonyPhaseType::Registering, 604800000u64), // 7d
(CeremonyPhaseType::Assigning, 86400000u64), // 1d
(CeremonyPhaseType::Attesting, 172800000u64), // 2d
],
},
"encointerCeremonies": {
"ceremonyReward": BalanceType::from_num(1),
"timeTolerance": 600_000u64, // +-10min
"locationTolerance": 1_000, // [m]
"endorsementTicketsPerBootstrapper": 10,
"endorsementTicketsPerReputable": 5,
"reputationLifetime": 5,
"inactivityTimeout": 5, // idle ceremonies before purging community
"meetupTimeOffset": 0,
},
"encointerCommunities": {
"minSolarTripTimeS": 1, // [s]
"maxSpeedMps": 1, // [m/s] suggested would be 83m/s for security,
},
"encointerBalances": {
// for relative adjustment.
"feeConversionFactor": 7_143u32,
},
"encointerFaucet": {
"reserveAmount": 10_000_000_000_000u128,
},
// no need to pass anything to aura, in fact it will panic if we do. Session will take care
// of this. `aura: Default::default()`
})
Expand Down
37 changes: 35 additions & 2 deletions system-parachains/encointer/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ use frame_support::{
traits::{
fungibles::{Balanced, Credit},
tokens::{imbalance::ResolveTo, ConversionToAssetBalance},
ConstBool, ConstU64, Contains, EitherOfDiverse, EqualPrivilegeOnly, InstanceFilter,
TransformOrigin,
ConstBool, ConstU128, ConstU64, Contains, EitherOfDiverse, EqualPrivilegeOnly,
InstanceFilter, TransformOrigin,
},
weights::{ConstantMultiplier, Weight, WeightToFee as _},
PalletId,
Expand Down Expand Up @@ -545,6 +545,29 @@ impl pallet_encointer_faucet::Config for Runtime {
type WeightInfo = weights::pallet_encointer_faucet::WeightInfo<Runtime>;
}

parameter_types! {
pub const ConfirmationPeriod: Moment = 2 * 24 * 3600 * 1000; // [ms]
pub const ProposalLifetime: Moment = 9 * 24 * 3600 * 1000; // [ms]
}

impl pallet_encointer_democracy::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type MaxReputationCount = ConstU32<64>;
type ConfirmationPeriod = ConfirmationPeriod;
type ProposalLifetime = ProposalLifetime;
type MinTurnout = ConstU128<50>; // perthousand of electorate: 1 = 0.1%, 50 = 5.0%
type WeightInfo = weights::pallet_encointer_democracy::WeightInfo<Runtime>;
}

parameter_types! {
pub const TreasuriesPalletId: PalletId = PalletId(*b"trsrysId");
}
impl pallet_encointer_treasuries::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = pallet_balances::Pallet<Runtime>;
type PalletId = TreasuriesPalletId;
}

impl pallet_aura::Config for Runtime {
type AuthorityId = AuraId;
type DisabledValidators = ();
Expand Down Expand Up @@ -724,6 +747,8 @@ construct_runtime! {
EncointerBazaar: pallet_encointer_bazaar = 64,
EncointerReputationCommitments: pallet_encointer_reputation_commitments = 65,
EncointerFaucet: pallet_encointer_faucet = 66,
EncointerDemocracy: pallet_encointer_democracy = 67,
EncointerTreasuries: pallet_encointer_treasuries = 68,
}
}

Expand Down Expand Up @@ -788,6 +813,7 @@ mod benches {
[pallet_encointer_bazaar, EncointerBazaar]
[pallet_encointer_ceremonies, EncointerCeremonies]
[pallet_encointer_communities, EncointerCommunities]
[pallet_encointer_democracy, EncointerDemocracy]
[pallet_encointer_faucet, EncointerFaucet]
[pallet_encointer_reputation_commitments, EncointerReputationCommitments]
[pallet_encointer_scheduler, EncointerScheduler]
Expand Down Expand Up @@ -1031,6 +1057,13 @@ impl_runtime_apis! {
}
}

impl pallet_encointer_treasuries_rpc_runtime_api::TreasuriesApi<Block, AccountId> for Runtime {

fn get_community_treasury_account_unchecked(maybecid: &Option<CommunityIdentifier>) -> AccountId {
EncointerTreasuries::get_community_treasury_account_unchecked(*maybecid)
}
}

impl sp_genesis_builder::GenesisBuilder<Block> for Runtime {
fn build_state(config: Vec<u8>) -> sp_genesis_builder::Result {
build_state::<RuntimeGenesisConfig>(config)
Expand Down
1 change: 1 addition & 0 deletions system-parachains/encointer/src/weights/mod.rs

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

102 changes: 102 additions & 0 deletions system-parachains/encointer/src/weights/pallet_encointer_democracy.rs

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

0 comments on commit 1651f41

Please sign in to comment.