Skip to content

Commit

Permalink
Merge pull request #92 from renlabs-dev/main
Browse files Browse the repository at this point in the history
fix: metadata
  • Loading branch information
functor-flow authored Oct 17, 2024
2 parents 0bd0029 + 3914c5a commit 63316a0
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 231 deletions.
40 changes: 12 additions & 28 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 Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fp-evm = { git = "https://github.com/paritytech/frontier", branch = "polkadot-v1
] }
# Frontier FRAME
pallet-base-fee = { git = "https://github.com/paritytech/frontier", branch = "polkadot-v1.10.1", default-features = false }
pallet-dynamic-fee = { git = "https://github.com/gztensor/frontier", branch = "polkadot-v1.10.1", default-features = false }
pallet-dynamic-fee = { git = "https://github.com/paritytech/frontier", branch = "polkadot-v1.10.1", default-features = false }
pallet-ethereum = { git = "https://github.com/paritytech/frontier", branch = "polkadot-v1.10.1", default-features = false }
pallet-evm = { git = "https://github.com/paritytech/frontier", branch = "polkadot-v1.10.1", default-features = false }
pallet-evm-chain-id = { git = "https://github.com/paritytech/frontier", branch = "polkadot-v1.10.1", default-features = false }
Expand Down
4 changes: 0 additions & 4 deletions pallets/faucet/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,10 +72,6 @@ pub mod pallet {
.propagate(true)
.build()
}

fn pre_dispatch(_: &Self::Call) -> Result<(), TransactionValidityError> {
Ok(())
}
}

pub type BalanceOf<T> =
Expand Down
195 changes: 3 additions & 192 deletions pallets/subspace/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,13 @@ use sp_std::collections::btree_set::BTreeSet;
pub mod migrations;

use frame_support::{
dispatch,
dispatch::{DispatchInfo, PostDispatchInfo},
ensure,
traits::{tokens::WithdrawReasons, ConstU32, Currency, ExistenceRequirement, IsSubType},
dispatch, ensure,
traits::{tokens::WithdrawReasons, ConstU32, Currency, ExistenceRequirement},
PalletId,
};

use frame_support::{pallet_prelude::Weight, sp_runtime::transaction_validity::ValidTransaction};
use frame_support::pallet_prelude::Weight;
use parity_scale_codec::{Decode, Encode};
use sp_runtime::{
traits::{DispatchInfoOf, Dispatchable, PostDispatchInfoOf, SignedExtension},
transaction_validity::{TransactionValidity, TransactionValidityError},
};
use sp_std::marker::PhantomData;

// ---------------------------------
Expand Down Expand Up @@ -1071,186 +1065,3 @@ impl<T: Config> Pallet<T> {
0
}
}

#[derive(Debug, PartialEq, Default)]
pub enum CallType {
SetWeights,
AddStake,
TransferStakeMultiple,
TransferMultiple,
TransferStake,
AddStakeMultiple,
RemoveStakeMultiple,
RemoveStake,
AddDelegate,
Register,
AddNetwork,
Update,
#[default]
Other,
}

#[derive(Encode, Decode, Clone, Eq, PartialEq, TypeInfo)]
pub struct SubspaceSignedExtension<T: Config + Send + Sync + TypeInfo>(pub PhantomData<T>);

impl<T: Config + Send + Sync + TypeInfo> Default for SubspaceSignedExtension<T>
where
T::RuntimeCall: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>,
<T as frame_system::Config>::RuntimeCall: IsSubType<Call<T>>,
{
fn default() -> Self {
Self::new()
}
}

impl<T: Config + Send + Sync + TypeInfo> SubspaceSignedExtension<T>
where
T::RuntimeCall: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>,
<T as frame_system::Config>::RuntimeCall: IsSubType<Call<T>>,
{
pub fn new() -> Self {
Self(Default::default())
}

pub fn get_priority_vanilla(who: &T::AccountId) -> u64 {
// Return high priority so that every extrinsic except set_weights function will
// have a higher priority than the set_weights call
// get the current block number
let current_block_number = Pallet::<T>::get_current_block_number();
let balance = Pallet::<T>::get_balance_u64(who);

// this is the current block number minus the last update block number
current_block_number.saturating_add(balance)
}

pub fn get_priority_set_weights(who: &T::AccountId, netuid: u16) -> u64 {
// Return the non vanilla priority for a set weights call.
Pallet::<T>::get_priority_set_weights(who, netuid)
}

#[must_use]
pub fn u64_to_balance(
input: u64,
) -> Option<
<<T as Config>::Currency as Currency<<T as frame_system::Config>::AccountId>>::Balance,
> {
input.try_into().ok()
}
}

impl<T: Config + Send + Sync + TypeInfo> sp_std::fmt::Debug for SubspaceSignedExtension<T> {
fn fmt(&self, f: &mut sp_std::fmt::Formatter) -> sp_std::fmt::Result {
write!(f, "SubspaceSignedExtension")
}
}

