Skip to content
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
3 changes: 1 addition & 2 deletions program/c/src/oracle/oracle.c
Original file line number Diff line number Diff line change
Expand Up @@ -489,8 +489,7 @@ static uint64_t upd_price( SolParameters *prm, SolAccountInfo *ka )
bool updated_aggregate = false;
// update aggregate price as necessary
if ( sptr->slot_ > pptr->agg_.pub_slot_ ) {
upd_aggregate( pptr, sptr->slot_, sptr->unix_timestamp_ );
updated_aggregate = true;
updated_aggregate = upd_aggregate( pptr, sptr->slot_, sptr->unix_timestamp_ );
}

// update component price if required
Expand Down
6 changes: 3 additions & 3 deletions program/c/src/oracle/test_oracle.c
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ Test( oracle, upd_price ) {
.data_len = sizeof( idata ),
.program_id = &p_id
};
cr_assert( SUCCESSFULLY_UPDATED_AGGREGATE == dispatch( &prm, acc ) );
cr_assert( SUCCESS == dispatch( &prm, acc ) );
cr_assert( sptr->comp_[0].latest_.price_ == 42L );
cr_assert( sptr->comp_[0].latest_.conf_ == 2L );
cr_assert( sptr->comp_[0].latest_.pub_slot_ == 1 );
Expand Down Expand Up @@ -478,7 +478,7 @@ Test( oracle, upd_price ) {
// Crank one more time and aggregate should be unknown
idata.pub_slot_ = 6;
cvar.slot_ = 7;
cr_assert( SUCCESSFULLY_UPDATED_AGGREGATE == dispatch( &prm, acc ) );
cr_assert( SUCCESS == dispatch( &prm, acc ) );
cr_assert( sptr->agg_.status_ == PC_STATUS_UNKNOWN );
}

Expand Down Expand Up @@ -559,7 +559,7 @@ Test( oracle, upd_price_no_fail_on_error ) {
pc_pub_key_assign( &sptr->comp_[0].pub_, (pc_pub_key_t*)&pkey );

// The update should now succeed, and have an effect.
cr_assert( SUCCESSFULLY_UPDATED_AGGREGATE == dispatch( &prm, acc ) );
cr_assert( SUCCESS == dispatch( &prm, acc ) );
cr_assert( sptr->comp_[0].latest_.price_ == 42L );
cr_assert( sptr->comp_[0].latest_.conf_ == 9L );
cr_assert( sptr->comp_[0].latest_.pub_slot_ == 1 );
Expand Down
9 changes: 5 additions & 4 deletions program/c/src/oracle/upd_aggregate.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,11 @@ static inline void upd_twap(
}

// update aggregate price
static inline void upd_aggregate( pc_price_t *ptr, uint64_t slot, int64_t timestamp )
static inline bool upd_aggregate( pc_price_t *ptr, uint64_t slot, int64_t timestamp )
{
// only re-compute aggregate in next slot
if ( slot <= ptr->agg_.pub_slot_ ) {
return;
return false;
}
pc_qset_t *qs = qset_new( ptr->expo_ );

Expand Down Expand Up @@ -195,7 +195,7 @@ static inline void upd_aggregate( pc_price_t *ptr, uint64_t slot, int64_t timest
ptr->num_qt_ = numv;
if ( numv == 0 || numv < ptr->min_pub_ ) {
ptr->agg_.status_ = PC_STATUS_UNKNOWN;
return;
return false;
}

// evaluate the model to get the p25/p50/p75 prices
Expand All @@ -220,7 +220,7 @@ static inline void upd_aggregate( pc_price_t *ptr, uint64_t slot, int64_t timest
// positive confidences given the current pricing model
if( agg_conf <= (int64_t)0 ) {
ptr->agg_.status_ = PC_STATUS_UNKNOWN;
return;
return false;
}
}

Expand All @@ -231,6 +231,7 @@ static inline void upd_aggregate( pc_price_t *ptr, uint64_t slot, int64_t timest
ptr->agg_.conf_ = (uint64_t)agg_conf;

upd_twap( ptr, agg_diff, qs );
return true;
}

#ifdef __cplusplus
Expand Down