Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix requests (by hash and number) #1741

Merged
merged 1 commit into from
May 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Djadih marked this conversation as resolved.
Show resolved Hide resolved
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
Loading