@@ -74,7 +74,8 @@ manager::manager()
7474 cmt_( commitment::e_confirmed ),
7575 max_batch_( PC_MAX_BATCH ),
7676 sreq_{ { commitment::e_processed } },
77- secondary_{ nullptr }
77+ secondary_{ nullptr },
78+ is_secondary_ ( false )
7879{
7980 tconn_.set_sub ( this );
8081 breq_->set_sub ( this );
@@ -117,7 +118,7 @@ void manager::del_map_sub()
117118{
118119 if ( --num_sub_ <= 0 && !has_status ( PC_PYTH_HAS_MAPPING ) ) {
119120 set_status ( PC_PYTH_HAS_MAPPING );
120- PC_LOG_INF ( " completed_mapping_init" ).add ( " secondary" , is_secondary () ).end ();
121+ PC_LOG_INF ( " completed_mapping_init" ).add ( " secondary" , get_is_secondary () ).end ();
121122 // notify user that initialization is complete
122123 if ( sub_ ) {
123124 sub_->on_init ( this );
@@ -267,7 +268,7 @@ uint64_t manager::get_slot() const
267268
268269void manager::teardown ()
269270{
270- PC_LOG_INF ( " pythd_teardown" ).add ( " secondary" , is_secondary () ).end ();
271+ PC_LOG_INF ( " pythd_teardown" ).add ( " secondary" , get_is_secondary () ).end ();
271272
272273 // shutdown listener
273274 lsvr_.close ();
@@ -305,15 +306,15 @@ bool manager::init()
305306 // log import key names
306307 key_pair *kp = get_publish_key_pair ();
307308 if ( kp ) {
308- PC_LOG_INF ( " publish_key" ).add ( " key_name" , *kp ).add ( " secondary" , is_secondary () ).end ();
309+ PC_LOG_INF ( " publish_key" ).add ( " key_name" , *kp ).add ( " secondary" , get_is_secondary () ).end ();
309310 }
310311 pub_key *mpub = get_mapping_pub_key ();
311312 if ( mpub ) {
312- PC_LOG_INF ( " mapping_key" ).add ( " key_name" , *mpub ).add ( " secondary" , is_secondary () ).end ();
313+ PC_LOG_INF ( " mapping_key" ).add ( " key_name" , *mpub ).add ( " secondary" , get_is_secondary () ).end ();
313314 }
314315 pub_key *gpub = get_program_pub_key ();
315316 if ( gpub ) {
316- PC_LOG_INF ( " program_key" ).add ( " key_name" , *gpub ).add ( " secondary" , is_secondary () ).end ();
317+ PC_LOG_INF ( " program_key" ).add ( " key_name" , *gpub ).add ( " secondary" , get_is_secondary () ).end ();
317318 }
318319
319320 // initialize capture
@@ -371,12 +372,12 @@ bool manager::init()
371372 return set_err_msg ( lsvr_.get_err_msg () );
372373 }
373374 PC_LOG_INF (" listening" ).add (" port" ,lsvr_.get_port ())
374- .add ( " secondary" , is_secondary () )
375+ .add ( " secondary" , get_is_secondary () )
375376 .add ( " content_dir" , get_content_dir () )
376377 .end ();
377378 }
378379 PC_LOG_INF ( " initialized" )
379- .add ( " secondary" , is_secondary () )
380+ .add ( " secondary" , get_is_secondary () )
380381 .add ( " version" , PC_VERSION )
381382 .add ( " rpc_host" , get_rpc_host () )
382383 .add ( " tx_host" , get_tx_host () )
@@ -405,6 +406,7 @@ void manager::add_secondary( const std::string& rpc_host, const std::string& key
405406 mgr->set_do_tx ( do_tx_ );
406407 mgr->set_do_ws ( do_ws_ );
407408 mgr->set_commitment ( cmt_ );
409+ mgr->set_is_secondary ( true );
408410
409411 secondary_ = mgr;
410412
@@ -414,8 +416,12 @@ bool manager::has_secondary() const {
414416 return secondary_ != nullptr ;
415417}
416418
417- bool manager::is_secondary () const {
418- return !has_secondary ();
419+ void manager::set_is_secondary (bool is_secondary) {
420+ is_secondary_ = is_secondary;
421+ }
422+
423+ bool manager::get_is_secondary () const {
424+ return is_secondary_;
419425}
420426
421427manager *manager::get_secondary () {
@@ -616,7 +622,7 @@ void manager::reconnect_rpc()
616622
617623 // check for successful (re)connect
618624 if ( !hconn_.get_is_err () && ( !wconn_ || !wconn_->get_is_err () ) ) {
619- PC_LOG_INF ( " rpc_connected" ).add ( " secondary" , is_secondary () ).end ();
625+ PC_LOG_INF ( " rpc_connected" ).add ( " secondary" , get_is_secondary () ).end ();
620626 set_status ( PC_PYTH_RPC_CONNECTED );
621627
622628 // reset state
@@ -720,7 +726,7 @@ void manager::log_disconnect()
720726{
721727 if ( hconn_.get_is_err () ) {
722728 PC_LOG_ERR ( " rpc_http_reset" )
723- .add ( " secondary" , is_secondary () )
729+ .add ( " secondary" , get_is_secondary () )
724730 .add ( " error" , hconn_.get_err_msg () )
725731 .add ( " host" , rhost_ )
726732 .add ( " port" , hconn_.get_port () )
@@ -729,7 +735,7 @@ void manager::log_disconnect()
729735 }
730736 if ( wconn_ && wconn_->get_is_err () ) {
731737 PC_LOG_ERR ( " rpc_websocket_reset" )
732- .add ( " secondary" , is_secondary () )
738+ .add ( " secondary" , get_is_secondary () )
733739 .add ( " error" , wconn_->get_err_msg () )
734740 .add ( " host" , rhost_ )
735741 .add ( " port" , wconn_->get_port () )
@@ -807,7 +813,7 @@ void manager::on_response( rpc::get_slot *res )
807813 PC_LOG_DBG ( " received get_slot" )
808814 .add ( " slot" , slot_ )
809815 .add ( " round_trip_time(ms)" , 1e-6 *ack_ts )
810- .add ( " secondary" , is_secondary () )
816+ .add ( " secondary" , get_is_secondary () )
811817 .end ();
812818
813819 // submit block hash every N slots
@@ -843,7 +849,7 @@ void manager::on_response( rpc::get_recent_block_hash *m )
843849 // set initialized status for block hash
844850 set_status ( PC_PYTH_HAS_BLOCK_HASH );
845851 PC_LOG_INF ( " received_recent_block_hash" )
846- .add ( " secondary" , is_secondary () )
852+ .add ( " secondary" , get_is_secondary () )
847853 .add ( " curr_slot" , slot_ )
848854 .add ( " hash_slot" , m->get_slot () )
849855 .add ( " round_trip_time(ms)" , 1e-6 *ack_ts )
@@ -862,15 +868,15 @@ void manager::on_response( rpc::account_update *m )
862868 if ( m->get_is_http () ) {
863869 int64_t ack_ts = m->get_recv_time () - m->get_sent_time ();
864870 PC_LOG_DBG ( " received account_update" )
865- .add ( " secondary" , is_secondary () )
871+ .add ( " secondary" , get_is_secondary () )
866872 .add ( " account" , *m->get_account () )
867873 .add ( " slot" , slot_ )
868874 .add ( " round_trip_time(ms)" , 1e-6 *ack_ts )
869875 .end ();
870876 }
871877 else {
872878 PC_LOG_DBG ( " received account_update" )
873- .add ( " secondary" , is_secondary () )
879+ .add ( " secondary" , get_is_secondary () )
874880 .add ( " account" , *m->get_account () )
875881 .add ( " slot" , slot_ )
876882 .end ();
@@ -917,14 +923,14 @@ bool manager::submit_poll( request *req )
917923 }
918924 if ( req->get_is_err () ) {
919925 PC_LOG_ERR ( " request error" )
920- .add ( " secondary" , is_secondary () )
926+ .add ( " secondary" , get_is_secondary () )
921927 .add ( " error" , req->get_err_msg () )
922928 .end ();
923929 return false ;
924930 }
925931 if ( get_is_err () ) {
926932 PC_LOG_ERR ( " request error" )
927- .add ( " secondary" , is_secondary () )
933+ .add ( " secondary" , get_is_secondary () )
928934 .add ( " error" , get_err_msg () )
929935 .end ();
930936 return false ;
@@ -944,7 +950,7 @@ void manager::on_connect()
944950void manager::on_disconnect ()
945951{
946952 // callback user with connection status
947- PC_LOG_INF ( " pyth_tx_reset" ).add ( " secondary" , is_secondary () ).end ();
953+ PC_LOG_INF ( " pyth_tx_reset" ).add ( " secondary" , get_is_secondary () ).end ();
948954 if ( sub_ ) {
949955 sub_->on_tx_disconnect ( this );
950956 }
0 commit comments