Open
Description
Problem
The deployed block concept is simple and good, but it can be better. cause some L2 not using block.number for return current block height. and to not always use lastest
block number when filter log can use LASTSEEN_BLOCKNUMBER
which is lastest action of contract and open design of choice, e.g,, every 10,000 blocks, then stamp LASTSEEN_BLOCKNUMBER
Solution
Reference Implementation
// SPDX-License-Identifier: Apache-2.0
pragma solidity >=0.8.0 <0.9.0;
abstract contract Indexed {
// @TODO adopt ERC-7201 for directly call data from storage by `eth_getStorageAt` instead `eth_call`.
uint256 public DEPLOYED_BLOCKNUMBER;
uint256 public LASTSEEN_BLOCKNUMBER;
constructor() {
DEPLOYED_BLOCKNUMBER = _blockNumberProvider();
LASTSEEN_BLOCKNUMBER = _blockNumberProvider();
}
/**
* @notice some L2 use precompiled contract to get current block number.
* @dev override this function if the network not use `block.number`.
*/
function _blockNumberProvider() internal view virtual returns (uint256) {
return block.number;
}
/**
* @dev stamp last seen block number.
*/
function _stamp() internal {
LASTSEEN_BLOCKNUMBER = _blockNumberProvider();
}
}
Nice to Have
Use ERC-7201 so indexed call eth_getStorageAt
instead of eth_call
to avoid EVM execution.
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
Status
No status