Skip to content

Commit 1428082

Browse files
authored
only return successfully updated aggrepage if upd_twap was called (#202)
1 parent d522ff4 commit 1428082

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

program/c/src/oracle/oracle.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,8 +489,7 @@ static uint64_t upd_price( SolParameters *prm, SolAccountInfo *ka )
489489
bool updated_aggregate = false;
490490
// update aggregate price as necessary
491491
if ( sptr->slot_ > pptr->agg_.pub_slot_ ) {
492-
upd_aggregate( pptr, sptr->slot_, sptr->unix_timestamp_ );
493-
updated_aggregate = true;
492+
updated_aggregate = upd_aggregate( pptr, sptr->slot_, sptr->unix_timestamp_ );
494493
}
495494

496495
// update component price if required

program/c/src/oracle/test_oracle.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ Test( oracle, upd_price ) {
409409
.data_len = sizeof( idata ),
410410
.program_id = &p_id
411411
};
412-
cr_assert( SUCCESSFULLY_UPDATED_AGGREGATE == dispatch( &prm, acc ) );
412+
cr_assert( SUCCESS == dispatch( &prm, acc ) );
413413
cr_assert( sptr->comp_[0].latest_.price_ == 42L );
414414
cr_assert( sptr->comp_[0].latest_.conf_ == 2L );
415415
cr_assert( sptr->comp_[0].latest_.pub_slot_ == 1 );
@@ -478,7 +478,7 @@ Test( oracle, upd_price ) {
478478
// Crank one more time and aggregate should be unknown
479479
idata.pub_slot_ = 6;
480480
cvar.slot_ = 7;
481-
cr_assert( SUCCESSFULLY_UPDATED_AGGREGATE == dispatch( &prm, acc ) );
481+
cr_assert( SUCCESS == dispatch( &prm, acc ) );
482482
cr_assert( sptr->agg_.status_ == PC_STATUS_UNKNOWN );
483483
}
484484

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

561561
// The update should now succeed, and have an effect.
562-
cr_assert( SUCCESSFULLY_UPDATED_AGGREGATE == dispatch( &prm, acc ) );
562+
cr_assert( SUCCESS == dispatch( &prm, acc ) );
563563
cr_assert( sptr->comp_[0].latest_.price_ == 42L );
564564
cr_assert( sptr->comp_[0].latest_.conf_ == 9L );
565565
cr_assert( sptr->comp_[0].latest_.pub_slot_ == 1 );

program/c/src/oracle/upd_aggregate.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,11 +141,11 @@ static inline void upd_twap(
141141
}
142142

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

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

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

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

233233
upd_twap( ptr, agg_diff, qs );
234+
return true;
234235
}
235236

236237
#ifdef __cplusplus

0 commit comments

Comments
 (0)