mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-15 08:23:46 +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"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/maticnetwork/bor"
|
ethereum "github.com/maticnetwork/bor"
|
||||||
"github.com/maticnetwork/bor/accounts"
|
"github.com/maticnetwork/bor/accounts"
|
||||||
"github.com/maticnetwork/bor/accounts/abi"
|
"github.com/maticnetwork/bor/accounts/abi"
|
||||||
"github.com/maticnetwork/bor/common"
|
"github.com/maticnetwork/bor/common"
|
||||||
|
|
@ -1038,7 +1038,7 @@ func (c *Bor) commitSpan(
|
||||||
header *types.Header,
|
header *types.Header,
|
||||||
chain core.ChainContext,
|
chain core.ChainContext,
|
||||||
) error {
|
) 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
@ -1158,7 +1158,7 @@ func (c *Bor) CommitStates(
|
||||||
// itereate through state ids
|
// itereate through state ids
|
||||||
for _, stateID := range stateIds {
|
for _, stateID := range stateIds {
|
||||||
// fetch from heimdall
|
// 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 {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ResponseWithHeight defines a response object type that wraps an original
|
// ResponseWithHeight defines a response object type that wraps an original
|
||||||
|
|
@ -16,19 +17,8 @@ type ResponseWithHeight struct {
|
||||||
Result json.RawMessage `json:"result"`
|
Result json.RawMessage `json:"result"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// FetchFromHeimdall returns data from heimdall
|
// internal fetch method
|
||||||
func FetchFromHeimdall(client http.Client, urlString string, paths ...string) (*ResponseWithHeight, error) {
|
func internalFetch(client http.Client, u *url.URL) (*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)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
res, err := client.Get(u.String())
|
res, err := client.Get(u.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
@ -54,3 +44,43 @@ func FetchFromHeimdall(client http.Client, urlString string, paths ...string) (*
|
||||||
|
|
||||||
return &response, nil
|
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