From 1c8d2a273766c571300014c1cb749a439b753203 Mon Sep 17 00:00:00 2001 From: kaladinlight <35275952+kaladinlight@users.noreply.github.com> Date: Wed, 11 Sep 2024 14:19:25 -0600 Subject: [PATCH] feat: thorchain-1 fork update + retry --- cli/MultiSig.md | 8 ++++---- cli/package.json | 5 ++--- cli/src/wallet.ts | 40 ++++++++++++++++++++++++++++------------ cli/yarn.lock | 25 +++++++++++++++++++------ 4 files changed, 53 insertions(+), 25 deletions(-) diff --git a/cli/MultiSig.md b/cli/MultiSig.md index ea1ff03..6690774 100644 --- a/cli/MultiSig.md +++ b/cli/MultiSig.md @@ -49,22 +49,22 @@ TAG=mainnet,cgo,ledger make install - Person 1 signs: ```bash - thornode tx sign --from {person1} --multisig multisig ~/rfox/unsignedTx_epoch-{N}.json --chain-id thorchain-mainnet-v1 --node https://daemon.thorchain.shapeshift.com:443/rpc --ledger --sign-mode amino-json > ~/rfox/signedTx_epoch-{N}_{person1}.json + thornode tx sign --from {person1} --multisig multisig ~/rfox/unsignedTx_epoch-{N}.json --chain-id thorchain-1 --node https://daemon.thorchain.shapeshift.com:443/rpc --ledger --sign-mode amino-json > ~/rfox/signedTx_epoch-{N}_{person1}.json ``` - Person 2 signs: ```bash - thornode tx sign --from {person2} --multisig multisig ~/rfox/unsignedTx_epoch-{N}.json --chain-id thorchain-mainnet-v1 --node https://daemon.thorchain.shapeshift.com:443/rpc --ledger --sign-mode amino-json > ~/rfox/signedTx_epoch-{N}_{person2}.json + thornode tx sign --from {person2} --multisig multisig ~/rfox/unsignedTx_epoch-{N}.json --chain-id thorchain-1 --node https://daemon.thorchain.shapeshift.com:443/rpc --ledger --sign-mode amino-json > ~/rfox/signedTx_epoch-{N}_{person2}.json ``` - Multisign: ```bash - thornode tx multisign ~/rfox/unsignedTx_epoch-{N}.json multisig ~/rfox/signedTx_epoch-{N}_{person1}.json ~/rfox/signedTx_epoch-{N}_{person2}.json --from multisig --chain-id thorchain-mainnet-v1 --node https://daemon.thorchain.shapeshift.com:443/rpc > ~/rfox/signedTx_epoch-{N}_multisig.json + thornode tx multisign ~/rfox/unsignedTx_epoch-{N}.json multisig ~/rfox/signedTx_epoch-{N}_{person1}.json ~/rfox/signedTx_epoch-{N}_{person2}.json --from multisig --chain-id thorchain-1 --node https://daemon.thorchain.shapeshift.com:443/rpc > ~/rfox/signedTx_epoch-{N}_multisig.json ``` ## Send Transaction - Broadcast transaction: ```bash - thornode tx broadcast ~/rfox/signedTx_epoch-{N}_multisig.json --chain-id thorchain-mainnet-v1 --node https://daemon.thorchain.shapeshift.com:443/rpc --gas auto > tx.json + thornode tx broadcast ~/rfox/signedTx_epoch-{N}_multisig.json --chain-id thorchain-1 --node https://daemon.thorchain.shapeshift.com:443/rpc --gas auto > tx.json ``` At this point, the cli should pick up the funding transaction and continue running the distribution from the hot wallet. diff --git a/cli/package.json b/cli/package.json index 40cff13..0be1333 100644 --- a/cli/package.json +++ b/cli/package.json @@ -16,15 +16,14 @@ "@inquirer/core": "^8.2.2", "@inquirer/prompts": "^5.0.5", "@pinata/sdk": "^2.1.0", - "@shapeshiftoss/hdwallet-core": "^1.54.0", - "@shapeshiftoss/hdwallet-native": "^1.54.0", + "@shapeshiftoss/hdwallet-core": "^1.55.1", + "@shapeshiftoss/hdwallet-native": "^1.55.1", "axios": "^1.7.2", "bignumber.js": "^9.1.2", "bip39": "^3.1.0", "chalk": "^5.3.0", "commander": "^12.1.0", "dotenv": "^16.4.5", - "hash-wasm": "^4.11.0", "log-symbols": "^6.0.0", "ora": "^8.0.1", "viem": "^2.17.3" diff --git a/cli/src/wallet.ts b/cli/src/wallet.ts index 0db5b71..dad0b1d 100644 --- a/cli/src/wallet.ts +++ b/cli/src/wallet.ts @@ -213,7 +213,7 @@ export class Wallet { const unsignedTx = { account_number: account.account_number, addressNList, - chain_id: 'thorchain-mainnet-v1', + chain_id: 'thorchain-1', sequence: String(Number(account.sequence) + i), tx: { msg: [ @@ -277,12 +277,10 @@ export class Wallet { const totalTxs = Object.values(epoch.distributionsByStakingAddress).length const spinner = ora(`Broadcasting ${totalTxs} transactions...`).start() - try { - for await (const [stakingAddress, { signedTx, txId }] of Object.entries(txsByStakingAddress)) { - if (txId) { - epoch.distributionsByStakingAddress[stakingAddress].txId = txId - continue - } + const doBroadcast = async (stakingAddress: string, signedTx: string, retryAttempt = 0) => { + try { + // delay between broadcast attempts to allow for transactions to confirm on chain + await new Promise(resolve => setTimeout(resolve, 1000)) const { data } = await axios.post<{ result: { code: number; data: string; log: string; hash: string } }>( `${THORNODE_URL}/rpc`, @@ -295,15 +293,33 @@ export class Wallet { ) if (!data.result.hash || data.result.code !== 0) { - spinner.suffixText = suffix(`Failed to broadcast transaction: ${data.result.data || data.result.log}.`) - break + if (retryAttempt >= 2) { + spinner.suffixText = suffix(`Failed to broadcast transaction: ${data.result.data || data.result.log}.`) + return + } + + return doBroadcast(stakingAddress, signedTx, ++retryAttempt) + } + + return data + } catch (err) { + if (retryAttempt >= 2) throw err + return doBroadcast(stakingAddress, signedTx, ++retryAttempt) + } + } + + try { + for await (const [stakingAddress, { signedTx, txId }] of Object.entries(txsByStakingAddress)) { + if (txId) { + epoch.distributionsByStakingAddress[stakingAddress].txId = txId + continue } + const data = await doBroadcast(stakingAddress, signedTx) + if (!data) break + txsByStakingAddress[stakingAddress].txId = data.result.hash epoch.distributionsByStakingAddress[stakingAddress].txId = data.result.hash - - // wait for transaction to confirm before broadcasting next transaction (this ensures sequence is incremented before subsequent broadcast) - await new Promise(resolve => setTimeout(resolve, 1_000)) } } catch (err) { if (isAxiosError(err)) { diff --git a/cli/yarn.lock b/cli/yarn.lock index 5e30c9e..7c8c803 100644 --- a/cli/yarn.lock +++ b/cli/yarn.lock @@ -1150,7 +1150,19 @@ web-encoding "^1.1.0" wif "^2.0.6" -"@shapeshiftoss/hdwallet-core@1.54.0", "@shapeshiftoss/hdwallet-core@^1.54.0", "@shapeshiftoss/hdwallet-core@latest": +"@shapeshiftoss/hdwallet-core@1.55.1", "@shapeshiftoss/hdwallet-core@^1.55.1": + version "1.55.1" + resolved "https://registry.yarnpkg.com/@shapeshiftoss/hdwallet-core/-/hdwallet-core-1.55.1.tgz#2369e47467e3e4e483352cea14d4f7744b928ba7" + integrity sha512-1aZbK+Eo9TqOeNk3x0bA/wRna1qV+QFXXyC6A75z4kzqbshFnogBlrD+71GlbzQYmB4d2JYhxouZ8HjA1kZnFw== + dependencies: + "@shapeshiftoss/proto-tx-builder" "^0.8.0" + eip-712 "^1.0.0" + eventemitter2 "^5.0.1" + lodash "^4.17.21" + rxjs "^6.4.0" + type-assertions "^1.1.0" + +"@shapeshiftoss/hdwallet-core@latest": version "1.54.0" resolved "https://registry.yarnpkg.com/@shapeshiftoss/hdwallet-core/-/hdwallet-core-1.54.0.tgz#e9e04ea363662d1dbfc62fb87c91ea293bdef4a7" integrity sha512-86HWxMXjEd87/Iw//M3xd+I8uDRIgmIauubdXzY8HpHytV3H0a1IO5cfB3dfMClE6OVWndmKjKONwcSN8uYtUw== @@ -1162,14 +1174,14 @@ rxjs "^6.4.0" type-assertions "^1.1.0" -"@shapeshiftoss/hdwallet-native@^1.54.0": - version "1.54.0" - resolved "https://registry.yarnpkg.com/@shapeshiftoss/hdwallet-native/-/hdwallet-native-1.54.0.tgz#a1ed16592018eb049bb6769425d8ef1a141941d1" - integrity sha512-ekGSduMQ2NHoLiNYwN2wCc+zra5ui6YKHFVb8Tw9hEgbsIT5CSpGJrzLKYDZXZKNBIB4/bzuESkhVYmaJ9D/fA== +"@shapeshiftoss/hdwallet-native@^1.55.1": + version "1.55.1" + resolved "https://registry.yarnpkg.com/@shapeshiftoss/hdwallet-native/-/hdwallet-native-1.55.1.tgz#6434c0b6cae6c60d770ab2c9cd93f3ba56fdcd1f" + integrity sha512-bpkX7Wpm3J93l119Crr6JEBAhfOqrB0y+FyslOTBm/aH1EBekTWH7rGaWRGe2CkOU5T817t31diow7nqzt9FUA== dependencies: "@shapeshiftoss/bitcoinjs-lib" "5.2.0-shapeshift.2" "@shapeshiftoss/fiosdk" "1.2.1-shapeshift.6" - "@shapeshiftoss/hdwallet-core" "1.54.0" + "@shapeshiftoss/hdwallet-core" "1.55.1" "@shapeshiftoss/proto-tx-builder" "^0.8.0" "@zxing/text-encoding" "^0.9.0" bchaddrjs "^0.4.9" @@ -1183,6 +1195,7 @@ ethers "5.7.2" eventemitter2 "^5.0.1" funtypes "^3.0.1" + hash-wasm "^4.11.0" lodash "^4.17.21" node-fetch "^2.6.1" p-lazy "^3.1.0"