@@ -49,6 +49,7 @@ use crate::net::relay::Relayer;
49
49
use crate :: net:: rpc:: ConversationHttp ;
50
50
use crate :: net:: test:: { RPCHandlerArgsType , TestEventObserver , TestPeer , TestPeerConfig } ;
51
51
use crate :: net:: tests:: inv:: nakamoto:: make_nakamoto_peers_from_invs_ext;
52
+ use crate :: net:: tests:: NakamotoBootPlan ;
52
53
use crate :: net:: {
53
54
Attachment , AttachmentInstance , MemPoolEventDispatcher , RPCHandlerArgs , StackerDBConfig ,
54
55
StacksNodeState , UrlString ,
@@ -955,6 +956,109 @@ impl<'a> TestRPC<'a> {
955
956
}
956
957
}
957
958
959
+ /// Set up the peers as Nakamoto nodes
960
+ pub fn setup_nakamoto_with_boot_plan < F > (
961
+ test_name : & str ,
962
+ observer : & ' a TestEventObserver ,
963
+ boot_plan_fn : F ,
964
+ ) -> TestRPC < ' a >
965
+ where
966
+ F : FnOnce ( NakamotoBootPlan ) -> NakamotoBootPlan ,
967
+ {
968
+ let bitvecs = vec ! [ vec![
969
+ true , true , true , true , true , true , true , true , true , true ,
970
+ ] ] ;
971
+
972
+ let ( mut peer, mut other_peers) =
973
+ make_nakamoto_peers_from_invs_ext ( function_name ! ( ) , observer, bitvecs, |boot_plan| {
974
+ boot_plan_fn (
975
+ boot_plan
976
+ . with_pox_constants ( 10 , 3 )
977
+ . with_extra_peers ( 1 )
978
+ . with_initial_balances ( vec ! [ ] )
979
+ . with_malleablized_blocks ( false ) ,
980
+ )
981
+ } ) ;
982
+ let mut other_peer = other_peers. pop ( ) . unwrap ( ) ;
983
+
984
+ let peer_1_indexer = BitcoinIndexer :: new_unit_test ( & peer. config . burnchain . working_dir ) ;
985
+ let peer_2_indexer =
986
+ BitcoinIndexer :: new_unit_test ( & other_peer. config . burnchain . working_dir ) ;
987
+
988
+ let convo_1 = ConversationHttp :: new (
989
+ format ! ( "127.0.0.1:{}" , peer. config. http_port)
990
+ . parse :: < SocketAddr > ( )
991
+ . unwrap ( ) ,
992
+ Some ( UrlString :: try_from ( "http://peer1.com" . to_string ( ) ) . unwrap ( ) ) ,
993
+ peer. to_peer_host ( ) ,
994
+ & peer. config . connection_opts ,
995
+ 0 ,
996
+ 32 ,
997
+ ) ;
998
+
999
+ let convo_2 = ConversationHttp :: new (
1000
+ format ! ( "127.0.0.1:{}" , other_peer. config. http_port)
1001
+ . parse :: < SocketAddr > ( )
1002
+ . unwrap ( ) ,
1003
+ Some ( UrlString :: try_from ( "http://peer2.com" . to_string ( ) ) . unwrap ( ) ) ,
1004
+ other_peer. to_peer_host ( ) ,
1005
+ & other_peer. config . connection_opts ,
1006
+ 1 ,
1007
+ 32 ,
1008
+ ) ;
1009
+
1010
+ let tip = SortitionDB :: get_canonical_burn_chain_tip ( peer. sortdb ( ) . conn ( ) ) . unwrap ( ) ;
1011
+ let nakamoto_tip = {
1012
+ let sortdb = peer. sortdb . take ( ) . unwrap ( ) ;
1013
+ let tip =
1014
+ NakamotoChainState :: get_canonical_block_header ( peer. chainstate ( ) . db ( ) , & sortdb)
1015
+ . unwrap ( )
1016
+ . unwrap ( ) ;
1017
+ peer. sortdb = Some ( sortdb) ;
1018
+ tip
1019
+ } ;
1020
+
1021
+ // sanity check
1022
+ let other_tip =
1023
+ SortitionDB :: get_canonical_burn_chain_tip ( other_peer. sortdb ( ) . conn ( ) ) . unwrap ( ) ;
1024
+ let other_nakamoto_tip = {
1025
+ let sortdb = other_peer. sortdb . take ( ) . unwrap ( ) ;
1026
+ let tip = NakamotoChainState :: get_canonical_block_header (
1027
+ other_peer. chainstate ( ) . db ( ) ,
1028
+ & sortdb,
1029
+ )
1030
+ . unwrap ( )
1031
+ . unwrap ( ) ;
1032
+ other_peer. sortdb = Some ( sortdb) ;
1033
+ tip
1034
+ } ;
1035
+
1036
+ assert_eq ! ( tip, other_tip) ;
1037
+ assert_eq ! ( nakamoto_tip, other_nakamoto_tip) ;
1038
+
1039
+ TestRPC {
1040
+ privk1 : peer. config . private_key . clone ( ) ,
1041
+ privk2 : other_peer. config . private_key . clone ( ) ,
1042
+ peer_1 : peer,
1043
+ peer_2 : other_peer,
1044
+ peer_1_indexer,
1045
+ peer_2_indexer,
1046
+ convo_1,
1047
+ convo_2,
1048
+ canonical_tip : nakamoto_tip. index_block_hash ( ) ,
1049
+ consensus_hash : nakamoto_tip. consensus_hash . clone ( ) ,
1050
+ tip_hash : nakamoto_tip. anchored_header . block_hash ( ) ,
1051
+ tip_height : nakamoto_tip. stacks_block_height ,
1052
+ microblock_tip_hash : BlockHeaderHash ( [ 0x00 ; 32 ] ) ,
1053
+ mempool_txids : vec ! [ ] ,
1054
+ microblock_txids : vec ! [ ] ,
1055
+ next_block : None ,
1056
+ next_microblock : None ,
1057
+ sendable_txs : vec ! [ ] ,
1058
+ unconfirmed_state : false ,
1059
+ }
1060
+ }
1061
+
958
1062
pub fn run ( self , requests : Vec < StacksHttpRequest > ) -> Vec < StacksHttpResponse > {
959
1063
self . run_with_observer ( requests, None )
960
1064
}
0 commit comments