Skip to content

Commit b2eb314

Browse files
author
Ludo Galabru
committed
fix: decrease compression - from 4 bytes to 8 bytes
1 parent db14f60 commit b2eb314

File tree

1 file changed

+40
-19
lines changed
  • components/chainhook-event-observer/src/hord/db

1 file changed

+40
-19
lines changed

components/chainhook-event-observer/src/hord/db/mod.rs

+40-19
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,11 @@ fn create_or_open_readwrite_db(cache_path: &PathBuf, ctx: &Context) -> Connectio
126126
};
127127
// db.profile(Some(trace_profile));
128128
// db.busy_handler(Some(tx_busy_handler))?;
129-
130-
let mmap_size: i64 = 256 * 1024 * 1024;
131-
let page_size: i64 = 16384;
132-
conn.pragma_update(None, "mmap_size", mmap_size).unwrap();
133-
conn.pragma_update(None, "page_size", page_size).unwrap();
134-
conn.pragma_update(None, "synchronous", &"NORMAL").unwrap();
129+
// let mmap_size: i64 = 256 * 1024 * 1024;
130+
// let page_size: i64 = 16384;
131+
// conn.pragma_update(None, "mmap_size", mmap_size).unwrap();
132+
// conn.pragma_update(None, "page_size", page_size).unwrap();
133+
// conn.pragma_update(None, "synchronous", &"NORMAL").unwrap();
135134
conn
136135
}
137136

