This commit is contained in:
poma 2020-10-02 12:10:21 +03:00
parent 37c56553d1
commit 0df2926992
No known key found for this signature in database
GPG Key ID: BA20CB01FE165657
1 changed files with 5 additions and 3 deletions

View File

@ -62,6 +62,7 @@ class Transaction {
} }
if (!tx.gas) { if (!tx.gas) {
tx.gas = await this._web3.eth.estimateGas(tx) tx.gas = await this._web3.eth.estimateGas(tx)
tx.gas = Math.floor(tx.gas * 1.1)
} }
tx.nonce = this.tx.nonce // can be different from `this.manager._nonce` tx.nonce = this.tx.nonce // can be different from `this.manager._nonce`
tx.gasPrice = Math.max(this.tx.gasPrice, tx.gasPrice || 0) // start no less than current tx gas price tx.gasPrice = Math.max(this.tx.gasPrice, tx.gasPrice || 0) // start no less than current tx gas price
@ -91,7 +92,7 @@ class Transaction {
* @private * @private
*/ */
async _execute() { async _execute() {
const release = await this.manager._mutex.acquire() await this.manager._mutex.acquire()
try { try {
await this._prepare() await this._prepare()
await this._send() await this._send()
@ -100,7 +101,7 @@ class Transaction {
this.manager._nonce = this.tx.nonce + 1 this.manager._nonce = this.tx.nonce + 1
return receipt return receipt
} finally { } finally {
release() this.manager._mutex.release()
} }
} }
@ -113,7 +114,7 @@ class Transaction {
async _prepare() { async _prepare() {
const gas = await this._web3.eth.estimateGas(this.tx) const gas = await this._web3.eth.estimateGas(this.tx)
if (!this.tx.gas) { if (!this.tx.gas) {
this.tx.gas = gas this.tx.gas = Math.floor(gas * 1.1)
} }
if (!this.tx.gasPrice) { if (!this.tx.gasPrice) {
this.tx.gasPrice = await this._getGasPrice('fast') this.tx.gasPrice = await this._getGasPrice('fast')
@ -199,6 +200,7 @@ class Transaction {
continue continue
} }
// There is a mined tx with our nonce, let's see if it has a known hash
let receipt = await this._getReceipts() let receipt = await this._getReceipts()
// There is a mined tx with current nonce, but it's not one of ours // There is a mined tx with current nonce, but it's not one of ours