@@ -33,7 +33,7 @@ use zksync_types::{
3333 pubdata_da:: PubdataSendingMode ,
3434 server_notification:: GatewayMigrationState ,
3535 settlement:: SettlementLayer ,
36- web3:: { contract:: Error as Web3ContractError , CallRequest } ,
36+ web3:: { contract:: Error as Web3ContractError , BlockId , BlockNumber , CallRequest } ,
3737 Address , L1BatchNumber , L2ChainId , ProtocolVersionId , SLChainId , H256 , U256 ,
3838} ;
3939
@@ -204,17 +204,56 @@ impl EthTxAggregator {
204204 if self . config . fusaka_upgrade_block == Some ( 0 ) {
205205 return Ok ( EthereumUpgradeState :: Finished ) ;
206206 }
207- let Some ( fusaka_upgrade_block) = self . config . fusaka_upgrade_block else {
207+
208+ if self . config . fusaka_upgrade_timestamp . is_none ( )
209+ && self . config . fusaka_upgrade_block . is_none ( )
210+ {
208211 return Ok ( EthereumUpgradeState :: NotStarted ) ;
209- } ;
212+ }
210213
211- let current_block = self . eth_client . block_number ( ) . await ?. as_u64 ( ) ;
212- if current_block - self . config . fusaka_upgrade_safety_margin < fusaka_upgrade_block {
213- Ok ( EthereumUpgradeState :: NotStarted )
214- } else if current_block < fusaka_upgrade_block {
215- Ok ( EthereumUpgradeState :: Pending )
216- } else {
217- Ok ( EthereumUpgradeState :: Finished )
214+ let current_block = self
215+ . eth_client
216+ . block ( BlockId :: Number ( BlockNumber :: Latest ) )
217+ . await ?
218+ . expect ( "Latest block not found" ) ;
219+
220+ // Prioritize using the block number for the upgrade if both are set
221+ // Timestamp is set with default, so block number takes precedence
222+ match (
223+ self . config . fusaka_upgrade_block ,
224+ self . config . fusaka_upgrade_timestamp ,
225+ ) {
226+ ( Some ( fusaka_upgrade_block) , _) => {
227+ if current_block. number . unwrap ( ) . as_u64 ( ) - self . config . fusaka_upgrade_safety_margin
228+ < fusaka_upgrade_block
229+ {
230+ Ok ( EthereumUpgradeState :: NotStarted )
231+ } else if current_block. number . unwrap ( ) . as_u64 ( )
232+ + self . config . fusaka_upgrade_safety_margin
233+ >= fusaka_upgrade_block
234+ {
235+ Ok ( EthereumUpgradeState :: Finished )
236+ } else {
237+ Ok ( EthereumUpgradeState :: Pending )
238+ }
239+ }
240+ ( _, Some ( fusaka_upgrade_timestamp) ) => {
241+ let current_timestamp = current_block. timestamp . as_u64 ( ) ;
242+ if current_timestamp
243+ < fusaka_upgrade_timestamp - self . config . fusaka_upgrade_safety_margin
244+ {
245+ Ok ( EthereumUpgradeState :: NotStarted )
246+ } else if current_timestamp + self . config . fusaka_upgrade_safety_margin
247+ >= fusaka_upgrade_timestamp
248+ {
249+ Ok ( EthereumUpgradeState :: Finished )
250+ } else {
251+ Ok ( EthereumUpgradeState :: Pending )
252+ }
253+ }
254+ // All the values has already been checked this case is rather unreachable.
255+ // But for safety reasons, it's better to not panic if it's not necessary
256+ ( _, _) => Ok ( EthereumUpgradeState :: NotStarted ) ,
218257 }
219258 }
220259
0 commit comments