File tree Expand file tree Collapse file tree 4 files changed +26
-29
lines changed Expand file tree Collapse file tree 4 files changed +26
-29
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " @pythnetwork/price-service-server" ,
3- "version" : " 3.0.7 " ,
3+ "version" : " 3.0.8 " ,
44 "description" : " Webservice for retrieving prices from the Pyth oracle." ,
55 "private" : " true" ,
66 "main" : " index.js" ,
Original file line number Diff line number Diff line change @@ -440,6 +440,26 @@ export class Listener implements PriceStore {
440440 return false ;
441441 }
442442
443+ // if too many price feeds are stale it probably means that the price service
444+ // is not receiving messages from Wormhole at all and is essentially dead.
445+ const stalenessThreshold = 60 ;
446+ const maxToleratedStaleFeeds = 10 ;
447+
448+ const priceIds = [ ...this . getPriceIds ( ) ] ;
449+ let stalePriceCnt = 0 ;
450+
451+ for ( const priceId of priceIds ) {
452+ const latency =
453+ currentTime - this . getLatestPriceInfo ( priceId ) ! . attestationTime ;
454+ if ( latency > stalenessThreshold ) {
455+ stalePriceCnt ++ ;
456+ }
457+ }
458+
459+ if ( stalePriceCnt > maxToleratedStaleFeeds ) {
460+ return false ;
461+ }
462+
443463 return true ;
444464 }
445465
Original file line number Diff line number Diff line change @@ -514,7 +514,7 @@ export class RestAPI {
514514 endpoints . push ( "/api/stale_feeds?threshold=<staleness_threshold_seconds>" ) ;
515515
516516 app . get ( "/ready" , ( _ , res : Response ) => {
517- if ( this . isReady ! ( ) ) {
517+ if ( this . isReady === undefined || this . isReady ! ( ) ) {
518518 res . sendStatus ( StatusCodes . OK ) ;
519519 } else {
520520 res . sendStatus ( StatusCodes . SERVICE_UNAVAILABLE ) ;
@@ -523,32 +523,7 @@ export class RestAPI {
523523 endpoints . push ( "ready" ) ;
524524
525525 app . get ( "/live" , ( _ , res : Response ) => {
526- const threshold = 60 ;
527- const stalePriceTreshold = 10 ;
528- const minimumNumPrices = 100 ;
529-
530- const currentTime : TimestampInSec = Math . floor ( Date . now ( ) / 1000 ) ;
531-
532- const priceIds = [ ...this . priceFeedVaaInfo . getPriceIds ( ) ] ;
533- let stalePriceCnt = 0 ;
534-
535- for ( const priceId of priceIds ) {
536- const latency =
537- currentTime -
538- this . priceFeedVaaInfo . getLatestPriceInfo ( priceId ) ! . attestationTime ;
539- if ( latency > threshold ) {
540- stalePriceCnt ++ ;
541- }
542- }
543-
544- if (
545- priceIds . length < minimumNumPrices ||
546- stalePriceCnt > stalePriceTreshold
547- ) {
548- res . sendStatus ( StatusCodes . SERVICE_UNAVAILABLE ) ;
549- } else {
550- res . sendStatus ( StatusCodes . OK ) ;
551- }
526+ res . sendStatus ( StatusCodes . OK ) ;
552527 } ) ;
553528 endpoints . push ( "live" ) ;
554529
You can’t perform that action at this time.
0 commit comments