@@ -116,20 +116,23 @@ impl HttpRequest for RPCPostStackerDBChunkRequestHandler {
116
116
pub enum StackerDBErrorCodes {
117
117
DataAlreadyExists ,
118
118
NoSuchSlot ,
119
+ BadSigner ,
119
120
}
120
121
121
122
impl StackerDBErrorCodes {
122
123
pub fn code ( & self ) -> u32 {
123
124
match self {
124
125
Self :: DataAlreadyExists => 0 ,
125
126
Self :: NoSuchSlot => 1 ,
127
+ Self :: BadSigner => 2 ,
126
128
}
127
129
}
128
130
129
131
pub fn reason ( & self ) -> & ' static str {
130
132
match self {
131
133
Self :: DataAlreadyExists => "Data for this slot and version already exist" ,
132
134
Self :: NoSuchSlot => "No such StackerDB slot" ,
135
+ Self :: BadSigner => "Signature does not match slot signer" ,
133
136
}
134
137
}
135
138
@@ -183,11 +186,18 @@ impl RPCRequestHandler for RPCPostStackerDBChunkRequestHandler {
183
186
& HttpNotFound :: new ( "StackerDB not found" . to_string ( ) ) ,
184
187
) ) ;
185
188
}
186
- if let Err ( _e ) = tx. try_replace_chunk (
189
+ if let Err ( e ) = tx. try_replace_chunk (
187
190
& contract_identifier,
188
191
& stackerdb_chunk. get_slot_metadata ( ) ,
189
192
& stackerdb_chunk. data ,
190
193
) {
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
+ ) ;
191
201
let slot_metadata_opt =
192
202
match tx. get_slot_metadata ( & contract_identifier, stackerdb_chunk. slot_id ) {
193
203
Ok ( slot_opt) => slot_opt,
@@ -209,11 +219,15 @@ impl RPCRequestHandler for RPCPostStackerDBChunkRequestHandler {
209
219
210
220
let ( reason, slot_metadata_opt) = if let Some ( slot_metadata) = slot_metadata_opt
211
221
{
222
+ let code = if let NetError :: BadSlotSigner ( ..) = e {
223
+ StackerDBErrorCodes :: BadSigner
224
+ } else {
225
+ StackerDBErrorCodes :: DataAlreadyExists
226
+ } ;
227
+
212
228
(
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 ( ) ) ,
217
231
Some ( slot_metadata) ,
218
232
)
219
233
} else {
0 commit comments