Skip to content

Commit

Permalink
feat!(runtime): removal of sudo (#774)
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanVerstraete authored Jul 10, 2023
1 parent e7425d0 commit 215a12a
Show file tree
Hide file tree
Showing 15 changed files with 168 additions and 137 deletions.
26 changes: 0 additions & 26 deletions clients/tfchain-client-go/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -662,32 +662,6 @@ func (s *Substrate) GetLastNodeID() (uint32, error) {
return uint32(v), nil
}

// SetNodeCertificate sets the node certificate type
func (s *Substrate) SetNodeCertificate(sudo Identity, id uint32, cert NodeCertification) error {
cl, meta, err := s.GetClient()
if err != nil {
return err
}

c, err := types.NewCall(meta, "TfgridModule.set_node_certification",
id, cert,
)
if err != nil {
return errors.Wrap(err, "failed to create call")
}

su, err := types.NewCall(meta, "Sudo.sudo", c)
if err != nil {
return errors.Wrap(err, "failed to create sudo call")
}

if _, err := s.Call(cl, meta, sudo, su); err != nil {
return errors.Wrap(err, "failed to set node certificate")
}

return nil
}

// SetNodePowerState updates the node uptime to given value
func (s *Substrate) SetNodePowerState(identity Identity, up bool) (hash types.Hash, err error) {
cl, meta, err := s.GetClient()
Expand Down
17 changes: 8 additions & 9 deletions clients/tfchain-client-go/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,27 @@ var (
var moduleErrors = [][]string{
nil, // System
nil, // Timestamp
nil, // Balances
nil, // Utility
nil, // Scheduler
nil, // ValidatorSet
nil, // Session
nil, // Aura
nil, // Grandpa
nil, // TransactionPayment
nil, // Sudo
nil, // Historical
nil, // Authorship
nil, // Balances
nil, // TransactionPayment
tfgridModuleErrors, // TfgridModule
smartContractModuleErrors, // SmartContractModule
tftBridgeModuleErrors, // TFTBridgeModule
nil, // TFTPriceModule
nil, // Scheduler
nil, // TftPriceModule
nil, // BurningModule
nil, // TFKVStore
nil, // RuntimeUpgrade
nil, // Council
nil, // CouncilMembership
nil, // RuntimeUpgrade
nil, // Validator
nil, // Dao
nil, // Utility
nil, // Historical
nil, // Validator
}

// https://github.com/threefoldtech/tfchain_pallets/blob/bc9c5d322463aaf735212e428da4ea32b117dc24/pallet-smart-contract/src/lib.rs#L58
Expand Down
8 changes: 4 additions & 4 deletions docs/misc/adding_validators.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,10 @@ proofs: 0

## Contact admin to insert the key into the validator set

An admin with access to the sudo key can call following extrinsic to insert the new node as a validator. For Devnet, is found in encrypted repo.
Create a council motion to add a new validator.

Submit the transaction with the SUDO key!

`Developer` -> `Extrinsics` -> `sudo` -> `sudo(call)` -> -> `validatorSet` -> `addValidator` -> `validatorId` must be the account of the node you are adding
`Council` -> `Propose Motion` -> `validatorSet` -> `addValidator` -> `validatorId` must be the account of the node you are adding

validatorID: SS58 encoded address of newly generated keypair (aura sr25519 key generated using 'subkey generate')

Let other council members know and ask them to vote on the proposal.
6 changes: 3 additions & 3 deletions docs/misc/initializing_runtime.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Initialize runtime for Threefold Grid 3.0

We need to initialize the runtime with a couple of objects to ensure the correct workflow. These policies can only be inserted with a `sudo` key, in order to ensure the objects cannot be changed by malicious users.
We need to initialize the runtime with a couple of objects to ensure the correct workflow. These policies can only be inserted with a council motion, in order to ensure the objects cannot be changed by malicious users.

Objects should be inserted through the Polkadot UI for now.

Expand All @@ -10,7 +10,7 @@ See this document: https://wiki.threefold.io/#/threefold__grid_pricing

We should insert the values for the prices defined in the wiki in our runtime.

Browse to `polkadot UI -> extrinsics -> sudo -> sudo(call) -> tfgridModule -> createPricingPolicy`
Browse to `polkadot UI -> extrinsics -> council -> Propose motion -> tfgridModule -> createPricingPolicy`

Given the values on the wiki the following object should be stored:

Expand Down Expand Up @@ -52,7 +52,7 @@ See this document: https://wiki.threefold.io/#/threefold__grid_pricing

We should insert the values for the prices defined in the wiki in our runtime.

Browse to `polkadot UI -> extrinsics -> sudo -> sudo(call) -> tfgridModule -> createFarmingPolicy`
Browse to `polkadot UI -> extrinsics -> council -> Propose motion -> tfgridModule -> createFarmingPolicy`

Given the values on the wiki the following *objects* should be stored:

Expand Down
15 changes: 0 additions & 15 deletions substrate-node/Cargo.lock

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

1 change: 0 additions & 1 deletion substrate-node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ pallet-membership = {git = "https://github.com/paritytech/substrate", default-fe
pallet-scheduler = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"}
pallet-session = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"}
pallet-session-benchmarking = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"}
pallet-sudo = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"}
pallet-timestamp = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"}
pallet-transaction-payment = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"}
pallet-transaction-payment-rpc = {git = "https://github.com/paritytech/substrate", default-features = false, branch = "polkadot-v0.9.42"}
Expand Down
14 changes: 2 additions & 12 deletions substrate-node/node/src/chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use std::convert::TryInto;
use tfchain_runtime::opaque::SessionKeys;
use tfchain_runtime::{
AccountId, AuraConfig, BalancesConfig, CouncilConfig, CouncilMembershipConfig, GenesisConfig,
GrandpaConfig, SessionConfig, Signature, SmartContractModuleConfig, SudoConfig, SystemConfig,
GrandpaConfig, SessionConfig, Signature, SmartContractModuleConfig, SystemConfig,
TFTBridgeModuleConfig, TFTPriceModuleConfig, TfgridModuleConfig, ValidatorSetConfig,
WASM_BINARY,
};
Expand Down Expand Up @@ -87,8 +87,6 @@ pub fn development_config() -> Result<ChainSpec, String> {
vec![
authority_keys_from_seed("Alice"),
],
// Sudo account
get_account_id_from_seed::<sr25519::Public>("Alice"),
// Foundation account
get_account_id_from_seed::<sr25519::Public>("Eve"),
// Sales account
Expand Down Expand Up @@ -172,8 +170,6 @@ pub fn local_testnet_config() -> Result<ChainSpec, String> {
authority_keys_from_seed("Alice"),
authority_keys_from_seed("Bob"),
],
// Sudo account
get_account_id_from_seed::<sr25519::Public>("Alice"),
// Foundation account
get_account_id_from_seed::<sr25519::Public>("Eve"),
// Sales account
Expand Down Expand Up @@ -262,8 +258,6 @@ pub fn live_config() -> Result<ChainSpec, String> {
wasm_binary,
// Initial PoA authorities
vec![authority_keys_from_seed("Alice")],
// Sudo account
get_account_id_from_seed::<sr25519::Public>("Alice"),
// Foundation account
get_account_id_from_seed::<sr25519::Public>("Alice"),
// Sales account
Expand Down Expand Up @@ -301,7 +295,6 @@ pub fn live_config() -> Result<ChainSpec, String> {
fn testnet_genesis(
wasm_binary: &[u8],
initial_authorities: Vec<(AccountId, AuraId, GrandpaId)>,
root_key: AccountId,
foundation_account: AccountId,
sales_account: AccountId,
endowed_accounts: Vec<AccountId>,
Expand Down Expand Up @@ -345,16 +338,13 @@ fn testnet_genesis(
})
.collect::<Vec<_>>(),
},
transaction_payment: Default::default(),
aura: AuraConfig {
authorities: vec![],
},
grandpa: GrandpaConfig {
authorities: vec![],
},
sudo: SudoConfig {
// Assign network admin rights.
key: Some(root_key),
},
tfgrid_module: TfgridModuleConfig {
su_price_value: 50000,
su_price_unit: 4,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ impl<T: Config> OnRuntimeUpgrade for ReworkBillingLoopInsertion<T> {
#[cfg(feature = "try-runtime")]
fn post_upgrade(_: Vec<u8>) -> Result<(), &'static str> {
info!("current pallet version: {:?}", PalletVersion::<T>::get());
assert!(PalletVersion::<T>::get() == types::StorageVersion::V10);
assert!(PalletVersion::<T>::get() >= types::StorageVersion::V10);

super::v9::check_contracts_to_bill_at::<T>();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl<T: Config> OnRuntimeUpgrade for ExtendContractLock<T> {
}

fn on_runtime_upgrade() -> Weight {
if PalletVersion::<T>::get() >= types::StorageVersion::V10 {
if PalletVersion::<T>::get() == types::StorageVersion::V10 {
migrate_to_version_11::<T>()
} else {
info!(" >>> Unused Smart Contract pallet V11 migration");
Expand Down
3 changes: 0 additions & 3 deletions substrate-node/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ tfchain-support.workspace = true
pallet-aura.workspace = true
pallet-balances.workspace = true
pallet-grandpa.workspace = true
pallet-sudo.workspace = true
pallet-timestamp.workspace = true
pallet-transaction-payment.workspace = true
pallet-session = {workspace = true, features = ["historical"]}
Expand Down Expand Up @@ -93,7 +92,6 @@ std = [
"pallet-aura/std",
"pallet-balances/std",
"pallet-grandpa/std",
"pallet-sudo/std",
"pallet-timestamp/std",
"pallet-transaction-payment-rpc-runtime-api/std",
"pallet-transaction-payment/std",
Expand Down Expand Up @@ -152,7 +150,6 @@ try-runtime = [
"pallet-aura/try-runtime",
"pallet-balances/try-runtime",
"pallet-grandpa/try-runtime",
"pallet-sudo/try-runtime",
"pallet-timestamp/try-runtime",
"pallet-transaction-payment/try-runtime",
"pallet-utility/try-runtime",
Expand Down
64 changes: 35 additions & 29 deletions substrate-node/runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,6 @@ impl pallet_transaction_payment::Config for Runtime {
type FeeMultiplierUpdate = ();
}

impl pallet_sudo::Config for Runtime {
type RuntimeEvent = RuntimeEvent;
type RuntimeCall = RuntimeCall;
}

pub type Serial = pallet_tfgrid::pallet::SerialNumberOf<Runtime>;
pub type Loc = pallet_tfgrid::pallet::LocationOf<Runtime>;
pub type Interface = pallet_tfgrid::pallet::InterfaceOf<Runtime>;
Expand Down Expand Up @@ -700,30 +695,40 @@ construct_runtime!(
NodeBlock = opaque::Block,
UncheckedExtrinsic = UncheckedExtrinsic
{
System: frame_system::{Pallet, Call, Config, Storage, Event<T>},
Timestamp: pallet_timestamp::{Pallet, Call, Storage, Inherent},
Balances: pallet_balances::{Pallet, Call, Storage, Config<T>, Event<T>},
ValidatorSet: substrate_validator_set::{Pallet, Call, Storage, Event<T>, Config<T>},
Session: pallet_session::{Pallet, Call, Storage, Event, Config<T>},
Aura: pallet_aura::{Pallet, Config<T>},
Grandpa: pallet_grandpa::{Pallet, Call, Storage, Config, Event},
TransactionPayment: pallet_transaction_payment::{Pallet, Storage, Event<T>},
Sudo: pallet_sudo::{Pallet, Call, Config<T>, Storage, Event<T>},
Authorship: pallet_authorship::{Pallet, Storage},
TfgridModule: pallet_tfgrid::{Pallet, Call, Storage, Event<T>, Config<T>},
SmartContractModule: pallet_smart_contract::{Pallet, Call, Config, Storage, Event<T>},
TFTBridgeModule: pallet_tft_bridge::{Pallet, Call, Config<T>, Storage, Event<T>},
TFTPriceModule: pallet_tft_price::{Pallet, Call, Storage, Config<T>, Event<T>},
Scheduler: pallet_scheduler::{Pallet, Call, Storage, Event<T>},
BurningModule: pallet_burning::{Pallet, Call, Storage, Event<T>},
TFKVStore: pallet_kvstore::{Pallet, Call, Storage, Event<T>},
Council: pallet_collective::<Instance1>::{Pallet, Call, Storage, Origin<T>, Event<T>, Config<T>},
CouncilMembership: pallet_membership::<Instance1>::{Pallet, Call, Storage, Event<T>, Config<T>},
RuntimeUpgrade: pallet_runtime_upgrade::{Pallet, Call},
Validator: pallet_validator::{Pallet, Call, Storage, Event<T>},
Dao: pallet_dao::{Pallet, Call, Storage, Event<T>},
Utility: pallet_utility::{Pallet, Call, Event},
Historical: pallet_session::historical::{Pallet},
// System support
System: frame_system = 0,
Timestamp: pallet_timestamp = 1,
Utility: pallet_utility = 3,
Scheduler: pallet_scheduler = 4,

// Consensus support
ValidatorSet: substrate_validator_set = 10,
Session: pallet_session = 11,
Aura: pallet_aura = 12,
Grandpa: pallet_grandpa = 13,
Historical: pallet_session::historical::{Pallet} = 14,
Authorship: pallet_authorship = 15,

// Money
Balances: pallet_balances = 20,
TransactionPayment: pallet_transaction_payment = 21,

// Custom
TfgridModule: pallet_tfgrid = 25,
SmartContractModule: pallet_smart_contract = 26,
TFTBridgeModule: pallet_tft_bridge = 27,
TFTPriceModule: pallet_tft_price = 28,
BurningModule: pallet_burning = 29,
TFKVStore: pallet_kvstore = 30,
RuntimeUpgrade: pallet_runtime_upgrade = 31,

// Governance
Council: pallet_collective::<Instance1> = 40,
CouncilMembership: pallet_membership::<Instance1> = 41,
Dao: pallet_dao = 43,

// otherwise it requires genesis config, will be deprecated in the future so we can remove later
Validator: pallet_validator::{Pallet, Call, Storage, Event<T>} = 50,
}
);

Expand Down Expand Up @@ -768,6 +773,7 @@ pub type Executive = frame_executive::Executive<
type Migrations = (
pallet_smart_contract::migrations::v10::ReworkBillingLoopInsertion<Runtime>,
pallet_smart_contract::migrations::v11::ExtendContractLock<Runtime>,
migrations::remove_sudo::RemoveSudo<Runtime>,
);

// follows Substrate's non destructive way of eliminating otherwise required
Expand Down
3 changes: 2 additions & 1 deletion substrate-node/runtime/src/migrations/mod.rs
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pub mod tfgrid_v15_smart_contract_v8;
pub mod tfgrid_v15_smart_contract_v8;
pub mod remove_sudo;
18 changes: 18 additions & 0 deletions substrate-node/runtime/src/migrations/remove_sudo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
use frame_system::Config;
use frame_support::{
traits::OnRuntimeUpgrade, weights::Weight, storage::migration
};
use log::debug;
use sp_core::Get;
use sp_std::marker::PhantomData;

pub struct RemoveSudo<T: Config>(PhantomData<T>);

impl<T: Config> OnRuntimeUpgrade for RemoveSudo<T> {
fn on_runtime_upgrade() -> Weight {
debug!("Removing Sudo");
let _ = migration::clear_storage_prefix(b"Sudo", b"Key", b"", None, None);
debug!("Sudo removed");
T::DbWeight::get().writes(1)
}
}
Loading

0 comments on commit 215a12a

Please sign in to comment.