Skip to content

Commit 107fdc9

Browse files
author
Michael Rosenberg
committed
Address small PR comments
1 parent 6378dfb commit 107fdc9

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

crates/generic_log_worker/src/log_ops.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ struct ProofPreparer(RefCell<Vec<TlogTile>>);
232232

233233
impl TileReader for ProofPreparer {
234234
fn height(&self) -> u8 {
235-
8
235+
TlogTile::HEIGHT
236236
}
237237

238238
fn read_tiles(&self, tiles: &[Tile]) -> Result<Vec<Vec<u8>>, TlogError> {
@@ -241,7 +241,7 @@ impl TileReader for ProofPreparer {
241241
*self.0.borrow_mut() = tiles
242242
.iter()
243243
.map(|t| {
244-
if t.height() != 8 {
244+
if t.height() != TlogTile::HEIGHT {
245245
Err(TlogError::InvalidInput(
246246
"SimpleTlogTileReader cannot read tiles of height not equal to 8"
247247
.to_string(),
@@ -267,7 +267,7 @@ struct SimpleTlogTileReader(HashMap<TlogTile, Vec<u8>>);
267267

268268
impl TileReader for SimpleTlogTileReader {
269269
fn height(&self) -> u8 {
270-
8
270+
TlogTile::HEIGHT
271271
}
272272

273273
/// Converts the given tiles into tlog tiles, then reads them from the
@@ -277,11 +277,11 @@ impl TileReader for SimpleTlogTileReader {
277277
/// Errors if any of given tiles hash height != 8, or is a data tile. Also
278278
/// errors if the hash map is missing tiles from the input here.
279279
fn read_tiles(&self, tiles: &[Tile]) -> Result<Vec<Vec<u8>>, TlogError> {
280-
let mut buf = Vec::with_capacity(32 * (1 << self.height()));
280+
let mut buf = Vec::with_capacity(HASH_SIZE * TlogTile::FULL_WIDTH as usize);
281281

282282
for tile in tiles {
283283
// Convert the tile to a tlog-tile, ie one where height=8 and data=false
284-
if tile.height() != 8 {
284+
if tile.height() != TlogTile::HEIGHT {
285285
return Err(TlogError::InvalidInput(
286286
"SimpleTlogTileReader cannot read tiles of height not equal to 8".to_string(),
287287
));
@@ -1454,7 +1454,7 @@ mod tests {
14541454
let last_hash: Hash = {
14551455
// Get the rightmost leaf tile, then extract the last hash from it
14561456
let leaf_edge = &sequence_state.edge_tiles.get(&0u8).unwrap().b;
1457-
Hash(leaf_edge[leaf_edge.len() - 32..].try_into().unwrap())
1457+
Hash(leaf_edge[leaf_edge.len() - HASH_SIZE..].try_into().unwrap())
14581458
};
14591459
check_record(&inc_proof, tree_size, new_tree_hash, leaf_index, last_hash).unwrap();
14601460

@@ -1482,17 +1482,17 @@ mod tests {
14821482
for i in 0..n {
14831483
// Compute the inclusion proof for leaf i
14841484
let proof = block_on(sequence_state.prove_inclusion(&log.object, i)).unwrap();
1485-
// Verify the inclusino proof. We need the leaf hash
1485+
// Verify the inclusion proof. We need the leaf hash
14861486
let leaf_hash = {
14871487
// Get the tile the leaf belongs to, and correct the width by getting the 0th parent
14881488
let leaf_tile = TlogTile::from_leaf_index(i).parent(0, n).unwrap();
14891489
let leaf_tile_data = block_on(log.object.fetch(&leaf_tile.path()))
14901490
.unwrap()
14911491
.unwrap();
14921492
// Extract the correct hash from the tile
1493-
let leaf_tile_idx = i as usize % 256;
1493+
let leaf_tile_idx = (i % TlogTile::FULL_WIDTH as u64) as usize;
14941494
Hash(
1495-
leaf_tile_data[32 * leaf_tile_idx..32 * (leaf_tile_idx + 1)]
1495+
leaf_tile_data[HASH_SIZE * leaf_tile_idx..HASH_SIZE * (leaf_tile_idx + 1)]
14961496
.try_into()
14971497
.unwrap(),
14981498
)

crates/generic_log_worker/src/sequencer_do.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ use prometheus::{Registry, TextEncoder};
1818
use serde::{Deserialize, Serialize};
1919
use serde_with::base64::Base64;
2020
use serde_with::serde_as;
21-
use tlog_tiles::{CheckpointSigner, LogEntry, PendingLogEntry, RecordProof};
21+
use tlog_tiles::{
22+
CheckpointSigner, LeafIndex, LogEntry, PendingLogEntry, RecordProof, UnixTimestamp,
23+
};
2224
use tokio::sync::Mutex;
2325
use worker::{Bucket, Error as WorkerError, Request, Response, State};
2426

@@ -47,7 +49,7 @@ pub struct SequencerConfig {
4749
pub checkpoint_signers: Vec<Box<dyn CheckpointSigner>>,
4850
/// A function that takes a Unix timestamp in milliseconds and returns
4951
/// extension lines to be included in the checkpoint
50-
pub checkpoint_extension: Box<dyn Fn(u64) -> Vec<String>>,
52+
pub checkpoint_extension: Box<dyn Fn(UnixTimestamp) -> Vec<String>>,
5153
pub sequence_interval: Duration,
5254
pub max_sequence_skips: usize,
5355
pub sequence_skip_threshold_millis: Option<u64>,
@@ -57,7 +59,7 @@ pub struct SequencerConfig {
5759
/// GET query structure for the sequencer's /prove_inclusion endpoint
5860
#[derive(Serialize, Deserialize)]
5961
pub struct ProveInclusionQuery {
60-
pub leaf_index: u64,
62+
pub leaf_index: LeafIndex,
6163
}
6264

6365
/// GET response structure for the sequencer's /prove_inclusion endpoint
@@ -263,7 +265,7 @@ impl<L: LogEntry> GenericSequencer<L> {
263265
.collect::<Vec<_>>()
264266
}
265267

266-
/// Returns the number of entires in this log
268+
/// Returns the number of entries in this log
267269
pub fn log_size(&self) -> Result<u64, WorkerError> {
268270
if let Some(s) = self.sequence_state.as_ref() {
269271
Ok(s.num_leaves())
@@ -343,7 +345,7 @@ impl<L: LogEntry> GenericSequencer<L> {
343345
///
344346
/// # Errors
345347
/// Errors when sequencer state has not been loaded
346-
pub fn prove_inclusion_of_last_elem(&mut self) -> Result<RecordProof, WorkerError> {
348+
pub fn prove_inclusion_of_last_elem(&self) -> Result<RecordProof, WorkerError> {
347349
if let Some(s) = self.sequence_state.as_ref() {
348350
Ok(s.prove_inclusion_of_last_elem())
349351
} else {

crates/tlog_tiles/src/checkpoint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl Checkpoint {
153153
}
154154

155155
/// Return a new checkpoint with the given arguments. The items in
156-
/// `extensions` MUST NOT contain a newline.
156+
/// `extensions` MUST NOT be empty or contain a newline.
157157
///
158158
/// # Errors
159159
///
@@ -169,7 +169,7 @@ impl Checkpoint {
169169
return Err(MalformedCheckpointError);
170170
}
171171

172-
if extensions.iter().any(|e| e.is_empty()) {
172+
if extensions.iter().any(|e| e.is_empty() || e.contains('\n')) {
173173
return Err(MalformedCheckpointError);
174174
}
175175

0 commit comments

Comments
 (0)