-
Notifications
You must be signed in to change notification settings - Fork 129
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/babe): add check of types.ConfigData.SecondarySlots for disabling secondary verification #1910
feat(lib/babe): add check of types.ConfigData.SecondarySlots for disabling secondary verification #1910
Changes from 3 commits
c8b46b5
250986d
7d6f8cd
3692fd0
09e702c
d25c781
c26553d
4e2f925
4ef4652
ee0900d
1e221c3
b6930bb
83a4591
ac41b7a
2ae9e0f
b4f4fad
da13828
1c21820
73f08b5
1ee9ffc
1d70d13
fb16b0b
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 |
---|---|---|
|
@@ -32,9 +32,10 @@ import ( | |
// verifierInfo contains the information needed to verify blocks | ||
// it remains the same for an epoch | ||
type verifierInfo struct { | ||
authorities []types.Authority | ||
randomness Randomness | ||
threshold *common.Uint128 | ||
authorities []types.Authority | ||
randomness Randomness | ||
threshold *common.Uint128 | ||
secondarySlots bool | ||
} | ||
|
||
// onDisabledInfo contains information about an authority that's been disabled at a certain | ||
|
@@ -225,9 +226,10 @@ func (v *VerificationManager) getVerifierInfo(epoch uint64) (*verifierInfo, erro | |
} | ||
|
||
return &verifierInfo{ | ||
authorities: epochData.Authorities, | ||
randomness: epochData.Randomness, | ||
threshold: threshold, | ||
authorities: epochData.Authorities, | ||
randomness: epochData.Randomness, | ||
threshold: threshold, | ||
secondarySlots: configData.SecondarySlots > 0, | ||
}, nil | ||
} | ||
|
||
|
@@ -248,11 +250,12 @@ func (v *VerificationManager) getConfigData(epoch uint64) (*types.ConfigData, er | |
|
||
// verifier is a BABE verifier for a specific authority set, randomness, and threshold | ||
type verifier struct { | ||
blockState BlockState | ||
epoch uint64 | ||
authorities []types.Authority | ||
randomness Randomness | ||
threshold *common.Uint128 | ||
blockState BlockState | ||
epoch uint64 | ||
authorities []types.Authority | ||
randomness Randomness | ||
threshold *common.Uint128 | ||
secondarySlots bool | ||
} | ||
|
||
// newVerifier returns a Verifier for the epoch described by the given descriptor | ||
|
@@ -262,11 +265,12 @@ func newVerifier(blockState BlockState, epoch uint64, info *verifierInfo) (*veri | |
} | ||
|
||
return &verifier{ | ||
blockState: blockState, | ||
epoch: epoch, | ||
authorities: info.authorities, | ||
randomness: info.randomness, | ||
threshold: info.threshold, | ||
blockState: blockState, | ||
epoch: epoch, | ||
authorities: info.authorities, | ||
randomness: info.randomness, | ||
threshold: info.threshold, | ||
secondarySlots: info.secondarySlots, | ||
}, nil | ||
} | ||
|
||
|
@@ -384,6 +388,10 @@ func (b *verifier) verifyPreRuntimeDigest(digest *types.PreRuntimeDigest) (types | |
case *types.BabePrimaryPreDigest: | ||
ok, err = b.verifyPrimarySlotWinner(d.AuthorityIndex(), d.SlotNumber(), d.VrfOutput(), d.VrfProof()) | ||
case *types.BabeSecondaryVRFPreDigest: | ||
if !b.secondarySlots { | ||
ok = true | ||
break | ||
} | ||
pub := b.authorities[d.AuthorityIndex()].Key | ||
var pk *sr25519.PublicKey | ||
pk, err = sr25519.NewPublicKey(pub.Encode()) | ||
|
@@ -392,9 +400,13 @@ func (b *verifier) verifyPreRuntimeDigest(digest *types.PreRuntimeDigest) (types | |
} | ||
|
||
ok, err = verifySecondarySlotVRF(d, pk, b.epoch, len(b.authorities), b.randomness) | ||
} | ||
|
||
case *types.BabeSecondaryPlainPreDigest: | ||
ok = true | ||
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. question: we keep assinging 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. Good question, @noot did I make a correct assumption? 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. yeah it should be 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. Ok, updated so |
||
err = verifySecondarySlotPlain(d.AuthorityIndex(), d.SlotNumber(), len(b.authorities), b.randomness) | ||
if b.secondarySlots { | ||
err = verifySecondarySlotPlain(d.AuthorityIndex(), d.SlotNumber(), len(b.authorities), b.randomness) | ||
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. can you update this to be the same logic as above (ie. 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. Updated. |
||
} | ||
} | ||
|
||
// verify that they are the slot winner | ||
|
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.
if there's a secondary slot digest but
b.secondarySlots == false
then this should beok = false
, as the digest would be invalidThere 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.
Updated.