15
15
mod v0;
16
16
17
17
use std:: collections:: HashSet ;
18
- use std:: sync:: atomic:: { AtomicBool , AtomicU64 , Ordering } ;
18
+ use std:: sync:: atomic:: { AtomicBool , Ordering } ;
19
19
use std:: sync:: { Arc , Mutex } ;
20
20
use std:: thread;
21
21
use std:: time:: { Duration , Instant } ;
22
22
23
23
use clarity:: boot_util:: boot_code_id;
24
24
use clarity:: vm:: types:: PrincipalData ;
25
25
use libsigner:: v0:: messages:: {
26
- BlockAccepted , BlockRejection , BlockResponse , MessageSlotID , PeerInfo , SignerMessage ,
26
+ BlockAccepted , BlockResponse , MessageSlotID , PeerInfo , SignerMessage ,
27
27
} ;
28
28
use libsigner:: { BlockProposal , SignerEntries , SignerEventTrait } ;
29
29
use stacks:: chainstate:: coordinator:: comm:: CoordinatorChannels ;
@@ -36,22 +36,21 @@ use stacks::net::api::postblock_proposal::{
36
36
BlockValidateOk , BlockValidateReject , BlockValidateResponse ,
37
37
} ;
38
38
use stacks:: types:: chainstate:: { StacksAddress , StacksPublicKey } ;
39
- use stacks:: types:: { PrivateKey , PublicKey } ;
39
+ use stacks:: types:: PrivateKey ;
40
40
use stacks:: util:: get_epoch_time_secs;
41
41
use stacks:: util:: hash:: MerkleHashFunc ;
42
42
use stacks:: util:: secp256k1:: { MessageSignature , Secp256k1PublicKey } ;
43
43
use stacks_common:: codec:: StacksMessageCodec ;
44
44
use stacks_common:: consts:: SIGNER_SLOTS_PER_USER ;
45
45
use stacks_common:: types:: StacksEpochId ;
46
46
use stacks_common:: util:: hash:: Sha512Trunc256Sum ;
47
- use stacks_common:: util:: tests:: TestFlag ;
48
47
use stacks_signer:: client:: { ClientError , SignerSlotID , StackerDB , StacksClient } ;
49
48
use stacks_signer:: config:: { build_signer_config_tomls, GlobalConfig as SignerConfig , Network } ;
50
49
use stacks_signer:: runloop:: { SignerResult , State , StateInfo } ;
51
50
use stacks_signer:: { Signer , SpawnedSigner } ;
52
51
53
52
use super :: nakamoto_integrations:: { check_nakamoto_empty_block_heuristics, wait_for} ;
54
- use crate :: neon:: { Counters , RunLoopCounter } ;
53
+ use crate :: neon:: Counters ;
55
54
use crate :: run_loop:: boot_nakamoto;
56
55
use crate :: tests:: bitcoin_regtest:: BitcoinCoreController ;
57
56
use crate :: tests:: nakamoto_integrations:: {
@@ -72,17 +71,6 @@ pub struct RunningNodes {
72
71
pub btcd_controller : BitcoinCoreController ,
73
72
pub run_loop_thread : thread:: JoinHandle < ( ) > ,
74
73
pub run_loop_stopper : Arc < AtomicBool > ,
75
- pub vrfs_submitted : RunLoopCounter ,
76
- pub commits_submitted : RunLoopCounter ,
77
- pub last_commit_burn_height : RunLoopCounter ,
78
- pub blocks_processed : RunLoopCounter ,
79
- pub sortitions_processed : RunLoopCounter ,
80
- pub nakamoto_blocks_proposed : RunLoopCounter ,
81
- pub nakamoto_blocks_mined : RunLoopCounter ,
82
- pub nakamoto_blocks_rejected : RunLoopCounter ,
83
- pub nakamoto_blocks_signer_pushed : RunLoopCounter ,
84
- pub nakamoto_miner_directives : Arc < AtomicU64 > ,
85
- pub nakamoto_test_skip_commit_op : TestFlag < bool > ,
86
74
pub counters : Counters ,
87
75
pub coord_channel : Arc < Mutex < CoordinatorChannels > > ,
88
76
pub conf : NeonConfig ,
@@ -334,7 +322,7 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
334
322
/// Note: do not use nakamoto blocks mined heuristic if running a test with multiple miners
335
323
fn mine_nakamoto_block ( & mut self , timeout : Duration , use_nakamoto_blocks_mined : bool ) {
336
324
let mined_block_time = Instant :: now ( ) ;
337
- let mined_before = self . running_nodes . nakamoto_blocks_mined . get ( ) ;
325
+ let mined_before = self . running_nodes . counters . naka_mined_blocks . get ( ) ;
338
326
let info_before = self . get_peer_info ( ) ;
339
327
next_block_and_mine_commit (
340
328
& mut self . running_nodes . btc_regtest_controller ,
@@ -346,7 +334,7 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
346
334
347
335
wait_for ( timeout. as_secs ( ) , || {
348
336
let info_after = self . get_peer_info ( ) ;
349
- let blocks_mined = self . running_nodes . nakamoto_blocks_mined . get ( ) ;
337
+ let blocks_mined = self . running_nodes . counters . naka_mined_blocks . get ( ) ;
350
338
Ok ( info_after. stacks_tip_height > info_before. stacks_tip_height
351
339
&& ( !use_nakamoto_blocks_mined || blocks_mined > mined_before) )
352
340
} )
@@ -388,14 +376,14 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
388
376
/// to ensure that the block was mined.
389
377
/// Note: this function does _not_ mine a BTC block.
390
378
fn wait_for_nakamoto_block ( & mut self , timeout_secs : u64 , f : impl FnOnce ( ) -> ( ) ) {
391
- let blocks_before = self . running_nodes . nakamoto_blocks_mined . get ( ) ;
379
+ let blocks_before = self . running_nodes . counters . naka_mined_blocks . get ( ) ;
392
380
let info_before = self . get_peer_info ( ) ;
393
381
394
382
f ( ) ;
395
383
396
384
// Verify that the block was mined
397
385
wait_for ( timeout_secs, || {
398
- let blocks_mined = self . running_nodes . nakamoto_blocks_mined . get ( ) ;
386
+ let blocks_mined = self . running_nodes . counters . naka_mined_blocks . get ( ) ;
399
387
let info = self . get_peer_info ( ) ;
400
388
Ok ( blocks_mined > blocks_before
401
389
&& info. stacks_tip_height > info_before. stacks_tip_height )
@@ -506,7 +494,7 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
506
494
// advance to epoch 3.0 and trigger a sign round (cannot vote on blocks in pre epoch 3.0)
507
495
run_until_burnchain_height (
508
496
& mut self . running_nodes . btc_regtest_controller ,
509
- & self . running_nodes . blocks_processed ,
497
+ & self . running_nodes . counters . blocks_processed ,
510
498
epoch_30_boundary,
511
499
& self . running_nodes . conf ,
512
500
) ;
@@ -618,100 +606,6 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
618
606
}
619
607
}
620
608
621
- pub fn wait_for_block_acceptance (
622
- & self ,
623
- timeout_secs : u64 ,
624
- signer_signature_hash : & Sha512Trunc256Sum ,
625
- expected_signers : & [ StacksPublicKey ] ,
626
- ) -> Result < ( ) , String > {
627
- // Make sure that at least 70% of signers accepted the block proposal
628
- wait_for ( timeout_secs, || {
629
- let signatures = test_observer:: get_stackerdb_chunks ( )
630
- . into_iter ( )
631
- . flat_map ( |chunk| chunk. modified_slots )
632
- . filter_map ( |chunk| {
633
- let message = SignerMessage :: consensus_deserialize ( & mut chunk. data . as_slice ( ) )
634
- . expect ( "Failed to deserialize SignerMessage" ) ;
635
- if let SignerMessage :: BlockResponse ( BlockResponse :: Accepted ( accepted) ) = message
636
- {
637
- if accepted. signer_signature_hash == * signer_signature_hash
638
- && expected_signers. iter ( ) . any ( |pk| {
639
- pk. verify (
640
- accepted. signer_signature_hash . bits ( ) ,
641
- & accepted. signature ,
642
- )
643
- . expect ( "Failed to verify signature" )
644
- } )
645
- {
646
- return Some ( accepted. signature ) ;
647
- }
648
- }
649
- None
650
- } )
651
- . collect :: < HashSet < _ > > ( ) ;
652
- Ok ( signatures. len ( ) > expected_signers. len ( ) * 7 / 10 )
653
- } )
654
- }
655
-
656
- pub fn wait_for_block_rejections (
657
- & self ,
658
- timeout_secs : u64 ,
659
- expected_signers : & [ StacksPublicKey ] ,
660
- ) -> Result < ( ) , String > {
661
- wait_for ( timeout_secs, || {
662
- let stackerdb_events = test_observer:: get_stackerdb_chunks ( ) ;
663
- let block_rejections: HashSet < _ > = stackerdb_events
664
- . into_iter ( )
665
- . flat_map ( |chunk| chunk. modified_slots )
666
- . filter_map ( |chunk| {
667
- let message = SignerMessage :: consensus_deserialize ( & mut chunk. data . as_slice ( ) )
668
- . expect ( "Failed to deserialize SignerMessage" ) ;
669
- match message {
670
- SignerMessage :: BlockResponse ( BlockResponse :: Rejected ( rejection) ) => {
671
- let rejected_pubkey = rejection
672
- . recover_public_key ( )
673
- . expect ( "Failed to recover public key from rejection" ) ;
674
- if expected_signers. contains ( & rejected_pubkey) {
675
- Some ( rejected_pubkey)
676
- } else {
677
- None
678
- }
679
- }
680
- _ => None ,
681
- }
682
- } )
683
- . collect :: < HashSet < _ > > ( ) ;
684
- Ok ( block_rejections. len ( ) == expected_signers. len ( ) )
685
- } )
686
- }
687
-
688
- /// Get all block rejections for a given block
689
- pub fn get_block_rejections (
690
- & self ,
691
- signer_signature_hash : & Sha512Trunc256Sum ,
692
- ) -> Vec < BlockRejection > {
693
- let stackerdb_events = test_observer:: get_stackerdb_chunks ( ) ;
694
- let block_rejections = stackerdb_events
695
- . into_iter ( )
696
- . flat_map ( |chunk| chunk. modified_slots )
697
- . filter_map ( |chunk| {
698
- let message = SignerMessage :: consensus_deserialize ( & mut chunk. data . as_slice ( ) )
699
- . expect ( "Failed to deserialize SignerMessage" ) ;
700
- match message {
701
- SignerMessage :: BlockResponse ( BlockResponse :: Rejected ( rejection) ) => {
702
- if rejection. signer_signature_hash == * signer_signature_hash {
703
- Some ( rejection)
704
- } else {
705
- None
706
- }
707
- }
708
- _ => None ,
709
- }
710
- } )
711
- . collect :: < Vec < _ > > ( ) ;
712
- block_rejections
713
- }
714
-
715
609
/// Get the latest block response from the given slot
716
610
pub fn get_latest_block_response ( & self , slot_id : u32 ) -> BlockResponse {
717
611
let mut stackerdb = StackerDB :: new_normal (
@@ -916,21 +810,8 @@ fn setup_stx_btc_node<G: FnMut(&mut NeonConfig)>(
916
810
917
811
let mut run_loop = boot_nakamoto:: BootRunLoop :: new ( naka_conf. clone ( ) ) . unwrap ( ) ;
918
812
let run_loop_stopper = run_loop. get_termination_switch ( ) ;
919
- let Counters {
920
- blocks_processed,
921
- sortitions_processed,
922
- naka_submitted_vrfs : vrfs_submitted,
923
- naka_submitted_commits : commits_submitted,
924
- naka_submitted_commit_last_burn_height : last_commit_burn_height,
925
- naka_proposed_blocks : naka_blocks_proposed,
926
- naka_mined_blocks : naka_blocks_mined,
927
- naka_rejected_blocks : naka_blocks_rejected,
928
- naka_miner_directives,
929
- naka_skip_commit_op : nakamoto_test_skip_commit_op,
930
- naka_signer_pushed_blocks,
931
- ..
932
- } = run_loop. counters ( ) ;
933
813
let counters = run_loop. counters ( ) ;
814
+ let blocks_processed = counters. blocks_processed . clone ( ) ;
934
815
935
816
let coord_channel = run_loop. coordinator_channels ( ) ;
936
817
let run_loop_thread = thread:: spawn ( move || run_loop. start ( None , 0 ) ) ;
@@ -941,32 +822,21 @@ fn setup_stx_btc_node<G: FnMut(&mut NeonConfig)>(
941
822
942
823
// First block wakes up the run loop.
943
824
info ! ( "Mine first block..." ) ;
944
- next_block_and_wait ( & mut btc_regtest_controller, & blocks_processed) ;
825
+ next_block_and_wait ( & mut btc_regtest_controller, & counters . blocks_processed ) ;
945
826
946
827
// Second block will hold our VRF registration.
947
828
info ! ( "Mine second block..." ) ;
948
- next_block_and_wait ( & mut btc_regtest_controller, & blocks_processed) ;
829
+ next_block_and_wait ( & mut btc_regtest_controller, & counters . blocks_processed ) ;
949
830
950
831
// Third block will be the first mined Stacks block.
951
832
info ! ( "Mine third block..." ) ;
952
- next_block_and_wait ( & mut btc_regtest_controller, & blocks_processed) ;
833
+ next_block_and_wait ( & mut btc_regtest_controller, & counters . blocks_processed ) ;
953
834
954
835
RunningNodes {
955
836
btcd_controller,
956
837
btc_regtest_controller,
957
838
run_loop_thread,
958
839
run_loop_stopper,
959
- vrfs_submitted,
960
- commits_submitted,
961
- last_commit_burn_height,
962
- blocks_processed,
963
- sortitions_processed,
964
- nakamoto_blocks_proposed : naka_blocks_proposed,
965
- nakamoto_blocks_mined : naka_blocks_mined,
966
- nakamoto_blocks_rejected : naka_blocks_rejected,
967
- nakamoto_blocks_signer_pushed : naka_signer_pushed_blocks,
968
- nakamoto_test_skip_commit_op,
969
- nakamoto_miner_directives : naka_miner_directives. 0 ,
970
840
coord_channel,
971
841
counters,
972
842
conf : naka_conf,
0 commit comments