iuna

iuna

iuna - experimental devnet protocol
git clone https://getiuna.org/git/iuna.git
Log | Files | Refs | README | LICENSE

domain.rs (5857B)


      1 #[cfg(test)]
      2 use std::collections::BTreeMap;
      3 use std::collections::BTreeSet;
      4 
      5 mod blinded;
      6 mod block;
      7 mod fork;
      8 mod genesis;
      9 mod hex;
     10 mod history;
     11 mod ledger_apply;
     12 mod ledger_builders;
     13 mod ledger_chain;
     14 mod ledger_consensus;
     15 mod ledger_mempool;
     16 mod ledger_ops;
     17 mod ledger_pending;
     18 mod ledger_prepare;
     19 mod ledger_queries;
     20 mod ledger_reveal;
     21 mod ledger_state;
     22 mod mine_policy;
     23 mod mining;
     24 mod profile;
     25 mod protocol;
     26 mod reveal;
     27 mod selection;
     28 mod stratum;
     29 mod ticket;
     30 mod transaction;
     31 mod validation;
     32 mod vdf;
     33 mod wallet;
     34 use blinded::{ActiveBlindedTransaction, blinded_fee_share};
     35 #[cfg(test)]
     36 use blinded::{
     37     blinded_committer_fee_outpoint, blinded_executor_fee_outpoint, blinded_expiry_change_outpoint,
     38     blinded_reveal_bundle_signer_fee_outpoint, blinded_transaction_commitment,
     39     credit_blinded_fee_outputs, decrypt_blinded_payload, decrypt_blinded_transaction,
     40 };
     41 use block::LeaderProofPayload;
     42 pub use block::{
     43     Block, BurnLeaderRank, ChainSnapshot, ChainStatus, FinalizerMode, LeaderProof, PreparedBlock,
     44 };
     45 use fork::LeaderScore;
     46 #[cfg(test)]
     47 use genesis::balances_from_utxos;
     48 use genesis::genesis_allocation_outpoint;
     49 pub use hex::hex_hash;
     50 use hex::{decode_hex, decode_hex_array, hex_encode};
     51 pub use history::revealed_blinded_transactions;
     52 #[cfg(test)]
     53 use ledger_apply::{reveal_fee_bundle_count_for_height, reveal_fee_signatures_for_height};
     54 #[cfg(test)]
     55 use ledger_ops::estimated_block_selection_size_bytes;
     56 #[cfg(test)]
     57 use ledger_ops::fee_reward;
     58 #[cfg(test)]
     59 use ledger_ops::reward_outpoint;
     60 use ledger_ops::{
     61     apply_transaction, credit_reward_output, ensure_block_has_burn, ensure_block_has_burn_from,
     62     ensure_outputs_do_not_overflow, ensure_single_input_owner_for_inputs,
     63     recovery_vdf_seed_for_child, validate_genesis_burn_transaction, vdf_seed_for_child,
     64 };
     65 pub use ledger_state::Ledger;
     66 use ledger_state::unix_now_ms;
     67 #[cfg(test)]
     68 use mine_policy::MINE_RETARGET_WINDOW_BLOCKS;
     69 #[cfg(test)]
     70 use mine_policy::{
     71     MINE_MAX_ANCHOR_AGE_BLOCKS, MINE_MAX_RETARGET_STEP_BITS, MINE_MIN_DIFFICULTY_BITS,
     72 };
     73 use mining::{mine_payload, mine_signature};
     74 pub use profile::{GenesisBurn, LaunchProfile};
     75 pub use protocol::{
     76     Amount, BLINDED_COMMITTER_FEE_BPS, BLINDED_FEE_BPS_DENOMINATOR,
     77     BLINDED_REVEAL_BUNDLE_SIGNER_FEE_BPS, BLINDED_REVEAL_FINALIZER_FEE_BPS, BLOCK_REWARD,
     78     DEFAULT_FEE_PER_BYTE, DEFAULT_MINE_FEE, DEFAULT_TRANSACTION_FEE,
     79     MAX_BLINDED_TRANSACTION_EXPIRY_HEIGHTS, MAX_BLOCK_BYTES, MAX_PENDING_TRANSACTIONS,
     80     MAX_REVEAL_BUNDLE_BYTES, MAX_VDF_ROUNDS, MICRO_IUNA, MINE_ACTIONS_PER_ANCHOR_LIMIT,
     81     MINE_DIFFICULTY_BITS, MINE_FINALIZER_FEE, MINE_REWARD, RECOVERY_BLOCK_DELAY_MS,
     82     REVEAL_COMMITTEE_SIZE, REVEAL_FEE_MASK_ATTRIBUTION_HEIGHT, TransactionSubmitOutcome,
     83     UNIQUE_OWNER_REVEAL_COMMITTEE_HEIGHT, VDF_TARGET_BLOCK_MS,
     84 };
     85 use protocol::{
     86     BLINDED_KEY_BYTES, BLINDED_NONCE_BYTES, BLOCK_MEDIAN_TIME_PAST_WINDOW,
     87     DEFAULT_TICKET_EXPIRY_WINDOW, DEFAULT_TICKET_MATURITY_DELAY, FORK_FINALITY_DEPTH, HASH_BYTES,
     88     MAX_BLOCK_TIMESTAMP_FUTURE_DRIFT_MS, MAX_BLOCK_TRANSACTIONS, MAX_ORPHAN_TRANSACTIONS,
     89     PUBLIC_KEY_BYTES, SIGNATURE_BYTES,
     90 };
     91 use reveal::RevealBundlePayload;
     92 #[cfg(test)]
     93 use reveal::reveal_bundle_hashes;
     94 pub use reveal::{
     95     MaskedBlindedReveal, RevealBundle, RevealBundleSection, RevealBundleSignature,
     96     RevealCommitteeMember, default_reveal_bundle_hash,
     97 };
     98 use selection::BlockSelection;
     99 pub use stratum::{
    100     STRATUM_EXTRANONCE1_HEX, STRATUM_EXTRANONCE2_SIZE, StratumMineShare, StratumMineTemplate,
    101     pack_stratum_nonce,
    102 };
    103 use stratum::{hash_meets_difficulty, stratum_mine_header_bytes, stratum_mine_signature};
    104 use ticket::{BurnTicket, ticket_block_min_timestamp};
    105 #[cfg(test)]
    106 use ticket::{
    107     MISSED_FALLBACK_TICKET_INVALIDATION_HEIGHT, consume_leader_ticket, ranked_tickets_for_height,
    108     ticket_is_eligible_for_height,
    109 };
    110 pub use transaction::{
    111     BlindedReveal, BlindedTransaction, BuiltBlindedTransaction, MineSearchOutcome, OutPoint,
    112     OwnedBlindedTransaction, RevealedBlindedTransaction, Transaction, TxInput, TxOutput,
    113 };
    114 #[cfg(test)]
    115 use transaction::{
    116     UnsignedTxInput, UnsignedUtxoTransaction, signed_blinded_inputs, unsigned_inputs,
    117 };
    118 pub use validation::validate_address;
    119 use validation::{
    120     canonical_transaction_size_bytes, validate_hash, validate_protocol_id, validate_signature,
    121 };
    122 #[cfg(test)]
    123 use vdf::{
    124     MAX_VDF_RETARGET_OBSERVED_BLOCK_MS, MIN_VDF_RETARGET_OBSERVED_BLOCK_MS,
    125     VDF_RETARGET_DEADBAND_PERCENT, clamped_vdf_retarget_observed_block_ms, retarget_vdf_rounds,
    126     vdf_retarget_observed_block_ms,
    127 };
    128 pub use vdf::{run_vdf, verify_vdf};
    129 pub use wallet::Wallet;
    130 
    131 pub fn reveal_committee_slot_count(eligible_rank_count: usize) -> usize {
    132     eligible_rank_count.min(REVEAL_COMMITTEE_SIZE)
    133 }
    134 
    135 pub fn reveal_committee_slot_count_for_owners<'a>(
    136     owners: impl IntoIterator<Item = &'a str>,
    137 ) -> usize {
    138     reveal_committee_slot_count(owners.into_iter().collect::<BTreeSet<_>>().len())
    139 }
    140 
    141 pub fn reveal_committee_slot_count_for_height<'a>(
    142     height: u64,
    143     eligible_rank_count: usize,
    144     owners: impl IntoIterator<Item = &'a str>,
    145 ) -> usize {
    146     if height < UNIQUE_OWNER_REVEAL_COMMITTEE_HEIGHT {
    147         return reveal_committee_slot_count(eligible_rank_count);
    148     }
    149     reveal_committee_slot_count_for_owners(owners)
    150 }
    151 
    152 pub fn blinded_reveal_finalizer_fee(
    153     fee: Amount,
    154     included_bundle_count: usize,
    155     available_bundle_slots: usize,
    156 ) -> Amount {
    157     if included_bundle_count == 0 {
    158         return 0;
    159     }
    160     let available_bundle_slots = available_bundle_slots.clamp(1, REVEAL_COMMITTEE_SIZE);
    161     let included_bundle_count = included_bundle_count.min(available_bundle_slots);
    162     let full_share = blinded_fee_share(fee, BLINDED_REVEAL_FINALIZER_FEE_BPS);
    163     ((full_share as u128 * included_bundle_count as u128) / available_bundle_slots as u128)
    164         as Amount
    165 }
    166 
    167 #[cfg(test)]
    168 mod tests;