Skip to content

Commit 9249415

Browse files
authored
fix: Hash ancillaryData in entity IDs to prevent PostgreSQL index overflow (#107)
* fix: Hash ancillaryData in entity IDs to prevent PostgreSQL index overflow * fix: remaining ancillary data in keys * feat: deploy new graphs Signed-off-by: Pablo Maldonado <pablo@umaproject.org> --------- Signed-off-by: Pablo Maldonado <pablo@umaproject.org>
1 parent 6d9cfb0 commit 9249415

File tree

19 files changed

+310
-218
lines changed

19 files changed

+310
-218
lines changed

README.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ This subgraph indexes events emitted by the "Skinny Optimistic Oracle" contracts
5353

5454
- Mainnet
5555
- TheGraph: <https://thegraph.com/studio/subgraph/mainnet-skinny-oo>
56-
- Goldsky:
56+
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/mainnet-skinny-optimistic-oracle/1.1.0/gn>
5757
- (testnet) Sepolia
5858
- TheGraph: <https://thegraph.com/studio/subgraph/sepolia-skinny-oo>
59-
- Goldsky:
59+
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/sepolia-skinny-optimistic-oracle/1.1.0/gn>
6060

6161
## Optimistic Oracle Events
6262

@@ -107,16 +107,16 @@ This subgraph indexes events and function calls by the "Optimistic Oracle V2" co
107107

108108
- Mainnet
109109
- TheGraph: <https://thegraph.com/studio/subgraph/mainnet-optimistic-oracle-v2>
110-
- Goldsky: <>
110+
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/mainnet-optimistic-oracle-v2/latest/gn>
111111
- Polygon
112112
- TheGraph: <https://thegraph.com/studio/subgraph/polygon-optimistic-oracle-v2>
113-
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/polygon-optimistic-oracle-v2/latest/gn>
113+
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/polygon-optimistic-oracle-v2/1.1.0/gn>
114114
- Arbitrum
115115
- TheGraph: <https://thegraph.com/studio/subgraph/arbitrum-optimistic-oracle-v2>
116-
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/arbitrum-optimistic-oracle-v2/latest/gn>
116+
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/arbitrum-optimistic-oracle-v2/1.1.0/gn>
117117
- Optimism
118118
- TheGraph: <https://thegraph.com/studio/subgraph/optimism-optimistic-oracle-v2>
119-
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/optimism-optimistic-oracle-v2/latest/gn>
119+
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/optimism-optimistic-oracle-v2/1.1.0/gn>
120120
- Boba
121121
- TheGraph: <https://thegraph.com/studio/subgraph/boba-optimistic-oracle-v2>
122122
- Goldsky:
@@ -126,30 +126,30 @@ This subgraph indexes events and function calls by the "Optimistic Oracle V2" co
126126
- TheGraph: <https://thegraph.coredao.org/subgraphs/name/umaprotocol/core-optimistic-oracle-v2>
127127
- (testnet) Sepolia
128128
- TheGraph: <https://thegraph.com/studio/subgraph/sepolia-optimistic-oracle-v2/>
129-
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/sepolia-optimistic-oracle-v2/1.0.0/gn>
129+
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/sepolia-optimistic-oracle-v2/1.1.0/gn>
130130
- Base
131131
- TheGraph: <https://thegraph.com/studio/subgraph/base-optimistic-oracle-v2>
132-
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/base-optimistic-oracle-v2/latest/gn>
132+
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/base-optimistic-oracle-v2/1.1.0/gn>
133133
- (staging) Base Sepolia
134134
- TheGraph: <https://thegraph.com/studio/subgraph/base-sepolia-oo-v2>
135-
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/base-optimistic-oracle-v2/latest/gn>
135+
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/base-sepolia-optimistic-oracle-v2/1.1.0/gn>
136136
- Blast
137137
- TheGraph: <https://thegraph.com/studio/subgraph/blast-optimistic-oracle-v2>
138-
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/blast-optimistic-oracle-v2/1.0.0/gn>
138+
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/blast-optimistic-oracle-v2/1.1.0/gn>
139139
- Story
140140
- TheGraph:
141-
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/story-optimistic-oracle-v2/0.0.1/gn>
141+
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/story-optimistic-oracle-v2/1.1.0/gn>
142142

143143
## Managed Optimistic Oracle V2 Events and Calls
144144

145145
This subgraph indexes events and function calls by the "Managed Optimistic Oracle V2" contracts. We reuse the code from `packages/optimistic-oracle-v2` because the events emitted are the same.
146146

147147
- Amoy
148148
- TheGraph:
149-
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/amoy-managed-optimistic-oracle-v2/1.0.6/gn>
149+
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/amoy-managed-optimistic-oracle-v2/1.1.0/gn>
150150
- Polygon
151151
- TheGraph:
152-
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/polygon-managed-optimistic-oracle-v2/1.0.3/gn>
152+
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/polygon-managed-optimistic-oracle-v2/1.0.4/gn>
153153

154154
## Financial Contract Events
155155

@@ -179,7 +179,7 @@ This subgraph indexes events emitted by the core Oracle contracts. The code can
179179

180180
- Mainnet
181181
- TheGraph: <https://thegraph.com/studio/subgraph/mainnet-voting-v2>
182-
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/mainnet-voting-v2/0.1.0/gn>
182+
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/mainnet-voting-v2/0.1.1/gn>
183183
- (testnet) Sepolia
184184
- TheGraph: <https://thegraph.com/studio/subgraph/sepolia-voting-v2/>
185185
- Goldsky: <https://api.goldsky.com/api/public/project_clus2fndawbcc01w31192938i/subgraphs/sepolia-voting-v2/1.0.0/gn>

packages/managed-oracle-v2/src/mappings/optimisticOracleV2.ts

Lines changed: 36 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import {
88
SetEventBasedCall,
99
Settle,
1010
} from "../../generated/ManagedOracleV2/ManagedOracleV2";
11-
import { getManagedRequestId, getOrCreateOptimisticPriceRequest } from "../utils/helpers";
11+
import { createOptimisticPriceRequestId, getManagedRequestId, getOrCreateOptimisticPriceRequest } from "../utils/helpers";
1212
import { CustomBond, CustomLiveness } from "../../generated/schema";
1313

1414
import { Address, BigInt, Bytes, dataSource, log } from "@graphprotocol/graph-ts";
@@ -89,12 +89,11 @@ export function handleOptimisticRequestPrice(event: RequestPrice): void {
8989
event.params.identifier.toString(),
9090
event.params.ancillaryData.toHex(),
9191
]);
92-
let requestId = event.params.identifier
93-
.toString()
94-
.concat("-")
95-
.concat(event.params.timestamp.toString())
96-
.concat("-")
97-
.concat(event.params.ancillaryData.toHex());
92+
let requestId = createOptimisticPriceRequestId(
93+
event.params.identifier,
94+
event.params.timestamp,
95+
event.params.ancillaryData
96+
);
9897

