From 7b637375c5d0524af4be918ae3026f4bcbead56c Mon Sep 17 00:00:00 2001 From: dantaik <99078276+dantaik@users.noreply.github.com> Date: Tue, 29 Nov 2022 13:13:03 +0800 Subject: [PATCH] chore(bridge): add a FAILED message status --- packages/protocol/contracts/L1/TaikoL1.sol | 9 ++++----- .../protocol/contracts/bridge/libs/LibBridgeData.sol | 3 ++- .../protocol/contracts/bridge/libs/LibBridgeRetry.sol | 5 ++++- packages/protocol/tasks/utils.ts | 1 + .../protocol/test/bridge/libs/LibBridgeData.test.ts | 7 +------ .../protocol/test/bridge/libs/LibBridgeProcess.test.ts | 8 +------- .../protocol/test/bridge/libs/LibBridgeRetry.test.ts | 10 ++-------- 7 files changed, 15 insertions(+), 28 deletions(-) diff --git a/packages/protocol/contracts/L1/TaikoL1.sol b/packages/protocol/contracts/L1/TaikoL1.sol index bfbe77bcf29..07c149d785d 100644 --- a/packages/protocol/contracts/L1/TaikoL1.sol +++ b/packages/protocol/contracts/L1/TaikoL1.sol @@ -237,11 +237,10 @@ contract TaikoL1 is EssentialContract, IHeaderSync, V1Events { return LibAnchorSignature.signTransaction(hash, k); } - function getBlockProvers(uint256 id, bytes32 parentHash) - public - view - returns (address[] memory) - { + function getBlockProvers( + uint256 id, + bytes32 parentHash + ) public view returns (address[] memory) { return state.forkChoices[id][parentHash].provers; } diff --git a/packages/protocol/contracts/bridge/libs/LibBridgeData.sol b/packages/protocol/contracts/bridge/libs/LibBridgeData.sol index 5eacfee1609..8f96058cc73 100644 --- a/packages/protocol/contracts/bridge/libs/LibBridgeData.sol +++ b/packages/protocol/contracts/bridge/libs/LibBridgeData.sol @@ -25,7 +25,8 @@ library LibBridgeData { enum MessageStatus { NEW, RETRIABLE, - DONE + DONE, + FAILED } struct State { diff --git a/packages/protocol/contracts/bridge/libs/LibBridgeRetry.sol b/packages/protocol/contracts/bridge/libs/LibBridgeRetry.sol index a0c118771d1..c15aea619f8 100644 --- a/packages/protocol/contracts/bridge/libs/LibBridgeRetry.sol +++ b/packages/protocol/contracts/bridge/libs/LibBridgeRetry.sol @@ -66,7 +66,10 @@ library LibBridgeRetry { ) { state.updateMessageStatus(signal, LibBridgeData.MessageStatus.DONE); } else if (isLastAttempt) { - state.updateMessageStatus(signal, LibBridgeData.MessageStatus.DONE); + state.updateMessageStatus( + signal, + LibBridgeData.MessageStatus.FAILED + ); address refundAddress = message.refundAddress == address(0) ? message.owner diff --git a/packages/protocol/tasks/utils.ts b/packages/protocol/tasks/utils.ts index 7c0a87a5e1e..8c2c948c00e 100644 --- a/packages/protocol/tasks/utils.ts +++ b/packages/protocol/tasks/utils.ts @@ -81,6 +81,7 @@ const MessageStatus = { NEW: 0, RETRIABLE: 1, DONE: 2, + FAILED: 3, } export { diff --git a/packages/protocol/test/bridge/libs/LibBridgeData.test.ts b/packages/protocol/test/bridge/libs/LibBridgeData.test.ts index 4409a8dcaed..84a633d1503 100644 --- a/packages/protocol/test/bridge/libs/LibBridgeData.test.ts +++ b/packages/protocol/test/bridge/libs/LibBridgeData.test.ts @@ -1,6 +1,7 @@ import { expect } from "chai" import { ethers } from "hardhat" import { TAIKO_BRIDGE_MESSAGE } from "../../constants/messages" +import { MessageStatus } from "../../../tasks/utils" describe("LibBridgeData", function () { async function deployLibBridgeDataFixture() { @@ -33,12 +34,6 @@ describe("LibBridgeData", function () { const testVar = [TAIKO_BRIDGE_MESSAGE, testMessage] - const MessageStatus = { - NEW: 0, - RETRIABLE: 1, - DONE: 2, - } - return { owner, nonOwner, diff --git a/packages/protocol/test/bridge/libs/LibBridgeProcess.test.ts b/packages/protocol/test/bridge/libs/LibBridgeProcess.test.ts index efebc4d9316..a05b9c458e8 100644 --- a/packages/protocol/test/bridge/libs/LibBridgeProcess.test.ts +++ b/packages/protocol/test/bridge/libs/LibBridgeProcess.test.ts @@ -3,7 +3,7 @@ import { expect } from "chai" import * as fs from "fs" import hre, { ethers } from "hardhat" import * as path from "path" -import { getSlot } from "../../../tasks/utils" +import { getSlot, MessageStatus } from "../../../tasks/utils" import { AddressManager, Bridge } from "../../../typechain" import { Message } from "../../utils/message" @@ -109,12 +109,6 @@ describe("LibBridgeProcess", function () { .connect(etherVaultOwner) .authorize(libProcess.address, true) - const MessageStatus = { - NEW: 0, - RETRIABLE: 1, - DONE: 2, - } - return { owner, srcChainId, diff --git a/packages/protocol/test/bridge/libs/LibBridgeRetry.test.ts b/packages/protocol/test/bridge/libs/LibBridgeRetry.test.ts index 8f0d50b8169..b67b2cc22d7 100644 --- a/packages/protocol/test/bridge/libs/LibBridgeRetry.test.ts +++ b/packages/protocol/test/bridge/libs/LibBridgeRetry.test.ts @@ -1,7 +1,7 @@ import * as helpers from "@nomicfoundation/hardhat-network-helpers" import { expect } from "chai" import hre, { ethers } from "hardhat" -import { decode, getSlot } from "../../../tasks/utils" +import { decode, getSlot, MessageStatus } from "../../../tasks/utils" import { Message } from "../../utils/message" describe("LibBridgeRetry", function () { @@ -73,12 +73,6 @@ describe("LibBridgeRetry", function () { await ethers.getContractFactory("TestLibBridgeData") ).deploy() - const MessageStatus = { - NEW: 0, - RETRIABLE: 1, - DONE: 2, - } - return { owner, refundAddress, @@ -276,7 +270,7 @@ describe("LibBridgeRetry", function () { getSlot(hre, signal, 202) ) ) - ).to.equal(MessageStatus.DONE.toString()) + ).to.equal(MessageStatus.FAILED.toString()) expect(balancePlusRefund).to.be.equal( originalBalance.add(message.callValue)