@@ -11,6 +11,7 @@ import (
1111 "encoding/hex"
1212 "errors"
1313 "fmt"
14+ "math"
1415 "math/big"
1516 "regexp"
1617 "strconv"
@@ -263,7 +264,11 @@ func (e *EthereumClient) HeaderTimestampByNumber(ctx context.Context, bn *big.In
263264 if err != nil {
264265 return 0 , err
265266 }
266- return uint64 (h .Timestamp .UTC ().Unix ()), nil
267+ timestamp := h .Timestamp .UTC ().Unix ()
268+ if timestamp < 0 {
269+ return 0 , fmt .Errorf ("negative timestamp value: %d" , timestamp )
270+ }
271+ return uint64 (timestamp ), nil
267272}
268273
269274// BlockNumber gets latest block number
@@ -539,7 +544,7 @@ func (e *EthereumClient) TransactionOpts(from *EthereumWallet) (*bind.TransactOp
539544 if err != nil {
540545 return nil , err
541546 }
542- opts .Nonce = big .NewInt (int64 (nonce ) )
547+ opts .Nonce = big .NewInt (0 ). SetUint64 (nonce )
543548
544549 if e .NetworkConfig .MinimumConfirmations <= 0 { // Wait for your turn to send on an L2 chain
545550 <- e .NonceSettings .registerInstantTransaction (from .Address (), nonce )
@@ -708,7 +713,7 @@ func (e *EthereumClient) WaitForFinalizedTx(txHash common.Hash) (*big.Int, time.
708713func (e * EthereumClient ) IsTxHeadFinalized (txHdr , header * SafeEVMHeader ) (bool , * big.Int , time.Time , error ) {
709714 if e .NetworkConfig .FinalityDepth > 0 {
710715 if header .Number .Cmp (new (big.Int ).Add (txHdr .Number ,
711- big .NewInt (int64 (e .NetworkConfig .FinalityDepth ) ))) > 0 {
716+ big .NewInt (0 ). SetUint64 (e .NetworkConfig .FinalityDepth ))) > 0 {
712717 return true , header .Number , header .Timestamp , nil
713718 }
714719 return false , nil , time.Time {}, nil
@@ -1058,8 +1063,6 @@ func (e *EthereumClient) WaitForEvents() error {
10581063 g := errgroup.Group {}
10591064
10601065 for subName , sub := range queuedEvents {
1061- subName := subName
1062- sub := sub
10631066 g .Go (func () error {
10641067 defer func () {
10651068 // if the subscription is complete, delete it from the queue
@@ -1100,6 +1103,9 @@ func (e *EthereumClient) GetLatestFinalizedBlockHeader(ctx context.Context) (*ty
11001103 }
11011104 latestBlockNumber := header .Number .Uint64 ()
11021105 finalizedBlockNumber := latestBlockNumber - e .NetworkConfig .FinalityDepth
1106+ if finalizedBlockNumber > math .MaxInt64 {
1107+ return nil , fmt .Errorf ("finalized block number %d exceeds int64 range" , finalizedBlockNumber )
1108+ }
11031109 return e .Client .HeaderByNumber (ctx , big .NewInt (int64 (finalizedBlockNumber )))
11041110}
11051111
@@ -1121,7 +1127,7 @@ func (e *EthereumClient) EstimatedFinalizationTime(ctx context.Context) (time.Du
11211127 if e .NetworkConfig .FinalityDepth == 0 {
11221128 return 0 , fmt .Errorf ("finality depth is 0 and finality tag is not enabled" )
11231129 }
1124- timeBetween := time .Duration (e .NetworkConfig .FinalityDepth ) * blckTime
1130+ timeBetween := time .Duration (e .NetworkConfig .FinalityDepth ) * blckTime //nolint
11251131 e .l .Info ().
11261132 Str ("Time" , timeBetween .String ()).
11271133 Str ("Network" , e .GetNetworkName ()).
@@ -1159,7 +1165,7 @@ func (e *EthereumClient) TimeBetweenFinalizedBlocks(ctx context.Context, maxTime
11591165 return 0 , err
11601166 }
11611167 if nextFinalizedHeader .Number .Cmp (currentFinalizedHeader .Number ) > 0 {
1162- timeBetween := time .Unix (int64 (nextFinalizedHeader .Time ), 0 ).Sub (time .Unix (int64 (currentFinalizedHeader .Time ), 0 ))
1168+ timeBetween := time .Unix (int64 (nextFinalizedHeader .Time ), 0 ).Sub (time .Unix (int64 (currentFinalizedHeader .Time ), 0 )) //nolint
11631169 e .l .Info ().
11641170 Str ("Time" , timeBetween .String ()).
11651171 Str ("Network" , e .GetNetworkName ()).
@@ -1190,24 +1196,24 @@ func (e *EthereumClient) AvgBlockTime(ctx context.Context) (time.Duration, error
11901196 }
11911197 totalTime := time .Duration (0 )
11921198 var previousHeader * types.Header
1193- previousHeader , err = e .Client .HeaderByNumber (ctx , big .NewInt (int64 (startBlockNumber - 1 )))
1199+ previousHeader , err = e .Client .HeaderByNumber (ctx , big .NewInt (int64 (startBlockNumber - 1 ))) //nolint
11941200 if err != nil {
11951201 return totalTime , err
11961202 }
11971203 for i := startBlockNumber ; i <= latestBlockNumber ; i ++ {
1198- hdr , err := e .Client .HeaderByNumber (ctx , big .NewInt (int64 (i )))
1204+ hdr , err := e .Client .HeaderByNumber (ctx , big .NewInt (int64 (i ))) //nolint
11991205 if err != nil {
12001206 return totalTime , err
12011207 }
12021208
1203- blockTime := time .Unix (int64 (hdr .Time ), 0 )
1204- previousBlockTime := time .Unix (int64 (previousHeader .Time ), 0 )
1209+ blockTime := time .Unix (int64 (hdr .Time ), 0 ) //nolint
1210+ previousBlockTime := time .Unix (int64 (previousHeader .Time ), 0 ) //nolint
12051211 blockDuration := blockTime .Sub (previousBlockTime )
12061212 totalTime += blockDuration
12071213 previousHeader = hdr
12081214 }
12091215
1210- averageBlockTime := totalTime / time .Duration (numBlocks )
1216+ averageBlockTime := totalTime / time .Duration (numBlocks ) //nolint
12111217
12121218 return averageBlockTime , nil
12131219}
@@ -1730,7 +1736,6 @@ func (e *EthereumMultinodeClient) DeleteHeaderEventSubscription(key string) {
17301736func (e * EthereumMultinodeClient ) WaitForEvents () error {
17311737 g := errgroup.Group {}
17321738 for _ , c := range e .Clients {
1733- c := c
17341739 g .Go (func () error {
17351740 return c .WaitForEvents ()
17361741 })
0 commit comments