Skip to content

Commit 894cbfb

Browse files
Merge branch 'develop' of https://github.com/stacks-network/stacks-core into chore/add-testing-to-runtime-errors
2 parents ce93756 + f251c33 commit 894cbfb

File tree

23 files changed

+2435
-139
lines changed

23 files changed

+2435
-139
lines changed

docs/rpc/components/schemas/pox-info.schema.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ required:
1515
- reward_cycle_length
1616
- contract_versions
1717
- epochs
18+
- current_epoch
1819
properties:
1920
contract_id:
2021
type: string
@@ -27,6 +28,10 @@ properties:
2728
type: integer
2829
minimum: 0
2930
description: The latest Bitcoin chain block height
31+
current_epoch:
32+
type: string
33+
pattern: "^Epoch[0-9]+(_[0-9]+)?$"
34+
description: The ID of the Stacks Epoch that the node is currently in.
3035
pox_activation_threshold_ustx:
3136
type: integer
3237
description:

docs/rpc/openapi.yaml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ components:
4343
name: authorization
4444
description: |
4545
Plain-text secret value that must exactly equal the node's
46-
configured password.
46+
configured password, which is set as `connection_options.auth_token`
47+
in the node's configuration file.
4748
responses:
4849
Unauthorized:
4950
description: Unauthorized. Invalid or missing authentication token.
@@ -449,6 +450,8 @@ paths:
449450
externalValue: "./components/examples/read-only-function-failure.example.json"
450451
"400":
451452
$ref: "#/components/responses/BadRequest"
453+
"401":
454+
$ref: "#/components/responses/Unauthorized"
452455
"404":
453456
$ref: "#/components/responses/NotFound"
454457
"408":
@@ -2205,7 +2208,8 @@ paths:
22052208
summary: Replay mining of a block and returns its content
22062209
tags:
22072210
- Blocks
2208-
security: []
2211+
security:
2212+
- rpcAuth: []
22092213
operationId: blockReplay
22102214
description: |
22112215
Replay the mining of a block (no data is written in the MARF) and returns its content.
@@ -2228,6 +2232,8 @@ paths:
22282232
$ref: "./components/examples/block-replay.example.json"
22292233
"400":
22302234
$ref: "#/components/responses/BadRequest"
2235+
"401":
2236+
$ref: "#/components/responses/Unauthorized"
22312237
"404":
22322238
$ref: "#/components/responses/NotFound"
22332239
"500":

stacks-signer/src/client/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ pub(crate) mod tests {
302302
network_epoch: 0,
303303
},
304304
],
305+
current_epoch: StacksEpochId::Epoch30,
305306
reward_cycle_length: thread_rng().next_u64(),
306307
rejection_votes_left_required: None,
307308
next_reward_cycle_in: thread_rng().next_u64(),

stacks-signer/src/client/stacks_client.rs

