Skip to content

Commit 705ebf3

Browse files
committed
chore: address PR feedback
1 parent 4376f14 commit 705ebf3

File tree

4 files changed

+41
-30
lines changed

4 files changed

+41
-30
lines changed

stackslib/src/net/api/getstackers.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ impl HttpRequest for GetStackersRequestHandler {
121121
}
122122

123123
fn path_regex(&self) -> Regex {
124-
Regex::new(r#"^/v3/stacker_set/(?P<cycle_num>[0-9]{1,20})$"#).unwrap()
124+
Regex::new(r#"^/v3/stacker_set/(?P<cycle_num>[0-9]{1,10})$"#).unwrap()
125125
}
126126

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

stackslib/src/net/atlas/db.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,8 +494,12 @@ impl AtlasDB {
494494
page_index: u32,
495495
block_id: &StacksBlockId,
496496
) -> Result<Vec<bool>, db_error> {
497-
let min = page_index * AttachmentInstance::ATTACHMENTS_INV_PAGE_SIZE;
498-
let max = min + AttachmentInstance::ATTACHMENTS_INV_PAGE_SIZE;
497+
let min = page_index
498+
.checked_mul(AttachmentInstance::ATTACHMENTS_INV_PAGE_SIZE)
499+
.ok_or(db_error::Overflow)?;
500+
let max = min
501+
.checked_add(AttachmentInstance::ATTACHMENTS_INV_PAGE_SIZE)
502+
.ok_or(db_error::Overflow)?;
499503
let qry = "SELECT attachment_index, is_available FROM attachment_instances WHERE attachment_index >= ?1 AND attachment_index < ?2 AND index_block_hash = ?3 ORDER BY attachment_index ASC";
500504
let args = params![min, max, block_id,];
501505
let rows = query_rows::<(u32, u32), _>(&self.conn, &qry, args)?;

stackslib/src/net/httpcore.rs

Lines changed: 18 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1686,17 +1686,17 @@ impl ProtocolFamily for StacksHttp {
16861686
&req.preamble().verb,
16871687
&decoded_path
16881688
)))?;
1689-
handler_index
1689+
Some(handler_index)
16901690
} else {
1691-
0
1691+
None
16921692
};
16931693

16941694
req.send(fd)?;
16951695

16961696
// remember this so we'll know how to decode the response.
16971697
// The next preamble and message we'll read _must be_ a response!
1698-
if !self.allow_arbitrary_response {
1699-
self.request_handler_index = Some(handler_index);
1698+
if handler_index.is_some() {
1699+
self.request_handler_index = handler_index;
17001700
}
17011701
Ok(())
17021702
}
@@ -1768,14 +1768,10 @@ pub fn decode_request_path(path: &str) -> Result<(String, String), NetError> {
17681768

17691769
/// Convert a NetError into an io::Error if appropriate.
17701770
fn handle_net_error(e: NetError, msg: &str) -> io::Error {
1771-
if let NetError::ReadError(ioe) = e {
1772-
ioe
1773-
} else if let NetError::WriteError(ioe) = e {
1774-
ioe
1775-
} else if let NetError::RecvTimeout = e {
1776-
io::Error::new(io::ErrorKind::WouldBlock, "recv timeout")
1777-
} else {
1778-
io::Error::new(io::ErrorKind::Other, format!("{}: {:?}", &e, msg).as_str())
1771+
match e {
1772+
NetError::ReadError(ioe) | NetError::WriteError(ioe) => ioe,
1773+
NetError::RecvTimeout => io::Error::new(io::ErrorKind::WouldBlock, "recv timeout"),
1774+
_ => io::Error::new(io::ErrorKind::Other, format!("{}: {:?}", &e, msg).as_str()),
17791775
}
17801776
}
17811777

@@ -1911,8 +1907,7 @@ pub fn send_http_request(
19111907
// and dispatched any new messages to the request handle. If so, then extract the message and
19121908
// check that it's a well-formed HTTP response.
19131909
debug!("send_request(receiving data)");
1914-
let response;
1915-
loop {
1910+
let response = loop {
19161911
// get back the reply
19171912
debug!("send_request(receiving data): try to receive data");
19181913
match connection.recv_data(&mut stream) {
@@ -1932,18 +1927,15 @@ pub fn send_http_request(
19321927
debug!("send_request(receiving data): try receive response");
19331928
let rh = match request_handle.try_recv() {
19341929
Ok(resp) => {
1935-
response = resp;
1936-
break;
1930+
break resp;
1931+
}
1932+
Err(Ok(handle)) => handle,
1933+
Err(Err(e)) => {
1934+
return Err(handle_net_error(
1935+
e,
1936+
"Failed to receive message after socket has been drained",
1937+
));
19371938
}
1938-
Err(e) => match e {
1939-
Ok(handle) => handle,
1940-
Err(e) => {
1941-
return Err(handle_net_error(
1942-
e,
1943-
"Failed to receive message after socket has been drained",
1944-
));
1945-
}
1946-
},
19471939
};
19481940
request_handle = rh;
19491941

@@ -1953,7 +1945,7 @@ pub fn send_http_request(
19531945
"Timed out while receiving request",
19541946
));
19551947
}
1956-
}
1948+
};
19571949

19581950
// Step 5: decode the HTTP message and return it if it's not an error.
19591951
let response_data = match response {

testnet/stacks-node/src/burnchains/bitcoin_regtest_controller.rs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,19 @@
1-
use std::convert::From;
1+
// Copyright (C) 2013-2020 Blockstack PBC, a public benefit corporation
2+
// Copyright (C) 2020-2024 Stacks Open Internet Foundation
3+
//
4+
// This program is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// This program is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with this program. If not, see <http://www.gnu.org/licenses/>.
16+
217
use std::io::Cursor;
318
use std::sync::atomic::{AtomicBool, Ordering};
419
use std::sync::Arc;

0 commit comments

Comments
 (0)