feat: bee 1.1.0 (#52)

* Update .env

* chore: format code and clean up dependencies

* refactor: extract BeePair

* feat: get traffic-gen to work with new endpoints

* docs: fix parameter names in jsdoc

* fix: fix bee endpoints

* fix: add prettier and fix endpoints

* fix: fix build param names

* docs: fix docs

* refactor: bee-cleanup for containers as well

Co-authored-by: nugaon <toth.viktor.levente@gmail.com>
This commit is contained in:
Cafe137 2021-10-06 12:15:56 +02:00 committed by GitHub
parent 8151b5597e
commit 84e7925165
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 32737 additions and 32681 deletions

13
.prettierrc Normal file
View File

@ -0,0 +1,13 @@
{
"printWidth": 120,
"tabWidth": 2,
"useTabs": false,
"bracketSpacing": true,
"semi": false,
"singleQuote": true,
"quoteProps": "as-needed",
"trailingComma": "all",
"endOfLine": "lf",
"arrowParens": "avoid",
"proseWrap": "always"
}

65257
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -12,9 +12,8 @@
"gen:traffic": "node ./scripts/gen-traffic.js" "gen:traffic": "node ./scripts/gen-traffic.js"
}, },
"dependencies": { "dependencies": {
"@ethersphere/bee-js": "0.12.0", "@ethersphere/bee-js": "1.2.1",
"@openzeppelin/contracts": "^3.1.0", "@openzeppelin/contracts": "^3.1.0",
"axios": "^0.20.0",
"truffle": "^5.3.5" "truffle": "^5.3.5"
}, },
"keywords": [ "keywords": [

View File

@ -1,4 +1,4 @@
BEE_VERSION="1.0.0" BEE_VERSION="1.1.0"
BLOCKCHAIN_VERSION="1.2.0" BLOCKCHAIN_VERSION="1.2.0"
BEE_ENV_PREFIX="swarm-test" BEE_ENV_PREFIX="swarm-test"
BEE_IMAGE_PREFIX="docker.pkg.github.com/ethersphere/bee-factory" BEE_IMAGE_PREFIX="docker.pkg.github.com/ethersphere/bee-factory"

View File

@ -13,6 +13,9 @@ do
sudo rm -rf "$BEE_DIR_PATH/statestore" sudo rm -rf "$BEE_DIR_PATH/statestore"
done done
echo "Removing stopped Bee Docker containers..."
docker container prune -f
echo "Removing built Bee Docker images..." echo "Removing built Bee Docker images..."
BEE_VERSION=$("$MY_PATH/utils/build-image-tag.sh" get) BEE_VERSION=$("$MY_PATH/utils/build-image-tag.sh" get)

View File

@ -4,12 +4,13 @@ usage() {
USAGE: USAGE:
$ build-environment.sh [PARAMETERS] $ build-environment.sh [PARAMETERS]
PARAMETERS: PARAMETERS:
--build-base-bee The base bee image will be built from source code --build-base-bee The base bee image will be built from source code
--base-bee-commit-hash=string the source code commit hash of the base bee; Default: HEAD; Dependency: --build-base-bee --base-bee-commit-hash=string the source code commit hash of the base bee; Default: HEAD; Dependency: --build-base-bee
--gen-traffic Generate traffic before bee image commit. --gen-traffic Generate traffic before bee image commit.
--gen-traffic-upload-node=string The traffic will be generated on the node under the given API URL. Default: http://locahost:1633; Dependency: --gen-traffic --gen-traffic-upload-node=string The traffic will be generated on the node under the given API URL. Default: http://locahost:1635; Dependency: --gen-traffic
--gen-traffic-checker-node=string The incoming cheques will be checked on the node under the given Debug API URL. Default: http://localhost:11635; Dependency: --gen-traffic --gen-traffic-upload-node-debug=string The traffic will be generated on the node under the given API URL. Default: http://locahost:1635; Dependency: --gen-traffic
--cheques-count=number this amount of cheques is intended to be generated by the traffic gen. Default: 1; Dependency: --gen-traffic --gen-traffic-checker-node-debug=string The incoming cheques will be checked on the node under the given Debug API URL. Default: http://localhost:11635; Dependency: --gen-traffic
--cheques-count=number This amount of cheques is intended to be generated by the traffic gen. Default: 1; Dependency: --gen-traffic
USAGE USAGE
exit 1 exit 1
} }
@ -49,8 +50,9 @@ MY_PATH=$( cd "$MY_PATH" && pwd )
COMMIT_HASH=HEAD COMMIT_HASH=HEAD
BUILD_BASE_BEE=false BUILD_BASE_BEE=false
GEN_TRAFFIC=false GEN_TRAFFIC=false
GEN_TRAFFIC_UPLOAD_NODE="http://localhost:1633" GEN_TRAFFIC_CHECKER_NODE_DEBUG="http://localhost:1635"
GEN_TRAFFIC_CHECKER_NODE="http://localhost:11635" GEN_TRAFFIC_UPLOAD_NODE="http://localhost:11633"
GEN_TRAFFIC_UPLOAD_NODE_DEBUG="http://localhost:11635"
CHEQUES_COUNT=1 CHEQUES_COUNT=1
# Bee version here means the base bee version on which the images will be built # Bee version here means the base bee version on which the images will be built
BEE_VERSION=$("$MY_PATH/utils/env-variable-value.sh" BEE_VERSION) BEE_VERSION=$("$MY_PATH/utils/env-variable-value.sh" BEE_VERSION)
@ -80,8 +82,12 @@ do
GEN_TRAFFIC_UPLOAD_NODE="${1#*=}" GEN_TRAFFIC_UPLOAD_NODE="${1#*=}"
shift 1 shift 1
;; ;;
--gen-traffic-checker-node=*) --gen-traffic-upload-node-debug=*)
GEN_TRAFFIC_CHECKER_NODE="${1#*=}" GEN_TRAFFIC_UPLOAD_NODE_DEBUG="${1#*=}"
shift 1
;;
--gen-traffic-checker-node-debug=*)
GEN_TRAFFIC_CHECKER_NODE_DEBUG="${1#*=}"
shift 1 shift 1
;; ;;
*) *)
@ -110,8 +116,8 @@ if $GEN_TRAFFIC ; then
echo "Start Bee nodes so that traffic can be generated and commited to the images" echo "Start Bee nodes so that traffic can be generated and commited to the images"
"$MY_PATH/bee.sh" start --workers=$SUPPORTED_WORKER_N --detach "$MY_PATH/bee.sh" start --workers=$SUPPORTED_WORKER_N --detach
echo "Generating traffic on Bee node $GEN_TRAFFIC_UPLOAD_NODE" echo "Generating traffic on Bee node $GEN_TRAFFIC_UPLOAD_NODE"
echo "Run traffic generation until $CHEQUES_COUNT incoming cheques will arrive to node under Debug API $GEN_TRAFFIC_CHECKER_NODE" echo "Run traffic generation until $CHEQUES_COUNT incoming cheques will arrive to node under Debug API $GEN_TRAFFIC_CHECKER_NODE_DEBUG"
npm run gen:traffic -- "$CHEQUES_COUNT" "$GEN_TRAFFIC_UPLOAD_NODE;$GEN_TRAFFIC_CHECKER_NODE" npm run gen:traffic -- "$CHEQUES_COUNT" "$GEN_TRAFFIC_CHECKER_NODE_DEBUG;$GEN_TRAFFIC_UPLOAD_NODE;$GEN_TRAFFIC_UPLOAD_NODE_DEBUG"
echo "traffic has been generated, stop nodes before commit..." echo "traffic has been generated, stop nodes before commit..."
"$MY_PATH/bee.sh" stop "$MY_PATH/bee.sh" stop
docker container prune -f docker container prune -f

