Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vrtnd committed Jun 23, 2023
1 parent 2be47be commit 5381419
Showing 1 changed file with 15 additions and 16 deletions.
31 changes: 15 additions & 16 deletions src/utils/adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,14 @@ export const runAdapterToCurrentBlock = async (
const recordedBlocksFilename = `blocks-${bridgeDbName}.json`;
let recordedBlocks: RecordedBlocks | null = null;
try {
recordedBlocks =
bridgeDbName !== "multichain"
? ((
await retry(
async (_bail: any) =>
await axios.get(`https://llama-bridges-data.s3.eu-central-1.amazonaws.com/${recordedBlocksFilename}`),
{ retries: 4, factor: 1 }
)
).data as RecordedBlocks)
: null;
recordedBlocks = (
await retry(
async (_bail: any) =>
await axios.get(`https://llama-bridges-data.s3.eu-central-1.amazonaws.com/${recordedBlocksFilename}`),
{ retries: 4, factor: 1 }
)
).data as RecordedBlocks;

console.log("Retrieved recorded blocks");
} catch (e) {
console.log("No recorded blocks data for " + bridgeDbName);
Expand All @@ -118,10 +116,7 @@ export const runAdapterToCurrentBlock = async (
console.log("Inserted or skipped config");

const adapterPromises = Promise.all(
Object.keys(adapter).map(async (chain, i) => {
await wait(100 * i); // attempt to space out API calls
const bridgeID = (await getBridgeID(bridgeDbName, chain))?.id;

Object.keys(adapter).map(async (chain) => {
const chainContractsAreOn = bridgeNetwork.chainMapping?.[chain as Chain]
? bridgeNetwork.chainMapping?.[chain as Chain]
: chain;
Expand All @@ -130,13 +125,14 @@ export const runAdapterToCurrentBlock = async (
bridgeDbName,
chain,
chainContractsAreOn,
recordedBlocks
recordedBlocks!
);

console.log(`Searching for ${bridgeDbName}'s transactions from ${startBlock} to ${endBlock}`);
if (startBlock == null) return;
try {
await runAdapterHistorical(startBlock, endBlock, id, chain as Chain, allowNullTxValues, true, onConflict);
if (useRecordedBlocks) {
if (useRecordedBlocks && recordedBlocks) {
console.log(endBlock);
recordedBlocks[`${bridgeDbName}:${chain}`] = recordedBlocks[`${bridgeDbName}:${chain}`] || {};
recordedBlocks[`${bridgeDbName}:${chain}`].startBlock =
Expand All @@ -155,6 +151,9 @@ export const runAdapterToCurrentBlock = async (
}
} else {
try {
return;

const bridgeID = (await getBridgeID(bridgeDbName, chain))?.id;
let startBlock = (
await sql`select * from bridges.transactions where bridge_id = ${bridgeID} and chain = ${chain} order by ts desc limit 1;`
)[0].tx_block;
Expand Down

0 comments on commit 5381419

Please sign in to comment.