Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add default fees for mainnet/testnet networks #376

Merged
merged 13 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ env:
DFX_VERSION: 0.23.0
POCKET_IC_SERVER_VERSION: 7.0.0
CARGO_TERM_COLOR: always # Force Cargo to use colors
TERM: xterm-256color

on:
push:
Expand Down Expand Up @@ -94,7 +95,7 @@ jobs:
- name: Run Tests
shell: bash
run: |
cargo test --release --all-targets --workspace --exclude benchmarks
cargo test --release --all-targets --workspace --exclude benchmarks --color always -- --color always
env:
RUST_BACKTRACE: 1

Expand Down
8 changes: 7 additions & 1 deletion canister/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,20 @@ impl State {
let unstable_blocks =
UnstableBlocks::new(&utxos, stability_threshold, genesis_block, network);

let fees = match network {
Network::Mainnet => Fees::mainnet(),
Network::Testnet => Fees::testnet(),
_ => Fees::default(),
};

Self {
utxos,
unstable_blocks,
syncing_state: SyncingState::default(),
blocks_source: Principal::management_canister(),
fee_percentiles_cache: None,
stable_block_headers: BlockHeaderStore::init(),
fees: Fees::default(),
fees,
metrics: Metrics::default(),
api_access: Flag::Enabled,
disable_api_if_not_fully_synced: Flag::Enabled,
Expand Down
56 changes: 56 additions & 0 deletions interface/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -634,6 +634,7 @@ impl From<InitConfig> for Config {
config.syncing = syncing;
}

let fees_explicitly_set = init_config.fees.is_some();
if let Some(fees) = init_config.fees {
config.fees = fees;
}
Expand All @@ -658,6 +659,15 @@ impl From<InitConfig> for Config {
config.lazily_evaluate_fee_percentiles = lazily_evaluate_fee_percentiles;
}

// Config post-processing.
if !fees_explicitly_set {
config.fees = match config.network {
Network::Mainnet => Fees::mainnet(),
Network::Testnet => Fees::testnet(),
_ => config.fees, // Keep unchanged for the rest of the networks.
};
}

config
}
}
Expand Down Expand Up @@ -725,6 +735,52 @@ pub struct Fees {
pub get_block_headers_maximum: u128,
}

impl Fees {
pub fn testnet() -> Self {
// https://internetcomputer.org/docs/references/bitcoin-how-it-works#bitcoin-testnet
Self {
get_utxos_base: 20_000_000,
get_utxos_cycles_per_ten_instructions: 10,
get_utxos_maximum: 4_000_000_000,

get_current_fee_percentiles: 4_000_000,
get_current_fee_percentiles_maximum: 40_000_000,

get_balance: 4_000_000,
get_balance_maximum: 40_000_000,

send_transaction_base: 2_000_000_000,
send_transaction_per_byte: 8_000_000,

get_block_headers_base: 20_000_000,
get_block_headers_cycles_per_ten_instructions: 10,
get_block_headers_maximum: 4_000_000_000,
}
}

pub fn mainnet() -> Self {
// https://internetcomputer.org/docs/references/bitcoin-how-it-works#bitcoin-mainnet
Self {
get_utxos_base: 50_000_000,
get_utxos_cycles_per_ten_instructions: 10,
get_utxos_maximum: 10_000_000_000,

get_current_fee_percentiles: 10_000_000,
get_current_fee_percentiles_maximum: 100_000_000,

get_balance: 10_000_000,
get_balance_maximum: 100_000_000,

send_transaction_base: 5_000_000_000,
send_transaction_per_byte: 20_000_000,

get_block_headers_base: 50_000_000,
get_block_headers_cycles_per_ten_instructions: 10,
get_block_headers_maximum: 10_000_000_000,
}
}
}

#[cfg(test)]
mod test {
use super::*;
Expand Down
Loading