Commit da9bcf53 authored by clabby's avatar clabby

Add event to block oracle checkpoint

parent 9beb8626
This diff is collapsed.
...@@ -13,7 +13,7 @@ const BlockOracleStorageLayoutJSON = "{\"storage\":[{\"astId\":1000,\"contract\" ...@@ -13,7 +13,7 @@ const BlockOracleStorageLayoutJSON = "{\"storage\":[{\"astId\":1000,\"contract\"
var BlockOracleStorageLayout = new(solc.StorageLayout) var BlockOracleStorageLayout = new(solc.StorageLayout)
var BlockOracleDeployedBin = "0x608060405234801561001057600080fd5b50600436106100365760003560e01c806399d548aa1461003b578063c2c4c5c114610078575b600080fd5b61004e610049366004610184565b61008e565b604080518251815260209283015167ffffffffffffffff1692810192909252015b60405180910390f35b61008061010d565b60405190815260200161006f565b604080518082018252600080825260209182018190528381528082528281208351808501909452805480855260019091015467ffffffffffffffff169284019290925203610108576040517f37cf270500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b919050565b600061011a60014361019d565b604080518082018252824081524267ffffffffffffffff908116602080840191825260008681529081905293909320915182559151600190910180547fffffffffffffffffffffffffffffffffffffffffffffffff00000000000000001691909216179055919050565b60006020828403121561019657600080fd5b5035919050565b6000828210156101d6577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b50039056fea164736f6c634300080f000a" var BlockOracleDeployedBin = "0x608060405234801561001057600080fd5b50600436106100365760003560e01c806399d548aa1461003b578063c2c4c5c114610078575b600080fd5b61004e6100493660046101b8565b61008e565b604080518251815260209283015167ffffffffffffffff1692810192909252015b60405180910390f35b61008061010d565b60405190815260200161006f565b604080518082018252600080825260209182018190528381528082528281208351808501909452805480855260019091015467ffffffffffffffff169284019290925203610108576040517f37cf270500000000000000000000000000000000000000000000000000000000815260040160405180910390fd5b919050565b600061011a6001436101d1565b60408051808201825282408082524267ffffffffffffffff81811660208086018281526000898152918290528782209651875551600190960180547fffffffffffffffffffffffffffffffffffffffffffffffff000000000000000016969093169590951790915593519495509093909291849186917fb67ff58b33060fd371a35ae2d9f1c3cdaec9b8197969f6efe2594a1ff4ba68c691a4505090565b6000602082840312156101ca57600080fd5b5035919050565b60008282101561020a577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b50039056fea164736f6c634300080f000a"
func init() { func init() {
if err := json.Unmarshal([]byte(BlockOracleStorageLayoutJSON), BlockOracleStorageLayout); err != nil { if err := json.Unmarshal([]byte(BlockOracleStorageLayoutJSON), BlockOracleStorageLayout); err != nil {
......
...@@ -16,7 +16,7 @@ AssetReceiverTest:test_withdrawETHwithAmount_unauthorized_reverts() (gas: 10738) ...@@ -16,7 +16,7 @@ AssetReceiverTest:test_withdrawETHwithAmount_unauthorized_reverts() (gas: 10738)
AttestationStationTest:test_attest_bulk_succeeds() (gas: 703740) AttestationStationTest:test_attest_bulk_succeeds() (gas: 703740)
AttestationStationTest:test_attest_individual_succeeds() (gas: 632078) AttestationStationTest:test_attest_individual_succeeds() (gas: 632078)
AttestationStationTest:test_attest_single_succeeds() (gas: 651316) AttestationStationTest:test_attest_single_succeeds() (gas: 651316)
BlockOracle_Test:test_checkpointAndLoad_succeeds() (gas: 51465) BlockOracle_Test:test_checkpointAndLoad_succeeds() (gas: 58341)
BlockOracle_Test:test_load_noBlockHash_reverts() (gas: 12805) BlockOracle_Test:test_load_noBlockHash_reverts() (gas: 12805)
Bytes_slice_Test:test_slice_acrossMultipleWords_works() (gas: 9413) Bytes_slice_Test:test_slice_acrossMultipleWords_works() (gas: 9413)
Bytes_slice_Test:test_slice_acrossWords_works() (gas: 1430) Bytes_slice_Test:test_slice_acrossWords_works() (gas: 1430)
......
...@@ -13,6 +13,13 @@ contract BlockOracle { ...@@ -13,6 +13,13 @@ contract BlockOracle {
Timestamp childTimestamp; Timestamp childTimestamp;
} }
/// @notice Emitted when a block is checkpointed.
event Checkpoint(
uint256 indexed blockNumber,
Hash indexed blockHash,
Timestamp indexed childTimestamp
);
/// @notice Maps block numbers to block hashes and timestamps /// @notice Maps block numbers to block hashes and timestamps
mapping(uint256 => BlockInfo) internal blocks; mapping(uint256 => BlockInfo) internal blocks;
...@@ -33,9 +40,11 @@ contract BlockOracle { ...@@ -33,9 +40,11 @@ contract BlockOracle {
// and in the case of `block.number = 0`, we'll underflow. // and in the case of `block.number = 0`, we'll underflow.
// Persist the block information. // Persist the block information.
blockNumber_ = block.number - 1; blockNumber_ = block.number - 1;
blocks[blockNumber_] = BlockInfo({ Hash blockHash = Hash.wrap(blockhash(blockNumber_));
hash: Hash.wrap(blockhash(blockNumber_)), Timestamp childTimestamp = Timestamp.wrap(uint64(block.timestamp));
childTimestamp: Timestamp.wrap(uint64(block.timestamp))
}); blocks[blockNumber_] = BlockInfo({ hash: blockHash, childTimestamp: childTimestamp });
emit Checkpoint(blockNumber_, blockHash, childTimestamp);
} }
} }
...@@ -9,6 +9,13 @@ import "src/libraries/DisputeErrors.sol"; ...@@ -9,6 +9,13 @@ import "src/libraries/DisputeErrors.sol";
contract BlockOracle_Test is Test { contract BlockOracle_Test is Test {
BlockOracle oracle; BlockOracle oracle;
/// @notice Emitted when a block is checkpointed.
event Checkpoint(
uint256 indexed blockNumber,
Hash indexed blockHash,
Timestamp indexed childTimestamp
);
function setUp() public { function setUp() public {
oracle = new BlockOracle(); oracle = new BlockOracle();
// Roll the chain forward 1 block. // Roll the chain forward 1 block.
...@@ -18,6 +25,12 @@ contract BlockOracle_Test is Test { ...@@ -18,6 +25,12 @@ contract BlockOracle_Test is Test {
/// @notice Tests that checkpointing a block and loading its information succeeds. /// @notice Tests that checkpointing a block and loading its information succeeds.
function test_checkpointAndLoad_succeeds() public { function test_checkpointAndLoad_succeeds() public {
vm.expectEmit(true, true, true, false);
emit Checkpoint(
block.number - 1,
Hash.wrap(blockhash(block.number - 1)),
Timestamp.wrap(uint64(block.timestamp))
);
oracle.checkpoint(); oracle.checkpoint();
uint256 blockNumber = block.number - 1; uint256 blockNumber = block.number - 1;
BlockOracle.BlockInfo memory res = oracle.load(blockNumber); BlockOracle.BlockInfo memory res = oracle.load(blockNumber);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment