-
Notifications
You must be signed in to change notification settings - Fork 124
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(lib/grandpa): Include equivocatory nodes while creating justification #1911
Changes from 2 commits
ef6546f
35fea30
1ceb49d
64b96fc
c2bf981
5039268
0100140
e2bafd8
b627509
d626dae
b0f3c27
7d21850
e6299b5
bbe8ba7
0ed4ce5
a5f4684
c9c278c
0274ef9
0b0c524
6e5dd0b
de8a4ed
f58afce
56f3d05
ad81602
c93a134
7abd69b
0301b49
ec61d8e
a7d9ecb
f1f4d04
5730645
69ee68d
5091650
349080b
32856fa
c10dc71
a0dd708
37b2ba3
add5820
e3546d8
9ac7015
3a4ee28
c675cab
9490f66
f3abef8
1bec0db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -697,7 +697,7 @@ func (s *Service) determinePreCommit() (*Vote, error) { | |
return &pvb, nil | ||
} | ||
|
||
// isFinalisable returns true is the round is finalisable, false otherwise. | ||
// isFinalisable returns true if the round is finalisable, false otherwise. | ||
func (s *Service) isFinalisable(round uint64) (bool, error) { | ||
var pvb Vote | ||
var err error | ||
|
@@ -766,16 +766,10 @@ func (s *Service) finalise() error { | |
s.bestFinalCandidate[s.state.round] = bfc | ||
|
||
// create prevote justification ie. list of all signed prevotes for the bfc | ||
pvs, err := s.createJustification(bfc.Hash, prevote) | ||
if err != nil { | ||
return err | ||
} | ||
pvs := s.createJustification(bfc.Hash, prevote) | ||
|
||
// create precommit justification ie. list of all signed precommits for the bfc | ||
pcs, err := s.createJustification(bfc.Hash, precommit) | ||
if err != nil { | ||
return err | ||
} | ||
pcs := s.createJustification(bfc.Hash, precommit) | ||
|
||
pcj, err := scale.Marshal(*newJustification(s.state.round, bfc.Hash, bfc.Number, pcs)) | ||
if err != nil { | ||
|
@@ -810,43 +804,54 @@ func (s *Service) finalise() error { | |
// createJustification collects the signed precommits received for this round and turns them into | ||
// a justification by adding all signed precommits that are for the best finalised candidate or | ||
// a descendent of the bfc | ||
func (s *Service) createJustification(bfc common.Hash, stage Subround) ([]SignedVote, error) { | ||
func (s *Service) createJustification(bfc common.Hash, stage Subround) []SignedVote { | ||
var ( | ||
spc *sync.Map | ||
err error | ||
just []SignedVote | ||
eqv map[ed25519.PublicKeyBytes][]*SignedVote | ||
) | ||
|
||
switch stage { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should probably throw an error if you pass an unsupported There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. added |
||
case prevote: | ||
spc = s.prevotes | ||
eqv = make(map[ed25519.PublicKeyBytes][]*SignedVote, len(s.pvEquivocations)) | ||
case precommit: | ||
spc = s.precommits | ||
eqv = make(map[ed25519.PublicKeyBytes][]*SignedVote, len(s.pcEquivocations)) | ||
} | ||
|
||
// TODO: use equivacatory votes to create justification as well (#1667) | ||
spc.Range(func(_, value interface{}) bool { | ||
pc := value.(*SignedVote) | ||
var isDescendant bool | ||
|
||
isDescendant, err = s.blockState.IsDescendantOf(bfc, pc.Vote.Hash) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
if !isDescendant { | ||
} else if !isDescendant { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I kinda prefer the second if statement here. |
||
return true | ||
} | ||
|
||
just = append(just, *pc) | ||
return true | ||
}) | ||
|
||
if err != nil { | ||
return nil, err | ||
for _, votes := range eqv { | ||
for _, vote := range votes { | ||
var signedVote SignedVote = *vote | ||
qdm12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
isDescendant, err := s.blockState.IsDescendantOf(bfc, signedVote.Vote.Hash) | ||
|
||
if err != nil { | ||
continue | ||
} else if !isDescendant { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here. |
||
continue | ||
} | ||
|
||
just = append(just, signedVote) | ||
} | ||
} | ||
|
||
return just, nil | ||
return just | ||
} | ||
|
||
// derivePrimary returns the primary for the current round | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what's the reasoning behind removing the error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, my bad, I realized that the error assignment inside the
.Range
function has been used lines below. I'm adding it back