Skip to content

Commit

Permalink
Save unit test progress
Browse files Browse the repository at this point in the history
  • Loading branch information
zivkovicmilos committed Nov 16, 2024
1 parent a82475e commit 7c59c13
Show file tree
Hide file tree
Showing 20 changed files with 517 additions and 273 deletions.
3 changes: 1 addition & 2 deletions gno.land/cmd/gnoland/secrets_get.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (
"github.com/gnolang/gno/tm2/pkg/bft/privval"
"github.com/gnolang/gno/tm2/pkg/commands"
osm "github.com/gnolang/gno/tm2/pkg/os"
"github.com/gnolang/gno/tm2/pkg/p2p"
"github.com/gnolang/gno/tm2/pkg/p2p/types"
)

Expand Down Expand Up @@ -200,7 +199,7 @@ func readNodeID(path string) (*nodeIDInfo, error) {

// constructP2PAddress constructs the P2P address other nodes can use
// to connect directly
func constructP2PAddress(nodeID p2p.ID, listenAddress string) string {
func constructP2PAddress(nodeID types.ID, listenAddress string) string {
var (
address string
parts = strings.SplitN(listenAddress, "://", 2)
Expand Down
22 changes: 11 additions & 11 deletions tm2/pkg/bft/mempool/reactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ type mempoolIDs struct {

// Reserve searches for the next unused ID and assigns it to the
// peer.
func (ids *mempoolIDs) ReserveForPeer(peer p2p.Peer) {
func (ids *mempoolIDs) ReserveForPeer(id p2pTypes.ID) {
ids.mtx.Lock()
defer ids.mtx.Unlock()

curID := ids.nextPeerID()
ids.peerMap[peer.ID()] = curID
ids.peerMap[id] = curID
ids.activeIDs[curID] = struct{}{}
}

Expand All @@ -74,23 +74,23 @@ func (ids *mempoolIDs) nextPeerID() uint16 {
}

// Reclaim returns the ID reserved for the peer back to unused pool.
func (ids *mempoolIDs) Reclaim(peer p2p.Peer) {
func (ids *mempoolIDs) Reclaim(id p2pTypes.ID) {
ids.mtx.Lock()
defer ids.mtx.Unlock()

removedID, ok := ids.peerMap[peer.ID()]
removedID, ok := ids.peerMap[id]
if ok {
delete(ids.activeIDs, removedID)
delete(ids.peerMap, peer.ID())
delete(ids.peerMap, id)
}
}

// GetForPeer returns an ID reserved for the peer.
func (ids *mempoolIDs) GetForPeer(peer p2p.Peer) uint16 {
func (ids *mempoolIDs) GetForPeer(id p2pTypes.ID) uint16 {
ids.mtx.RLock()
defer ids.mtx.RUnlock()

return ids.peerMap[peer.ID()]
return ids.peerMap[id]
}

func newMempoolIDs() *mempoolIDs {
Expand Down Expand Up @@ -140,13 +140,13 @@ func (memR *Reactor) GetChannels() []*p2p.ChannelDescriptor {
// AddPeer implements Reactor.
// It starts a broadcast routine ensuring all txs are forwarded to the given peer.
func (memR *Reactor) AddPeer(peer p2p.Peer) {
memR.ids.ReserveForPeer(peer)
memR.ids.ReserveForPeer(peer.ID())
go memR.broadcastTxRoutine(peer)
}

// RemovePeer implements Reactor.
func (memR *Reactor) RemovePeer(peer p2p.Peer, reason interface{}) {
memR.ids.Reclaim(peer)
memR.ids.Reclaim(peer.ID())
// broadcast routine checks if peer is gone and returns
}

Expand All @@ -163,7 +163,7 @@ func (memR *Reactor) Receive(chID byte, src p2p.Peer, msgBytes []byte) {

switch msg := msg.(type) {
case *TxMessage:
peerID := memR.ids.GetForPeer(src)
peerID := memR.ids.GetForPeer(src.ID())
err := memR.mempool.CheckTxWithInfo(msg.Tx, nil, TxInfo{SenderID: peerID})
if err != nil {
memR.Logger.Info("Could not check tx", "tx", txID(msg.Tx), "err", err)
Expand All @@ -185,7 +185,7 @@ func (memR *Reactor) broadcastTxRoutine(peer p2p.Peer) {
return
}

peerID := memR.ids.GetForPeer(peer)
peerID := memR.ids.GetForPeer(peer.ID())
var next *clist.CElement
for {
// In case of both next.NextWaitChan() and peer.Quit() are variable at the same time
Expand Down
Loading

0 comments on commit 7c59c13

Please sign in to comment.