@@ -19,7 +19,7 @@ use std::net::SocketAddr;
19
19
use blockstack_lib:: burnchains:: Txid ;
20
20
use blockstack_lib:: chainstate:: nakamoto:: NakamotoBlock ;
21
21
use blockstack_lib:: chainstate:: stacks:: boot:: {
22
- NakamotoSignerEntry , SIGNERS_VOTING_FUNCTION_NAME , SIGNERS_VOTING_NAME ,
22
+ NakamotoSignerEntry , SIGNERS_NAME , SIGNERS_VOTING_FUNCTION_NAME , SIGNERS_VOTING_NAME ,
23
23
} ;
24
24
use blockstack_lib:: chainstate:: stacks:: db:: StacksBlockHeaderTypes ;
25
25
use blockstack_lib:: chainstate:: stacks:: {
@@ -162,6 +162,20 @@ impl StacksClient {
162
162
Ok ( sortition_info)
163
163
}
164
164
165
+ /// Get the last set reward cycle stored within the stackerdb contract
166
+ pub fn get_last_set_cycle ( & self ) -> Result < u128 , ClientError > {
167
+ let signer_stackerdb_contract_id = boot_code_id ( SIGNERS_NAME , self . mainnet ) ;
168
+ let function_name_str = "get-last-set-cycle" ;
169
+ let function_name = ClarityName :: from ( function_name_str) ;
170
+ let value = self . read_only_contract_call (
171
+ & signer_stackerdb_contract_id. issuer . clone ( ) . into ( ) ,
172
+ & signer_stackerdb_contract_id. name ,
173
+ & function_name,
174
+ & [ ] ,
175
+ ) ?;
176
+ Ok ( value. expect_result_ok ( ) ?. expect_u128 ( ) ?)
177
+ }
178
+
165
179
/// Retrieve the signer slots stored within the stackerdb contract
166
180
pub fn get_stackerdb_signer_slots (
167
181
& self ,
@@ -450,7 +464,10 @@ impl StacksClient {
450
464
"last_sortition" => %last_sortition,
451
465
) ;
452
466
let path = self . tenure_forking_info_path ( chosen_parent, last_sortition) ;
453
- let timer = crate :: monitoring:: new_rpc_call_timer ( & path, & self . http_origin ) ;
467
+ let timer = crate :: monitoring:: new_rpc_call_timer (
468
+ "/v3/tenures/fork_info/:start/:stop" ,
469
+ & self . http_origin ,
470
+ ) ;
454
471
let send_request = || {
455
472
self . stacks_node_client
456
473
. get ( & path)
@@ -491,7 +508,8 @@ impl StacksClient {
491
508
pub fn get_sortition ( & self , ch : & ConsensusHash ) -> Result < SortitionInfo , ClientError > {
492
509
debug ! ( "stacks_node_client: Getting sortition with consensus hash {ch}..." ) ;
493
510
let path = format ! ( "{}/consensus/{}" , self . sortition_info_path( ) , ch. to_hex( ) ) ;
494
- let timer = crate :: monitoring:: new_rpc_call_timer ( & path, & self . http_origin ) ;
511
+ let timer_label = format ! ( "{}/consensus/:consensus_hash" , self . sortition_info_path( ) ) ;
512
+ let timer = crate :: monitoring:: new_rpc_call_timer ( & timer_label, & self . http_origin ) ;
495
513
let send_request = || {
496
514
self . stacks_node_client . get ( & path) . send ( ) . map_err ( |e| {
497
515
warn ! ( "Signer failed to request sortition" ; "consensus_hash" => %ch, "err" => ?e) ;
@@ -561,7 +579,7 @@ impl StacksClient {
561
579
) -> Result < Option < Vec < NakamotoSignerEntry > > , ClientError > {
562
580
debug ! ( "stacks_node_client: Getting reward set signers for reward cycle {reward_cycle}..." ) ;
563
581
let timer = crate :: monitoring:: new_rpc_call_timer (
564
- & self . reward_set_path ( reward_cycle) ,
582
+ & format ! ( "{}/v3/stacker_set/: reward_cycle" , self . http_origin ) ,
565
583
& self . http_origin ,
566
584
) ;
567
585
let send_request = || {
@@ -581,7 +599,7 @@ impl StacksClient {
581
599
backoff:: Error :: permanent ( e. into ( ) )
582
600
} ) ?;
583
601
if error_data. err_type == GetStackersErrors :: NOT_AVAILABLE_ERR_TYPE {
584
- Err ( backoff:: Error :: transient ( ClientError :: NoSortitionOnChain ) )
602
+ Err ( backoff:: Error :: permanent ( ClientError :: NoSortitionOnChain ) )
585
603
} else {
586
604
warn ! ( "Got error response ({status}): {}" , error_data. err_msg) ;
587
605
Err ( backoff:: Error :: permanent ( ClientError :: RequestFailure (
@@ -644,8 +662,8 @@ impl StacksClient {
644
662
address : & StacksAddress ,
645
663
) -> Result < AccountEntryResponse , ClientError > {
646
664
debug ! ( "stacks_node_client: Getting account info..." ) ;
647
- let timer =
648
- crate :: monitoring:: new_rpc_call_timer ( & self . accounts_path ( address ) , & self . http_origin ) ;
665
+ let timer_label = format ! ( "{}/v2/accounts/:principal" , self . http_origin ) ;
666
+ let timer = crate :: monitoring:: new_rpc_call_timer ( & timer_label , & self . http_origin ) ;
649
667
let send_request = || {
650
668
self . stacks_node_client
651
669
. get ( self . accounts_path ( address) )
@@ -797,7 +815,11 @@ impl StacksClient {
797
815
let body =
798
816
json ! ( { "sender" : self . stacks_address. to_string( ) , "arguments" : args} ) . to_string ( ) ;
799
817
let path = self . read_only_path ( contract_addr, contract_name, function_name) ;
800
- let timer = crate :: monitoring:: new_rpc_call_timer ( & path, & self . http_origin ) ;
818
+ let timer_label = format ! (
819
+ "{}/v2/contracts/call-read/:principal/{contract_name}/{function_name}" ,
820
+ self . http_origin
821
+ ) ;
822
+ let timer = crate :: monitoring:: new_rpc_call_timer ( & timer_label, & self . http_origin ) ;
801
823
let response = self
802
824
. stacks_node_client
803
825
. post ( path)
@@ -962,11 +984,11 @@ mod tests {
962
984
use super :: * ;
963
985
use crate :: client:: tests:: {
964
986
build_account_nonce_response, build_get_approved_aggregate_key_response,
965
- build_get_last_round_response, build_get_medium_estimated_fee_ustx_response ,
966
- build_get_peer_info_response , build_get_pox_data_response , build_get_round_info_response ,
967
- build_get_tenure_tip_response , build_get_vote_for_aggregate_key_response ,
968
- build_get_weight_threshold_response , build_read_only_response , write_response ,
969
- MockServerClient ,
987
+ build_get_last_round_response, build_get_last_set_cycle_response ,
988
+ build_get_medium_estimated_fee_ustx_response , build_get_peer_info_response ,
989
+ build_get_pox_data_response , build_get_round_info_response , build_get_tenure_tip_response ,
990
+ build_get_vote_for_aggregate_key_response , build_get_weight_threshold_response ,
991
+ build_read_only_response , write_response , MockServerClient ,
970
992
} ;
971
993
972
994
#[ test]
@@ -1623,4 +1645,14 @@ mod tests {
1623
1645
write_response ( mock. server , response. as_bytes ( ) ) ;
1624
1646
assert_eq ! ( h. join( ) . unwrap( ) . unwrap( ) , header) ;
1625
1647
}
1648
+
1649
+ #[ test]
1650
+ fn get_last_set_cycle_should_succeed ( ) {
1651
+ let mock = MockServerClient :: new ( ) ;
1652
+ let reward_cycle = thread_rng ( ) . next_u64 ( ) ;
1653
+ let response = build_get_last_set_cycle_response ( reward_cycle) ;
1654
+ let h = spawn ( move || mock. client . get_last_set_cycle ( ) ) ;
1655
+ write_response ( mock. server , response. as_bytes ( ) ) ;
1656
+ assert_eq ! ( h. join( ) . unwrap( ) . unwrap( ) , reward_cycle as u128 ) ;
1657
+ }
1626
1658
}
0 commit comments