当我把下面的代码部署到我的生产站点时,我遇到了一个无法解释的错误情况。在本地,所有这些函数都经过测试并且工作正常。
我试着深入了解那些看起来失败的承诺,但是它们没有触发任何异常。usersApiGateway.getNonce是一个get请求,我验证了当我在POSTMAN上发送get请求时,我得到了正确的返回值。
在我的AWS日志中,它基本上显示它一直执行到下面指定的点,然后就停止了。然后在大约10分钟后,它退出了通过asyncTimeout调用进程的尝试,然后它就永久卡住了。如果能帮助我找到这一问题的根本原因,我将不胜感激。
违规函数:
async createBuyOrder(tokenAddress, amountSell, amountBuy) {
amountSell = new BigNumber(amountSell);
amountBuy = new BigNumber(amountBuy);
let nonce = '';
[amountBuy, amountSell, nonce] = await Promise.all([
web3Service.convertToWei(tokenAddress, amountBuy),
web3Service.convertToWei(ETHER_ADDRESS, amountSell),
usersApiGateway.getNonce(this.adminAccount)
]);
// FUNCTION FAILS TO RETURN ANYTHING AFTER THIS POINT
// Console.log for nonce, amount buy/sell/buy order below fail to show up
// that is what I mean by not working
const buyOrder = {
"addressBuy" : tokenAddress,
"amountBuy" : amountBuy,
"addressSell": ETHER_ADDRESS,
"amountSell" : amountSell,
"nonce" : nonce,
}
await this.createOrder(buyOrder);
}
这是从以下函数调用的:
async populateOrderBook(tokenAddress, numOrders = 1) {
for(let i = numOrders; i > 0; i--) {
for(let j = -1; j < numOrders - i; j++){
try {
await this.createBuyOrder(tokenAddress, BUYORDER_amountSell, BUYORDER_amountBuy);
await this.createSellOrder(tokenAddress, SELLORDER_amountBuy, SELLORDER_amountSell);
} catch(exc) {
console.log(exc)
}
}
}
}
在类的init()函数中定期调用
asyncTimeout(async () => {
try {
await Promise.all([
this.populateOrderBook(tokenAddress, 3)
]);
} catch (exc) {
console.error('Error while populating order book from Kyber');
console.error(exc);
}
}, 60000);
我已经测试了web3Service中看似令人不快的函数,它希望挂起,并且似乎在本地运行良好
async convertToWei(tokenAddress, amount) {
const numberOfDecimals = await this.tokenDecimals(tokenAddress);
return new BigNumber(toBaseUnit(amount, numberOfDecimals));
}
1条答案
按热度按时间11dmarpk1#
我的节点与以太坊区块链的连接失效了,我用这个连接来确定convertToWei函数调用的小数位数,但由于连接失效,它陷入了一个永远无法解决的循环。