Skip to content

Commit

Permalink
remove native token pallet from the runtime and node
Browse files Browse the repository at this point in the history
  • Loading branch information
AmbientTea committed Oct 2, 2024
1 parent 12d2aa3 commit 31b57d6
Show file tree
Hide file tree
Showing 13 changed files with 18 additions and 174 deletions.
37 changes: 0 additions & 37 deletions Cargo.lock

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

4 changes: 0 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ members = [
"primitives/session-manager",
"primitives/sidechain",
"partner-chains-cli",
"pallets/native-token-management",
"primitives/native-token-management"
]
resolver = "2"

Expand Down Expand Up @@ -205,8 +203,6 @@ authority-selection-inherents = { path = "primitives/authority-selection-inheren
session-manager = { path = "primitives/session-manager", default-features = false }
sp-sidechain = { path = "primitives/sidechain", default-features = false }
chain-params = { path = "primitives/chain-params", default-features = false }
pallet-native-token-management = { path = "pallets/native-token-management", default-features = false }
sp-native-token-management = { path = "primitives/native-token-management", default-features = false }
sc-partner-chains-consensus-aura = { path = "client/consensus/aura", default-features = false }
sp-partner-chains-consensus-aura = { path = "primitives/consensus/aura", default-features = false }
pallet-partner-chains-session = { path = "pallets/partner-chains-session", default-features = false }
Expand Down
5 changes: 2 additions & 3 deletions node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ frame-benchmarking-cli = { workspace = true }
# Local Dependencies
sidechain-runtime = { workspace = true }
sidechain-mc-hash = { workspace = true, features = ["mock"] }
sp-native-token-management = { workspace = true }
main-chain-follower-api = { workspace = true }
db-sync-follower = { workspace = true, features = ["block-source", "candidate-source", "native-token"] }
main-chain-follower-mock = { workspace = true, features = ["block-source", "candidate-source", "native-token"] }
db-sync-follower = { workspace = true, features = ["block-source", "candidate-source"] }
main-chain-follower-mock = { workspace = true, features = ["block-source", "candidate-source"] }
tokio = { workspace = true }
cli-commands = { workspace = true }

Expand Down
35 changes: 3 additions & 32 deletions node/src/inherent_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ use sp_consensus_aura::{
};
use sp_core::Pair;
use sp_inherents::CreateInherentDataProviders;
use sp_native_token_management::{
NativeTokenManagementApi, NativeTokenManagementInherentDataProvider as NativeTokenIDP,
};
use sp_partner_chains_consensus_aura::CurrentSlotProvider;
use sp_runtime::traits::{Block as BlockT, Header, Zero};
use sp_session_validator_management::SessionValidatorManagementApi;
Expand All @@ -50,15 +47,13 @@ where
AuthoritySelectionInputs,
ScEpochNumber,
>,
T::Api: NativeTokenManagementApi<Block>,
{
type InherentDataProviders = (
AuraIDP,
TimestampIDP,
McHashIDP,
AriadneIDP,
BlockBeneficiaryInherentProvider<BeneficiaryId>,
NativeTokenIDP,
);

async fn create_inherent_data_providers(
Expand Down Expand Up @@ -93,22 +88,7 @@ where
"SIDECHAIN_BLOCK_BENEFICIARY",
)?;

let native_token = NativeTokenIDP::new(
client.clone(),
data_sources.native_token.as_ref(),
mc_hash.mc_hash(),
parent_hash.clone(),
)
.await?;

Ok((
slot,
timestamp,
mc_hash,
ariadne_data_provider,
block_beneficiary_provider,
native_token,
))
Ok((slot, timestamp, mc_hash, ariadne_data_provider, block_beneficiary_provider))
}
}

Expand Down Expand Up @@ -136,9 +116,8 @@ where
AuthoritySelectionInputs,
ScEpochNumber,
>,
T::Api: NativeTokenManagementApi<Block>,
{
type InherentDataProviders = (TimestampIDP, AriadneIDP, NativeTokenIDP);
type InherentDataProviders = (TimestampIDP, AriadneIDP);

async fn create_inherent_data_providers(
&self,
Expand Down Expand Up @@ -172,15 +151,7 @@ where
)
.await?;

let native_token = NativeTokenIDP::new(
client.clone(),
data_sources.native_token.as_ref(),
mc_hash,
parent_hash.clone(),
)
.await?;

Ok((timestamp, ariadne_data_provider, native_token))
Ok((timestamp, ariadne_data_provider))
}
}

