Skip to content

Commit 36fc1bf

Browse files
committed
Only send one price update per price per slot
1 parent 1eea565 commit 36fc1bf

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

pc/manager.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,14 @@ void manager::on_response( rpc::get_slot *res )
847847
cap_.flush();
848848
}
849849

850+
// mark all prices as unsent in the current slot
851+
for (size_t i = 0; i < svec_.size(); i++) {
852+
product* product = svec_[i];
853+
for (size_t j = 0; j < product->get_num_price(); j++) {
854+
product->get_price( j )->set_sent_in_current_slot( false );
855+
}
856+
}
857+
850858
if (
851859
has_status( PC_PYTH_RPC_CONNECTED )
852860
) {
@@ -1021,6 +1029,10 @@ price *manager::get_price( const pub_key& acc )
10211029

10221030
void manager::add_dirty_price(price* sptr)
10231031
{
1032+
if ( sptr->get_sent_in_current_slot() ) {
1033+
return;
1034+
}
1035+
10241036
if( std::find(pending_upds_.begin(), pending_upds_.end(), sptr) == pending_upds_.end() ) {
10251037
pending_upds_.emplace_back( sptr );
10261038
}

pc/request.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,8 @@ price::price( const pub_key& acc, product *prod )
458458
prod_( prod ),
459459
sched_( this ),
460460
pinit_( this ),
461-
pptr_(nullptr)
461+
pptr_(nullptr),
462+
sent_in_curr_slot_( false )
462463
{
463464
areq_->set_account( &apub_ );
464465
preq_->set_account( &apub_ );
@@ -558,6 +559,16 @@ uint64_t price::get_twac() const
558559
return static_cast< uint64_t >( pptr_->twac_.val_ );
559560
}
560561

562+
bool price::get_sent_in_current_slot() const
563+
{
564+
return sent_in_curr_slot_;
565+
}
566+
567+
void price::set_sent_in_current_slot( bool sent )
568+
{
569+
sent_in_curr_slot_ = sent;
570+
}
571+
561572
uint64_t price::get_prev_slot() const
562573
{
563574
return pptr_->prev_slot_;
@@ -738,6 +749,10 @@ bool price::send( price *prices[], const unsigned n )
738749
for ( unsigned i = 0, j = 0; i < n; ++i ) {
739750
price *const p = prices[ i ];
740751
manager *const mgr = p->get_manager();
752+
753+
// Mark that we have attempted to send the price update in the current slot
754+
p->set_sent_in_current_slot( true );
755+
741756
if ( PC_UNLIKELY( ! p->init_ && ! p->init_publish() ) ) {
742757
PC_LOG_ERR( "failed to initialize publisher" )
743758
.add( "secondary", mgr->get_is_secondary() )

pc/request.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,10 @@ namespace pc
265265
// ready to publish (i.e. not waiting for confirmation)
266266
bool get_is_ready_publish() const;
267267

268+
// a price update has been attempted in the current slot
269+
bool get_sent_in_current_slot() const;
270+
void set_sent_in_current_slot( bool );
271+
268272
// submit new price update and update aggregate
269273
// will fail with false if in error (check get_is_err() )
270274
// or because symbol is not ready to publish (get_is_ready_publish())
@@ -359,6 +363,7 @@ namespace pc
359363
rpc::upd_price preq_[1];
360364
pc_price_t *pptr_;
361365
txid_vec_t tvec_;
366+
bool sent_in_curr_slot_;
362367
};
363368

364369
template<class T>

0 commit comments

Comments
 (0)