From 86cdd279b99a899e269a1f10b43f7a848f640c0d Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Tue, 30 May 2023 18:30:59 -0700 Subject: [PATCH 1/7] show latest proof reward --- .../src/components/StatusIndicator.svelte | 1 + packages/status-page/src/domain/status.ts | 2 +- .../src/utils/buildStatusIndicators.ts | 39 +++++++++---------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/packages/status-page/src/components/StatusIndicator.svelte b/packages/status-page/src/components/StatusIndicator.svelte index db27b3ff5f7..96c69f7a3aa 100644 --- a/packages/status-page/src/components/StatusIndicator.svelte +++ b/packages/status-page/src/components/StatusIndicator.svelte @@ -58,6 +58,7 @@ } if (watchStatusFunc) { + statusValue = "Waiting for event..."; cancelFunc = watchStatusFunc( provider, contractAddress, diff --git a/packages/status-page/src/domain/status.ts b/packages/status-page/src/domain/status.ts index c09f82b8bc4..5610cbbbf97 100644 --- a/packages/status-page/src/domain/status.ts +++ b/packages/status-page/src/domain/status.ts @@ -11,7 +11,7 @@ type StatusIndicatorProp = { provider: ethers.providers.JsonRpcProvider, contractAddress: string, onEvent: (value: Status) => void - ) => () => void; + ) => Promise<() => void>; provider: ethers.providers.JsonRpcProvider; contractAddress: string; header: string; diff --git a/packages/status-page/src/utils/buildStatusIndicators.ts b/packages/status-page/src/utils/buildStatusIndicators.ts index 41c5fbb866b..9421f9710f2 100644 --- a/packages/status-page/src/utils/buildStatusIndicators.ts +++ b/packages/status-page/src/utils/buildStatusIndicators.ts @@ -310,33 +310,28 @@ export async function buildStatusIndicators( "The current fee to propose a block to the TaikoL1 smart contract.", }); indicators.push({ - statusFunc: async ( + watchStatusFunc: async ( provider: ethers.providers.JsonRpcProvider, - contractAddress: string - ): Promise => { - const contract: Contract = new Contract( - contractAddress, - TaikoL1, - provider - ); - const averageProofTime = await getAverageProofTime( - config.eventIndexerApiUrl - ); - const fee = await contract.getProofReward(Number(averageProofTime)); - return `${ethers.utils.formatUnits(fee, decimals)} ${ - import.meta.env.VITE_FEE_TOKEN_SYMBOL ?? "TKO" - }`; + address: string, + onEvent: (value: Status) => void + ) => { + const contract = new Contract(address, TaikoL1, provider); + const listener = (id, blockHash, reward, ...args) => { + onEvent(`${ethers.utils.parseUnits(reward, decimals)} TKO`); + }; + contract.on("BlockVerified", listener); + + return () => contract.off("BlockVerified", listener); }, - watchStatusFunc: null, provider: config.l1Provider, contractAddress: config.l1TaikoAddress, - header: "Proof Reward", - intervalInMs: 15000, + header: "Latest Proof Reward", + intervalInMs: 0, + status: "Waiting for event...", 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, given the proof time is equal to average proof time.", + tooltip: "The most recent proof reward, updated on block being verified.", }); indicators.push({ provider: config.l1Provider, @@ -368,7 +363,9 @@ export async function buildStatusIndicators( }; contract.on("BlockProven", listener); - return () => contract.off("BlockProven", listener); + return () => { + contract.off("BlockProven", listener); + }; }, colorFunc: function (status: Status) { return "green"; // todo: whats green, yellow, red? From 893bd9de7fc8dc4cbbd1db2973fda80374ada6dd Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Tue, 30 May 2023 18:36:35 -0700 Subject: [PATCH 2/7] string --- packages/status-page/src/utils/buildStatusIndicators.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/status-page/src/utils/buildStatusIndicators.ts b/packages/status-page/src/utils/buildStatusIndicators.ts index 9421f9710f2..6cfe99ee708 100644 --- a/packages/status-page/src/utils/buildStatusIndicators.ts +++ b/packages/status-page/src/utils/buildStatusIndicators.ts @@ -317,7 +317,9 @@ export async function buildStatusIndicators( ) => { const contract = new Contract(address, TaikoL1, provider); const listener = (id, blockHash, reward, ...args) => { - onEvent(`${ethers.utils.parseUnits(reward, decimals)} TKO`); + onEvent( + `${ethers.utils.parseUnits(reward.toString(), decimals)} TKO` + ); }; contract.on("BlockVerified", listener); From 4da83ff60959edc33382f57bdf8a96a5d4de5d85 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Tue, 30 May 2023 18:39:22 -0700 Subject: [PATCH 3/7] Fix --- packages/status-page/src/components/StatusIndicator.svelte | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/status-page/src/components/StatusIndicator.svelte b/packages/status-page/src/components/StatusIndicator.svelte index 96c69f7a3aa..9f289e9d245 100644 --- a/packages/status-page/src/components/StatusIndicator.svelte +++ b/packages/status-page/src/components/StatusIndicator.svelte @@ -58,7 +58,9 @@ } if (watchStatusFunc) { - statusValue = "Waiting for event..."; + if (!statusFunc) { + statusValue = "Waiting for event..."; + } cancelFunc = watchStatusFunc( provider, contractAddress, From 3cd655b446d50bce3c357acdc62f60cbf473f0d0 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Tue, 30 May 2023 18:49:00 -0700 Subject: [PATCH 4/7] get most recent one --- .../src/utils/buildStatusIndicators.ts | 33 +++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/packages/status-page/src/utils/buildStatusIndicators.ts b/packages/status-page/src/utils/buildStatusIndicators.ts index 6cfe99ee708..33b84380a60 100644 --- a/packages/status-page/src/utils/buildStatusIndicators.ts +++ b/packages/status-page/src/utils/buildStatusIndicators.ts @@ -310,6 +310,36 @@ export async function buildStatusIndicators( "The current fee to propose a block to the TaikoL1 smart contract.", }); indicators.push({ + statusFunc: async ( + provider: ethers.providers.JsonRpcProvider, + contractAddress: string + ): Promise => { + const contract: Contract = new Contract( + contractAddress, + TaikoL1, + provider + ); + const latestBlockNumber = await provider.getBlockNumber(); + const eventFilter = contract.filters.BlockVerified(); + const events = await contract.queryFilter( + eventFilter, + latestBlockNumber - 200, + latestBlockNumber + ); + + if (!events || events.length === 0) { + return `0 TKO`; + } + + const event = events[events.length - 1].args as any as { + reward: BigNumber; + }; + + return `${ethers.utils.formatUnits( + event.reward.toString(), + decimals + )} TKO`; + }, watchStatusFunc: async ( provider: ethers.providers.JsonRpcProvider, address: string, @@ -318,7 +348,7 @@ export async function buildStatusIndicators( const contract = new Contract(address, TaikoL1, provider); const listener = (id, blockHash, reward, ...args) => { onEvent( - `${ethers.utils.parseUnits(reward.toString(), decimals)} TKO` + `${ethers.utils.formatUnits(reward.toString(), decimals)} TKO` ); }; contract.on("BlockVerified", listener); @@ -329,7 +359,6 @@ export async function buildStatusIndicators( contractAddress: config.l1TaikoAddress, header: "Latest Proof Reward", intervalInMs: 0, - status: "Waiting for event...", colorFunc: function (status: Status) { return "green"; // todo: whats green, yellow, red? }, From c38ac3497f3bb1fe3c8fa94f7db30f3ac95325d1 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Tue, 30 May 2023 19:05:09 -0700 Subject: [PATCH 5/7] change last proof from timestamp, to show the proof time --- .../src/utils/buildStatusIndicators.ts | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/status-page/src/utils/buildStatusIndicators.ts b/packages/status-page/src/utils/buildStatusIndicators.ts index 33b84380a60..63f8865e85b 100644 --- a/packages/status-page/src/utils/buildStatusIndicators.ts +++ b/packages/status-page/src/utils/buildStatusIndicators.ts @@ -367,7 +367,7 @@ export async function buildStatusIndicators( indicators.push({ provider: config.l1Provider, contractAddress: config.l1TaikoAddress, - header: "Latest Proof", + header: "Latest Proof Time", intervalInMs: 0, status: "0", watchStatusFunc: async ( @@ -376,20 +376,26 @@ export async function buildStatusIndicators( onEvent: (value: Status) => void ) => { const contract = new Contract(address, TaikoL1, provider); - const listener = ( + const listener = async ( id, parentHash, blockHash, signalRoot, prover, - provenAt, - ...args + parentGasUsed, + event ) => { + console.log(event); // ignore oracle prover if ( prover.toLowerCase() !== config.oracleProverAddress.toLowerCase() ) { - onEvent(new Date(provenAt).toTimeString()); + const proposedBlock = await contract.getBlock(id); + const block = await event.getBlock(); + const proofTime = + block.timestamp - proposedBlock._proposedAt.toNumber(); + + onEvent(`${proofTime} seconds`); } }; contract.on("BlockProven", listener); From 6ceff1690253f8dc08ab77f3e5ab7646dbb575d9 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Tue, 30 May 2023 19:07:49 -0700 Subject: [PATCH 6/7] ignore system proof --- packages/status-page/src/utils/buildStatusIndicators.ts | 3 ++- packages/status-page/src/utils/initConfig.ts | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/status-page/src/utils/buildStatusIndicators.ts b/packages/status-page/src/utils/buildStatusIndicators.ts index 63f8865e85b..1511e93eca1 100644 --- a/packages/status-page/src/utils/buildStatusIndicators.ts +++ b/packages/status-page/src/utils/buildStatusIndicators.ts @@ -388,7 +388,8 @@ export async function buildStatusIndicators( console.log(event); // ignore oracle prover if ( - prover.toLowerCase() !== config.oracleProverAddress.toLowerCase() + prover.toLowerCase() !== config.oracleProverAddress.toLowerCase() && + prover.toLowerCase() !== config.systemProverAddress.toLowerCase() ) { const proposedBlock = await contract.getBlock(id); const block = await event.getBlock(); diff --git a/packages/status-page/src/utils/initConfig.ts b/packages/status-page/src/utils/initConfig.ts index c41977445ec..49a48502bb8 100644 --- a/packages/status-page/src/utils/initConfig.ts +++ b/packages/status-page/src/utils/initConfig.ts @@ -30,7 +30,10 @@ export function initConfig(layer: Layer) { const feeTokenSymbol = import.meta.env.VITE_FEE_TOKEN_SYMBOL || "TKO"; const oracleProverAddress = import.meta.env.ORACLE_PROVER_ADDRESS || - "0x1567CDAb5F7a69154e61A16D8Ff5eE6A3e991b39"; + "0x0000000000000000000000000000000000000000"; + const systemProverAddress = + import.meta.env.SYSTEM_PROVER_ADDRESS || + "0x0000000000000000000000000000000000000001"; const eventIndexerApiUrl = layer === Layer.Two ? import.meta.env.VITE_L2_EVENT_INDEXER_API_URL @@ -46,5 +49,6 @@ export function initConfig(layer: Layer) { feeTokenSymbol, oracleProverAddress, eventIndexerApiUrl, + systemProverAddress, }; } From 26e742d17ec4a6523e7f6ec76c53d2a385dfbcb3 Mon Sep 17 00:00:00 2001 From: Jeffery Walsh Date: Tue, 30 May 2023 19:14:21 -0700 Subject: [PATCH 7/7] add latest system proof --- .../src/utils/buildStatusIndicators.ts | 42 ++++++++++++++++++- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/packages/status-page/src/utils/buildStatusIndicators.ts b/packages/status-page/src/utils/buildStatusIndicators.ts index 1511e93eca1..02ec3df2d73 100644 --- a/packages/status-page/src/utils/buildStatusIndicators.ts +++ b/packages/status-page/src/utils/buildStatusIndicators.ts @@ -385,8 +385,6 @@ export async function buildStatusIndicators( parentGasUsed, event ) => { - console.log(event); - // ignore oracle prover if ( prover.toLowerCase() !== config.oracleProverAddress.toLowerCase() && prover.toLowerCase() !== config.systemProverAddress.toLowerCase() @@ -410,6 +408,46 @@ export async function buildStatusIndicators( }, tooltip: "The most recent block proof submitted on TaikoL1 contract.", }); + indicators.push({ + provider: config.l1Provider, + contractAddress: config.l1TaikoAddress, + header: "Latest System Proof", + intervalInMs: 0, + status: "0", + watchStatusFunc: async ( + provider: ethers.providers.JsonRpcProvider, + address: string, + onEvent: (value: Status) => void + ) => { + const contract = new Contract(address, TaikoL1, provider); + const listener = async ( + id, + parentHash, + blockHash, + signalRoot, + prover, + parentGasUsed, + event + ) => { + if ( + prover.toLowerCase() === config.systemProverAddress.toLowerCase() + ) { + const block = await event.getBlock(); + + onEvent(`${new Date(block.timestamp * 1000).toUTCString()}`); + } + }; + contract.on("BlockProven", listener); + + return () => { + contract.off("BlockProven", listener); + }; + }, + colorFunc: function (status: Status) { + return "green"; // todo: whats green, yellow, red? + }, + tooltip: "The timestamp of the latest system proof", + }); indicators.push({ provider: config.l1Provider,