Skip to content

Commit

Permalink
update paseo runtime v1003000 add paseo-people runtime v1002007
Browse files Browse the repository at this point in the history
  • Loading branch information
paulormart committed Sep 16, 2024
1 parent 6aaec74 commit a47af91
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 31 deletions.
Binary file modified metadata/paseo_metadata.scale
Binary file not shown.
Binary file added metadata/people_paseo_metadata.scale
Binary file not shown.
1 change: 1 addition & 0 deletions src/runtimes/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ subxt metadata --url wss://rpc.turboflakes.io:443/kusama -f bytes > kusama_metad
subxt metadata --url wss://rpc.turboflakes.io:443/polkadot -f bytes > polkadot_metadata.scale
# People Chains
subxt metadata --url wss://sys.turboflakes.io:443/people-westend -f bytes > people_westend_metadata.scale
subxt metadata --url wss://sys.turboflakes.io:443/people-paseo -f bytes > people_paseo_metadata.scale
subxt metadata --url wss://sys.turboflakes.io:443/people-kusama -f bytes > people_kusama_metadata.scale
subxt metadata --url wss://sys.turboflakes.io:443/people-polkadot -f bytes > people_polkadot_metadata.scale
```
Expand Down
65 changes: 34 additions & 31 deletions src/runtimes/paseo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,9 @@ mod node_runtime {}

use node_runtime::{
runtime_types::{
bounded_collections::bounded_vec::BoundedVec, pallet_identity::types::Data,
pallet_nomination_pools::PoolState, polkadot_parachain_primitives::primitives::Id,
polkadot_primitives::v6::DisputeStatement, polkadot_primitives::v6::ValidatorIndex,
polkadot_primitives::v6::ValidityAttestation,
bounded_collections::bounded_vec::BoundedVec, pallet_nomination_pools::PoolState,
polkadot_parachain_primitives::primitives::Id, polkadot_primitives::v7::DisputeStatement,
polkadot_primitives::v7::ValidatorIndex, polkadot_primitives::v7::ValidityAttestation,
polkadot_runtime_parachains::scheduler::common::Assignment,
polkadot_runtime_parachains::scheduler::pallet::CoreOccupied,
sp_arithmetic::per_things::Perbill, sp_consensus_babe::digests::PreDigest,
Expand All @@ -92,6 +91,14 @@ use node_runtime::{
system::events::ExtrinsicFailed,
};

#[subxt::subxt(
runtime_metadata_path = "metadata/people_paseo_metadata.scale",
derive_for_all_types = "PartialEq, Clone"
)]
mod people_node_runtime {}

use people_node_runtime::runtime_types::pallet_identity::types::Data;

type Call = node_runtime::runtime_types::paseo_runtime::RuntimeCall;
type NominationPoolsCall = node_runtime::runtime_types::pallet_nomination_pools::pallet::Call;

Expand Down Expand Up @@ -194,7 +201,7 @@ pub async fn init_and_subscribe_on_chain_events(onet: &Onet) -> Result<(), OnetE
// finalized_head can always be queried so as soon as it changes we process th repective block_hash
let mut blocks_sub = api.blocks().subscribe_best().await?;
while let Some(Ok(best_block)) = blocks_sub.next().await {
debug!("block head {:?} received", best_block.number());
info!("block head {:?} received", best_block.number());
// update records best_block number
process_best_block(&onet, &mut records, best_block.number().into()).await?;

Expand All @@ -205,7 +212,7 @@ pub async fn init_and_subscribe_on_chain_events(onet: &Onet) -> Result<(), OnetE
.chain_get_header(Some(finalized_block_hash))
.await?
{
debug!("finalized block head {:?} in storage", block.number);
info!("finalized block head {:?} in storage", block.number);
// process older blocks that have not been processed first
while let Some(processed_block_number) = latest_block_number_processed {
if block.number as u64 == processed_block_number {
Expand Down Expand Up @@ -288,6 +295,7 @@ pub async fn process_finalized_block(
is_loading: bool,
) -> Result<(), OnetError> {
let start = Instant::now();
debug!("Block #{} to be processed now", block_number);
let api = onet.client().clone();

// DEPRECATE exceptional_blocks, see note below
Expand All @@ -304,20 +312,21 @@ pub async fn process_finalized_block(
// Some(block_hash)
// };

//NOTE: Clone static metadata has it might be useful later to be restored again!
let static_metadata = api.metadata().clone();

// NOTE: To better handle runtime upgrades where the event system.code_updated can only be decoded by the parent metadata,
// (an example is the block_number 15426015 in Kusama) we retrieve first the metadata from parent block
// and use it to decode the current block
//
// and use it to iterate the events, after if no specific breaking changes aredecode the current block
let block_hash_metadata = onet
.rpc()
.chain_get_block_hash(Some((block_number - 1).into()))
.await?;

let metadata = onet.rpc().state_get_metadata(block_hash_metadata).await?;
// debug!("metadata_legacy: {:?}", metadata);
let block_metadata = onet.rpc().state_get_metadata(block_hash_metadata).await?;

// assign metadata to the api
api.set_metadata(metadata);
// Assign block_metadata to the api
api.set_metadata(block_metadata);

let events = api.events().at(block_hash).await?;

Expand Down Expand Up @@ -348,6 +357,15 @@ pub async fn process_finalized_block(
try_run_cache_nomination_pools(block_number, block_hash).await?;
}

// NOTE_1: It might require further testing, but since v1003000 the aproach will be to
// restore the original static_metadata to process the next records!

// NOTE_2: Lookup for exceptions where both metadatas (block_metadata or static_metadatas) need to be passed down
// and apply them where required!

// Restore assignement of static_metadata to the api
api.set_metadata(static_metadata);

// Update records
// Note: this records should be updated after the switch of session
track_records(&onet, records, block_number, block_hash).await?;
Expand Down Expand Up @@ -1861,9 +1879,6 @@ pub async fn run_network_report(records: &Records) -> Result<(), OnetError> {

let mut validators: Validators = Vec::new();

// Load TVP stashes
let tvp_stashes = Vec::new();

// Fetch active validators
let authorities_addr = node_runtime::storage().session().validators();
if let Some(authorities) = api
Expand All @@ -1884,13 +1899,8 @@ pub async fn run_network_report(records: &Records) -> Result<(), OnetError> {
while let Some(Ok(storage_resp)) = iter.next().await {
let stash = get_account_id_from_storage_key(storage_resp.key_bytes);
let mut v = Validator::new(stash.clone());
// TODO: Perhaps we could introduce different kinds of subsets configurable or just disable it
if storage_resp.value.commission != Perbill(1000000000) {
if !tvp_stashes.contains(&stash) {
v.subset = Subset::NONTVP;
} else {
v.subset = Subset::TVP;
}
v.subset = Subset::NONTVP;
} else {
v.subset = Subset::C100;
}
Expand Down Expand Up @@ -2990,7 +3000,7 @@ async fn get_identity(
onet.client().clone()
};

let identity_of_addr = node_runtime::storage().identity().identity_of(stash);
let identity_of_addr = people_node_runtime::storage().identity().identity_of(stash);
match api
.storage()
.at_latest()
Expand All @@ -3008,7 +3018,7 @@ async fn get_identity(
Ok(Some(identity))
}
None => {
let super_of_addr = node_runtime::storage().identity().super_of(stash);
let super_of_addr = people_node_runtime::storage().identity().super_of(stash);
if let Some((parent_account, data)) = api
.storage()
.at_latest()
Expand Down Expand Up @@ -3167,9 +3177,6 @@ pub async fn cache_session_stats_records(
// Collect Nominators data (** heavy duty task **)
let nominators_map = collect_nominators_data(&onet, block.parent_hash).await?;

// Load TVP stashes
let tvp_stashes = Vec::new();

// Fetch active validators
let authorities_addr = node_runtime::storage().session().validators();
if let Some(authorities) = api
Expand Down Expand Up @@ -3209,11 +3216,7 @@ pub async fn cache_session_stats_records(

// verify subset (1_000_000_000 = 100% commission)
v.subset = if commission != 1_000_000_000 {
if !tvp_stashes.contains(&stash) {
Subset::NONTVP
} else {
Subset::TVP
}
Subset::NONTVP
} else {
Subset::C100
};
Expand Down

0 comments on commit a47af91

Please sign in to comment.