@@ -77,7 +77,8 @@ manager::manager()
7777 cmt_( commitment::e_confirmed ),
7878 max_batch_( PC_MAX_BATCH ),
7979 sreq_{ { commitment::e_processed } },
80- secondary_{ nullptr }
80+ secondary_{ nullptr },
81+ is_secondary_ ( false )
8182{
8283 tconn_.set_sub ( this );
8384 breq_->set_sub ( this );
@@ -120,7 +121,7 @@ void manager::del_map_sub()
120121{
121122 if ( --num_sub_ <= 0 && !has_status ( PC_PYTH_HAS_MAPPING ) ) {
122123 set_status ( PC_PYTH_HAS_MAPPING );
123- PC_LOG_INF ( " completed_mapping_init" ).add ( " secondary" , is_secondary () ).end ();
124+ PC_LOG_INF ( " completed_mapping_init" ).add ( " secondary" , get_is_secondary () ).end ();
124125 // notify user that initialization is complete
125126 if ( sub_ ) {
126127 sub_->on_init ( this );
@@ -270,7 +271,7 @@ uint64_t manager::get_slot() const
270271
271272void manager::teardown ()
272273{
273- PC_LOG_INF ( " pythd_teardown" ).add ( " secondary" , is_secondary () ).end ();
274+ PC_LOG_INF ( " pythd_teardown" ).add ( " secondary" , get_is_secondary () ).end ();
274275
275276 // shutdown listener
276277 lsvr_.close ();
@@ -308,15 +309,15 @@ bool manager::init()
308309 // log import key names
309310 key_pair *kp = get_publish_key_pair ();
310311 if ( kp ) {
311- PC_LOG_INF ( " publish_key" ).add ( " key_name" , *kp ).add ( " secondary" , is_secondary () ).end ();
312+ PC_LOG_INF ( " publish_key" ).add ( " key_name" , *kp ).add ( " secondary" , get_is_secondary () ).end ();
312313 }
313314 pub_key *mpub = get_mapping_pub_key ();
314315 if ( mpub ) {
315- PC_LOG_INF ( " mapping_key" ).add ( " key_name" , *mpub ).add ( " secondary" , is_secondary () ).end ();
316+ PC_LOG_INF ( " mapping_key" ).add ( " key_name" , *mpub ).add ( " secondary" , get_is_secondary () ).end ();
316317 }
317318 pub_key *gpub = get_program_pub_key ();
318319 if ( gpub ) {
319- PC_LOG_INF ( " program_key" ).add ( " key_name" , *gpub ).add ( " secondary" , is_secondary () ).end ();
320+ PC_LOG_INF ( " program_key" ).add ( " key_name" , *gpub ).add ( " secondary" , get_is_secondary () ).end ();
320321 }
321322
322323 // initialize capture
@@ -374,12 +375,12 @@ bool manager::init()
374375 return set_err_msg ( lsvr_.get_err_msg () );
375376 }
376377 PC_LOG_INF (" listening" ).add (" port" ,lsvr_.get_port ())
377- .add ( " secondary" , is_secondary () )
378+ .add ( " secondary" , get_is_secondary () )
378379 .add ( " content_dir" , get_content_dir () )
379380 .end ();
380381 }
381382 PC_LOG_INF ( " initialized" )
382- .add ( " secondary" , is_secondary () )
383+ .add ( " secondary" , get_is_secondary () )
383384 .add ( " version" , PC_VERSION )
384385 .add ( " rpc_host" , get_rpc_host () )
385386 .add ( " tx_host" , get_tx_host () )
@@ -408,6 +409,7 @@ void manager::add_secondary( const std::string& rpc_host, const std::string& key
408409 mgr->set_do_tx ( do_tx_ );
409410 mgr->set_do_ws ( do_ws_ );
410411 mgr->set_commitment ( cmt_ );
412+ mgr->set_is_secondary ( true );
411413
412414 secondary_ = mgr;
413415
@@ -417,8 +419,12 @@ bool manager::has_secondary() const {
417419 return secondary_ != nullptr ;
418420}
419421
420- bool manager::is_secondary () const {
421- return !has_secondary ();
422+ void manager::set_is_secondary (bool is_secondary) {
423+ is_secondary_ = is_secondary;
424+ }
425+
426+ bool manager::get_is_secondary () const {
427+ return is_secondary_;
422428}
423429
424430manager *manager::get_secondary () {
@@ -628,7 +634,7 @@ void manager::reconnect_rpc()
628634
629635 // check for successful (re)connect
630636 if ( !hconn_.get_is_err () && ( !wconn_ || !wconn_->get_is_err () ) ) {
631- PC_LOG_INF ( " rpc_connected" ).add ( " secondary" , is_secondary () ).end ();
637+ PC_LOG_INF ( " rpc_connected" ).add ( " secondary" , get_is_secondary () ).end ();
632638 set_status ( PC_PYTH_RPC_CONNECTED );
633639
634640 // reset state
@@ -735,7 +741,7 @@ void manager::log_disconnect()
735741{
736742 if ( hconn_.get_is_err () ) {
737743 PC_LOG_ERR ( " rpc_http_reset" )
738- .add ( " secondary" , is_secondary () )
744+ .add ( " secondary" , get_is_secondary () )
739745 .add ( " error" , hconn_.get_err_msg () )
740746 .add ( " host" , rhost_ )
741747 .add ( " port" , hconn_.get_port () )
@@ -744,7 +750,7 @@ void manager::log_disconnect()
744750 }
745751 if ( wconn_ && wconn_->get_is_err () ) {
746752 PC_LOG_ERR ( " rpc_websocket_reset" )
747- .add ( " secondary" , is_secondary () )
753+ .add ( " secondary" , get_is_secondary () )
748754 .add ( " error" , wconn_->get_err_msg () )
749755 .add ( " host" , rhost_ )
750756 .add ( " port" , wconn_->get_port () )
@@ -822,7 +828,7 @@ void manager::on_response( rpc::get_slot *res )
822828 PC_LOG_DBG ( " received get_slot" )
823829 .add ( " slot" , slot_ )
824830 .add ( " round_trip_time(ms)" , 1e-6 *ack_ts )
825- .add ( " secondary" , is_secondary () )
831+ .add ( " secondary" , get_is_secondary () )
826832 .end ();
827833
828834 // submit block hash every N slots
@@ -865,7 +871,7 @@ void manager::on_response( rpc::get_recent_block_hash *m )
865871 // set initialized status for block hash
866872 set_status ( PC_PYTH_HAS_BLOCK_HASH );
867873 PC_LOG_INF ( " received_recent_block_hash" )
868- .add ( " secondary" , is_secondary () )
874+ .add ( " secondary" , get_is_secondary () )
869875 .add ( " curr_slot" , slot_ )
870876 .add ( " hash_slot" , m->get_slot () )
871877 .add ( " round_trip_time(ms)" , 1e-6 *ack_ts )
@@ -884,15 +890,15 @@ void manager::on_response( rpc::account_update *m )
884890 if ( m->get_is_http () ) {
885891 int64_t ack_ts = m->get_recv_time () - m->get_sent_time ();
886892 PC_LOG_DBG ( " received account_update" )
887- .add ( " secondary" , is_secondary () )
893+ .add ( " secondary" , get_is_secondary () )
888894 .add ( " account" , *m->get_account () )
889895 .add ( " slot" , slot_ )
890896 .add ( " round_trip_time(ms)" , 1e-6 *ack_ts )
891897 .end ();
892898 }
893899 else {
894900 PC_LOG_DBG ( " received account_update" )
895- .add ( " secondary" , is_secondary () )
901+ .add ( " secondary" , get_is_secondary () )
896902 .add ( " account" , *m->get_account () )
897903 .add ( " slot" , slot_ )
898904 .end ();
@@ -939,14 +945,14 @@ bool manager::submit_poll( request *req )
939945 }
940946 if ( req->get_is_err () ) {
941947 PC_LOG_ERR ( " request error" )
942- .add ( " secondary" , is_secondary () )
948+ .add ( " secondary" , get_is_secondary () )
943949 .add ( " error" , req->get_err_msg () )
944950 .end ();
945951 return false ;
946952 }
947953 if ( get_is_err () ) {
948954 PC_LOG_ERR ( " request error" )
949- .add ( " secondary" , is_secondary () )
955+ .add ( " secondary" , get_is_secondary () )
950956 .add ( " error" , get_err_msg () )
951957 .end ();
952958 return false ;
@@ -966,7 +972,7 @@ void manager::on_connect()
966972void manager::on_disconnect ()
967973{
968974 // callback user with connection status
969- PC_LOG_INF ( " pyth_tx_reset" ).add ( " secondary" , is_secondary () ).end ();
975+ PC_LOG_INF ( " pyth_tx_reset" ).add ( " secondary" , get_is_secondary () ).end ();
970976 if ( sub_ ) {
971977 sub_->on_tx_disconnect ( this );
972978 }
0 commit comments