Skip to content

Commit

Permalink
feat: thorchain-1 fork update + retry
Browse files Browse the repository at this point in the history
  • Loading branch information
kaladinlight committed Sep 11, 2024
1 parent 52c8259 commit 1c8d2a2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 25 deletions.
8 changes: 4 additions & 4 deletions cli/MultiSig.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
5 changes: 2 additions & 3 deletions cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
40 changes: 28 additions & 12 deletions cli/src/wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand Down Expand Up @@ -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`,
Expand All @@ -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)) {
Expand Down
25 changes: 19 additions & 6 deletions cli/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,19 @@
web-encoding "^1.1.0"
wif "^2.0.6"

"@shapeshiftoss/[email protected]", "@shapeshiftoss/hdwallet-core@^1.54.0", "@shapeshiftoss/hdwallet-core@latest":
"@shapeshiftoss/[email protected]", "@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==
Expand All @@ -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"
Expand All @@ -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"
Expand Down

0 comments on commit 1c8d2a2

Please sign in to comment.