Skip to content

Commit

Permalink
feat: add treasuries, vesting and utility.
Browse files Browse the repository at this point in the history
  • Loading branch information
gdethier committed Feb 6, 2024
1 parent 94a81ad commit 3d70977
Show file tree
Hide file tree
Showing 10 changed files with 1,042 additions and 2,233 deletions.
2,687 changes: 904 additions & 1,783 deletions Cargo.lock

Large diffs are not rendered by default.

96 changes: 15 additions & 81 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@

This project contains Logion's collator node.

Logion is not yet a parachain. It relies on a production-ready (i.e. mainnet) Substrate-based
Logion is now a parachain. However, it still relies on a production-ready (i.e. mainnet) Substrate-based
solochain (see runtime [here](https://github.com/logion-network/logion-node)). The purpose of
this project is to follow the evolution of Logion's parachain runtime in the process of
migrating from the solochain to the parachain. It also enabled to build the runtime
and genesis state for the crowdloan.

[Logion collator node prototype](https://github.com/logion-network/logion-collator-prototype) is aligned,
in terms of features, with the solochain runtime and is a better representation of what this runtime
will look like once the parachain becomes production-ready.
migrating from the solochain to the parachain.

## What to expect next?

Expand All @@ -22,88 +17,17 @@ and future [governance](https://docs.logion.network/logion-white-paper/governanc

## Test locally

Below steps describe the "quick and dirty" way to run your collator node locally and, as a result, be able to test your developments
or play with the network. It does not describe the "production way" of registering a (logion) parachain.

### Prerequisites

Your environment must be ready for Substrate development, see
[here](https://docs.substrate.io/tutorials/v3/create-your-first-substrate-chain/#install-rust-and-the-rust-toolchain)
for a step-by-step guide.
Install [Zombienet](https://github.com/paritytech/zombienet).

### Setup

Below steps show how to instantiate a local logion parachain and its relay chain. If you already followed those steps
and did not clean-up the data, you can just start the nodes (steps 3, 4 and 10).

1. If not already done, download polkadot binaries with command `./scripts/download_polkadot.sh`

2. If relevant (e.g. after an upgrade), regenerate relay chainspec

```
./bin/polkadot build-spec --chain rococo-local --disable-default-bootnode > ./res/local-chainspec.json
./bin/polkadot build-spec --chain ./res/local-chainspec.json --raw --disable-default-bootnode > ./res/local-chainspec.raw.json
```

3. If not already done, build logion collator with command `cargo build --release`

4. Run validator alice with command `./scripts/run_validator.sh alice`

5. Run validator bob with command `./scripts/run_validator.sh bob`
2. If not already done, build logion collator with command `cargo build --release`

6. Reserve para ID

- With [Polkadot.js](https://polkadot.js.org/apps), connect to the local relay chain (`ws://localhost:9944`)
- Go to Network > Parachains > Parathreads
- Click on "+ ParaID" and, with Charlie, register para ID 2000

7. (optional if you did not change the runtime) Generate plain chainspec:

```
./target/release/logion build-spec --chain local --disable-default-bootnode > ./res/local.json
```

8. (optional if you did not change the runtime) Generate raw chainspec

```
./target/release/logion build-spec --chain ./res/local.json --raw --disable-default-bootnode > ./res/local.raw.json
```

9. Generate WASM and genesis state

```
./target/release/logion export-genesis-wasm --chain ./res/local.raw.json > ./bin/local-wasm
./target/release/logion export-genesis-state --chain ./res/local.raw.json > ./bin/local-genesis
```

10. Register parachain

- With [Polkadot.js](https://polkadot.js.org/apps), connect to the local relay chain (`ws://localhost:9944`)
- Go to Developer > Sudo
- Select extrinsic `paraSudoWrapper.sudoScheduleParaInitialize` and set the following parameters:
- id: 2000
- genesisHead: set file `./bin/local-genesis` generated above
- validationCode: set file `./bin/local-wasm` generated above
- parachain: Yes
- Submit the extrinsic

11. Wait for the parathread to be onboard (Network > Parachains > Parathreads)

12. Run collator with command `./scripts/run_collator.sh`

13. Wait for the collator to start producing blocks (spy the parachain's best and finalized block in the logs
or via Polkadot.js's dashboard: Network > Parachains).

14. You may start interacting with the logion parachain using Polkadot.js and connecting to `ws://localhost:8844`.

### Clean-up

Once the two validators and the collator are stopped and you would like to wipe all previously created state,
you can run the following command:

```
rm -rf /tmp/relay /tmp/parachain/
```
3. Run `$ZOMBIENET spawn local-zombienet.toml` where `$ZOMBIENET` is the path to Zombienet binary

## JSON chainspec generation

Expand All @@ -130,3 +54,13 @@ Below, `$CHAIN` is one of `logion`, `logion-dev`, `logion-test` or `local`. It i
```
./target/release/logion export-genesis-state --chain ./res/$CHAIN.raw.json > ./bin/$CHAIN-genesis
```

## Deploy an upgrade

- Build using [`srtool`](https://docs.substrate.io/reference/command-line-tools/srtool/)
- `srtool build --root --package logion-runtime --runtime-dir runtime`
- `parachainSystem.authorizeUpgrade(codeHash, checkVersion)`
- `codeHash`: `BLAKE2_256` field of compressed runtime in `srtool` build output
- `checkVersion`: Yes
- `parachainSystem.enactAuthorizedUpgrade(code)`
- `code`: the compressed runtime produced by `srtool`
22 changes: 22 additions & 0 deletions local-zombienet.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[settings]
provider = "native"

[relaychain]
default_command = "./bin/polkadot"
chain = "rococo-local"

[[relaychain.nodes]]
name = "alice"
validator = true

[[relaychain.nodes]]
name = "bob"
validator = true

[[parachains]]
id = 2000

[parachains.collator]
name = "collator01"
chain = "local"
command = "./target/release/logion"
2 changes: 1 addition & 1 deletion node/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "logion"
version = "0.1.0"
version = "0.2.0"
authors = ['Logion Team <https://github.com/logion-network>']
description = "The logion Collator Node."
license = "Apache 2.0"
Expand Down
3 changes: 3 additions & 0 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,9 @@ fn build_genesis_config(
key: Some(root_key),
},
transaction_payment: Default::default(),
community_treasury: Default::default(),
logion_treasury: Default::default(),
vesting: Default::default(),
}
}

Expand Down
164 changes: 0 additions & 164 deletions res/local-chainspec.raw.json

This file was deleted.

110 changes: 0 additions & 110 deletions res/local.json

This file was deleted.

75 changes: 0 additions & 75 deletions res/local.raw.json

This file was deleted.

7 changes: 6 additions & 1 deletion runtime/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "logion-runtime"
version = "0.1.0"
version = "0.2.0"
authors = ['Logion Team <https://github.com/logion-network>']
description = "The Logion Collator Runtime."
license = "Apache 2.0"
Expand All @@ -15,6 +15,7 @@ targets = ["x86_64-unknown-linux-gnu"]
substrate-wasm-builder = { git = "https://github.com/paritytech/substrate", branch = "polkadot-v1.0.0" }

[dependencies]
ahash = { version = "=0.8.6", default-features = false }
codec = { package = "parity-scale-codec", version = "3.0.0", default-features = false, features = ["derive"] }
hex-literal = { version = "0.4.1", optional = true }
log = { version = "0.4.20", default-features = false }
Expand All @@ -37,6 +38,9 @@ pallet-sudo = { git = "https://github.com/paritytech/substrate", default-feature
pallet-timestamp = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" }
pallet-transaction-payment = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" }
pallet-transaction-payment-rpc-runtime-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" }
pallet-treasury = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" }
pallet-utility = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" }
pallet-vesting = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" }
sp-api = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" }
sp-block-builder = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" }
sp-consensus-aura = { git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v1.0.0" }
Expand Down Expand Up @@ -76,6 +80,7 @@ default = [
"std",
]
std = [
"ahash/std",
"codec/std",
"log/std",
"scale-info/std",
Expand Down
109 changes: 91 additions & 18 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use sp_core::{crypto::KeyTypeId, H160, OpaqueMetadata};
use sp_runtime::{
create_runtime_str, generic, impl_opaque_keys,
traits::{
AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT, IdentifyAccount,
One, Verify
AccountIdConversion, AccountIdLookup, BlakeTwo256, Block as BlockT,
ConvertInto, IdentifyAccount, One, Verify,
},
transaction_validity::{TransactionSource, TransactionValidity},
ApplyExtrinsicResult, MultiSignature,
Expand All @@ -31,7 +31,10 @@ use frame_support::{
construct_runtime,
dispatch::DispatchClass,
parameter_types,
traits::{ConstBool, ConstU32, ConstU64, ConstU8, Currency, EitherOfDiverse, Everything, Imbalance, OnUnbalanced},
traits::{
ConstBool, ConstU32, ConstU64, ConstU8, Currency, EitherOfDiverse,
Everything, OnUnbalanced, WithdrawReasons,
},
weights::{
constants::WEIGHT_REF_TIME_PER_SECOND, ConstantMultiplier, Weight,
},
Expand Down Expand Up @@ -161,7 +164,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
spec_name: create_runtime_str!("logion"),
impl_name: create_runtime_str!("logion"),
authoring_version: 1,
spec_version: 1,
spec_version: 2,
impl_version: 0,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down Expand Up @@ -334,26 +337,13 @@ impl pallet_balances::Config for Runtime {
type MaxFreezes = ConstU32<0>;
}

parameter_types! {
pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
pub TreasuryAccountId: AccountId = TreasuryPalletId::get().into_account_truncating();
pub const InclusionFeesToBurnPercent: u32 = 100;
pub const InclusionFeesTreasuryPercent: u32 = 0; // Inclusion fees disabled for the moment
}

type NegativeImbalance = <Balances as Currency<AccountId>>::NegativeImbalance;

pub struct DealWithInclusionFees;

impl OnUnbalanced<NegativeImbalance> for DealWithInclusionFees {

fn on_nonzero_unbalanced(fees: NegativeImbalance) {

let (to_burn, treasury) = fees.ration(InclusionFeesToBurnPercent::get(), InclusionFeesTreasuryPercent::get());
drop(to_burn);
if treasury != NegativeImbalance::zero() {
Balances::resolve_creating(&TreasuryPalletId::get().into_account_truncating(), treasury);
}
drop(fees); // Disable fees distribution for the moment
}
}

Expand Down Expand Up @@ -477,6 +467,81 @@ impl pallet_sudo::Config for Runtime {
type WeightInfo = ();
}

parameter_types! {
pub const LogionTreasuryPalletId: PalletId = PalletId(*b"lg/lgtrs");
pub LogionTreasuryAccountId: AccountId = LogionTreasuryPalletId::get().into_account_truncating();
pub const CommunityTreasuryPalletId: PalletId = PalletId(*b"lg/cmtrs");
pub CommunityTreasuryAccountId: AccountId = CommunityTreasuryPalletId::get().into_account_truncating();

pub const ProposalBond: Permill = Permill::from_percent(5);
pub const ProposalBondMinimum: Balance = 100 * LGNT;
pub const SpendPeriod: BlockNumber = 1 * DAYS;
pub const SpendPayoutPeriod: BlockNumber = 30 * DAYS;
}

type LogionTreasuryType = pallet_treasury::Instance1;
impl pallet_treasury::Config<LogionTreasuryType> for Runtime {
type Currency = Balances;
type ApproveOrigin = EnsureRoot<AccountId>;
type RejectOrigin = EnsureRoot<AccountId>;
type RuntimeEvent = RuntimeEvent;
type OnSlash = LogionTreasury;
type ProposalBond = ProposalBond;
type ProposalBondMinimum = ProposalBondMinimum;
type ProposalBondMaximum = ();
type SpendPeriod = SpendPeriod;
type Burn = ();
type PalletId = LogionTreasuryPalletId;
type BurnDestination = ();
type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>; // Benchmark broken
type SpendFunds = ();
type MaxApprovals = ConstU32<100>;
type SpendOrigin = frame_support::traits::NeverEnsureOrigin<Balance>;
}

type CommunityTreasuryType = pallet_treasury::Instance2;
impl pallet_treasury::Config<CommunityTreasuryType> for Runtime {
type Currency = Balances;
type ApproveOrigin = EnsureRoot<AccountId>;
type RejectOrigin = EnsureRoot<AccountId>;
type RuntimeEvent = RuntimeEvent;
type OnSlash = CommunityTreasury;
type ProposalBond = ProposalBond;
type ProposalBondMinimum = ProposalBondMinimum;
type ProposalBondMaximum = ();
type SpendPeriod = SpendPeriod;
type Burn = ();
type PalletId = CommunityTreasuryPalletId;
type BurnDestination = ();
type WeightInfo = pallet_treasury::weights::SubstrateWeight<Runtime>; // Benchmark broken
type SpendFunds = ();
type MaxApprovals = ConstU32<100>;
type SpendOrigin = frame_support::traits::NeverEnsureOrigin<Balance>;
}

impl pallet_utility::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
type PalletsOrigin = OriginCaller;
type WeightInfo = pallet_utility::weights::SubstrateWeight<Runtime>;
}

parameter_types! {
pub const MinVestedTransfer: Balance = 1 * LGNT;
pub UnvestedFundsAllowedWithdrawReasons: WithdrawReasons =
WithdrawReasons::except(WithdrawReasons::TRANSFER | WithdrawReasons::RESERVE);
}

impl pallet_vesting::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type Currency = Balances;
type BlockNumberToBalance = ConvertInto;
type MinVestedTransfer = MinVestedTransfer;
type WeightInfo = pallet_vesting::weights::SubstrateWeight<Runtime>;
type UnvestedFundsAllowedWithdrawReasons = UnvestedFundsAllowedWithdrawReasons;
const MAX_VESTING_SCHEDULES: u32 = 28;
}

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub enum Runtime {
Expand All @@ -492,6 +557,8 @@ construct_runtime!(

// Governance
Sudo: pallet_sudo = 15,
LogionTreasury: pallet_treasury::<Instance1> = 16,
CommunityTreasury: pallet_treasury::<Instance2> = 17,

// Collator support. The order of these 4 are important and shall not change.
Authorship: pallet_authorship = 20,
Expand All @@ -505,6 +572,12 @@ construct_runtime!(
PolkadotXcm: pallet_xcm = 31,
CumulusXcm: cumulus_pallet_xcm = 32,
DmpQueue: cumulus_pallet_dmp_queue = 33,

// Misc helpers.
Utility: pallet_utility = 40,

// Vesting.
Vesting: pallet_vesting = 50,
}
);

Expand Down

0 comments on commit 3d70977

Please sign in to comment.