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
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
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
bfab1d93
Commit
bfab1d93
authored
4 years ago
by
atvanguard
Browse files
Options
Downloads
Patches
Plain Diff
dev: rename CompareProposerPriority to Cmp, add nil check (2.27)
parent
48d6d76d
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
consensus/bor/validator.go
+8
-4
8 additions, 4 deletions
consensus/bor/validator.go
consensus/bor/validator_set.go
+2
-2
2 additions, 2 deletions
consensus/bor/validator_set.go
with
10 additions
and
6 deletions
consensus/bor/validator.go
+
8
−
4
View file @
bfab1d93
...
...
@@ -29,18 +29,23 @@ func NewValidator(address common.Address, votingPower int64) *Validator {
}
}
// Creates a new copy of the validator so we can mutate ProposerPriority.
// C
opy c
reates a new copy of the validator so we can mutate ProposerPriority.
// Panics if the validator is nil.
func
(
v
*
Validator
)
Copy
()
*
Validator
{
vCopy
:=
*
v
return
&
vCopy
}
// Returns the one with higher ProposerPriority.
func
(
v
*
Validator
)
CompareProposerPriority
(
other
*
Validator
)
*
Validator
{
// Cmp returns the one validator with a higher ProposerPriority.
// If ProposerPriority is same, it returns the validator with lexicographically smaller address
func
(
v
*
Validator
)
Cmp
(
other
*
Validator
)
*
Validator
{
// if both of v and other are nil, nil will be returned and that could possibly lead to nil pointer dereference bubbling up the stack
if
v
==
nil
{
return
other
}
if
other
==
nil
{
return
v
}
if
v
.
ProposerPriority
>
other
.
ProposerPriority
{
return
v
}
else
if
v
.
ProposerPriority
<
other
.
ProposerPriority
{
...
...
@@ -53,7 +58,6 @@ func (v *Validator) CompareProposerPriority(other *Validator) *Validator {
return
other
}
else
{
panic
(
"Cannot compare identical validators"
)
return
nil
}
}
}
...
...
This diff is collapsed.
Click to expand it.
consensus/bor/validator_set.go
+
2
−
2
View file @
bfab1d93
...
...
@@ -182,7 +182,7 @@ func computeMaxMinPriorityDiff(vals *ValidatorSet) int64 {
func
(
vals
*
ValidatorSet
)
getValWithMostPriority
()
*
Validator
{
var
res
*
Validator
for
_
,
val
:=
range
vals
.
Validators
{
res
=
res
.
C
o
mp
areProposerPriority
(
val
)
res
=
res
.
Cmp
(
val
)
}
return
res
}
...
...
@@ -298,7 +298,7 @@ func (vals *ValidatorSet) findProposer() *Validator {
var
proposer
*
Validator
for
_
,
val
:=
range
vals
.
Validators
{
if
proposer
==
nil
||
!
bytes
.
Equal
(
val
.
Address
.
Bytes
(),
proposer
.
Address
.
Bytes
())
{
proposer
=
proposer
.
C
o
mp
areProposerPriority
(
val
)
proposer
=
proposer
.
Cmp
(
val
)
}
}
return
proposer
...
...
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