good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
039c932f
Commit
039c932f
authored
5 years ago
by
vaibhavchellani
Browse files
Options
Downloads
Plain Diff
removed conflicts
parents
088b57eb
2f0b5ce1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
consensus/bor/bor.go
+4
-4
4 additions, 4 deletions
consensus/bor/bor.go
consensus/bor/rest.go
+44
-13
44 additions, 13 deletions
consensus/bor/rest.go
consensus/bor/snapshot.go
+19
-1
19 additions, 1 deletion
consensus/bor/snapshot.go
with
67 additions
and
18 deletions
consensus/bor/bor.go
+
4
−
4
View file @
039c932f
...
...
@@ -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
:=
FetchFromHeimdall
WithRetry
(
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
:=
FetchFromHeimdall
WithRetry
(
c
.
httpClient
,
c
.
chainConfig
.
Bor
.
Heimdall
,
"clerk"
,
"event-record"
,
strconv
.
FormatUint
(
stateID
.
Uint64
(),
10
))
if
err
!=
nil
{
return
err
}
...
...
This diff is collapsed.
Click to expand it.
consensus/bor/rest.go
+
44
−
13
View file @
039c932f
...
...
@@ -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
)
}
This diff is collapsed.
Click to expand it.
consensus/bor/snapshot.go
+
19
−
1
View file @
039c932f
...
...
@@ -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
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment