diff --git a/blockchain/bl_pool.go b/blockchain/bl_pool.go index e432ffa..e65d933 100644 --- a/blockchain/bl_pool.go +++ b/blockchain/bl_pool.go @@ -430,14 +430,14 @@ func (bl *FxBlockchain) HandlePoolJoinRequest(ctx context.Context, from peer.ID, } // Call PoolVote method - responseBytes, err := bl.PoolVote(ctx, bl.h.ID(), voteRequest) + responseBody, err := bl.callBlockchain(ctx, "POST", actionPoolVote, voteRequest) if err != nil { - return fmt.Errorf("failed to cast vote: %w", err) + return err } // Interpret the response var voteResponse PoolVoteResponse - if err := json.Unmarshal(responseBytes, &voteResponse); err != nil { + if err := json.Unmarshal(responseBody, &voteResponse); err != nil { return fmt.Errorf("failed to unmarshal vote response: %w", err) } diff --git a/blockchain/blockchain.go b/blockchain/blockchain.go index bd763af..dd1e48e 100644 --- a/blockchain/blockchain.go +++ b/blockchain/blockchain.go @@ -786,7 +786,9 @@ func (bl *FxBlockchain) FetchUsersAndPopulateSets(ctx context.Context, topicStri // Loop through the static relays and convert them to multiaddr for _, relay := range bl.relays { - ma, err := multiaddr.NewMultiaddr(relay + "/p2p-circuit/p2p/" + pid.String()) + fullAddr := relay + "/p2p-circuit/p2p/" + pid.String() + log.Debugw("full relay address", "peer", bl.h.ID(), "for", pid, "fullAddr", fullAddr) + ma, err := multiaddr.NewMultiaddr(fullAddr) if err != nil { bl.membersLock.Unlock() return err @@ -797,12 +799,13 @@ func (bl *FxBlockchain) FetchUsersAndPopulateSets(ctx context.Context, topicStri // Add the relay addresses to the peerstore for the peer ID bl.h.Peerstore().AddAddrs(pid, addrs, peerstore.ConnectedAddrTTL) - log.Debugw("Added peer to peerstore", "h.ID", bl.h.ID(), "pid", pid) + log.Debugw("Added peer to peerstore", "h.ID", bl.h.ID(), "pid", pid, "addrs", addrs) } if pid != bl.h.ID() { //bl.h.Connect(ctx, peer.AddrInfo{ID: pid, Addrs: addrs}) - log.Debugw("Connecting to other peer", "from", bl.h.ID(), "to", pid) - err := bl.h.Connect(ctx, bl.h.Peerstore().PeerInfo(pid)) + peerAddr := bl.h.Peerstore().PeerInfo(pid) + log.Debugw("Connecting to other peer", "from", bl.h.ID(), "to", pid, "with address", peerAddr) + err := bl.h.Connect(ctx, peerAddr) if err != nil { log.Debugw("Not Connected to peer", "from", bl.h.ID(), "to", pid, "err", err) } diff --git a/cmd/test/main.go b/cmd/test/main.go index e7d9c66..6788c97 100644 --- a/cmd/test/main.go +++ b/cmd/test/main.go @@ -31,6 +31,9 @@ func requestLoggerMiddleware(next http.Handler) http.Handler { // Log the request body, _ := io.ReadAll(r.Body) log.Debugw("Received request", "url", r.URL.Path, "method", r.Method, "body", string(body)) + if r.URL.Path == "/fula/pool/vote" { + fmt.Printf("Voted on QmUg1bGBZ1rSNt3LZR7kKf9RDy3JtJLZZDZGKrzSP36TMe %s", string(body)) + } // Create a new io.Reader from the read body as the original body is now drained r.Body = io.NopCloser(bytes.NewBuffer(body)) @@ -386,6 +389,16 @@ func main() { n4.AnnounceJoinPoolRequestPeriodically(ctx) + if err = h1.Connect(ctx, peer.AddrInfo{ID: h2.ID(), Addrs: h2.Addrs()}); err != nil { + panic(err) + } + if err = h1.Connect(ctx, peer.AddrInfo{ID: h3.ID(), Addrs: h3.Addrs()}); err != nil { + panic(err) + } + if err = h1.Connect(ctx, peer.AddrInfo{ID: h4.ID(), Addrs: h4.Addrs()}); err != nil { + panic(err) + } + // Wait until the fourth node discover others for { members := n4.GetBlMembers() @@ -443,6 +456,11 @@ func main() { // - QmUg1bGBZ1rSNt3LZR7kKf9RDy3JtJLZZDZGKrzSP36TMe // - QmaUMRTBMoANXqpUbfARnXkw9esfz9LP2AjXRRr7YknDAT // - QmPNZMi2LAhczsN2FoXXQng6YFYbSHApuP6RpKuHbBH9eF - // Member ID: 12D3KooWACVcVsQh18jM9UudRQzeYEjxCJQJgFUaAgs41tayjxC4, Status: 1 - // Member ID: , Status: 2 + // Member ID: QmUg1bGBZ1rSNt3LZR7kKf9RDy3JtJLZZDZGKrzSP36TMe, Status: 1 + // Member ID: QmYMEnv3GUKPNr34gePX2qQmBH4YEQcuGhQHafuKuujvMA, Status: 2 + // Member ID: QmaUMRTBMoANXqpUbfARnXkw9esfz9LP2AjXRRr7YknDAT, Status: 2 + //Member ID: QmPNZMi2LAhczsN2FoXXQng6YFYbSHApuP6RpKuHbBH9eF, Status: 2 + // Voted on QmUg1bGBZ1rSNt3LZR7kKf9RDy3JtJLZZDZGKrzSP36TMe {"pool_id":1,"account":"QmUg1bGBZ1rSNt3LZR7kKf9RDy3JtJLZZDZGKrzSP36TMe","vote_value":true} + // Voted on QmUg1bGBZ1rSNt3LZR7kKf9RDy3JtJLZZDZGKrzSP36TMe {"pool_id":1,"account":"QmUg1bGBZ1rSNt3LZR7kKf9RDy3JtJLZZDZGKrzSP36TMe","vote_value":true} + // Voted on QmUg1bGBZ1rSNt3LZR7kKf9RDy3JtJLZZDZGKrzSP36TMe {"pool_id":1,"account":"QmUg1bGBZ1rSNt3LZR7kKf9RDy3JtJLZZDZGKrzSP36TMe","vote_value":true} }