retry contract calls
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 34s
Details
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 34s
Details
This commit is contained in:
parent
6911c04684
commit
233dcee11f
|
@ -11,6 +11,7 @@ const {
|
|||
const read = require('../util/forum/read');
|
||||
const write = require('../util/forum/write');
|
||||
const addPostWithRetry = require('../util/add-post-with-retry');
|
||||
const callWithRetry = require('../util/call-contract-method-with-retry');
|
||||
|
||||
const {
|
||||
ROLLUP_BATCH_SIZE,
|
||||
|
@ -39,7 +40,11 @@ const resetBatch = async () => {
|
|||
const stakeRollupAvailability = async () => {
|
||||
const currentRep = await dao.balanceOf(await wallet.getAddress());
|
||||
if (currentRep) {
|
||||
await dao.stakeAvailability(rollup.target, currentRep, availabilityStakeDuration);
|
||||
await callWithRetry(() => dao.stakeAvailability(
|
||||
rollup.target,
|
||||
currentRep,
|
||||
availabilityStakeDuration,
|
||||
));
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -95,7 +100,7 @@ const submitRollup = async () => {
|
|||
await stakeRollupAvailability();
|
||||
// Call Rollup.submitBatch
|
||||
const poolDuration = 60;
|
||||
await rollup.submitBatch(batchPostId, batchItems.length, poolDuration);
|
||||
await callWithRetry(() => rollup.submitBatch(batchPostId, batchItems.length, poolDuration));
|
||||
// Send matrix event
|
||||
await sendMatrixEvent('io.dgov.rollup.submit', { batchPostId, batchItems, authors });
|
||||
console.log('Submitted batch', { batchPostId, batchItems, authors });
|
||||
|
|
|
@ -1,16 +1,11 @@
|
|||
const Promise = require('bluebird');
|
||||
|
||||
const callWithRetry = require('./call-contract-method-with-retry');
|
||||
const { dao } = require('./contracts');
|
||||
|
||||
const addPostWithRetry = async (authors, hash, citations, retryDelay = 5000) => {
|
||||
const addPostWithRetry = async (authors, hash, citations) => {
|
||||
try {
|
||||
await dao.addPost(authors, hash, citations);
|
||||
await callWithRetry(() => dao.addPost(authors, hash, citations));
|
||||
} catch (e) {
|
||||
if (e.code === 'REPLACEMENT_UNDERPRICED') {
|
||||
console.log('retry delay (sec):', retryDelay / 1000);
|
||||
await Promise.delay(retryDelay);
|
||||
return addPostWithRetry(authors, hash, citations, retryDelay * 2);
|
||||
} if (e.reason === 'A post with this postId already exists') {
|
||||
if (e.reason === 'A post with this postId already exists') {
|
||||
return { alreadyAdded: true };
|
||||
}
|
||||
throw e;
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
const Promise = require('bluebird');
|
||||
|
||||
const callWithRetry = async (contractCall, retryDelay = 5000) => {
|
||||
let result;
|
||||
try {
|
||||
result = await contractCall();
|
||||
} catch (e) {
|
||||
if (e.code === 'REPLACEMENT_UNDERPRICED') {
|
||||
console.log('retry delay (sec):', retryDelay / 1000);
|
||||
await Promise.delay(retryDelay);
|
||||
return callWithRetry(contractCall, retryDelay * 2);
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
return result;
|
||||
};
|
||||
|
||||
module.exports = callWithRetry;
|
Loading…
Reference in New Issue