diff --git a/metadata/kusama_metadata.scale b/metadata/kusama_metadata.scale index cf50416..67fa4aa 100644 Binary files a/metadata/kusama_metadata.scale and b/metadata/kusama_metadata.scale differ diff --git a/src/records.rs b/src/records.rs index 94ce053..9139c78 100644 --- a/src/records.rs +++ b/src/records.rs @@ -1522,6 +1522,7 @@ pub struct ValidatorProfileRecord { pub mvr: Option, // mvr_session contains the session from where the mvr was last updated pub mvr_session: Option, + // TODO: DEPRECATE is_oversubscribed, after runtime v1.2 no longer needed pub is_oversubscribed: bool, pub is_active: bool, pub is_chilled: bool, diff --git a/src/runtimes/README.md b/src/runtimes/README.md index d189d75..0ecd5d6 100644 --- a/src/runtimes/README.md +++ b/src/runtimes/README.md @@ -10,15 +10,15 @@ TODO: Improve the runtimes implementation without the need of replicating the sa Download metadata from a substrate node, for use with `subxt` codegen. ```bash -subxt metadata --url wss://rpc.polkadot.io:443 -f bytes > polkadot_metadata.scale -subxt metadata --url wss://kusama-rpc.polkadot.io:443 -f bytes > kusama_metadata.scale -subxt metadata --url wss://westend-rpc.polkadot.io:443 -f bytes > westend_metadata.scale +subxt metadata --url wss://rpc.turboflakes.io:443/westend -f bytes > westend_metadata.scale +subxt metadata --url wss://rpc.turboflakes.io:443/kusama -f bytes > kusama_metadata.scale +subxt metadata --url wss://rpc.turboflakes.io:443/polkadot -f bytes > polkadot_metadata.scale ``` Generate runtime API client code from metadata. ```bash -subxt codegen --file polkadot_metadata.scale | rustfmt --edition=2018 --emit=stdout > polkadot_runtime.rs -subxt codegen --file kusama_metadata.scale | rustfmt --edition=2018 --emit=stdout > kusama_runtime.rs -subxt codegen --file westend_metadata.scale | rustfmt --edition=2018 --emit=stdout > westend_runtime.rs +subxt codegen --url wss://rpc.turboflakes.io:443/westend | rustfmt --edition=2018 --emit=stdout > westend_metadata.rs +subxt codegen --url wss://rpc.turboflakes.io:443/kusama | rustfmt --edition=2018 --emit=stdout > kusama_runtime.rs +subxt codegen --url wss://rpc.turboflakes.io:443/polkadot | rustfmt --edition=2018 --emit=stdout > polkadot_runtime.rs ``` diff --git a/src/runtimes/kusama.rs b/src/runtimes/kusama.rs index 7cff48f..99dbc08 100644 --- a/src/runtimes/kusama.rs +++ b/src/runtimes/kusama.rs @@ -81,8 +81,10 @@ 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::v5::CoreOccupied, polkadot_primitives::v5::DisputeStatement, - polkadot_primitives::v5::ValidatorIndex, polkadot_primitives::v5::ValidityAttestation, + polkadot_primitives::v6::DisputeStatement, polkadot_primitives::v6::ValidatorIndex, + polkadot_primitives::v6::ValidityAttestation, + polkadot_runtime_parachains::scheduler::common::Assignment, + polkadot_runtime_parachains::scheduler::pallet::CoreOccupied, sp_arithmetic::per_things::Perbill, sp_consensus_babe::digests::PreDigest, }, session::events::NewSession, @@ -1287,7 +1289,43 @@ pub async fn track_records( .fetch(&last_runtime_upgrade_addr) .await? { - if info.spec_version >= 1000000 { + // TODO: evaluate how history can also be imported with different metadata + // + // if info.spec_version >= 1000000 && info.spec_version < 1002000 { + // // Fetch availability_cores + // let availability_cores_addr = node_runtime::storage() + // .para_scheduler() + // .availability_cores(); + + // if let Some(availability_cores) = api + // .storage() + // .at(block_hash) + // .fetch(&availability_cores_addr) + // .await? + // { + // for (i, core_occupied) in availability_cores.iter().enumerate() + // { + // let core_idx = u32::try_from(i).unwrap(); + // match &core_occupied { + // CoreOccupied::Free => records.update_core_free( + // core_idx, + // Some(backing_votes.session), + // ), + // CoreOccupied::Paras(paras_entry) => { + // // destructure para_id + // let Id(para_id) = paras_entry.assignment.para_id; + // records.update_core_by_para_id( + // para_id, + // core_idx, + // Some(backing_votes.session), + // ); + // } + // } + // } + // } + // } + + if info.spec_version >= 1002000 { // Fetch availability_cores let availability_cores_addr = node_runtime::storage() .para_scheduler() @@ -1308,13 +1346,26 @@ pub async fn track_records( Some(backing_votes.session), ), CoreOccupied::Paras(paras_entry) => { - // destructure para_id - let Id(para_id) = paras_entry.assignment.para_id; - records.update_core_by_para_id( - para_id, - core_idx, - Some(backing_votes.session), - ); + match ¶s_entry.assignment { + // ParasEntry:: + Assignment::Pool { + para_id: Id(para_id), + core_index: _, + } => { + records.update_core_by_para_id( + para_id.clone(), + core_idx, + Some(backing_votes.session), + ); + } + Assignment::Bulk(Id(para_id)) => { + records.update_core_by_para_id( + para_id.clone(), + core_idx, + Some(backing_votes.session), + ); + } + } } } } @@ -1833,8 +1884,6 @@ pub async fn run_network_report(records: &Records) -> Result<(), OnetError> { } else { v.subset = Subset::TVP; } - v.is_oversubscribed = - verify_oversubscribed(&onet, active_era_index, &stash, None).await?; } else { v.subset = Subset::C100; } @@ -2814,41 +2863,42 @@ async fn try_run_nomination( )) } -async fn verify_oversubscribed( - onet: &Onet, - era_index: u32, - stash: &AccountId32, - block_hash: Option, -) -> Result { - let api = onet.client().clone(); - - let max_addr = node_runtime::constants() - .staking() - .max_nominator_rewarded_per_validator(); - let max: u32 = api.constants().at(&max_addr)?; - - let block_hash = match block_hash { - Some(bh) => bh, - None => onet - .rpc() - .chain_get_block_hash(None) - .await? - .expect("didn't pass a block number; qed"), - }; - - let eras_stakers_addr = node_runtime::storage() - .staking() - .eras_stakers(&era_index, stash); - if let Some(exposure) = api - .storage() - .at(block_hash) - .fetch(&eras_stakers_addr) - .await? - { - return Ok(exposure.others.len() as u32 > max); - } - return Ok(false); -} +// TODO: DEPRECATE, no longer needed after runtime upgrade v1.2 +// async fn verify_oversubscribed( +// onet: &Onet, +// era_index: u32, +// stash: &AccountId32, +// block_hash: Option, +// ) -> Result { +// let api = onet.client().clone(); + +// let max_addr = node_runtime::constants() +// .staking() +// .max_nominator_rewarded_per_validator(); +// let max: u32 = api.constants().at(&max_addr)?; + +// let block_hash = match block_hash { +// Some(bh) => bh, +// None => onet +// .rpc() +// .chain_get_block_hash(None) +// .await? +// .expect("didn't pass a block number; qed"), +// }; + +// let eras_stakers_addr = node_runtime::storage() +// .staking() +// .eras_stakers(&era_index, stash); +// if let Some(exposure) = api +// .storage() +// .at(block_hash) +// .fetch(&eras_stakers_addr) +// .await? +// { +// return Ok(exposure.others.len() as u32 > max); +// } +// return Ok(false); +// } async fn get_own_stake_via_controller( onet: &Onet, @@ -2902,7 +2952,7 @@ async fn get_identity( .fetch(&identity_of_addr) .await? { - Some(identity) => { + Some((identity, _)) => { debug!("identity {:?}", identity); let parent = parse_identity_data(identity.info.display); let identity = match sub_account_name { @@ -3122,11 +3172,6 @@ pub async fn cache_session_stats_records( Subset::C100 }; - // check if is oversubscribed - v.is_oversubscribed = - verify_oversubscribed(&onet, era_index, &stash, Some(block.parent_hash)) - .await?; - // check if is in active set v.is_active = authorities.contains(&stash);