Skip to content

Commit 20abde0

Browse files
authored
Fix Vaa key for cache/metrics (#424)
1 parent 6e279c8 commit 20abde0

File tree

3 files changed

+11
-12
lines changed

3 files changed

+11
-12
lines changed

third_party/pyth/price-service/package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

third_party/pyth/price-service/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/pyth-price-service",
3-
"version": "2.2.1",
3+
"version": "2.2.2",
44
"description": "Pyth Price Service",
55
"main": "index.js",
66
"scripts": {

third_party/pyth/price-service/src/listen.ts

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ import {
77

88
import { importCoreWasm } from "@certusone/wormhole-sdk/lib/cjs/solana/wasm";
99

10-
import { createHash } from "crypto";
11-
1210
import {
1311
getBatchSummary,
1412
parseBatchPriceAttestation,
@@ -52,7 +50,7 @@ type ListenerConfig = {
5250
readiness: ListenerReadinessConfig;
5351
};
5452

55-
type VaaHash = string;
53+
type VaaKey = string;
5654

5755
export 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

Comments
 (0)