77
88import { importCoreWasm } from "@certusone/wormhole-sdk/lib/cjs/solana/wasm" ;
99
10- import { createHash } from "crypto" ;
11-
1210import {
1311 getBatchSummary ,
1412 parseBatchPriceAttestation ,
@@ -52,7 +50,7 @@ type ListenerConfig = {
5250 readiness : ListenerReadinessConfig ;
5351} ;
5452
55- type VaaHash = string ;
53+ type VaaKey = string ;
5654
5755export class Listener implements PriceStore {
5856 // Mapping of Price Feed Id to Vaa
@@ -63,7 +61,7 @@ export class Listener implements PriceStore {
6361 private spyConnectionTime : TimestampInSec | undefined ;
6462 private readinessConfig : ListenerReadinessConfig ;
6563 private updateCallbacks : ( ( priceInfo : PriceInfo ) => any ) [ ] ;
66- private observedVaas : LRUCache < VaaHash , boolean > ;
64+ private observedVaas : LRUCache < VaaKey , boolean > ;
6765
6866 constructor ( config : ListenerConfig , promClient ?: PromClient ) {
6967 this . promClient = promClient ;
@@ -162,15 +160,16 @@ export class Listener implements PriceStore {
162160
163161 const parsedVaa = parse_vaa ( vaa ) ;
164162
165- const vaaHash : VaaHash = createHash ( "md5" )
166- . update ( Buffer . from ( parsedVaa . payload ) )
167- . digest ( "base64" ) ;
163+ const vaaEmitterAddressHex = Buffer . from (
164+ parsedVaa . emitter_address
165+ ) . toString ( "hex" ) ;
166+ const vaaKey : VaaKey = `${ parsedVaa . emitter_chain } #${ vaaEmitterAddressHex } #${ parsedVaa . sequence } ` ;
168167
169- if ( this . observedVaas . has ( vaaHash ) ) {
168+ if ( this . observedVaas . has ( vaaKey ) ) {
170169 return ;
171170 }
172171
173- this . observedVaas . set ( vaaHash , true ) ;
172+ this . observedVaas . set ( vaaKey , true ) ;
174173 this . promClient ?. incReceivedVaa ( ) ;
175174
176175 let batchAttestation ;
0 commit comments