Skip to content

Commit

Permalink
feat: bee 2.2 (#147)
Browse files Browse the repository at this point in the history
* feat: change ports 1635 to 1633 and remove restricted api

* docs: fix path

* feat: api addr get bind to localhost

* feat: bootnode params and cli options for api

* fix: 404 error of bee on stamp sync

* feat: update redis and staking contracts
  • Loading branch information
nugaon authored Sep 12, 2024
1 parent 6af71e6 commit 3c91aa6
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 40 deletions.
2 changes: 1 addition & 1 deletion orchestrator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ start the Bee cluster
When different bee client builds need to be tested and the same data must be available in different environments,
`environment.sh` script can be used to spin up any specific bee image.

To define what is the bee image in question, change the `./scripts/utils/.commit-version-tag` to the tag that the docker image has and suffix that with `-commit`.
To define what is the bee image in question, change the `./builder/utils/.commit-version-tag` to the tag that the docker image has and suffix that with `-commit`.

Execute
```sh
Expand Down
2 changes: 1 addition & 1 deletion orchestrator/builder/.env
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
BEE_VERSION="1.11.1"
BLOCKCHAIN_VERSION="2.0.1"
BLOCKCHAIN_VERSION="2.1.0"
BEE_ENV_PREFIX="fdp-play"
BEE_IMAGE_PREFIX="fairdatasociety"
COMMIT_VERSION_TAG="false"
Expand Down
37 changes: 14 additions & 23 deletions orchestrator/builder/bee.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ PARAMETERS:
--ephemeral create ephemeral container for bee-client. Data won't be persisted.
--workers=number all Bee nodes in the test environment. Default is 4.
--port-maps=number map ports of the cluster nodes to the hosting machine in the following manner:
1. 1633:1635
2. 11633:11635
3. 21633:21635 (...)
1. 1633:1634
2. 11633:11634
3. 21633:21634 (...)
number represents the nodes number to map from. Default is 2.
--password=string password for Bee client(s).
--own-image If passed, the used Docker image names will be identical as the name of the workers.
Expand Down Expand Up @@ -73,7 +73,7 @@ fetch_queen_underlay_addr() {
TIMEOUT=$((2*12*WAITING_TIME))
while (( TIMEOUT > ELAPSED_TIME )) ; do
check_queen_is_running
QUEEN_UNDERLAY_ADDRESS=$(curl -s "$HOSTNAME:1635/addresses" | python -mjson.tool | grep "/ip4/" | awk "!/127.0.0.1/" | sed 's/,$//' | xargs)
QUEEN_UNDERLAY_ADDRESS=$(curl -s "$HOSTNAME:1633/addresses" | python -mjson.tool | grep "/ip4/" | awk "!/127.0.0.1/" | sed 's/,$//' | xargs)
if [[ -z "$QUEEN_UNDERLAY_ADDRESS" ]] ; then
echo "Waiting for the Queen initialization..."
ELAPSED_TIME=$((ELAPSED_TIME+WAITING_TIME))
Expand All @@ -97,7 +97,7 @@ log_queen() {
}

count_connected_peers() {
COUNT=$( (curl -s "http://$HOSTNAME:1635/peers" -H "Authorization: Bearer $1" | python -c 'import json,sys; obj=json.load(sys.stdin); print (len(obj["peers"]));') || echo 0 )
COUNT=$( (curl -s "http://$HOSTNAME:1633/peers" -H "Authorization: Bearer $1" | python -c 'import json,sys; obj=json.load(sys.stdin); print (len(obj["peers"]));') || echo 0 )

echo "$COUNT"
}
Expand All @@ -106,7 +106,6 @@ MY_PATH=$(dirname "$0") # relative
MY_PATH=$( cd "$MY_PATH" && pwd ) # absolutized and normalized
# Check used system variable set
BEE_VERSION=$("$MY_PATH/utils/build-image-tag.sh" get)
BEE_IMAGE_PREFIX=$("$MY_PATH/utils/env-variable-value.sh" BEE_IMAGE_PREFIX)
BEE_ENV_PREFIX=$("$MY_PATH/utils/env-variable-value.sh" BEE_ENV_PREFIX)

# Init variables
Expand All @@ -115,7 +114,6 @@ WORKERS=4
LOG=true
RESTRICTED=false
RESTRICTED_PASSWORD=""
RESTRICTED_PASSWORD_HASH=""
QUEEN_CONTAINER_NAME="$BEE_ENV_PREFIX-queen"
WORKER_CONTAINER_NAME="$BEE_ENV_PREFIX-worker"
SWARM_BLOCKCHAIN_NAME="$BEE_ENV_PREFIX-blockchain"
Expand Down Expand Up @@ -165,12 +163,6 @@ do
BEE_PASSWORD="${1#*=}"
shift 1
;;
--restrict=*)
RESTRICTED="true"
RESTRICTED_PASSWORD="${1#*=}"
RESTRICTED_PASSWORD_HASH=$(htpasswd -bnBC 10 "" $RESTRICTED_PASSWORD | tr -d ':\n')
shift 1
;;
--version=*)
BEE_VERSION="${1#*=}"
shift 1
Expand Down Expand Up @@ -208,7 +200,7 @@ if [ -z "$QUEEN_CONTAINER_IN_DOCKER" ] || $EPHEMERAL ; then
DOCKER_IMAGE="$BEE_IMAGE"
EXTRA_QUEEN_PARAMS="-v $INIT_ROOT_DATA_DIR/$QUEEN_CONTAINER_NAME:/home/bee/.bee"
if [ "$PORT_MAPS" -ge 1 ] ; then
EXTRA_QUEEN_PARAMS="$EXTRA_QUEEN_PARAMS -p 1633-1635:1633-1635"
EXTRA_QUEEN_PARAMS="$EXTRA_QUEEN_PARAMS -p 1633-1634:1633-1634"
fi

echo "start Bee Queen process"
Expand All @@ -223,15 +215,14 @@ if [ -z "$QUEEN_CONTAINER_IN_DOCKER" ] || $EPHEMERAL ; then
$EXTRA_QUEEN_PARAMS \
$DOCKER_IMAGE \
start \
--admin-password="$RESTRICTED_PASSWORD_HASH" \
--restricted="$RESTRICTED" \
--warmup-time=0 \
--password "$BEE_PASSWORD" \
--bootnode="$QUEEN_BOOTNODE" \
--debug-api-enable \
--bootnode-mode=true \
--verbosity=4 \
--mainnet=false \
--block-time=1 \
--block-time=5 \
--api-addr=0.0.0.0:1633 \
--swap-enable=$SWAP \
--swap-endpoint="http://$SWARM_BLOCKCHAIN_NAME:9545" \
--swap-factory-address=$SWAP_FACTORY_ADDRESS \
Expand Down Expand Up @@ -262,8 +253,8 @@ for i in $(seq 1 1 "$WORKERS"); do
EXTRA_WORKER_PARAMS="$EXTRA_WORKER_PARAMS -v $INIT_ROOT_DATA_DIR/$WORKER_NAME:/home/bee/.bee"
if [ $PORT_MAPS -gt $i ] ; then
PORT_START=$((1633+(10000*i)))
PORT_END=$((PORT_START + 2))
EXTRA_WORKER_PARAMS="$EXTRA_WORKER_PARAMS -p $PORT_START-$PORT_END:1633-1635"
PORT_END=$((PORT_START + 1))
EXTRA_WORKER_PARAMS="$EXTRA_WORKER_PARAMS -p $PORT_START-$PORT_END:1633-1634"
fi

# run docker container
Expand All @@ -279,10 +270,10 @@ for i in $(seq 1 1 "$WORKERS"); do
--warmup-time=0 \
--password "$BEE_PASSWORD" \
--bootnode="$QUEEN_UNDERLAY_ADDRESS" \
--debug-api-enable \
--verbosity=4 \
--mainnet=false \
--block-time=1 \
--block-time=5 \
--api-addr=0.0.0.0:1633 \
--swap-enable=$SWAP \
--swap-endpoint="http://$SWARM_BLOCKCHAIN_NAME:9545" \
--swap-factory-address=$SWAP_FACTORY_ADDRESS \
Expand Down Expand Up @@ -313,7 +304,7 @@ while (( TIMEOUT > ELAPSED_TIME )) ; do
fi;

COUNT=$(count_connected_peers "$RESTRICTED_TOKEN")
[[ $COUNT < $WORKERS ]] || break
[[ $COUNT -lt $WORKERS ]] || break
echo "Only $COUNT peers have been connected to the Queen Bee node yet. Waiting until $WORKERS"
ELAPSED_TIME=$((ELAPSED_TIME+WAITING_TIME))
sleep $WAITING_TIME
Expand Down
6 changes: 3 additions & 3 deletions orchestrator/builder/environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ PARAMETERS:
--workers=number all Bee nodes in the test environment. Default is 4.
--detach It will not log the output of Queen node at the end of the process.
--port-maps=number map ports of the cluster nodes to the hosting machine in the following manner:
1. 1633:1635
2. 11633:11635
3. 21633:21635 (...)
1. 1633:1634
2. 11633:11634
3. 21633:21634 (...)
number represents the nodes number to map from. Default is 2.
--hostname=string Interface to which should the nodes be bound (default 127.0.0.0).
USAGE
Expand Down
2 changes: 1 addition & 1 deletion orchestrator/contracts/Redistribution.bytecode

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion orchestrator/contracts/StakeRegistry.bytecode

Large diffs are not rendered by default.

10 changes: 4 additions & 6 deletions src/utils/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ export class Docker {
ExposedPorts: {
'1633/tcp': {},
'1634/tcp': {},
'1635/tcp': {},
},
Tty: true,
Cmd: ['start'],
Expand All @@ -252,7 +251,6 @@ export class Docker {
PortBindings: {
'1633/tcp': [{ HostPort: '1633' }],
'1634/tcp': [{ HostPort: '1634' }],
'1635/tcp': [{ HostPort: '1635' }],
},
},
},
Expand Down Expand Up @@ -287,7 +285,6 @@ export class Docker {
ExposedPorts: {
'1633/tcp': {},
'1634/tcp': {},
'1635/tcp': {},
},
Cmd: ['start'],
Env: this.createBeeEnvParameters(queenAddress),
Expand All @@ -298,7 +295,6 @@ export class Docker {
PortBindings: {
'1633/tcp': [{ HostPort: (1633 + workerNumber * 10000).toString() }],
'1634/tcp': [{ HostPort: (1634 + workerNumber * 10000).toString() }],
'1635/tcp': [{ HostPort: (1635 + workerNumber * 10000).toString() }],
},
},
},
Expand Down Expand Up @@ -523,11 +519,14 @@ export class Docker {
'network-id': '4020',
'full-node': 'true',
'welcome-message': 'You have found the queen of the beehive...',
'api-addr': '0.0.0.0:1633',
'cors-allowed-origins': '*',
}

if (bootnode) {
options.bootnode = bootnode
} else {
options['bootnode-mode'] = 'true'
}

// Env variables for Bee has form of `BEE_WARMUP_TIME`, so we need to transform it.
Expand All @@ -544,7 +543,6 @@ export class Docker {
const corsOrigins = '*'
const cookieDomain = 'localhost'
const beeApiUrl = `http://${this.queenName}:1633`
const beeDebugApiUrl = `http://${this.queenName}:1635`

return [
`--postageBlockId=${batchId}`,
Expand All @@ -557,7 +555,7 @@ export class Docker {
}

private async createPostageBatch(): Promise<string> {
const beeDebug = new BeeDebug('http://localhost:1635')
const beeDebug = new BeeDebug('http://localhost:1633')

return beeDebug.createPostageBatch('10000000000', 21)
}
Expand Down
8 changes: 5 additions & 3 deletions src/utils/wait.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export async function waitForBlockchain(waitingIterations = 30): Promise<void> {
}

export async function waitForQueen(verifyQueenIsUp: () => Promise<boolean>, waitingIterations = 120): Promise<string> {
const beeDebug = new BeeDebug('http://127.0.0.1:1635')
const beeDebug = new BeeDebug('http://127.0.0.1:1633')

for (let i = 0; i < waitingIterations; i++) {
try {
Expand Down Expand Up @@ -97,7 +97,7 @@ export async function waitForWorkers(
getStatus: () => Promise<AllStatus>,
waitingIterations = 120,
): Promise<void> {
const beeDebug = new BeeDebug('http://127.0.0.1:1635')
const beeDebug = new BeeDebug('http://127.0.0.1:1633')

const status = await getStatus()
for (let i = 1; i <= workerCount; i++) {
Expand All @@ -114,7 +114,9 @@ export async function waitForWorkers(
return
}
} catch (e) {
if (!isAllowedError(e as FetchError)) {
if ((e as { message: string }).message.includes('404')) {
// TODO remove when https://github.com/ethersphere/bee/issues/4734 is fixed

Check warning on line 118 in src/utils/wait.ts

View workflow job for this annotation

GitHub Actions / check (18.x)

Unexpected 'todo' comment: 'TODO remove when...'
} else if (!isAllowedError(e as FetchError)) {
throw e
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/start.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ describe('start command', () => {
beforeAll(() => {
docker = new Dockerode()
bee = new Bee('http://127.0.0.1:1633')
beeDebug = new BeeDebug('http://127.0.0.1:1635')
beeDebug = new BeeDebug('http://127.0.0.1:1633')

// This will force Bee Factory to create
process.env[ENV_ENV_PREFIX_KEY] = envPrefix
Expand Down

0 comments on commit 3c91aa6

Please sign in to comment.