Skip to content

Commit

Permalink
Merge pull request #126 from ackintosh/concurrent-requests
Browse files Browse the repository at this point in the history
concurrent requests
  • Loading branch information
ackintosh authored Feb 16, 2024
2 parents 87fefc6 + 5acb48d commit d96207e
Show file tree
Hide file tree
Showing 21 changed files with 2,238 additions and 76 deletions.
154 changes: 106 additions & 48 deletions Cargo.lock

Large diffs are not rendered by default.

24 changes: 20 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,31 @@ name = "discv5-testground"
path = "src/main.rs"

[dependencies]
#discv5 = "0.4.0"

# Change rlp to alloy-rlp
# https://github.com/sigp/discv5/pull/212
discv5 = { git = "https://github.com/armaganyildirak/discv5.git", rev = "f86b64af16bfb74c9252e454d2bd52571e0b69d3" }

# Merge master into discv5.2
# https://github.com/sigp/discv5/pull/234
#discv5 = { git = "https://github.com/ackintosh/discv5.git", rev = "c58677e387f27bd075b671ea5d5410a64ffd9bb4"}

chrono = "0.4.31"
# Speed up ENR update
# https://github.com/sigp/discv5/commit/a9ded0490229418cb61e747d55d3e0879b62e1d7
discv5 = { git = "https://github.com/sigp/discv5.git", rev = "a9ded0490229418cb61e747d55d3e0879b62e1d7" }
rand_xorshift = "0.3.0"
serde = "1.0.193"
serde_json = "1.0.108"
testground = "0.4.0"
tokio = { version = "1.34.0", features = ["macros"] }
tokio-stream = "0.1.14"
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

# *** mock *** ################################################################
aes-gcm = "0.9.4"
rand = "0.8.5"
zeroize = { version = "1.4.3", features = ["zeroize_derive"] }
# This version must be kept up to date do it uses the same dependencies as ENR
hkdf = "0.12.3"
enr = { version = "0.9.0", features = ["k256", "ed25519"] }
# #############################################################################
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ RUN mkdir -p ./plan/src/
RUN echo "fn main() { println!(\"If you see this message, you may want to clean up the target directory or the Docker build cache.\") }" > ./plan/src/main.rs
COPY ./plan/Cargo.lock ./plan/
COPY ./plan/Cargo.toml ./plan/
RUN cd ./plan/ && cargo build --release
RUN cd ./plan/ && cargo build

COPY . .

Expand All @@ -24,6 +24,6 @@ RUN cd plan && cargo install --locked --path .
FROM debian:bullseye-slim
COPY --from=builder /usr/local/cargo/bin/discv5-testground /usr/local/bin/discv5-testground

ENV RUST_LOG=discv5=debug
ENV RUST_LOG=discv5=trace

