Skip to content

Commit

Permalink
fix: added basic span read
Browse files Browse the repository at this point in the history
  • Loading branch information
0xsharma authored and Victor Castell committed Mar 10, 2022
1 parent 28963d5 commit 10c4e89
Show file tree
Hide file tree
Showing 3 changed files with 29,917 additions and 4 deletions.
34 changes: 30 additions & 4 deletions consensus/bor/bor.go
Original file line number Diff line number Diff line change
Expand Up @@ -1074,13 +1074,39 @@ func (c *Bor) fetchAndCommitSpan(
}
heimdallSpan = *s
} else {
response, err := c.HeimdallClient.FetchWithRetry(fmt.Sprintf("bor/span/%d", newSpanID), "")
if err != nil {

var spanArray []*ResponseWithHeight

if err := json.Unmarshal([]byte(SPANS), &spanArray); err != nil {
return err
}
spanInJSON := false

if err := json.Unmarshal(response.Result, &heimdallSpan); err != nil {
return err
for _, val := range spanArray {

var tempHeimdallSpan HeimdallSpan

if err := json.Unmarshal(val.Result, &tempHeimdallSpan); err != nil {
return err
}

if tempHeimdallSpan.ID == newSpanID {
heimdallSpan = tempHeimdallSpan
log.Info("Got span from local", "span", heimdallSpan.Span.ID)
spanInJSON = true
break
}
}

if !spanInJSON {
response, err := c.HeimdallClient.FetchWithRetry(fmt.Sprintf("bor/span/%d", newSpanID), "")
if err != nil {
return err
}

if err := json.Unmarshal(response.Result, &heimdallSpan); err != nil {
return err
}
}
}

Expand Down
25 changes: 25 additions & 0 deletions consensus/bor/bor_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package bor

import (
"encoding/json"
"math/big"
"testing"

Expand Down Expand Up @@ -135,3 +136,27 @@ func TestEncodeSigHeaderJaipur(t *testing.T) {
hash = SealHash(h, &params.BorConfig{JaipurBlock: 10})
assert.Equal(t, hash, hashWithoutBaseFee)
}

func TestReadHardcodedSpan(t *testing.T) {
// t.Skip()

var spanArray []*ResponseWithHeight

if err := json.Unmarshal([]byte(SPANS), &spanArray); err != nil {
t.Fatal(err)

}

for i, val := range spanArray {

var tempHeimdallSpan HeimdallSpan

if err := json.Unmarshal(val.Result, &tempHeimdallSpan); err != nil {
t.Fatal(err)
}

t.Log(i, tempHeimdallSpan.ID)

}

}
Loading

0 comments on commit 10c4e89

Please sign in to comment.