Skip to content

Commit 5a812fa

Browse files
committed
fixed blockbyheight to use the marf
1 parent 1535f9b commit 5a812fa

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

stackslib/src/net/api/getblockbyheight.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ use stacks_common::types::chainstate::{ConsensusHash, StacksBlockId};
2525
use stacks_common::types::net::PeerHost;
2626
use {serde, serde_json};
2727

28+
use crate::chainstate::nakamoto::{
29+
NakamotoBlock, NakamotoChainState, NakamotoStagingBlocksConn, StacksDBIndexed,
30+
};
2831
use crate::chainstate::nakamoto::{
2932
NakamotoBlock, NakamotoChainState, NakamotoStagingBlocksConn, StacksDBIndexed,
3033
};
@@ -124,6 +127,13 @@ impl RPCRequestHandler for RPCNakamotoBlockByHeightRequestHandler {
124127
}
125128
};
126129

130+
let tip = match node.load_stacks_chain_tip(&preamble, &contents) {
131+
Ok(tip) => tip,
132+
Err(error_resp) => {
133+
return error_resp.try_into_contents().map_err(NetError::from);
134+
}
135+
};
136+
127137
let index_block_hash_res =
128138
node.with_node_state(|_network, _sortdb, chainstate, _mempool, _rpc_args| {
129139
chainstate

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,12 @@ fn test_try_parse_request() {
5151
let addr = SocketAddr::new(IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)), 33333);
5252
let mut http = StacksHttp::new(addr.clone(), &ConnectionOptions::default());
5353

54+
// NOTE: MARF enforces the height to be a u32 value
55+
let request = StacksHttpRequest::new_get_nakamoto_block_by_height(
56+
addr.into(),
57+
0xfffffffe,
58+
TipRequest::UseLatestAnchoredTip,
59+
);
5460
// NOTE: MARF enforces the height to be a u32 value
5561
let request = StacksHttpRequest::new_get_nakamoto_block_by_height(
5662
addr.into(),
@@ -133,6 +139,15 @@ fn test_try_make_response() {
133139
let mut dummy_tip = rpc_test.canonical_tip.clone();
134140
dummy_tip.0[0] = dummy_tip.0[0].wrapping_add(1);
135141

142+
let request = StacksHttpRequest::new_get_nakamoto_block_by_height(
143+
addr.into(),
144+
nakamoto_chain_tip_height,
145+
TipRequest::SpecificTip(dummy_tip),
146+
);
147+
// dummy hack for generating an invalid tip
148+
let mut dummy_tip = rpc_test.canonical_tip.clone();
149+
dummy_tip.0[0] = dummy_tip.0[0].wrapping_add(1);
150+
136151
let request = StacksHttpRequest::new_get_nakamoto_block_by_height(
137152
addr.into(),
138153
nakamoto_chain_tip_height,

0 commit comments

Comments
 (0)