mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-18 01:43:47 +00:00
Merge pull request #256 from ethersphere/make-snrs-green-3
configurable EnableMsgEvents ; enable TestDeliveryFromNodes and TestSyncerSimulation
This commit is contained in:
commit
a1e6ff3556
14 changed files with 77 additions and 76 deletions
|
|
@ -219,7 +219,7 @@ func TestVerifyErrors(t *testing.T) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func XTestDeposit(t *testing.T) {
|
func TestDeposit(t *testing.T) {
|
||||||
path0 := filepath.Join(os.TempDir(), "chequebook-test-0.json")
|
path0 := filepath.Join(os.TempDir(), "chequebook-test-0.json")
|
||||||
backend := newTestBackend()
|
backend := newTestBackend()
|
||||||
contr0, _ := deploy(key0, new(big.Int), backend)
|
contr0, _ := deploy(key0, new(big.Int), backend)
|
||||||
|
|
@ -281,8 +281,8 @@ func XTestDeposit(t *testing.T) {
|
||||||
t.Fatalf("expected balance %v, got %v", exp, chbook.Balance())
|
t.Fatalf("expected balance %v, got %v", exp, chbook.Balance())
|
||||||
}
|
}
|
||||||
|
|
||||||
// autodeposit every 30ms if new cheque issued
|
// autodeposit every 200ms if new cheque issued
|
||||||
interval := 30 * time.Millisecond
|
interval := 200 * time.Millisecond
|
||||||
chbook.AutoDeposit(interval, common.Big1, balance)
|
chbook.AutoDeposit(interval, common.Big1, balance)
|
||||||
_, err = chbook.Issue(addr1, amount)
|
_, err = chbook.Issue(addr1, amount)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ func (s *SimAdapter) NewNode(config *NodeConfig) (Node, error) {
|
||||||
MaxPeers: math.MaxInt32,
|
MaxPeers: math.MaxInt32,
|
||||||
NoDiscovery: true,
|
NoDiscovery: true,
|
||||||
Dialer: s,
|
Dialer: s,
|
||||||
EnableMsgEvents: true,
|
EnableMsgEvents: config.EnableMsgEvents,
|
||||||
},
|
},
|
||||||
NoUSB: true,
|
NoUSB: true,
|
||||||
Logger: log.New("node.id", id.String()),
|
Logger: log.New("node.id", id.String()),
|
||||||
|
|
|
||||||
|
|
@ -109,6 +109,7 @@ type nodeConfigJSON struct {
|
||||||
PrivateKey string `json:"private_key"`
|
PrivateKey string `json:"private_key"`
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Services []string `json:"services"`
|
Services []string `json:"services"`
|
||||||
|
EnableMsgEvents bool `json:"enable_msg_events"`
|
||||||
Port uint16 `json:"port"`
|
Port uint16 `json:"port"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,6 +121,7 @@ func (n *NodeConfig) MarshalJSON() ([]byte, error) {
|
||||||
Name: n.Name,
|
Name: n.Name,
|
||||||
Services: n.Services,
|
Services: n.Services,
|
||||||
Port: n.Port,
|
Port: n.Port,
|
||||||
|
EnableMsgEvents: n.EnableMsgEvents,
|
||||||
}
|
}
|
||||||
if n.PrivateKey != nil {
|
if n.PrivateKey != nil {
|
||||||
confJSON.PrivateKey = hex.EncodeToString(crypto.FromECDSA(n.PrivateKey))
|
confJSON.PrivateKey = hex.EncodeToString(crypto.FromECDSA(n.PrivateKey))
|
||||||
|
|
@ -158,6 +160,7 @@ func (n *NodeConfig) UnmarshalJSON(data []byte) error {
|
||||||
n.Name = confJSON.Name
|
n.Name = confJSON.Name
|
||||||
n.Services = confJSON.Services
|
n.Services = confJSON.Services
|
||||||
n.Port = confJSON.Port
|
n.Port = confJSON.Port
|
||||||
|
n.EnableMsgEvents = confJSON.EnableMsgEvents
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
@ -177,8 +180,10 @@ func RandomNodeConfig() *NodeConfig {
|
||||||
}
|
}
|
||||||
return &NodeConfig{
|
return &NodeConfig{
|
||||||
ID: id,
|
ID: id,
|
||||||
|
Name: fmt.Sprintf("node_%s", id.String()),
|
||||||
PrivateKey: key,
|
PrivateKey: key,
|
||||||
Port: port,
|
Port: port,
|
||||||
|
EnableMsgEvents: true,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -561,7 +561,8 @@ func (s *Server) LoadSnapshot(w http.ResponseWriter, req *http.Request) {
|
||||||
|
|
||||||
// CreateNode creates a node in the network using the given configuration
|
// CreateNode creates a node in the network using the given configuration
|
||||||
func (s *Server) CreateNode(w http.ResponseWriter, req *http.Request) {
|
func (s *Server) CreateNode(w http.ResponseWriter, req *http.Request) {
|
||||||
config := adapters.RandomNodeConfig()
|
config := &adapters.NodeConfig{}
|
||||||
|
|
||||||
err := json.NewDecoder(req.Body).Decode(config)
|
err := json.NewDecoder(req.Body).Decode(config)
|
||||||
if err != nil && err != io.EOF {
|
if err != nil && err != io.EOF {
|
||||||
http.Error(w, err.Error(), http.StatusBadRequest)
|
http.Error(w, err.Error(), http.StatusBadRequest)
|
||||||
|
|
|
||||||
|
|
@ -348,7 +348,8 @@ func startTestNetwork(t *testing.T, client *Client) []string {
|
||||||
nodeCount := 2
|
nodeCount := 2
|
||||||
nodeIDs := make([]string, nodeCount)
|
nodeIDs := make([]string, nodeCount)
|
||||||
for i := 0; i < nodeCount; i++ {
|
for i := 0; i < nodeCount; i++ {
|
||||||
node, err := client.CreateNode(nil)
|
config := adapters.RandomNodeConfig()
|
||||||
|
node, err := client.CreateNode(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error creating node: %s", err)
|
t.Fatalf("error creating node: %s", err)
|
||||||
}
|
}
|
||||||
|
|
@ -527,7 +528,9 @@ func TestHTTPNodeRPC(t *testing.T) {
|
||||||
|
|
||||||
// start a node in the network
|
// start a node in the network
|
||||||
client := NewClient(s.URL)
|
client := NewClient(s.URL)
|
||||||
node, err := client.CreateNode(nil)
|
|
||||||
|
config := adapters.RandomNodeConfig()
|
||||||
|
node, err := client.CreateNode(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error creating node: %s", err)
|
t.Fatalf("error creating node: %s", err)
|
||||||
}
|
}
|
||||||
|
|
@ -589,7 +592,8 @@ func TestHTTPSnapshot(t *testing.T) {
|
||||||
nodeCount := 2
|
nodeCount := 2
|
||||||
nodes := make([]*p2p.NodeInfo, nodeCount)
|
nodes := make([]*p2p.NodeInfo, nodeCount)
|
||||||
for i := 0; i < nodeCount; i++ {
|
for i := 0; i < nodeCount; i++ {
|
||||||
node, err := client.CreateNode(nil)
|
config := adapters.RandomNodeConfig()
|
||||||
|
node, err := client.CreateNode(config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error creating node: %s", err)
|
t.Fatalf("error creating node: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,7 @@ import (
|
||||||
|
|
||||||
"github.com/ethereum/go-ethereum/log"
|
"github.com/ethereum/go-ethereum/log"
|
||||||
"github.com/ethereum/go-ethereum/p2p/discover"
|
"github.com/ethereum/go-ethereum/p2p/discover"
|
||||||
|
"github.com/ethereum/go-ethereum/p2p/simulations/adapters"
|
||||||
)
|
)
|
||||||
|
|
||||||
//a map of mocker names to its function
|
//a map of mocker names to its function
|
||||||
|
|
@ -165,7 +166,8 @@ func probabilistic(net *Network, quit chan struct{}, nodeCount int) {
|
||||||
func connectNodesInRing(net *Network, nodeCount int) ([]discover.NodeID, error) {
|
func connectNodesInRing(net *Network, nodeCount int) ([]discover.NodeID, error) {
|
||||||
ids := make([]discover.NodeID, nodeCount)
|
ids := make([]discover.NodeID, nodeCount)
|
||||||
for i := 0; i < nodeCount; i++ {
|
for i := 0; i < nodeCount; i++ {
|
||||||
node, err := net.NewNode()
|
conf := adapters.RandomNodeConfig()
|
||||||
|
node, err := net.NewNodeWithConfig(conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("Error creating a node! %s", err)
|
log.Error("Error creating a node! %s", err)
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|
|
||||||
|
|
@ -78,26 +78,12 @@ func (self *Network) Events() *event.Feed {
|
||||||
return &self.events
|
return &self.events
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewNode adds a new node to the network with a random ID
|
|
||||||
func (self *Network) NewNode() (*Node, error) {
|
|
||||||
conf := adapters.RandomNodeConfig()
|
|
||||||
conf.Services = []string{self.DefaultService}
|
|
||||||
return self.NewNodeWithConfig(conf)
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewNodeWithConfig adds a new node to the network with the given config,
|
// NewNodeWithConfig adds a new node to the network with the given config,
|
||||||
// returning an error if a node with the same ID or name already exists
|
// returning an error if a node with the same ID or name already exists
|
||||||
func (self *Network) NewNodeWithConfig(conf *adapters.NodeConfig) (*Node, error) {
|
func (self *Network) NewNodeWithConfig(conf *adapters.NodeConfig) (*Node, error) {
|
||||||
self.lock.Lock()
|
self.lock.Lock()
|
||||||
defer self.lock.Unlock()
|
defer self.lock.Unlock()
|
||||||
|
|
||||||
// create a random ID and PrivateKey if not set
|
|
||||||
if conf.ID == (discover.NodeID{}) {
|
|
||||||
c := adapters.RandomNodeConfig()
|
|
||||||
conf.ID = c.ID
|
|
||||||
conf.PrivateKey = c.PrivateKey
|
|
||||||
}
|
|
||||||
id := conf.ID
|
|
||||||
if conf.Reachable == nil {
|
if conf.Reachable == nil {
|
||||||
conf.Reachable = func(otherID discover.NodeID) bool {
|
conf.Reachable = func(otherID discover.NodeID) bool {
|
||||||
_, err := self.InitConn(conf.ID, otherID)
|
_, err := self.InitConn(conf.ID, otherID)
|
||||||
|
|
@ -105,14 +91,9 @@ func (self *Network) NewNodeWithConfig(conf *adapters.NodeConfig) (*Node, error)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// assign a name to the node if not set
|
|
||||||
if conf.Name == "" {
|
|
||||||
conf.Name = fmt.Sprintf("node%02d", len(self.Nodes)+1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// check the node doesn't already exist
|
// check the node doesn't already exist
|
||||||
if node := self.getNode(id); node != nil {
|
if node := self.getNode(conf.ID); node != nil {
|
||||||
return nil, fmt.Errorf("node with ID %q already exists", id)
|
return nil, fmt.Errorf("node with ID %q already exists", conf.ID)
|
||||||
}
|
}
|
||||||
if node := self.getNodeByName(conf.Name); node != nil {
|
if node := self.getNodeByName(conf.Name); node != nil {
|
||||||
return nil, fmt.Errorf("node with name %q already exists", conf.Name)
|
return nil, fmt.Errorf("node with name %q already exists", conf.Name)
|
||||||
|
|
@ -132,8 +113,8 @@ func (self *Network) NewNodeWithConfig(conf *adapters.NodeConfig) (*Node, error)
|
||||||
Node: adapterNode,
|
Node: adapterNode,
|
||||||
Config: conf,
|
Config: conf,
|
||||||
}
|
}
|
||||||
log.Trace(fmt.Sprintf("node %v created", id))
|
log.Trace(fmt.Sprintf("node %v created", conf.ID))
|
||||||
self.nodeMap[id] = len(self.Nodes)
|
self.nodeMap[conf.ID] = len(self.Nodes)
|
||||||
self.Nodes = append(self.Nodes, node)
|
self.Nodes = append(self.Nodes, node)
|
||||||
|
|
||||||
// emit a "control" event
|
// emit a "control" event
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,8 @@ func TestNetworkSimulation(t *testing.T) {
|
||||||
nodeCount := 20
|
nodeCount := 20
|
||||||
ids := make([]discover.NodeID, nodeCount)
|
ids := make([]discover.NodeID, nodeCount)
|
||||||
for i := 0; i < nodeCount; i++ {
|
for i := 0; i < nodeCount; i++ {
|
||||||
node, err := network.NewNode()
|
conf := adapters.RandomNodeConfig()
|
||||||
|
node, err := network.NewNodeWithConfig(conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("error creating node: %s", err)
|
t.Fatalf("error creating node: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -164,7 +164,8 @@ func discoverySimulation(nodes, conns int, adapter adapters.NodeAdapter) (*simul
|
||||||
trigger := make(chan discover.NodeID)
|
trigger := make(chan discover.NodeID)
|
||||||
ids := make([]discover.NodeID, nodes)
|
ids := make([]discover.NodeID, nodes)
|
||||||
for i := 0; i < nodes; i++ {
|
for i := 0; i < nodes; i++ {
|
||||||
node, err := net.NewNode()
|
conf := adapters.RandomNodeConfig()
|
||||||
|
node, err := net.NewNodeWithConfig(conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error starting node: %s", err)
|
return nil, fmt.Errorf("error starting node: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -306,7 +306,7 @@ func TestStreamerDownstreamChunkDeliveryMsgExchange(t *testing.T) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func XTestDeliveryFromNodes(t *testing.T) {
|
func TestDeliveryFromNodes(t *testing.T) {
|
||||||
testDeliveryFromNodes(t, 2, 1, dataChunkCount, true)
|
testDeliveryFromNodes(t, 2, 1, dataChunkCount, true)
|
||||||
testDeliveryFromNodes(t, 2, 1, dataChunkCount, false)
|
testDeliveryFromNodes(t, 2, 1, dataChunkCount, false)
|
||||||
testDeliveryFromNodes(t, 4, 1, dataChunkCount, true)
|
testDeliveryFromNodes(t, 4, 1, dataChunkCount, true)
|
||||||
|
|
@ -326,6 +326,7 @@ func testDeliveryFromNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck
|
||||||
ConnLevel: conns,
|
ConnLevel: conns,
|
||||||
ToAddr: toAddr,
|
ToAddr: toAddr,
|
||||||
Services: services,
|
Services: services,
|
||||||
|
EnableMsgEvents: false,
|
||||||
}
|
}
|
||||||
|
|
||||||
sim, teardown, err := streamTesting.NewSimulation(conf)
|
sim, teardown, err := streamTesting.NewSimulation(conf)
|
||||||
|
|
@ -500,6 +501,7 @@ func benchmarkDeliveryFromNodes(b *testing.B, nodes, conns, chunkCount int, skip
|
||||||
ConnLevel: conns,
|
ConnLevel: conns,
|
||||||
ToAddr: toAddr,
|
ToAddr: toAddr,
|
||||||
Services: services,
|
Services: services,
|
||||||
|
EnableMsgEvents: false,
|
||||||
}
|
}
|
||||||
sim, teardown, err := streamTesting.NewSimulation(conf)
|
sim, teardown, err := streamTesting.NewSimulation(conf)
|
||||||
defer teardown()
|
defer teardown()
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ import (
|
||||||
|
|
||||||
const dataChunkCount = 500
|
const dataChunkCount = 500
|
||||||
|
|
||||||
func XTestSyncerSimulation(t *testing.T) {
|
func TestSyncerSimulation(t *testing.T) {
|
||||||
testSyncBetweenNodes(t, 2, 1, dataChunkCount, true, 1)
|
testSyncBetweenNodes(t, 2, 1, dataChunkCount, true, 1)
|
||||||
testSyncBetweenNodes(t, 4, 1, dataChunkCount, true, 1)
|
testSyncBetweenNodes(t, 4, 1, dataChunkCount, true, 1)
|
||||||
testSyncBetweenNodes(t, 8, 1, dataChunkCount, true, 1)
|
testSyncBetweenNodes(t, 8, 1, dataChunkCount, true, 1)
|
||||||
|
|
@ -56,6 +56,7 @@ func testSyncBetweenNodes(t *testing.T, nodes, conns, chunkCount int, skipCheck
|
||||||
ConnLevel: conns,
|
ConnLevel: conns,
|
||||||
ToAddr: toAddr,
|
ToAddr: toAddr,
|
||||||
Services: services,
|
Services: services,
|
||||||
|
EnableMsgEvents: false,
|
||||||
}
|
}
|
||||||
// create context for simulation run
|
// create context for simulation run
|
||||||
timeout := 30 * time.Second
|
timeout := 30 * time.Second
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,7 @@ type RunConfig struct {
|
||||||
ConnLevel int
|
ConnLevel int
|
||||||
ToAddr func(discover.NodeID) *network.BzzAddr
|
ToAddr func(discover.NodeID) *network.BzzAddr
|
||||||
Services adapters.Services
|
Services adapters.Services
|
||||||
|
EnableMsgEvents bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewSimulation(conf *RunConfig) (*Simulation, func(), error) {
|
func NewSimulation(conf *RunConfig) (*Simulation, func(), error) {
|
||||||
|
|
@ -144,7 +145,9 @@ func NewSimulation(conf *RunConfig) (*Simulation, func(), error) {
|
||||||
addrs := make([]network.Addr, nodes)
|
addrs := make([]network.Addr, nodes)
|
||||||
// start nodes
|
// start nodes
|
||||||
for i := 0; i < nodes; i++ {
|
for i := 0; i < nodes; i++ {
|
||||||
node, err := net.NewNode()
|
nodeconf := adapters.RandomNodeConfig()
|
||||||
|
nodeconf.EnableMsgEvents = conf.EnableMsgEvents
|
||||||
|
node, err := net.NewNodeWithConfig(nodeconf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, teardown, fmt.Errorf("error creating node: %s", err)
|
return nil, teardown, fmt.Errorf("error creating node: %s", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -180,9 +180,9 @@ func setupNetwork(numnodes int) (clients []*rpc.Client, err error) {
|
||||||
DefaultService: "bzz",
|
DefaultService: "bzz",
|
||||||
})
|
})
|
||||||
for i := 0; i < numnodes; i++ {
|
for i := 0; i < numnodes; i++ {
|
||||||
nodes[i], err = net.NewNodeWithConfig(&adapters.NodeConfig{
|
nodeconf := adapters.RandomNodeConfig()
|
||||||
Services: []string{"bzz", "pss"},
|
nodeconf.Services = []string{"bzz", "pss"}
|
||||||
})
|
nodes[i], err = net.NewNodeWithConfig(nodeconf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error creating node 1: %v", err)
|
return nil, fmt.Errorf("error creating node 1: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1081,9 +1081,9 @@ func setupNetwork(numnodes int) (clients []*rpc.Client, err error) {
|
||||||
DefaultService: "bzz",
|
DefaultService: "bzz",
|
||||||
})
|
})
|
||||||
for i := 0; i < numnodes; i++ {
|
for i := 0; i < numnodes; i++ {
|
||||||
nodes[i], err = net.NewNodeWithConfig(&adapters.NodeConfig{
|
nodeconf := adapters.RandomNodeConfig()
|
||||||
Services: []string{"bzz", pssProtocolName},
|
nodeconf.Services = []string{"bzz", pssProtocolName}
|
||||||
})
|
nodes[i], err = net.NewNodeWithConfig(nodeconf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("error creating node 1: %v", err)
|
return nil, fmt.Errorf("error creating node 1: %v", err)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue