Scripts: For upgrading testnet (#2984)

This commit is contained in:
bruce-riley 2023-05-26 08:29:14 -05:00 committed by GitHub
parent e7abd1d968
commit 1514d7cd79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 279 additions and 37 deletions

View File

@ -1,50 +1,47 @@
// This script can be used to do a contract migration in testnet. The normal process of submitting a contract upgrade VAA
// does not work because admin of the contracts in testnet still belongs to the deployer wallet.
import { LCDClient, MnemonicKey } from "@terra-money/terra.js";
import {
MsgMigrateContract,
} from "@terra-money/terra.js";
import axios from "axios";
import { MsgMigrateContract } from "@terra-money/terra.js";
// import axios from "axios";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
export const TERRA_GAS_PRICES_URL = "https://fcd.terra.dev/v1/txs/gas_prices";
// export const TERRA_GAS_PRICES_URL = "https://fcd.terra.dev/v1/txs/gas_prices";
const argv = yargs(hideBin(process.argv))
.option('code_id', {
description: 'Which code id to upgrade to',
type: 'number',
.option("code_id", {
description: "Which code id to upgrade to",
type: "number",
})
.option('mnemonic', {
description: 'Mnemonic (private key)',
type: 'string',
required: true
.option("mnemonic", {
description: "Mnemonic (private key)",
type: "string",
required: true,
})
.option('contract', {
description: 'Contract to upgrade',
type: 'string',
required: true
.option("contract", {
description: "Contract address to upgrade",
type: "string",
required: true,
})
.help()
.alias('help', 'h').argv;
.alias("help", "h").argv;
/* Set up terra client & wallet */
const terra_host = {
URL: "https://bombay-lcd.terra.dev",
chainID: "bombay-12",
const host = {
URL: "https://pisco-lcd.terra.dev",
chainID: "pisco-1",
name: "testnet",
};
const lcd = new LCDClient(terra_host);
const lcd = new LCDClient(host);
const feeDenoms = ["uluna"];
const gasPrices = await axios
.get(TERRA_GAS_PRICES_URL)
.then((result) => result.data);
// const feeDenoms = ["uluna"];
// const gasPrices = await axios
// .get(TERRA_GAS_PRICES_URL)
// .then((result) => result.data);
const wallet = lcd.wallet(
new MnemonicKey({
mnemonic: argv.mnemonic
mnemonic: argv.mnemonic,
})
);
@ -59,14 +56,14 @@ const tx = await wallet.createAndSignTx({
argv.contract,
argv.code_id,
{
"action": ""
action: "",
},
{ uluna: 1000 }
),
],
memo: "",
feeDenoms,
gasPrices,
// feeDenoms,
// gasPrices,
});
const rs = await lcd.tx.broadcast(tx);

View File

@ -0,0 +1,81 @@
import { LCDClient, MnemonicKey } from "@terra-money/terra.js";
import { MsgStoreCode } from "@terra-money/terra.js";
import { readFileSync } from "fs";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
const argv = yargs(hideBin(process.argv))
.option("network", {
description: "Which network to deploy to",
choices: ["mainnet", "testnet", "devnet"],
required: true,
})
.option("artifact", {
description: "Which WASM file to deploy",
type: "string",
required: true,
})
.option("mnemonic", {
description: "Mnemonic (private key)",
type: "string",
required: true,
})
.help()
.alias("help", "h").argv;
const artifact = argv.artifact;
/* Set up terra client & wallet */
const host =
argv.network === "mainnet"
? {
URL: "https://phoenix-lcd.terra.dev",
chainID: "phoenix-1",
name: "mainnet",
}
: argv.network === "testnet"
? {
URL: "https://pisco-lcd.terra.dev",
chainID: "pisco-1",
name: "testnet",
}
: {
URL: "http://localhost:1318",
chainID: "phoenix-1",
};
const lcd = new LCDClient({
URL: host.URL,
chainID: host.chainID,
});
const wallet = lcd.wallet(
new MnemonicKey({
mnemonic: argv.mnemonic,
})
);
await wallet.sequence();
/* Deploy artifacts */
let codeId;
const contract_bytes = readFileSync(artifact);
console.log(`Storing WASM: ${artifact} (${contract_bytes.length} bytes)`);
const store_code = new MsgStoreCode(
wallet.key.accAddress,
contract_bytes.toString("base64")
);
const tx = await wallet.createAndSignTx({
msgs: [store_code],
memo: "",
});
const rs = await lcd.tx.broadcast(tx);
const ci = /"code_id","value":"([^"]+)/gm.exec(rs.raw_log)[1];
codeId = parseInt(ci);
console.log("Code ID: ", codeId);

View File

@ -0,0 +1,81 @@
import "dotenv/config";
import { LCDClient, MnemonicKey, MsgStoreCode } from "@xpla/xpla.js";
import { readFileSync } from "fs";
import yargs from "yargs";
import { hideBin } from "yargs/helpers";
const argv = yargs(hideBin(process.argv))
.option("network", {
description: "Which network to deploy to",
choices: ["mainnet", "testnet", "devnet"],
required: true,
})
.option("artifact", {
description: "Which WASM file to deploy",
type: "string",
required: true,
})
.option("mnemonic", {
description: "Mnemonic (private key)",
type: "string",
required: true,
})
.help()
.alias("help", "h").argv;
const artifact = argv.artifact;
/* Set up terra client & wallet */
const host =
argv.network === "mainnet"
? {
URL: "https://dimension-lcd.xpla.dev",
chainID: "dimension_37-1",
name: "mainnet",
}
: argv.network === "testnet"
? {
URL: "https://cube-lcd.xpla.dev:443",
chainID: "cube_47-5",
name: "testnet",
}
: {
URL: undefined,
chainID: undefined,
};
const lcd = new LCDClient({
URL: host.URL,
chainID: host.chainID,
});
const wallet = lcd.wallet(
new MnemonicKey({
mnemonic: argv.mnemonic,
})
);
await wallet.sequence();
/* Deploy artifacts */
let codeId;
const contract_bytes = readFileSync(artifact);
console.log(`Storing WASM: ${artifact} (${contract_bytes.length} bytes)`);
const store_code = new MsgStoreCode(
wallet.key.accAddress,
contract_bytes.toString("base64")
);
const tx = await wallet.createAndSignTx({
msgs: [store_code],
memo: "",
});
const rs = await lcd.tx.broadcast(tx);
const ci = /"code_id","value":"([^"]+)/gm.exec(rs.raw_log)[1];
codeId = parseInt(ci);
console.log("Code ID: ", codeId);

83
docs/updating_testnet.md Normal file
View File

@ -0,0 +1,83 @@
# Updating All Contracts in Testnet
This document describes how to update all the token bridge contracts in testnet for the purpose of resetting an emitter address
for a chain. In this example, we will be updating "all" token bridge contracts to reset the emitter address for
Sui. This is necessary because the Sui testnet environment gets reset periodically, requiring that the Wormhole
contracts be redeployed, changing the emitter address.
It should be noted that "all" does not literally mean all chains. At this time, this process does not support the following:
- Algorand
- Near
Supporting these chains just requires adding the appropriate documentation / scripting to support a contract upgrade
to reset a given emitter address.
Additionally, some chains allow you to overwrite an existing registration with a new one, so you do not need to upgrade the contract to reset a registration. This includes:
- Solana
- Aptos
- Sui
It should also be noted that this is a work in progress. Over time, some of these steps may be automated in the `worm` tool or other scripts.
## Process Setup
To set up for this process, start with a clean repo and follow these steps.
1. Checkout the `deploy_update_all_in_testnet` branch.
2. Rebase the branch off the latest `main`.
## Upgrading EVM Chains
The EVM contracts do not allow updating a registration for a chain that is already registered, so you need to upgrade the contract to clear the registration, and then submit the new VAA.
1. Edit `ethereum/contracts/bridge/BridgeImplementation.sol` to set the chain ID that you want reset (default is chain 21 for Sui).
2. cd to `ethereum` and do `npm run build`
3. Update the gas parameters in `ethereum/truffle-config.js` for Karura and Acala.
- Use the `getKaruraTestnetGas.sh` and `getAcalaTestnetGas.sh` scripts to query for the latest gas prices and update the `gasPrice` and `gas` parameters for karura_testnet and acala_testnet. TODO: Automate this or put these scripts in the repo.
4. Run `./upgrade_all_test`. This should upgrade each EVM chain and submit the contract upgrade VAA for it.
5. Deal with any chains that fail, on a case by case basis. If you need to rerun a single chain, do something like this:
```bash
MNEMONIC=<deployerMnemonic> GUARDIAN_MNEMONIC=<guardianSecretKey> ./upgrade testnet TokenBridge acala
```
## Upgrading Cosmwasm Contracts
The cosmwasm contracts do not allow updating a registration for a chain that is already registered, so you need to upgrade the contract to clear the registration, and then submit the new VAA.
1. Edit `cosmwasm/contracts/token-bridge/src/contract.rs` to set the chain ID that you want reset (default is chain 21 for Sui).
2. cd to `cosmwasm` and do `make artifacts`
### Resetting the Registration on Terra2
1. Deploy the new code to Terra2 by doing the following. This should give you the `code_id`.
```bash
cd cosmwasm
node deployment/terra2/tools/deploy_single.js --network testnet --artifact artifacts/cw_token_bridge.wasm --mnemonic "<testnetDeployerSeedPhrase>"
```
2. The admin of the Terra2 token bridge in testnet has not been transferred to the contract itself, so you cannot use the standard contract upgrade VAA to complete the upgrade. Instead, do the following:
```bash
node deployment/terra2/tools/migrate_testnet.js --network testnet --code_id <codeIdFromDeploy> --contract terra1c02vds4uhgtrmcw7ldlg75zumdqxr8hwf7npseuf2h58jzhpgjxsgmwkvk --mnemonic "<testnetDeployerSeedPhrase>"
```
### Resetting the Registration on XPLA
1. Deploy the new code to XPLA by doing the following. This should give you the `code_id`.
```bash
cd cosmwasm
node deployment/xpla/tools/deploy_single.js --network testnet --artifact artifacts/cw_token_bridge.wasm --mnemonic "<testnetDeployerSeedPhrase>"
```
2. Generate the contract upgrade VAA.
```
export UPGRADE_VAA=`worm generate upgrade --guardian-secret <guardianSecretKey> --chain xpla --module TokenBridge --contract-address <codeIdFromDeploy>`
```
3. Submit the contract upgrade VAA.
```
worm submit $UPGRADE_VAA --network testnet --chain xpla
```
## Submitting the Chain Registration on each Chain
1. Generate the new chain registration VAA using the new emitter address (which for Sui is different from the contract address) and update the entry in the Testnet V2 notion page:
```bash
export VAA=`worm generate registration --guardian-secret <guardianSecretKey> --chain sui --module TokenBridge --contract-address <newEmitterAddress>`
```
2. Submit the VAA to each chain like this:
```bash
worm submit $VAA --network testnet --chain <chainName>
```
## Verifying the Registrations
To verify that the registrations are all correct for a given chain, you can do the following. This command currently works for Solana, EVM, Terra2, XPLA, Aptos, Sui and Sei.
```bash
worm info registrations testnet acala TokenBridge --verify
```

View File

@ -140,7 +140,7 @@ module.exports = {
},
network_id: 0x4e454153,
gas: 10000000,
from: "0x3bC7f2e458aC4E55F941C458cfD8c6851a591B4F", // public key
from: "0x8F26A0025dcCc6Cfc07A7d38756280a10E295ad7", // public key
},
fantom: {
provider: () => {
@ -186,7 +186,7 @@ module.exports = {
);
},
network_id: 596,
gasPrice: "0x2f7e8805de",
gasPrice: "0x3006b003ea",
gasLimit: "0x329b140",
gas: "0x329b0dc",
},
@ -212,9 +212,8 @@ module.exports = {
);
},
network_id: 597,
gasPrice: "0x2ed51903ea",
gasLimit: "0x6fc3540",
gas: "0x329b0dc",
gasPrice: "0x33a70303ea", // Query for gas parameters.
gas: "0x6fc3540", // This is the value reported as "gasLimit" in the query.
},
klaytn: {
// Note that Klaytn works with version 5.3.14 of truffle, but not some of the newer versions.

View File

@ -31,6 +31,7 @@ var knownTestnetTokenbridgeEmitters = map[vaa.ChainID]string{
vaa.ChainIDNeon: "000000000000000000000000c7a204bdbfe983fcd8d8e61d02b475d4073ff97e",
vaa.ChainIDXpla: "b66da121bd3621c8d2604c08c82965640fe682d606af26a302ee09094f5e62cf",
vaa.ChainIDInjective: "00000000000000000000000003f3e7b2e363f51cf6e57ef85f43a2b91dbce501",
vaa.ChainIDSui: "40440411a170b4842ae7dee4f4a7b7a58bc0a98566e998850a7bb87bf5dc05b9",
vaa.ChainIDBase: "000000000000000000000000A31aa3FDb7aF7Db93d18DDA4e19F811342EDF780",
vaa.ChainIDSei: "9328673cb5de3fd99974cefbbd90fea033f4c59a572abfd7e1a4eebcc5d18157",
vaa.ChainIDSepolia: "000000000000000000000000DB5492265f6038831E89f495670FF909aDe94bd9",