9998
let request = getOrCreateOptimisticPriceRequest(requestId);
10099

@@ -184,12 +183,11 @@ export function handleOptimisticProposePrice(event: ProposePrice): void {
184183
event.params.identifier.toString(),
185184
event.params.ancillaryData.toHex(),
186185
]);
187-
let requestId = event.params.identifier
188-
.toString()
189-
.concat("-")
190-
.concat(event.params.timestamp.toString())
191-
.concat("-")
192-
.concat(event.params.ancillaryData.toHex());
186+
let requestId = createOptimisticPriceRequestId(
187+
event.params.identifier,
188+
event.params.timestamp,
189+
event.params.ancillaryData
190+
);
193191

194192
let request = getOrCreateOptimisticPriceRequest(requestId);
195193

@@ -260,12 +258,11 @@ export function handleOptimisticDisputePrice(event: DisputePrice): void {
260258
event.params.identifier.toString(),
261259
event.params.ancillaryData.toHex(),
262260
]);
263-
let requestId = event.params.identifier
264-
.toString()
265-
.concat("-")
266-
.concat(event.params.timestamp.toString())
267-
.concat("-")
268-
.concat(event.params.ancillaryData.toHex());
261+
let requestId = createOptimisticPriceRequestId(
262+
event.params.identifier,
263+
event.params.timestamp,
264+
event.params.ancillaryData
265+
);
269266

