mirror of
https://source.quilibrium.com/quilibrium/ceremonyclient.git
synced 2024-11-20 15:15:18 +00:00
QOL – stop spamming peer list, fix crazy VDF edge case
This commit is contained in:
parent
e4d9bcdbf0
commit
5f9c90f284
@ -48,6 +48,9 @@ func NewClassGroupFromBytesDiscriminant(buf []byte, discriminant *big.Int) (*Cla
|
||||
|
||||
a := decodeTwosComplement(buf[:int_size])
|
||||
b := decodeTwosComplement(buf[int_size:])
|
||||
if a.Cmp(big.NewInt(0)) == 0 {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
return NewClassGroupFromAbDiscriminant(a, b, discriminant), true
|
||||
}
|
||||
@ -472,7 +475,7 @@ func EncodeBigIntBigEndian(a *big.Int) []byte {
|
||||
return signBitFill(encodeTwosComplement(a), int_size)
|
||||
}
|
||||
|
||||
//Return r, s, t such that gcd(a, b) = r = a * s + b * t
|
||||
// Return r, s, t such that gcd(a, b) = r = a * s + b * t
|
||||
func extendedGCD(a, b *big.Int) (r, s, t *big.Int) {
|
||||
//r0, r1 = a, b
|
||||
r0 := new(big.Int).Set(a)
|
||||
@ -519,12 +522,12 @@ func extendedGCD(a, b *big.Int) (r, s, t *big.Int) {
|
||||
return r0, s0, t0
|
||||
}
|
||||
|
||||
//wrapper around big.Int GCD to allow all input values for GCD
|
||||
//as Golang big.Int GCD requires both a, b > 0
|
||||
//If a == b == 0, GCD sets r = 0.
|
||||
//If a == 0 and b != 0, GCD sets r = |b|
|
||||
//If a != 0 and b == 0, GCD sets r = |a|
|
||||
//Otherwise r = GCD(|a|, |b|)
|
||||
// wrapper around big.Int GCD to allow all input values for GCD
|
||||
// as Golang big.Int GCD requires both a, b > 0
|
||||
// If a == b == 0, GCD sets r = 0.
|
||||
// If a == 0 and b != 0, GCD sets r = |b|
|
||||
// If a != 0 and b == 0, GCD sets r = |a|
|
||||
// Otherwise r = GCD(|a|, |b|)
|
||||
func allInputValueGCD(a, b *big.Int) (r *big.Int) {
|
||||
if a.Sign() == 0 {
|
||||
return new(big.Int).Abs(b)
|
||||
@ -537,8 +540,8 @@ func allInputValueGCD(a, b *big.Int) (r *big.Int) {
|
||||
return new(big.Int).GCD(nil, nil, new(big.Int).Abs(a), new(big.Int).Abs(b))
|
||||
}
|
||||
|
||||
//Solve ax == b mod m for x.
|
||||
//Return s, t where x = s + k * t for integer k yields all solutions.
|
||||
// Solve ax == b mod m for x.
|
||||
// Return s, t where x = s + k * t for integer k yields all solutions.
|
||||
func SolveMod(a, b, m *big.Int) (s, t *big.Int, solvable bool) {
|
||||
//g, d, e = extended_gcd(a, m)
|
||||
//TODO: golang 1.x big.int GCD requires both a > 0 and m > 0, so we can't use it :(
|
||||
@ -546,6 +549,9 @@ func SolveMod(a, b, m *big.Int) (s, t *big.Int, solvable bool) {
|
||||
//e := big.NewInt(0)
|
||||
//g := new(big.Int).GCD(d, e, a, m)
|
||||
g, d, _ := extendedGCD(a, m)
|
||||
if g.Cmp(big.NewInt(0)) == 0 {
|
||||
return nil, nil, false
|
||||
}
|
||||
|
||||
//q, r = divmod(b, g)
|
||||
r := big.NewInt(1)
|
||||
|
@ -177,10 +177,6 @@ func (e *MasterClockConsensusEngine) Start() <-chan error {
|
||||
zap.Int("peer_store_count", e.pubSub.GetPeerstoreCount()),
|
||||
zap.Int("network_peer_count", e.pubSub.GetNetworkPeersCount()),
|
||||
)
|
||||
e.logger.Info(
|
||||
"peers by bitmask",
|
||||
zap.Any("peers", e.pubSub.GetBitmaskPeers()),
|
||||
)
|
||||
time.Sleep(10 * time.Second)
|
||||
}
|
||||
}()
|
||||
|
Loading…
Reference in New Issue
Block a user