console.table输出24行后报错,求技术排查
问题分析:console.table执行超24行触发合约回滚错误
我用console.table输出前24行数据完全正常,但超过24行就会抛出合约回滚错误。所有调用的语法完全一致,只有业务数据内容不同。
console.table配置代码
console.table([{ 'Input Token': inputTokenSymbol, 'Output Token': outputTokenSymbol, 'Input Amount': web3.utils.fromWei(inputAmount, 'Ether'), 'Uniswap V2 Return': uniV2Int, // 'Kyber Expected Rate': web3.utils.fromWei(kyberResult.expectedRate, 'Ether') - (web3.utils.fromWei(kyberResult.expectedRate, 'Ether') * 0.001), // 'Kyber Min Return': kyberInt, 'Para Return': paraInt, // 'Uniswap V2 Swapback': uniV2IntBack, // 'Para Swapback': paraIntBack, 'Gas': gasDueInEth, 'Transaction Fee': flashLoanTxnFee, 'Total Uni -> Para': totalUniToPara, 'Total Para -> Uni': totalParaToUni }]) }
调用示例
try { await checkPair({ inputTokenSymbol: 'WETH', inputTokenAddress: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', outputTokenSymbol: 'DAI', outputTokenAddress: '0x6b175474e89094c44da98b954eedeac495271d0f', inputAmount: web3.utils.toWei('10', 'ETHER') }) await checkPair({ inputTokenSymbol: 'WETH', inputTokenAddress: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2', outputTokenSymbol: 'LINK', outputTokenAddress: '0x514910771af9ca656af840dff83e8264ecf986ca', inputAmount: web3.utils.toWei('10', 'ETHER') }) // 以此类推,共约100行 }
抛出的错误信息
Error: Returned error: execution reverted at Object.ErrorResponse (/Users/TrentKennelly/price-bot/node_modules/web3-core-helpers/lib/errors.js:28:19) at /Users/TrentKennelly/price-bot/node_modules/web3-core-requestmanager/lib/index.js:300:36 at /Users/TrentKennelly/price-bot/node_modules/web3-providers-http/lib/index.js:124:13 at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { data: null }
无论选择哪24行,都会在输出第24行后触发报错,请问该问题的原因是什么?
可能的原因及验证方法
- RPC节点请求限流:绝大多数以太坊RPC节点(比如Infura、Alchemy)都有请求频率限制,免费额度一般是每分钟几十到上百次请求。你连续调用100次
checkPair,每次都会发起多个链上查询(比如Uniswap V2的流动性、Para的兑换价格),前24次刚好卡在节点的限流阈值内,超过后被节点拒绝,返回模糊的execution reverted错误(部分节点不会明确提示限流)。
验证:在每次checkPair调用后加1秒延迟,比如await new Promise(resolve => setTimeout(resolve, 1000)),看超过24行后是否还报错。 - web3连接池耗尽:web3的HTTP Provider默认连接数有限,连续发起大量请求会把连接池占满,后续请求无法建立连接,最终表现为合约回滚错误。
验证:检查web3 provider的配置,增加maxConnections参数,或者拆分调用批次,每20次调用后休息3-5秒再继续。 - 累计Gas超限:如果
checkPair内部是在同一个交易上下文里批量调用合约方法,累计Gas消耗超过了区块的Gas上限,节点会直接拒绝后续调用,触发回滚。
验证:单独调用第25个pair,看是否能正常执行,如果单独执行没问题,就说明是批量调用的累计问题。
内容的提问来源于stack exchange,提问作者Trent Kennelly
相关产品推荐
相关产品推荐

