Skip to content

Commit

Permalink
feat(relayer): catch relayer & status page up to new testnet (#13114)
Browse files Browse the repository at this point in the history
  • Loading branch information
cyberhorsey authored Feb 8, 2023
1 parent 0bffeb0 commit 543f242
Show file tree
Hide file tree
Showing 15 changed files with 145 additions and 80 deletions.
2 changes: 2 additions & 0 deletions packages/relayer/.default.env
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ L1_BRIDGE_ADDRESS=0x3612E284D763f42f5E4CB72B1602b23DAEC3cA60
L2_BRIDGE_ADDRESS=0x0000777700000000000000000000000000000004
L1_TAIKO_ADDRESS=0x7B3AF414448ba906f02a1CA307C56c4ADFF27ce7
L2_TAIKO_ADDRESS=0x0000777700000000000000000000000000000001
L1_SIGNAL_SERVICE_ADDRESS=0x403cc7802725928652a3d116Bb1781005e2e76d3
L2_SIGNAL_SERVICE_ADDRESS=0x8BDa62dc6c0160Bce2C3a9360755dF030575985a
L1_RPC_URL=wss://l1ws.a1.taiko.xyz
L2_RPC_URL=wss://l2ws.a1.taiko.xyz
CONFIRMATIONS_BEFORE_PROCESSING=13
Expand Down
22 changes: 11 additions & 11 deletions packages/relayer/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,12 +198,12 @@ func makeIndexers(
RPCClient: l1RpcClient,
DestRPCClient: l2RpcClient,

ECDSAKey: os.Getenv("RELAYER_ECDSA_KEY"),
BridgeAddress: common.HexToAddress(os.Getenv("L1_BRIDGE_ADDRESS")),
DestBridgeAddress: common.HexToAddress(os.Getenv("L2_BRIDGE_ADDRESS")),
DestTaikoAddress: common.HexToAddress(os.Getenv("L2_TAIKO_ADDRESS")),
SrcTaikoAddress: common.HexToAddress(os.Getenv("L1_TAIKO_ADDRESS")),

ECDSAKey: os.Getenv("RELAYER_ECDSA_KEY"),
BridgeAddress: common.HexToAddress(os.Getenv("L1_BRIDGE_ADDRESS")),
DestBridgeAddress: common.HexToAddress(os.Getenv("L2_BRIDGE_ADDRESS")),
DestTaikoAddress: common.HexToAddress(os.Getenv("L2_TAIKO_ADDRESS")),
SrcTaikoAddress: common.HexToAddress(os.Getenv("L1_TAIKO_ADDRESS")),
SrcSignalServiceAddress: common.HexToAddress(os.Getenv("L1_SIGNAL_SERVICE_ADDRESS")),
BlockBatchSize: uint64(blockBatchSize),
NumGoroutines: numGoroutines,
SubscriptionBackoff: subscriptionBackoff,
Expand All @@ -227,11 +227,11 @@ func makeIndexers(
RPCClient: l2RpcClient,
DestRPCClient: l1RpcClient,

ECDSAKey: os.Getenv("RELAYER_ECDSA_KEY"),
BridgeAddress: common.HexToAddress(os.Getenv("L2_BRIDGE_ADDRESS")),
DestBridgeAddress: common.HexToAddress(os.Getenv("L1_BRIDGE_ADDRESS")),
DestTaikoAddress: common.HexToAddress(os.Getenv("L1_TAIKO_ADDRESS")),

ECDSAKey: os.Getenv("RELAYER_ECDSA_KEY"),
BridgeAddress: common.HexToAddress(os.Getenv("L2_BRIDGE_ADDRESS")),
DestBridgeAddress: common.HexToAddress(os.Getenv("L1_BRIDGE_ADDRESS")),
DestTaikoAddress: common.HexToAddress(os.Getenv("L1_TAIKO_ADDRESS")),
SrcSignalServiceAddress: common.HexToAddress(os.Getenv("L2_SIGNAL_SERVICE_ADDRESS")),
BlockBatchSize: uint64(blockBatchSize),
NumGoroutines: numGoroutines,
SubscriptionBackoff: subscriptionBackoff,
Expand Down
2 changes: 2 additions & 0 deletions packages/relayer/indexer/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ type NewServiceOpts struct {
DestBridgeAddress common.Address
SrcTaikoAddress common.Address
DestTaikoAddress common.Address
SrcSignalServiceAddress common.Address
BlockBatchSize uint64
NumGoroutines int
SubscriptionBackoff time.Duration
Expand Down Expand Up @@ -159,6 +160,7 @@ func NewService(opts NewServiceOpts) (*Service, error) {
SrcETHClient: opts.EthClient,
ProfitableOnly: opts.ProfitableOnly,
HeaderSyncIntervalSeconds: opts.HeaderSyncIntervalInSeconds,
SrcSignalServiceAddress: opts.SrcSignalServiceAddress,
})
if err != nil {
return nil, errors.Wrap(err, "message.NewProcessor")
Expand Down
4 changes: 2 additions & 2 deletions packages/relayer/message/process_message.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ func (p *Processor) ProcessMessage(

key := hex.EncodeToString(hashed)

encodedSignalProof, err := p.prover.EncodedSignalProof(ctx, p.rpc, event.Raw.Address, key, latestSyncedHeader)
encodedSignalProof, err := p.prover.EncodedSignalProof(ctx, p.rpc, p.srcSignalServiceAddress, key, latestSyncedHeader)
if err != nil {
log.Errorf("srcChainID: %v, destChainID: %v, txHash: %v: signal: %v, from: %v",
log.Errorf("srcChainID: %v, destChainID: %v, txHash: %v: msgHash: %v, from: %v",
event.Message.SrcChainId,
event.Message.DestChainId,
event.Raw.TxHash.Hex(),
Expand Down
15 changes: 9 additions & 6 deletions packages/relayer/message/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ type Processor struct {

mu *sync.Mutex

destNonce uint64
relayerAddr common.Address
confirmations uint64
destNonce uint64
relayerAddr common.Address
srcSignalServiceAddress common.Address
confirmations uint64

profitableOnly relayer.ProfitableOnly
headerSyncIntervalSeconds int64
Expand All @@ -50,6 +51,7 @@ type NewProcessorOpts struct {
EventRepo relayer.EventRepository
DestHeaderSyncer relayer.HeaderSyncer
RelayerAddress common.Address
SrcSignalServiceAddress common.Address
Confirmations uint64
ProfitableOnly relayer.ProfitableOnly
HeaderSyncIntervalSeconds int64
Expand Down Expand Up @@ -106,9 +108,10 @@ func NewProcessor(opts NewProcessorOpts) (*Processor, error) {

mu: &sync.Mutex{},

destNonce: 0,
relayerAddr: opts.RelayerAddress,
confirmations: opts.Confirmations,
destNonce: 0,
relayerAddr: opts.RelayerAddress,
srcSignalServiceAddress: opts.SrcSignalServiceAddress,
confirmations: opts.Confirmations,

profitableOnly: opts.ProfitableOnly,
headerSyncIntervalSeconds: opts.HeaderSyncIntervalSeconds,
Expand Down
10 changes: 5 additions & 5 deletions packages/relayer/proof/encoded_signal_proof.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (
func (p *Prover) EncodedSignalProof(
ctx context.Context,
caller relayer.Caller,
bridgeAddress common.Address,
signalServiceAddress common.Address,
key string,
blockHash common.Hash,
) ([]byte, error) {
Expand All @@ -28,7 +28,7 @@ func (p *Prover) EncodedSignalProof(
return nil, errors.Wrap(err, "p.blockHeader")
}

encodedStorageProof, err := p.encodedStorageProof(ctx, caller, bridgeAddress, key, blockHeader.Height.Int64())
encodedStorageProof, err := p.encodedStorageProof(ctx, caller, signalServiceAddress, key, blockHeader.Height.Int64())
if err != nil {
return nil, errors.Wrap(err, "p.getEncodedStorageProof")
}
Expand All @@ -52,18 +52,18 @@ func (p *Prover) EncodedSignalProof(
func (p *Prover) encodedStorageProof(
ctx context.Context,
c relayer.Caller,
bridgeAddress common.Address,
signalServiceAddress common.Address,
key string,
blockNumber int64,
) ([]byte, error) {
var ethProof StorageProof

log.Infof("getting proof for: %v, key: %v, blockNum: %v", bridgeAddress, key, blockNumber)
log.Infof("getting proof for: %v, key: %v, blockNum: %v", signalServiceAddress, key, blockNumber)

err := c.CallContext(ctx,
&ethProof,
"eth_getProof",
bridgeAddress,
signalServiceAddress,
[]string{key},
hexutil.EncodeBig(new(big.Int).SetInt64(blockNumber)),
)
Expand Down
1 change: 1 addition & 0 deletions packages/status-page/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import { ethers } from "ethers";
setupI18n({ withLocale: "en" });
console.log(import.meta.env.VITE_L1_RPC_URL);
const l1Provider = new ethers.providers.JsonRpcProvider(
import.meta.env.VITE_L1_RPC_URL
);
Expand Down
2 changes: 1 addition & 1 deletion packages/status-page/src/components/StatusIndicator.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
statusValue = 0;
}
} catch (e) {
console.error(e);
console.error(header, e);
}
if (watchStatusFunc) {
Expand Down
4 changes: 2 additions & 2 deletions packages/status-page/src/domain/status.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { ethers } from "ethers";
import type { BigNumber, ethers } from "ethers";

type Status = string | number | boolean;
type Status = string | number | boolean | BigNumber;

type StatusIndicatorProp = {
statusFunc?: (
Expand Down
135 changes: 91 additions & 44 deletions packages/status-page/src/pages/home/Home.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script lang="ts">
import { BigNumber, ethers } from "ethers";
import { BigNumber, Contract, ethers } from "ethers";
import { getLatestSyncedHeader } from "../../utils/getLatestSyncedHeader";
import StatusIndicator from "../../components/StatusIndicator.svelte";
import { watchHeaderSynced } from "../../utils/watchHeaderSynced";
Expand All @@ -15,8 +15,9 @@
import { onMount } from "svelte";
import { getProofReward } from "../../utils/getProofReward";
import type { Status, StatusIndicatorProp } from "../../domain/status";
import { getConfig } from "../../utils/getConfig";
import { getStateVariables } from "../../utils/getStateVariables";
import { truncateString } from "../../utils/truncateString";
import TaikoL1 from "../../constants/abi/TaikoL1";
export let l1Provider: ethers.providers.JsonRpcProvider;
export let l1TaikoAddress: string;
Expand Down Expand Up @@ -176,88 +177,134 @@
onMount(async () => {
try {
const config = await getConfig(l1Provider, l1TaikoAddress);
if (!Object.hasOwn(config, "enableTokenomics")) return;
if (config.enableTokenomics) {
statusIndicators.push({
statusFunc: getBlockFee,
watchStatusFunc: null,
provider: l1Provider,
contractAddress: l1TaikoAddress,
header: "Block Fee",
intervalInMs: 15000,
colorFunc: null,
tooltip:
"The current fee to propose a block to the TaikoL1 smart contract.",
});
statusIndicators.push({
statusFunc: getBlockFee,
watchStatusFunc: null,
provider: l1Provider,
contractAddress: l1TaikoAddress,
header: "Block Fee",
intervalInMs: 15000,
colorFunc: function (status: Status) {
return "green"; // todo: whats green, yellow, red?
},
tooltip:
"The current fee to propose a block to the TaikoL1 smart contract.",
});
statusIndicators.push({
statusFunc: getProofReward,
watchStatusFunc: null,
provider: l1Provider,
contractAddress: l1TaikoAddress,
header: "Proof Reward",
intervalInMs: 15000,
colorFunc: null,
tooltip:
"The current reward for successfully submitting a proof for a proposed block on the TaikoL1 smart contract.",
});
}
statusIndicators.push({
statusFunc: getProofReward,
watchStatusFunc: null,
provider: l1Provider,
contractAddress: l1TaikoAddress,
header: "Proof Reward",
intervalInMs: 15000,
colorFunc: function (status: Status) {
return "green"; // todo: whats green, yellow, red?
},
tooltip:
"The current reward for successfully submitting a proof for a proposed block on the TaikoL1 smart contract.",
});
} catch (e) {
console.error(e);
}
try {
const stateVars = await getStateVariables(l1Provider, l1TaikoAddress);
// TODO: remove. this check prevents this code from running before we deploy next testnet
// since the state vars have had large changes.
if (stateVars.length < 10) {
return;
}
statusIndicators.push({
status: stateVars[4],
provider: l1Provider,
contractAddress: l1TaikoAddress,
header: "Latest Proposal",
intervalInMs: 0,
intervalInMs: 5 * 1000,
statusFunc: async (
provider: ethers.providers.JsonRpcProvider,
address: string
) => {
const stateVars = await getStateVariables(provider, address);
return new Date(
stateVars.lastProposedAt.toNumber() * 1000
).toString();
},
colorFunc: function (status: Status) {
return "green"; // todo: whats green, yellow, red?
},
tooltip: "The most recent block proposal on TaikoL1 contract.",
});
statusIndicators.push({
status: stateVars[9],
provider: l1Provider,
contractAddress: l1TaikoAddress,
header: "Average Proof Time",
header: "Latest Proof",
intervalInMs: 0,
colorFunc: null,
status: "0",
watchStatusFunc: async (
provider: ethers.providers.JsonRpcProvider,
address: string,
onEvent: (value: Status) => void
) => {
const contract = new Contract(address, TaikoL1, provider);
contract.on("BlockProven", (id, parentHash, blockHash, timestamp) => {
console.log("block proven", timestamp);
onEvent(new Date(timestamp).toString());
});
},
colorFunc: function (status: Status) {
return "green"; // todo: whats green, yellow, red?
},
tooltip: "The most recent block proof submitted on TaikoL1 contract.",
});
statusIndicators.push({
provider: l1Provider,
contractAddress: l1TaikoAddress,
statusFunc: async (
provider: ethers.providers.JsonRpcProvider,
address: string
) => {
const stateVars = await getStateVariables(provider, address);
return stateVars.avgProofTime.toNumber();
},
colorFunc: function (status: Status) {
return "green"; // todo: whats green, yellow, red?
},
header: "Average Proof Time",
intervalInMs: 5 * 1000,
tooltip:
"The current average proof time, updated when a block is successfully proven.",
});
statusIndicators.push({
status: stateVars[9],
provider: l1Provider,
contractAddress: l1TaikoAddress,
header: "Average Block Time",
intervalInMs: 0,
intervalInMs: 5 * 1000,
colorFunc: function (status: Status) {
return "green"; // todo: whats green, yellow, red?
},
statusFunc: async (
provider: ethers.providers.JsonRpcProvider,
address: string
) => {
const stateVars = await getStateVariables(provider, address);
return stateVars.avgBlockTime.toNumber();
},
tooltip:
"The current average block time, updated when a block is successfully proposed.",
});
statusIndicators.push({
status: `${ethers.utils.parseEther(stateVars[3])} ${feeTokenSymbol}`,
provider: l1Provider,
contractAddress: l1TaikoAddress,
header: "Fee Base",
intervalInMs: 0,
statusFunc: async (
provider: ethers.providers.JsonRpcProvider,
address: string
) => {
const stateVars = await getStateVariables(provider, address);
return `${truncateString(
ethers.utils.formatEther(stateVars.feeBase),
6
)} ${feeTokenSymbol}`;
},
colorFunc: function (status: Status) {
return "green"; // todo: whats green, yellow, red?
},
Expand Down
3 changes: 2 additions & 1 deletion packages/status-page/src/utils/displayStatusValue.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { ethers } from "ethers";
import type { Status } from "src/domain/status";

export const displayStatusValue = (value: string | number | boolean) => {
export const displayStatusValue = (value: Status) => {
if (typeof value === "string") {
if (!value) return "0x";
if (ethers.utils.isHexString(value)) {
Expand Down
6 changes: 3 additions & 3 deletions packages/status-page/src/utils/getBlockFee.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { Contract, ethers } from "ethers";
import { BigNumber, Contract, ethers } from "ethers";
import TaikoL1 from "../constants/abi/TaikoL1";

export const getBlockFee = async (
provider: ethers.providers.JsonRpcProvider,
contractAddress: string
): Promise<number> => {
): Promise<string> => {
const contract: Contract = new Contract(contractAddress, TaikoL1, provider);
const fee = await contract.getBlockFee();
return fee;
return ethers.utils.formatEther(fee);
};
2 changes: 1 addition & 1 deletion packages/status-page/src/utils/getConfig.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BigNumber, Contract, ethers } from "ethers";
import { Contract, ethers } from "ethers";
import TaikoL1 from "../constants/abi/TaikoL1";

export const getConfig = async (
Expand Down
Loading

0 comments on commit 543f242

Please sign in to comment.