@@ -197,24 +196,26 @@ fn open_existing_readonly_db(path: &PathBuf, ctx: &Context) -> Connection {
197196
#[repr(C)]
198197
pub struct CompactedBlock(
199198
pub (
200-
([u8; 4], u64),
201-
Vec<([u8; 4], Vec<([u8; 4], u32, u16, u64)>, Vec<u64>)>,
199+
([u8; 8], u64),
200+
Vec<([u8; 8], Vec<([u8; 8], u32, u16, u64)>, Vec<u64>)>,
202201
),
203202
);
204203

205204
use std::io::{Read, Write};
206205

207206
impl CompactedBlock {
208207
fn empty() -> CompactedBlock {
209-
CompactedBlock((([0, 0, 0, 0], 0), vec![]))
208+
CompactedBlock((([0, 0, 0, 0, 0, 0, 0, 0], 0), vec![]))
210209
}
211210

212211
pub fn from_full_block(block: &BitcoinBlockFullBreakdown) -> CompactedBlock {
213212
let mut txs = vec![];
214213
let mut coinbase_value = 0;
215214
let coinbase_txid = {
216215
let txid = hex::decode(block.tx[0].txid.to_string()).unwrap();
217-
[txid[0], txid[1], txid[2], txid[3]]
216+
[
217+
txid[0], txid[1], txid[2], txid[3], txid[4], txid[5], txid[6], txid[7],
218+
]
218219
};
219220
for coinbase_output in block.tx[0].vout.iter() {
220221
coinbase_value += coinbase_output.value.to_sat();
@@ -225,7 +226,9 @@ impl CompactedBlock {
225226
let txin = hex::decode(input.txid.unwrap().to_string()).unwrap();
226227

227228
inputs.push((
228-
[txin[0], txin[1], txin[2], txin[3]],
229+
[
230+
txin[0], txin[1], txin[2], txin[3], txin[4], txin[5], txin[6], txin[7],
231+
],
229232
input.prevout.as_ref().unwrap().height as u32,
230233
input.vout.unwrap() as u16,
231234
input.prevout.as_ref().unwrap().value.to_sat(),
@@ -236,7 +239,13 @@ impl CompactedBlock {
236239
outputs.push(output.value.to_sat());
237240
}
238241
let txid = hex::decode(tx.txid.to_string()).unwrap();
239-
txs.push(([txid[0], txid[1], txid[2], txid[3]], inputs, outputs));
242+
txs.push((
243+
[
244+
txid[0], txid[1], txid[2], txid[3], txid[4], txid[5], txid[6], txid[7],
245+
],
246+
inputs,
247+
outputs,
248+
));
240249
}
241250
CompactedBlock(((coinbase_txid, coinbase_value), txs))
242251
}
@@ -247,7 +256,9 @@ impl CompactedBlock {
247256
let coinbase_txid = {
248257
let txid =
249258
hex::decode(&block.transactions[0].transaction_identifier.hash[2..]).unwrap();
250-
[txid[0], txid[1], txid[2], txid[3]]
259+
[
260+
txid[0], txid[1], txid[2], txid[3], txid[4], txid[5], txid[6], txid[7],
261+
]
251262
};
252263
for coinbase_output in block.transactions[0].metadata.outputs.iter() {
253264
coinbase_value += coinbase_output.value;
@@ -258,7 +269,9 @@ impl CompactedBlock {
258269
let txin = hex::decode(&input.previous_output.txid[2..]).unwrap();
259270

260271
inputs.push((
261-
[txin[0], txin[1], txin[2], txin[3]],
272+
[
273+
txin[0], txin[1], txin[2], txin[3], txin[4], txin[5], txin[6], txin[7],
274+
],
262275
input.previous_output.block_height as u32,
263276
input.previous_output.vout as u16,
264277
input.previous_output.value,
@@ -269,7 +282,13 @@ impl CompactedBlock {
269282
outputs.push(output.value);
270283
}
271284
let txid = hex::decode(&tx.transaction_identifier.hash[2..]).unwrap();
272-
txs.push(([txid[0], txid[1], txid[2], txid[3]], inputs, outputs));
285+
txs.push((
286+
[
287+
txid[0], txid[1], txid[2], txid[3], txid[4], txid[5], txid[6], txid[7],
288+
],
289+
inputs,
290+
outputs,
291+
));
273292
}
274293
CompactedBlock(((coinbase_txid, coinbase_value), txs))
275294
}
@@ -306,21 +325,21 @@ impl CompactedBlock {
306325
}
307326

308327
fn deserialize<R: Read>(fd: &mut R) -> std::io::Result<CompactedBlock> {
309-
let mut ci = [0u8; 4];
328+
let mut ci = [0u8; 8];
310329
fd.read_exact(&mut ci)?;
311330
let mut cv = [0u8; 8];
312331
fd.read_exact(&mut cv)?;
313332
let mut tx_len = [0u8; 8];
314333
fd.read_exact(&mut tx_len)?;
315334
let mut txs = vec![];
316335
for _ in 0..usize::from_be_bytes(tx_len) {
317-
let mut txid = [0u8; 4];
336+
let mut txid = [0u8; 8];
318337
fd.read_exact(&mut txid)?;
319338
let mut inputs_len = [0u8; 8];
320339
fd.read_exact(&mut inputs_len)?;
321340
let mut inputs = vec![];
322341
for _ in 0..usize::from_be_bytes(inputs_len) {
323-
let mut txin = [0u8; 4];
342+
let mut txin = [0u8; 8];
324343
fd.read_exact(&mut txin)?;
325344
let mut block = [0u8; 4];
326345
fd.read_exact(&mut block)?;
@@ -921,7 +940,9 @@ pub fn retrieve_satoshi_point_using_local_storage(
921940
let mut ordinal_block_number = block_identifier.index as u32;
922941
let txid = {
923942
let bytes = hex::decode(&transaction_identifier.hash[2..]).unwrap();
924-
[bytes[0], bytes[1], bytes[2], bytes[3]]
943+
[
944+
bytes[0], bytes[1], bytes[2], bytes[3], bytes[4], bytes[5], bytes[6], bytes[7],
945+
]
925946
};
926947
let mut tx_cursor = (txid, 0);
927948
let mut hops: u32 = 0;

0 commit comments

Comments
 (0)