@ -132,9 +132,6 @@ func bumpCount(
return err
return err
}
}
utils . Logger ( ) . Info ( ) . RawJSON ( "validator" , [ ] byte ( wrapper . String ( ) ) ) .
Msg ( "about to adjust counters" )
wrapper . Counters . NumBlocksToSign . Add (
wrapper . Counters . NumBlocksToSign . Add (
wrapper . Counters . NumBlocksToSign , common . Big1 ,
wrapper . Counters . NumBlocksToSign , common . Big1 ,
)
)
@ -145,9 +142,6 @@ func bumpCount(
)
)
}
}
utils . Logger ( ) . Info ( ) . RawJSON ( "validator" , [ ] byte ( wrapper . String ( ) ) ) .
Msg ( "bumped signing counters" )
if err := compute ( bc , state , wrapper ) ; err != nil {
if err := compute ( bc , state , wrapper ) ; err != nil {
return err
return err
}
}
@ -168,71 +162,78 @@ func IncrementValidatorSigningCounts(
state * state . DB ,
state * state . DB ,
signers , missing shard . SlotList ,
signers , missing shard . SlotList ,
) error {
) error {
utils . Logger ( ) . Info ( ) .
RawJSON ( "missing" , [ ] byte ( missing . String ( ) ) ) .
Msg ( "signers that did sign" )
utils . Logger ( ) . Info ( ) .
Msg ( "bumping signing counters for non-missing signers" )
if err := bumpCount (
if err := bumpCount (
bc , state , signers , true , staked . LookupSet ,
bc , state , signers , true , staked . LookupSet ,
) ; err != nil {
) ; err != nil {
return err
return err
}
}
utils . Logger ( ) . Info ( ) .
Msg ( "bumping missing signers counters" )
return bumpCount ( bc , state , missing , false , staked . LookupSet )
return bumpCount ( bc , state , missing , false , staked . LookupSet )
}
}
// Reader ..
// Reader ..
type Reader interface {
type Reader interface {
ReadValidatorSnapshot ( addr common . Address ) ( * staking . ValidatorWrapper , error )
ReadValidatorSnapshot (
addr common . Address ,
) ( * staking . ValidatorWrapper , error )
}
}
// compute sets the validator to
// ComputeCurrentSigning returns (signed, toSign, quotient, error)
// inactive and thereby keeping it out of
func ComputeCurrentSigning (
// consideration in the pool of validators for
snapshot , wrapper * staking . ValidatorWrapper ,
// whenever committee selection happens in future, the
) ( * big . Int , * big . Int , numeric . Dec , error ) {
// signing threshold is 66%
func compute (
bc Reader ,
state * state . DB ,
wrapper * staking . ValidatorWrapper ,
) error {
snapshot , err := bc . ReadValidatorSnapshot ( wrapper . Address )
if err != nil {
return err
}
statsNow , snapSigned , snapToSign :=
statsNow , snapSigned , snapToSign :=
wrapper . Counters ,
wrapper . Counters ,
snapshot . Counters . NumBlocksSigned ,
snapshot . Counters . NumBlocksSigned ,
snapshot . Counters . NumBlocksToSign
snapshot . Counters . NumBlocksToSign
utils . Logger ( ) . Info ( ) .
RawJSON ( "snapshot" , [ ] byte ( snapshot . String ( ) ) ) .
RawJSON ( "current" , [ ] byte ( wrapper . String ( ) ) ) .
Msg ( "begin checks for availability" )
signed , toSign :=
signed , toSign :=
new ( big . Int ) . Sub ( statsNow . NumBlocksSigned , snapSigned ) ,
new ( big . Int ) . Sub ( statsNow . NumBlocksSigned , snapSigned ) ,
new ( big . Int ) . Sub ( statsNow . NumBlocksToSign , snapToSign )
new ( big . Int ) . Sub ( statsNow . NumBlocksToSign , snapToSign )
if signed . Sign ( ) == - 1 {
if signed . Sign ( ) == - 1 {
return errors . Wrapf (
return nil , nil , numeric . ZeroDec ( ) , errors . Wrapf (
errNegativeSign , "diff for signed period wrong: stat %s, snapshot %s" ,
errNegativeSign , "diff for signed period wrong: stat %s, snapshot %s" ,
statsNow . NumBlocksSigned . String ( ) , snapSigned . String ( ) ,
statsNow . NumBlocksSigned . String ( ) , snapSigned . String ( ) ,
)
)
}
}
if toSign . Sign ( ) == - 1 {
if toSign . Sign ( ) == - 1 {
return errors . Wrapf (
return nil , nil , numeric . ZeroDec ( ) , errors . Wrapf (
errNegativeSign , "diff for toSign period wrong: stat %s, snapshot %s" ,
errNegativeSign , "diff for toSign period wrong: stat %s, snapshot %s" ,
statsNow . NumBlocksToSign . String ( ) , snapToSign . String ( ) ,
statsNow . NumBlocksToSign . String ( ) , snapToSign . String ( ) ,
)
)
}
}
s1 , s2 :=
numeric . NewDecFromBigInt ( signed ) , numeric . NewDecFromBigInt ( toSign )
quotient := s1 . Quo ( s2 )
return signed , toSign , quotient , nil
}
// IsBelowSigningThreshold ..
func IsBelowSigningThreshold ( quotient numeric . Dec ) bool {
return quotient . LTE ( measure )
}
// compute sets the validator to
// inactive and thereby keeping it out of
// consideration in the pool of validators for
// whenever committee selection happens in future, the
// signing threshold is 66%
func compute (
bc Reader ,
state * state . DB ,
wrapper * staking . ValidatorWrapper ,
) error {
utils . Logger ( ) . Info ( ) . Msg ( "begin compute for availability" )
snapshot , err := bc . ReadValidatorSnapshot ( wrapper . Address )
if err != nil {
return err
}
signed , toSign , quotient , err := ComputeCurrentSigning ( snapshot , wrapper )
if toSign . Cmp ( common . Big0 ) == 0 {
if toSign . Cmp ( common . Big0 ) == 0 {
utils . Logger ( ) . Info ( ) .
utils . Logger ( ) . Info ( ) .
RawJSON ( "snapshot" , [ ] byte ( snapshot . String ( ) ) ) .
RawJSON ( "snapshot" , [ ] byte ( snapshot . String ( ) ) ) .
@ -241,22 +242,22 @@ func compute(
return nil
return nil
}
}
s1 , s2 :=
if err != nil {
numeric . NewDecFromBigInt ( signed ) , numeric . NewDecFromBigInt ( toSign )
return err
quotient := s1 . Quo ( s2 )
}
utils . Logger ( ) . Info ( ) .
utils . Logger ( ) . Info ( ) .
RawJSON ( "snapshot" , [ ] byte ( snapshot . String ( ) ) ) .
RawJSON ( "snapshot" , [ ] byte ( snapshot . String ( ) ) ) .
RawJSON ( "current" , [ ] byte ( wrapper . String ( ) ) ) .
RawJSON ( "current" , [ ] byte ( wrapper . String ( ) ) ) .
Str ( "signed" , s1 . String ( ) ) .
Str ( "signed" , signed . String ( ) ) .
Str ( "to-sign" , s2 . String ( ) ) .
Str ( "to-sign" , toSign . String ( ) ) .
Str ( "percentage-signed" , quotient . String ( ) ) .
Str ( "percentage-signed" , quotient . String ( ) ) .
Bool ( "meets-threshold" , quotient . LTE ( measure ) ) .
Bool ( "meets-threshold" , quotient . LTE ( measure ) ) .
Msg ( "check if signing percent is meeting required threshold" )
Msg ( "check if signing percent is meeting required threshold" )
const missedTooManyBlocks = true
const missedTooManyBlocks = true
switch quotient . LTE ( measure ) {
switch IsBelowSigningThreshold ( quotient ) {
case missedTooManyBlocks :
case missedTooManyBlocks :
wrapper . Active = false
wrapper . Active = false
utils . Logger ( ) . Info ( ) .
utils . Logger ( ) . Info ( ) .