Skip to content

Commit

Permalink
feat(protocol): Add reward and fee fields to events (#13808)
Browse files Browse the repository at this point in the history
Co-authored-by: adaki2004 <[email protected]>
  • Loading branch information
adaki2004 and adaki2004 authored May 24, 2023
1 parent 6f9f022 commit 10be2fb
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
4 changes: 2 additions & 2 deletions packages/protocol/contracts/L1/TaikoEvents.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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);

Expand Down
11 changes: 6 additions & 5 deletions packages/protocol/contracts/L1/libs/LibProposing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions packages/protocol/contracts/L1/libs/LibVerifying.sol
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -65,7 +65,7 @@ library LibVerifying {
fc.blockHash = genesisBlockHash;
fc.provenAt = timeNow;

emit BlockVerified(0, genesisBlockHash);
emit BlockVerified(0, genesisBlockHash, 0);
}

function verifyBlocks(
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 10be2fb

Please sign in to comment.