Skip to content

Commit 10c4e89

Browse files
0xsharmaVictor Castell
authored and
Victor Castell
committed
fix: added basic span read
1 parent 28963d5 commit 10c4e89

File tree

3 files changed

+29917
-4
lines changed

3 files changed

+29917
-4
lines changed

consensus/bor/bor.go

+30-4
Original file line numberDiff line numberDiff line change
@@ -1074,13 +1074,39 @@ func (c *Bor) fetchAndCommitSpan(
10741074
}
10751075
heimdallSpan = *s
10761076
} else {
1077-
response, err := c.HeimdallClient.FetchWithRetry(fmt.Sprintf("bor/span/%d", newSpanID), "")
1078-
if err != nil {
1077+
1078+
var spanArray []*ResponseWithHeight
1079+
1080+
if err := json.Unmarshal([]byte(SPANS), &spanArray); err != nil {
10791081
return err
10801082
}
1083+
spanInJSON := false
10811084

1082-
if err := json.Unmarshal(response.Result, &heimdallSpan); err != nil {
1083-
return err
1085+
for _, val := range spanArray {
1086+
1087+
var tempHeimdallSpan HeimdallSpan
1088+
1089+
if err := json.Unmarshal(val.Result, &tempHeimdallSpan); err != nil {
1090+
return err
1091+
}
1092+
1093+
if tempHeimdallSpan.ID == newSpanID {
1094+
heimdallSpan = tempHeimdallSpan
1095+
log.Info("Got span from local", "span", heimdallSpan.Span.ID)
1096+
spanInJSON = true
1097+
break
1098+
}
1099+
}
1100+
1101+
if !spanInJSON {
1102+
response, err := c.HeimdallClient.FetchWithRetry(fmt.Sprintf("bor/span/%d", newSpanID), "")
1103+
if err != nil {
1104+
return err
1105+
}
1106+
1107+
if err := json.Unmarshal(response.Result, &heimdallSpan); err != nil {
1108+
return err
1109+
}
10841110
}
10851111
}
10861112

consensus/bor/bor_test.go

+25
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package bor
22

33
import (
4+
"encoding/json"
45
"math/big"
56
"testing"
67

@@ -135,3 +136,27 @@ func TestEncodeSigHeaderJaipur(t *testing.T) {
135136
hash = SealHash(h, &params.BorConfig{JaipurBlock: 10})
136137
assert.Equal(t, hash, hashWithoutBaseFee)
137138
}
139+
140+
func TestReadHardcodedSpan(t *testing.T) {
141+
// t.Skip()
142+
143+
var spanArray []*ResponseWithHeight
144+
145+
if err := json.Unmarshal([]byte(SPANS), &spanArray); err != nil {
146+
t.Fatal(err)
147+
148+
}
149+
150+
for i, val := range spanArray {
151+
152+
var tempHeimdallSpan HeimdallSpan
153+
154+
if err := json.Unmarshal(val.Result, &tempHeimdallSpan); err != nil {
155+
t.Fatal(err)
156+
}
157+
158+
t.Log(i, tempHeimdallSpan.ID)
159+
160+
}
161+
162+
}

0 commit comments

Comments
 (0)