@@ -717,10 +717,36 @@ func (vals *ValidatorSet) VerifyCommit(chainID string, blockID BlockID,
717
717
718
718
// VerifyCommitLight verifies +2/3 of the set had signed the given commit.
719
719
//
720
- // This method is primarily used by the light client and does not check all the
720
+ // This method is primarily used by the light client and does NOT check all the
721
721
// signatures.
722
- func (vals * ValidatorSet ) VerifyCommitLight (chainID string , blockID BlockID ,
723
- height int64 , commit * Commit ) error {
722
+ func (vals * ValidatorSet ) VerifyCommitLight (
723
+ chainID string ,
724
+ blockID BlockID ,
725
+ height int64 ,
726
+ commit * Commit ,
727
+ ) error {
728
+ return vals .verifyCommitLightInternal (chainID , blockID , height , commit , false )
729
+ }
730
+
731
+ // VerifyCommitLightAllSignatures verifies +2/3 of the set had signed the given commit.
732
+ //
733
+ // This method DOES check all the signatures.
734
+ func (vals * ValidatorSet ) VerifyCommitLightAllSignatures (
735
+ chainID string ,
736
+ blockID BlockID ,
737
+ height int64 ,
738
+ commit * Commit ,
739
+ ) error {
740
+ return vals .verifyCommitLightInternal (chainID , blockID , height , commit , true )
741
+ }
742
+
743
+ func (vals * ValidatorSet ) verifyCommitLightInternal (
744
+ chainID string ,
745
+ blockID BlockID ,
746
+ height int64 ,
747
+ commit * Commit ,
748
+ countAllSignatures bool ,
749
+ ) error {
724
750
725
751
if vals .Size () != len (commit .Signatures ) {
726
752
return NewErrInvalidCommitSignatures (vals .Size (), len (commit .Signatures ))
@@ -738,8 +764,9 @@ func (vals *ValidatorSet) VerifyCommitLight(chainID string, blockID BlockID,
738
764
talliedVotingPower := int64 (0 )
739
765
votingPowerNeeded := vals .TotalVotingPower () * 2 / 3
740
766
for idx , commitSig := range commit .Signatures {
741
- // No need to verify absent or nil votes.
742
- if ! commitSig .ForBlock () {
767
+ // No need to verify absent or nil votes if not counting all signatures,
768
+ // but need to verify nil votes if counting all signatures.
769
+ if (! countAllSignatures && ! commitSig .ForBlock ()) || (countAllSignatures && commitSig .Absent ()) {
743
770
continue
744
771
}
745
772
@@ -756,11 +783,14 @@ func (vals *ValidatorSet) VerifyCommitLight(chainID string, blockID BlockID,
756
783
talliedVotingPower += val .VotingPower
757
784
758
785
// return as soon as +2/3 of the signatures are verified
759
- if talliedVotingPower > votingPowerNeeded {
786
+ if ! countAllSignatures && talliedVotingPower > votingPowerNeeded {
760
787
return nil
761
788
}
762
789
}
763
790
791
+ if talliedVotingPower > votingPowerNeeded {
792
+ return nil
793
+ }
764
794
return ErrNotEnoughVotingPowerSigned {Got : talliedVotingPower , Needed : votingPowerNeeded }
765
795
}
766
796
@@ -770,9 +800,37 @@ func (vals *ValidatorSet) VerifyCommitLight(chainID string, blockID BlockID,
770
800
// NOTE the given validators do not necessarily correspond to the validator set
771
801
// for this commit, but there may be some intersection.
772
802
//
773
- // This method is primarily used by the light client and does not check all the
803
+ // This method is primarily used by the light client and does NOT check all the
774
804
// signatures.
775
- func (vals * ValidatorSet ) VerifyCommitLightTrusting (chainID string , commit * Commit , trustLevel cmtmath.Fraction ) error {
805
+ func (vals * ValidatorSet ) VerifyCommitLightTrusting (
806
+ chainID string ,
807
+ commit * Commit ,
808
+ trustLevel cmtmath.Fraction ,
809
+ ) error {
810
+ return vals .verifyCommitLightTrustingInternal (chainID , commit , trustLevel , false )
811
+ }
812
+
813
+ // VerifyCommitLightTrustingAllSignatures verifies that trustLevel of the validator
814
+ // set signed this commit.
815
+ //
816
+ // NOTE the given validators do not necessarily correspond to the validator set
817
+ // for this commit, but there may be some intersection.
818
+ //
819
+ // This method DOES check all the signatures.
820
+ func (vals * ValidatorSet ) VerifyCommitLightTrustingAllSignatures (
821
+ chainID string ,
822
+ commit * Commit ,
823
+ trustLevel cmtmath.Fraction ,
824
+ ) error {
825
+ return vals .verifyCommitLightTrustingInternal (chainID , commit , trustLevel , true )
826
+ }
827
+
828
+ func (vals * ValidatorSet ) verifyCommitLightTrustingInternal (
829
+ chainID string ,
830
+ commit * Commit ,
831
+ trustLevel cmtmath.Fraction ,
832
+ countAllSignatures bool ,
833
+ ) error {
776
834
// sanity check
777
835
if trustLevel .Denominator == 0 {
778
836
return errors .New ("trustLevel has zero Denominator" )
@@ -791,8 +849,9 @@ func (vals *ValidatorSet) VerifyCommitLightTrusting(chainID string, commit *Comm
791
849
votingPowerNeeded := totalVotingPowerMulByNumerator / int64 (trustLevel .Denominator )
792
850
793
851
for idx , commitSig := range commit .Signatures {
794
- // No need to verify absent or nil votes.
795
- if ! commitSig .ForBlock () {
852
+ // No need to verify absent or nil votes if not counting all signatures,
853
+ // but need to verify nil votes if counting all signatures.
854
+ if (! countAllSignatures && ! commitSig .ForBlock ()) || (countAllSignatures && commitSig .Absent ()) {
796
855
continue
797
856
}
798
857
@@ -816,12 +875,14 @@ func (vals *ValidatorSet) VerifyCommitLightTrusting(chainID string, commit *Comm
816
875
817
876
talliedVotingPower += val .VotingPower
818
877
819
- if talliedVotingPower > votingPowerNeeded {
878
+ if ! countAllSignatures && talliedVotingPower > votingPowerNeeded {
820
879
return nil
821
880
}
822
881
}
823
882
}
824
-
883
+ if talliedVotingPower > votingPowerNeeded {
884
+ return nil
885
+ }
825
886
return ErrNotEnoughVotingPowerSigned {Got : talliedVotingPower , Needed : votingPowerNeeded }
826
887
}
827
888
0 commit comments