Continuously send messages to create load

This commit is contained in:
Joe Howarth 2023-03-10 16:16:23 -08:00
parent 0bf8bec315
commit 6dbcf7b495
8 changed files with 239 additions and 178 deletions

View File

@ -10,6 +10,13 @@ import "../interfaces/IWormholeReceiver.sol";
import "forge-std/console.sol";
interface Structs {
struct XAddress {
uint16 chainId;
bytes32 addr;
}
}
contract MockRelayerIntegration is IWormholeReceiver {
using BytesLib for bytes;
@ -38,8 +45,6 @@ contract MockRelayerIntegration is IWormholeReceiver {
uint32[] gasLimits;
}
event Received(bytes[] messages, uint16 sourceChain);
constructor(address _wormholeCore, address _coreRelayer) {
wormhole = IWormhole(_wormholeCore);
relayer = IWormholeRelayer(_coreRelayer);
@ -153,7 +158,6 @@ contract MockRelayerIntegration is IWormholeReceiver {
messages[i] = parsed.payload;
}
messageHistory.push(messages);
emit Received(messages, emitterChainId);
(IWormhole.VM memory parsed, bool valid, string memory reason) =
wormhole.parseAndVerifyVM(wormholeObservations[wormholeObservations.length - 2]);
@ -190,17 +194,17 @@ contract MockRelayerIntegration is IWormholeReceiver {
}
function getMessage() public view returns (bytes memory) {
if (messageHistory.length == 0) {
if (messageHistory.length == 0 || messageHistory[messageHistory.length - 1].length == 0) {
return new bytes(0);
}
return messageHistory[0][0];
return messageHistory[messageHistory.length - 1][0];
}
function getMessages() public view returns (bytes[] memory) {
if (messageHistory.length == 0 || messageHistory[0].length == 0) {
if (messageHistory.length == 0 || messageHistory[messageHistory.length - 1].length == 0) {
return new bytes[](0);
}
return messageHistory[0];
return messageHistory[messageHistory.length - 1];
}
function getMessageHistory() public view returns (bytes[][] memory) {
@ -224,18 +228,13 @@ contract MockRelayerIntegration is IWormholeReceiver {
registeredContracts[chainId] = emitterAddress;
}
function registerEmitters(XAddress[] calldata emitters) public {
function registerEmitters(Structs.XAddress[] calldata emitters) public {
require(msg.sender == owner);
for (uint256 i = 0; i < emitters.length; ++i) {
registerEmitter(emitters[i].chainId, emitters[i].addr);
for (uint256 i = 0; i < emitters.length; i++) {
registeredContracts[emitters[i].chainId] = emitters[i].addr;
}
}
struct XAddress {
uint16 chainId;
bytes32 addr;
}
function encodeFurtherInstructions(FurtherInstructions memory furtherInstructions)
public
view

View File

@ -23,7 +23,7 @@ import {IWormhole} from "../contracts/interfaces/IWormhole.sol";
import {WormholeSimulator, FakeWormholeSimulator} from "./WormholeSimulator.sol";
import {IWormholeReceiver} from "../contracts/interfaces/IWormholeReceiver.sol";
import {AttackForwardIntegration} from "../contracts/mock/AttackForwardIntegration.sol";
import {MockRelayerIntegration} from "../contracts/mock/MockRelayerIntegration.sol";
import {MockRelayerIntegration, Structs} from "../contracts/mock/MockRelayerIntegration.sol";
import "../contracts/libraries/external/BytesLib.sol";
import "forge-std/Test.sol";
@ -255,6 +255,9 @@ contract TestCoreRelayer is Test {
);
map[i].relayProvider.updateMaximumBudget(j, maxBudget);
map[i].integration.registerEmitter(j, bytes32(uint256(uint160(address(map[j].integration)))));
Structs.XAddress[] memory addresses = new Structs.XAddress[](1);
addresses[0] = Structs.XAddress(j, bytes32(uint256(uint160(address(map[j].integration)))));
map[i].integration.registerEmitters(addresses);
}
}
}

View File

@ -19,6 +19,7 @@
"build": "forge build -o build",
"unit-test": "forge test -vvvvv",
"integration-test": "bash shell-scripts/run_integration_tests.sh",
"load-test": "ENV=testnet ts-node ts-scripts/mockIntegrations/loadGeneration.ts",
"typechain": "bash ../sdk/scripts/make_ethers_types.sh",
"flatten": "mkdir -p node_modules/@poanet/solidity-flattener/contracts && cp -r contracts/* node_modules/@poanet/solidity-flattener/contracts/ && poa-solidity-flattener",
"deployAndConfigureTilt": "ENV=tilt bash ./ts-scripts/shell/deployConfigureTest.sh",

View File

@ -48,23 +48,23 @@
"mockIntegrations": [
{
"chainId": 6,
"address": "0x0979c1b2c04E0268a1DBF1800D5561354C719Ff9"
"address": "0xaC19a80C3409F8296043FC24F955790164Ccb15E"
},
{
"chainId": 14,
"address": "0x1C6508C24C05f631C1771dcF064AB46e8c7ADFd0"
"address": "0xC02d04f9067Ede6fF4CaDC31233c795ec982eFd7"
},
{
"chainId": 4,
"address": "0xFB29B4756F5F81991F621305f52BecF5fe0b2576"
"address": "0x3C1cd47E8D9aa563B238841B8D95c80d11E6B3A6"
},
{
"chainId": 5,
"address": "0x62631C37a91f35e8F50A90e9A0cf09B3f0eae150"
"address": "0xf4092f14f74E119fae5343d08C3A253FB9D2e8d6"
},
{
"chainId": 16,
"address": "0xc636a63001Ca975E409aa01E65e1982baaef41C2"
"address": "0x0896fB74CaBeDb603E3A6EdA36f40af00010Bf4c"
}
]
}

View File

@ -1,23 +1,28 @@
import { init, loadChains, writeOutputFiles, getMockIntegration } from "../helpers/env"
import {
init,
loadChains,
writeOutputFiles,
getMockIntegration,
Deployment,
} from "../helpers/env"
import { deployMockIntegration } from "../helpers/deployments"
import { BigNumber, BigNumberish, BytesLike } from "ethers"
import { tryNativeToHexString } from "@certusone/wormhole-sdk"
import { tryNativeToHexString, tryNativeToUint8Array } from "@certusone/wormhole-sdk"
import { MockRelayerIntegration__factory } from "../../../sdk/src"
import { wait } from "../helpers/utils"
const processName = "deployMockIntegration"
init()
const chains = loadChains().slice(0, 2)
const chains = loadChains()
async function run() {
console.log("Start!")
const output: any = {
mockIntegrations: [],
const output = {
mockIntegrations: [] as Deployment[],
}
for (let i = 0; i < chains.length; i++) {
const mockIntegration = await deployMockIntegration(chains[i])
output.mockIntegrations.push(mockIntegration)
}
@ -25,35 +30,17 @@ async function run() {
for (let i = 0; i < chains.length; i++) {
console.log(`Registering emitters for chainId ${chains[i].chainId}`)
// note: must use useLastRun = true
const mockIntegration = getMockIntegration(chains[i])
const arg: {
chainId: BigNumberish
addr: BytesLike
}[] = chains.flatMap((c, j) =>
j === i
? []
: [
{
chainId: c.chainId,
addr:
"0x" +
tryNativeToHexString(output.mockIntegrations[j].address, "ethereum"),
},
]
)
}[] = chains.map((c, j) => ({
chainId: c.chainId,
addr: "0x" + tryNativeToHexString(output.mockIntegrations[j].address, "ethereum"),
}))
await mockIntegration.registerEmitters(arg, { gasLimit: 500000 }).then(wait)
// for (let j = 0; j < chains.length; j++) {
// console.log(`Registering emitter ${chains[j].chainId}`)
// const secondMockIntegration = output.mockIntegrations[j]
// await mockIntegration
// .registerEmitter(
// secondMockIntegration.chainId,
// "0x" + tryNativeToHexString(secondMockIntegration.address, "ethereum"),
// { gasLimit: 500000 }
// )
// .then(wait)
// }
}
}

View File

@ -0,0 +1,64 @@
import { ChainInfo, init, loadChains } from "../helpers/env"
import { sendMessage, sleep } from "./messageUtils"
init()
const chains = loadChains()
async function run() {
const chainIntervalIdx = process.argv.findIndex((arg) => arg === "--chainInterval")
const salvoIntervalIdx = process.argv.findIndex((arg) => arg === "--salvoInterval")
const chainInterval =
chainIntervalIdx !== -1 ? Number(process.argv[chainIntervalIdx + 1]) : 5_000
const salvoInterval =
salvoIntervalIdx !== -1 ? Number(process.argv[salvoIntervalIdx + 1]) : 60_000
console.log(`chainInterval: ${chainInterval}`)
console.log(`salvoInterval: ${salvoInterval}`)
if (process.argv.find((arg) => arg === "--per-chain")) {
await perChain(chainInterval, salvoInterval)
} else {
await matrix(chainInterval, salvoInterval)
}
}
async function perChain(chainInterval: number, salvoInterval: number) {
console.log(`Sending test messages to and from each chain...`)
for (let salvo = 0; true; salvo++) {
console.log("")
console.log(`Sending salvo ${salvo}`)
for (let i = 0; i < chains.length; ++i) {
const j = i === 0 ? chains.length - 1 : 0
try {
await sendMessage(chains[i], chains[j], false, true)
} catch (e) {
console.error(e)
}
await sleep(chainInterval)
}
await sleep(salvoInterval)
}
}
async function matrix(chainInterval: number, salvoInterval: number) {
console.log(`Sending test messages to and from every combination of chains...`)
for (let salvo = 0; true; salvo++) {
console.log("")
console.log(`Sending salvo ${salvo}`)
for (let i = 0; i < chains.length; ++i) {
for (let j = 0; i < chains.length; ++i) {
try {
await sendMessage(chains[i], chains[j], false, true)
} catch (e) {
console.error(e)
}
await sleep(chainInterval)
}
}
await sleep(salvoInterval)
}
}
console.log("Start!")
run().then(() => console.log("Done!"))

View File

@ -1,111 +1,18 @@
import * as wh from "@certusone/wormhole-sdk"
import { Implementation__factory } from "@certusone/wormhole-sdk/lib/cjs/ethers-contracts"
import { LogMessagePublishedEvent } from "../../../sdk/src"
import {
ChainInfo,
getCoreRelayer,
getCoreRelayerAddress,
getMockIntegration,
getMockIntegrationAddress,
getRelayProviderAddress,
init,
loadChains,
} from "../helpers/env"
import * as grpcWebNodeHttpTransport from "@improbable-eng/grpc-web-node-http-transport"
import { sendMessage } from "./messageUtils"
init()
const chains = loadChains()
async function sendMessage(
sourceChain: ChainInfo,
targetChain: ChainInfo,
fetchSignedVaa: boolean = false,
queryMessageOnTarget: boolean = false
) {
console.log(
`Sending message from chain ${sourceChain.chainId} to ${targetChain.chainId}...`
)
const sourceRelayer = getCoreRelayer(sourceChain)
// todo: remove
const registeredChain = await sourceRelayer.registeredCoreRelayerContract(
sourceChain.chainId
)
console.log("The source chain should be registered to itself")
console.log(registeredChain)
console.log(getCoreRelayerAddress(sourceChain))
console.log("")
const defaultRelayerProvider = await sourceRelayer.getDefaultRelayProvider()
console.log("Default relay provider should be this chains relayProvider ")
console.log(defaultRelayerProvider)
console.log(getRelayProviderAddress(sourceChain))
console.log("")
const relayQuote = await (
await sourceRelayer.quoteGas(
targetChain.chainId,
2000000,
await sourceRelayer.getDefaultRelayProvider()
)
).add(10000000000)
console.log("relay quote: " + relayQuote)
const mockIntegration = getMockIntegration(sourceChain)
const targetAddress = getMockIntegrationAddress(targetChain)
const sentMessage = Buffer.from("Hello World: " + String(Math.ceil(Math.random() * 100)))
const tx = await mockIntegration.sendMessage(
sentMessage,
targetChain.chainId,
targetAddress,
{
gasLimit: 1000000,
value: relayQuote,
}
)
const rx = await tx.wait()
const sequences = wh.parseSequencesFromLogEth(rx, sourceChain.wormholeAddress)
console.log("Tx hash: ", rx.transactionHash)
console.log(`Sequences: ${sequences}`)
if (fetchSignedVaa) {
for (let i = 0; i < 120; i++) {
try {
const vaa1 = await fetchVaaFromLog(rx.logs[0], sourceChain.chainId)
console.log(vaa1)
const vaa2 = await fetchVaaFromLog(rx.logs[1], sourceChain.chainId)
console.log(vaa2)
break
} catch (e) {
console.error(`${i} seconds`)
if (i === 0) {
console.error(e)
}
}
await new Promise((resolve) => setTimeout(resolve, 1_000))
}
}
if (queryMessageOnTarget) {
await new Promise<void>((resolve) => setTimeout(() => resolve(), 5000))
const targetIntegration = getMockIntegration(targetChain)
const message = await targetIntegration.getMessage()
const messages = await targetIntegration.getMessages()
const messageHistory = await targetIntegration.getMessageHistory();
const messageParsed = Buffer.from(message, "hex").toString("utf-8")
console.log(`Sent message: ${sentMessage}`)
console.log(`Received message: ${message}`)
console.log(`Received messages: ${messages}`)
console.log(`Received messageHistory: ${messageHistory}`)
}
console.log("")
}
async function run() {
console.log(process.argv)
const fetchSignedVaa = !!process.argv.find((arg) => arg === "--fetchSignedVaa")
const queryMessageOnTarget = !!process.argv.find(
(arg) => arg === "--queryMessageOnTarget"
const queryMessageOnTarget = !process.argv.find(
(arg) => arg === "--noQueryMessageOnTarget"
)
if (process.argv[2] === "--from" && process.argv[4] === "--to") {
await sendMessage(
@ -152,35 +59,3 @@ function getChainById(id: number | string): ChainInfo {
console.log("Start!")
run().then(() => console.log("Done!"))
export async function encodeEmitterAddress(
myChainId: wh.ChainId,
emitterAddressStr: string
): Promise<string> {
if (myChainId === wh.CHAIN_ID_SOLANA || myChainId === wh.CHAIN_ID_PYTHNET) {
return wh.getEmitterAddressSolana(emitterAddressStr)
}
if (wh.isTerraChain(myChainId)) {
return wh.getEmitterAddressTerra(emitterAddressStr)
}
if (wh.isEVMChain(myChainId)) {
return wh.getEmitterAddressEth(emitterAddressStr)
}
throw new Error(`Unrecognized wormhole chainId ${myChainId}`)
}
function fetchVaaFromLog(bridgeLog: any, chainId: wh.ChainId): Promise<wh.SignedVaa> {
const iface = Implementation__factory.createInterface()
const log = iface.parseLog(bridgeLog) as unknown as LogMessagePublishedEvent
const sequence = log.args.sequence.toString()
const emitter = wh.tryNativeToHexString(log.args.sender, "ethereum")
return wh
.getSignedVAA(
"https://wormhole-v2-testnet-api.certus.one",
chainId,
emitter,
sequence,
{ transport: grpcWebNodeHttpTransport.NodeHttpTransport() }
)
.then((r) => r.vaaBytes)
}

View File

@ -0,0 +1,132 @@
import * as wh from "@certusone/wormhole-sdk"
import { Implementation__factory } from "@certusone/wormhole-sdk/lib/cjs/ethers-contracts"
import { LogMessagePublishedEvent } from "../../../sdk/src"
import {
ChainInfo,
getCoreRelayer,
getMockIntegration,
getMockIntegrationAddress,
} from "../helpers/env"
import * as grpcWebNodeHttpTransport from "@improbable-eng/grpc-web-node-http-transport"
import { ethers } from "ethers"
export async function sendMessage(
sourceChain: ChainInfo,
targetChain: ChainInfo,
fetchSignedVaa: boolean = false,
queryMessageOnTargetFlag: boolean = true
) {
console.log(
`Sending message from chain ${sourceChain.chainId} to ${targetChain.chainId}...`
)
const sourceRelayer = getCoreRelayer(sourceChain)
const relayQuote = await (
await sourceRelayer.quoteGas(
targetChain.chainId,
2000000,
await sourceRelayer.getDefaultRelayProvider()
)
).add(10000000000)
console.log("relay quote: " + relayQuote)
const mockIntegration = getMockIntegration(sourceChain)
const targetAddress = getMockIntegrationAddress(targetChain)
const sentMessage = "ID: " + String(Math.ceil(Math.random() * 10000))
console.log(`Sent message: ${sentMessage}`)
const tx = await mockIntegration.sendMessage(
Buffer.from(sentMessage),
targetChain.chainId,
targetAddress,
{
gasLimit: 1000000,
value: relayQuote,
}
)
const rx = await tx.wait()
const sequences = wh.parseSequencesFromLogEth(rx, sourceChain.wormholeAddress)
console.log("Tx hash: ", rx.transactionHash)
console.log(`Sequences: ${sequences}`)
if (fetchSignedVaa) {
for (let i = 0; i < 120; i++) {
try {
const vaa1 = await fetchVaaFromLog(rx.logs[0], sourceChain.chainId)
console.log(vaa1)
const vaa2 = await fetchVaaFromLog(rx.logs[1], sourceChain.chainId)
console.log(vaa2)
break
} catch (e) {
console.error(`${i} seconds`)
if (i === 0) {
console.error(e)
}
}
await new Promise((resolve) => setTimeout(resolve, 1_000))
}
}
if (queryMessageOnTargetFlag) {
await queryMessageOnTarget(sentMessage, targetChain)
}
console.log("")
}
async function queryMessageOnTarget(sentMessage: string, targetChain: ChainInfo) {
let messageHistory: string[][] = []
const targetIntegration = getMockIntegration(targetChain)
let notFound = true
for (let i = 0; i < 20 && notFound; i++) {
await new Promise<void>((resolve) => setTimeout(() => resolve(), 2000))
const messageHistoryResp = await targetIntegration.getMessageHistory()
messageHistory = messageHistoryResp.map((messages) =>
messages.map((message) => ethers.utils.toUtf8String(message))
)
notFound = !messageHistory
.slice(messageHistory.length - 20)
.find((msgs) => msgs.find((m) => m === sentMessage))
process.stdout.write("..")
}
console.log("")
console.log(`Received message: ${messageHistory[messageHistory.length - 1][0]}`)
console.log(`Received messageHistory: ${messageHistory.join(", ")}`)
}
export async function encodeEmitterAddress(
myChainId: wh.ChainId,
emitterAddressStr: string
): Promise<string> {
if (myChainId === wh.CHAIN_ID_SOLANA || myChainId === wh.CHAIN_ID_PYTHNET) {
return wh.getEmitterAddressSolana(emitterAddressStr)
}
if (wh.isTerraChain(myChainId)) {
return wh.getEmitterAddressTerra(emitterAddressStr)
}
if (wh.isEVMChain(myChainId)) {
return wh.getEmitterAddressEth(emitterAddressStr)
}
throw new Error(`Unrecognized wormhole chainId ${myChainId}`)
}
function fetchVaaFromLog(bridgeLog: any, chainId: wh.ChainId): Promise<wh.SignedVaa> {
const iface = Implementation__factory.createInterface()
const log = iface.parseLog(bridgeLog) as unknown as LogMessagePublishedEvent
const sequence = log.args.sequence.toString()
const emitter = wh.tryNativeToHexString(log.args.sender, "ethereum")
return wh
.getSignedVAA(
"https://wormhole-v2-testnet-api.certus.one",
chainId,
emitter,
sequence,
{ transport: grpcWebNodeHttpTransport.NodeHttpTransport() }
)
.then((r) => r.vaaBytes)
}
export async function sleep(ms: number) {
return new Promise((r) => setTimeout(r, ms))
}