diff --git a/pool/tests/block_reconciliation.rs b/pool/tests/block_reconciliation.rs index 73f6a5d22..8525ea198 100644 --- a/pool/tests/block_reconciliation.rs +++ b/pool/tests/block_reconciliation.rs @@ -183,6 +183,10 @@ fn test_transaction_pool_block_reconciliation() { }).unwrap(); } + let tip = Tip::from_block(&block.header); + chain.store.save_block_header(&block.header).unwrap(); + chain.store.save_head(&tip).unwrap(); + block }; @@ -191,9 +195,9 @@ fn test_transaction_pool_block_reconciliation() { let mut write_pool = pool.write().unwrap(); write_pool.reconcile_block(&block).unwrap(); - assert_eq!(write_pool.total_size(), 4); - assert_eq!(write_pool.txpool.entries[0].tx, valid_transaction); // TODO - this is the "correct" behavior (see below) + // assert_eq!(write_pool.total_size(), 4); + // assert_eq!(write_pool.txpool.entries[0].tx, valid_transaction); // assert_eq!(write_pool.txpool.entries[1].tx, pool_child); // assert_eq!(write_pool.txpool.entries[2].tx, conflict_valid_child); // assert_eq!(write_pool.txpool.entries[3].tx, valid_child_valid); @@ -205,6 +209,8 @@ fn test_transaction_pool_block_reconciliation() { // // TODO - wtf is with these name permutations... // + assert_eq!(write_pool.total_size(), 4); + assert_eq!(write_pool.txpool.entries[0].tx, valid_transaction); assert_eq!(write_pool.txpool.entries[1].tx, conflict_valid_child); assert_eq!(write_pool.txpool.entries[2].tx, valid_child_conflict); assert_eq!(write_pool.txpool.entries[3].tx, valid_child_valid); diff --git a/store/src/types.rs b/store/src/types.rs index f955071b8..a688bace2 100644 --- a/store/src/types.rs +++ b/store/src/types.rs @@ -148,11 +148,8 @@ impl AppendOnlyFile { /// Leverages the memory map. pub fn read(&self, offset: usize, length: usize) -> Vec { if offset >= self.buffer_start { - if self.buffer.is_empty() { - return vec![]; - } - let offset = offset - self.buffer_start; - return self.buffer[offset..(offset + length)].to_vec(); + let buffer_offset = offset - self.buffer_start; + return self.read_from_buffer(buffer_offset, length); } if let None = self.mmap { return vec![]; @@ -166,6 +163,17 @@ impl AppendOnlyFile { (&mmap[offset..(offset + length)]).to_vec() } + // Read length bytes from the buffer, from offset. + // Return empty vec if we do not have enough bytes in the buffer to read a full + // vec. + fn read_from_buffer(&self, offset: usize, length: usize) -> Vec { + if self.buffer.len() < (offset + length) { + vec![] + } else { + self.buffer[offset..(offset + length)].to_vec() + } + } + /// Truncates the underlying file to the provided offset pub fn truncate(&self, offs: usize) -> io::Result<()> { let fd = self.file.as_raw_fd();