From 4141ac51fae77a7ac29bd179c9dc1b08678c1dc2 Mon Sep 17 00:00:00 2001 From: wizeguyy Date: Wed, 15 May 2024 15:09:57 -0500 Subject: [PATCH 1/2] Quo() -> Div() --- consensus/blake3pow/poem.go | 2 +- consensus/progpow/poem.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/consensus/blake3pow/poem.go b/consensus/blake3pow/poem.go index 55893e1c6f..630fd031f9 100644 --- a/consensus/blake3pow/poem.go +++ b/consensus/blake3pow/poem.go @@ -198,7 +198,7 @@ func (blake3pow *Blake3pow) WorkShareLogS(wo *types.WorkObject) (*big.Int, error cBigBits := blake3pow.IntrinsicLogS(powHash) thresholdBigBits := blake3pow.IntrinsicLogS(common.BytesToHash(target.Bytes())) wsEntropy = new(big.Int).Sub(thresholdBigBits, cBigBits) - extraBits := new(big.Int).Quo(wsEntropy, new(big.Int).Exp(big.NewInt(2), big.NewInt(int64(mantBits)), nil)) + extraBits := new(big.Int).Div(wsEntropy, new(big.Int).Exp(big.NewInt(2), big.NewInt(int64(mantBits)), nil)) wsEntropy = new(big.Int).Div(wsEntropy, new(big.Int).Exp(big.NewInt(2), new(big.Int).Add(extraBits, big.NewInt(1)), nil)) } else { wsEntropy = new(big.Int).Set(blake3pow.IntrinsicLogS(powHash)) diff --git a/consensus/progpow/poem.go b/consensus/progpow/poem.go index 2182cfab77..f9780a1523 100644 --- a/consensus/progpow/poem.go +++ b/consensus/progpow/poem.go @@ -197,7 +197,7 @@ func (progpow *Progpow) WorkShareLogS(wo *types.WorkObject) (*big.Int, error) { cBigBits := progpow.IntrinsicLogS(powHash) thresholdBigBits := progpow.IntrinsicLogS(common.BytesToHash(target.Bytes())) wsEntropy = new(big.Int).Sub(thresholdBigBits, cBigBits) - extraBits := new(big.Int).Quo(wsEntropy, new(big.Int).Exp(big.NewInt(2), big.NewInt(int64(mantBits)), nil)) + extraBits := new(big.Int).Div(wsEntropy, new(big.Int).Exp(big.NewInt(2), big.NewInt(int64(mantBits)), nil)) wsEntropy = new(big.Int).Div(wsEntropy, new(big.Int).Exp(big.NewInt(2), new(big.Int).Add(extraBits, big.NewInt(1)), nil)) } else { wsEntropy = new(big.Int).Set(progpow.IntrinsicLogS(powHash)) From e8d619649dd3879daa65a5fa2319056bb51e4b9c Mon Sep 17 00:00:00 2001 From: Hussam Date: Tue, 14 May 2024 14:48:13 -0500 Subject: [PATCH 2/2] Correct the requestByNumber topic --- p2p/node/peerManager/peerManager.go | 13 ++++++++++--- p2p/node/pubsubManager/utils.go | 8 ++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/p2p/node/peerManager/peerManager.go b/p2p/node/peerManager/peerManager.go index be7b443a1d..b5f6019093 100644 --- a/p2p/node/peerManager/peerManager.go +++ b/p2p/node/peerManager/peerManager.go @@ -4,6 +4,7 @@ import ( "context" "maps" "net" + "reflect" "runtime/debug" "strings" "sync" @@ -343,19 +344,25 @@ func (pm *BasicPeerManager) GetPeers(location common.Location, data interface{}, func (pm *BasicPeerManager) queryDHT(location common.Location, data interface{}, peerList map[p2p.PeerID]struct{}, peerCount int) map[p2p.PeerID]struct{} { // create a Cid from the slice location - topicName, _ := pubsubManager.TopicName(pm.genesis, location, data) + topicName, err := pubsubManager.TopicName(pm.genesis, location, data) + if err != nil { + log.Global.WithFields(log.Fields{ + "location": location, + "dataType": reflect.TypeOf(data), + }).Error("Unable to find topic for requested data") + } topicCid := pubsubManager.TopicToCid(topicName) // Internal list of peers from the dht dhtPeers := make(map[p2p.PeerID]struct{}) - log.Global.Infof("Querying DHT for slice Cid %s", topicCid) + log.Global.WithField("topic", topicName).Infof("Querying DHT for topic") // query the DHT for peers in the slice for peer := range pm.dht.FindProvidersAsync(pm.ctx, topicCid, peerCount) { if peer.ID != pm.selfID { dhtPeers[peer.ID] = struct{}{} } } - log.Global.Warn("Found the following peers from the DHT: ", dhtPeers) + log.Global.Info("Found the following peers from the DHT: ", dhtPeers) maps.Copy(peerList, dhtPeers) return peerList } diff --git a/p2p/node/pubsubManager/utils.go b/p2p/node/pubsubManager/utils.go index d934adada0..f7abffe7bc 100644 --- a/p2p/node/pubsubManager/utils.go +++ b/p2p/node/pubsubManager/utils.go @@ -2,6 +2,7 @@ package pubsubManager import ( "errors" + "math/big" "strings" "github.com/dominant-strategies/go-quai/common" @@ -17,7 +18,6 @@ const ( C_workObjectType = "blocks" C_transactionType = "transactions" C_headerType = "headers" - C_hashType = "hash" C_workObjectHeaderType = "woHeaders" ) @@ -25,10 +25,10 @@ const ( func TopicName(genesis common.Hash, location common.Location, data interface{}) (string, error) { baseTopic := strings.Join([]string{genesis.String(), location.Name()}, "/") switch data.(type) { - case *types.WorkObject: + case *types.WorkObject, *big.Int, common.Hash: return strings.Join([]string{baseTopic, C_workObjectType}, "/"), nil - case common.Hash: - return strings.Join([]string{baseTopic, C_hashType}, "/"), nil + case *types.Transaction: + return strings.Join([]string{baseTopic, C_transactionType}, "/"), nil case *types.Transactions: return strings.Join([]string{baseTopic, C_transactionType}, "/"), nil case *types.WorkObjectHeader: