mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-05-27 10:19:28 +00:00
30 lines
583 B
Go
30 lines
583 B
Go
package health
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"net/http"
|
|
)
|
|
|
|
var (
|
|
errTimestampTooOld = errors.New("timestamp too old")
|
|
)
|
|
|
|
// checkTime fetches the timestamp of the most recent block and returns an error if it is earlier than 'minTimestamp'.
|
|
func checkTime(
|
|
ec ethClient,
|
|
r *http.Request,
|
|
minTimestamp int,
|
|
) error {
|
|
i, err := ec.BlockByNumber(context.TODO(), nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
timestamp := i.Time()
|
|
if timestamp < uint64(minTimestamp) {
|
|
return fmt.Errorf("%w: got ts: %d, need: %d", errTimestampTooOld, timestamp, minTimestamp)
|
|
}
|
|
|
|
return nil
|
|
}
|