@@ -6,7 +6,7 @@ using namespace pc;
6
6
#define PC_RPC_HTTP_PORT 8899
7
7
#define PC_RPC_WEBSOCKET_PORT 8900
8
8
#define PC_RECONNECT_TIMEOUT (120L *1000000000L )
9
- #define PC_BLOCKHASH_TIMEOUT 5
9
+ #define PC_BLOCKHASH_TIMEOUT 3
10
10
11
11
// /////////////////////////////////////////////////////////////////////////
12
12
// manager_sub
@@ -47,10 +47,9 @@ manager::manager()
47
47
slot_min_( 0L ),
48
48
slot_( 0UL ),
49
49
slot_cnt_( 0UL ),
50
- cum_ack_( 0L ),
51
- num_ack_( 0L ),
52
50
wait_conn_( false ),
53
- do_cap_( false )
51
+ do_cap_( false ),
52
+ first_ack_( true )
54
53
{
55
54
breq_->set_sub ( this );
56
55
sreq_->set_sub ( this );
@@ -356,8 +355,8 @@ void manager::poll( bool do_wait )
356
355
int64_t ts = get_now ();
357
356
while ( kidx_ < kvec_.size () ) {
358
357
price_sched *kptr = kvec_[kidx_];
359
- int64_t ack_ts = num_ack_?(cum_ack_/num_ack_): 0L ;
360
- int64_t tot_ts = slot_min_ - ack_ts - ack_ts ;
358
+ int64_t tot_ts = slot_min_ - ack_ts_ - ack_ts_ ;
359
+ tot_ts = std::max ( slot_min_/ 10 , tot_ts ) ;
361
360
int64_t pub_ts = slot_ts_ + ( tot_ts * kptr->get_hash () ) /
362
361
price_sched::fraction;
363
362
if ( ts > pub_ts ) {
@@ -392,6 +391,7 @@ void manager::reconnect_rpc()
392
391
393
392
// reset state
394
393
wait_conn_ = false ;
394
+ first_ack_ = true ;
395
395
ctimeout_ = PC_NSECS_IN_SEC;
396
396
slot_ts_ = slot_int_ = 0L ;
397
397
slot_cnt_ = 0UL ;
@@ -551,9 +551,14 @@ void manager::on_response( rpc::get_recent_block_hash *m )
551
551
+ m->get_err_msg () + " ]" );
552
552
return ;
553
553
}
554
+ static const double afactor = 2 ./(1 +8 .);
554
555
int64_t ack_ts = m->get_recv_time () - m->get_sent_time ();
555
- cum_ack_ += ack_ts;
556
- ++num_ack_;
556
+ if ( !first_ack_ ) {
557
+ ack_ts_ = (1 .-afactor)*ack_ts_ + afactor * ack_ts;
558
+ } else {
559
+ ack_ts_ = ack_ts;
560
+ first_ack_ = false ;
561
+ }
557
562
if ( has_status ( PC_PYTH_HAS_BLOCK_HASH ) ) {
558
563
return ;
559
564
}
@@ -562,7 +567,7 @@ void manager::on_response( rpc::get_recent_block_hash *m )
562
567
PC_LOG_INF ( " received_recent_block_hash" )
563
568
.add ( " slot" , m->get_slot () )
564
569
.add ( " slot_interval(ms)" , 1e-6 *slot_int_ )
565
- .add ( " rount_trip_time(ms)" , 1e-6 *ack_ts )
570
+ .add ( " rount_trip_time(ms)" , 1e-6 *ack_ts_ )
566
571
.end ();
567
572
568
573
// subscribe to mapping account if not done before
0 commit comments