Skip to content

Commit bc716db

Browse files
committed
fix: a bad slot signature should be a distinct error
1 parent ec96e7a commit bc716db

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

stackslib/src/net/api/poststackerdbchunk.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,23 @@ impl HttpRequest for RPCPostStackerDBChunkRequestHandler {
116116
pub enum StackerDBErrorCodes {
117117
DataAlreadyExists,
118118
NoSuchSlot,
119+
BadSigner,
119120
}
120121

121122
impl StackerDBErrorCodes {
122123
pub fn code(&self) -> u32 {
123124
match self {
124125
Self::DataAlreadyExists => 0,
125126
Self::NoSuchSlot => 1,
127+
Self::BadSigner => 2,
126128
}
127129
}
128130

129131
pub fn reason(&self) -> &'static str {
130132
match self {
131133
Self::DataAlreadyExists => "Data for this slot and version already exist",
132134
Self::NoSuchSlot => "No such StackerDB slot",
135+
Self::BadSigner => "Signature does not match slot signer",
133136
}
134137
}
135138

@@ -183,11 +186,18 @@ impl RPCRequestHandler for RPCPostStackerDBChunkRequestHandler {
183186
&HttpNotFound::new("StackerDB not found".to_string()),
184187
));
185188
}
186-
if let Err(_e) = tx.try_replace_chunk(
189+
if let Err(e) = tx.try_replace_chunk(
187190
&contract_identifier,
188191
&stackerdb_chunk.get_slot_metadata(),
189192
&stackerdb_chunk.data,
190193
) {
194+
test_debug!(
195+
"Failed to replace chunk {}.{} in {}: {:?}",
196+
stackerdb_chunk.slot_id,
197+
stackerdb_chunk.slot_version,
198+
&contract_identifier,
199+
&e
200+
);
191201
let slot_metadata_opt =
192202
match tx.get_slot_metadata(&contract_identifier, stackerdb_chunk.slot_id) {
193203
Ok(slot_opt) => slot_opt,
@@ -209,11 +219,15 @@ impl RPCRequestHandler for RPCPostStackerDBChunkRequestHandler {
209219

210220
let (reason, slot_metadata_opt) = if let Some(slot_metadata) = slot_metadata_opt
211221
{
222+
let code = if let NetError::BadSlotSigner(..) = e {
223+
StackerDBErrorCodes::BadSigner
224+
} else {
225+
StackerDBErrorCodes::DataAlreadyExists
226+
};
227+
212228
(
213-
serde_json::to_string(
214-
&StackerDBErrorCodes::DataAlreadyExists.into_json(),
215-
)
216-
.unwrap_or("(unable to encode JSON)".to_string()),
229+
serde_json::to_string(&code.into_json())
230+
.unwrap_or("(unable to encode JSON)".to_string()),
217231
Some(slot_metadata),
218232
)
219233
} else {

0 commit comments

Comments
 (0)