From 10be2fbe57b154909c99818ac8f2196276541a9b Mon Sep 17 00:00:00 2001 From: D <51912515+adaki2004@users.noreply.github.com> Date: Wed, 24 May 2023 21:35:59 +0200 Subject: [PATCH] feat(protocol): Add reward and fee fields to events (#13808) Co-authored-by: adaki2004 --- packages/protocol/contracts/L1/TaikoEvents.sol | 4 ++-- packages/protocol/contracts/L1/libs/LibProposing.sol | 11 ++++++----- packages/protocol/contracts/L1/libs/LibVerifying.sol | 6 +++--- .../contract-documentation/L1/TaikoEvents.md | 4 ++-- 4 files changed, 13 insertions(+), 12 deletions(-) diff --git a/packages/protocol/contracts/L1/TaikoEvents.sol b/packages/protocol/contracts/L1/TaikoEvents.sol index a0d6cb864a9..8b62a08ab07 100644 --- a/packages/protocol/contracts/L1/TaikoEvents.sol +++ b/packages/protocol/contracts/L1/TaikoEvents.sol @@ -10,7 +10,7 @@ import {TaikoData} from "./TaikoData.sol"; abstract contract TaikoEvents { // The following events must match the definitions in corresponding L1 libraries. - event BlockProposed(uint256 indexed id, TaikoData.BlockMetadata meta); + event BlockProposed(uint256 indexed id, TaikoData.BlockMetadata meta, uint64 blockFee); event BlockProven( uint256 indexed id, @@ -21,7 +21,7 @@ abstract contract TaikoEvents { uint32 parentGasUsed ); - event BlockVerified(uint256 indexed id, bytes32 blockHash); + event BlockVerified(uint256 indexed id, bytes32 blockHash, uint64 reward); event EthDeposited(TaikoData.EthDeposit deposit); diff --git a/packages/protocol/contracts/L1/libs/LibProposing.sol b/packages/protocol/contracts/L1/libs/LibProposing.sol index 056e3996f75..794d34692d7 100644 --- a/packages/protocol/contracts/L1/libs/LibProposing.sol +++ b/packages/protocol/contracts/L1/libs/LibProposing.sol @@ -20,7 +20,7 @@ library LibProposing { using LibAddress for address payable; using LibUtils for TaikoData.State; - event BlockProposed(uint256 indexed id, TaikoData.BlockMetadata meta); + event BlockProposed(uint256 indexed id, TaikoData.BlockMetadata meta, uint64 blockFee); error L1_BLOCK_ID(); error L1_INSUFFICIENT_TOKEN(); @@ -78,17 +78,18 @@ library LibProposing { blk.metaHash = LibUtils.hashMetadata(meta); blk.proposer = msg.sender; - if (state.taikoTokenBalances[msg.sender] < state.blockFee) { + uint64 blockFee = state.blockFee; + if (state.taikoTokenBalances[msg.sender] < blockFee) { revert L1_INSUFFICIENT_TOKEN(); } unchecked { - state.taikoTokenBalances[msg.sender] -= state.blockFee; - state.accBlockFees += state.blockFee; + state.taikoTokenBalances[msg.sender] -= blockFee; + state.accBlockFees += blockFee; state.accProposedAt += meta.timestamp; } - emit BlockProposed(state.numBlocks, meta); + emit BlockProposed(state.numBlocks, meta, blockFee); unchecked { ++state.numBlocks; } diff --git a/packages/protocol/contracts/L1/libs/LibVerifying.sol b/packages/protocol/contracts/L1/libs/LibVerifying.sol index 57042b16a5c..aa9f93a4719 100644 --- a/packages/protocol/contracts/L1/libs/LibVerifying.sol +++ b/packages/protocol/contracts/L1/libs/LibVerifying.sol @@ -18,7 +18,7 @@ library LibVerifying { using SafeCastUpgradeable for uint256; using LibUtils for TaikoData.State; - event BlockVerified(uint256 indexed id, bytes32 blockHash); + event BlockVerified(uint256 indexed id, bytes32 blockHash, uint64 reward); event CrossChainSynced(uint256 indexed srcHeight, bytes32 blockHash, bytes32 signalRoot); @@ -65,7 +65,7 @@ library LibVerifying { fc.blockHash = genesisBlockHash; fc.provenAt = timeNow; - emit BlockVerified(0, genesisBlockHash); + emit BlockVerified(0, genesisBlockHash, 0); } function verifyBlocks( @@ -183,6 +183,6 @@ library LibVerifying { blk.nextForkChoiceId = 1; blk.verifiedForkChoiceId = fcId; - emit BlockVerified(blk.blockId, fc.blockHash); + emit BlockVerified(blk.blockId, fc.blockHash, reward); } } diff --git a/packages/website/pages/docs/reference/contract-documentation/L1/TaikoEvents.md b/packages/website/pages/docs/reference/contract-documentation/L1/TaikoEvents.md index c5b4964c07b..1f0ea94cc1e 100644 --- a/packages/website/pages/docs/reference/contract-documentation/L1/TaikoEvents.md +++ b/packages/website/pages/docs/reference/contract-documentation/L1/TaikoEvents.md @@ -7,7 +7,7 @@ title: TaikoEvents ### BlockProposed ```solidity -event BlockProposed(uint256 id, struct TaikoData.BlockMetadata meta) +event BlockProposed(uint256 id, struct TaikoData.BlockMetadata meta, uint64 blockFee) ``` ### BlockProven @@ -19,7 +19,7 @@ event BlockProven(uint256 id, bytes32 parentHash, bytes32 blockHash, bytes32 sig ### BlockVerified ```solidity -event BlockVerified(uint256 id, bytes32 blockHash) +event BlockVerified(uint256 id, bytes32 blockHash, uint64 reward) ``` ### EthDeposited