Skip to content

Commit

Permalink
Merge tag 'v1.0.6' into TS_merge_v1.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ayazabbas committed Oct 6, 2023
2 parents be2c6ec + d521b8e commit 2de360e
Show file tree
Hide file tree
Showing 19 changed files with 1,588 additions and 265 deletions.
2 changes: 1 addition & 1 deletion builder/files/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ syncmode = "full"
# nodekeyhex = ""
[p2p.discovery]
# v5disc = false
bootnodes = ["enode://b8f1cc9c5d4403703fbf377116469667d2b1823c0daf16b7250aa576bacf399e42c3930ccfcb02c5df6879565a2b8931335565f0e8d3f8e72385ecf4a4bf160a@3.36.224.80:30303", "enode://8729e0c825f3d9cad382555f3e46dcff21af323e89025a0e6312df541f4a9e73abfa562d64906f5e59c51fe6f0501b3e61b07979606c56329c020ed739910759@54.194.245.5:30303"]
bootnodes = ["enode://76316d1cb93c8ed407d3332d595233401250d48f8fbb1d9c65bd18c0495eca1b43ec38ee0ea1c257c0abb7d1f25d649d359cdfe5a805842159cfe36c5f66b7e8@52.78.36.216:30303", "enode://b8f1cc9c5d4403703fbf377116469667d2b1823c0daf16b7250aa576bacf399e42c3930ccfcb02c5df6879565a2b8931335565f0e8d3f8e72385ecf4a4bf160a@3.36.224.80:30303", "enode://8729e0c825f3d9cad382555f3e46dcff21af323e89025a0e6312df541f4a9e73abfa562d64906f5e59c51fe6f0501b3e61b07979606c56329c020ed739910759@54.194.245.5:30303", "enode://681ebac58d8dd2d8a6eef15329dfbad0ab960561524cf2dfde40ad646736fe5c244020f20b87e7c1520820bc625cfb487dd71d63a3a3bf0baea2dbb8ec7c79f1@34.240.245.39:30303"]
# Uncomment below `bootnodes` field for Mumbai bootnode
# bootnodes = ["enode://bdcd4786a616a853b8a041f53496d853c68d99d54ff305615cd91c03cd56895e0a7f6e9f35dbf89131044e2114a9a782b792b5661e3aff07faf125a98606a071@43.200.206.40:30303", "enode://209aaf7ed549cf4a5700fd833da25413f80a1248bd3aa7fe2a87203e3f7b236dd729579e5c8df61c97bf508281bae4969d6de76a7393bcbd04a0af70270333b3@54.216.248.9:30303"]
# bootnodesv4 = []
Expand Down
22 changes: 20 additions & 2 deletions consensus/bor/heimdall/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var (
ErrNotSuccessfulResponse = errors.New("error while fetching data from Heimdall")
ErrNotInRejectedList = errors.New("milestoneID doesn't exist in rejected list")
ErrNotInMilestoneList = errors.New("milestoneID doesn't exist in Heimdall")
ErrServiceUnavailable = errors.New("service unavailable")
)

