Skip to content

Commit

Permalink
Merge branch 'chore/scale-test' into 'dev'
Browse files Browse the repository at this point in the history
chore: add scale test package

See merge request ergo/rosen-bridge/rosenet!23
  • Loading branch information
zargarzadehm committed Apr 17, 2024
2 parents cbb02e4 + c3093d5 commit 26675d3
Show file tree
Hide file tree
Showing 23 changed files with 859 additions and 3 deletions.
2 changes: 2 additions & 0 deletions .changeset/shy-emus-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
---
---
5 changes: 5 additions & 0 deletions .changeset/strong-ears-drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-bridge/rosenet-node': patch
---

check cached stream writeStatus instead of status
5 changes: 5 additions & 0 deletions .changeset/tough-phones-knock.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-bridge/rosenet-relay': minor
---

prevent applying default reservation limits
5 changes: 5 additions & 0 deletions .changeset/twelve-rockets-sell.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-bridge/rosenet-node': patch
---

return cached streams with writeStatus of writing, too
5 changes: 5 additions & 0 deletions .changeset/unlucky-rocks-impress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@rosen-bridge/rosenet-node': patch
---

only choose outbound streams for sending messages
File renamed without changes.
44 changes: 44 additions & 0 deletions .github/workflows/scale-test-docker-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Build and Push Scale Test Docker Image
on:
push:
paths:
- 'packages/**'
- 'tests/scaling/**'

jobs:
build:
strategy:
matrix:
role: [node, relay]

name: Build and Push Scale Test Docker Image
permissions: write-all
runs-on: ubuntu-latest

steps:
- name: Checkout the Code
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Login to Docker Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: rosen-bridge
password: ${{ secrets.GITHUB_TOKEN }}

- name: Docker Metadata action
uses: docker/metadata-action@v5
id: meta
with:
images: ghcr.io/rosen-bridge/scale-test-${{matrix.role}}
tags: latest

- name: Build and push ${{matrix.role}}
uses: docker/build-push-action@v4
with:
context: .
file: 'tests/scaling/src/${{matrix.role}}/Dockerfile'
push: true
tags: ${{ steps.meta.outputs.tags }}
25 changes: 25 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions packages/rosenet-node/lib/getStreamAndPushable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@ const cache = new Map<
}
>();

/**
* return if a stream can be written on
* @param stream
*/
const isStreamWritable = (stream: Stream) =>
['ready', 'writing'].includes(stream.writeStatus);

/**
* get a stream and a pushable to the `to` remotePeer with
* ROSENET_DIRECT_PROTOCOL_V1 protocol, caching the pair for future use
Expand All @@ -25,7 +32,7 @@ const cache = new Map<
*/
async function getStreamAndPushable(to: string, node: Libp2p) {
const cacheHit = cache.get(to);
if (cacheHit?.stream.status === 'open') {
if (cacheHit && isStreamWritable(cacheHit.stream)) {
RoseNetNodeTools.logger.debug(
`Found existing stream and pushable in the cache to peer ${to}`,
{
Expand Down Expand Up @@ -63,7 +70,8 @@ async function getStreamAndPushable(to: string, node: Libp2p) {
const connectionStream = shuffle(connection.streams);
const possibleWritableStream = connectionStream.find(
(stream) =>
stream.writeStatus === 'ready' &&
isStreamWritable(stream) &&
stream.direction === 'outbound' &&
stream.protocol === ROSENET_DIRECT_PROTOCOL_V1,
);
const stream =
Expand Down
9 changes: 8 additions & 1 deletion packages/rosenet-relay/lib/createRoseNetRelay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,14 @@ const createRoseNetRelay = async ({
},
streamMuxers: [mplex()],
services: {
circuitRelay: circuitRelayServer(),
circuitRelay: circuitRelayServer({
reservations: {
maxReservations: config.maxReservations,
defaultDurationLimit: 0,
defaultDataLimit: 0n,
applyDefaultLimit: false,
},
}),
pubsub: gossipsub({ allowPublishToZeroPeers: true }),
identify: identify(),
},
Expand Down
1 change: 1 addition & 0 deletions packages/rosenet-relay/lib/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,5 @@ export interface RoseNetRelayConfig {
privateKey: string;
logger: AbstractLogger;
whitelist: string[];
maxReservations?: number;
}
1 change: 1 addition & 0 deletions tests/scaling/.eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dist
24 changes: 24 additions & 0 deletions tests/scaling/.terraform.lock.hcl

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 23 additions & 0 deletions tests/scaling/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# RoseNet scaling test

## Table of contents

- [Introduction](#introduction)
- [Usage](#usage)

## Introduction

RoseNet scaling test

## Usage

You need to have [OpenTofu](https://opentofu.org/) installed. Then, after
[passing required variables](https://opentofu.org/docs/language/values/variables/#assigning-values-to-root-module-variables) (defined in [`variables.tf`](./variables.tf)),
run the following commands. It should complete with no errors.

```bash
tofu init
tofu apply
```

Finally run `tofu destroy` to destroy the infrastructure.
Loading

0 comments on commit 26675d3

Please sign in to comment.