Added missing DB indexes

This commit is contained in:
Tornado Contrib 2024-10-21 15:23:26 +00:00
parent dfb20aa617
commit 3d3b987635
Signed by: tornadocontrib
GPG Key ID: 60B4DF1A076C64B1
6 changed files with 362 additions and 107 deletions

113
dist/index.js vendored

@ -3691,8 +3691,14 @@ async function saveDBEvents({
lastBlock lastBlock
}) { }) {
try { try {
const formattedEvents = events.map((e) => {
return {
eid: `${e.transactionHash}_${e.logIndex}`,
...e
};
});
await idb.createMultipleTransactions({ await idb.createMultipleTransactions({
data: events, data: formattedEvents,
storeName: instanceName storeName: instanceName
}); });
await idb.putItem({ await idb.putItem({
@ -3722,8 +3728,12 @@ async function loadDBEvents({
lastBlock: 0 lastBlock: 0
}; };
} }
const events = (await idb.getAll({ storeName: instanceName })).map((e) => {
delete e.eid;
return e;
});
return { return {
events: await idb.getAll({ storeName: instanceName }), events,
lastBlock: lastBlockStore.blockNumber lastBlock: lastBlockStore.blockNumber
}; };
} catch (err) { } catch (err) {
@ -9779,7 +9789,7 @@ class IndexedDB {
} }
}; };
this.dbName = dbName; this.dbName = dbName;
this.dbVersion = 34; this.dbVersion = 35;
} }
async initDB() { async initDB() {
try { try {
@ -9973,24 +9983,42 @@ async function getIndexedDB(netId) {
await idb2.initDB(); await idb2.initDB();
return idb2; return idb2;
} }
const DEPOSIT_INDEXES = [ const minimalIndexes = [
{ name: "transactionHash", unique: false }, {
{ name: "commitment", unique: true } name: "blockNumber",
unique: false
},
{
name: "transactionHash",
unique: false
}
]; ];
const WITHDRAWAL_INDEXES = [
{ name: "nullifierHash", unique: true }
// keys on which the index is created
];
const LAST_EVENT_INDEXES = [{ name: "name", unique: false }];
const defaultState = [ const defaultState = [
{ {
name: "encrypted_events", name: `echo_${netId}`,
keyPath: "transactionHash" keyPath: "eid",
indexes: [
...minimalIndexes,
{
name: "address",
unique: false
}
]
},
{
name: `encrypted_notes_${netId}`,
keyPath: "eid",
indexes: minimalIndexes
}, },
{ {
name: "lastEvents", name: "lastEvents",
keyPath: "name", keyPath: "name",
indexes: LAST_EVENT_INDEXES indexes: [
{
name: "name",
unique: false
}
]
} }
]; ];
const config = getConfig(netId); const config = getConfig(netId);
@ -9998,33 +10026,68 @@ async function getIndexedDB(netId) {
const stores = [...defaultState]; const stores = [...defaultState];
if (netId === NetId.MAINNET) { if (netId === NetId.MAINNET) {
stores.push({ stores.push({
name: "register_events", name: `registered_${netId}`,
keyPath: "ensName" keyPath: "ensName",
indexes: [
...minimalIndexes,
{
name: "relayerAddress",
unique: false
}
]
});
stores.push({
name: `governance_${netId}`,
keyPath: "eid",
indexes: [
...minimalIndexes,
{
name: "event",
unique: false
}
]
}); });
} }
Object.entries(tokens).forEach(([token, { instanceAddress }]) => { Object.entries(tokens).forEach(([token, { instanceAddress }]) => {
Object.keys(instanceAddress).forEach((amount) => { Object.keys(instanceAddress).forEach((amount) => {
if (nativeCurrency === token) { if (nativeCurrency === token) {
stores.push({ stores.push(
{
name: `stringify_bloom_${netId}_${token}_${amount}`, name: `stringify_bloom_${netId}_${token}_${amount}`,
keyPath: "hashBloom" keyPath: "hashBloom",
}); indexes: []
},
{
name: `stringify_tree_${netId}_${token}_${amount}`,
keyPath: "hashTree",
indexes: []
}
);
} }
stores.push( stores.push(
{ {
name: `deposits_${netId}_${token}_${amount}`, name: `deposits_${netId}_${token}_${amount}`,
keyPath: "leafIndex", keyPath: "leafIndex",
// the key by which it refers to the object must be in all instances of the storage // the key by which it refers to the object must be in all instances of the storage
indexes: DEPOSIT_INDEXES indexes: [
...minimalIndexes,
{
name: "commitment",
unique: true
}
]
}, },
{ {
name: `withdrawals_${netId}_${token}_${amount}`, name: `withdrawals_${netId}_${token}_${amount}`,
keyPath: "blockNumber", keyPath: "eid",
indexes: WITHDRAWAL_INDEXES indexes: [
}, ...minimalIndexes,
{ {
name: `stringify_tree_${netId}_${token}_${amount}`, name: "nullifierHash",
keyPath: "hashTree" unique: true
}
// keys on which the index is created
]
} }
); );
}); });

113
dist/index.mjs vendored

@ -3670,8 +3670,14 @@ async function saveDBEvents({
lastBlock lastBlock
}) { }) {
try { try {
const formattedEvents = events.map((e) => {
return {
eid: `${e.transactionHash}_${e.logIndex}`,
...e
};
});
await idb.createMultipleTransactions({ await idb.createMultipleTransactions({
data: events, data: formattedEvents,
storeName: instanceName storeName: instanceName
}); });
await idb.putItem({ await idb.putItem({
@ -3701,8 +3707,12 @@ async function loadDBEvents({
lastBlock: 0 lastBlock: 0
}; };
} }
const events = (await idb.getAll({ storeName: instanceName })).map((e) => {
delete e.eid;
return e;
});
return { return {
events: await idb.getAll({ storeName: instanceName }), events,
lastBlock: lastBlockStore.blockNumber lastBlock: lastBlockStore.blockNumber
}; };
} catch (err) { } catch (err) {
@ -9758,7 +9768,7 @@ class IndexedDB {
} }
}; };
this.dbName = dbName; this.dbName = dbName;
this.dbVersion = 34; this.dbVersion = 35;
} }
async initDB() { async initDB() {
try { try {
@ -9952,24 +9962,42 @@ async function getIndexedDB(netId) {
await idb2.initDB(); await idb2.initDB();
return idb2; return idb2;
} }
const DEPOSIT_INDEXES = [ const minimalIndexes = [
{ name: "transactionHash", unique: false }, {
{ name: "commitment", unique: true } name: "blockNumber",
unique: false
},
{
name: "transactionHash",
unique: false
}
]; ];
const WITHDRAWAL_INDEXES = [
{ name: "nullifierHash", unique: true }
// keys on which the index is created
];
const LAST_EVENT_INDEXES = [{ name: "name", unique: false }];
const defaultState = [ const defaultState = [
{ {
name: "encrypted_events", name: `echo_${netId}`,
keyPath: "transactionHash" keyPath: "eid",
indexes: [
...minimalIndexes,
{
name: "address",
unique: false
}
]
},
{
name: `encrypted_notes_${netId}`,
keyPath: "eid",
indexes: minimalIndexes
}, },
{ {
name: "lastEvents", name: "lastEvents",
keyPath: "name", keyPath: "name",
indexes: LAST_EVENT_INDEXES indexes: [
{
name: "name",
unique: false
}
]
} }
]; ];
const config = getConfig(netId); const config = getConfig(netId);
@ -9977,33 +10005,68 @@ async function getIndexedDB(netId) {
const stores = [...defaultState]; const stores = [...defaultState];
if (netId === NetId.MAINNET) { if (netId === NetId.MAINNET) {
stores.push({ stores.push({
name: "register_events", name: `registered_${netId}`,
keyPath: "ensName" keyPath: "ensName",
indexes: [
...minimalIndexes,
{
name: "relayerAddress",
unique: false
}
]
});
stores.push({
name: `governance_${netId}`,
keyPath: "eid",
indexes: [
...minimalIndexes,
{
name: "event",
unique: false
}
]
}); });
} }
Object.entries(tokens).forEach(([token, { instanceAddress }]) => { Object.entries(tokens).forEach(([token, { instanceAddress }]) => {
Object.keys(instanceAddress).forEach((amount) => { Object.keys(instanceAddress).forEach((amount) => {
if (nativeCurrency === token) { if (nativeCurrency === token) {
stores.push({ stores.push(
{
name: `stringify_bloom_${netId}_${token}_${amount}`, name: `stringify_bloom_${netId}_${token}_${amount}`,
keyPath: "hashBloom" keyPath: "hashBloom",
}); indexes: []
},
{
name: `stringify_tree_${netId}_${token}_${amount}`,
keyPath: "hashTree",
indexes: []
}
);
} }
stores.push( stores.push(
{ {
name: `deposits_${netId}_${token}_${amount}`, name: `deposits_${netId}_${token}_${amount}`,
keyPath: "leafIndex", keyPath: "leafIndex",
// the key by which it refers to the object must be in all instances of the storage // the key by which it refers to the object must be in all instances of the storage
indexes: DEPOSIT_INDEXES indexes: [
...minimalIndexes,
{
name: "commitment",
unique: true
}
]
}, },
{ {
name: `withdrawals_${netId}_${token}_${amount}`, name: `withdrawals_${netId}_${token}_${amount}`,
keyPath: "blockNumber", keyPath: "eid",
indexes: WITHDRAWAL_INDEXES indexes: [
}, ...minimalIndexes,
{ {
name: `stringify_tree_${netId}_${token}_${amount}`, name: "nullifierHash",
keyPath: "hashTree" unique: true
}
// keys on which the index is created
]
} }
); );
}); });

113
dist/tornado.umd.js vendored

@ -60083,8 +60083,14 @@ async function saveDBEvents({
lastBlock lastBlock
}) { }) {
try { try {
const formattedEvents = events.map((e) => {
return {
eid: `${e.transactionHash}_${e.logIndex}`,
...e
};
});
await idb.createMultipleTransactions({ await idb.createMultipleTransactions({
data: events, data: formattedEvents,
storeName: instanceName storeName: instanceName
}); });
await idb.putItem({ await idb.putItem({
@ -60114,8 +60120,12 @@ async function loadDBEvents({
lastBlock: 0 lastBlock: 0
}; };
} }
const events = (await idb.getAll({ storeName: instanceName })).map((e) => {
delete e.eid;
return e;
});
return { return {
events: await idb.getAll({ storeName: instanceName }), events,
lastBlock: lastBlockStore.blockNumber lastBlock: lastBlockStore.blockNumber
}; };
} catch (err) { } catch (err) {
@ -61872,7 +61882,7 @@ class IndexedDB {
} }
}; };
this.dbName = dbName; this.dbName = dbName;
this.dbVersion = 34; this.dbVersion = 35;
} }
async initDB() { async initDB() {
try { try {
@ -62066,24 +62076,42 @@ async function getIndexedDB(netId) {
await idb2.initDB(); await idb2.initDB();
return idb2; return idb2;
} }
const DEPOSIT_INDEXES = [ const minimalIndexes = [
{ name: "transactionHash", unique: false }, {
{ name: "commitment", unique: true } name: "blockNumber",
unique: false
},
{
name: "transactionHash",
unique: false
}
]; ];
const WITHDRAWAL_INDEXES = [
{ name: "nullifierHash", unique: true }
// keys on which the index is created
];
const LAST_EVENT_INDEXES = [{ name: "name", unique: false }];
const defaultState = [ const defaultState = [
{ {
name: "encrypted_events", name: `echo_${netId}`,
keyPath: "transactionHash" keyPath: "eid",
indexes: [
...minimalIndexes,
{
name: "address",
unique: false
}
]
},
{
name: `encrypted_notes_${netId}`,
keyPath: "eid",
indexes: minimalIndexes
}, },
{ {
name: "lastEvents", name: "lastEvents",
keyPath: "name", keyPath: "name",
indexes: LAST_EVENT_INDEXES indexes: [
{
name: "name",
unique: false
}
]
} }
]; ];
const config = (0,networkConfig/* getConfig */.zj)(netId); const config = (0,networkConfig/* getConfig */.zj)(netId);
@ -62091,33 +62119,68 @@ async function getIndexedDB(netId) {
const stores = [...defaultState]; const stores = [...defaultState];
if (netId === networkConfig/* NetId */.zr.MAINNET) { if (netId === networkConfig/* NetId */.zr.MAINNET) {
stores.push({ stores.push({
name: "register_events", name: `registered_${netId}`,
keyPath: "ensName" keyPath: "ensName",
indexes: [
...minimalIndexes,
{
name: "relayerAddress",
unique: false
}
]
});
stores.push({
name: `governance_${netId}`,
keyPath: "eid",
indexes: [
...minimalIndexes,
{
name: "event",
unique: false
}
]
}); });
} }
Object.entries(tokens).forEach(([token, { instanceAddress }]) => { Object.entries(tokens).forEach(([token, { instanceAddress }]) => {
Object.keys(instanceAddress).forEach((amount) => { Object.keys(instanceAddress).forEach((amount) => {
if (nativeCurrency === token) { if (nativeCurrency === token) {
stores.push({ stores.push(
{
name: `stringify_bloom_${netId}_${token}_${amount}`, name: `stringify_bloom_${netId}_${token}_${amount}`,
keyPath: "hashBloom" keyPath: "hashBloom",
}); indexes: []
},
{
name: `stringify_tree_${netId}_${token}_${amount}`,
keyPath: "hashTree",
indexes: []
}
);
} }
stores.push( stores.push(
{ {
name: `deposits_${netId}_${token}_${amount}`, name: `deposits_${netId}_${token}_${amount}`,
keyPath: "leafIndex", keyPath: "leafIndex",
// the key by which it refers to the object must be in all instances of the storage // the key by which it refers to the object must be in all instances of the storage
indexes: DEPOSIT_INDEXES indexes: [
...minimalIndexes,
{
name: "commitment",
unique: true
}
]
}, },
{ {
name: `withdrawals_${netId}_${token}_${amount}`, name: `withdrawals_${netId}_${token}_${amount}`,
keyPath: "blockNumber", keyPath: "eid",
indexes: WITHDRAWAL_INDEXES indexes: [
}, ...minimalIndexes,
{ {
name: `stringify_tree_${netId}_${token}_${amount}`, name: "nullifierHash",
keyPath: "hashTree" unique: true
}
// keys on which the index is created
]
} }
); );
}); });

File diff suppressed because one or more lines are too long

@ -38,8 +38,15 @@ export async function saveDBEvents<T extends MinimalEvents>({
lastBlock: number; lastBlock: number;
}) { }) {
try { try {
const formattedEvents = events.map((e) => {
return {
eid: `${e.transactionHash}_${e.logIndex}`,
...e,
};
});
await idb.createMultipleTransactions({ await idb.createMultipleTransactions({
data: events, data: formattedEvents,
storeName: instanceName, storeName: instanceName,
}); });
@ -76,8 +83,13 @@ export async function loadDBEvents<T extends MinimalEvents>({
}; };
} }
const events = (await idb.getAll<(T & { eid?: string })[]>({ storeName: instanceName })).map((e) => {
delete e.eid;
return e;
});
return { return {
events: await idb.getAll<T[]>({ storeName: instanceName }), events,
lastBlock: lastBlockStore.blockNumber, lastBlock: lastBlockStore.blockNumber,
}; };
} catch (err) { } catch (err) {

@ -55,7 +55,7 @@ export class IndexedDB {
}; };
this.dbName = dbName; this.dbName = dbName;
this.dbVersion = 34; this.dbVersion = 35;
} }
async initDB() { async initDB() {
@ -322,24 +322,43 @@ export async function getIndexedDB(netId?: NetIdType) {
return idb; return idb;
} }
const DEPOSIT_INDEXES = [ const minimalIndexes = [
{ name: 'transactionHash', unique: false }, {
{ name: 'commitment', unique: true }, name: 'blockNumber',
unique: false,
},
{
name: 'transactionHash',
unique: false,
},
]; ];
const WITHDRAWAL_INDEXES = [
{ name: 'nullifierHash', unique: true }, // keys on which the index is created
];
const LAST_EVENT_INDEXES = [{ name: 'name', unique: false }];
const defaultState = [ const defaultState = [
{ {
name: 'encrypted_events', name: `echo_${netId}`,
keyPath: 'transactionHash', keyPath: 'eid',
indexes: [
...minimalIndexes,
{
name: 'address',
unique: false,
},
],
},
{
name: `encrypted_notes_${netId}`,
keyPath: 'eid',
indexes: minimalIndexes,
}, },
{ {
name: 'lastEvents', name: 'lastEvents',
keyPath: 'name', keyPath: 'name',
indexes: LAST_EVENT_INDEXES, indexes: [
{
name: 'name',
unique: false,
},
],
}, },
]; ];
@ -351,34 +370,69 @@ export async function getIndexedDB(netId?: NetIdType) {
if (netId === NetId.MAINNET) { if (netId === NetId.MAINNET) {
stores.push({ stores.push({
name: 'register_events', name: `registered_${netId}`,
keyPath: 'ensName', keyPath: 'ensName',
indexes: [
...minimalIndexes,
{
name: 'relayerAddress',
unique: false,
},
],
});
stores.push({
name: `governance_${netId}`,
keyPath: 'eid',
indexes: [
...minimalIndexes,
{
name: 'event',
unique: false,
},
],
}); });
} }
Object.entries(tokens).forEach(([token, { instanceAddress }]) => { Object.entries(tokens).forEach(([token, { instanceAddress }]) => {
Object.keys(instanceAddress).forEach((amount) => { Object.keys(instanceAddress).forEach((amount) => {
if (nativeCurrency === token) { if (nativeCurrency === token) {
stores.push({ stores.push(
{
name: `stringify_bloom_${netId}_${token}_${amount}`, name: `stringify_bloom_${netId}_${token}_${amount}`,
keyPath: 'hashBloom', keyPath: 'hashBloom',
}); indexes: [],
},
{
name: `stringify_tree_${netId}_${token}_${amount}`,
keyPath: 'hashTree',
indexes: [],
},
);
} }
stores.push( stores.push(
{ {
name: `deposits_${netId}_${token}_${amount}`, name: `deposits_${netId}_${token}_${amount}`,
keyPath: 'leafIndex', // the key by which it refers to the object must be in all instances of the storage keyPath: 'leafIndex', // the key by which it refers to the object must be in all instances of the storage
indexes: DEPOSIT_INDEXES, indexes: [
...minimalIndexes,
{
name: 'commitment',
unique: true,
},
],
}, },
{ {
name: `withdrawals_${netId}_${token}_${amount}`, name: `withdrawals_${netId}_${token}_${amount}`,
keyPath: 'blockNumber', keyPath: 'eid',
indexes: WITHDRAWAL_INDEXES, indexes: [
}, ...minimalIndexes,
{ {
name: `stringify_tree_${netId}_${token}_${amount}`, name: 'nullifierHash',
keyPath: 'hashTree', unique: true,
}, // keys on which the index is created
],
}, },
); );
}); });