Skip to content

Commit

Permalink
Merge branch 'main' into pprof-update
Browse files Browse the repository at this point in the history
  • Loading branch information
kiltsonfire authored May 16, 2024
2 parents c8ba197 + e8d6196 commit 3d7182c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion consensus/blake3pow/poem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
2 changes: 1 addition & 1 deletion consensus/progpow/poem.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
13 changes: 10 additions & 3 deletions p2p/node/peerManager/peerManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"maps"
"net"
"reflect"
"runtime/debug"
"strings"
"sync"
Expand Down Expand Up @@ -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
}
Expand Down
8 changes: 4 additions & 4 deletions p2p/node/pubsubManager/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package pubsubManager

import (
"errors"
"math/big"
"strings"

"github.com/dominant-strategies/go-quai/common"
Expand All @@ -17,18 +18,17 @@ const (
C_workObjectType = "blocks"
C_transactionType = "transactions"
C_headerType = "headers"
C_hashType = "hash"
C_workObjectHeaderType = "woHeaders"
)

// gets the name of the topic for the given type of data
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:
Expand Down

0 comments on commit 3d7182c

Please sign in to comment.