on master help sign in
Merge pull request #384 from urbit/m/reticket-bugs

Reticket end-of-flow bugs

commitb595254023935bd7d203835942b8c3fba7a4e69e authorFang <git@fang.io> dateMon 3 Feb 2020, 14:13 (7 years ago) parentb98e2d3f63d396
2 files changed+35−35
src/lib/reticket.js+27−27 src/lib/txn.js+8−8
src/lib/reticket.js+27−27
@@ -148,13 +148,12 @@ export async function reticketPointBetweenWallets({
148148
149149 progress(TRANSACTION_PROGRESS.SIGNING);
150150
151− const suggestedGasPrice = await getSuggestedGasPrice(networkType);
151+ const gasPriceGwei = (await getSuggestedGasPrice(networkType)).toFixed();
152152 const chainId = await web3.eth.net.getId();
153− const gasPrice = safeToWei(suggestedGasPrice.toFixed(), 'gwei');
154− const gasPriceBN = toBN(gasPrice);
153+ const gasPriceWeiBN = toBN(safeToWei(gasPriceGwei, 'gwei'));
155154 let inviteNonce = await web3.eth.getTransactionCount(fromWallet.address);
156155 const totalCost = txs.reduce(
157− (acc, tx) => acc.add(gasPriceBN.mul(toBN(tx.gas))),
156+ (acc, tx) => acc.add(gasPriceWeiBN.mul(toBN(tx.gas))),
158157 toBN(0)
159158 );
160159
@@ -170,7 +169,7 @@ export async function reticketPointBetweenWallets({
170169 txn: txs[i],
171170 nonce: inviteNonce + i,
172171 chainId,
173− gasPrice: suggestedGasPrice.toFixed(),
172+ gasPrice: gasPriceGwei,
174173 gasLimit: txs[i].gas,
175174 });
176175 txPairs.push({
@@ -215,29 +214,30 @@ export async function reticketPointBetweenWallets({
215214 // if non-trivial eth left in invite wallet, transfer to new ownership
216215 let balance = toBN(await web3.eth.getBalance(fromWallet.address));
217216 const gasLimit = GAS_LIMITS.SEND_ETH;
218− const sendEthCost = gasPriceBN.mul(toBN(gasLimit));
217+ const sendEthCost = gasPriceWeiBN.mul(toBN(gasLimit));
219218 if (transferEth && balance.gt(sendEthCost)) {
220− const value = balance.sub(sendEthCost);
221− const txn = {
222− to: toWallet.ownership.keys.address,
223− value: value,
224− };
225− const stx = signTransaction({
226− wallet: fromWallet,
227− walletType: fromWalletType,
228− walletHdPath: fromWalletHdPath,
229− txn,
230− chainId,
231− networkType,
232− gasPrice: gasPriceBN,
233− gasLimit,
234− nonce: inviteNonce++,
235− });
236− // let stx = new Tx(tx);
237− // stx.sign(fromWallet.privateKey);
238− sendSignedTransaction(web3, stx).catch(err => {
239− console.log('error sending value tx, who cares', err);
240− });
219+ try {
220+ const value = balance.sub(sendEthCost);
221+ const txn = {
222+ to: toWallet.ownership.keys.address,
223+ value: value,
224+ };
225+ const stx = await signTransaction({
226+ wallet: fromWallet,
227+ walletType: fromWalletType,
228+ walletHdPath: fromWalletHdPath,
229+ txn,
230+ chainId,
231+ networkType,
232+ gasPrice: gasPriceGwei,
233+ gasLimit,
234+ nonce: inviteNonce,
235+ });
236+ sendSignedTransaction(web3, stx);
237+ } catch (err) {
238+ console.log('error sending value tx, safely ignored:');
239+ console.log(err);
240+ }
241241 }
242242
243243 progress(TRANSACTION_PROGRESS.DONE);
src/lib/txn.js+8−8
@@ -127,20 +127,20 @@ const sendSignedTransaction = (web3, stx, doubtNonceError) => {
127127 // if there's a nonce error, but we used the gas tank, it's likely
128128 // that it's because the tank already submitted our transaction.
129129 // we just wait for first confirmation here.
130− console.error(err);
131− const isKnownError = (err.message || '').includes(
132− 'known transaction: '
133− );
134− const isNonceError = (err.message || '').includes(
135− "the tx doesn't have the correct nonce."
136− );
130+ const message = err.message || '';
131+ const isKnownError = message.includes('known transaction: ');
132+ const isNonceError =
133+ message.includes("the tx doesn't have the correct nonce.") ||
134+ message.includes('nonce too low');
137135 if (isKnownError || (doubtNonceError && isNonceError)) {
138136 console.log(
139− 'tx send error likely from gas tank submission, ignoring'
137+ 'tx send error likely from gas tank submission, ignoring:',
138+ message
140139 );
141140 const txHash = web3.utils.keccak256(rawTx);
142141 resolve(txHash);
143142 } else {
143+ console.error(err);
144144 reject(err.message || 'Transaction sending failed!');
145145 }
146146 });