Skip to content

Commit

Permalink
chore: revert back changes to fix integration tests (#529)
Browse files Browse the repository at this point in the history
Regression in tests introduced in
#524

Signed-off-by: mudler <mudler@localai.io>
  • Loading branch information
mudler authored Aug 26, 2024
1 parent 00c3918 commit c7ca9d1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 13 deletions.
10 changes: 2 additions & 8 deletions pkg/network/kdht.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import (
"github.com/libp2p/go-libp2p/core/network"
"github.com/libp2p/go-libp2p/core/peer"
"github.com/libp2p/go-libp2p/core/protocol"
"github.com/multiformats/go-multiaddr"
"github.com/sirupsen/logrus"

"github.com/masa-finance/masa-oracle/pkg/config"
"github.com/masa-finance/masa-oracle/pkg/pubsub"
)

Expand All @@ -30,8 +30,7 @@ type dbValidator struct{}
func (dbValidator) Validate(_ string, _ []byte) error { return nil }
func (dbValidator) Select(_ string, _ [][]byte) (int, error) { return 0, nil }

func WithDht(ctx context.Context, host host.Host, protocolId, prefix protocol.ID,
peerChan chan PeerEvent, nodeData *pubsub.NodeData) (*dht.IpfsDHT, error) {
func WithDHT(ctx context.Context, host host.Host, bootstrapNodes []multiaddr.Multiaddr, protocolId, prefix protocol.ID, peerChan chan PeerEvent, nodeData *pubsub.NodeData) (*dht.IpfsDHT, error) {
options := make([]dht.Option, 0)
options = append(options, dht.BucketSize(100)) // Adjust bucket size
options = append(options, dht.Concurrency(100)) // Increase concurrency
Expand All @@ -40,11 +39,6 @@ func WithDht(ctx context.Context, host host.Host, protocolId, prefix protocol.ID
options = append(options, dht.ProtocolPrefix(prefix))
options = append(options, dht.NamespacedValidator("db", dbValidator{}))

bootstrapNodes, err := GetBootNodesMultiAddress(config.GetInstance().Bootnodes)
if err != nil {
return nil, err
}

kademliaDHT, err := dht.New(ctx, host, options...)
if err != nil {
return nil, err
Expand Down
17 changes: 15 additions & 2 deletions pkg/oracle_node.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,25 @@ func (node *OracleNode) Start() (err error) {
go node.ListenToNodeTracker()
go node.handleDiscoveredPeers()

myNodeData := pubsub2.GetSelfNodeData(node.Host, node.IsStaked, node.priorityAddrs)
var publicKeyHex string
if node.options.RandomIdentity {
publicKeyHex, _ = node.generateEthHexKeyForRandomIdentity()
} else {
publicKeyHex = masacrypto.KeyManagerInstance().EthAddress
}

myNodeData := pubsub2.GetSelfNodeData(node.Host, node.IsStaked, node.priorityAddrs, publicKeyHex)

bootstrapNodes, err := myNetwork.GetBootNodesMultiAddress(append(config.GetInstance().Bootnodes, node.options.Bootnodes...))
if err != nil {
return err
}

node.DHT, err = myNetwork.WithDht(node.Context, node.Host, node.Protocol, config.MasaPrefix, node.PeerChan, myNodeData)
node.DHT, err = myNetwork.WithDHT(node.Context, node.Host, bootstrapNodes, node.Protocol, config.MasaPrefix, node.PeerChan, myNodeData)
if err != nil {
return err
}

err = myNetwork.WithMDNS(node.Host, config.Rendezvous, node.PeerChan)
if err != nil {
return err
Expand Down
5 changes: 2 additions & 3 deletions pkg/pubsub/node_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (

"github.com/masa-finance/masa-oracle/internal/versioning"
"github.com/masa-finance/masa-oracle/pkg/config"
"github.com/masa-finance/masa-oracle/pkg/masacrypto"

"github.com/libp2p/go-libp2p/core/host"
"github.com/libp2p/go-libp2p/core/peer"
Expand Down Expand Up @@ -253,9 +252,9 @@ func (n *NodeData) UpdateAccumulatedUptime() {
// It populates a NodeData struct with the node's ID, staking status, and Ethereum address.
// The NodeData struct is then marshalled into a JSON byte array.
// Returns nil if there is an error marshalling to JSON.
func GetSelfNodeData(host host.Host, isStaked bool, addr multiaddr.Multiaddr) *NodeData {
func GetSelfNodeData(host host.Host, isStaked bool, addr multiaddr.Multiaddr, publicEthAddress string) *NodeData {
// Create and populate NodeData
nodeData := NewNodeData(addr, host.ID(), masacrypto.KeyManagerInstance().EthAddress, ActivityJoined)
nodeData := NewNodeData(addr, host.ID(), publicEthAddress, ActivityJoined)
nodeData.MultiaddrsString = addr.String()
nodeData.IsStaked = isStaked
nodeData.IsTwitterScraper = config.GetInstance().TwitterScraper
Expand Down

0 comments on commit c7ca9d1

Please sign in to comment.