Skip to content

Commit 208491f

Browse files
committed
only set discount CT attributes on tx newer than CT start date
- discount CT for liquid was enabled as policy on December 13, 2024; it doesn't make sense to add it to txes from before that date - add discount_vsize to TxOverview struct - bring github actions up to date
1 parent 181256b commit 208491f

File tree

5 files changed

+73
-6
lines changed

5 files changed

+73
-6
lines changed

src/new_index/mempool.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ pub struct TxOverview {
6060
vsize: u64,
6161
#[cfg(not(feature = "liquid"))]
6262
value: u64,
63+
#[cfg(feature = "liquid")]
64+
discount_vsize: u64,
6365
}
6466

6567
impl Mempool {
@@ -366,6 +368,8 @@ impl Mempool {
366368
.values()
367369
.map(|prevout| prevout.value.to_sat())
368370
.sum(),
371+
#[cfg(feature = "liquid")]
372+
discount_vsize: tx.discount_vsize() as u64,
369373
});
370374

371375
self.feeinfo.insert(txid, feeinfo);

src/rest.rs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
12
use crate::chain::{
23
address, BlockHash, Network, OutPoint, Script, Sequence, Transaction, TxIn, TxMerkleNode,
34
TxOut, Txid,
@@ -10,7 +11,8 @@ use crate::util::{
1011
is_coinbase, BlockHeaderMeta, BlockId, FullHash, ScriptToAddr, ScriptToAsm, TransactionStatus,
1112
DEFAULT_BLOCKHASH,
1213
};
13-
14+
#[cfg(feature = "liquid")]
15+
use crate::util::optional_value_for_newer_blocks;
1416
#[cfg(not(feature = "liquid"))]
1517
use bitcoin::consensus::encode;
1618

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

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

133137
#[cfg(feature = "liquid")]
134-
discount_vsize: usize,
138+
#[serde(skip_serializing_if = "Option::is_none")]
139+
discount_vsize: Option<usize>,
135140

136141
#[cfg(feature = "liquid")]
137-
discount_weight: usize,
142+
#[serde(skip_serializing_if = "Option::is_none")]
143+
discount_weight: Option<usize>,
138144
}
139145

140146
impl TransactionValue {
@@ -180,10 +186,14 @@ impl TransactionValue {
180186
status: Some(TransactionStatus::from(blockid)),
181187

182188
#[cfg(feature = "liquid")]
183-
discount_vsize: tx.discount_vsize(),
189+
discount_vsize: optional_value_for_newer_blocks(blockid,
190+
START_OF_LIQUID_DISCOUNT_CT_POLICY,
191+
tx.discount_vsize()),
184192

185193
#[cfg(feature = "liquid")]
186-
discount_weight: tx.discount_weight(),
194+
discount_weight: optional_value_for_newer_blocks(blockid,
195+
START_OF_LIQUID_DISCOUNT_CT_POLICY,
196+
tx.discount_weight()),
187197
}
188198
}
189199
}

src/util/block.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ lazy_static! {
2020
.unwrap();
2121
}
2222

23-
#[derive(Debug, Serialize, Deserialize, Clone)]
23+
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
2424
pub struct BlockId {
2525
pub height: usize,
2626
pub hash: BlockHash,

src/util/mod.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ pub use self::transaction::{
1616
serialize_outpoint, TransactionStatus, TxInput,
1717
};
1818

19+
#[cfg(feature = "liquid")]
20+
pub use self::transaction::optional_value_for_newer_blocks;
21+
1922
use std::collections::HashMap;
2023
use std::sync::mpsc::{channel, sync_channel, Receiver, Sender, SyncSender};
2124
use std::thread;

src/util/transaction.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,21 @@ impl From<Option<BlockId>> for TransactionStatus {
4545
}
4646
}
4747

48+
49+
#[cfg(feature = "liquid")]
50+
pub fn optional_value_for_newer_blocks(block_id: Option<BlockId>,
51+
check_time: u32,
52+
value: usize) -> Option<usize> {
53+
match block_id {
54+
// use the provided value only if it was after the "activation" time
55+
Some(b) if b.time >= check_time => Some(value),
56+
// otherwise don't include it
57+
Some(_) => None,
58+
// also use the value for unconfirmed blocks
59+
None => Some(value),
60+
}
61+
}
62+
4863
#[derive(Serialize, Deserialize)]
4964
pub struct TxInput {
5065
pub txid: Txid,
@@ -116,3 +131,38 @@ where
116131
s.serialize_field("vout", &outpoint.vout)?;
117132
s.end()
118133
}
134+
135+
136+
#[cfg(all(test, feature = "liquid"))]
137+
mod test {
138+
use bitcoin::hashes::Hash;
139+
use elements::BlockHash;
140+
use crate::util::BlockId;
141+
use super::optional_value_for_newer_blocks;
142+
143+
#[test]
144+
fn opt_value_newer_block() {
145+
let value = 123;
146+
let check_time = 32;
147+
let hash = BlockHash::from_slice(&[0; 32]).unwrap();
148+
let height = 456;
149+
150+
// unconfirmed block should include the value
151+
let block_id = None;
152+
assert_eq!(optional_value_for_newer_blocks(block_id, check_time, value), Some(value));
153+
154+
// block time before check_time should NOT include the value
155+
let block_id = Some(BlockId{ height, hash, time: 0 });
156+
assert_eq!(optional_value_for_newer_blocks(block_id, check_time, value), None);
157+
let block_id = Some(BlockId{ height, hash, time: 31 });
158+
assert_eq!(optional_value_for_newer_blocks(block_id, check_time, value), None);
159+
160+
// block time on or after check_time should include the value
161+
let block_id = Some(BlockId{ height, hash, time: 32 });
162+
assert_eq!(optional_value_for_newer_blocks(block_id, check_time, value), Some(value));
163+
let block_id = Some(BlockId{ height, hash, time: 33 });
164+
assert_eq!(optional_value_for_newer_blocks(block_id, check_time, value), Some(value));
165+
let block_id = Some(BlockId{ height, hash, time: 333 });
166+
assert_eq!(optional_value_for_newer_blocks(block_id, check_time, value), Some(value));
167+
}
168+
}

0 commit comments

Comments
 (0)