good morning!!!!

Skip to content
Snippets Groups Projects
Commit 039c932f authored by vaibhavchellani's avatar vaibhavchellani
Browse files

removed conflicts

parents 088b57eb 2f0b5ce1
No related branches found
No related tags found
No related merge requests found
......@@ -577,7 +577,7 @@ func (c *Bor) verifySeal(chain consensus.ChainReader, header *types.Header, pare
}
proposerIndex, _ := snap.ValidatorSet.GetByAddress(proposer)
signerIndex, _ := snap.ValidatorSet.GetByAddress(signer)
limit := len(validators) - (len(validators)/2 + 1)
limit := len(validators)/2 + 1
// temp index
tempIndex := signerIndex
......@@ -761,7 +761,7 @@ func (c *Bor) Seal(chain consensus.ChainReader, block *types.Block, results chan
proposerIndex, _ := snap.ValidatorSet.GetByAddress(proposer)
signerIndex, _ := snap.ValidatorSet.GetByAddress(signer)
limit := len(validators) - (len(validators)/2 + 1)
limit := len(validators)/2 + 1
// temp index
tempIndex := signerIndex
......@@ -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
}
......@@ -1157,7 +1157,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,9 @@ import (
"net/http"
"net/url"
"path"
"time"
"github.com/maticnetwork/bor/log"
)
// ResponseWithHeight defines a response object type that wraps an original
......@@ -16,19 +19,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 +46,42 @@ 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
}
log.Info("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)
}
......@@ -150,6 +150,7 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
return nil, err
}
<<<<<<< HEAD
// change validator set and change proposer
if number > 0 && (number+1)%s.config.Sprint == 0 {
validatorBytes := header.Extra[extraVanity : len(header.Extra)-extraSeal]
......@@ -164,6 +165,8 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
log.Info("Current validator set", "number", snap.Number, "validatorSet", snap.ValidatorSet)
}
=======
>>>>>>> origin/mat-494
// check if signer is in validator set
if !snap.ValidatorSet.HasAddress(signer.Bytes()) {
return nil, errUnauthorizedSigner
......@@ -178,7 +181,7 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
proposer := snap.ValidatorSet.GetProposer().Address
proposerIndex, _ := snap.ValidatorSet.GetByAddress(proposer)
signerIndex, _ := snap.ValidatorSet.GetByAddress(signer)
limit := len(validators) - (len(validators)/2 + 1)
limit := len(validators)/2 + 1
// temp index
tempIndex := signerIndex
......@@ -188,12 +191,27 @@ func (s *Snapshot) apply(headers []*types.Header) (*Snapshot, error) {
}
if tempIndex-proposerIndex > limit {
fmt.Println("Invalid signer: error while applying headers", "proposerIndex", validators[proposerIndex].Address.Hex(), "signerIndex", validators[signerIndex].Address.Hex())
return nil, errRecentlySigned
}
}
// add recents
snap.Recents[number] = signer
// change validator set and change proposer
if number > 0 && (number+1)%s.config.Sprint == 0 {
validatorBytes := header.Extra[extraVanity : len(header.Extra)-extraSeal]
// get validators from headers and use that for new validator set
newVals, _ := ParseValidators(validatorBytes)
v := getUpdatedValidatorSet(snap.ValidatorSet.Copy(), newVals)
v.IncrementProposerPriority(1)
snap.ValidatorSet = v
// log new validator set
fmt.Println("New changed validator set", "number", snap.Number, "validatorSet", snap.ValidatorSet, "currentSigner", signer.Hex())
}
}
snap.Number += uint64(len(headers))
snap.Hash = headers[len(headers)-1].Hash()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment