fix: concurrency feature
MODIFY
src/common/ExitManager.ts
src/common/ExitManager.ts
@@ -28,7 +28,7 @@ export default class ExitManager extends ContractsBase {
this.networkApiUrl = options.network.Matic.NetworkAPI
}
- async buildPayloadForExit(burnTxHash, logEventSig) {
+ async buildPayloadForExit(burnTxHash, logEventSig, requestConcurrency?) {
// check checkpoint
const lastChildBlock = await this.rootChain.getLastChildBlock()
const burnTx = await this.web3Client.getMaticWeb3().eth.getTransaction(burnTxHash)
@@ -56,7 +56,12 @@ export default class ExitManager extends ContractsBase {
parseInt(burnTx.blockNumber + '', 10)
)
- const receiptProof: any = await Proofs.getReceiptProof(receipt, block, this.web3Client.getMaticWeb3())
+ const receiptProof: any = await Proofs.getReceiptProof(
+ receipt,
+ block,
+ this.web3Client.getMaticWeb3(),
+ requestConcurrency
+ )
let logIndex = -1
@@ -201,7 +206,7 @@ export default class ExitManager extends ContractsBase {
)
}
- async getExitHash(burnTxHash, logEventSig) {
+ async getExitHash(burnTxHash, logEventSig, requestConcurrency?) {
const lastChildBlock = await this.rootChain.getLastChildBlock()
const receipt = await this.web3Client.getMaticWeb3().eth.getTransactionReceipt(burnTxHash)
const block: any = await this.web3Client
@@ -213,7 +218,12 @@ export default class ExitManager extends ContractsBase {
'Burn transaction has not been checkpointed as yet'
)
- const receiptProof: any = await Proofs.getReceiptProof(receipt, block, this.web3Client.getMaticWeb3())
+ const receiptProof: any = await Proofs.getReceiptProof(
+ receipt,
+ block,
+ this.web3Client.getMaticWeb3(),
+ requestConcurrency
+ )
let logIndex = -1

MODIFY
src/libs/ProofsUtil.ts
src/libs/ProofsUtil.ts
@@ -228,7 +228,7 @@ export default class ProofsUtil {
return block.header
}
- static async getReceiptProof(receipt, block, web3, receipts?) {
+ static async getReceiptProof(receipt, block, web3, requestConcurrency = Infinity, receipts?) {
const stateSyncTxHash = ethUtils.bufferToHex(ProofsUtil.getStateSyncTxHash(block))
const receiptsTrie = new Trie()
const receiptPromises = []
@@ -240,7 +240,15 @@ export default class ProofsUtil {
}
receiptPromises.push(web3.eth.getTransactionReceipt(tx.hash))
})
- receipts = await Promise.all(receiptPromises)
+ receipts = await mapPromise(
+ receiptPromises,
+ val => {
+ return Promise.resolve(val)
+ },
+ {
+ concurrency: requestConcurrency,
+ }
+ )
}
for (let i = 0; i < receipts.length; i++) {

MODIFY
src/root/POSRootChainManager.ts
src/root/POSRootChainManager.ts
@@ -26,6 +26,7 @@ export default class POSRootChainManager extends ContractsBase {
private erc1155Predicate: address | null
private erc1155MintablePredicate: address | null
private rootTunnelContractAbi: any
+ public requestConcurrency: number | null
private formatUint256 = this.encode
@@ -42,6 +43,7 @@ export default class POSRootChainManager extends ContractsBase {
this.erc1155Predicate = options.posERC1155Predicate || options.network.Main.POSContracts.ERC1155PredicateProxy
this.erc1155MintablePredicate =
options.posMintableERC1155Predicate || options.network.Main.POSContracts.MintableERC1155PredicateProxy
+ this.requestConcurrency = options.requestConcurrency
}
async getPredicateAddress(rootToken: address) {
@@ -82,7 +84,7 @@ export default class POSRootChainManager extends ContractsBase {
if (!this.posRootChainManager.options.address) {
throw new Error('posRootChainManager address not found. Set it while constructing MaticPOSClient.')
}
- const payload = await this.exitManager.buildPayloadForExit(burnTxHash, logSignature)
+ const payload = await this.exitManager.buildPayloadForExit(burnTxHash, logSignature, this.requestConcurrency)
const txObject = this.posRootChainManager.methods.exit(payload)
const web3Options = await this.web3Client.fillOptions(txObject, true /* onRootChain */, options)
if (web3Options.encodeAbi) {
@@ -115,7 +117,7 @@ export default class POSRootChainManager extends ContractsBase {
}
async isExitProcessed(burnTxHash: string, logSignature: string) {
- const exitHash = await this.exitManager.getExitHash(burnTxHash, logSignature)
+ const exitHash = await this.exitManager.getExitHash(burnTxHash, logSignature, this.requestConcurrency)
return this.posRootChainManager.methods.processedExits(exitHash).call()
}

MODIFY
src/types/Common.ts
src/types/Common.ts
@@ -38,4 +38,5 @@ export declare interface MaticClientInitializationOptions {
posERC721Predicate?: string
posERC1155Predicate?: string
posMintableERC1155Predicate?: string
+ requestConcurrency?: number
}

fix: concurrency feature