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 ,
@@ -337,7 +325,7 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
337
325
/// Note: do not use nakamoto blocks mined heuristic if running a test with multiple miners
338
326
fn mine_nakamoto_block ( & mut self , timeout : Duration , use_nakamoto_blocks_mined : bool ) {
339
327
let mined_block_time = Instant :: now ( ) ;
340
- let mined_before = self . running_nodes . nakamoto_blocks_mined . get ( ) ;
328
+ let mined_before = self . running_nodes . counters . naka_mined_blocks . get ( ) ;
341
329
let info_before = self . get_peer_info ( ) ;
342
330
next_block_and_mine_commit (
343
331
& mut self . running_nodes . btc_regtest_controller ,
@@ -349,7 +337,7 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
349
337
350
338
wait_for ( timeout. as_secs ( ) , || {
351
339
let info_after = self . get_peer_info ( ) ;
352
- let blocks_mined = self . running_nodes . nakamoto_blocks_mined . get ( ) ;
340
+ let blocks_mined = self . running_nodes . counters . naka_mined_blocks . get ( ) ;
353
341
Ok ( info_after. stacks_tip_height > info_before. stacks_tip_height
354
342
&& ( !use_nakamoto_blocks_mined || blocks_mined > mined_before) )
355
343
} )
@@ -391,14 +379,14 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
391
379
/// to ensure that the block was mined.
392
380
/// Note: this function does _not_ mine a BTC block.
393
381
fn wait_for_nakamoto_block ( & mut self , timeout_secs : u64 , f : impl FnOnce ( ) -> ( ) ) {
394
- let blocks_before = self . running_nodes . nakamoto_blocks_mined . get ( ) ;
382
+ let blocks_before = self . running_nodes . counters . naka_mined_blocks . get ( ) ;
395
383
let info_before = self . get_peer_info ( ) ;
396
384
397
385
f ( ) ;
398
386
399
387
// Verify that the block was mined
400
388
wait_for ( timeout_secs, || {
401
- let blocks_mined = self . running_nodes . nakamoto_blocks_mined . get ( ) ;
389
+ let blocks_mined = self . running_nodes . counters . naka_mined_blocks . get ( ) ;
402
390
let info = self . get_peer_info ( ) ;
403
391
Ok ( blocks_mined > blocks_before
404
392
&& info. stacks_tip_height > info_before. stacks_tip_height )
@@ -509,7 +497,7 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
509
497
// advance to epoch 3.0 and trigger a sign round (cannot vote on blocks in pre epoch 3.0)
510
498
run_until_burnchain_height (
511
499
& mut self . running_nodes . btc_regtest_controller ,
512
- & self . running_nodes . blocks_processed ,
500
+ & self . running_nodes . counters . blocks_processed ,
513
501
epoch_30_boundary,
514
502
& self . running_nodes . conf ,
515
503
) ;
@@ -621,100 +609,6 @@ impl<S: Signer<T> + Send + 'static, T: SignerEventTrait + 'static> SignerTest<Sp
621
609
}
622
610
}
623
611
624
- pub fn wait_for_block_acceptance (
625
- & self ,
626
- timeout_secs : u64 ,
627
- signer_signature_hash : & Sha512Trunc256Sum ,
628
- expected_signers : & [ StacksPublicKey ] ,
629
- ) -> Result < ( ) , String > {
630
- // Make sure that at least 70% of signers accepted the block proposal
631
- wait_for ( timeout_secs, || {
632
- let signatures = test_observer:: get_stackerdb_chunks ( )
633
- . into_iter ( )
634
- . flat_map ( |chunk| chunk. modified_slots )
635
- . filter_map ( |chunk| {
636
- let message = SignerMessage :: consensus_deserialize ( & mut chunk. data . as_slice ( ) )
637
- . expect ( "Failed to deserialize SignerMessage" ) ;
638
- if let SignerMessage :: BlockResponse ( BlockResponse :: Accepted ( accepted) ) = message
639
- {
640
- if accepted. signer_signature_hash == * signer_signature_hash
641
- && expected_signers. iter ( ) . any ( |pk| {
642
- pk. verify (
643
- accepted. signer_signature_hash . bits ( ) ,
644
- & accepted. signature ,
645
- )
646
- . expect ( "Failed to verify signature" )
647
- } )
648
- {
649
- return Some ( accepted. signature ) ;
650
- }
651
- }
652
- None
653
- } )
654
- . collect :: < HashSet < _ > > ( ) ;
655
- Ok ( signatures. len ( ) > expected_signers. len ( ) * 7 / 10 )
656
- } )
657
- }
658
-
659
- pub fn wait_for_block_rejections (
660
- & self ,
661
- timeout_secs : u64 ,
662
- expected_signers : & [ StacksPublicKey ] ,
663
- ) -> Result < ( ) , String > {
664
- wait_for ( timeout_secs, || {
665
- let stackerdb_events = test_observer:: get_stackerdb_chunks ( ) ;
666
- let block_rejections: HashSet < _ > = stackerdb_events
667
- . into_iter ( )
668
- . flat_map ( |chunk| chunk. modified_slots )
669
- . filter_map ( |chunk| {
670
- let message = SignerMessage :: consensus_deserialize ( & mut chunk. data . as_slice ( ) )
671
- . expect ( "Failed to deserialize SignerMessage" ) ;
672
- match message {
673
- SignerMessage :: BlockResponse ( BlockResponse :: Rejected ( rejection) ) => {
674
- let rejected_pubkey = rejection
675
- . recover_public_key ( )
676
- . expect ( "Failed to recover public key from rejection" ) ;
677
- if expected_signers. contains ( & rejected_pubkey) {
678
- Some ( rejected_pubkey)
679
- } else {
680
- None
681
- }
682
- }
683
- _ => None ,
684
- }
685
- } )
686
- . collect :: < HashSet < _ > > ( ) ;
687
- Ok ( block_rejections. len ( ) == expected_signers. len ( ) )
688
- } )
689
- }
690
-
691
- /// Get all block rejections for a given block
692
- pub fn get_block_rejections (
693
- & self ,
694
- signer_signature_hash : & Sha512Trunc256Sum ,
695
- ) -> Vec < BlockRejection > {
696
- let stackerdb_events = test_observer:: get_stackerdb_chunks ( ) ;
697
- let block_rejections = stackerdb_events
698
- . into_iter ( )
699
- . flat_map ( |chunk| chunk. modified_slots )
700
- . filter_map ( |chunk| {
701
- let message = SignerMessage :: consensus_deserialize ( & mut chunk. data . as_slice ( ) )
702
- . expect ( "Failed to deserialize SignerMessage" ) ;
703
- match message {
704
- SignerMessage :: BlockResponse ( BlockResponse :: Rejected ( rejection) ) => {
705
- if rejection. signer_signature_hash == * signer_signature_hash {
706
- Some ( rejection)
707
- } else {
708
- None
709
- }
710
- }
711
- _ => None ,
712
- }
713
- } )
714
- . collect :: < Vec < _ > > ( ) ;
715
- block_rejections
716
- }
717
-
718
612
/// Get the latest block response from the given slot
719
613
pub fn get_latest_block_response ( & self , slot_id : u32 ) -> BlockResponse {
720
614
let mut stackerdb = StackerDB :: new_normal (
@@ -919,21 +813,8 @@ fn setup_stx_btc_node<G: FnMut(&mut NeonConfig)>(
919
813
920
814
let mut run_loop = boot_nakamoto:: BootRunLoop :: new ( naka_conf. clone ( ) ) . unwrap ( ) ;
921
815
let run_loop_stopper = run_loop. get_termination_switch ( ) ;
922
- let Counters {
923
- blocks_processed,
924
- sortitions_processed,
925
- naka_submitted_vrfs : vrfs_submitted,
926
- naka_submitted_commits : commits_submitted,
927
- naka_submitted_commit_last_burn_height : last_commit_burn_height,
928
- naka_proposed_blocks : naka_blocks_proposed,
929
- naka_mined_blocks : naka_blocks_mined,
930
- naka_rejected_blocks : naka_blocks_rejected,
931
- naka_miner_directives,
932
- naka_skip_commit_op : nakamoto_test_skip_commit_op,
933
- naka_signer_pushed_blocks,
934
- ..
935
- } = run_loop. counters ( ) ;
936
816
let counters = run_loop. counters ( ) ;
817
+ let blocks_processed = counters. blocks_processed . clone ( ) ;
937
818
938
819
let coord_channel = run_loop. coordinator_channels ( ) ;
939
820
let run_loop_thread = thread:: spawn ( move || run_loop. start ( None , 0 ) ) ;
@@ -944,32 +825,21 @@ fn setup_stx_btc_node<G: FnMut(&mut NeonConfig)>(
944
825
945
826
// First block wakes up the run loop.
946
827
info ! ( "Mine first block..." ) ;
947
- next_block_and_wait ( & mut btc_regtest_controller, & blocks_processed) ;
828
+ next_block_and_wait ( & mut btc_regtest_controller, & counters . blocks_processed ) ;
948
829
949
830
// Second block will hold our VRF registration.
950
831
info ! ( "Mine second block..." ) ;
951
- next_block_and_wait ( & mut btc_regtest_controller, & blocks_processed) ;
832
+ next_block_and_wait ( & mut btc_regtest_controller, & counters . blocks_processed ) ;
952
833
953
834
// Third block will be the first mined Stacks block.
954
835
info ! ( "Mine third block..." ) ;
955
- next_block_and_wait ( & mut btc_regtest_controller, & blocks_processed) ;
836
+ next_block_and_wait ( & mut btc_regtest_controller, & counters . blocks_processed ) ;
956
837
957
838
RunningNodes {
958
839
btcd_controller,
959
840
btc_regtest_controller,
960
841
run_loop_thread,
961
842
run_loop_stopper,
962
- vrfs_submitted,
963
- commits_submitted,
964
- last_commit_burn_height,
965
- blocks_processed,
966
- sortitions_processed,
967
- nakamoto_blocks_proposed : naka_blocks_proposed,
968
- nakamoto_blocks_mined : naka_blocks_mined,
969
- nakamoto_blocks_rejected : naka_blocks_rejected,
970
- nakamoto_blocks_signer_pushed : naka_signer_pushed_blocks,
971
- nakamoto_test_skip_commit_op,
972
- nakamoto_miner_directives : naka_miner_directives. 0 ,
973
843
coord_channel,
974
844
counters,
975
845
conf : naka_conf,
0 commit comments