QOL – stop spamming peer list, fix crazy VDF edge case

This commit is contained in:
Cassandra Heart 2023-09-24 23:12:05 -05:00
parent e4d9bcdbf0
commit 5f9c90f284
No known key found for this signature in database
GPG Key ID: 6352152859385958
2 changed files with 15 additions and 13 deletions

View File

@ -48,6 +48,9 @@ func NewClassGroupFromBytesDiscriminant(buf []byte, discriminant *big.Int) (*Cla
a := decodeTwosComplement(buf[:int_size]) a := decodeTwosComplement(buf[:int_size])
b := 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 return NewClassGroupFromAbDiscriminant(a, b, discriminant), true
} }
@ -472,7 +475,7 @@ func EncodeBigIntBigEndian(a *big.Int) []byte {
return signBitFill(encodeTwosComplement(a), int_size) 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) { func extendedGCD(a, b *big.Int) (r, s, t *big.Int) {
//r0, r1 = a, b //r0, r1 = a, b
r0 := new(big.Int).Set(a) 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 return r0, s0, t0
} }
//wrapper around big.Int GCD to allow all input values for GCD // wrapper around big.Int GCD to allow all input values for GCD
//as Golang big.Int GCD requires both a, b > 0 // as Golang big.Int GCD requires both a, b > 0
//If a == b == 0, GCD sets r = 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 = |b|
//If a != 0 and b == 0, GCD sets r = |a| // If a != 0 and b == 0, GCD sets r = |a|
//Otherwise r = GCD(|a|, |b|) // Otherwise r = GCD(|a|, |b|)
func allInputValueGCD(a, b *big.Int) (r *big.Int) { func allInputValueGCD(a, b *big.Int) (r *big.Int) {
if a.Sign() == 0 { if a.Sign() == 0 {
return new(big.Int).Abs(b) 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)) return new(big.Int).GCD(nil, nil, new(big.Int).Abs(a), new(big.Int).Abs(b))
} }
//Solve ax == b mod m for x. // Solve ax == b mod m for x.
//Return s, t where x = s + k * t for integer k yields all solutions. // 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) { func SolveMod(a, b, m *big.Int) (s, t *big.Int, solvable bool) {
//g, d, e = extended_gcd(a, m) //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 :( //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) //e := big.NewInt(0)
//g := new(big.Int).GCD(d, e, a, m) //g := new(big.Int).GCD(d, e, a, m)
g, d, _ := extendedGCD(a, m) g, d, _ := extendedGCD(a, m)
if g.Cmp(big.NewInt(0)) == 0 {
return nil, nil, false
}
//q, r = divmod(b, g) //q, r = divmod(b, g)
r := big.NewInt(1) r := big.NewInt(1)

View File

@ -177,10 +177,6 @@ func (e *MasterClockConsensusEngine) Start() <-chan error {
zap.Int("peer_store_count", e.pubSub.GetPeerstoreCount()), zap.Int("peer_store_count", e.pubSub.GetPeerstoreCount()),
zap.Int("network_peer_count", e.pubSub.GetNetworkPeersCount()), 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) time.Sleep(10 * time.Second)
} }
}() }()