Skip to content

Only send one price update per price per slot #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions pc/manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,11 @@ price *manager::get_price( const pub_key& acc )

void manager::add_dirty_price(price* sptr)
{
// Skip this update if we have already attempted to update this price in the current slot.
if ( sptr->get_last_attempted_update_slot() == get_slot() ) {
return;
}

if( std::find(pending_upds_.begin(), pending_upds_.end(), sptr) == pending_upds_.end() ) {
pending_upds_.emplace_back( sptr );
}
Expand Down
14 changes: 13 additions & 1 deletion pc/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,8 @@ price::price( const pub_key& acc, product *prod )
prod_( prod ),
sched_( this ),
pinit_( this ),
pptr_(nullptr)
pptr_(nullptr),
last_attempted_update_slot_( 0UL )
{
areq_->set_account( &apub_ );
preq_->set_account( &apub_ );
Expand Down Expand Up @@ -558,6 +559,16 @@ uint64_t price::get_twac() const
return static_cast< uint64_t >( pptr_->twac_.val_ );
}

uint64_t price::get_last_attempted_update_slot() const
{
return last_attempted_update_slot_;
}

void price::set_last_attempted_update_slot( uint64_t slot )
{
last_attempted_update_slot_ = slot;
}

uint64_t price::get_prev_slot() const
{
return pptr_->prev_slot_;
Expand Down Expand Up @@ -738,6 +749,7 @@ bool price::send( price *prices[], const unsigned n )
for ( unsigned i = 0, j = 0; i < n; ++i ) {
price *const p = prices[ i ];
manager *const mgr = p->get_manager();
p->set_last_attempted_update_slot( mgr->get_slot() );
if ( PC_UNLIKELY( ! p->init_ && ! p->init_publish() ) ) {
PC_LOG_ERR( "failed to initialize publisher" )
.add( "secondary", mgr->get_is_secondary() )
Expand Down
5 changes: 5 additions & 0 deletions pc/request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ namespace pc
// ready to publish (i.e. not waiting for confirmation)
bool get_is_ready_publish() const;

// the slot when a price update was last attempted
uint64_t get_last_attempted_update_slot() const;
void set_last_attempted_update_slot( uint64_t );

// submit new price update and update aggregate
// will fail with false if in error (check get_is_err() )
// or because symbol is not ready to publish (get_is_ready_publish())
Expand Down Expand Up @@ -359,6 +363,7 @@ namespace pc
rpc::upd_price preq_[1];
pc_price_t *pptr_;
txid_vec_t tvec_;
uint64_t last_attempted_update_slot_;
};

template<class T>
Expand Down