diff --git a/consensus/bor/bor.go b/consensus/bor/bor.go index d84288d42900efdc1982c193d6ccfdab9d5702c4..406989b6cb672719af65cdee4d540eb0fac6ae71 100644 --- a/consensus/bor/bor.go +++ b/consensus/bor/bor.go @@ -1253,6 +1253,10 @@ func (c *Bor) IsValidatorAction(chain consensus.ChainReader, from common.Address func isProposeSpanAction(tx *types.Transaction, validatorContract string) bool { // keccak256('proposeSpan()').slice(0, 4) proposeSpanSig, _ := hex.DecodeString("4b0e4d17") + if tx.Data() == nil || len(tx.Data()) < 4 { + return false + } + return bytes.Compare(proposeSpanSig, tx.Data()[:4]) == 0 && tx.To().String() == validatorContract } @@ -1260,6 +1264,10 @@ func isProposeSpanAction(tx *types.Transaction, validatorContract string) bool { func isProposeStateAction(tx *types.Transaction, stateReceiverContract string) bool { // keccak256('proposeState(uint256)').slice(0, 4) proposeStateSig, _ := hex.DecodeString("ede01f17") + if tx.Data() == nil || len(tx.Data()) < 4 { + return false + } + return bytes.Compare(proposeStateSig, tx.Data()[:4]) == 0 && tx.To().String() == stateReceiverContract } diff --git a/consensus/bor/rest.go b/consensus/bor/rest.go index 6129037fc38d78254a00f286f1525d791d07d891..9c525d6df6c5b355e6a403845adbb0cb748f6d17 100644 --- a/consensus/bor/rest.go +++ b/consensus/bor/rest.go @@ -25,18 +25,13 @@ type IHeimdallClient interface { } type HeimdallClient struct { - u *url.URL - client http.Client + urlString string + client http.Client } func NewHeimdallClient(urlString string) (*HeimdallClient, error) { - u, err := url.Parse(urlString) - if err != nil { - return nil, err - } - h := &HeimdallClient{ - u: u, + urlString: urlString, client: http.Client{ Timeout: time.Duration(5 * time.Second), }, @@ -45,35 +40,46 @@ func NewHeimdallClient(urlString string) (*HeimdallClient, error) { } func (h *HeimdallClient) Fetch(paths ...string) (*ResponseWithHeight, error) { + u, err := url.Parse(h.urlString) + if err != nil { + return nil, err + } + for _, e := range paths { if e != "" { - h.u.Path = path.Join(h.u.Path, e) + u.Path = path.Join(u.Path, e) } } - return h.internalFetch() + + return h.internalFetch(u) } // FetchWithRetry returns data from heimdall with retry func (h *HeimdallClient) FetchWithRetry(paths ...string) (*ResponseWithHeight, error) { + u, err := url.Parse(h.urlString) + if err != nil { + return nil, err + } + for _, e := range paths { if e != "" { - h.u.Path = path.Join(h.u.Path, e) + u.Path = path.Join(u.Path, e) } } for { - res, err := h.internalFetch() + res, err := h.internalFetch(u) if err == nil && res != nil { return res, nil } - log.Info("Retrying again in 5 seconds for next Heimdall span", "path", h.u.Path) + log.Info("Retrying again in 5 seconds for next Heimdall span", "path", u.Path) time.Sleep(5 * time.Second) } } // internal fetch method -func (h *HeimdallClient) internalFetch() (*ResponseWithHeight, error) { - res, err := h.client.Get(h.u.String()) +func (h *HeimdallClient) internalFetch(u *url.URL) (*ResponseWithHeight, error) { + res, err := h.client.Get(u.String()) if err != nil { return nil, err }