File tree Expand file tree Collapse file tree 1 file changed +20
-5
lines changed
apps/price_pusher/src/solana Expand file tree Collapse file tree 1 file changed +20
-5
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,25 @@ export class SolanaPriceListener extends ChainPriceListener {
2828 super ( config . pollingFrequency , priceItems ) ;
2929 }
3030
31+ // Checking the health of the Solana connection by checking the last block time
32+ // and ensuring it is not older than 30 seconds.
33+ private async checkHealth ( ) {
34+ const slot = await this . pythSolanaReceiver . connection . getSlot ( ) ;
35+ const blockTime = await this . pythSolanaReceiver . connection . getBlockTime (
36+ slot
37+ ) ;
38+ if ( blockTime !== undefined || blockTime < Date . now ( ) / 1000 - 30 ) {
39+ throw new Error ( "Solana connection is unhealthy" ) ;
40+ }
41+ }
42+
43+ async start ( ) {
44+ // Frequently check the RPC connection to ensure it is healthy
45+ setInterval ( ( ) => this . checkHealth . bind ( this ) , 5000 ) ;
46+
47+ await super . start ( ) ;
48+ }
49+
3150 async getOnChainPriceInfo ( priceId : string ) : Promise < PriceInfo | undefined > {
3251 try {
3352 const priceFeedAccount =
@@ -103,13 +122,9 @@ export class SolanaPricePusher implements IPricePusher {
103122 this . pythSolanaReceiver . connection ,
104123 this . pythSolanaReceiver . wallet
105124 ) ;
106- this . logger . info (
107- { signatures } ,
108- "broadcasted updatePriceFeed transactions"
109- ) ;
125+ this . logger . info ( { signatures } , "updatePriceFeed successful" ) ;
110126 } catch ( err : any ) {
111127 this . logger . error ( err , "updatePriceFeed failed" ) ;
112- throw err ;
113128 }
114129 }
115130}
You can’t perform that action at this time.
0 commit comments