Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 4 additions & 0 deletions src/new_index/mempool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ pub struct TxOverview {
vsize: u64,
#[cfg(not(feature = "liquid"))]
value: u64,
#[cfg(feature = "liquid")]
discount_vsize: u64,
}

impl Mempool {
Expand Down Expand Up @@ -366,6 +368,8 @@ impl Mempool {
.values()
.map(|prevout| prevout.value.to_sat())
.sum(),
#[cfg(feature = "liquid")]
discount_vsize: tx.discount_vsize() as u64,
});

self.feeinfo.insert(txid, feeinfo);
Expand Down
20 changes: 15 additions & 5 deletions src/rest.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

use crate::chain::{
address, BlockHash, Network, OutPoint, Script, Sequence, Transaction, TxIn, TxMerkleNode,
TxOut, Txid,
Expand All @@ -10,7 +11,8 @@ use crate::util::{
is_coinbase, BlockHeaderMeta, BlockId, FullHash, ScriptToAddr, ScriptToAsm, TransactionStatus,
DEFAULT_BLOCKHASH,
};

#[cfg(feature = "liquid")]
use crate::util::optional_value_for_newer_blocks;
#[cfg(not(feature = "liquid"))]
use bitcoin::consensus::encode;

Expand Down Expand Up @@ -50,6 +52,8 @@ const ADDRESS_SEARCH_LIMIT: usize = 10;
const ASSETS_PER_PAGE: usize = 25;
#[cfg(feature = "liquid")]
const ASSETS_MAX_PER_PAGE: usize = 100;
#[cfg(feature = "liquid")]
const START_OF_LIQUID_DISCOUNT_CT_POLICY: u32 = 1734120000; // Friday, December 13, 2024, 20:00 GMT

const TTL_LONG: u32 = 157_784_630; // ttl for static resources (5 years)
const TTL_SHORT: u32 = 10; // ttl for volatie resources
Expand Down Expand Up @@ -131,10 +135,12 @@ struct TransactionValue {
status: Option<TransactionStatus>,

#[cfg(feature = "liquid")]
discount_vsize: usize,
#[serde(skip_serializing_if = "Option::is_none")]
discount_vsize: Option<usize>,

#[cfg(feature = "liquid")]
discount_weight: usize,
#[serde(skip_serializing_if = "Option::is_none")]
discount_weight: Option<usize>,
}

impl TransactionValue {
Expand Down Expand Up @@ -180,10 +186,14 @@ impl TransactionValue {
status: Some(TransactionStatus::from(blockid)),

#[cfg(feature = "liquid")]
discount_vsize: tx.discount_vsize(),
discount_vsize: optional_value_for_newer_blocks(blockid,
START_OF_LIQUID_DISCOUNT_CT_POLICY,
tx.discount_vsize()),

#[cfg(feature = "liquid")]
discount_weight: tx.discount_weight(),
discount_weight: optional_value_for_newer_blocks(blockid,
START_OF_LIQUID_DISCOUNT_CT_POLICY,
tx.discount_weight()),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/util/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ lazy_static! {
.unwrap();
}

#[derive(Debug, Serialize, Deserialize, Clone)]
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
pub struct BlockId {
pub height: usize,
pub hash: BlockHash,
Expand Down
3 changes: 3 additions & 0 deletions src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ pub use self::transaction::{
serialize_outpoint, TransactionStatus, TxInput,
};

#[cfg(feature = "liquid")]
pub use self::transaction::optional_value_for_newer_blocks;

use std::collections::HashMap;
use std::sync::mpsc::{channel, sync_channel, Receiver, Sender, SyncSender};
use std::thread;
Expand Down
50 changes: 50 additions & 0 deletions src/util/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ impl From<Option<BlockId>> for TransactionStatus {
}
}


#[cfg(feature = "liquid")]
pub fn optional_value_for_newer_blocks(block_id: Option<BlockId>,
check_time: u32,
value: usize) -> Option<usize> {
match block_id {
// use the provided value only if it was after the "activation" time
Some(b) if b.time >= check_time => Some(value),
// otherwise don't include it
Some(_) => None,
// also use the value for unconfirmed blocks
None => Some(value),
}
}

#[derive(Serialize, Deserialize)]
pub struct TxInput {
pub txid: Txid,
Expand Down Expand Up @@ -116,3 +131,38 @@ where
s.serialize_field("vout", &outpoint.vout)?;
s.end()
}


#[cfg(all(test, feature = "liquid"))]
mod test {
use bitcoin::hashes::Hash;
use elements::BlockHash;
use crate::util::BlockId;
use super::optional_value_for_newer_blocks;

#[test]
fn opt_value_newer_block() {
let value = 123;
let check_time = 32;
let hash = BlockHash::from_slice(&[0; 32]).unwrap();
let height = 456;

// unconfirmed block should include the value
let block_id = None;
assert_eq!(optional_value_for_newer_blocks(block_id, check_time, value), Some(value));

// block time before check_time should NOT include the value
let block_id = Some(BlockId{ height, hash, time: 0 });
assert_eq!(optional_value_for_newer_blocks(block_id, check_time, value), None);
let block_id = Some(BlockId{ height, hash, time: 31 });
assert_eq!(optional_value_for_newer_blocks(block_id, check_time, value), None);

// block time on or after check_time should include the value
let block_id = Some(BlockId{ height, hash, time: 32 });
assert_eq!(optional_value_for_newer_blocks(block_id, check_time, value), Some(value));
let block_id = Some(BlockId{ height, hash, time: 33 });
assert_eq!(optional_value_for_newer_blocks(block_id, check_time, value), Some(value));
let block_id = Some(BlockId{ height, hash, time: 333 });
assert_eq!(optional_value_for_newer_blocks(block_id, check_time, value), Some(value));
}
}