Skip to content

Commit

Permalink
Update put_chunk to take a ref and cleanup clippy
Browse files Browse the repository at this point in the history
Signed-off-by: Jacinta Ferrant <[email protected]>
  • Loading branch information
jferrant committed Jan 10, 2024
1 parent 8418456 commit 7db8548
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
6 changes: 3 additions & 3 deletions libsigner/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub trait SignerSession {
/// query the replica for zero or more latest chunks
fn get_latest_chunks(&mut self, slot_ids: &[u32]) -> Result<Vec<Option<Vec<u8>>>, RPCError>;
/// Upload a chunk to the stacker DB instance
fn put_chunk(&mut self, chunk: StackerDBChunkData) -> Result<StackerDBChunkAckData, RPCError>;
fn put_chunk(&mut self, chunk: &StackerDBChunkData) -> Result<StackerDBChunkAckData, RPCError>;

/// Get a single chunk with the given version
/// Returns Ok(Some(..)) if the chunk exists
Expand Down Expand Up @@ -207,9 +207,9 @@ impl SignerSession for StackerDBSession {
}

/// upload a chunk
fn put_chunk(&mut self, chunk: StackerDBChunkData) -> Result<StackerDBChunkAckData, RPCError> {
fn put_chunk(&mut self, chunk: &StackerDBChunkData) -> Result<StackerDBChunkAckData, RPCError> {
let body =
serde_json::to_vec(&chunk).map_err(|e| RPCError::Deserialize(format!("{:?}", &e)))?;
serde_json::to_vec(chunk).map_err(|e| RPCError::Deserialize(format!("{:?}", &e)))?;
let path = stackerdb_post_chunk_path(self.stackerdb_contract_id.clone());
let resp_bytes = self.rpc_request("POST", &path, Some("application/json"), &body)?;
let ack: StackerDBChunkAckData = serde_json::from_slice(&resp_bytes)
Expand Down
4 changes: 2 additions & 2 deletions stacks-signer/src/client/stackerdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,10 @@ impl StackerDB {
let slot_version = *self.slot_versions.entry(slot_id).or_insert(0) + 1;
let mut chunk = StackerDBChunkData::new(slot_id, slot_version, message_bytes.clone());
chunk.sign(&self.stacks_private_key)?;
debug!("Sending a chunk to stackerdb!\n{:?}", chunk.clone());
debug!("Sending a chunk to stackerdb!\n{:?}", &chunk);
let send_request = || {
self.signers_stackerdb_session
.put_chunk(chunk.clone())
.put_chunk(&chunk)
.map_err(backoff::Error::transient)
};
let chunk_ack: StackerDBChunkAckData = retry_with_exponential_backoff(send_request)?;
Expand Down
2 changes: 1 addition & 1 deletion stacks-signer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ fn handle_put_chunk(args: PutChunkArgs) {
let mut session = stackerdb_session(args.db_args.host, args.db_args.contract);
let mut chunk = StackerDBChunkData::new(args.slot_id, args.slot_version, args.data);
chunk.sign(&args.private_key).unwrap();
let chunk_ack = session.put_chunk(chunk).unwrap();
let chunk_ack = session.put_chunk(&chunk).unwrap();
println!("{}", serde_json::to_string(&chunk_ack).unwrap());
}

Expand Down
7 changes: 4 additions & 3 deletions stacks-signer/src/runloop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,12 @@ impl<C: Coordinator> RunLoop<C> {
// Received a block proposal from the miner.
// If the signer is the coordinator, then trigger a Signing round for the block
if coordinator_id == self.signing_round.signer_id {
// Don't bother triggering a signing round for the block if it is invalid
if !self.stacks_client.is_valid_nakamoto_block(&block).unwrap_or_else(|e| {
let is_valid_block = self.stacks_client.is_valid_nakamoto_block(&block).unwrap_or_else(|e| {
warn!("Failed to validate block: {:?}", e);
false
}) {
});
// Don't bother triggering a signing round for the block if it is invalid
if !is_valid_block {
warn!("Received an invalid block proposal from the miner. Ignoring block proposal: {:?}", block);
return;
}
Expand Down

0 comments on commit 7db8548

Please sign in to comment.