diff --git a/node/src/components/block_accumulator/tests.rs b/node/src/components/block_accumulator/tests.rs index c6608b3b38..fbcf7153c0 100644 --- a/node/src/components/block_accumulator/tests.rs +++ b/node/src/components/block_accumulator/tests.rs @@ -17,7 +17,7 @@ use tokio::time; use casper_types::{ generate_ed25519_keypair, testing::TestRng, ActivationPoint, BlockV2, ChainNameDigest, Chainspec, ChainspecRawBytes, FinalitySignature, FinalitySignatureV2, ProtocolVersion, - PublicKey, SecretKey, Signature, TestBlockBuilder, U512, + PublicKey, SecretKey, Signature, TestBlockBuilder, TransactionConfig, U512, }; use reactor::ReactorEvent; @@ -197,6 +197,7 @@ impl Reactor for MockReactor { chainspec.core_config.recent_era_count(), Some(registry), false, + TransactionConfig::default(), ) .unwrap(); diff --git a/node/src/components/contract_runtime/operations.rs b/node/src/components/contract_runtime/operations.rs index 34c914f3f3..62ff7514ea 100644 --- a/node/src/components/contract_runtime/operations.rs +++ b/node/src/components/contract_runtime/operations.rs @@ -453,7 +453,7 @@ pub fn execute_finalized_block( ); match scratch_state.distribute_fees(fee_req) { FeeResult::RootNotFound => { - return Err(BlockExecutionError::RootNotFound(state_root_hash)) + return Err(BlockExecutionError::RootNotFound(state_root_hash)); } FeeResult::Failure(fer) => return Err(BlockExecutionError::DistributeFees(fer)), FeeResult::Success { @@ -486,10 +486,10 @@ pub fn execute_finalized_block( ); match scratch_state.distribute_block_rewards(rewards_req) { BlockRewardsResult::RootNotFound => { - return Err(BlockExecutionError::RootNotFound(state_root_hash)) + return Err(BlockExecutionError::RootNotFound(state_root_hash)); } BlockRewardsResult::Failure(bre) => { - return Err(BlockExecutionError::DistributeBlockRewards(bre)) + return Err(BlockExecutionError::DistributeBlockRewards(bre)); } BlockRewardsResult::Success { post_state_hash, .. @@ -513,7 +513,7 @@ pub fn execute_finalized_block( executable_block.era_id.successor(), ) { StepResult::RootNotFound => { - return Err(BlockExecutionError::RootNotFound(state_root_hash)) + return Err(BlockExecutionError::RootNotFound(state_root_hash)); } StepResult::Failure(err) => return Err(BlockExecutionError::Step(err)), StepResult::Success { diff --git a/node/src/components/contract_runtime/tests.rs b/node/src/components/contract_runtime/tests.rs index 07cb6eb709..576089a2d9 100644 --- a/node/src/components/contract_runtime/tests.rs +++ b/node/src/components/contract_runtime/tests.rs @@ -9,7 +9,7 @@ use tempfile::TempDir; use casper_types::{ bytesrepr::Bytes, runtime_args, BlockHash, Chainspec, ChainspecRawBytes, Deploy, Digest, EraId, ExecutableDeployItem, PublicKey, SecretKey, TimeDiff, Timestamp, Transaction, - TransactionCategory, U512, + TransactionCategory, TransactionConfig, U512, }; use super::*; @@ -103,6 +103,7 @@ impl reactor::Reactor for Reactor { RECENT_ERA_COUNT, Some(registry), false, + TransactionConfig::default(), ) .unwrap(); diff --git a/node/src/components/contract_runtime/utils.rs b/node/src/components/contract_runtime/utils.rs index 9d7c038c5e..8675cb3ec5 100644 --- a/node/src/components/contract_runtime/utils.rs +++ b/node/src/components/contract_runtime/utils.rs @@ -86,8 +86,6 @@ pub(super) async fn exec_or_requeue( { debug!("ContractRuntime: execute_finalized_block_or_requeue"); let contract_runtime_metrics = metrics.clone(); - let block_max_install_upgrade_count = - chainspec.transaction_config.block_max_install_upgrade_count; let is_era_end = executable_block.era_report.is_some(); if is_era_end && executable_block.rewards.is_none() { executable_block.rewards = Some(if chainspec.core_config.compute_rewards { @@ -117,6 +115,8 @@ pub(super) async fn exec_or_requeue( let block_max_standard_count = chainspec.transaction_config.block_max_standard_count; let block_max_mint_count = chainspec.transaction_config.block_max_mint_count; let block_max_auction_count = chainspec.transaction_config.block_max_auction_count; + let block_max_install_upgrade_count = + chainspec.transaction_config.block_max_install_upgrade_count; let go_up = chainspec.vacancy_config.upper_threshold; let go_down = chainspec.vacancy_config.lower_threshold; let max = chainspec.vacancy_config.max_gas_price; @@ -125,10 +125,32 @@ pub(super) async fn exec_or_requeue( let era_id = executable_block.era_id; let block_height = executable_block.height; - let switch_block_transaction_hashes = executable_block.transactions.len() as u64; + let per_block_capacity = { + block_max_install_upgrade_count + + block_max_standard_count + + block_max_mint_count + + block_max_auction_count + } as u64; + + let switch_block_utilization_score = { + let has_hit_slot_limt = { + (executable_block.mint.len() as u32 >= block_max_mint_count) + || (executable_block.auction.len() as u32 >= block_max_auction_count) + || (executable_block.standard.len() as u32 >= block_max_standard_count) + || (executable_block.install_upgrade.len() as u32 + >= block_max_install_upgrade_count) + }; + + if has_hit_slot_limt { + 100u64 + } else { + let num = executable_block.transactions.len() as u64; + Ratio::new(num * 100, per_block_capacity).to_integer() + } + }; let maybe_utilization = effect_builder - .get_block_utilization(era_id, block_height, switch_block_transaction_hashes) + .get_block_utilization(era_id, block_height, switch_block_utilization_score) .await; match maybe_utilization { @@ -137,18 +159,7 @@ pub(super) async fn exec_or_requeue( return fatal!(effect_builder, "{}", error).await; } Some((utilization, block_count)) => { - let per_block_capacity = { - block_max_install_upgrade_count - + block_max_standard_count - + block_max_mint_count - + block_max_auction_count - } as u64; - - let era_score = { - let numerator = utilization * 100; - let denominator = per_block_capacity * block_count; - Ratio::new(numerator, denominator).to_integer() - }; + let era_score = { Ratio::new(utilization, block_count).to_integer() }; let new_gas_price = if era_score >= go_up { let new_gas_price = current_gas_price + 1; diff --git a/node/src/components/fetcher/tests.rs b/node/src/components/fetcher/tests.rs index 5ee80f61c9..fcea95e531 100644 --- a/node/src/components/fetcher/tests.rs +++ b/node/src/components/fetcher/tests.rs @@ -13,7 +13,7 @@ use thiserror::Error; use casper_types::{ testing::TestRng, BlockV2, Chainspec, ChainspecRawBytes, FinalitySignatureV2, Transaction, - TransactionHash, TransactionId, + TransactionConfig, TransactionHash, TransactionId, }; use super::*; @@ -295,6 +295,7 @@ impl ReactorTrait for Reactor { chainspec.core_config.unbonding_delay, Some(registry), false, + TransactionConfig::default(), ) .unwrap(); diff --git a/node/src/components/gossiper/tests.rs b/node/src/components/gossiper/tests.rs index a1954ee9f7..78c657bbe6 100644 --- a/node/src/components/gossiper/tests.rs +++ b/node/src/components/gossiper/tests.rs @@ -19,7 +19,7 @@ use tracing::debug; use casper_types::{ testing::TestRng, BlockV2, Chainspec, ChainspecRawBytes, EraId, FinalitySignatureV2, - ProtocolVersion, TimeDiff, Transaction, + ProtocolVersion, TimeDiff, Transaction, TransactionConfig, }; use super::*; @@ -169,6 +169,7 @@ impl reactor::Reactor for Reactor { RECENT_ERA_COUNT, Some(registry), false, + TransactionConfig::default(), ) .unwrap(); diff --git a/node/src/components/storage.rs b/node/src/components/storage.rs index 5f95ffc7a2..1f480ee6b1 100644 --- a/node/src/components/storage.rs +++ b/node/src/components/storage.rs @@ -69,7 +69,7 @@ use casper_types::{ Approval, ApprovalsHash, AvailableBlockRange, Block, BlockBody, BlockHash, BlockHeader, BlockSignatures, BlockSignaturesV1, BlockSignaturesV2, BlockV2, ChainNameDigest, DeployHash, EraId, ExecutionInfo, FinalitySignature, ProtocolVersion, SignedBlockHeader, Timestamp, - Transaction, TransactionHash, TransactionHeader, TransactionId, Transfer, + Transaction, TransactionConfig, TransactionHash, TransactionHeader, TransactionId, Transfer, }; use datasize::DataSize; use prometheus::Registry; @@ -148,6 +148,8 @@ pub struct Storage { max_ttl: MaxTtl, /// The hash of the chain name. chain_name_hash: ChainNameDigest, + /// The transaction config as specified by the chainspec. + transaction_config: TransactionConfig, /// The utilization of blocks. utilization_tracker: BTreeMap>, } @@ -245,6 +247,7 @@ impl Storage { recent_era_count: u64, registry: Option<&Registry>, force_resync: bool, + transaction_config: TransactionConfig, ) -> Result { let config = cfg.value(); @@ -289,6 +292,7 @@ impl Storage { utilization_tracker: BTreeMap::new(), metrics, chain_name_hash: ChainNameDigest::from_chain_name(network_name), + transaction_config, }; if force_resync { @@ -960,8 +964,10 @@ impl Storage { responder, } => { let block: Block = (*block).clone().into(); + let transaction_config = self.transaction_config; responder .respond(self.put_executed_block( + transaction_config, &block, &approvals_hashes, execution_results, @@ -1000,11 +1006,14 @@ impl Storage { StorageRequest::GetBlockUtilizationScore { era_id, block_height, - transaction_count, + switch_block_utilization, responder, } => { - let utilization = - self.get_block_utilization_score(era_id, block_height, transaction_count); + let utilization = self.get_block_utilization_score( + era_id, + block_height, + switch_block_utilization, + ); responder.respond(utilization).ignore() } @@ -1051,13 +1060,14 @@ impl Storage { pub(crate) fn put_executed_block( &mut self, + transaction_config: TransactionConfig, block: &Block, approvals_hashes: &ApprovalsHashes, execution_results: HashMap, ) -> Result { let mut txn = self.block_store.checkout_rw()?; - let transaction_hash_count = block.transaction_count(); let era_id = block.era_id(); + let block_utilization_score = block.block_utilization(transaction_config); let block_hash = txn.write(block)?; let _ = txn.write(approvals_hashes)?; let block_info = BlockHashHeightAndEra::new(block_hash, block.height(), block.era_id()); @@ -1068,17 +1078,13 @@ impl Storage { })?; txn.commit()?; - if let Some(block_score) = self.utilization_tracker.get_mut(&era_id) { - block_score.insert(block.height(), transaction_hash_count); - }; - match self.utilization_tracker.get_mut(&era_id) { Some(block_score) => { - block_score.insert(block.height(), transaction_hash_count); + block_score.insert(block.height(), block_utilization_score); } None => { let mut block_score = BTreeMap::new(); - block_score.insert(block.height(), transaction_hash_count); + block_score.insert(block.height(), block_utilization_score); self.utilization_tracker.insert(era_id, block_score); } } @@ -1967,11 +1973,11 @@ impl Storage { &mut self, era_id: EraId, block_height: u64, - transaction_count: u64, + block_utilization: u64, ) -> Option<(u64, u64)> { let ret = match self.utilization_tracker.get_mut(&era_id) { Some(utilization) => { - utilization.entry(block_height).or_insert(transaction_count); + utilization.entry(block_height).or_insert(block_utilization); let transaction_count = utilization.values().into_iter().sum(); let block_count = utilization.keys().len() as u64; @@ -1980,12 +1986,12 @@ impl Storage { } None => { let mut utilization = BTreeMap::new(); - utilization.insert(block_height, transaction_count); + utilization.insert(block_height, block_utilization); self.utilization_tracker.insert(era_id, utilization); let block_count = 1u64; - Some((transaction_count, block_count)) + Some((block_utilization, block_count)) } }; diff --git a/node/src/components/storage/tests.rs b/node/src/components/storage/tests.rs index d88ce58972..e45cec5c4a 100644 --- a/node/src/components/storage/tests.rs +++ b/node/src/components/storage/tests.rs @@ -27,7 +27,8 @@ use casper_types::{ BlockSignaturesV2, BlockV2, ChainNameDigest, Chainspec, ChainspecRawBytes, Deploy, DeployHash, Digest, EraId, ExecutionInfo, FinalitySignature, FinalitySignatureV2, Gas, InitiatorAddr, ProtocolVersion, PublicKey, SecretKey, SignedBlockHeader, TestBlockBuilder, TestBlockV1Builder, - TimeDiff, Transaction, TransactionHash, TransactionV1Hash, Transfer, TransferV2, U512, + TimeDiff, Transaction, TransactionConfig, TransactionHash, TransactionV1Hash, Transfer, + TransferV2, U512, }; use tempfile::tempdir; @@ -193,6 +194,7 @@ fn storage_fixture(harness: &ComponentHarness) -> Storage { RECENT_ERA_COUNT, None, false, + TransactionConfig::default(), ) .expect("could not create storage component fixture") } @@ -223,6 +225,7 @@ fn storage_fixture_from_parts( recent_era_count.unwrap_or(RECENT_ERA_COUNT), None, false, + TransactionConfig::default(), ) .expect("could not create storage component fixture from parts") } @@ -245,6 +248,7 @@ fn storage_fixture_with_force_resync(cfg: &WithDir) -> Storage { RECENT_ERA_COUNT, None, true, + TransactionConfig::default(), ) .expect("could not create storage component fixture") } @@ -1782,6 +1786,7 @@ fn should_create_subdir_named_after_network() { RECENT_ERA_COUNT, None, false, + TransactionConfig::default(), ) .unwrap(); diff --git a/node/src/components/transaction_acceptor/tests.rs b/node/src/components/transaction_acceptor/tests.rs index a3acea9b30..51b9c1a0e4 100644 --- a/node/src/components/transaction_acceptor/tests.rs +++ b/node/src/components/transaction_acceptor/tests.rs @@ -34,7 +34,7 @@ use casper_types::{ Block, BlockV2, CLValue, Chainspec, ChainspecRawBytes, Contract, Deploy, EraId, HashAddr, InvalidDeploy, InvalidTransaction, InvalidTransactionV1, Package, PricingMode, ProtocolVersion, PublicKey, SecretKey, StoredValue, TestBlockBuilder, TimeDiff, Timestamp, Transaction, - TransactionSessionKind, TransactionV1, TransactionV1Builder, URef, U512, + TransactionConfig, TransactionSessionKind, TransactionV1, TransactionV1Builder, URef, U512, }; use super::*; @@ -910,6 +910,7 @@ impl reactor::Reactor for Reactor { chainspec.core_config.recent_era_count(), Some(registry), false, + TransactionConfig::default(), ) .unwrap(); diff --git a/node/src/effect.rs b/node/src/effect.rs index 5de0c3b25e..be16469130 100644 --- a/node/src/effect.rs +++ b/node/src/effect.rs @@ -1160,7 +1160,7 @@ impl EffectBuilder { |responder| StorageRequest::GetBlockUtilizationScore { era_id, block_height, - transaction_count, + switch_block_utilization: transaction_count, responder, }, QueueKind::FromStorage, diff --git a/node/src/effect/requests.rs b/node/src/effect/requests.rs index 033aab0a0f..c1dac727cd 100644 --- a/node/src/effect/requests.rs +++ b/node/src/effect/requests.rs @@ -493,10 +493,15 @@ pub(crate) enum StorageRequest { }, /// Retrieve the height of the final block of the previous protocol version, if known. GetKeyBlockHeightForActivationPoint { responder: Responder> }, + /// Retrieve the block utilization score. GetBlockUtilizationScore { + /// The era id. era_id: EraId, + /// The block height of the switch block block_height: u64, - transaction_count: u64, + /// The utilization within the switch block. + switch_block_utilization: u64, + /// Responder, responded once the utilization for the era has been determined. responder: Responder>, }, } diff --git a/node/src/reactor/main_reactor.rs b/node/src/reactor/main_reactor.rs index 8159a2edcf..f03845a735 100644 --- a/node/src/reactor/main_reactor.rs +++ b/node/src/reactor/main_reactor.rs @@ -1111,6 +1111,7 @@ impl reactor::Reactor for MainReactor { chainspec.core_config.recent_era_count(), Some(registry), config.node.force_resync, + chainspec.transaction_config, )?; let contract_runtime = ContractRuntime::new( diff --git a/node/src/reactor/main_reactor/tests.rs b/node/src/reactor/main_reactor/tests.rs index 891fb116fc..a5e7b7bd30 100644 --- a/node/src/reactor/main_reactor/tests.rs +++ b/node/src/reactor/main_reactor/tests.rs @@ -12,6 +12,7 @@ use std::{ }; use either::Either; +use itertools::Itertools; use num::Zero; use num_rational::Ratio; use num_traits::One; @@ -783,6 +784,53 @@ impl TestFixture { price.gas_price() } + #[track_caller] + fn check_account_balance_hold_at_tip(&self, account_public_key: PublicKey) -> U512 { + let (_, runner) = self + .network + .nodes() + .iter() + .next() + .expect("must have runner"); + + let highest_block = runner + .main_reactor() + .storage + .read_highest_block() + .expect("should have block"); + + let block_time = highest_block.clone_header().timestamp(); + + let holds_epoch = HoldsEpoch::from_timestamp( + block_time, + self.chainspec.core_config.balance_hold_interval, + ); + + let balance_request = BalanceRequest::from_public_key( + *highest_block.state_root_hash(), + highest_block.protocol_version(), + account_public_key, + BalanceHandling::Available { holds_epoch }, + ); + + let balance_result = runner + .main_reactor() + .contract_runtime + .data_access_layer() + .balance(balance_request); + + if let BalanceResult::Success { balance_holds, .. } = balance_result { + balance_holds + .values() + .flat_map(|holds| holds.values().map(|(v, _)| *v)) + .collect_vec() + .into_iter() + .sum() + } else { + panic!("failed balance result") + } + } + async fn inject_transaction(&mut self, txn: Transaction) { // saturate the network with the transactions via just making them all store and accept it // they're all validators so one of them should propose it @@ -1919,10 +1967,13 @@ async fn rewards_are_calculated() { const STAKE: u128 = 1000000000; const PRIME_STAKES: [u128; 5] = [106907, 106921, 106937, 106949, 106957]; const ERA_COUNT: u64 = 3; -const ERA_DURATION: u64 = 20000; //milliseconds +const ERA_DURATION: u64 = 20000; +//milliseconds const MIN_HEIGHT: u64 = 6; -const BLOCK_TIME: u64 = 2000; //milliseconds -const TIME_OUT: u64 = 600; //seconds +const BLOCK_TIME: u64 = 2000; +//milliseconds +const TIME_OUT: u64 = 600; +//seconds const SEIGNIORAGE: (u64, u64) = (1u64, 100u64); const REPRESENTATIVE_NODE_INDEX: usize = 0; // Parameters we generally want to vary @@ -2578,9 +2629,6 @@ async fn should_raise_gas_price_to_ceiling_and_reduce_to_floor() { minimum_era_height: 5, lower_threshold: 0, upper_threshold: 1, - max_standard_count: 1, - max_staking_count: 1, - max_install_count: 1, max_transfer_count: 1, max_gas_price, ..Default::default() @@ -2597,22 +2645,23 @@ async fn should_raise_gas_price_to_ceiling_and_reduce_to_floor() { let switch_block = fixture.switch_block(ERA_ONE); let mut current_era = switch_block.era_id(); + let chain_name = fixture.chainspec.network_config.name.clone(); // Run the network at load for at least 5 eras. for _ in 0..5 { let target_public_key = PublicKey::random(&mut fixture.rng); - let mut native_transfer = Deploy::native_transfer( - fixture.chainspec.network_config.name.clone(), - alice_public_key.clone(), - target_public_key, - None, - Timestamp::now(), - TimeDiff::from_seconds(1200), - max_gas_price as u64, - ); + let fixed_native_mint_transaction = + TransactionV1Builder::new_transfer(10_000_000_000u64, None, target_public_key, None) + .expect("must get builder") + .with_chain_name(chain_name.clone()) + .with_secret_key(&alice_secret_key) + .with_pricing_mode(PricingMode::Fixed { + gas_price_tolerance: max_gas_price, + }) + .build() + .expect("must get transaction"); - native_transfer.sign(&alice_secret_key); - let txn = Transaction::Deploy(native_transfer); + let txn = Transaction::V1(fixed_native_mint_transaction); fixture.inject_transaction(txn).await; let next_era = current_era.successor(); fixture @@ -2624,6 +2673,39 @@ async fn should_raise_gas_price_to_ceiling_and_reduce_to_floor() { let expected_gas_price = fixture.chainspec.vacancy_config.max_gas_price; let actual_gas_price = fixture.get_current_era_price(); assert_eq!(actual_gas_price, expected_gas_price); + let target_public_key = PublicKey::random(&mut fixture.rng); + + let holds_before = fixture.check_account_balance_hold_at_tip(alice_public_key.clone()); + let amount = 10_000_000_000u64; + + let fixed_native_mint_transaction = + TransactionV1Builder::new_transfer(amount, None, target_public_key, None) + .expect("must get builder") + .with_chain_name(chain_name) + .with_secret_key(&alice_secret_key) + .with_pricing_mode(PricingMode::Fixed { + gas_price_tolerance: max_gas_price, + }) + .build() + .expect("must get transaction"); + + let txn = Transaction::V1(fixed_native_mint_transaction); + let txn_hash = txn.hash(); + + fixture.inject_transaction(txn).await; + fixture + .run_until_executed_transaction(&txn_hash, TEN_SECS) + .await; + + let holds_after = fixture.check_account_balance_hold_at_tip(alice_public_key.clone()); + + let current_gas_price = fixture + .highest_complete_block() + .maybe_current_gas_price() + .expect("must have gas price"); + let cost = + fixture.chainspec.system_costs_config.mint_costs().transfer * (current_gas_price as u32); + assert_eq!(holds_after, holds_before + U512::from(cost)); // Run the network at zero load and ensure the value falls back to the floor. for _ in 0..5 { diff --git a/node/src/types/block/executable_block.rs b/node/src/types/block/executable_block.rs index ded26c6c43..5272304c8f 100644 --- a/node/src/types/block/executable_block.rs +++ b/node/src/types/block/executable_block.rs @@ -73,8 +73,8 @@ impl ExecutableBlock { height: block.height(), proposer: Box::new(block.proposer().clone()), transactions, - mint: block.transfer().copied().collect(), - auction: block.staking().copied().collect(), + mint: block.mint().copied().collect(), + auction: block.auction().copied().collect(), install_upgrade: block.install_upgrade().copied().collect(), standard: block.standard().copied().collect(), rewards: block.era_end().map(|era_end| era_end.rewards().clone()), diff --git a/node/src/types/block/finalized_block.rs b/node/src/types/block/finalized_block.rs index b917fd000b..0cbef73e3e 100644 --- a/node/src/types/block/finalized_block.rs +++ b/node/src/types/block/finalized_block.rs @@ -149,8 +149,8 @@ impl FinalizedBlock { impl From for FinalizedBlock { fn from(block: BlockV2) -> Self { FinalizedBlock { - mint: block.transfer().copied().collect(), - auction: block.staking().copied().collect(), + mint: block.mint().copied().collect(), + auction: block.auction().copied().collect(), install_upgrade: block.install_upgrade().copied().collect(), standard: block.standard().copied().collect(), timestamp: block.timestamp(), diff --git a/types/src/block.rs b/types/src/block.rs index 273ed87da3..e2cf94b39e 100644 --- a/types/src/block.rs +++ b/types/src/block.rs @@ -29,10 +29,15 @@ use std::error::Error as StdError; #[cfg(feature = "datasize")] use datasize::DataSize; +#[cfg(feature = "std")] +use num_rational::Ratio; #[cfg(feature = "json-schema")] use schemars::JsonSchema; +#[cfg(feature = "std")] +use crate::TransactionConfig; + use crate::{ bytesrepr, bytesrepr::{FromBytes, ToBytes, U8_SERIALIZED_LENGTH}, @@ -393,6 +398,41 @@ impl Block { } } + /// Returns the utilization of the block against a given chainspec. + #[cfg(feature = "std")] + pub fn block_utilization(&self, transaction_config: TransactionConfig) -> u64 { + match self { + Block::V1(_) => { + // We shouldnt be tracking this for legacy blocks + 0 + } + Block::V2(block_v2) => { + let has_hit_slot_limt = { + (block_v2.mint().count() as u32 >= transaction_config.block_max_mint_count) + || (block_v2.auction().count() as u32 + >= transaction_config.block_max_auction_count) + || (block_v2.standard().count() as u32 + >= transaction_config.block_max_standard_count) + || (block_v2.install_upgrade().count() as u32 + >= transaction_config.block_max_install_upgrade_count) + }; + + let per_block_capacity = (transaction_config.block_max_mint_count + + transaction_config.block_max_auction_count + + transaction_config.block_max_standard_count + + transaction_config.block_max_install_upgrade_count) + as u64; + + if has_hit_slot_limt { + 100u64 + } else { + let num = block_v2.all_transactions().count() as u64; + Ratio::new(num * 100, per_block_capacity).to_integer() + } + } + } + } + // This method is not intended to be used by third party crates. #[doc(hidden)] #[cfg(feature = "json-schema")] diff --git a/types/src/block/block_v2.rs b/types/src/block/block_v2.rs index 793b36f028..e8eeff694d 100644 --- a/types/src/block/block_v2.rs +++ b/types/src/block/block_v2.rs @@ -242,12 +242,12 @@ impl BlockV2 { } /// Returns the hashes of the transfer transactions within the block. - pub fn transfer(&self) -> impl Iterator { + pub fn mint(&self) -> impl Iterator { self.body.mint() } /// Returns the hashes of the non-transfer, native transactions within the block. - pub fn staking(&self) -> impl Iterator { + pub fn auction(&self) -> impl Iterator { self.body.auction() }