ENTRYPOINT ["discv5-testground"]
169 changes: 169 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ testground run single \
- [eclipse-attack-monopolizing-by-incoming-nodes](#eclipse-attack-monopolizing-by-incoming-nodes)
- [enr-update](#enr-update)
- [ip-change](#ip-change)
- [concurrent-requests](#concurrent-requests)
- [concurrent-requests_whoareyou-timeout](#concurrent-requests_whoareyou-timeout)
- [concurrent-requests_before-establishing-session](#concurrent-requests_before-establishing-session)
- [talk](#talk)
- [sandbox](#sandbox)

### [`find-node`](#test-cases)

Expand Down Expand Up @@ -148,6 +153,170 @@ sequenceDiagram
end
```

### [`concurrent-requests`](#test-cases)

```shell
testground run single \
--plan=discv5-testground \
--testcase=concurrent-requests \
--builder=docker:generic \
--runner=local:docker \
--instances=2 \
--wait
```

```mermaid
sequenceDiagram
participant Node1
participant Node2
Note over Node1: Start discv5 server
Note over Node2: Start discv5 server
rect rgb(10, 10, 10)
Note left of Node1: They communicate with each other<br> to establish a session.
Node1 ->> Node2: message
Node2 ->> Node1: message
Note over Node1,Node2: Session established
end
rect rgb(100, 100, 0)
Note right of Node2: In this test case, Node2 session timeout <br>is set to short term (a few seconds)<br> to reproduce session expiration.
Note over Node2: Session expired
end
rect rgb(10, 10, 10)
Note left of Node1: Node1 sends multiple requests<br> **in parallel**.
par
Node1 ->> Node2: FINDNODE
and
Node1 ->> Node2: FINDNODE
end
end
```

### [`concurrent-requests_whoareyou-timeout`](#test-cases)

A test case where WHOAREYOU packet times out.

```shell
testground run single \
--plan=discv5-testground \
--testcase=concurrent-requests_whoareyou-timeout \
--builder=docker:generic \
--runner=local:docker \
--instances=2 \
--wait
```

```mermaid
sequenceDiagram
participant Node1
participant Node2
Node2 ->> Node1: Random packet
Node1 ->> Node2: WHOAREYOU
rect rgb(100, 100, 0)
Note over Node2: ** Discard the WHOAREYOU packet<br>to reproduce kind of network issue. **
end
rect rgb(10, 10, 10)
Note left of Node1: Node1 want to send FINDNODE to Node2<br>but active_challenge exists.<br>So insert requests into pending_requests.
par
Note over Node1: pending_requests.insert()
and
Note over Node1: pending_requests.insert()
end
end
rect rgb(100, 100, 0)
Note over Node1: The challenge in active_challenges<br>has been expired.
end
```

### [`concurrent-requests_before-establishing-session`](#test-cases)

A test case where a node attempts to send requests in parallel before establishing a session.

```shell
testground run single \
--plan=discv5-testground \
--testcase=concurrent-requests_before-establishing-session \
--builder=docker:generic \
--runner=local:docker \
--instances=2 \
--wait
```

```mermaid
sequenceDiagram
participant Node1
participant Node2
Note over Node1: No session with Node2
rect rgb(10, 10, 10)
Note left of Node1: Node1 attempts to send multiple requests in parallel <br> but no session with Node2.<br> So Node1 sends a random packet for the first request, <br>and the rest of the requests are inserted into pending_requests.
par
Node1 ->> Node2: Random packet (id:1)
Note over Node1: Insert the request into `active_requests`
and
Note over Node1: Insert Request(id:2) into *pending_requests*
and
Note over Node1: Insert Request(id:3) into *pending_requests*
end
end
Node2 ->> Node1: WHOAREYOU (id:1)
Note over Node1: New session established with Node2
rect rgb(0, 100, 0)
Note over Node1: Send pending requests since a session has been established.
Node1 ->> Node2: Request (id:2)
Node1 ->> Node2: Request (id:3)
end
Node1 ->> Node2: Handshake message (id:1)
Note over Node2: New session established with Node1
Node2 ->> Node1: Response (id:2)
Node2 ->> Node1: Response (id:3)
Node2 ->> Node1: Response (id:1)
Note over Node1: The request (id:2) completed.
Note over Node1: The request (id:3) completed.
Note over Node1: The request (id:1) completed.
```

### [`talk`](#test-cases)

This test plan runs simple TALKREQ/TALKRESP communication between two nodes.

```shell
testground run single \
--plan=discv5-testground \
--testcase=talk \
--builder=docker:generic \
--runner=local:docker \
--instances=2 \
--wait
```

### [`sandbox`](#test-cases)

This is a special test plan where the test flow is undefined, used for experiments to debug.

```shell
testground run single \
--plan=discv5-testground \
--testcase=sandbox \
--builder=docker:generic \
--runner=local:docker \
--instances=2 \
--wait
```

## Metrics

Metrics are stored into the metrics store, InfluxDB. The metrics can be visualized with Grafana, bundled with Testground.
Expand Down
54 changes: 54 additions & 0 deletions manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ enabled = true
[runners."local:docker"]
enabled = true

# #############################################################################
# FINDNODE
# #############################################################################
[[testcases]]
name = "find-node"
instances = { min = 3, max = 100, default = 3 }

[testcases.params]
latency = { type = "int", desc = "Latency between peers.", unit = "ms", default = 100 }

# #############################################################################
# Eclipse attack by monopolizing by incoming nodes
# #############################################################################
[[testcases]]
name = "eclipse-attack-monopolizing-by-incoming-nodes"
# The number of `instances` is fixed to 20 in this test case. For more detail,
Expand All @@ -31,7 +35,35 @@ instances = { min = 20, max = 20, default = 20 }
# Params for the `victim` group
incoming_bucket_limit = { type = "int", desc = "A maximum limit to the number of incoming nodes per bucket.", default = 16 }

# #############################################################################
# Concurrent requests
# #############################################################################
[[testcases]]
name = "concurrent-requests"
instances = { min = 2, max = 2, default = 2 }

[testcases.params]
latency = { type = "int", desc = "Latency between peers.", unit = "ms", default = 100 }

# A test case where WHOAREYOU packet times out.
[[testcases]]
name = "concurrent-requests_whoareyou-timeout"
instances = { min = 2, max = 2, default = 2 }

[testcases.params]
latency = { type = "int", desc = "Latency between peers.", unit = "ms", default = 100 }

# A test case where a node attempts to send requests in parallel before establishing a session.
[[testcases]]
name = "concurrent-requests_before-establishing-session"
instances = { min = 2, max = 2, default = 2 }

[testcases.params]
latency = { type = "int", desc = "Latency between peers.", unit = "ms", default = 100 }

# #############################################################################
# IP change
# #############################################################################
[[testcases]]
name = "ip-change"
instances = { min = 3, max = 100, default = 3 }
Expand All @@ -47,7 +79,9 @@ instances = { min = 3, max = 100, default = 3 }
duration_before = { type = "int", desc = "Duration to run the simulation before changing IP address.", default = 5, unit="sec" }
duration_after = { type = "int", desc = "Duration to run the simulation after changing IP address.", default = 15, unit="sec" }

# #############################################################################
# ENR update
# #############################################################################
[[testcases]]
name = "enr-update"
instances = { min = 11, max = 100, default = 11 }
Expand All @@ -57,3 +91,23 @@ instances = { min = 11, max = 100, default = 11 }

# discv5 params
ping_interval = { type = "int", desc = "The time between pings.", unit = "sec", default = 30 }

# #############################################################################
# Sandbox
# #############################################################################
[[testcases]]
name = "sandbox"
instances = { min = 2, max = 3, default = 2 }

[testcases.params]
latency = { type = "int", desc = "Latency between peers.", unit = "ms", default = 100 }

# #############################################################################
# Talk
# #############################################################################
[[testcases]]
name = "talk"
instances = { min = 2, max = 2, default = 2 }

[testcases.params]
latency = { type = "int", desc = "Latency between peers.", unit = "ms", default = 100 }
Loading

0 comments on commit d96207e

Please sign in to comment.