270267
let request = getOrCreateOptimisticPriceRequest(requestId);
271268

@@ -306,12 +303,11 @@ export function handleOptimisticSettle(event: Settle): void {
306303
event.params.identifier.toString(),
307304
event.params.ancillaryData.toHex(),
308305
]);
309-
let requestId = event.params.identifier
310-
.toString()
311-
.concat("-")
312-
.concat(event.params.timestamp.toString())
313-
.concat("-")
314-
.concat(event.params.ancillaryData.toHex());
306+
let requestId = createOptimisticPriceRequestId(
307+
event.params.identifier,
308+
event.params.timestamp,
309+
event.params.ancillaryData
310+
);
315311

316312
let request = getOrCreateOptimisticPriceRequest(requestId);
317313

@@ -347,12 +343,11 @@ export function handleSetCustomLiveness(call: SetCustomLivenessCall): void {
347343
call.inputs.ancillaryData.toHex(),
348344
call.inputs.customLiveness.toString(),
349345
]);
350-
let requestId = call.inputs.identifier
351-
.toString()
352-
.concat("-")
353-
.concat(call.inputs.timestamp.toString())
354-
.concat("-")
355-
.concat(call.inputs.ancillaryData.toHex());
346+
let requestId = createOptimisticPriceRequestId(
347+
call.inputs.identifier,
348+
call.inputs.timestamp,
349+
call.inputs.ancillaryData
350+
);
356351

357352
let request = getOrCreateOptimisticPriceRequest(requestId);
358353
request.customLiveness = call.inputs.customLiveness;
@@ -367,12 +362,11 @@ export function handleSetBond(call: SetBondCall): void {
367362
call.inputs.ancillaryData.toHex(),
368363
call.inputs.bond.toString(),
369364
]);
370-
let requestId = call.inputs.identifier
371-
.toString()
372-
.concat("-")
373-
.concat(call.inputs.timestamp.toString())
374-
.concat("-")
375-
.concat(call.inputs.ancillaryData.toHex());
365+
let requestId = createOptimisticPriceRequestId(
366+
call.inputs.identifier,
367+
call.inputs.timestamp,
368+
call.inputs.ancillaryData
369+
);
376370

377371
let request = getOrCreateOptimisticPriceRequest(requestId);
378372
request.bond = call.inputs.bond;
@@ -386,12 +380,11 @@ export function handleSetEventBased(call: SetEventBasedCall): void {
386380
call.inputs.identifier.toString(),
387381
call.inputs.ancillaryData.toHex(),
388382
]);
389-
let requestId = call.inputs.identifier
390-
.toString()
391-
.concat("-")
392-
.concat(call.inputs.timestamp.toString())
393-
.concat("-")
394-
.concat(call.inputs.ancillaryData.toHex());
383+
let requestId = createOptimisticPriceRequestId(
384+
call.inputs.identifier,
385+
call.inputs.timestamp,
386+
call.inputs.ancillaryData
387+
);
395388

396389
let request = getOrCreateOptimisticPriceRequest(requestId);
397390
request.eventBased = true;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
export { getOrCreateOptimisticPriceRequest } from "./optimisticOracle";
1+
export { getOrCreateOptimisticPriceRequest, createOptimisticPriceRequestId } from "./optimisticOracle";
22
export { getManagedRequestId } from "./managedOracleV2";