impl<T: Config + Send + Sync + TypeInfo> SignedExtension for SubspaceSignedExtension<T>
where
T::RuntimeCall: Dispatchable<Info = DispatchInfo, PostInfo = PostDispatchInfo>,
<T as frame_system::Config>::RuntimeCall: IsSubType<Call<T>>,
{
const IDENTIFIER: &'static str = "SubspaceSignedExtension";

type AccountId = T::AccountId;
type Call = T::RuntimeCall;
type AdditionalSigned = ();
type Pre = (CallType, u64, Self::AccountId);

fn additional_signed(&self) -> Result<Self::AdditionalSigned, TransactionValidityError> {
Ok(())
}

fn validate(
&self,
who: &Self::AccountId,
call: &Self::Call,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> TransactionValidity {
match call.is_sub_type() {
Some(Call::set_weights { netuid, .. }) => {
let priority: u64 = Self::get_priority_set_weights(who, *netuid);
Ok(ValidTransaction {
priority,
longevity: 1,
..Default::default()
})
}
_ => Ok(ValidTransaction {
priority: Self::get_priority_vanilla(who),
..Default::default()
}),
}
}

// NOTE: Add later when we put in a pre and post dispatch step.
fn pre_dispatch(
self,
who: &Self::AccountId,
call: &Self::Call,
_info: &DispatchInfoOf<Self::Call>,
_len: usize,
) -> Result<Self::Pre, TransactionValidityError> {
let who = who.clone();
match call.is_sub_type() {
Some(Call::add_stake { .. }) => Ok((CallType::AddStake, 0, who)),
Some(Call::add_stake_multiple { .. }) => Ok((CallType::AddStakeMultiple, 0, who)),
Some(Call::remove_stake { .. }) => Ok((CallType::RemoveStake, 0, who)),
Some(Call::remove_stake_multiple { .. }) => Ok((CallType::RemoveStakeMultiple, 0, who)),
Some(Call::transfer_stake { .. }) => Ok((CallType::TransferStake, 0, who)),
Some(Call::transfer_multiple { .. }) => Ok((CallType::TransferMultiple, 0, who)),
Some(Call::set_weights { .. }) => Ok((CallType::SetWeights, 0, who)),
Some(Call::register { .. }) => Ok((CallType::Register, 0, who)),
Some(Call::update_module { .. }) => Ok((CallType::Update, 0, who)),
_ => Ok((CallType::Other, 0, who)),
}
}

fn post_dispatch(
maybe_pre: Option<Self::Pre>,
_info: &DispatchInfoOf<Self::Call>,
_post_info: &PostDispatchInfoOf<Self::Call>,
_len: usize,
_result: &dispatch::DispatchResult,
) -> Result<(), TransactionValidityError> {
if let Some((call_type, _transaction_fee, _who)) = maybe_pre {
match call_type {
CallType::SetWeights => {
log::debug!("Not Implemented!");
}
CallType::AddStake => {
log::debug!("Not Implemented! Need to add potential transaction fees here.");
}

CallType::AddStakeMultiple => {
log::debug!("Not Implemented! Need to add potential transaction fees here.");
}
CallType::RemoveStake => {
log::debug!("Not Implemented! Need to add potential transaction fees here.");
}
CallType::RemoveStakeMultiple => {
log::debug!("Not Implemented! Need to add potential transaction fees here.");
}
CallType::TransferStake => {
log::debug!("Not Implemented! Need to add potential transaction fees here.");
}
CallType::TransferStakeMultiple => {
log::debug!("Not Implemented! Need to add potential transaction fees here.");
}
CallType::TransferMultiple => {
log::debug!("Not Implemented! Need to add potential transaction fees here.");
}
CallType::AddNetwork => {
log::debug!("Not Implemented! Need to add potential transaction fees here.");
}
CallType::Register => {
log::debug!("Not Implemented!");
}
_ => {
log::debug!("Not Implemented!");
}
}
}
Ok(())
}
}
5 changes: 0 additions & 5 deletions pallets/subspace/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -285,11 +285,6 @@ impl<T: Config> Pallet<T> {
Address::<T>::remove(netuid, replace_uid);

// HANDLE THE METADATA
Metadata::<T>::insert(
netuid,
&module_key,
Metadata::<T>::get(netuid, &replace_key).unwrap_or_default(),
);
Metadata::<T>::remove(netuid, &replace_key);

// HANDLE THE NAMES
Expand Down
2 changes: 1 addition & 1 deletion runtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ pub const VERSION: RuntimeVersion = RuntimeVersion {
// `spec_version`, and `authoring_version` are the same between Wasm and native.
// This value is set to 100 to notify Polkadot-JS App (https://polkadot.js.org/apps) to use
// the compatible custom types.
spec_version: 122,
spec_version: 123,
impl_version: 1,
apis: RUNTIME_API_VERSIONS,
transaction_version: 1,
Expand Down

0 comments on commit 63316a0

Please sign in to comment.