forked from tendermint/tendermint
-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mempool: add a safety check, write tests for mempoolIDs (tendermint#3487
) * mempool: add a safety check, write tests for mempoolIDs and document 65536 limit in the mempool reactor spec follow-up to tendermint#2778 * rename the test * fixes after Ismail's review
- Loading branch information
Showing
8 changed files
with
140 additions
and
159 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package mock | ||
|
||
import ( | ||
"net" | ||
|
||
"github.com/tendermint/tendermint/crypto/ed25519" | ||
cmn "github.com/tendermint/tendermint/libs/common" | ||
"github.com/tendermint/tendermint/p2p" | ||
"github.com/tendermint/tendermint/p2p/conn" | ||
) | ||
|
||
type Peer struct { | ||
*cmn.BaseService | ||
ip net.IP | ||
id p2p.ID | ||
addr *p2p.NetAddress | ||
kv map[string]interface{} | ||
Outbound, Persistent bool | ||
} | ||
|
||
// NewPeer creates and starts a new mock peer. If the ip | ||
// is nil, random routable address is used. | ||
func NewPeer(ip net.IP) *Peer { | ||
var netAddr *p2p.NetAddress | ||
if ip == nil { | ||
_, netAddr = p2p.CreateRoutableAddr() | ||
} else { | ||
netAddr = p2p.NewNetAddressIPPort(ip, 26656) | ||
} | ||
nodeKey := p2p.NodeKey{PrivKey: ed25519.GenPrivKey()} | ||
netAddr.ID = nodeKey.ID() | ||
mp := &Peer{ | ||
ip: ip, | ||
id: nodeKey.ID(), | ||
addr: netAddr, | ||
kv: make(map[string]interface{}), | ||
} | ||
mp.BaseService = cmn.NewBaseService(nil, "MockPeer", mp) | ||
mp.Start() | ||
return mp | ||
} | ||
|
||
func (mp *Peer) FlushStop() { mp.Stop() } | ||
func (mp *Peer) TrySend(chID byte, msgBytes []byte) bool { return true } | ||
func (mp *Peer) Send(chID byte, msgBytes []byte) bool { return true } | ||
func (mp *Peer) NodeInfo() p2p.NodeInfo { | ||
return p2p.DefaultNodeInfo{ | ||
ID_: mp.addr.ID, | ||
ListenAddr: mp.addr.DialString(), | ||
} | ||
} | ||
func (mp *Peer) Status() conn.ConnectionStatus { return conn.ConnectionStatus{} } | ||
func (mp *Peer) ID() p2p.ID { return mp.id } | ||
func (mp *Peer) IsOutbound() bool { return mp.Outbound } | ||
func (mp *Peer) IsPersistent() bool { return mp.Persistent } | ||
func (mp *Peer) Get(key string) interface{} { | ||
if value, ok := mp.kv[key]; ok { | ||
return value | ||
} | ||
return nil | ||
} | ||
func (mp *Peer) Set(key string, value interface{}) { | ||
mp.kv[key] = value | ||
} | ||
func (mp *Peer) RemoteIP() net.IP { return mp.ip } | ||
func (mp *Peer) OriginalAddr() *p2p.NetAddress { return mp.addr } | ||
func (mp *Peer) RemoteAddr() net.Addr { return &net.TCPAddr{IP: mp.ip, Port: 8800} } | ||
func (mp *Peer) CloseConn() error { return nil } |
Oops, something went wrong.