Skip to content

Commit b5a6354

Browse files
committed
Add secondary field to log lines
1 parent d090f72 commit b5a6354

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

pc/manager.cpp

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ void manager::del_map_sub()
120120
{
121121
if ( --num_sub_ <= 0 && !has_status( PC_PYTH_HAS_MAPPING ) ) {
122122
set_status( PC_PYTH_HAS_MAPPING );
123-
PC_LOG_INF( "completed_mapping_init" ).end();
123+
PC_LOG_INF( "completed_mapping_init" ).add( "secondary", is_secondary() ).end();
124124
// notify user that initialization is complete
125125
if ( sub_ ) {
126126
sub_->on_init( this );
@@ -270,7 +270,7 @@ uint64_t manager::get_slot() const
270270

271271
void manager::teardown()
272272
{
273-
PC_LOG_INF( "pythd_teardown" ).end();
273+
PC_LOG_INF( "pythd_teardown" ).add( "secondary", is_secondary() ).end();
274274

275275
// shutdown listener
276276
lsvr_.close();
@@ -308,15 +308,15 @@ bool manager::init()
308308
// log import key names
309309
key_pair *kp = get_publish_key_pair();
310310
if ( kp ) {
311-
PC_LOG_INF( "publish_key" ).add( "key_name", *kp ).end();
311+
PC_LOG_INF( "publish_key" ).add( "key_name", *kp ).add( "secondary", is_secondary() ).end();
312312
}
313313
pub_key *mpub = get_mapping_pub_key();
314314
if ( mpub ) {
315-
PC_LOG_INF( "mapping_key" ).add( "key_name", *mpub ).end();
315+
PC_LOG_INF( "mapping_key" ).add( "key_name", *mpub ).add( "secondary", is_secondary() ).end();
316316
}
317317
pub_key *gpub = get_program_pub_key();
318318
if ( gpub ) {
319-
PC_LOG_INF( "program_key" ).add( "key_name", *gpub ).end();
319+
PC_LOG_INF( "program_key" ).add( "key_name", *gpub ).add( "secondary", is_secondary() ).end();
320320
}
321321

322322
// initialize capture
@@ -374,10 +374,12 @@ bool manager::init()
374374
return set_err_msg( lsvr_.get_err_msg() );
375375
}
376376
PC_LOG_INF("listening").add("port",lsvr_.get_port())
377+
.add( "secondary", is_secondary() )
377378
.add( "content_dir", get_content_dir() )
378379
.end();
379380
}
380381
PC_LOG_INF( "initialized" )
382+
.add( "secondary", is_secondary() )
381383
.add( "version", PC_VERSION )
382384
.add( "rpc_host", get_rpc_host() )
383385
.add( "tx_host", get_tx_host() )
@@ -415,6 +417,10 @@ bool manager::has_secondary() const {
415417
return secondary_ != nullptr;
416418
}
417419

420+
bool manager::is_secondary() const {
421+
return !has_secondary();
422+
}
423+
418424
manager *manager::get_secondary() {
419425
return secondary_;
420426
}
@@ -622,7 +628,7 @@ void manager::reconnect_rpc()
622628

623629
// check for successful (re)connect
624630
if ( !hconn_.get_is_err() && ( !wconn_ || !wconn_->get_is_err() ) ) {
625-
PC_LOG_INF( "rpc_connected" ).end();
631+
PC_LOG_INF( "rpc_connected" ).add( "secondary", is_secondary() ).end();
626632
set_status( PC_PYTH_RPC_CONNECTED );
627633

628634
// reset state
@@ -729,6 +735,7 @@ void manager::log_disconnect()
729735
{
730736
if ( hconn_.get_is_err() ) {
731737
PC_LOG_ERR( "rpc_http_reset")
738+
.add( "secondary", is_secondary() )
732739
.add( "error", hconn_.get_err_msg() )
733740
.add( "host", rhost_ )
734741
.add( "port", hconn_.get_port() )
@@ -737,6 +744,7 @@ void manager::log_disconnect()
737744
}
738745
if ( wconn_ && wconn_->get_is_err() ) {
739746
PC_LOG_ERR( "rpc_websocket_reset" )
747+
.add( "secondary", is_secondary() )
740748
.add( "error", wconn_->get_err_msg() )
741749
.add( "host", rhost_ )
742750
.add( "port", wconn_->get_port() )
@@ -814,6 +822,7 @@ void manager::on_response( rpc::get_slot *res )
814822
PC_LOG_DBG( "received get_slot" )
815823
.add( "slot", slot_ )
816824
.add( "round_trip_time(ms)", 1e-6*ack_ts )
825+
.add( "secondary", is_secondary() )
817826
.end();
818827

819828
// submit block hash every N slots
@@ -856,6 +865,7 @@ void manager::on_response( rpc::get_recent_block_hash *m )
856865
// set initialized status for block hash
857866
set_status( PC_PYTH_HAS_BLOCK_HASH );
858867
PC_LOG_INF( "received_recent_block_hash" )
868+
.add( "secondary", is_secondary() )
859869
.add( "curr_slot", slot_ )
860870
.add( "hash_slot", m->get_slot() )
861871
.add( "round_trip_time(ms)", 1e-6*ack_ts )
@@ -874,13 +884,15 @@ void manager::on_response( rpc::account_update *m )
874884
if ( m->get_is_http() ) {
875885
int64_t ack_ts = m->get_recv_time() - m->get_sent_time();
876886
PC_LOG_DBG( "received account_update" )
887+
.add( "secondary", is_secondary() )
877888
.add( "account", *m->get_account() )
878889
.add( "slot", slot_ )
879890
.add( "round_trip_time(ms)", 1e-6*ack_ts )
880891
.end();
881892
}
882893
else {
883894
PC_LOG_DBG( "received account_update" )
895+
.add( "secondary", is_secondary() )
884896
.add( "account", *m->get_account() )
885897
.add( "slot", slot_ )
886898
.end();
@@ -927,12 +939,14 @@ bool manager::submit_poll( request *req )
927939
}
928940
if ( req->get_is_err() ) {
929941
PC_LOG_ERR( "request error")
942+
.add( "secondary", is_secondary() )
930943
.add( "error", req->get_err_msg() )
931944
.end();
932945
return false;
933946
}
934947
if ( get_is_err() ) {
935948
PC_LOG_ERR( "request error")
949+
.add( "secondary", is_secondary() )
936950
.add( "error", get_err_msg() )
937951
.end();
938952
return false;
@@ -952,7 +966,7 @@ void manager::on_connect()
952966
void manager::on_disconnect()
953967
{
954968
// callback user with connection status
955-
PC_LOG_INF( "pyth_tx_reset" ).end();
969+
PC_LOG_INF( "pyth_tx_reset" ).add( "secondary", is_secondary() ).end();
956970
if ( sub_ ) {
957971
sub_->on_tx_disconnect( this );
958972
}

pc/manager.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,7 @@ namespace pc
193193
bool get_is_rpc_send() const;
194194

195195
bool has_secondary() const;
196+
bool is_secondary() const;
196197
manager *get_secondary();
197198

198199
private:

pc/request.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ void get_mapping::update( T *res )
235235
// check and get any new product accounts in mapping table
236236
num_sym_ = tab->num_;
237237
PC_LOG_INF( "add_mapping" )
238+
.add( "secondary", cptr->is_secondary() )
238239
.add( "account", mkey_ )
239240
.add( "num_products", num_sym_ )
240241
.end();
@@ -381,6 +382,7 @@ void product::update( T *res )
381382
net_buf *jhd, *jtl;
382383
wtr.detach( jhd, jtl );
383384
PC_LOG_INF( st_ != e_done ? "add_product" : "upd_product" )
385+
.add( "secondary", cptr->is_secondary() )
384386
.add( "account", acc_ )
385387
.add( "attr", str( jhd->buf_, jhd->size_) )
386388
.end();
@@ -691,6 +693,7 @@ bool price::update(
691693
tvec_.emplace_back( std::string( 100, '\0' ), preq_->get_sent_time() );
692694
preq_->get_signature()->enc_base58( tvec_.back().first );
693695
PC_LOG_DBG( "sent price update transaction" )
696+
.add( "secondary", mgr->is_secondary() )
694697
.add( "price_account", *get_account() )
695698
.add( "product_account", *prod_->get_account() )
696699
.add( "symbol", get_symbol() )
@@ -700,6 +703,7 @@ bool price::update(
700703
.end();
701704
if ( PC_UNLIKELY( tvec_.size() >= 100 ) ) {
702705
PC_LOG_WRN( "too many unacked price update transactions" )
706+
.add( "secondary", mgr->is_secondary() )
703707
.add( "price_account", *get_account() )
704708
.add( "product_account", *prod_->get_account() )
705709
.add( "symbol", get_symbol() )
@@ -732,8 +736,10 @@ bool price::send( price *prices[], const unsigned n )
732736
// Build an upd_price rpc request for every price
733737
for ( unsigned i = 0, j = 0; i < n; ++i ) {
734738
price *const p = prices[ i ];
739+
manager *const mgr = p->get_manager();
735740
if ( PC_UNLIKELY( ! p->init_ && ! p->init_publish() ) ) {
736741
PC_LOG_ERR( "failed to initialize publisher" )
742+
.add( "secondary", mgr->is_secondary() )
737743
.add( "price_account", *p->get_account() )
738744
.add( "product_account", *p->prod_->get_account() )
739745
.add( "symbol", p->get_symbol() )
@@ -742,6 +748,7 @@ bool price::send( price *prices[], const unsigned n )
742748
}
743749
if ( PC_UNLIKELY( ! p->has_publisher() ) ) {
744750
PC_LOG_ERR( "missing publish permission" )
751+
.add( "secondary", mgr->is_secondary() )
745752
.add( "price_account", *p->get_account() )
746753
.add( "product_account", *p->prod_->get_account() )
747754
.add( "symbol", p->get_symbol() )
@@ -750,18 +757,20 @@ bool price::send( price *prices[], const unsigned n )
750757
}
751758
if ( PC_UNLIKELY( ! p->get_is_ready_publish() ) ) {
752759
PC_LOG_ERR( "not ready to publish - check rpc / pyth_tx connection" )
760+
.add( "secondary", mgr->is_secondary() )
753761
.add( "price_account", *p->get_account() )
754762
.add( "product_account", *p->prod_->get_account() )
755763
.add( "symbol", p->get_symbol() )
756764
.add( "price_type", price_type_to_str( p->get_price_type() ) ).end();
757765
continue;
758766
}
759-
manager *const mgr = p->get_manager();
767+
760768
if ( ! mgr1 ) {
761769
mgr1 = mgr;
762770
}
763771
else if ( mgr != mgr1 ) {
764772
PC_LOG_ERR( "unexpected manager" )
773+
.add( "secondary", mgr->is_secondary() )
765774
.add( "price_account", *p->get_account() )
766775
.add( "product_account", *p->prod_->get_account() )
767776
.add( "symbol", p->get_symbol() )
@@ -786,6 +795,7 @@ bool price::send( price *prices[], const unsigned n )
786795
}
787796
else {
788797
PC_LOG_ERR( "failed to build msg" )
798+
.add( "secondary", mgr->is_secondary() )
789799
.add( "price_account", *p->get_account() )
790800
.add( "product_account", *p->prod_->get_account() )
791801
.add( "symbol", p->get_symbol() )
@@ -801,6 +811,7 @@ bool price::send( price *prices[], const unsigned n )
801811
);
802812
p1->preq_->get_signature()->enc_base58( p1->tvec_.back().first );
803813
PC_LOG_DBG( "sent price update" )
814+
.add( "secondary", mgr->is_secondary() )
804815
.add( "price_account", *p1->get_account() )
805816
.add( "product_account", *p1->prod_->get_account() )
806817
.add( "symbol", p1->get_symbol() )
@@ -810,6 +821,7 @@ bool price::send( price *prices[], const unsigned n )
810821
.end();
811822
if ( PC_UNLIKELY( p1->tvec_.size() >= 100 ) ) {
812823
PC_LOG_WRN( "too many unacked price update transactions" )
824+
.add( "secondary", mgr->is_secondary() )
813825
.add( "price_account", *p1->get_account() )
814826
.add( "product_account", *p1->prod_->get_account() )
815827
.add( "symbol", p1->get_symbol() )
@@ -860,6 +872,7 @@ void price::on_response( rpc::upd_price *res )
860872
const int64_t ack_dur = res->get_recv_time() - it->second;
861873
tvec_.erase( it );
862874
PC_LOG_DBG( "received price update transaction ack" )
875+
.add( "secondary", get_manager()->is_secondary() )
863876
.add( "price_account", *get_account() )
864877
.add( "product_account", *prod_->get_account() )
865878
.add( "symbol", get_symbol() )
@@ -885,6 +898,7 @@ void price::on_response( rpc::account_update *res )
885898
void price::log_update( const char *title )
886899
{
887900
PC_LOG_INF( title )
901+
.add( "secondary", get_manager()->is_secondary() )
888902
.add( "account", *get_account() )
889903
.add( "product", *prod_->get_account() )
890904
.add( "symbol", get_symbol() )

0 commit comments

Comments
 (0)