const (
Expand Down Expand Up @@ -277,10 +278,18 @@ func FetchWithRetry[T any](ctx context.Context, client http.Client, url *url.URL
return result, nil
}

// 503 (Service Unavailable) is thrown when an endpoint isn't activated
// yet in heimdall. E.g. when the hardfork hasn't hit yet but heimdall
// is upgraded.
if errors.Is(err, ErrServiceUnavailable) {
log.Debug("Heimdall service unavailable at the moment", "path", url.Path, "error", err)
return nil, err
}

// attempt counter
attempt := 1

log.Warn("an error while trying fetching from Heimdall", "attempt", attempt, "error", err)
log.Warn("an error while trying fetching from Heimdall", "path", url.Path, "attempt", attempt, "error", err)

// create a new ticker for retrying the request
ticker := time.NewTicker(retryCall)
Expand All @@ -307,9 +316,14 @@ retryLoop:
request = &Request{client: client, url: url, start: time.Now()}
result, err = Fetch[T](ctx, request)

if errors.Is(err, ErrServiceUnavailable) {
log.Debug("Heimdall service unavailable at the moment", "path", url.Path, "error", err)
return nil, err
}

if err != nil {
if attempt%logEach == 0 {
log.Warn("an error while trying fetching from Heimdall", "attempt", attempt, "error", err)
log.Warn("an error while trying fetching from Heimdall", "path", url.Path, "attempt", attempt, "error", err)
}

continue retryLoop
Expand Down Expand Up @@ -426,6 +440,10 @@ func internalFetch(ctx context.Context, client http.Client, u *url.URL) ([]byte,

defer res.Body.Close()

if res.StatusCode == http.StatusServiceUnavailable {
return nil, fmt.Errorf("%w: response code %d", ErrServiceUnavailable, res.StatusCode)
}

// check status code
if res.StatusCode != 200 && res.StatusCode != 204 {
return nil, fmt.Errorf("%w: response code %d", ErrNotSuccessfulResponse, res.StatusCode)
Expand Down
10 changes: 9 additions & 1 deletion eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/ethereum/go-ethereum/consensus"
"github.com/ethereum/go-ethereum/consensus/beacon"
"github.com/ethereum/go-ethereum/consensus/bor"
"github.com/ethereum/go-ethereum/consensus/bor/heimdall"
"github.com/ethereum/go-ethereum/consensus/clique"
"github.com/ethereum/go-ethereum/core"
"github.com/ethereum/go-ethereum/core/bloombits"
Expand Down Expand Up @@ -788,6 +789,10 @@ func (s *Ethereum) handleMilestone(ctx context.Context, ethHandler *ethHandler,
ethHandler.downloader.ProcessFutureMilestone(num, hash)
}

if errors.Is(err, heimdall.ErrServiceUnavailable) {
return nil
}

if err != nil {
return err
}
Expand All @@ -800,7 +805,10 @@ func (s *Ethereum) handleMilestone(ctx context.Context, ethHandler *ethHandler,
func (s *Ethereum) handleNoAckMilestone(ctx context.Context, ethHandler *ethHandler, bor *bor.Bor) error {
milestoneID, err := ethHandler.fetchNoAckMilestone(ctx, bor)

//If failed to fetch the no-ack milestone then it give the error.
if errors.Is(err, heimdall.ErrServiceUnavailable) {
return nil
}

if err != nil {
return err
}
Expand Down
16 changes: 15 additions & 1 deletion eth/handler_bor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/consensus/bor"
"github.com/ethereum/go-ethereum/consensus/bor/heimdall"
"github.com/ethereum/go-ethereum/log"
)

Expand Down Expand Up @@ -63,6 +64,11 @@ func (h *ethHandler) fetchWhitelistMilestone(ctx context.Context, bor *bor.Bor,

// fetch latest milestone
milestone, err := bor.HeimdallClient.FetchMilestone(ctx)
if errors.Is(err, heimdall.ErrServiceUnavailable) {
log.Debug("Failed to fetch latest milestone for whitelisting", "err", err)
return num, hash, err
}

if err != nil {
log.Error("Failed to fetch latest milestone for whitelisting", "err", err)
return num, hash, errMilestone
Expand Down Expand Up @@ -92,9 +98,13 @@ func (h *ethHandler) fetchNoAckMilestone(ctx context.Context, bor *bor.Bor) (str

// fetch latest milestone
milestoneID, err := bor.HeimdallClient.FetchLastNoAckMilestone(ctx)
if errors.Is(err, heimdall.ErrServiceUnavailable) {
log.Debug("Failed to fetch latest no-ack milestone", "err", err)
return milestoneID, err
}

if err != nil {
log.Error("Failed to fetch latest no-ack milestone", "err", err)

return milestoneID, errMilestone
}

Expand All @@ -104,6 +114,10 @@ func (h *ethHandler) fetchNoAckMilestone(ctx context.Context, bor *bor.Bor) (str
func (h *ethHandler) fetchNoAckMilestoneByID(ctx context.Context, bor *bor.Bor, milestoneID string) error {
// fetch latest milestone
err := bor.HeimdallClient.FetchNoAckMilestone(ctx, milestoneID)
if errors.Is(err, heimdall.ErrServiceUnavailable) {
log.Debug("Failed to fetch no-ack milestone by ID", "milestoneID", milestoneID, "err", err)
return err
}

// fixme: handle different types of errors
if errors.Is(err, ErrNotInRejectedList) {
Expand Down
Loading

0 comments on commit 2de360e

Please sign in to comment.