View File

@ -1,5 +1,19 @@
const axios = require('axios').default; const { Bee, BeeDebug } = require('@ethersphere/bee-js')
const { Bee, BeeDebug } = require('@ethersphere/bee-js');
class BeePair {
/**
* @param {BeeDebug} chequeReceiverBeeDebug
* @param {Bee} uploaderBee
* @param {BeeDebug} uploaderBeeDebug
* @param {string} uploaderStamp
*/
constructor(chequeReceiverBeeDebug, uploaderBee, uploaderBeeDebug, uploaderStamp) {
this.chequeReceiverBeeDebug = chequeReceiverBeeDebug
this.uploaderBee = uploaderBee
this.uploaderBeeDebug = uploaderBeeDebug
this.uploaderStamp = uploaderStamp
}
}
const SLEEP_BETWEEN_UPLOADS_MS = 1000 const SLEEP_BETWEEN_UPLOADS_MS = 1000
const POSTAGE_STAMPS_AMOUNT = '10000' const POSTAGE_STAMPS_AMOUNT = '10000'
@ -34,97 +48,103 @@ function randomByteArray(length, seed = 500) {
return buf return buf
} }
async function trafficGen(bee, postageBatchId, seed = 500, bytes = 1024 * 4 * 400) { /**
* @param {BeePair} beePair
*/
async function uploadRandomBytes(beePair, seed = 500, bytes = 1024 * 4 * 400) {
const randomBytes = randomByteArray(bytes, seed) const randomBytes = randomByteArray(bytes, seed)
const ref = await bee.uploadData(postageBatchId, randomBytes) const reference = await beePair.uploaderBee.uploadData(beePair.uploaderStamp, randomBytes)
console.log(`Generated ${bytes} bytes traffic, the random data's root reference: ${ref}`) console.log(`${beePair.uploaderBee.url} uploaded ${bytes} bytes to ${reference}`)
} }
/** /**
* Generate traffic on Bee node(s) * Generate traffic on Bee node(s)
* *
* @param bees Array of Bee instances and postage batches where the random generated data will be sent to. * @param {BeePair[]} beePairs
*/ */
async function genTrafficOnOpenPorts(bees) { async function genTrafficOnOpenPorts(beePairs) {
const promises = bees.map(({bee, postageBatchId}) => { const promises = beePairs.map(beePair => {
console.log(`Generate Swarm Chunk traffic on ${bee.url}...`) return uploadRandomBytes(beePair, Date.now())
return trafficGen(bee, postageBatchId, new Date().getTime())
}) })
await Promise.all(promises) await Promise.all(promises)
} }
function sleep(ms) { function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms)); return new Promise(resolve => setTimeout(resolve, ms))
} }
/** /**
* *
* Generates cheques on the given Bee API EP * Generates cheques on the given Bee API EP
* *
* The hosts parameter has to be assimetric in the API;DEBUG_API paired string * The hosts parameter has to be assimetric in the API;DEBUG_API paired string
* because on the API EP the data will be generated, so the cheques should be * because on the API EP the data will be generated, so the cheques should be
* *
* @param {string[]} hosts API;DEBUG_API URL strings of the target Bee (e.g. http://localhost:1633;http://localhost:1635) * @param {string[]} hosts API;DEBUG_API URL strings of the target Bee (e.g. http://localhost:1635;http://localhost:11633;http://localhost:11635)
* @param {number} minCheques * @param {number} minCheques
*/ */
async function genTrafficLoop(hosts, minCheques) { async function genTrafficLoop(hosts, minCheques) {
const promises = hosts.map(async (host) => { const promises = hosts.map(async host => {
const [ beeApiUrl, beeDebugApiUrl ] = host.split(';') const [chequeReceiverBeeDebugUrl, uploaderBeeUrl, uploaderBeeDebugUrl] = host.split(';')
const bee = new Bee(beeApiUrl) const chequeReceiverBeeDebug = new BeeDebug(chequeReceiverBeeDebugUrl)
const beeDebug = new BeeDebug(beeDebugApiUrl) const uploaderBee = new Bee(uploaderBeeUrl)
const uploaderBeeDebug = new BeeDebug(uploaderBeeDebugUrl)
console.log(`Create postage stamp on ${beeApiUrl}...`) console.log(`Creating postage stamp on ${uploaderBeeDebugUrl}...`)
const postageBatchId = await bee.createPostageBatch(POSTAGE_STAMPS_AMOUNT, POSTAGE_STAMPS_DEPTH) const postageBatchId = await uploaderBeeDebug.createPostageBatch(POSTAGE_STAMPS_AMOUNT, POSTAGE_STAMPS_DEPTH)
console.log(`Generated ${postageBatchId} postage stamp on ${beeApiUrl}...`) console.log(`Generated ${postageBatchId} postage stamp on ${uploaderBeeDebugUrl}...`)
return {bee, beeDebug, postageBatchId} return new BeePair(chequeReceiverBeeDebug, uploaderBee, uploaderBeeDebug, postageBatchId)
}) })
const bees = await Promise.all(promises) const bees = await Promise.all(promises)
console.log(`wait 11 secs (>10 block time) before postage stamp usages`) console.log(`wait 11 secs (>10 block time) before postage stamp usages`)
await sleep(11*1000) await sleep(11 * 1000)
while(true) { while (true) {
await genTrafficOnOpenPorts(bees) await genTrafficOnOpenPorts(bees)
if(!isNaN(minCheques)) { if (!isNaN(minCheques)) {
const beesUncashedCheques = [] const beesUncashedCheques = []
for(const bee of bees) { for (const beePair of bees) {
const beeDebug = bee.beeDebug const { chequeReceiverBeeDebug } = beePair
const { lastcheques } = await beeDebug.getLastCheques() const { lastcheques } = await chequeReceiverBeeDebug.getLastCheques()
const incomingCheques = lastcheques.filter(cheque => !!cheque.lastreceived) const incomingCheques = lastcheques.filter(cheque => !!cheque.lastreceived)
const uncashedCheques = [] const uncashedCheques = []
const lastCashOutPromises = incomingCheques.map(({ peer }) => beeDebug.getLastCashoutAction(peer)) const lastCashOutPromises = incomingCheques.map(({ peer }) => chequeReceiverBeeDebug.getLastCashoutAction(peer))
const lastCashOuts = await Promise.all(lastCashOutPromises) const lastCashOuts = await Promise.all(lastCashOutPromises)
for(const [index, lastCashOut] of lastCashOuts.entries()) { for (const [index, lastCashOut] of lastCashOuts.entries()) {
if(BigInt(lastCashOut.uncashedAmount) > 0) { if (BigInt(lastCashOut.uncashedAmount) > 0) {
uncashedCheques.push(incomingCheques[index]) uncashedCheques.push(incomingCheques[index])
} }
} }
beesUncashedCheques.push(uncashedCheques) beesUncashedCheques.push(uncashedCheques)
} }
if(beesUncashedCheques.every(uncashedCheques => uncashedCheques.length >= minCheques)) { if (beesUncashedCheques.every(uncashedCheques => uncashedCheques.length >= minCheques)) {
console.log(`Generated at least ${minCheques} for every node on the given Debug API endpoints`,) console.log(`Generated at least ${minCheques} for every node on the given Debug API endpoints`)
break break
} else { } else {
console.log(`There is not enough uncashed cheques on Bee node(s)`, beesUncashedCheques.map(beeCheques => beeCheques.length)) console.log(
`There is not enough uncashed cheques on Bee node(s)`,
beesUncashedCheques.map(beeCheques => beeCheques.length),
)
} }
} }
await sleep(SLEEP_BETWEEN_UPLOADS_MS) await sleep(SLEEP_BETWEEN_UPLOADS_MS)
} }
} }
let inputArray = process.argv.slice(2) let inputArray = process.argv.slice(2)
// if there is no related input to the minimum required cheques count, // if there is no related input to the minimum required cheques count,
// then the traffic generation will go infinitely // then the traffic generation will go infinitely
let minCheques = parseInt(inputArray[0]) let minCheques = parseInt(inputArray[0])
let hosts = inputArray.slice(1) let hosts = inputArray.slice(1)
if(hosts.length === 0) { if (hosts.length === 0) {
hosts = [ 'http://localhost:1633;http://localhost:11635' ] hosts = ['http://localhost:1635;http://localhost:11633;http://localhost:11635']
} }
genTrafficLoop(hosts, minCheques) genTrafficLoop(hosts, minCheques)