packages/managed-oracle-v2/src/utils/helpers/optimisticOracle.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,25 @@
1-
import { Bytes } from "@graphprotocol/graph-ts";
1+
import { BigInt, Bytes, crypto } from "@graphprotocol/graph-ts";
22
import { OptimisticPriceRequest } from "../../../generated/schema";
33
import { BIGINT_ZERO } from "../constants";
44

5+
6+
// Creates a unique ID for an OptimisticPriceRequest entity.
7+
export function createOptimisticPriceRequestId(
8+
identifier: Bytes,
9+
timestamp: BigInt,
10+
ancillaryData: Bytes
11+
): string {
12+
const ancillaryDataHash = crypto.keccak256(ancillaryData).toHexString();
13+
return identifier
14+
.toString()
15+
.concat("-")
16+
.concat(timestamp.toString())
17+
.concat("-")
18+
.concat(ancillaryDataHash);
19+
}
20+
521
export function getOrCreateOptimisticPriceRequest(
6-
id: String,
22+
id: string,
723
createIfNotFound: boolean = true
824
): OptimisticPriceRequest {
925
let request = OptimisticPriceRequest.load(id);

packages/managed-oracle-v2/tests/managed-oracle-v2/managedOracle.test.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { describe, test, clearStore, assert, log, afterEach } from "matchstick-a
22
import { handleCustomLivenessSet, handleCustomBondSet } from "../../src/mappings/managedOracleV2";
33
import { handleOptimisticProposePrice, handleOptimisticRequestPrice } from "../../src/mappings/optimisticOracleV2";
44
import { createCustomBondIdFromEvent } from "../../src/utils/helpers/managedOracleV2";
5+
import { createOptimisticPriceRequestId } from "../../src/utils/helpers/optimisticOracle";
56
import {
67
createCustomLivenessSetEvent,
78
createCustomBondSetEvent,
@@ -173,7 +174,11 @@ describe("Managed OOv2", () => {
173174
);
174175
handleOptimisticRequestPrice(requestPriceEvent);
175176

176-
const requestId = identifierString.concat("-").concat(timestamp.toString()).concat("-").concat(ancillaryData);
177+
const requestId = createOptimisticPriceRequestId(
178+
Bytes.fromHexString(identifierHex) as Bytes,
179+
BigInt.fromI32(timestamp),
180+
Bytes.fromHexString(ancillaryData) as Bytes
181+
);
177182

178183
const priceRequestEntity = OptimisticPriceRequest.load(requestId);
179184

@@ -294,7 +299,11 @@ describe("Managed OOv2", () => {
294299
);
295300
handleOptimisticProposePrice(proposePriceEvent);
296301

297-
const requestId = identifierString.concat("-").concat(timestamp.toString()).concat("-").concat(ancillaryData);
302+
const requestId = createOptimisticPriceRequestId(
303+
Bytes.fromHexString(identifierHex) as Bytes,
304+
BigInt.fromI32(timestamp),
305+
Bytes.fromHexString(ancillaryData) as Bytes
306+
);
298307

299308
const priceRequestEntity = OptimisticPriceRequest.load(requestId);
300309

@@ -389,7 +398,11 @@ describe("Managed OOv2", () => {
389398
);
390399
handleOptimisticRequestPrice(requestPriceEvent);
391400

392-
const requestId = identifierString.concat("-").concat(timestamp.toString()).concat("-").concat(ancillaryData);
401+
const requestId = createOptimisticPriceRequestId(
402+
Bytes.fromHexString(identifierHex) as Bytes,
403+
BigInt.fromI32(timestamp),
404+
Bytes.fromHexString(ancillaryData) as Bytes
405+
);
393406

394407
const priceRequestEntity = OptimisticPriceRequest.load(requestId);
395408

0 commit comments

Comments
 (0)