2022-05-18 16:12:54 +00:00
|
|
|
// VulcanizeDB
|
|
|
|
// Copyright © 2022 Vulcanize
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU Affero General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU Affero General Public License
|
|
|
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2022-04-25 15:32:46 +00:00
|
|
|
package beaconclient
|
2022-04-25 14:41:50 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
log "github.com/sirupsen/logrus"
|
2022-06-09 21:32:46 +00:00
|
|
|
"github.com/vulcanize/ipld-eth-beacon-indexer/pkg/loghelper"
|
2022-04-25 14:41:50 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// This function will ensure that we can connect to the beacon client.
|
|
|
|
// Keep in mind, the beacon client will allow you to connect to it but it might
|
|
|
|
// Not allow you to make http requests. This is part of its built in logic, and you will have
|
|
|
|
// to follow their provided guidelines. https://lighthouse-book.sigmaprime.io/api-bn.html#security
|
2022-04-26 17:57:01 +00:00
|
|
|
func (bc BeaconClient) CheckBeaconClient() error {
|
2022-04-25 14:41:50 +00:00
|
|
|
log.Debug("Attempting to connect to the beacon client")
|
2022-04-27 18:01:59 +00:00
|
|
|
bcEndpoint := bc.ServerEndpoint + bcHealthEndpoint
|
2022-04-25 14:41:50 +00:00
|
|
|
resp, err := http.Get(bcEndpoint)
|
|
|
|
if err != nil {
|
|
|
|
loghelper.LogError(err).Error("Unable to get bc endpoint: ", bcEndpoint)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if resp.StatusCode < 200 || resp.StatusCode > 299 {
|
2022-05-13 12:48:31 +00:00
|
|
|
loghelper.LogEndpoint(bcEndpoint).Error("We recieved a non 2xx status code when checking the health of the beacon node.")
|
|
|
|
loghelper.LogEndpoint(bcEndpoint).Error("Health Endpoint Status Code: ", resp.StatusCode)
|
2022-04-25 14:41:50 +00:00
|
|
|
return fmt.Errorf("beacon Node Provided a non 2xx status code, code provided: %d", resp.StatusCode)
|
|
|
|
}
|
|
|
|
|
|
|
|
log.Info("We can successfully reach the beacon client.")
|
|
|
|
return nil
|
|
|
|
|
|
|
|
}
|