Lines changed: 15 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -274,31 +274,7 @@ impl StacksClient {
274274
pub fn get_node_epoch(&self) -> Result<StacksEpochId, ClientError> {
275275
debug!("StacksClient: Getting node epoch");
276276
let pox_info = self.get_pox_data()?;
277-
let burn_block_height = self.get_burn_block_height()?;
278-
279-
let epoch_25 = pox_info
280-
.epochs
281-
.iter()
282-
.find(|epoch| epoch.epoch_id == StacksEpochId::Epoch25)
283-
.ok_or(ClientError::UnsupportedStacksFeature(
284-
"/v2/pox must report epochs".into(),
285-
))?;
286-
287-
let epoch_30 = pox_info
288-
.epochs
289-
.iter()
290-
.find(|epoch| epoch.epoch_id == StacksEpochId::Epoch30)
291-
.ok_or(ClientError::UnsupportedStacksFeature(
292-
"/v2/pox mut report epochs".into(),
293-
))?;
294-
295-
if burn_block_height < epoch_25.start_height {
296-
Ok(StacksEpochId::Epoch24)
297-
} else if burn_block_height < epoch_30.start_height {
298-
Ok(StacksEpochId::Epoch25)
299-
} else {
300-
Ok(StacksEpochId::Epoch30)
301-
}
277+
Ok(pox_info.current_epoch)
302278
}
303279

304280
/// Submit the block proposal to the stacks node. The block will be validated and returned via the HTTP endpoint for Block events.
@@ -553,12 +529,6 @@ impl StacksClient {
553529
Ok(pox_info_data)
554530
}
555531

556-
/// Helper function to retrieve the burn tip height from the stacks node
557-
fn get_burn_block_height(&self) -> Result<u64, ClientError> {
558-
debug!("StacksClient: Getting burn block height");
559-
self.get_peer_info().map(|info| info.burn_block_height)
560-
}
561-
562532
/// Get the current reward cycle info from the stacks node
563533
pub fn get_current_reward_cycle_info(&self) -> Result<RewardCycleInfo, ClientError> {
564534
debug!("StacksClient: Getting current reward cycle info");
@@ -914,17 +884,21 @@ mod tests {
914884
#[test]
915885
fn core_info_call_for_burn_block_height_should_succeed() {
916886
let mock = MockServerClient::new();
917-
let h = spawn(move || mock.client.get_burn_block_height());
887+
let h = spawn(move || mock.client.get_peer_info());
918888
let (response, peer_info) = build_get_peer_info_response(None, None);
919889
write_response(mock.server, response.as_bytes());
920-
let burn_block_height = h.join().unwrap().expect("Failed to deserialize response");
890+
let burn_block_height = h
891+
.join()
892+
.unwrap()
893+
.expect("Failed to deserialize response")
894+
.burn_block_height;
921895
assert_eq!(burn_block_height, peer_info.burn_block_height);
922896
}
923897

924898
#[test]
925899
fn core_info_call_for_burn_block_height_should_fail() {
926900
let mock = MockServerClient::new();
927-
let h = spawn(move || mock.client.get_burn_block_height());
901+
let h = spawn(move || mock.client.get_peer_info());
928902
write_response(
929903
mock.server,
930904
b"HTTP/1.1 200 OK\n\n4e99f99bc4a05437abb8c7d0c306618f45b203196498e2ebe287f10497124958",
@@ -998,85 +972,17 @@ mod tests {
998972
#[test]
999973
fn get_node_epoch_should_succeed() {
1000974
let mock = MockServerClient::new();
1001-
// The burn block height is one BEHIND the activation height of 2.5, therefore is 2.4
1002-
let burn_block_height: u64 = 100;
1003-
let pox_response = build_get_pox_data_response(
1004-
None,
1005-
None,
1006-
Some(burn_block_height.saturating_add(1)),
1007-
None,
1008-
)
1009-
.0;
1010-
let peer_response = build_get_peer_info_response(Some(burn_block_height), None).0;
1011-
let h = spawn(move || mock.client.get_node_epoch());
1012-
write_response(mock.server, pox_response.as_bytes());
1013-
let mock = MockServerClient::from_config(mock.config);
1014-
write_response(mock.server, peer_response.as_bytes());
1015-
let epoch = h.join().unwrap().expect("Failed to deserialize response");
1016-
assert_eq!(epoch, StacksEpochId::Epoch24);
1017975

1018-
// The burn block height is the same as the activation height of 2.5, therefore is 2.5
1019-
let pox_response = build_get_pox_data_response(None, None, Some(burn_block_height), None).0;
1020-
let peer_response = build_get_peer_info_response(Some(burn_block_height), None).0;
1021-
let mock = MockServerClient::from_config(mock.config);
1022-
let h = spawn(move || mock.client.get_node_epoch());
1023-
write_response(mock.server, pox_response.as_bytes());
1024-
let mock = MockServerClient::from_config(mock.config);
1025-
write_response(mock.server, peer_response.as_bytes());
1026-
let epoch = h.join().unwrap().expect("Failed to deserialize response");
1027-
assert_eq!(epoch, StacksEpochId::Epoch25);
1028-
1029-
// The burn block height is the AFTER as the activation height of 2.5 but BEFORE the activation height of 3.0, therefore is 2.5
1030-
let pox_response = build_get_pox_data_response(
1031-
None,
1032-
None,
1033-
Some(burn_block_height.saturating_sub(1)),
1034-
Some(burn_block_height.saturating_add(1)),
1035-
)
1036-
.0;
1037-
let peer_response = build_get_peer_info_response(Some(burn_block_height), None).0;
1038-
let mock = MockServerClient::from_config(mock.config);
1039-
let h = spawn(move || mock.client.get_node_epoch());
1040-
write_response(mock.server, pox_response.as_bytes());
1041-
let mock = MockServerClient::from_config(mock.config);
1042-
write_response(mock.server, peer_response.as_bytes());
1043-
let epoch = h.join().unwrap().expect("Failed to deserialize response");
1044-
assert_eq!(epoch, StacksEpochId::Epoch25);
1045-
1046-
// The burn block height is the AFTER as the activation height of 2.5 and the SAME as the activation height of 3.0, therefore is 3.0
1047-
let pox_response = build_get_pox_data_response(
1048-
None,
1049-
None,
1050-
Some(burn_block_height.saturating_sub(1)),
1051-
Some(burn_block_height),
1052-
)
1053-
.0;
1054-
let peer_response = build_get_peer_info_response(Some(burn_block_height), None).0;
1055-
let mock = MockServerClient::from_config(mock.config);
1056-
let h = spawn(move || mock.client.get_node_epoch());
1057-
write_response(mock.server, pox_response.as_bytes());
1058-
let mock = MockServerClient::from_config(mock.config);
1059-
write_response(mock.server, peer_response.as_bytes());
1060-
let epoch = h.join().unwrap().expect("Failed to deserialize response");
1061-
assert_eq!(epoch, StacksEpochId::Epoch30);
1062-
1063-
// The burn block height is the AFTER as the activation height of 2.5 and AFTER the activation height of 3.0, therefore is 3.0
1064-
let pox_response = build_get_pox_data_response(
1065-
None,
1066-
None,
1067-
Some(burn_block_height.saturating_sub(1)),
1068-
Some(burn_block_height),
1069-
)
1070-
.0;
1071-
let peer_response =
1072-
build_get_peer_info_response(Some(burn_block_height.saturating_add(1)), None).0;
1073-
let mock = MockServerClient::from_config(mock.config);
976+
let expected_epoch = StacksEpochId::Epoch30;
977+
978+
let (pox_response, _) = build_get_pox_data_response(None, None, None, None);
979+
1074980
let h = spawn(move || mock.client.get_node_epoch());
981+
1075982
write_response(mock.server, pox_response.as_bytes());
1076-
let mock = MockServerClient::from_config(mock.config);
1077-
write_response(mock.server, peer_response.as_bytes());
983+
1078984
let epoch = h.join().unwrap().expect("Failed to deserialize response");
1079-
assert_eq!(epoch, StacksEpochId::Epoch30);
985+
assert_eq!(epoch, expected_epoch);
1080986
}
1081987

1082988
#[test]

0 commit comments

Comments
 (0)