Skip to content

Commit

Permalink
Remove milestone no-ack fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
avalkov committed Feb 28, 2025
1 parent 7c8d7a8 commit c329380
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 119 deletions.
2 changes: 0 additions & 2 deletions consensus/bor/heimdall.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,5 @@ type IHeimdallClient interface {
FetchCheckpointCount(ctx context.Context) (int64, error)
FetchMilestone(ctx context.Context) (*milestone.Milestone, error)
FetchMilestoneCount(ctx context.Context) (int64, error)
FetchNoAckMilestone(ctx context.Context, milestoneID string) error // Fetch the bool value whether milestone corresponding to the given id failed in the Heimdall
FetchLastNoAckMilestone(ctx context.Context) (string, error) // Fetch latest failed milestone id
Close()
}
50 changes: 0 additions & 50 deletions consensus/bor/heimdall/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,6 @@ const (
fetchMilestone = "/milestone/latest"
fetchMilestoneCount = "/milestone/count"

fetchLastNoAckMilestone = "/milestone/last-no-ack"
fetchNoAckMilestone = "/milestone/no-ack/%s"

fetchSpanFormat = "bor/span/%d"
)

Expand Down Expand Up @@ -229,44 +226,6 @@ func (h *HeimdallClient) FetchMilestoneCount(ctx context.Context) (int64, error)
return response.Count, nil
}

// FetchLastNoAckMilestone fetches the last no-ack-milestone from heimdall
func (h *HeimdallClient) FetchLastNoAckMilestone(ctx context.Context) (string, error) {
url, err := lastNoAckMilestoneURL(h.urlString)
if err != nil {
return "", err
}

ctx = withRequestType(ctx, milestoneLastNoAckRequest)

response, err := FetchWithRetry[milestone.MilestoneLastNoAckResponse](ctx, h.client, url, h.closeCh)
if err != nil {
return "", err
}

return response.Result, nil
}

// FetchNoAckMilestone fetches the last no-ack-milestone from heimdall
func (h *HeimdallClient) FetchNoAckMilestone(ctx context.Context, milestoneID string) error {
url, err := noAckMilestoneURL(h.urlString, milestoneID)
if err != nil {
return err
}

ctx = withRequestType(ctx, milestoneNoAckRequest)

response, err := FetchWithRetry[milestone.MilestoneNoAckResponse](ctx, h.client, url, h.closeCh)
if err != nil {
return err
}

if !response.Result {
return fmt.Errorf("%w: milestoneID %q", ErrNotInRejectedList, milestoneID)
}

return nil
}

// FetchWithRetry returns data from heimdall with retry
func FetchWithRetry[T any](ctx context.Context, client http.Client, url *url.URL, closeCh chan struct{}) (*T, error) {
// request data once
Expand Down Expand Up @@ -417,15 +376,6 @@ func milestoneCountURL(urlString string) (*url.URL, error) {
return makeURL(urlString, fetchMilestoneCount, "")
}

func lastNoAckMilestoneURL(urlString string) (*url.URL, error) {
return makeURL(urlString, fetchLastNoAckMilestone, "")
}

func noAckMilestoneURL(urlString string, id string) (*url.URL, error) {
url := fmt.Sprintf(fetchNoAckMilestone, id)
return makeURL(urlString, url, "")
}

func makeURL(urlString, rawPath, rawQuery string) (*url.URL, error) {
u, err := url.Parse(urlString)
if err != nil {
Expand Down
50 changes: 0 additions & 50 deletions eth/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -635,8 +635,6 @@ func (s *Ethereum) Start() error {

go s.startCheckpointWhitelistService()
go s.startMilestoneWhitelistService()
go s.startNoAckMilestoneService()
go s.startNoAckMilestoneByIDService()

return nil
}
Expand Down Expand Up @@ -673,24 +671,6 @@ func (s *Ethereum) startMilestoneWhitelistService() {
s.retryHeimdallHandler(s.handleMilestone, tickerDuration, whitelistTimeout, fnName)
}

func (s *Ethereum) startNoAckMilestoneService() {
const (
tickerDuration = 1 * time.Second
fnName = "no-ack-milestone service"
)

s.retryHeimdallHandler(s.handleNoAckMilestone, tickerDuration, noAckMilestoneTimeout, fnName)
}

func (s *Ethereum) startNoAckMilestoneByIDService() {
const (
tickerDuration = 1 * time.Minute
fnName = "no-ack-milestone-by-id service"
)

s.retryHeimdallHandler(s.handleNoAckMilestoneByID, tickerDuration, noAckMilestoneTimeout, fnName)
}

func (s *Ethereum) retryHeimdallHandler(fn heimdallHandler, tickerDuration time.Duration, timeout time.Duration, fnName string) {
retryHeimdallHandler(fn, tickerDuration, timeout, fnName, s.closeCh, s.getHandler)
}
Expand Down Expand Up @@ -787,36 +767,6 @@ func (s *Ethereum) handleMilestone(ctx context.Context, ethHandler *ethHandler,
return nil
}

func (s *Ethereum) handleNoAckMilestone(ctx context.Context, ethHandler *ethHandler, bor *bor.Bor) error {
milestoneID, err := ethHandler.fetchNoAckMilestone(ctx, bor)

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

if err != nil {
return err
}

ethHandler.downloader.RemoveMilestoneID(milestoneID)

return nil
}

func (s *Ethereum) handleNoAckMilestoneByID(ctx context.Context, ethHandler *ethHandler, bor *bor.Bor) error {
milestoneIDs := ethHandler.downloader.GetMilestoneIDsList()

for _, milestoneID := range milestoneIDs {
// todo: check if we can ignore the error
err := ethHandler.fetchNoAckMilestoneByID(ctx, bor, milestoneID)
if err == nil {
ethHandler.downloader.RemoveMilestoneID(milestoneID)
}
}

return nil
}

func (s *Ethereum) getHandler() (*ethHandler, *bor.Bor, error) {
ethHandler := (*ethHandler)(s.handler)

Expand Down
17 changes: 0 additions & 17 deletions eth/handler_bor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ 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 @@ -93,22 +92,6 @@ func (h *ethHandler) fetchWhitelistMilestone(ctx context.Context, bor *bor.Bor,
return num, hash, err
}

func (h *ethHandler) fetchNoAckMilestone(ctx context.Context, bor *bor.Bor) (string, error) {
milestoneID, err := bor.HeimdallClient.FetchLastNoAckMilestone(ctx)
err = reportCommonErrors("latest no-ack milestone", err, nil)

return milestoneID, err
}

func (h *ethHandler) fetchNoAckMilestoneByID(ctx context.Context, bor *bor.Bor, milestoneID string) error {
err := bor.HeimdallClient.FetchNoAckMilestone(ctx, milestoneID)
if errors.Is(err, heimdall.ErrNotInRejectedList) {
log.Debug("MilestoneID not in rejected list", "milestoneID", milestoneID)
}
err = reportCommonErrors("no-ack milestone by ID", err, nil, "milestoneID", milestoneID)
return err
}

// reportCommonErrors reports common errors which can occur while fetching data from heimdall. It also
// returns back the wrapped erorr if required to the caller.
func reportCommonErrors(msg string, err error, wrapError error, ctx ...interface{}) error {
Expand Down

0 comments on commit c329380

Please sign in to comment.