Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ sp-finality-grandpa = { version = "4.0.0-dev", git = "https://github.com/parityt
sc-client-api = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-runtime = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
sp-timestamp = { version = "4.0.0-dev", git = "https://github.com/paritytech/substrate.git", branch = "master" }
hex-literal = { version = "0.3.1"}

# These dependencies are used for the node template's RPCs
jsonrpc-core = "18.0.0"
Expand Down
32 changes: 22 additions & 10 deletions node/src/chain_spec.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
use integritee_node_runtime::{
AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig, Signature, SudoConfig,
SystemConfig, WASM_BINARY,
};
use integritee_node_runtime::{AccountId, AuraConfig, BalancesConfig, GenesisConfig, GrandpaConfig, Signature, SudoConfig, SystemConfig, WASM_BINARY, TreasuryPalletId};
use sc_service::ChainType;
use sp_consensus_aura::sr25519::AuthorityId as AuraId;
use sp_core::{sr25519, Pair, Public};
use sp_finality_grandpa::AuthorityId as GrandpaId;
use sp_runtime::traits::{IdentifyAccount, Verify};
use sp_runtime::traits::{IdentifyAccount, Verify, AccountIdConversion};

// The URL for the telemetry server.
// const STAGING_TELEMETRY_URL: &str = "wss://telemetry.polkadot.io/submit/";

/// Specialized `ChainSpec`. This is a specialization of the general Substrate ChainSpec type.
pub type ChainSpec = sc_service::GenericChainSpec<GenesisConfig>;

pub const TREASURY_FUNDING_PERCENT: u128 = 5;
pub const ENDOWED_FUNDING: u128 = 1 << 60;
/// Generate a crypto pair from seed.
pub fn get_from_seed<TPublic: Public>(seed: &str) -> <TPublic::Pair as Pair>::Public {
TPublic::Pair::from_string(&format!("//{}", seed), None)
Expand All @@ -35,10 +33,13 @@ where
pub fn authority_keys_from_seed(s: &str) -> (AuraId, GrandpaId) {
(get_from_seed::<AuraId>(s), get_from_seed::<GrandpaId>(s))
}
///Get the account id for the treasury
pub fn treasury_account_id() -> AccountId {
TreasuryPalletId::get().into_account()
}

pub fn development_config() -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;

Ok(ChainSpec::from_genesis(
// Name
"Development",
Expand All @@ -58,6 +59,7 @@ pub fn development_config() -> Result<ChainSpec, String> {
get_account_id_from_seed::<sr25519::Public>("Bob"),
get_account_id_from_seed::<sr25519::Public>("Alice//stash"),
get_account_id_from_seed::<sr25519::Public>("Bob//stash"),
treasury_account_id(),
],
true,
)
Expand All @@ -77,7 +79,6 @@ pub fn development_config() -> Result<ChainSpec, String> {

pub fn local_testnet_config() -> Result<ChainSpec, String> {
let wasm_binary = WASM_BINARY.ok_or_else(|| "Development wasm not available".to_string())?;

Ok(ChainSpec::from_genesis(
// Name
"Local Testnet",
Expand Down Expand Up @@ -105,6 +106,7 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {
get_account_id_from_seed::<sr25519::Public>("Dave//stash"),
get_account_id_from_seed::<sr25519::Public>("Eve//stash"),
get_account_id_from_seed::<sr25519::Public>("Ferdie//stash"),
treasury_account_id(),
],
true,
)
Expand All @@ -130,15 +132,24 @@ fn testnet_genesis(
endowed_accounts: Vec<AccountId>,
_enable_println: bool,
) -> GenesisConfig {

let treasury_funding = (endowed_accounts.len() as u128 - 1u128)* ENDOWED_FUNDING * TREASURY_FUNDING_PERCENT /100u128;
GenesisConfig {
system: SystemConfig {
// Add Wasm runtime to storage.
code: wasm_binary.to_vec(),
changes_trie_config: Default::default(),
},
balances: BalancesConfig {
// Configure endowed accounts with initial balance of 1 << 60.
balances: endowed_accounts.iter().cloned().map(|k| (k, 1 << 60)).collect(),
// Configure endowed accounts with initial balance of ENDOWED_FUNDING and allocate the treasury TREASURY_FUNDING_PERCENT of total supply .
balances: endowed_accounts.iter().cloned().map(|k| {
if k == treasury_account_id()
{
(k, treasury_funding)
} else {
(k, ENDOWED_FUNDING)
}
}).collect(),
},
aura: AuraConfig {
authorities: initial_authorities.iter().map(|x| (x.0.clone())).collect(),
Expand All @@ -150,5 +161,6 @@ fn testnet_genesis(
// Assign network admin rights.
key: root_key,
},
treasury: Default::default(),
}
}
1 change: 1 addition & 0 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,6 @@ runtime-benchmarks = [
"hex-literal",
"pallet-balances/runtime-benchmarks",
"pallet-timestamp/runtime-benchmarks",
"pallet-treasury/runtime-benchmarks",
"sp-runtime/runtime-benchmarks",
]
61 changes: 59 additions & 2 deletions runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,17 +31,20 @@ pub use frame_support::{
constants::{BlockExecutionWeight, ExtrinsicBaseWeight, RocksDbWeight, WEIGHT_PER_SECOND},
IdentityFee, Weight,
},
StorageValue,
PalletId, StorageValue,
};
pub use pallet_balances::Call as BalancesCall;
pub use pallet_timestamp::Call as TimestampCall;
use pallet_transaction_payment::CurrencyAdapter;
#[cfg(any(feature = "std", test))]
pub use sp_runtime::BuildStorage;
pub use sp_runtime::{Perbill, Permill};
use frame_system::EnsureRoot;

/// added by SCS
pub use pallet_teerex;
use frame_support::traits::OnUnbalanced;


/// An index to a block.
pub type BlockNumber = u32;
Expand Down Expand Up @@ -155,6 +158,27 @@ pub fn native_version() -> NativeVersion {
NativeVersion { runtime_version: VERSION, can_author_with: Default::default() }
}

pub struct DealWithFees;
impl OnUnbalanced<pallet_balances::NegativeImbalance<Runtime>> for DealWithFees
{
fn on_unbalanceds<B>(
mut fees_then_tips: impl Iterator<Item = pallet_balances::NegativeImbalance<Runtime>>,
) {
if let Some(fees) = fees_then_tips.next() {
// for fees, 80% to treasury, 20% to author
//let mut split = fees.ration(80, 20);
/* if let Some(tips) = fees_then_tips.next() {
// for tips, if any, 80% to treasury, 20% to author (though this can be anything)
tips.ration_merge_into(80, 20, &mut split);
}
*/
//everything to the Treasury
Treasury::on_unbalanced(fees);
// Author::on_unbalanced(split.1);
}
}
}

const NORMAL_DISPATCH_RATIO: Perbill = Perbill::from_percent(75);

parameter_types! {
Expand Down Expand Up @@ -288,7 +312,7 @@ impl pallet_balances::Config for Runtime {
}

impl pallet_transaction_payment::Config for Runtime {
type OnChargeTransaction = CurrencyAdapter<Balances, ()>;
type OnChargeTransaction = CurrencyAdapter<Balances, DealWithFees>;
type TransactionByteFee = TransactionByteFee;
type WeightToFee = IdentityFee<Balance>;
type FeeMultiplierUpdate = ();
Expand All @@ -314,6 +338,34 @@ impl pallet_teerex::Config for Runtime {
type WeightInfo = pallet_teerex::weights::IntegriteeWeight<Runtime>;
}

parameter_types! {
pub const ProposalBond: Permill = Permill::from_percent(5);
pub const ProposalBondMinimum: Balance = 100 * MILLITEER;
pub const SpendPeriod: BlockNumber = 24 * DAYS;
pub const Burn: Permill = Permill::from_percent(1);
pub const TreasuryPalletId: PalletId = PalletId(*b"py/trsry");
pub const MaxApprovals: u32 = 0; //100
}

type RootOrigin = EnsureRoot<AccountId>;

impl pallet_treasury::Config for Runtime {
type PalletId = TreasuryPalletId;
type Currency = pallet_balances::Pallet<Runtime>;
type ApproveOrigin = RootOrigin;
type RejectOrigin = RootOrigin;
type Event = Event;
type OnSlash = (); //No proposal
type ProposalBond = (); //No proposal
type ProposalBondMinimum = (); //No proposal
type SpendPeriod = SpendPeriod; //Cannot be 0: Error: Thread 'tokio-runtime-worker' panicked at 'attempt to calculate the remainder with a divisor of zero
type Burn = (); //No burn
type BurnDestination = (); //No burn
type SpendFunds = (); //No spend, no bounty
type MaxApprovals = MaxApprovals; //0:cannot approve any proposal
type WeightInfo = ();
}

// Create the runtime by composing the FRAME pallets that were previously configured.
construct_runtime!(
pub enum Runtime where
Expand All @@ -331,6 +383,7 @@ construct_runtime!(
Sudo: pallet_sudo::{Pallet, Call, Config<T>, Storage, Event<T>},
// added by SCS
Teerex: pallet_teerex::{Pallet, Call, Storage, Event<T>},
Treasury: pallet_treasury::{Pallet, Call, Storage, Config, Event<T>},
}
);

Expand Down Expand Up @@ -507,6 +560,7 @@ impl_runtime_apis! {
list_benchmark!(list, extra, frame_system, SystemBench::<Runtime>);
list_benchmark!(list, extra, pallet_balances, Balances);
list_benchmark!(list, extra, pallet_timestamp, Timestamp);
list_benchmark!(list, extra, pallet_treasury, Treasury);

let storage_info = AllPalletsWithSystem::storage_info();

Expand All @@ -532,6 +586,8 @@ impl_runtime_apis! {
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef70a98fdbe9ce6c55837576c60c7af3850").to_vec().into(),
// System Events
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef780d41e5e16056765bc8461851072c9d7").to_vec().into(),
// Treasury Account
hex_literal::hex!("26aa394eea5630e07c48ae0c9558cef7b99d880ec681799c0cf30e8886371da95ecffd7b6c0f78751baa9d281e0bfa3a6d6f646c70792f74727372790000000000000000000000000000000000000000").to_vec().into(),
];

let mut batches = Vec::<BenchmarkBatch>::new();
Expand All @@ -540,6 +596,7 @@ impl_runtime_apis! {
add_benchmark!(params, batches, frame_system, SystemBench::<Runtime>);
add_benchmark!(params, batches, pallet_balances, Balances);
add_benchmark!(params, batches, pallet_timestamp, Timestamp);
add_benchmark!(params, batches, pallet_treasury, Treasury);

if batches.is_empty() { return Err("Benchmark not found for this pallet.".into()) }
Ok(batches)
Expand Down