mirror of
https://github.com/logos-storage/codex-factory.git
synced 2026-01-04 05:53:09 +00:00
feat: 0.6.0 Bee (#4)
* feat: postage stamp * chore: remove empty postage stamp sol * fix: start the nodes with the new '--full-node' flag * chore: blockchain image 1.1.1 - updated factory bin (#29) * fix: add network id to the bee statup params * fix: change payment treshold limit to the possible min value * feat: add port-maps to the environment sh * fix: specify the same chainId as the networkId * feat: expose blockchain 9545 port to localhost * feat: extended postage stamp contract * refactor: remove price oracle setups * feat: updated the gen-traffic to work with postage stamps (#28) * feat: updated the gen-traffic to work with postage stamps * chore: update to latest bee-js version Co-authored-by: Vojtech Simetka <vojtech@simetka.cz>
This commit is contained in:
parent
e61f2cb8a1
commit
9e366130b8
1
contracts/PostageStamp.bytecode
Normal file
1
contracts/PostageStamp.bytecode
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -2,34 +2,58 @@ const ERC20PresetMinterPauser = artifacts.require("ERC20PresetMinterPauser");
|
|||||||
const FS = require('fs')
|
const FS = require('fs')
|
||||||
const Path = require('path')
|
const Path = require('path')
|
||||||
|
|
||||||
function getSimpleSwapFactoryBin(tokenAddress) {
|
function prefixedAddressParamToByteCode(address) {
|
||||||
const simpleSwapFactoryBinPath = Path.join(__dirname, '..', 'contracts', 'SimpleSwapFactory.bytecode')
|
// the first 2 chars removal removes 0x prefix
|
||||||
const baseBin = FS.readFileSync(simpleSwapFactoryBinPath, 'utf8').toString()
|
return address.substring(2).toLowerCase().padStart(64, '0')
|
||||||
//remove 0x prefix
|
|
||||||
tokenAddress = tokenAddress.substring(2).toLowerCase().padStart(64, '0')
|
|
||||||
//add tokenaddress for param to the end of the bytecode
|
|
||||||
return baseBin + tokenAddress
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function createSimpleSwapFactoryContract(erc20ContractAddress, creatorAccount) {
|
function getSimpleSwapFactoryBin(tokenAddress) {
|
||||||
|
const binPath = Path.join(__dirname, '..', 'contracts', 'SimpleSwapFactory.bytecode')
|
||||||
|
const bin = FS.readFileSync(binPath, 'utf8').toString()
|
||||||
|
tokenAddress = prefixedAddressParamToByteCode(tokenAddress)
|
||||||
|
//add tokenaddress for param to the end of the bytecode
|
||||||
|
return bin + tokenAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPostageStampBin(tokenAddress) {
|
||||||
|
const binPath = Path.join(__dirname, '..', 'contracts', 'PostageStamp.bytecode')
|
||||||
|
const bin = FS.readFileSync(binPath, 'utf8').toString()
|
||||||
|
tokenAddress = prefixedAddressParamToByteCode(tokenAddress)
|
||||||
|
//add tokenaddress for param to the end of the bytecode
|
||||||
|
return bin + tokenAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Returns back contract hash */
|
||||||
|
async function createContract(contractName, data, creatorAccount) {
|
||||||
const transaction = await web3.eth.sendTransaction({
|
const transaction = await web3.eth.sendTransaction({
|
||||||
data: getSimpleSwapFactoryBin(erc20ContractAddress),
|
data: data,
|
||||||
gasLimit: 6721975,
|
gasLimit: 6721975,
|
||||||
gasPrice: web3.utils.toWei('10', 'gwei'),
|
gasPrice: web3.utils.toWei('10', 'gwei'),
|
||||||
from: creatorAccount
|
from: creatorAccount
|
||||||
})
|
})
|
||||||
|
|
||||||
if(!transaction.status) {
|
if(!transaction.status) {
|
||||||
console.error('SimpleSwapFactory contract creation Error', error)
|
console.error(`${contractName} contract creation Error`, error)
|
||||||
throw new Error('Error happened at creating SimpleSwapFactory contract creation')
|
throw new Error(`Error happened at creating ${contractName} contract creation`)
|
||||||
}
|
}
|
||||||
console.log(`SimpleSwapFactory contract creation was successful!\n`
|
console.log(`${contractName} contract creation was successful!\n`
|
||||||
+ `\tTransaction ID: ${transaction.transactionHash}\n`
|
+ `\tTransaction ID: ${transaction.transactionHash}\n`
|
||||||
+ `\tContract ID: ${transaction.contractAddress}`)
|
+ `\tContract ID: ${transaction.contractAddress}`)
|
||||||
|
|
||||||
|
return transaction.contractAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createSimpleSwapFactoryContract(erc20ContractAddress, creatorAccount) {
|
||||||
|
return createContract('SimpleSwapFactory', getSimpleSwapFactoryBin(erc20ContractAddress), creatorAccount)
|
||||||
|
}
|
||||||
|
|
||||||
|
async function createPostageStampContract(erc20ContractAddress, creatorAccount) {
|
||||||
|
return createContract('PostageStamp', getPostageStampBin(erc20ContractAddress), creatorAccount)
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = function (deployer, network, accounts) {
|
module.exports = function (deployer, network, accounts) {
|
||||||
deployer.deploy(ERC20PresetMinterPauser, "Swarm Token", "BZZ").then(async () => {
|
deployer.deploy(ERC20PresetMinterPauser, "Swarm Token", "BZZ").then(async () => {
|
||||||
await createSimpleSwapFactoryContract(ERC20PresetMinterPauser.address, accounts[0])
|
await createSimpleSwapFactoryContract(ERC20PresetMinterPauser.address, accounts[0])
|
||||||
|
await createPostageStampContract(ERC20PresetMinterPauser.address, accounts[0])
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
3814
package-lock.json
generated
3814
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -12,7 +12,7 @@
|
|||||||
"gen:traffic": "node ./scripts/gen-traffic.js"
|
"gen:traffic": "node ./scripts/gen-traffic.js"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@ethersphere/bee-js": "^0.8.1",
|
"@ethersphere/bee-js": "github:ethersphere/bee-js#bee-0.6.0",
|
||||||
"@openzeppelin/contracts": "^3.1.0",
|
"@openzeppelin/contracts": "^3.1.0",
|
||||||
"axios": "^0.20.0",
|
"axios": "^0.20.0",
|
||||||
"truffle": "^5.3.5"
|
"truffle": "^5.3.5"
|
||||||
|
|||||||
@ -1,5 +1,5 @@
|
|||||||
BEE_VERSION="0.5.3"
|
BEE_VERSION="latest"
|
||||||
BLOCKCHAIN_VERSION="1.0.0"
|
BLOCKCHAIN_VERSION="1.1.1"
|
||||||
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"
|
||||||
COMMIT_VERSION_TAG="false"
|
COMMIT_VERSION_TAG="false"
|
||||||
|
|||||||
@ -16,12 +16,12 @@ PARAMETERS:
|
|||||||
1. 1633:1635
|
1. 1633:1635
|
||||||
2. 11633:11635
|
2. 11633:11635
|
||||||
3. 21633:21635 (...)
|
3. 21633:21635 (...)
|
||||||
number represents the nodes number to map from. Default is 4.
|
number represents the nodes number to map from. Default is 2.
|
||||||
--password=string password for Bee client(s).
|
--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.
|
--own-image If passed, the used Docker image names will be identical as the name of the workers.
|
||||||
--version=x.y.z used version of Bee client.
|
--version=x.y.z used version of Bee client.
|
||||||
--detach It will not log the output of Queen node at the end of the process.
|
--detach It will not log the output of Queen node at the end of the process.
|
||||||
--payment-threshold The threshold in BZZ where you expect to get paid from your peers. (without decimals, default: 10000000000000)
|
--payment-threshold The threshold in BZZ where you expect to get paid from your peers. (without decimals, default: 310000000000)
|
||||||
USAGE
|
USAGE
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
@ -106,8 +106,9 @@ QUEEN_BOOTNODE=""
|
|||||||
PORT_MAPS=2
|
PORT_MAPS=2
|
||||||
SWAP=true
|
SWAP=true
|
||||||
SWAP_FACTORY_ADDRESS="0x5b1869D9A4C187F2EAa108f3062412ecf0526b24"
|
SWAP_FACTORY_ADDRESS="0x5b1869D9A4C187F2EAa108f3062412ecf0526b24"
|
||||||
|
POSTAGE_STAMP_ADDRESS="0xCfEB869F69431e42cdB54A4F4f105C19C080A601"
|
||||||
INIT_ROOT_DATA_DIR="$MY_PATH/bee-data-dirs"
|
INIT_ROOT_DATA_DIR="$MY_PATH/bee-data-dirs"
|
||||||
PAYMENT_THRESHOLD="10000000000000"
|
PAYMENT_THRESHOLD="310000000000"
|
||||||
|
|
||||||
# Decide script action
|
# Decide script action
|
||||||
case "$1" in
|
case "$1" in
|
||||||
@ -204,6 +205,9 @@ if [ -z "$QUEEN_CONTAINER_IN_DOCKER" ] || $EPHEMERAL ; then
|
|||||||
--swap-endpoint="http://$SWARM_BLOCKCHAIN_NAME:9545" \
|
--swap-endpoint="http://$SWARM_BLOCKCHAIN_NAME:9545" \
|
||||||
--swap-factory-address=$SWAP_FACTORY_ADDRESS \
|
--swap-factory-address=$SWAP_FACTORY_ADDRESS \
|
||||||
--payment-threshold="$PAYMENT_THRESHOLD" \
|
--payment-threshold="$PAYMENT_THRESHOLD" \
|
||||||
|
--postage-stamp-address=$POSTAGE_STAMP_ADDRESS \
|
||||||
|
--network-id 4020 \
|
||||||
|
--full-node=true \
|
||||||
--welcome-message="You have found the queen of the beehive..." \
|
--welcome-message="You have found the queen of the beehive..." \
|
||||||
--cors-allowed-origins="*"
|
--cors-allowed-origins="*"
|
||||||
else
|
else
|
||||||
@ -249,6 +253,9 @@ for i in $(seq 1 1 "$WORKERS"); do
|
|||||||
--swap-endpoint="http://$SWARM_BLOCKCHAIN_NAME:9545" \
|
--swap-endpoint="http://$SWARM_BLOCKCHAIN_NAME:9545" \
|
||||||
--swap-factory-address=$SWAP_FACTORY_ADDRESS \
|
--swap-factory-address=$SWAP_FACTORY_ADDRESS \
|
||||||
--payment-threshold="$PAYMENT_THRESHOLD" \
|
--payment-threshold="$PAYMENT_THRESHOLD" \
|
||||||
|
--postage-stamp-address=$POSTAGE_STAMP_ADDRESS \
|
||||||
|
--network-id 4020 \
|
||||||
|
--full-node=true \
|
||||||
--welcome-message="I'm just Bee worker ${i} in the beehive." \
|
--welcome-message="I'm just Bee worker ${i} in the beehive." \
|
||||||
--cors-allowed-origins="*"
|
--cors-allowed-origins="*"
|
||||||
else
|
else
|
||||||
|
|||||||
@ -17,6 +17,7 @@ if [ -z "$CONTAINER_IN_DOCKER" ]; then
|
|||||||
trufflesuite/ganache-cli ganache-cli \
|
trufflesuite/ganache-cli ganache-cli \
|
||||||
-d -i 4020 -h 0.0.0.0 -p 9545 \
|
-d -i 4020 -h 0.0.0.0 -p 9545 \
|
||||||
-b 1 \
|
-b 1 \
|
||||||
|
--chainId 4020 \
|
||||||
--db swarm-testchain --gasLimit 6721975
|
--db swarm-testchain --gasLimit 6721975
|
||||||
else
|
else
|
||||||
docker start $NAME
|
docker start $NAME
|
||||||
|
|||||||
@ -10,7 +10,12 @@ PARAMETERS:
|
|||||||
--ephemeral create ephemeral container for bee-client. Data won't be persisted.
|
--ephemeral create ephemeral container for bee-client. Data won't be persisted.
|
||||||
--workers=number all Bee nodes in the test environment. Default is 4.
|
--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.
|
--detach It will not log the output of Queen node at the end of the process.
|
||||||
--payment-treshold excess debt above payment threshold in BZZ where you disconnect from your peer (without decimals, default: 2000000000)
|
--payment-treshold excess debt above payment threshold in BZZ where you disconnect from your peer (without decimals, default: 310000000000)
|
||||||
|
--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 (...)
|
||||||
|
number represents the nodes number to map from. Default is 2.
|
||||||
USAGE
|
USAGE
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
@ -39,7 +44,8 @@ WORKERS=4
|
|||||||
LOG=true
|
LOG=true
|
||||||
SWARM_BLOCKCHAIN_NAME="$BEE_ENV_PREFIX-blockchain"
|
SWARM_BLOCKCHAIN_NAME="$BEE_ENV_PREFIX-blockchain"
|
||||||
SWARM_NETWORK="$BEE_ENV_PREFIX-network"
|
SWARM_NETWORK="$BEE_ENV_PREFIX-network"
|
||||||
PAYMENT_THRESHOLD="2000000000"
|
PAYMENT_THRESHOLD="310000000000"
|
||||||
|
PORT_MAPS=2
|
||||||
|
|
||||||
# Decide script action
|
# Decide script action
|
||||||
case "$1" in
|
case "$1" in
|
||||||
@ -72,6 +78,10 @@ do
|
|||||||
PAYMENT_THRESHOLD=${1#*=}
|
PAYMENT_THRESHOLD=${1#*=}
|
||||||
shift 1
|
shift 1
|
||||||
;;
|
;;
|
||||||
|
--port-maps=*)
|
||||||
|
PORT_MAPS="${1#*=}"
|
||||||
|
shift 1
|
||||||
|
;;
|
||||||
--detach)
|
--detach)
|
||||||
LOG=false
|
LOG=false
|
||||||
shift 1
|
shift 1
|
||||||
@ -93,7 +103,7 @@ echo "Create Docker network..."
|
|||||||
echo "Start Blockchain node..."
|
echo "Start Blockchain node..."
|
||||||
BLOCKCHAIN_CONTAINER=$(docker container ls -qaf name=$SWARM_BLOCKCHAIN_NAME)
|
BLOCKCHAIN_CONTAINER=$(docker container ls -qaf name=$SWARM_BLOCKCHAIN_NAME)
|
||||||
if [ -z "$BLOCKCHAIN_CONTAINER" ] ; then
|
if [ -z "$BLOCKCHAIN_CONTAINER" ] ; then
|
||||||
BLOCKCHAIN_ARGUMENTS="--name $SWARM_BLOCKCHAIN_NAME --network $SWARM_NETWORK -d"
|
BLOCKCHAIN_ARGUMENTS="--name $SWARM_BLOCKCHAIN_NAME --network $SWARM_NETWORK -p 127.0.0.1:9545:9545 -d"
|
||||||
if $EPHEMERAL ; then
|
if $EPHEMERAL ; then
|
||||||
BLOCKCHAIN_ARGUMENTS="$BLOCKCHAIN_ARGUMENTS --rm"
|
BLOCKCHAIN_ARGUMENTS="$BLOCKCHAIN_ARGUMENTS --rm"
|
||||||
fi
|
fi
|
||||||
@ -106,7 +116,7 @@ fi
|
|||||||
sleep 5
|
sleep 5
|
||||||
|
|
||||||
# Build up bee.sh parameters
|
# Build up bee.sh parameters
|
||||||
BEE_SH_ARGUMENTS="--workers=$WORKERS --own-image --payment-treshold=$PAYMENT_THRESHOLD"
|
BEE_SH_ARGUMENTS="--workers=$WORKERS --own-image --payment-treshold=$PAYMENT_THRESHOLD --port-maps=$PORT_MAPS"
|
||||||
if $EPHEMERAL ; then
|
if $EPHEMERAL ; then
|
||||||
BEE_SH_ARGUMENTS="$BEE_SH_ARGUMENTS --ephemeral"
|
BEE_SH_ARGUMENTS="$BEE_SH_ARGUMENTS --ephemeral"
|
||||||
fi
|
fi
|
||||||
|
|||||||
@ -1,7 +1,9 @@
|
|||||||
const axios = require('axios').default;
|
const axios = require('axios').default;
|
||||||
const Bee = require('@ethersphere/bee-js').Bee;
|
const Bee = require('@ethersphere/bee-js').Bee;
|
||||||
|
|
||||||
const SLEEP_BETWEEN_UPLOADS_MS = 1000
|
const SLEEP_BETWEEN_UPLOADS_MS = 100
|
||||||
|
const POSTAGE_STAMPS_AMOUNT = BigInt(10000)
|
||||||
|
const POSTAGE_STAMPS_DEPTH = 20
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Lehmer random number generator with seed (minstd_rand in C++11)
|
* Lehmer random number generator with seed (minstd_rand in C++11)
|
||||||
@ -32,22 +34,21 @@ function randomByteArray(length, seed = 500) {
|
|||||||
return buf
|
return buf
|
||||||
}
|
}
|
||||||
|
|
||||||
async function trafficGen(host = 'http://localhost:1633', seed = 500, bytes = 1024 * 4 * 400) {
|
async function trafficGen(bee, postageBatchId, seed = 500, bytes = 1024 * 4 * 400) {
|
||||||
const randomBytes = randomByteArray(bytes, seed)
|
const randomBytes = randomByteArray(bytes, seed)
|
||||||
const bee = new Bee(host)
|
const ref = await bee.uploadData(postageBatchId, randomBytes)
|
||||||
const ref = await bee.uploadData(randomBytes)
|
|
||||||
console.log(`Generated ${bytes} bytes traffic, the random data's root reference: ${ref}`)
|
console.log(`Generated ${bytes} bytes traffic, the random data's root reference: ${ref}`)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate traffic on Bee node(s)
|
* Generate traffic on Bee node(s)
|
||||||
*
|
*
|
||||||
* @param beeApiUrls Bee API URLs where the random generated data will be sent to.
|
* @param bees Array of Bee instances and postage batches where the random generated data will be sent to.
|
||||||
*/
|
*/
|
||||||
async function genTrafficOnOpenPorts(beeApiUrls) {
|
async function genTrafficOnOpenPorts(bees) {
|
||||||
const promises = beeApiUrls.map((url) => {
|
const promises = bees.map(({bee, postageBatchId}) => {
|
||||||
console.log(`Generate Swarm Chunk traffic on ${url}...`)
|
console.log(`Generate Swarm Chunk traffic on ${bee.url}...`)
|
||||||
return trafficGen(url, new Date().getTime())
|
return trafficGen(bee, postageBatchId, new Date().getTime())
|
||||||
})
|
})
|
||||||
await Promise.all(promises)
|
await Promise.all(promises)
|
||||||
}
|
}
|
||||||
@ -57,8 +58,20 @@ function sleep(ms) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function genTrafficLoop(hosts) {
|
async function genTrafficLoop(hosts) {
|
||||||
|
const promisses = hosts.map(async (host) => {
|
||||||
|
const bee = new Bee(host)
|
||||||
|
|
||||||
|
console.log(`Generating postage stamps on ${host}...`)
|
||||||
|
const postageBatchId = await bee.createPostageBatch(POSTAGE_STAMPS_AMOUNT, POSTAGE_STAMPS_DEPTH)
|
||||||
|
console.log(`Generated ${postageBatchId} postage stamp on ${host}...`)
|
||||||
|
|
||||||
|
return {bee, postageBatchId}
|
||||||
|
})
|
||||||
|
|
||||||
|
const bees = await Promise.all(promisses)
|
||||||
|
|
||||||
while(true) {
|
while(true) {
|
||||||
await genTrafficOnOpenPorts(hosts)
|
await genTrafficOnOpenPorts(bees)
|
||||||
|
|
||||||
await sleep(SLEEP_BETWEEN_UPLOADS_MS)
|
await sleep(SLEEP_BETWEEN_UPLOADS_MS)
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user