The aim is to fully simulate devp2p networks, manage connections between nodes and record interactions in a replayable journal.
A simulation framework is currently in progress on the network-testing-framework branch and currently includes the following packages:
An adapter is responsible for creating nodes and connecting them together, examples being:
inproc- creates in-memory simulator nodes and connects them with in-memory pipesrlpx- createsp2p.Servernodes and connects them using TCP connectionsdocker- starts Docker containers and connects them using ssh+ipc connections
Provides an interface to simplify defining sub-protocols to run on devp2p, abstracting away the following:
- provide the forever loop to read incoming messages
- automatic RLP encoding / decoding of protocol messages
- standardise error handling related to communication
See this test protocol.
Implements an event-based simulation Network which accepts incoming events to
manage nodes using an adapter and send messages between nodes, and outputs
simulation events to subscribers.
Example events:
node up- a new node has startednode down- a node has gone downconn up- a connection has been established between two nodesconn down- a connection has been severed between two nodesmsg- a message has been sent between two nodes
A Journal is a network subscriber which records events which can then be
replayed into a new network simulation.
p2psim is a simulator REPL to perform in-memory simulations, currently
implementing the following commands:
p2psim> help
add add new node
start <node> start <node>
stop <node> stop <node>
connect <nodeA> <nodeB> connect <nodeA> with <nodeB>
disconnect <nodeA> <nodeB> disconnect <nodeA> from <nodeB>
list list nodes
info <node> display info on <node>
help show usage
exit exit the simulator
A sample session:
p2psim> add
added node1 (049ffad1729ebd43e5a44b7127f9aaabf0f6a5a20848837db6b4639876b5c4bd11591d46de15bde0570fe1a26716209c1502e33a0bcdc7dafb4a67447d775138)
p2psim> add
added node2 (a21cd8771c9b6a15713b0cb042c646833dc978b5a049ca151488a5dc704b7770c9cf33c8cfc5521121fbbab09d1d3f82d635cf6419da51297d8a71a3a9853a62)
p2psim> add
added node3 (d09d6e2077f0527a97bb7347783182a8e1ba8020885ba85f970f9c72307db5b3c6f5af34b652def7342781781e2e3cb26cb103e3254c4ffa66a8865c4d1d9126)
p2psim> list
NAME UP ID
node1 false 049ffad1729ebd43e5a44b7127f9aaabf0f6a5a20848837db6b4639876b5c4bd11591d46de15bde0570fe1a26716209c1502e33a0bcdc7dafb4a67447d775138
node2 false a21cd8771c9b6a15713b0cb042c646833dc978b5a049ca151488a5dc704b7770c9cf33c8cfc5521121fbbab09d1d3f82d635cf6419da51297d8a71a3a9853a62
node3 false d09d6e2077f0527a97bb7347783182a8e1ba8020885ba85f970f9c72307db5b3c6f5af34b652def7342781781e2e3cb26cb103e3254c4ffa66a8865c4d1d9126
p2psim> start node1
started node1 (049ffad1729ebd43e5a44b7127f9aaabf0f6a5a20848837db6b4639876b5c4bd11591d46de15bde0570fe1a26716209c1502e33a0bcdc7dafb4a67447d775138)
p2psim> start node3
started node3 (d09d6e2077f0527a97bb7347783182a8e1ba8020885ba85f970f9c72307db5b3c6f5af34b652def7342781781e2e3cb26cb103e3254c4ffa66a8865c4d1d9126)
p2psim> connect node1 node3
connected node1 to node3
p2psim> info node1
ID 049ffad1729ebd43e5a44b7127f9aaabf0f6a5a20848837db6b4639876b5c4bd11591d46de15bde0570fe1a26716209c1502e33a0bcdc7dafb4a67447d775138
Up true
- update
simulations.Networkto handle message events - implement remote node adapters (
rlpx/docker) with event subscriptions - run protocols in
p2psim - journal support in
p2psim(e.g.load <journal>,save <journal>) - add a logical clock to allow the simulation to be paused / resumed and tests to wait for logical clock durations before making assertions
- add
nextandstep <n>commands top2psimto step through a discrete number of events - implement
p2psimscripts for writing full network simulation scenarios - add VM adapters to create more realistic networks (e.g. KVM / AWS / Azure)