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
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
54609b61
Commit
54609b61
authored
Apr 22, 2020
by
atvanguard
Browse files
Options
Downloads
Patches
Plain Diff
refactor: Bubble up error in updateTotalVotingPower instead of panic (2.29)
parent
18266b0d
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
consensus/bor/errors.go
+15
-0
15 additions, 0 deletions
consensus/bor/errors.go
consensus/bor/snapshot.go
+3
-1
3 additions, 1 deletion
consensus/bor/snapshot.go
consensus/bor/validator_set.go
+12
-8
12 additions, 8 deletions
consensus/bor/validator_set.go
with
30 additions
and
9 deletions
consensus/bor/errors.go
+
15
−
0
View file @
54609b61
...
...
@@ -25,3 +25,18 @@ type SignerNotFoundError struct {
func
(
e
*
SignerNotFoundError
)
Error
()
string
{
return
fmt
.
Sprintf
(
"Signer: %s not found"
,
e
.
Address
.
Hex
())
}
// TotalVotingPowerExceededError is returned when the maximum allowed total voting power is exceeded
type
TotalVotingPowerExceededError
struct
{
Sum
int64
Validators
[]
*
Validator
}
func
(
e
*
TotalVotingPowerExceededError
)
Error
()
string
{
return
fmt
.
Sprintf
(
"Total voting power should be guarded to not exceed %v; got: %v; for validator set: %v"
,
MaxTotalVotingPower
,
e
.
Sum
,
e
.
Validators
,
)
}
This diff is collapsed.
Click to expand it.
consensus/bor/snapshot.go
+
3
−
1
View file @
54609b61
...
...
@@ -87,7 +87,9 @@ func loadSnapshot(config *params.BorConfig, sigcache *lru.ARCCache, db ethdb.Dat
snap
.
ethAPI
=
ethAPI
// update total voting power
snap
.
ValidatorSet
.
updateTotalVotingPower
()
if
err
:=
snap
.
ValidatorSet
.
updateTotalVotingPower
();
err
!=
nil
{
return
nil
,
err
}
return
snap
,
nil
}
...
...
This diff is collapsed.
Click to expand it.
consensus/bor/validator_set.go
+
12
−
8
View file @
54609b61
...
...
@@ -11,6 +11,7 @@ import (
"strings"
"github.com/maticnetwork/bor/common"
"github.com/maticnetwork/bor/log"
)
// MaxTotalVotingPower - the maximum allowed total voting power.
...
...
@@ -256,28 +257,29 @@ func (vals *ValidatorSet) Size() int {
}
// Force recalculation of the set's total voting power.
func
(
vals
*
ValidatorSet
)
updateTotalVotingPower
()
{
func
(
vals
*
ValidatorSet
)
updateTotalVotingPower
()
error
{
sum
:=
int64
(
0
)
for
_
,
val
:=
range
vals
.
Validators
{
// mind overflow
sum
=
safeAddClip
(
sum
,
val
.
VotingPower
)
if
sum
>
MaxTotalVotingPower
{
panic
(
fmt
.
Sprintf
(
"Total voting power should be guarded to not exceed %v; got: %v"
,
MaxTotalVotingPower
,
sum
))
return
&
TotalVotingPowerExceededError
{
sum
,
vals
.
Validators
}
}
}
vals
.
totalVotingPower
=
sum
return
nil
}
// TotalVotingPower returns the sum of the voting powers of all validators.
// It recomputes the total voting power if required.
func
(
vals
*
ValidatorSet
)
TotalVotingPower
()
int64
{
if
vals
.
totalVotingPower
==
0
{
vals
.
updateTotalVotingPower
()
log
.
Info
(
"invoking updateTotalVotingPower before returning it"
)
if
err
:=
vals
.
updateTotalVotingPower
();
err
!=
nil
{
// Can/should we do better?
panic
(
err
)
}
}
return
vals
.
totalVotingPower
}
...
...
@@ -562,7 +564,9 @@ func (vals *ValidatorSet) updateWithChangeSet(changes []*Validator, allowDeletes
vals
.
applyUpdates
(
updates
)
vals
.
applyRemovals
(
deletes
)
vals
.
updateTotalVotingPower
()
if
err
:=
vals
.
updateTotalVotingPower
();
err
!=
nil
{
return
err
}
// Scale and center.
vals
.
RescalePriorities
(
PriorityWindowSizeFactor
*
vals
.
TotalVotingPower
())
...
...
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