summary refs log tree commit diff
path: root/ripple/fossil
diff options
context:
space:
mode:
authoredef <edef@unfathomable.blue>2022-04-25 00:11:33 +0000
committeredef <edef@unfathomable.blue>2022-04-25 00:11:33 +0000
commit2d1c796947dff6370dc5de27abdc789c1f9dd338 (patch)
tree0fdc63ca834bfaef0a7b9b9d87295afd9d2a64df /ripple/fossil
parent1d7ce6b089931f48e254e9ec520de1e3e007ee8d (diff)
downloadunf-legacy-2d1c796947dff6370dc5de27abdc789c1f9dd338.tar.zst
ripple/fossil: store bao outboard tree in the blob metadata
One step closer to genuine incremental blob reads.

Change-Id: I796710820c1b69baad91a6dc65f9d7f0dee311d3
Diffstat (limited to 'ripple/fossil')
-rw-r--r--ripple/fossil/src/lib.rs53
-rw-r--r--ripple/fossil/src/store.proto1
2 files changed, 26 insertions, 28 deletions
diff --git a/ripple/fossil/src/lib.rs b/ripple/fossil/src/lib.rs
index 8c182eb..4c747e8 100644
--- a/ripple/fossil/src/lib.rs
+++ b/ripple/fossil/src/lib.rs
@@ -108,10 +108,11 @@ impl Store {
 	}
 
 	fn write_blob(&self, data: &[u8]) -> Digest {
-		let ident = {
-			let mut h = blake3::Hasher::new();
-			h.update_rayon(data);
-			h.finalize()
+		let mut outboard = Vec::new();
+		let ident: blake3::Hash = {
+			let mut encoder = bao::encode::Encoder::new_outboard(io::Cursor::new(&mut outboard));
+			encoder.write_all(&data).unwrap();
+			encoder.finalize().unwrap()
 		};
 
 		if self.db.contains_key(&*ident.as_bytes()).unwrap() {
@@ -132,6 +133,7 @@ impl Store {
 		let blob_buf = store::Blob {
 			offset,
 			length: data.len() as u64,
+			bao_inline: outboard,
 		}
 		.encode_to_vec();
 
@@ -155,37 +157,32 @@ impl Store {
 	}
 
 	pub fn read_blob(&self, ident: Digest) -> Vec<u8> {
-		let mut buffer = Vec::new();
-		self.raw_blob(ident).read_to_end(&mut buffer).unwrap();
-
-		let mut outboard = Vec::new();
-		let computed_ident: blake3::Hash = {
-			let mut encoder = bao::encode::Encoder::new_outboard(io::Cursor::new(&mut outboard));
-			encoder.write_all(&buffer).unwrap();
-			encoder.finalize().unwrap()
-		};
-
-		if computed_ident != ident {
-			panic!("hash mismatch");
-		}
-
-		buffer
-	}
-
-	fn raw_blob(&self, ident: Digest) -> RawBlob<'_> {
 		let buf = self
 			.db
 			.get(&*ident.as_bytes())
 			.unwrap()
 			.expect("blob not found");
 
-		let store::Blob { offset, length } = store::Blob::decode(&*buf).unwrap();
+		let store::Blob {
+			offset,
+			length,
+			bao_inline,
+		} = store::Blob::decode(&*buf).unwrap();
+
+		let mut blob = bao::decode::Decoder::new_outboard(
+			RawBlob {
+				store: self,
+				slice: Slice { offset, length },
+				position: 0,
+			},
+			io::Cursor::new(bao_inline),
+			&ident,
+		);
+
+		let mut buffer = Vec::new();
+		blob.read_to_end(&mut buffer).unwrap();
 
-		RawBlob {
-			store: self,
-			slice: Slice { offset, length },
-			position: 0,
-		}
+		buffer
 	}
 }
 
diff --git a/ripple/fossil/src/store.proto b/ripple/fossil/src/store.proto
index cbbbbf1..cbeb16d 100644
--- a/ripple/fossil/src/store.proto
+++ b/ripple/fossil/src/store.proto
@@ -32,4 +32,5 @@ message LinkNode {
 message Blob {
     uint64 offset = 1;
     uint64 length = 2;
+    bytes bao_inline = 3;
 }