Expand Down
13 changes: 2 additions & 11 deletions node/src/main_chain_follower.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
use db_sync_follower::native_token::NativeTokenManagementDataSourceImpl;
use db_sync_follower::{
block::{BlockDataSourceImpl, DbSyncBlockDataSourceConfig},
candidates::{cached::CandidateDataSourceCached, CandidatesDataSourceImpl},
metrics::McFollowerMetrics,
};
use main_chain_follower_api::{
BlockDataSource, CandidateDataSource, NativeTokenManagementDataSource,
};
use main_chain_follower_mock::{
block::BlockDataSourceMock, candidate::MockCandidateDataSource,
native_token::NativeTokenDataSourceMock,
};
use main_chain_follower_api::{BlockDataSource, CandidateDataSource};
use main_chain_follower_mock::{block::BlockDataSourceMock, candidate::MockCandidateDataSource};
use sc_service::error::Error as ServiceError;
use std::error::Error;
use std::sync::Arc;
Expand All @@ -19,7 +13,6 @@ use std::sync::Arc;
pub struct DataSources {
pub block: Arc<dyn BlockDataSource + Send + Sync>,
pub candidate: Arc<dyn CandidateDataSource + Send + Sync>,
pub native_token: Arc<dyn NativeTokenManagementDataSource + Send + Sync>,
}

pub(crate) async fn create_cached_main_chain_follower_data_sources(
Expand Down Expand Up @@ -58,7 +51,6 @@ pub fn create_mock_data_sources(
Ok(DataSources {
block: Arc::new(block_data_source_mock),
candidate: Arc::new(MockCandidateDataSource::from_env()?),
native_token: Arc::new(NativeTokenDataSourceMock::new()),
})
}

Expand All @@ -80,6 +72,5 @@ pub async fn create_cached_data_sources(
CandidatesDataSourceImpl::from_config(pool.clone(), metrics_opt.clone()).await?,
CANDIDATES_FOR_EPOCH_CACHE_SIZE,
)?),
native_token: Arc::new(NativeTokenManagementDataSourceImpl { pool, metrics_opt }),
})
}
9 changes: 2 additions & 7 deletions node/src/staging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ use chain_params::SidechainParams;
use sc_service::ChainType;
use sidechain_domain::*;
use sidechain_runtime::{
AccountId, AuraConfig, BalancesConfig, GrandpaConfig, NativeTokenManagementConfig,
RuntimeGenesisConfig, SessionCommitteeManagementConfig, SessionConfig, SidechainConfig,
SudoConfig, SystemConfig,
AccountId, AuraConfig, BalancesConfig, GrandpaConfig, RuntimeGenesisConfig,
SessionCommitteeManagementConfig, SessionConfig, SidechainConfig, SudoConfig, SystemConfig,
};
use sp_core::bytes::from_hex;
use sp_core::{ed25519, sr25519};
Expand Down Expand Up @@ -160,10 +159,6 @@ pub fn staging_genesis(
.collect(),
main_chain_scripts: sp_session_validator_management::MainChainScripts::read_from_env()?,
},
native_token_management: NativeTokenManagementConfig {
main_chain_scripts: sp_native_token_management::MainChainScripts::read_from_env()?,
..Default::default()
},
};

Ok(serde_json::to_value(config).expect("Genesis config must be serialized correctly"))
Expand Down
6 changes: 1 addition & 5 deletions node/src/template_chain_spec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::chain_spec::*;
use chain_params::SidechainParams;
use sc_service::ChainType;
use sidechain_runtime::{
AuraConfig, BalancesConfig, GrandpaConfig, NativeTokenManagementConfig, RuntimeGenesisConfig,
AuraConfig, BalancesConfig, GrandpaConfig, RuntimeGenesisConfig,
SessionCommitteeManagementConfig, SessionConfig, SidechainConfig, SudoConfig, SystemConfig,
};

Expand Down Expand Up @@ -38,10 +38,6 @@ pub fn chain_spec() -> Result<ChainSpec, envy::Error> {
initial_authorities: vec![],
main_chain_scripts: sp_session_validator_management::MainChainScripts::read_from_env()?,
},
native_token_management: NativeTokenManagementConfig {
main_chain_scripts: sp_native_token_management::MainChainScripts::read_from_env()?,
..Default::default()
},
};
let genesis_json = serde_json::to_value(runtime_genesis_config)
.expect("Genesis config must be serialized correctly");
Expand Down
9 changes: 2 additions & 7 deletions node/src/testnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ use chain_params::SidechainParams;
use sc_service::ChainType;
use sidechain_domain::*;
use sidechain_runtime::{
AccountId, AuraConfig, BalancesConfig, GrandpaConfig, NativeTokenManagementConfig,
RuntimeGenesisConfig, SessionCommitteeManagementConfig, SessionConfig, SidechainConfig,
SudoConfig, SystemConfig,
AccountId, AuraConfig, BalancesConfig, GrandpaConfig, RuntimeGenesisConfig,
SessionCommitteeManagementConfig, SessionConfig, SidechainConfig, SudoConfig, SystemConfig,
};
use sidechain_slots::SlotsPerEpoch;
use sp_core::bytes::from_hex;
Expand Down Expand Up @@ -200,10 +199,6 @@ pub fn testnet_genesis(
.collect(),
main_chain_scripts: sp_session_validator_management::MainChainScripts::read_from_env()?,
},
native_token_management: NativeTokenManagementConfig {
main_chain_scripts: sp_native_token_management::MainChainScripts::read_from_env()?,
..Default::default()
},
};

