Skip to content

Commit

Permalink
Force sequential handling of bulk transactions
Browse files Browse the repository at this point in the history
  • Loading branch information
ThibautBremand committed Aug 10, 2023
1 parent 58277b3 commit 8c092d3
Showing 1 changed file with 16 additions and 13 deletions.
29 changes: 16 additions & 13 deletions packages/extension/src/contexts/LedgerContext/LedgerContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,11 @@ const LedgerProvider: FC = ({ children }) => {
? await client.submit(signed.tx_blob)
: await client.submitAndWait(signed.tx_blob);

if (payload.parallelize) {
// Throttle the requests
await new Promise((resolve) => setTimeout(resolve, 1000));
}

// Check transaction result
if (payload.parallelize && !(tx as SubmitResponse).result.accepted) {
throw new Error("Couldn't submit the transaction");
Expand Down Expand Up @@ -831,19 +836,17 @@ const LedgerProvider: FC = ({ children }) => {
}
};

const results = await (payload.parallelize
? Promise.all(payload.transactions.map((tx) => processTransaction(tx)))
: (async () => {
const sequentialResults = [];
for (const tx of payload.transactions) {
const result = await processTransaction(tx);
sequentialResults.push(result);
if (result.error && onError === 'abort') {
return sequentialResults;
}
}
return sequentialResults;
})());
const results = await (async () => {
const results = [];
for (const tx of payload.transactions) {
const result = await processTransaction(tx);
results.push(result);
if (result.error && onError === 'abort') {
return results;
}
}
return results;
})();

const hasError = results.some((r) => r.error);

Expand Down

0 comments on commit 8c092d3

Please sign in to comment.