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"
}

69
package-lock.json generated
View File

@ -5,10 +5,11 @@
"requires": true,
"packages": {
"": {
"name": "bee-factory",
"version": "0.0.1",
"license": "BSD-3-Clause",
"dependencies": {
"@ethersphere/bee-js": "0.12.0",
"@ethersphere/bee-js": "1.2.1",
"@openzeppelin/contracts": "^3.1.0",
"axios": "^0.20.0",
"truffle": "^5.3.5"
@ -1038,19 +1039,19 @@
}
},
"node_modules/@ethersphere/bee-js": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-0.12.0.tgz",
"integrity": "sha512-fpZjbjIU5pxuGGo6nvVyAkEvCNSYIuoUb5fyaaIyZ+czswEkVm5oPeEfNvF703EWnar6kcAjCpAOs+dLWwLKAg==",
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-1.2.1.tgz",
"integrity": "sha512-Z1lh016EB8bxTNHUDXCDEcJN8IrPaz+vlIz89oscJF9q3Xuevmo/QCn7fQ0dqrppB8Motz7gjPteFJk5glsNGQ==",
"dependencies": {
"axios": "^0.21.1",
"elliptic": "^6.5.4",
"isomorphic-ws": "^4.0.1",
"js-sha3": "^0.8.0",
"tar-js": "^0.3.0",
"ws": "^7.4.4"
"ws": "^7.5.0"
},
"engines": {
"bee": "1.0.0-3a92ef5-dirty",
"bee": "1.1.0-80cdea19",
"node": ">=12.0.0",
"npm": ">=6.0.0"
}
@ -1087,6 +1088,26 @@
"resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz",
"integrity": "sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q=="
},
"node_modules/@ethersphere/bee-js/node_modules/ws": {
"version": "7.5.5",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.5.tgz",
"integrity": "sha512-BAkMFcAzl8as1G/hArkxOxq3G7pjUqQ3gzYbLL0/5zNkph70e+lCoxBGnm6AW1+/aiNeV4fnKqZ8m4GZewmH2w==",
"engines": {
"node": ">=8.3.0"
},
"peerDependencies": {
"bufferutil": "^4.0.1",
"utf-8-validate": "^5.0.2"
},
"peerDependenciesMeta": {
"bufferutil": {
"optional": true
},
"utf-8-validate": {
"optional": true
}
}
},
"node_modules/@ethersproject/abi": {
"version": "5.0.7",
"resolved": "https://registry.npmjs.org/@ethersproject/abi/-/abi-5.0.7.tgz",
@ -5682,6 +5703,7 @@
"version": "4.0.3",
"resolved": "https://registry.npmjs.org/bufferutil/-/bufferutil-4.0.3.tgz",
"integrity": "sha512-yEYTwGndELGvfXsImMBLop58eaGW+YdONi1fNjTINSY98tmMmFijBG6WXgdkfuLNt4imzQNtIE+eBp1PVpMCSw==",
"hasInstallScript": true,
"dependencies": {
"node-gyp-build": "^4.2.0"
}
@ -5861,7 +5883,6 @@
"dependencies": {
"anymatch": "~3.1.1",
"braces": "~3.0.2",
"fsevents": "~2.1.2",
"glob-parent": "~5.1.0",
"is-binary-path": "~2.1.0",
"is-glob": "~4.0.1",
@ -7281,8 +7302,7 @@
"esprima": "^4.0.1",
"estraverse": "^4.2.0",
"esutils": "^2.0.2",
"optionator": "^0.8.1",
"source-map": "~0.6.1"
"optionator": "^0.8.1"
},
"bin": {
"escodegen": "bin/escodegen.js",
@ -7342,9 +7362,6 @@
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
"integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=",
"dependencies": {
"graceful-fs": "^4.1.6"
},
"optionalDependencies": {
"graceful-fs": "^4.1.6"
}
@ -9019,7 +9036,6 @@
"dom-serializer": "~0.1.0",
"entities": "~1.1.1",
"htmlparser2": "~3.8.1",
"jsdom": "^7.0.2",
"lodash": "^4.1.0"
},
"engines": {
@ -10272,7 +10288,6 @@
"integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==",
"optional": true,
"dependencies": {
"graceful-fs": "^4.1.6",
"universalify": "^2.0.0"
},
"optionalDependencies": {
@ -15745,9 +15760,6 @@
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-4.0.0.tgz",
"integrity": "sha1-h3Gq4HmbZAdrdmQPygWPnBDjPss=",
"dependencies": {
"graceful-fs": "^4.1.6"
},
"optionalDependencies": {
"graceful-fs": "^4.1.6"
}
@ -16087,12 +16099,7 @@
"integrity": "sha512-qdvaZzKc5WxnWS6qW7hpAo4aAphAtQfJYnr2hv7FftbycgOv7lemtIPxcd91+/3eZAIGM6hmCjbFYXgEyyaIkQ==",
"hasInstallScript": true,
"dependencies": {
"@truffle/db": "^0.5.11",
"@truffle/debugger": "^8.0.25",
"@truffle/preserve-fs": "^0.2.2",
"@truffle/preserve-to-buckets": "^0.2.2",
"@truffle/preserve-to-filecoin": "^0.2.2",
"@truffle/preserve-to-ipfs": "^0.2.2",
"app-module-path": "^2.2.0",
"mocha": "8.1.2",
"original-require": "^1.0.1"
@ -16467,6 +16474,7 @@
"version": "5.0.4",
"resolved": "https://registry.npmjs.org/utf-8-validate/-/utf-8-validate-5.0.4.tgz",
"integrity": "sha512-MEF05cPSq3AwJ2C7B7sHAA6i53vONoZbMGX8My5auEVm6W+dJ2Jd/TZPyGJ5CH42V2XtbI5FD28HeHeqlPzZ3Q==",
"hasInstallScript": true,
"dependencies": {
"node-gyp-build": "^4.2.0"
}
@ -16685,7 +16693,6 @@
"integrity": "sha512-HYLeVCdJ0+lBYV2FvNZmv3HJ2Nt0QYXqZojk3d9FJOLkwnuhzM9tmamh8d7HPM8QqjKH8DeHkFTx+CFlWpZZDA==",
"optional": true,
"dependencies": {
"@zxing/text-encoding": "0.9.0",
"util": "^0.12.3"
},
"optionalDependencies": {
@ -17317,6 +17324,7 @@
"version": "7.4.5",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.4.5.tgz",
"integrity": "sha512-xzyu3hFvomRfXKH8vOFMU3OguG6oOvhXMo3xsGy3xWExqaM2dxBbVxuD99O7m3ZUFMvvscsZDqxfgMaRr/Nr1g==",
"optional": true,
"engines": {
"node": ">=8.3.0"
},
@ -18578,16 +18586,16 @@
}
},
"@ethersphere/bee-js": {
"version": "0.12.0",
"resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-0.12.0.tgz",
"integrity": "sha512-fpZjbjIU5pxuGGo6nvVyAkEvCNSYIuoUb5fyaaIyZ+czswEkVm5oPeEfNvF703EWnar6kcAjCpAOs+dLWwLKAg==",
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/@ethersphere/bee-js/-/bee-js-1.2.1.tgz",
"integrity": "sha512-Z1lh016EB8bxTNHUDXCDEcJN8IrPaz+vlIz89oscJF9q3Xuevmo/QCn7fQ0dqrppB8Motz7gjPteFJk5glsNGQ==",
"requires": {
"axios": "^0.21.1",
"elliptic": "^6.5.4",
"isomorphic-ws": "^4.0.1",
"js-sha3": "^0.8.0",
"tar-js": "^0.3.0",
"ws": "^7.4.4"
"ws": "^7.5.0"
},
"dependencies": {
"axios": {
@ -18621,6 +18629,12 @@
"version": "0.8.0",
"resolved": "https://registry.npmjs.org/js-sha3/-/js-sha3-0.8.0.tgz",
"integrity": "sha512-gF1cRrHhIzNfToc802P800N8PpXS+evLLXfsVpowqmAFR9uwbi89WvXg2QspOmXL8QL86J4T1EpFu+yUkwJY3Q=="
},
"ws": {
"version": "7.5.5",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.5.5.tgz",
"integrity": "sha512-BAkMFcAzl8as1G/hArkxOxq3G7pjUqQ3gzYbLL0/5zNkph70e+lCoxBGnm6AW1+/aiNeV4fnKqZ8m4GZewmH2w==",
"requires": {}
}
}
},
@ -32569,6 +32583,7 @@
"version": "7.4.5",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.4.5.tgz",
"integrity": "sha512-xzyu3hFvomRfXKH8vOFMU3OguG6oOvhXMo3xsGy3xWExqaM2dxBbVxuD99O7m3ZUFMvvscsZDqxfgMaRr/Nr1g==",
"optional": true,
"requires": {}
},
"xdg-basedir": {

View File

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

View File

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

View File

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

View File

@ -7,9 +7,10 @@ PARAMETERS:
--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
--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-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
--cheques-count=number this amount of cheques is intended to be generated by the traffic gen. Default: 1; 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-upload-node-debug=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-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
exit 1
}
@ -49,8 +50,9 @@ MY_PATH=$( cd "$MY_PATH" && pwd )
COMMIT_HASH=HEAD
BUILD_BASE_BEE=false
GEN_TRAFFIC=false
GEN_TRAFFIC_UPLOAD_NODE="http://localhost:1633"
GEN_TRAFFIC_CHECKER_NODE="http://localhost:11635"
GEN_TRAFFIC_CHECKER_NODE_DEBUG="http://localhost:1635"
GEN_TRAFFIC_UPLOAD_NODE="http://localhost:11633"
GEN_TRAFFIC_UPLOAD_NODE_DEBUG="http://localhost:11635"
CHEQUES_COUNT=1
# 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)
@ -80,8 +82,12 @@ do
GEN_TRAFFIC_UPLOAD_NODE="${1#*=}"
shift 1
;;
--gen-traffic-checker-node=*)
GEN_TRAFFIC_CHECKER_NODE="${1#*=}"
--gen-traffic-upload-node-debug=*)
GEN_TRAFFIC_UPLOAD_NODE_DEBUG="${1#*=}"
shift 1
;;
--gen-traffic-checker-node-debug=*)
GEN_TRAFFIC_CHECKER_NODE_DEBUG="${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"
"$MY_PATH/bee.sh" start --workers=$SUPPORTED_WORKER_N --detach
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"
npm run gen:traffic -- "$CHEQUES_COUNT" "$GEN_TRAFFIC_UPLOAD_NODE;$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_CHECKER_NODE_DEBUG;$GEN_TRAFFIC_UPLOAD_NODE;$GEN_TRAFFIC_UPLOAD_NODE_DEBUG"
echo "traffic has been generated, stop nodes before commit..."
"$MY_PATH/bee.sh" stop
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 POSTAGE_STAMPS_AMOUNT = '10000'
@ -34,27 +48,29 @@ function randomByteArray(length, seed = 500) {
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 ref = await bee.uploadData(postageBatchId, randomBytes)
console.log(`Generated ${bytes} bytes traffic, the random data's root reference: ${ref}`)
const reference = await beePair.uploaderBee.uploadData(beePair.uploaderStamp, randomBytes)
console.log(`${beePair.uploaderBee.url} uploaded ${bytes} bytes to ${reference}`)
}
/**
* 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) {
const promises = bees.map(({bee, postageBatchId}) => {
console.log(`Generate Swarm Chunk traffic on ${bee.url}...`)
return trafficGen(bee, postageBatchId, new Date().getTime())
async function genTrafficOnOpenPorts(beePairs) {
const promises = beePairs.map(beePair => {
return uploadRandomBytes(beePair, Date.now())
})
await Promise.all(promises)
}
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
return new Promise(resolve => setTimeout(resolve, ms))
}
/**
@ -64,53 +80,57 @@ function sleep(ms) {
* 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
*
* @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
*/
async function genTrafficLoop(hosts, minCheques) {
const promises = hosts.map(async (host) => {
const [ beeApiUrl, beeDebugApiUrl ] = host.split(';')
const bee = new Bee(beeApiUrl)
const beeDebug = new BeeDebug(beeDebugApiUrl)
const promises = hosts.map(async host => {
const [chequeReceiverBeeDebugUrl, uploaderBeeUrl, uploaderBeeDebugUrl] = host.split(';')
const chequeReceiverBeeDebug = new BeeDebug(chequeReceiverBeeDebugUrl)
const uploaderBee = new Bee(uploaderBeeUrl)
const uploaderBeeDebug = new BeeDebug(uploaderBeeDebugUrl)
console.log(`Create postage stamp on ${beeApiUrl}...`)
const postageBatchId = await bee.createPostageBatch(POSTAGE_STAMPS_AMOUNT, POSTAGE_STAMPS_DEPTH)
console.log(`Generated ${postageBatchId} postage stamp on ${beeApiUrl}...`)
console.log(`Creating postage stamp on ${uploaderBeeDebugUrl}...`)
const postageBatchId = await uploaderBeeDebug.createPostageBatch(POSTAGE_STAMPS_AMOUNT, POSTAGE_STAMPS_DEPTH)
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)
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)
if(!isNaN(minCheques)) {
if (!isNaN(minCheques)) {
const beesUncashedCheques = []
for(const bee of bees) {
const beeDebug = bee.beeDebug
const { lastcheques } = await beeDebug.getLastCheques()
for (const beePair of bees) {
const { chequeReceiverBeeDebug } = beePair
const { lastcheques } = await chequeReceiverBeeDebug.getLastCheques()
const incomingCheques = lastcheques.filter(cheque => !!cheque.lastreceived)
const uncashedCheques = []
const lastCashOutPromises = incomingCheques.map(({ peer }) => beeDebug.getLastCashoutAction(peer))
const lastCashOutPromises = incomingCheques.map(({ peer }) => chequeReceiverBeeDebug.getLastCashoutAction(peer))
const lastCashOuts = await Promise.all(lastCashOutPromises)
for(const [index, lastCashOut] of lastCashOuts.entries()) {
if(BigInt(lastCashOut.uncashedAmount) > 0) {
for (const [index, lastCashOut] of lastCashOuts.entries()) {
if (BigInt(lastCashOut.uncashedAmount) > 0) {
uncashedCheques.push(incomingCheques[index])
}
}
beesUncashedCheques.push(uncashedCheques)
}
if(beesUncashedCheques.every(uncashedCheques => uncashedCheques.length >= minCheques)) {
console.log(`Generated at least ${minCheques} for every node on the given Debug API endpoints`,)
if (beesUncashedCheques.every(uncashedCheques => uncashedCheques.length >= minCheques)) {
console.log(`Generated at least ${minCheques} for every node on the given Debug API endpoints`)
break
} 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),
)
}
}
@ -123,8 +143,8 @@ let inputArray = process.argv.slice(2)
// then the traffic generation will go infinitely
let minCheques = parseInt(inputArray[0])
let hosts = inputArray.slice(1)
if(hosts.length === 0) {
hosts = [ 'http://localhost:1633;http://localhost:11635' ]
if (hosts.length === 0) {
hosts = ['http://localhost:1635;http://localhost:11633;http://localhost:11635']
}
genTrafficLoop(hosts, minCheques)