Ok(serde_json::to_value(config).expect("Genesis config must be serialized correctly"))
Expand Down
19 changes: 3 additions & 16 deletions node/src/tests/inherent_data_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ use crate::tests::mock::{test_client, test_create_inherent_data_config};
use crate::tests::runtime_api_mock::{mock_header, TestApi};
use authority_selection_inherents::authority_selection_inputs::AuthoritySelectionInputs;
use main_chain_follower_api::{block::MainchainBlock, mock_services::*};
use sidechain_domain::{
McBlockHash, McBlockNumber, McEpochNumber, McSlotNumber, NativeTokenAmount, ScEpochNumber,
};
use sidechain_domain::{McBlockHash, McBlockNumber, McEpochNumber, McSlotNumber, ScEpochNumber};
use sp_consensus_aura::Slot;
use sp_core::H256;
use sp_inherents::CreateInherentDataProviders;
Expand All @@ -31,15 +29,13 @@ async fn block_proposal_cidp_should_be_created_correctly() {
.await
.unwrap();

let (slot, timestamp, mc_hash, ariadne_data, block_beneficiary, native_token) =
inherent_data_providers;
let (slot, timestamp, mc_hash, ariadne_data, block_beneficiary) = inherent_data_providers;
let mut inherent_data = InherentData::new();
slot.provide_inherent_data(&mut inherent_data).await.unwrap();
timestamp.provide_inherent_data(&mut inherent_data).await.unwrap();
mc_hash.provide_inherent_data(&mut inherent_data).await.unwrap();
ariadne_data.provide_inherent_data(&mut inherent_data).await.unwrap();
block_beneficiary.provide_inherent_data(&mut inherent_data).await.unwrap();
native_token.provide_inherent_data(&mut inherent_data).await.unwrap();
assert_eq!(
inherent_data
.get_data::<Slot>(&sp_consensus_aura::inherents::INHERENT_IDENTIFIER)
Expand All @@ -65,10 +61,6 @@ async fn block_proposal_cidp_should_be_created_correctly() {
.get_data::<AuthoritySelectionInputs>(&sp_session_validator_management::INHERENT_IDENTIFIER)
.unwrap()
.is_some());
assert!(inherent_data
.get_data::<NativeTokenAmount>(&sp_native_token_management::INHERENT_IDENTIFIER)
.unwrap()
.is_some())
}

#[tokio::test]
Expand All @@ -94,11 +86,10 @@ async fn block_verification_cidp_should_be_created_correctly() {
.create_inherent_data_providers(mock_header().hash(), (30.into(), mc_block_hash))
.await
.unwrap();
let (timestamp, ariadne_data_provider, native_token_provider) = inherent_data_providers;
let (timestamp, ariadne_data_provider) = inherent_data_providers;
let mut inherent_data = InherentData::new();
timestamp.provide_inherent_data(&mut inherent_data).await.unwrap();
ariadne_data_provider.provide_inherent_data(&mut inherent_data).await.unwrap();
native_token_provider.provide_inherent_data(&mut inherent_data).await.unwrap();

assert_eq!(
inherent_data.get_data::<Timestamp>(&sp_timestamp::INHERENT_IDENTIFIER).unwrap(),
Expand All @@ -108,8 +99,4 @@ async fn block_verification_cidp_should_be_created_correctly() {
.get_data::<AuthoritySelectionInputs>(&sp_session_validator_management::INHERENT_IDENTIFIER)
.unwrap()
.is_some());
assert!(inherent_data
.get_data::<NativeTokenAmount>(&sp_native_token_management::INHERENT_IDENTIFIER)
.unwrap()
.is_some())
}
2 changes: 1 addition & 1 deletion node/src/tests/mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use std::sync::Arc;

impl From<TestDataSources> for DataSources {
fn from(value: TestDataSources) -> Self {
Self { block: value.block, candidate: value.candidate, native_token: value.native_token }
Self { block: value.block, candidate: value.candidate }
}
}

Expand Down
11 changes: 0 additions & 11 deletions node/src/tests/runtime_api_mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,6 @@ sp_api::mock_impl_runtime_apis! {
}
}
}

impl sp_native_token_management::NativeTokenManagementApi<Block> for TestApi {
fn get_main_chain_scripts() -> sp_native_token_management::MainChainScripts {
sp_native_token_management::MainChainScripts {
native_token_policy_id: Default::default(),
native_token_asset_name: Default::default(),
illiquid_supply_validator_address: Default::default(),

}
}
}
}

impl HeaderBackend<Block> for TestApi {
Expand Down
4 changes: 0 additions & 4 deletions runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ sidechain-domain = { workspace = true, features = ["serde"] }
chain-params = { workspace = true, features = ["serde"] }
sidechain-slots = { workspace = true }
session-manager = { workspace = true }
pallet-native-token-management = { workspace = true }
sp-native-token-management = { workspace = true, features = ["serde"] }
pallet-session-runtime-stub = { workspace = true, default-features = false }

[dev-dependencies]
Expand Down Expand Up @@ -142,8 +140,6 @@ std = [
"sidechain-domain/std",
"sp-inherents/std",
"chain-params/std",
"pallet-native-token-management/std",
"sp-native-token-management/std",
"pallet-session-runtime-stub/std",
]

Expand Down
Loading

0 comments on commit 31b57d6

Please sign in to comment.