mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-14 16:03:45 +00:00
Merge pull request #37 from maticnetwork/fix-path
Fix polluted path and check data length for validation action
This commit is contained in:
commit
a14bfacf31
2 changed files with 29 additions and 15 deletions
|
|
@ -1253,6 +1253,10 @@ func (c *Bor) IsValidatorAction(chain consensus.ChainReader, from common.Address
|
||||||
func isProposeSpanAction(tx *types.Transaction, validatorContract string) bool {
|
func isProposeSpanAction(tx *types.Transaction, validatorContract string) bool {
|
||||||
// keccak256('proposeSpan()').slice(0, 4)
|
// keccak256('proposeSpan()').slice(0, 4)
|
||||||
proposeSpanSig, _ := hex.DecodeString("4b0e4d17")
|
proposeSpanSig, _ := hex.DecodeString("4b0e4d17")
|
||||||
|
if tx.Data() == nil || len(tx.Data()) < 4 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
return bytes.Compare(proposeSpanSig, tx.Data()[:4]) == 0 &&
|
return bytes.Compare(proposeSpanSig, tx.Data()[:4]) == 0 &&
|
||||||
tx.To().String() == validatorContract
|
tx.To().String() == validatorContract
|
||||||
}
|
}
|
||||||
|
|
@ -1260,6 +1264,10 @@ func isProposeSpanAction(tx *types.Transaction, validatorContract string) bool {
|
||||||
func isProposeStateAction(tx *types.Transaction, stateReceiverContract string) bool {
|
func isProposeStateAction(tx *types.Transaction, stateReceiverContract string) bool {
|
||||||
// keccak256('proposeState(uint256)').slice(0, 4)
|
// keccak256('proposeState(uint256)').slice(0, 4)
|
||||||
proposeStateSig, _ := hex.DecodeString("ede01f17")
|
proposeStateSig, _ := hex.DecodeString("ede01f17")
|
||||||
|
if tx.Data() == nil || len(tx.Data()) < 4 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
return bytes.Compare(proposeStateSig, tx.Data()[:4]) == 0 &&
|
return bytes.Compare(proposeStateSig, tx.Data()[:4]) == 0 &&
|
||||||
tx.To().String() == stateReceiverContract
|
tx.To().String() == stateReceiverContract
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -25,18 +25,13 @@ type IHeimdallClient interface {
|
||||||
}
|
}
|
||||||
|
|
||||||
type HeimdallClient struct {
|
type HeimdallClient struct {
|
||||||
u *url.URL
|
urlString string
|
||||||
client http.Client
|
client http.Client
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewHeimdallClient(urlString string) (*HeimdallClient, error) {
|
func NewHeimdallClient(urlString string) (*HeimdallClient, error) {
|
||||||
u, err := url.Parse(urlString)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
h := &HeimdallClient{
|
h := &HeimdallClient{
|
||||||
u: u,
|
urlString: urlString,
|
||||||
client: http.Client{
|
client: http.Client{
|
||||||
Timeout: time.Duration(5 * time.Second),
|
Timeout: time.Duration(5 * time.Second),
|
||||||
},
|
},
|
||||||
|
|
@ -45,35 +40,46 @@ func NewHeimdallClient(urlString string) (*HeimdallClient, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *HeimdallClient) Fetch(paths ...string) (*ResponseWithHeight, 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 {
|
for _, e := range paths {
|
||||||
if e != "" {
|
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
|
// FetchWithRetry returns data from heimdall with retry
|
||||||
func (h *HeimdallClient) FetchWithRetry(paths ...string) (*ResponseWithHeight, error) {
|
func (h *HeimdallClient) FetchWithRetry(paths ...string) (*ResponseWithHeight, error) {
|
||||||
|
u, err := url.Parse(h.urlString)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
for _, e := range paths {
|
for _, e := range paths {
|
||||||
if e != "" {
|
if e != "" {
|
||||||
h.u.Path = path.Join(h.u.Path, e)
|
u.Path = path.Join(u.Path, e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
res, err := h.internalFetch()
|
res, err := h.internalFetch(u)
|
||||||
if err == nil && res != nil {
|
if err == nil && res != nil {
|
||||||
return 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)
|
time.Sleep(5 * time.Second)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// internal fetch method
|
// internal fetch method
|
||||||
func (h *HeimdallClient) internalFetch() (*ResponseWithHeight, error) {
|
func (h *HeimdallClient) internalFetch(u *url.URL) (*ResponseWithHeight, error) {
|
||||||
res, err := h.client.Get(h.u.String())
|
res, err := h.client.Get(u.String())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue