mirror of
https://github.com/logos-storage/codex-factory.git
synced 2026-01-02 13:03:07 +00:00
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:
parent
8151b5597e
commit
84e7925165
13
.prettierrc
Normal file
13
.prettierrc
Normal 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
65257
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -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": [
|
||||
|
||||
@ -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"
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -4,12 +4,13 @@ usage() {
|
||||
USAGE:
|
||||
$ build-environment.sh [PARAMETERS]
|
||||
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
|
||||
--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: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
|
||||
|
||||
@ -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,97 +48,103 @@ 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.
|
||||
*/
|
||||
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())
|
||||
*
|
||||
* @param {BeePair[]} beePairs
|
||||
*/
|
||||
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))
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* Generates cheques on the given Bee API EP
|
||||
*
|
||||
*
|
||||
* 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 {number} minCheques
|
||||
* 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: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),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
await sleep(SLEEP_BETWEEN_UPLOADS_MS)
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
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)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user