mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-27 23:26:44 +00:00
Merge pull request #8 from maticnetwork/span-retry
MAT-467 retry span and states in bor
This commit is contained in:
commit
6e9fb12945
2 changed files with 46 additions and 16 deletions
|
|
@ -17,7 +17,7 @@ import (
|
|||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/maticnetwork/bor"
|
||||
ethereum "github.com/maticnetwork/bor"
|
||||
"github.com/maticnetwork/bor/accounts"
|
||||
"github.com/maticnetwork/bor/accounts/abi"
|
||||
"github.com/maticnetwork/bor/common"
|
||||
|
|
@ -1038,7 +1038,7 @@ func (c *Bor) commitSpan(
|
|||
header *types.Header,
|
||||
chain core.ChainContext,
|
||||
) error {
|
||||
response, err := FetchFromHeimdall(c.httpClient, c.chainConfig.Bor.Heimdall, "bor", "span", strconv.FormatUint(span.ID+1, 10))
|
||||
response, err := FetchFromHeimdallWithRetry(c.httpClient, c.chainConfig.Bor.Heimdall, "bor", "span", strconv.FormatUint(span.ID+1, 10))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -1158,7 +1158,7 @@ func (c *Bor) CommitStates(
|
|||
// itereate through state ids
|
||||
for _, stateID := range stateIds {
|
||||
// fetch from heimdall
|
||||
response, err := FetchFromHeimdall(c.httpClient, c.chainConfig.Bor.Heimdall, "clerk", "event-record", strconv.FormatUint(stateID.Uint64(), 10))
|
||||
response, err := FetchFromHeimdallWithRetry(c.httpClient, c.chainConfig.Bor.Heimdall, "clerk", "event-record", strconv.FormatUint(stateID.Uint64(), 10))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
"path"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ResponseWithHeight defines a response object type that wraps an original
|
||||
|
|
@ -16,19 +17,8 @@ type ResponseWithHeight struct {
|
|||
Result json.RawMessage `json:"result"`
|
||||
}
|
||||
|
||||
// FetchFromHeimdall returns data from heimdall
|
||||
func FetchFromHeimdall(client http.Client, urlString string, paths ...string) (*ResponseWithHeight, error) {
|
||||
u, err := url.Parse(urlString)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, e := range paths {
|
||||
if e != "" {
|
||||
u.Path = path.Join(u.Path, e)
|
||||
}
|
||||
}
|
||||
|
||||
// internal fetch method
|
||||
func internalFetch(client http.Client, u *url.URL) (*ResponseWithHeight, error) {
|
||||
res, err := client.Get(u.String())
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
|
@ -54,3 +44,43 @@ func FetchFromHeimdall(client http.Client, urlString string, paths ...string) (*
|
|||
|
||||
return &response, nil
|
||||
}
|
||||
|
||||
// FetchFromHeimdallWithRetry returns data from heimdall with retry
|
||||
func FetchFromHeimdallWithRetry(client http.Client, urlString string, paths ...string) (*ResponseWithHeight, error) {
|
||||
u, err := url.Parse(urlString)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, e := range paths {
|
||||
if e != "" {
|
||||
u.Path = path.Join(u.Path, e)
|
||||
}
|
||||
}
|
||||
|
||||
for {
|
||||
res, err := internalFetch(client, u)
|
||||
if err == nil && res != nil {
|
||||
return res, nil
|
||||
}
|
||||
fmt.Println("Retrying again in 5 seconds", u.String())
|
||||
time.Sleep(5 * time.Second)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// FetchFromHeimdall returns data from heimdall
|
||||
func FetchFromHeimdall(client http.Client, urlString string, paths ...string) (*ResponseWithHeight, error) {
|
||||
u, err := url.Parse(urlString)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, e := range paths {
|
||||
if e != "" {
|
||||
u.Path = path.Join(u.Path, e)
|
||||
}
|
||||
}
|
||||
|
||||
return internalFetch(client, u)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue