Skip to content

Commit c5aa341

Browse files
authored
Merge pull request #5518 from stacks-network/fix/trailing-v3-blocks-upload-regex
fix v3 update block to support no trailing
2 parents 2833cfb + 2ae7a18 commit c5aa341

File tree

2 files changed

+61
-1
lines changed

2 files changed

+61
-1
lines changed

stackslib/src/net/api/postblock_v3.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl HttpRequest for RPCPostBlockRequestHandler {
7070
}
7171

7272
fn path_regex(&self) -> Regex {
73-
Regex::new(&format!("^{PATH}$")).unwrap()
73+
Regex::new(&format!("^{}(/)?$", PATH.trim_end_matches('/'))).unwrap()
7474
}
7575

7676
fn metrics_identifier(&self) -> &str {

stackslib/src/net/api/tests/postblock_v3.rs

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,66 @@ fn handle_req_accepted() {
214214
assert_eq!(resp.stacks_block_id, next_block_id);
215215
}
216216

217+
#[test]
218+
fn handle_req_without_trailing_accepted() {
219+
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 33333);
220+
let path_without_slash: &str = "/v3/blocks/upload";
221+
let observer = TestEventObserver::new();
222+
let mut rpc_test = TestRPC::setup_nakamoto(function_name!(), &observer);
223+
let (next_block, ..) = rpc_test.peer_1.single_block_tenure(
224+
&rpc_test.privk1,
225+
|_| {},
226+
|burn_ops| {
227+
rpc_test.peer_2.next_burnchain_block(burn_ops.clone());
228+
},
229+
|_| true,
230+
);
231+
let next_block_id = next_block.block_id();
232+
let mut requests = vec![];
233+
234+
// post the block
235+
requests.push(
236+
StacksHttpRequest::new_for_peer(
237+
addr.into(),
238+
"POST".into(),
239+
path_without_slash.into(),
240+
HttpRequestContents::new().payload_stacks(&next_block),
241+
)
242+
.unwrap(),
243+
);
244+
245+
// idempotent
246+
requests.push(
247+
StacksHttpRequest::new_for_peer(
248+
addr.into(),
249+
"POST".into(),
250+
path_without_slash.into(),
251+
HttpRequestContents::new().payload_stacks(&next_block),
252+
)
253+
.unwrap(),
254+
);
255+
let mut responses = rpc_test.run(requests);
256+
257+
let response = responses.remove(0);
258+
info!(
259+
"Response for the request that has the path without the last '/': {}",
260+
std::str::from_utf8(&response.try_serialize().unwrap()).unwrap()
261+
);
262+
263+
let resp = response.decode_stacks_block_accepted().unwrap();
264+
assert_eq!(resp.accepted, true);
265+
assert_eq!(resp.stacks_block_id, next_block_id);
266+
267+
let response = responses.remove(0);
268+
info!(
269+
"Response for the request that has the path without the last '/': {}",
270+
std::str::from_utf8(&response.try_serialize().unwrap()).unwrap()
271+
);
272+
let resp = response.decode_stacks_block_accepted().unwrap();
273+
assert_eq!(resp.accepted, false);
274+
assert_eq!(resp.stacks_block_id, next_block_id);
275+
}
276+
217277
#[test]
218278
fn handle_req_unknown_burn_block() {
219279
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 33333);

0 commit comments

Comments
 (0)