Skip to content
This repository has been archived by the owner on Jan 22, 2025. It is now read-only.

Commit

Permalink
move cost const def into block_cost_limits.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
tao-stones committed Aug 4, 2021
1 parent 93baef1 commit 8e89674
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 24 deletions.
24 changes: 2 additions & 22 deletions core/src/cost_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,10 @@
//!
use crate::execute_cost_table::ExecuteCostTable;
use log::*;
use solana_ledger::block_cost_limits::*;
use solana_sdk::{pubkey::Pubkey, sanitized_transaction::SanitizedTransaction};
use std::collections::HashMap;

// 07-27-2021, compute_unit to microsecond conversion ratio collected from mainnet-beta
// differs between instructions. Some bpf instruction has much higher CU/US ratio
// (eg 7vxeyaXGLqcp66fFShqUdHxdacp4k4kwUpRSSeoZLCZ4 has average ratio 135), others
// have lower ratio (eg 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin has an average ratio 14).
// With this, I am guestimating the flat_fee for sigver and account read/write
// as following. This can be adjusted when needed.
const SIGVER_COST: u64 = 1;
const NON_SIGNED_READONLY_ACCOUNT_ACCESS_COST: u64 = 1;
const NON_SIGNED_WRITABLE_ACCOUNT_ACCESS_COST: u64 = 2;
const SIGNED_READONLY_ACCOUNT_ACCESS_COST: u64 =
SIGVER_COST + NON_SIGNED_READONLY_ACCOUNT_ACCESS_COST;
const SIGNED_WRITABLE_ACCOUNT_ACCESS_COST: u64 =
SIGVER_COST + NON_SIGNED_WRITABLE_ACCOUNT_ACCESS_COST;

// 07-27-2021, cost model limit is set to "worst case scenario", which is the
// max compute unit it can execute. From mainnet-beta, the max CU of instruction
// is 3753, round up to 4_000. Say we allows max 50_000 instruction per writable i
// account, and 1_000_000 instruction per block. It comes to following limits:
pub const ACCOUNT_MAX_COST: u64 = 200_000_000;
pub const BLOCK_MAX_COST: u64 = 4_000_000_000;

const MAX_WRITABLE_ACCOUNTS: usize = 256;

#[derive(Debug, Clone)]
Expand Down Expand Up @@ -88,7 +68,7 @@ pub struct CostModel {

impl Default for CostModel {
fn default() -> Self {
CostModel::new(ACCOUNT_MAX_COST, BLOCK_MAX_COST)
CostModel::new(account_cost_max(), block_cost_max())
}
}

Expand Down
23 changes: 21 additions & 2 deletions ledger/src/block_cost_limits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,28 @@
//!
// see https://github.com/solana-labs/solana/issues/18944
const MAX_INSTRUMENT_COST: u64 = 200_000;
const MAX_NUMBER_BPF_INSTRUCTIONS_PER_BLOCK: u64 = 3_399;
pub const MAX_INSTRUMENT_COST: u64 = 200_000;
pub const MAX_NUMBER_BPF_INSTRUCTIONS_PER_BLOCK: u64 = 4_000;
pub const MAX_NUMBER_BPF_INSTRUCTIONS_PER_ACCOUNT: u64 = 200;

pub fn block_cost_max() -> u64 {
MAX_NUMBER_BPF_INSTRUCTIONS_PER_BLOCK * MAX_INSTRUMENT_COST
}

pub fn account_cost_max() -> u64 {
MAX_NUMBER_BPF_INSTRUCTIONS_PER_ACCOUNT * MAX_INSTRUMENT_COST
}

// 07-27-2021, compute_unit to microsecond conversion ratio collected from mainnet-beta
// differs between instructions. Some bpf instruction has much higher CU/US ratio
// (eg 7vxeyaXGLqcp66fFShqUdHxdacp4k4kwUpRSSeoZLCZ4 has average ratio 135), others
// have lower ratio (eg 9xQeWvG816bUx9EPjHmaT23yvVM2ZWbrrpZb9PusVFin has an average ratio 14).
// With this, I am guestimating the flat_fee for sigver and account read/write
// as following. This can be adjusted when needed.
pub const SIGVER_COST: u64 = 1;
pub const NON_SIGNED_READONLY_ACCOUNT_ACCESS_COST: u64 = 1;
pub const NON_SIGNED_WRITABLE_ACCOUNT_ACCESS_COST: u64 = 2;
pub const SIGNED_READONLY_ACCOUNT_ACCESS_COST: u64 =
SIGVER_COST + NON_SIGNED_READONLY_ACCOUNT_ACCESS_COST;
pub const SIGNED_WRITABLE_ACCOUNT_ACCESS_COST: u64 =
SIGVER_COST + NON_SIGNED_WRITABLE_ACCOUNT_ACCESS_COST;

0 comments on commit 8e89674

Please sign in to comment.