├── etc ├── region.conf ├── storage.ab ├── mode.conf └── watch-chain.yaml ├── .idea ├── .gitignore ├── misc.xml ├── vcs.xml ├── inspectionProfiles │ └── profiles_settings.xml ├── modules.xml └── spacex-script.iml ├── generator ├── config-validator.js ├── schema │ ├── api.schema.js │ ├── chain.schema.js │ ├── node.schema.js │ ├── identity.schema.js │ └── index.js ├── Dockerfile ├── logger.js ├── package.json ├── utils.js ├── config-gen │ ├── api-config.gen.js │ ├── ipfs-config.gen.js │ ├── storage-config.gen.js │ ├── sdatamanager-config.gen.js │ ├── chain-config.gen.js │ └── index.js ├── key-utils.js ├── index.js ├── .gitignore └── pnpm-lock.yaml ├── scripts ├── uninstall.sh ├── online_install.sh ├── auto_sdatamanager.sh ├── install_sgx.sh ├── version.sh ├── sgx_detect.sh ├── utils.sh ├── config.sh ├── tools.sh └── spacex.sh ├── config.yaml ├── docs ├── build-node.md ├── guardian.md └── miner.md ├── README.md ├── tools └── test-sgx.c ├── install.sh └── LICENSE /etc/region.conf: -------------------------------------------------------------------------------- 1 | en -------------------------------------------------------------------------------- /etc/storage.ab: -------------------------------------------------------------------------------- 1 | a -------------------------------------------------------------------------------- /etc/mode.conf: -------------------------------------------------------------------------------- 1 | isolation -------------------------------------------------------------------------------- /.idea/.gitignore: -------------------------------------------------------------------------------- 1 | # Default ignored files 2 | /shelf/ 3 | /workspace.xml 4 | -------------------------------------------------------------------------------- /generator/config-validator.js: -------------------------------------------------------------------------------- 1 | 2 | 3 | function validate(config) { 4 | return config 5 | } 6 | 7 | module.exports = { 8 | validate, 9 | } 10 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /generator/schema/api.schema.js: -------------------------------------------------------------------------------- 1 | const Joi = require('joi') 2 | 3 | const apiSchema = Joi.object({ 4 | ws: Joi.string().required().default("ws://127.0.0.1:19944"), 5 | }) 6 | 7 | module.exports = { 8 | apiSchema, 9 | } 10 | -------------------------------------------------------------------------------- /.idea/inspectionProfiles/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 6 | -------------------------------------------------------------------------------- /generator/schema/chain.schema.js: -------------------------------------------------------------------------------- 1 | const Joi = require('joi') 2 | 3 | const chainSchema = Joi.object({ 4 | name: Joi.string().required(), 5 | port: Joi.number().port().default(30888), 6 | }) 7 | 8 | module.exports = { 9 | chainSchema, 10 | } 11 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /.idea/spacex-script.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /scripts/uninstall.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | installdir=/opt/mannheimworld/spacex-script 4 | bin_file=/usr/bin/spacex 5 | 6 | if [ $(id -u) -ne 0 ]; then 7 | echo "Please run with sudo!" 8 | exit 1 9 | fi 10 | 11 | if [ -f "$bin_file" ]; then 12 | spacex stop 13 | rm /usr/bin/spacex 14 | fi 15 | 16 | rm -rf $installdir 17 | -------------------------------------------------------------------------------- /generator/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM "node:12-buster" 2 | 3 | RUN apt-get update && apt-get install -y wget 4 | RUN wget https://github.com/mannheim-network/spacex-script/releases/download/subkey-2.0.1/subkey -O /usr/local/bin/subkey 5 | RUN chmod +x /usr/local/bin/subkey 6 | 7 | ENV KEY_TOOL /usr/local/bin/subkey 8 | 9 | COPY . /opt/app 10 | WORKDIR /opt/app 11 | RUN npm i 12 | -------------------------------------------------------------------------------- /generator/schema/node.schema.js: -------------------------------------------------------------------------------- 1 | const Joi = require('joi') 2 | 3 | const nodeSchema = Joi.object({ 4 | chain: Joi.string().valid('authority', 'full').required(), 5 | storage: Joi.string().valid('enable', 'disable').required(), 6 | sdatamanager: Joi.string().valid('disable', 'isolation', 'member').required(), 7 | ipfs: Joi.string().valid('enable', 'disable').required(), 8 | }) 9 | 10 | module.exports = { 11 | nodeSchema, 12 | } -------------------------------------------------------------------------------- /generator/logger.js: -------------------------------------------------------------------------------- 1 | // 2 | // logger utils 3 | const winston = require('winston') 4 | 5 | const logger = winston.createLogger({ 6 | level: 'debug', 7 | format: winston.format.simple(), 8 | }) 9 | 10 | logger.add(new winston.transports.Console({ 11 | format: winston.format.combine( 12 | winston.format.colorize(), 13 | winston.format.splat(), 14 | winston.format.simple() 15 | ) 16 | })) 17 | 18 | module.exports = { 19 | logger, 20 | } 21 | -------------------------------------------------------------------------------- /generator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "config-generator", 3 | "version": "1.1.0", 4 | "description": "", 5 | "main": "index.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "", 10 | "license": "MIT", 11 | "dependencies": { 12 | "bluebird": "^3.7.2", 13 | "execa": "^4.0.3", 14 | "fs-extra": "^9.0.1", 15 | "joi": "^17.1.1", 16 | "js-yaml": "^3.14.0", 17 | "lodash": "^4.17.19", 18 | "shelljs": "^0.8.4", 19 | "winston": "^3.3.3" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /generator/utils.js: -------------------------------------------------------------------------------- 1 | const fs = require('fs-extra') 2 | const shell = require('shelljs') 3 | const yaml = require('js-yaml') 4 | 5 | async function createDir(dir) { 6 | if(shell.mkdir('-p', dir).code !== 0) { 7 | throw `failed to create directory: ${dir}` 8 | } 9 | } 10 | 11 | async function writeConfig(path, cfg) { 12 | await fs.outputJson(path, cfg, { 13 | spaces: 2, 14 | }) 15 | return true 16 | } 17 | 18 | async function writeYaml(path, cfg) { 19 | await fs.outputFile(path, yaml.safeDump(cfg, { 20 | ident: 2, 21 | })) 22 | return true 23 | } 24 | 25 | 26 | module.exports = { 27 | createDir, 28 | writeConfig, 29 | writeYaml, 30 | } 31 | -------------------------------------------------------------------------------- /config.yaml: -------------------------------------------------------------------------------- 1 | ## node configurations 2 | node: 3 | ## the type of spacex: authority/full 4 | chain: "authority" 5 | ## the type of storage: disable/enable 6 | storage: "enable" 7 | ## the type of sdatamanager: disable/bridge/miner 8 | sdatamanager: "disable" 9 | ## the type of ipfs: disable/enable 10 | ipfs: "disable" 11 | 12 | ## identity configurations 13 | identity: 14 | ## the backup of chain account 15 | backup: '' 16 | ## the password of chain account 17 | password: "" 18 | 19 | ## chain configurations 20 | chain: 21 | ## the name of chain node 22 | name: "spacex-node" 23 | ## the port of chain node 24 | port: 30888 25 | 26 | api: 27 | ## the url for chain 28 | ws: "ws://127.0.0.1:19944" 29 | -------------------------------------------------------------------------------- /generator/config-gen/api-config.gen.js: -------------------------------------------------------------------------------- 1 | async function genApiConfig(config, outputCfg) { 2 | const apiConfig = { 3 | port: 56666, 4 | chain_ws_url: config.api.ws, 5 | } 6 | return { 7 | config: apiConfig, 8 | paths: [], 9 | } 10 | } 11 | 12 | async function genApiComposeConfig(config) { 13 | const args = [ 14 | '56666', 15 | `${config.api.ws}`, 16 | ].join(' ') 17 | return { 18 | image: 'mannheimworld/spacex-api:latest', 19 | network_mode: 'host', 20 | restart: 'always', 21 | environment: { 22 | ARGS: args, 23 | }, 24 | logging: { 25 | driver: "json-file", 26 | options: { 27 | "max-size": "500m" 28 | } 29 | }, 30 | } 31 | } 32 | 33 | module.exports = { 34 | genApiConfig, 35 | genApiComposeConfig, 36 | } 37 | -------------------------------------------------------------------------------- /scripts/online_install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | version=$1 4 | shift 5 | 6 | if [ $(id -u) -ne 0 ]; then 7 | echo "Please run with sudo!" 8 | exit 1 9 | fi 10 | 11 | wget https://github.com/mannheim-network/spacex-script/archive/v$version.tar.gz 12 | if [ $res -ne 0 ]; then 13 | echo "Download v$version.tar.gz failed" 14 | exit 1 15 | fi 16 | 17 | tar -xvf v$version.tar.gz 18 | if [ $res -ne 0 ]; then 19 | echo "Unzip v$version.tar.gz failed" 20 | rm v$version.tar.gz 21 | exit 1 22 | fi 23 | 24 | ./spacex-script-$version/install.sh $@ 25 | if [ $res -ne 0 ]; then 26 | echo "Install spacex node $version failed" 27 | rm v$version.tar.gz 28 | rm -rf spacex-script-$version 29 | exit 1 30 | fi 31 | 32 | rm v$version.tar.gz 33 | rm -rf spacex-script-$version 34 | exit 0 35 | -------------------------------------------------------------------------------- /generator/schema/identity.schema.js: -------------------------------------------------------------------------------- 1 | const Joi = require('joi') 2 | const bluebird = require('bluebird') 3 | const { logger } = require('../logger') 4 | 5 | const backupSchema = Joi.object({ 6 | address: Joi.string().required(), 7 | }) 8 | 9 | const identitySchema = Joi.object({ 10 | backup: Joi.string().custom((value, helpers) => { 11 | try { 12 | const result = backupSchema.validate(JSON.parse(value), {allowUnknown: true}) 13 | if (result.error) { 14 | return helpers.error(result.error) 15 | } 16 | return result.value 17 | } catch(ex) { 18 | logger.error('Failed to parse json: %s', ex) 19 | return helpers.error('Backup is not a valid json string') 20 | } 21 | }).required(), 22 | password: Joi.string().min(1).required(), 23 | }) 24 | 25 | module.exports = { 26 | identitySchema, 27 | } 28 | -------------------------------------------------------------------------------- /generator/schema/index.js: -------------------------------------------------------------------------------- 1 | 2 | const Joi = require('joi') 3 | const { chainSchema } = require('./chain.schema') 4 | const { apiSchema } = require('./api.schema') 5 | const { identitySchema } = require('./identity.schema') 6 | const { nodeSchema } = require('./node.schema') 7 | 8 | function getConfigSchema(config) { 9 | let sMap = { 10 | node: nodeSchema.required(), 11 | chain: chainSchema.required(), 12 | } 13 | 14 | if (config.node.storage == "enable") { 15 | sMap["api"] = apiSchema.required() 16 | sMap["identity"] = identitySchema.required() 17 | sMap["storage"] = Joi.object().default() 18 | } 19 | 20 | if (config.node.sdatamanager != "disable") { 21 | sMap["identity"] = identitySchema.required() 22 | sMap["sdatamanager"] = Joi.object().default() 23 | } 24 | 25 | if (config.node.ipfs == "enable") { 26 | sMap["ipfs"] = Joi.object().default() 27 | } 28 | 29 | return Joi.object(sMap) 30 | } 31 | 32 | module.exports = { 33 | getConfigSchema, 34 | } 35 | -------------------------------------------------------------------------------- /generator/key-utils.js: -------------------------------------------------------------------------------- 1 | const _ = require('lodash') 2 | const execa = require('execa') 3 | const { logger } = require('./logger') 4 | 5 | async function inspectKey(address) { 6 | const keyTool = process.env['KEY_TOOL'] 7 | if (!keyTool) { 8 | throw 'key tool path not specified' 9 | } 10 | const {stdout} = await execa(keyTool, ['inspect', address]); 11 | 12 | const rows = _.chain(stdout).split('\n').map(_.trim) 13 | const accountId = extractAccountId(rows) 14 | if (!accountId) { 15 | logger.warn('Invalid address: %s!', address) 16 | throw `address is invalid ${address}` 17 | } 18 | return { 19 | address, 20 | accountId, 21 | } 22 | } 23 | 24 | function extractAccountId(outputs) { 25 | const accountIdPrefix = 'Account ID:' 26 | const ids = outputs.filter(v =>_.startsWith(v, accountIdPrefix)).map(v => v.substr(accountIdPrefix.length)).map(_.trim).value() 27 | if (_.isEmpty(ids)) { 28 | return null 29 | } 30 | 31 | return ids[0].substring(2) 32 | } 33 | 34 | 35 | module.exports = { 36 | inspectKey, 37 | } 38 | -------------------------------------------------------------------------------- /etc/watch-chain.yaml: -------------------------------------------------------------------------------- 1 | version: '3.0' 2 | services: 3 | spacex: 4 | image: 'mannheimworld/spacex:latest' 5 | network_mode: host 6 | volumes: 7 | - '/opt/mannheimworld/data/watchchain:/opt/mannheimworld/data/watchchain' 8 | command: 9 | - ./spacex 10 | - '--base-path' 11 | - /opt/mannheimworld/data/watchchain 12 | - '--chain' 13 | - rubik 14 | - '--port' 15 | - '30888' 16 | - '--name' 17 | - spacex-script 18 | - '--rpc-port' 19 | - '19933' 20 | - '--ws-port' 21 | - '19944' 22 | - '--execution' 23 | - 'WASM' 24 | - '--wasm-execution' 25 | - compiled 26 | - '--in-peers' 27 | - '75' 28 | - '--out-peers' 29 | - '75' 30 | - '--no-telemetry' 31 | - '--pruning' 32 | - '8000' 33 | - '--ws-max-connections' 34 | - '50000' 35 | - '--ws-external' 36 | - '--rpc-external' 37 | - '--rpc-cors' 38 | - 'all' 39 | logging: 40 | driver: json-file 41 | options: 42 | max-size: 500m 43 | container_name: spacex-watch 44 | -------------------------------------------------------------------------------- /scripts/auto_sdatamanager.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source /opt/mannheimworld/spacex-script/scripts/utils.sh 4 | 5 | auto_sdatamanager_main() 6 | { 7 | log_info "Start sdatamanager auto upgrade task." 8 | local rnd=$(rand 1 200) 9 | log_info "Random sleep $rnd s" 10 | sleep $rnd 11 | while : 12 | do 13 | sleep 900 14 | log_info "New check Round" 15 | 16 | upgrade_docker_image spacex-sdatamanager $node_type 17 | if [ $? -ne 0 ]; then 18 | continue 19 | fi 20 | 21 | log_info "Found a new sdatamanager version, ready to upgrade..." 22 | log_success "Image has been updated" 23 | 24 | check_docker_status spacex-sdatamanager 25 | if [ $? -eq 1 ]; then 26 | log_info "Service spacex sdatamanager is not started now" 27 | log_success "Update completed" 28 | continue 29 | fi 30 | 31 | docker-compose -f $composeyaml up -d spacex-sdatamanager 32 | if [ $? -ne 0 ]; then 33 | log_err "Start spacex-sdatamanager failed" 34 | continue 35 | fi 36 | 37 | log_success "spacex sdatamanager service has been updated" 38 | log_success "Update completed" 39 | done 40 | } 41 | 42 | auto_sdatamanager_main -------------------------------------------------------------------------------- /generator/config-gen/ipfs-config.gen.js: -------------------------------------------------------------------------------- 1 | async function genIpfsConfig(config, outputCfg) { 2 | const ipfsConfig = { 3 | swarm_port: 4001, 4 | api_port: 5001, 5 | gateway_port: 37773, 6 | path: '/opt/mannheimworld/data/ipfs' 7 | } 8 | return { 9 | config: ipfsConfig, 10 | paths: [{ 11 | required: true, 12 | path: '/opt/mannheimworld/data/ipfs', 13 | }], 14 | } 15 | } 16 | 17 | async function genIpfsComposeConfig(config) { 18 | return { 19 | image: 'mannheimworld/go-ipfs:latest', 20 | network_mode: 'host', 21 | restart: 'always', 22 | volumes: [ 23 | '/opt/mannheimworld/data/ipfs:/data/ipfs' 24 | ], 25 | entrypoint: '/sbin/tini --', 26 | environment: { 27 | IPFS_PROFILE: 'leveldb', 28 | }, 29 | logging: { 30 | driver: "json-file", 31 | options: { 32 | "max-size": "500m" 33 | } 34 | }, 35 | command: '/bin/sh -c "/usr/local/bin/start_ipfs config Addresses.Gateway /ip4/0.0.0.0/tcp/37773 && /usr/local/bin/start_ipfs config Datastore.StorageMax 250GB && /usr/local/bin/start_ipfs bootstrap add /ip4/101.33.32.103/tcp/4001/p2p/12D3KooWEVFe1uGbgsDCgt9GV5sAC864RNPPDJLTnX9phoWHuV2d && /usr/local/bin/start_ipfs daemon --enable-gc --migrate=true"', 36 | } 37 | } 38 | 39 | module.exports = { 40 | genIpfsConfig, 41 | genIpfsComposeConfig, 42 | } 43 | -------------------------------------------------------------------------------- /generator/config-gen/storage-config.gen.js: -------------------------------------------------------------------------------- 1 | const _ = require('lodash') 2 | const { getSharedChainConfig } = require('./chain-config.gen') 3 | 4 | async function genStorageConfig(config, outputCfg) { 5 | var dataPaths = [] 6 | 7 | for (i = 1; i <= 128; i++) { 8 | dataPaths.push("/opt/mannheimworld/disks/" + i) 9 | } 10 | 11 | const storageConfig = { 12 | base_path: "/opt/mannheimworld/data/storage", 13 | base_url: "http://127.0.0.1:12222/api/v0", 14 | chain: getSharedChainConfig(config), 15 | data_path: dataPaths, 16 | ipfs_url: "http://127.0.0.1:5001/api/v0", 17 | } 18 | return { 19 | config: storageConfig, 20 | paths: [{ 21 | required: true, 22 | path: '/opt/mannheimworld/data/storage', 23 | }, { 24 | required: true, 25 | path: '/opt/mannheimworld/disks', 26 | }], 27 | } 28 | } 29 | 30 | async function genStorageComposeConfig(config) { 31 | let tempVolumes = [ 32 | '/opt/mannheimworld/data/storage:/opt/mannheimworld/data/storage', 33 | '/opt/mannheimworld/disks:/opt/mannheimworld/disks', 34 | './storage:/config' 35 | ] 36 | 37 | return { 38 | image: 'mannheimworld/spacex-storage:latest', 39 | network_mode: 'host', 40 | devices: [ 41 | '/dev/isgx:/dev/isgx' 42 | ], 43 | volumes: tempVolumes, 44 | environment: { 45 | ARGS: '-c /config/storage_config.json $EX_STORAGE_ARGS', 46 | }, 47 | logging: { 48 | driver: "json-file", 49 | options: { 50 | "max-size": "500m" 51 | } 52 | }, 53 | } 54 | } 55 | 56 | module.exports = { 57 | genStorageConfig, 58 | genStorageComposeConfig, 59 | } 60 | -------------------------------------------------------------------------------- /generator/config-gen/sdatamanager-config.gen.js: -------------------------------------------------------------------------------- 1 | async function genSdatamanagerConfig(config, outputCfg) { 2 | const sdatamanagerConfig = { 3 | chain: { 4 | account: config.identity.backup.address, 5 | endPoint: config.api.ws 6 | }, 7 | storage: { 8 | endPoint: "http://127.0.0.1:12222" 9 | }, 10 | ipfs: { 11 | endPoint: "http://127.0.0.1:5001" 12 | }, 13 | node: { 14 | role: config.node.sdatamanager 15 | }, 16 | telemetry: { 17 | endPoint: "#####.#####" 18 | }, 19 | dataDir: "/data", 20 | scheduler: { 21 | minSrdRatio: 30, 22 | strategy: { 23 | existedFilesWeight: 0, 24 | newFilesWeight: 100 25 | } 26 | } 27 | } 28 | 29 | return { 30 | config: sdatamanagerConfig, 31 | paths: [{ 32 | required: true, 33 | path: '/opt/mannheimworld/data/sdatamanager', 34 | }], 35 | } 36 | } 37 | 38 | async function genSdatamanagerComposeConfig(config) { 39 | return { 40 | image: 'mannheimworld/spacex-sdatamanager:latest', 41 | network_mode: 'host', 42 | restart: 'unless-stopped', 43 | environment: { 44 | SDATAMANAGER_CONFIG: "/config/sdatamanager_config.json", 45 | }, 46 | volumes: [ 47 | './sdatamanager:/config', 48 | '/opt/mannheimworld/data/sdatamanager:/data' 49 | ], 50 | logging: { 51 | driver: "json-file", 52 | options: { 53 | "max-size": "500m" 54 | } 55 | }, 56 | } 57 | } 58 | 59 | module.exports = { 60 | genSdatamanagerConfig, 61 | genSdatamanagerComposeConfig, 62 | } 63 | 64 | -------------------------------------------------------------------------------- /generator/config-gen/chain-config.gen.js: -------------------------------------------------------------------------------- 1 | async function genChainConfig(config, outputCfg) { 2 | const chainConfig = config.chain 3 | return { 4 | config: chainConfig, 5 | paths: [{ 6 | required: true, 7 | path: config.chain.base_path, 8 | }], 9 | } 10 | } 11 | 12 | async function genChainComposeConfig(config) { 13 | let args = [ 14 | './spacex', 15 | '--base-path', 16 | '/opt/mannheimworld/data/chain', 17 | '--chain', 18 | 'rubik', 19 | '--port', 20 | `${config.chain.port}`, 21 | '--name', 22 | `${config.chain.name}`, 23 | '--rpc-port', 24 | '19933', 25 | '--ws-port', 26 | '19944', 27 | '--execution', 28 | 'WASM', 29 | '--wasm-execution', 30 | 'compiled', 31 | '--in-peers', 32 | '75', 33 | '--out-peers', 34 | '75' 35 | ] 36 | 37 | if (config.node.chain == "authority") { 38 | args.push('--validator', '--pruning', 'archive') 39 | } 40 | 41 | if (config.node.chain == "full") { 42 | args.push('--no-telemetry', '--pruning', '8000') 43 | } 44 | 45 | return { 46 | image: 'mannheimworld/spacex:latest', 47 | network_mode: 'host', 48 | volumes: [ 49 | '/opt/mannheimworld/data/chain:/opt/mannheimworld/data/chain' 50 | ], 51 | command: args, 52 | logging: { 53 | driver: "json-file", 54 | options: { 55 | "max-size": "500m" 56 | } 57 | }, 58 | } 59 | } 60 | 61 | function getSharedChainConfig(config) { 62 | return { 63 | ...config.identity, 64 | base_url: `http://127.0.0.1:56666/api/v1`, 65 | address: config.identity.backup.address, 66 | account_id: config.identity.account_id, 67 | backup: JSON.stringify(config.identity.backup), 68 | } 69 | } 70 | 71 | module.exports = { 72 | genChainConfig, 73 | genChainComposeConfig, 74 | getSharedChainConfig, 75 | } 76 | -------------------------------------------------------------------------------- /scripts/install_sgx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source /opt/mannheimworld/spacex-script/scripts/utils.sh 4 | 5 | #!/bin/bash 6 | 7 | source /opt/mannheimworld/spacex-script/scripts/utils.sh 8 | 9 | is_16=`cat /etc/issue | grep 16.04` 10 | is_18=`cat /etc/issue | grep 18.04` 11 | is_20=`cat /etc/issue | grep 20.04` 12 | if [ x"$is_16" != x"" ]; then 13 | driverbin=sgx_linux_x64_driver_2.6.0_b0a445b.bin 14 | driverurl=https://download.01.org/intel-sgx/sgx-linux/2.11/distro/ubuntu16.04-server/$driverbin 15 | log_info "Current system is ubuntu 16.04" 16 | elif [ x"$is_18" != x"" ]; then 17 | driverbin=sgx_linux_x64_driver_2.6.0_b0a445b.bin 18 | driverurl=https://download.01.org/intel-sgx/sgx-linux/2.11/distro/ubuntu18.04-server/$driverbin 19 | log_info "Current system is ubuntu 18.04" 20 | elif [ x"$is_20" != x"" ]; then 21 | driverbin=sgx_linux_x64_driver_2.11.0_4505f07.bin 22 | driverurl=https://download.01.org/intel-sgx/sgx-linux/2.12/distro/ubuntu20.04-server/$driverbin 23 | log_info "Current system is ubuntu 20.04" 24 | else 25 | log_err "Spacex storage can't support this system!" 26 | exit 1 27 | fi 28 | 29 | log_info "Download sgx driver" 30 | if [ -f "$driverbin" ]; then 31 | rm $driverbin 32 | fi 33 | wget $driverurl 34 | 35 | if [ $? -ne 0 ]; then 36 | log_err "Download sgx dirver failed" 37 | exit 1 38 | fi 39 | 40 | log_info "Installing denpendencies..." 41 | apt-get install -y wget build-essential kmod linux-headers-`uname -r` 42 | if [ $? -ne 0 ]; then 43 | log_err "Install sgx driver dependencies failed" 44 | exit 1 45 | fi 46 | 47 | log_info "Give sgx driver executable permission" 48 | chmod +x $driverbin 49 | 50 | log_info "Installing sgx driver..." 51 | ./$driverbin 52 | 53 | if [ $? -ne 0 ]; then 54 | log_err "Install sgx dirver bin failed" 55 | exit 1 56 | fi 57 | 58 | log_info "Clear resource" 59 | rm $driverbin 60 | 61 | exit 0 62 | -------------------------------------------------------------------------------- /generator/index.js: -------------------------------------------------------------------------------- 1 | 2 | const _ = require('lodash') 3 | const fs = require('fs-extra') 4 | const path = require('path') 5 | const yaml = require('js-yaml') 6 | const { genConfig, genComposeConfig } = require('./config-gen') 7 | const { getConfigSchema } = require('./schema') 8 | const { validate } = require('./config-validator') 9 | const { logger } = require('./logger') 10 | const { inspectKey } = require('./key-utils') 11 | const { writeYaml } = require('./utils') 12 | 13 | console.log('Spacex config generator') 14 | 15 | async function loadConfig(file) { 16 | logger.debug('Loading config file: %s', file) 17 | const c = await fs.readFile('config.yaml', 'utf8') 18 | const config = yaml.safeLoad(c) 19 | const configSchema = getConfigSchema(config) 20 | const value = await configSchema.validateAsync(config, { 21 | allowUnknown: true, 22 | stripUnknown: true, 23 | }) 24 | 25 | if (value.node.storage == "enable") { 26 | const keyInfo = await inspectKey(value.identity.backup.address) 27 | value.identity.account_id = keyInfo.accountId 28 | } 29 | 30 | const data = await genConfig(value, { 31 | baseDir: '.tmp', 32 | }) 33 | const composeConfig = await genComposeConfig(value) 34 | await writeYaml(path.join('.tmp','docker-compose.yaml'), composeConfig) 35 | await dumpConfigPaths(path.join('.tmp', '.paths'), data) 36 | } 37 | 38 | async function dumpConfigPaths(toFile, data) { 39 | const paths = _(data).map(d => _.get(d, 'paths', [])).flatten().map(p => { 40 | let mark = '|' 41 | if (p.required) { 42 | mark = '+' 43 | } 44 | return `${mark} ${p.path}` 45 | }).uniq() 46 | 47 | await fs.outputFile(toFile, paths.join('\n')) 48 | } 49 | 50 | function getConfigFileName() { 51 | const args = process.argv.slice(2); 52 | if (args.length >= 1) { 53 | return args[0] 54 | } 55 | return 'config.yaml' 56 | } 57 | 58 | async function main(){ 59 | try { 60 | await loadConfig(getConfigFileName()) 61 | } catch(e) { 62 | logger.error('failed to load config: %o', e.message) 63 | process.exit(1) 64 | } 65 | } 66 | 67 | main() 68 | -------------------------------------------------------------------------------- /scripts/version.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source /opt/mannheimworld/spacex-script/scripts/utils.sh 4 | 5 | version() 6 | { 7 | printf "Node version: ${node_version}\n" 8 | printf "Node network: ${node_type}\n" 9 | local mode=`cat $basedir/etc/mode.conf` 10 | printf "Node mode: ${mode}\n" 11 | inner_storage_version 12 | inner_docker_version 13 | } 14 | 15 | inner_storage_version() 16 | { 17 | local storage_config_file=$builddir/storage/storage_config.json 18 | if [ ! -f "$storage_config_file" ]; then 19 | return 20 | fi 21 | 22 | storage_base_url=`cat $storage_config_file | jq .base_url` 23 | 24 | if [ x"$storage_base_url" = x"" ]; then 25 | return 26 | fi 27 | 28 | storage_base_url=`echo "$storage_base_url" | sed -e 's/^"//' -e 's/"$//'` 29 | 30 | local id_info=`curl --max-time 30 $storage_base_url/enclave/id_info 2>/dev/null` 31 | if [ x"$id_info" = x"" ]; then 32 | return 33 | fi 34 | printf "Storage version:\n${id_info}\n" 35 | } 36 | 37 | inner_docker_version() 38 | { 39 | local chain_image=(`docker images | grep '^\b'mannheimworld/spacex'\b ' | grep 'latest'`) 40 | chain_image=${chain_image[2]} 41 | 42 | local storage_image=(`docker images | grep '^\b'mannheimworld/spacex-storage'\b ' | grep 'latest'`) 43 | storage_image=${storage_image[2]} 44 | 45 | local cgen_image=(`docker images | grep '^\b'mannheimworld/config-generator'\b ' | grep 'latest'`) 46 | cgen_image=${cgen_image[2]} 47 | 48 | local ipfs_image=(`docker images | grep '^\b'mannheimworld/go-ipfs'\b ' | grep 'latest'`) 49 | ipfs_image=${ipfs_image[2]} 50 | 51 | local api_image=(`docker images | grep '^\b'mannheimworld/spacex-api'\b ' | grep 'latest'`) 52 | api_image=${api_image[2]} 53 | 54 | local sdatamanager_image=(`docker images | grep '^\b'mannheimworld/spacex-sdatamanager'\b ' | grep 'latest'`) 55 | sdatamanager_image=${sdatamanager_image[2]} 56 | 57 | printf "Docker images:\n" 58 | printf " Chain: ${chain_image}\n" 59 | printf " Storage: ${storage_image}\n" 60 | printf " C-gen: ${cgen_image}\n" 61 | printf " IPFS: ${ipfs_image}\n" 62 | printf " API: ${api_image}\n" 63 | printf " Sdatamanager: ${sdatamanager_image}\n" 64 | } 65 | -------------------------------------------------------------------------------- /docs/build-node.md: -------------------------------------------------------------------------------- 1 | 2 | ## 1 Configure external source chain 3 | 4 | The use of an external chain can make the miner node more lightweight, and it can also make multiple miners connect to the same watch chain node, thereby avoiding repeated chain synchronization to a certain extent. However, due to the single point of failure in this method, that is to say, the failure of the external source chain node will cause multiple miners to fail to report the workload, so please try to use a better network device or cloud server to start the external source chain. At the same time, do not connect too many miners to the same chain. It is recommended to have less than 10 miners, otherwise the workload may not be reported due to congested transactions. 5 | 6 | ### 1.1 Configure watch chain service 7 | 8 | 1. Machine selection 9 | 10 | The requirements of the Watch machine are as follows: 11 | - The machine running the watch does not require SGX 12 | - 500GB solid state drive 13 | - It is recommended to use a stable network with public IP and fixed ports, which will directly affect the workload report of miner nodes 14 | - Install node 15 | - Recommend cloud server 16 | 17 | 2. Generate docker compose file 18 | 19 | ```shell 20 | sudo spacex tools watch-chain 21 | ``` 22 | 23 | Generate a "watch-chain.yaml" configuration file in the current directory 24 | 25 | 3. Start watch chain 26 | 27 | Start: 28 | ```shell 29 | sudo docker-compose -f watch-chain.yaml up -d 30 | ``` 31 | 32 | Monitor: 33 | ```shell 34 | sudo docker logs spacex-watch 35 | ``` 36 | 37 | 4. Matters needing attention 38 | 39 | - You can edit the "watch-chain.yaml" file to customize the watcher node 40 | - The watcher node can provide ws and rpc services, the default port is 30888, 19933, 19944, pay attention to open ports 41 | 42 | ### 1.2 Miner node use external source chain 43 | 44 | Set up to connect to other chains,default is "ws://127.0.0.1:19944" 45 | 46 | - Command 47 | ```shell 48 | sudo spacex config conn-chain {ws} 49 | ``` 50 | - Instance 51 | 52 | Set up a chain connected to "ws://7.7.7.7:19944" 53 | 54 | ```shell 55 | sudo spacex config conn-chain ws://7.7.7.7:19944 56 | ``` 57 | 58 | **If it is a node that is already running, the node needs to be restarted for the configuration of the external source chain to take effect** -------------------------------------------------------------------------------- /scripts/sgx_detect.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source /opt/mannheimworld/spacex-script/scripts/utils.sh 4 | 5 | install_sgx_driver() 6 | { 7 | is_16=`cat /etc/issue | grep 16.04` 8 | is_18=`cat /etc/issue | grep 18.04` 9 | is_20=`cat /etc/issue | grep 20.04` 10 | if [ x"$is_16" != x"" ]; then 11 | driverbin=sgx_linux_x64_driver_2.6.0_b0a445b.bin 12 | driverurl=https://download.01.org/intel-sgx/sgx-linux/2.11/distro/ubuntu16.04-server/$driverbin 13 | log_info "Current system is ubuntu 16.04" 14 | elif [ x"$is_18" != x"" ]; then 15 | driverbin=sgx_linux_x64_driver_2.6.0_b0a445b.bin 16 | driverurl=https://download.01.org/intel-sgx/sgx-linux/2.11/distro/ubuntu18.04-server/$driverbin 17 | log_info "Current system is ubuntu 18.04" 18 | elif [ x"$is_20" != x"" ]; then 19 | driverbin=sgx_linux_x64_driver_2.11.0_4505f07.bin 20 | driverurl=https://download.01.org/intel-sgx/sgx-linux/2.12/distro/ubuntu20.04-server/$driverbin 21 | log_info "Current system is ubuntu 20.04" 22 | else 23 | log_err "Spacex storage can't support this system!" 24 | exit 1 25 | fi 26 | 27 | log_info "Download sgx driver" 28 | if [ -f "$driverbin" ]; then 29 | rm $driverbin 30 | fi 31 | wget $driverurl 32 | 33 | if [ $? -ne 0 ]; then 34 | log_err "Download sgx dirver failed" 35 | exit 1 36 | fi 37 | 38 | log_info "Installing denpendencies..." 39 | apt-get install -y wget build-essential kmod linux-headers-`uname -r` 40 | if [ $? -ne 0 ]; then 41 | log_err "Install sgx driver dependencies failed" 42 | exit 1 43 | fi 44 | 45 | log_info "Give sgx driver executable permission" 46 | chmod +x $driverbin 47 | 48 | log_info "Installing sgx driver..." 49 | ./$driverbin 50 | if [ $? -ne 0 ]; then 51 | log_err "Install sgx dirver bin failed" 52 | exit 1 53 | fi 54 | 55 | log_info "Clear sgx dirver resource" 56 | rm $driverbin 57 | } 58 | 59 | 60 | 61 | function echo_c() 62 | { 63 | printf "\033[0;$1m$2\033[0m\n" 64 | } 65 | 66 | function log_info() 67 | { 68 | echo_c 33 "$1" 69 | } 70 | 71 | function log_success() 72 | { 73 | echo_c 32 "$1" 74 | } 75 | 76 | function log_err() 77 | { 78 | echo_c 35 "$1" 79 | } 80 | 81 | install_sgx_driver 82 | 83 | 84 | exit $? 85 | -------------------------------------------------------------------------------- /generator/.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # Snowpack dependency directory (https://snowpack.dev/) 45 | web_modules/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Microbundle cache 57 | .rpt2_cache/ 58 | .rts2_cache_cjs/ 59 | .rts2_cache_es/ 60 | .rts2_cache_umd/ 61 | 62 | # Optional REPL history 63 | .node_repl_history 64 | 65 | # Output of 'npm pack' 66 | *.tgz 67 | 68 | # Yarn Integrity file 69 | .yarn-integrity 70 | 71 | # dotenv environment variables file 72 | .env 73 | .env.test 74 | 75 | # parcel-bundler cache (https://parceljs.org/) 76 | .cache 77 | .parcel-cache 78 | 79 | # Next.js build output 80 | .next 81 | out 82 | 83 | # Nuxt.js build / generate output 84 | .nuxt 85 | dist 86 | 87 | # Gatsby files 88 | .cache/ 89 | # Comment in the public line in if your project uses Gatsby and not Next.js 90 | # https://nextjs.org/blog/next-9-1#public-directory-support 91 | # public 92 | 93 | # vuepress build output 94 | .vuepress/dist 95 | 96 | # Serverless directories 97 | .serverless/ 98 | 99 | # FuseBox cache 100 | .fusebox/ 101 | 102 | # DynamoDB Local files 103 | .dynamodb/ 104 | 105 | # TernJS port file 106 | .tern-port 107 | 108 | # Stores VSCode versions used for testing VSCode extensions 109 | .vscode-test 110 | 111 | # yarn v2 112 | .yarn/cache 113 | .yarn/unplugged 114 | .yarn/build-state.yml 115 | .yarn/install-state.gz 116 | .pnp.* 117 | config.yaml 118 | package-lock.json 119 | -------------------------------------------------------------------------------- /scripts/utils.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | node_type="rubik" 4 | #node_type="1.1.0" 5 | 6 | node_version="v1.1.0" 7 | aliyun_address="" 8 | basedir=/opt/mannheimworld/spacex-script 9 | scriptdir=$basedir/scripts 10 | builddir=$basedir/build 11 | configfile=$basedir/config.yaml 12 | composeyaml=$builddir/docker-compose.yaml 13 | 14 | function echo_c() 15 | { 16 | printf "\033[0;$1m$2\033[0m\n" 17 | } 18 | 19 | function log_info() 20 | { 21 | echo_c 33 "$1" 22 | } 23 | 24 | function log_success() 25 | { 26 | echo_c 32 "$1" 27 | } 28 | 29 | function log_err() 30 | { 31 | echo_c 35 "[ERROR] $1" 32 | } 33 | 34 | function upgrade_docker_image() 35 | { 36 | local image_name=$1 37 | local image_tag=$node_type 38 | if [ x"$2" != x"" ]; then 39 | image_tag=$2 40 | fi 41 | 42 | local old_image=(`docker images | grep '^\b'mannheimworld/$image_name'\b ' | grep 'latest'`) 43 | old_image=${old_image[2]} 44 | 45 | local region=`cat $basedir/etc/region.conf` 46 | local docker_org="mannheimworld" 47 | 48 | 49 | local res=0 50 | docker pull $docker_org/$image_name:$image_tag 51 | res=$(($?|$res)) 52 | docker tag $docker_org/$image_name:$image_tag mannheimworld/$image_name 53 | 54 | if [ $res -ne 0 ]; then 55 | log_err "Download docker image $image_name:$image_tag failed" 56 | return 1 57 | fi 58 | 59 | local new_image=(`docker images | grep '^\b'mannheimworld/$image_name'\b ' | grep 'latest'`) 60 | new_image=${new_image[2]} 61 | if [ x"$old_image" = x"$new_image" ]; then 62 | log_info "The current docker image $image_name ($old_image) is already the latest" 63 | return 1 64 | fi 65 | 66 | log_info "The docker image of $image_name is changed from $old_image to $new_image" 67 | 68 | return 0 69 | } 70 | 71 | check_port() { 72 | local port=$1 73 | local grep_port=`netstat -tlpn | grep "\b$port\b"` 74 | if [ -n "$grep_port" ]; then 75 | log_err "please make sure port $port is not occupied" 76 | return 1 77 | fi 78 | } 79 | 80 | ## 0 for running, 2 for error, 1 for stop 81 | check_docker_status() 82 | { 83 | local exist=`docker inspect --format '{{.State.Running}}' $1 2>/dev/null` 84 | if [ x"${exist}" == x"true" ]; then 85 | return 0 86 | elif [ "${exist}" == "false" ]; then 87 | return 2 88 | else 89 | return 1 90 | fi 91 | } 92 | 93 | ## rnd=$(rand 1 50) 94 | rand() 95 | { 96 | min=$1 97 | max=$(($2-$min+1)) 98 | num=$(date +%s%N) 99 | echo $(($num%$max+$min)) 100 | } 101 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

2 | 3 | Mannheim 4 | 5 |

6 | 7 |

RUBIK

8 | 9 | The repo of spacex-script used to automate processes to configure and run Mannheim testnet **RUBIK**, the script is a list of commands that are executed by spacex program. 10 | 11 | # 🚀Getting Started 12 | Official Guardian/Miner Node service for running Mannheim protocol. 13 | 14 | ## 🧰Preparation work 15 | 16 | | Requirements | | 17 | | --------------------- | ------------------------------------------------------------ | 18 | | ⚙️Hardware | CPU must contain **SGX module**, and make sure the SGX function is turned on in the bios | 19 | | ⚙️Operating system | Ubuntu 16.04/18.04/20.04 | 20 | | ⚙️Other configurations | **Secure Boot** in BIOS needs to be turned off | 21 | 22 | 23 | 24 | ## 🛠️Install dependencies 25 | 26 | ### Install Rubik service 27 | ```shell 28 | sudo ./install.sh # Use 'sudo ./install.sh --registry cn' to accelerate installation in some areas 29 | ``` 30 | 31 | ### Modify config.yaml 32 | ```shell 33 | sudo spacex config set 34 | ``` 35 | 36 | ### Run service 37 | 38 | - Please make sure the following ports are not occupied before starting: 39 | - 30888 19933 19944 (for chain ) 40 | - 56666 (for rubik API) 41 | - 12222 (for rubik storage) 42 | - 5001 4001 37773 (for IPFS) 43 | 44 | ```shell 45 | sudo spacex help 46 | sudo spacex start 47 | sudo spacex status 48 | ``` 49 | 50 | ### Stop service 51 | 52 | ```shell 53 | sudo spacex stop 54 | ``` 55 | 56 | ### 🛡️How to become a guardian? 57 | 58 | The Guardian node is the initiator of and in charge of the Group, participating in block generation. Effective storage of the miner can be clustered on the Guardian to participate in the block generation competition. Meantime, the organizers of the Guardians are accountable for the Group's strategy of receiving meaningful files to improve the Group's overall competitiveness. Since the Guardian node itself does not store files, support for SGX is not necessary. 59 | 60 | For details, please refer to [this page](docs/guardian.md). 61 | 62 | ### 💎How to become a miner? 63 | 64 | The Miner node acts as the storage provider in Group. There can be multiple Miner nodes in a Group, and their effective storage can be clustered on Owner to participate in block generation competition. Since Miner nodes store files and perform trusted quantification, support for SGX is necessary. The Miner node is connected to its account through configuring backup files. 65 | 66 | For details, please refer to [this page](docs/miner.md). 67 | 68 | ## License 69 | 70 | [GPL v3](LICENSE) 71 | -------------------------------------------------------------------------------- /generator/config-gen/index.js: -------------------------------------------------------------------------------- 1 | /** 2 | * config generators 3 | */ 4 | const path = require('path') 5 | const { createDir, writeConfig, } = require('../utils') 6 | const { genApiConfig, genApiComposeConfig } = require('./api-config.gen') 7 | const { genSdatamanagerConfig, genSdatamanagerComposeConfig } = require('./sdatamanager-config.gen') 8 | const { genIpfsConfig, genIpfsComposeConfig } = require('./ipfs-config.gen') 9 | const { genChainConfig, genChainComposeConfig } = require('./chain-config.gen') 10 | const { genStorageConfig, genStorageComposeConfig } = require('./storage-config.gen') 11 | const { logger } = require('../logger') 12 | 13 | /** 14 | * configuration of generators to use 15 | * name: the generator name 16 | * 17 | * async configFun(config, outputOptions) => {file, paths} 18 | * file: the result filename 19 | * paths: an array of files/directories should be verified later 20 | * required: boolean whether this file is a mandontary requirement 21 | * path: the file path 22 | * 23 | * composeName: the compose service name of this generator 24 | * async composeFunc(config) => composeConfig 25 | * return the service definition for this generator 26 | */ 27 | const configGenerators = [{ 28 | name: 'chain', 29 | configFunc: genChainConfig, 30 | to: path.join('chain', 'chain_config.json'), 31 | composeName: 'spacex', 32 | composeFunc: genChainComposeConfig, 33 | }, { 34 | name: 'api', 35 | configFunc: genApiConfig, 36 | to: path.join('api', 'api_config.json'), 37 | composeName: 'spacex-api', 38 | composeFunc: genApiComposeConfig, 39 | }, { 40 | name: 'storage', 41 | configFunc: genStorageConfig, 42 | to: path.join('storage', 'storage_config.json'), 43 | composeName: 'spacex-storage-a', 44 | composeFunc: genStorageComposeConfig, 45 | }, { 46 | name: 'storage', 47 | configFunc: genStorageConfig, 48 | to: path.join('storage', 'storage_config.json'), 49 | composeName: 'spacex-storage-b', 50 | composeFunc: genStorageComposeConfig, 51 | }, { 52 | name: 'sdatamanager', 53 | configFunc: genSdatamanagerConfig, 54 | to: path.join('sdatamanager', 'sdatamanager_config.json'), 55 | composeName: 'spacex-sdatamanager', 56 | composeFunc: genSdatamanagerComposeConfig, 57 | }, { 58 | name: 'ipfs', 59 | configFunc: genIpfsConfig, 60 | to: path.join('ipfs', 'ipfs_config.json'), 61 | composeName: 'ipfs', 62 | composeFunc: genIpfsComposeConfig, 63 | }] 64 | 65 | async function genConfig(config, outputOpts) { 66 | // 67 | // application config generation 68 | let outputs = [] 69 | const { baseDir } = outputOpts 70 | for (const cg of configGenerators) { 71 | if (!config[cg.name]) { 72 | continue 73 | } 74 | const ret = await cg.configFunc(config, outputOpts) 75 | await writeConfig(path.join(baseDir, cg.to), ret.config) 76 | outputs.push({ 77 | generator: cg.name, 78 | ...ret, 79 | }) 80 | } 81 | 82 | logger.info('Generating configurations done') 83 | return outputs 84 | } 85 | 86 | async function genComposeConfig(config) { 87 | // 88 | // docker compose config generation 89 | let output = { 90 | version: '3.0', 91 | services: {}, 92 | } 93 | 94 | for (const cg of configGenerators) { 95 | if (!config[cg.name]) { 96 | continue 97 | } 98 | const cfg = await cg.composeFunc(config) 99 | cfg["container_name"] = cg.composeName 100 | output = { 101 | ...output, 102 | services: { 103 | ...output.services, 104 | [cg.composeName]: cfg, 105 | } 106 | } 107 | } 108 | 109 | logger.info('Generating docker compose file done') 110 | 111 | return output 112 | } 113 | 114 | module.exports = { 115 | genConfig, 116 | genComposeConfig, 117 | } 118 | -------------------------------------------------------------------------------- /tools/test-sgx.c: -------------------------------------------------------------------------------- 1 | #include 2 | #if defined(_MSC_VER) 3 | #include 4 | #endif 5 | 6 | static inline void native_cpuid(unsigned int *eax, unsigned int *ebx, 7 | unsigned int *ecx, unsigned int *edx) 8 | { 9 | /* ecx is often an input as well as an output. */ 10 | 11 | #if !defined(_MSC_VER) 12 | 13 | asm volatile("cpuid" 14 | : "=a"(*eax), 15 | "=b"(*ebx), 16 | "=c"(*ecx), 17 | "=d"(*edx) 18 | : "0"(*eax), "2"(*ecx)); 19 | 20 | #else 21 | int registers[4] = {0, 0, 0, 0}; 22 | 23 | __cpuidex(registers, *eax, *ecx); 24 | *eax = registers[0]; 25 | *ebx = registers[1]; 26 | *ecx = registers[2]; 27 | *edx = registers[3]; 28 | 29 | #endif 30 | } 31 | 32 | int main(int argc, char **argv) 33 | { 34 | /* This programm prints some CPUID information and tests the SGX support of the CPU */ 35 | unsigned eax, ebx, ecx, edx; 36 | int is_sgx_available = 0; 37 | int is_sgx_enable = 0; 38 | eax = 1; /* processor info and feature bits */ 39 | 40 | native_cpuid(&eax, &ebx, &ecx, &edx); 41 | printf("eax: %x ebx: %x ecx: %x edx: %x\n", eax, ebx, ecx, edx); 42 | 43 | printf("stepping %d\n", eax & 0xF); // Bit 3-0 44 | printf("model %d\n", (eax >> 4) & 0xF); // Bit 7-4 45 | printf("family %d\n", (eax >> 8) & 0xF); // Bit 11-8 46 | printf("processor type %d\n", (eax >> 12) & 0x3); // Bit 13-12 47 | printf("extended model %d\n", (eax >> 16) & 0xF); // Bit 19-16 48 | printf("extended family %d\n", (eax >> 20) & 0xFF); // Bit 27-20 49 | 50 | // if smx set - SGX global enable is supported 51 | printf("smx: %d\n", (ecx >> 6) & 1); // CPUID.1:ECX.[bit6] 52 | 53 | /* Extended feature bits (EAX=07H, ECX=0H)*/ 54 | printf("\nExtended feature bits (EAX=07H, ECX=0H)\n"); 55 | eax = 7; 56 | ecx = 0; 57 | native_cpuid(&eax, &ebx, &ecx, &edx); 58 | printf("eax: %x ebx: %x ecx: %x edx: %x\n", eax, ebx, ecx, edx); 59 | 60 | //CPUID.(EAX=07H, ECX=0H):EBX.SGX = 1, 61 | is_sgx_available = (ebx >> 2) & 0x1; 62 | printf("sgx available: %d\n", is_sgx_available); 63 | 64 | //CPUID.(EAX=07H, ECX=0H):ECX.SGX_LC = 1 65 | printf("sgx launch control: %d\n", (ecx >> 30) & 0x01); 66 | 67 | /* SGX has to be enabled in MSR.IA32_Feature_Control.SGX_Enable 68 | check with msr-tools: rdmsr -ax 0x3a 69 | SGX_Enable is Bit 18 70 | if SGX_Enable = 0 no leaf information will appear. 71 | for more information check Intel Docs Architectures-software-developer-system-programming-manual - 35.1 Architectural MSRS 72 | */ 73 | 74 | /* CPUID Leaf 12H, Sub-Leaf 0 Enumeration of Intel SGX Capabilities (EAX=12H,ECX=0) */ 75 | printf("\nCPUID Leaf 12H, Sub-Leaf 0 of Intel SGX Capabilities (EAX=12H,ECX=0)\n"); 76 | eax = 0x12; 77 | ecx = 0; 78 | native_cpuid(&eax, &ebx, &ecx, &edx); 79 | printf("eax: %x ebx: %x ecx: %x edx: %x\n", eax, ebx, ecx, edx); 80 | 81 | printf("sgx 1 supported: %d\n", eax & 0x1); 82 | printf("sgx 2 supported: %d\n", (eax >> 1) & 0x1); 83 | is_sgx_enable = (eax & 0x1) || ((eax >> 1) & 0x1); 84 | 85 | printf("MaxEnclaveSize_Not64: %x\n", edx & 0xFF); 86 | printf("MaxEnclaveSize_64: %x\n", (edx >> 8) & 0xFF); 87 | 88 | /* CPUID Leaf 12H, Sub-Leaf 1 Enumeration of Intel SGX Capabilities (EAX=12H,ECX=1) */ 89 | printf("\nCPUID Leaf 12H, Sub-Leaf 1 of Intel SGX Capabilities (EAX=12H,ECX=1)\n"); 90 | eax = 0x12; 91 | ecx = 1; 92 | native_cpuid(&eax, &ebx, &ecx, &edx); 93 | printf("eax: %x ebx: %x ecx: %x edx: %x\n", eax, ebx, ecx, edx); 94 | 95 | int i; 96 | for (i = 2; i < 10; i++) 97 | { 98 | /* CPUID Leaf 12H, Sub-Leaf i Enumeration of Intel SGX Capabilities (EAX=12H,ECX=i) */ 99 | printf("\nCPUID Leaf 12H, Sub-Leaf %d of Intel SGX Capabilities (EAX=12H,ECX=%d)\n", i, i); 100 | eax = 0x12; 101 | ecx = i; 102 | native_cpuid(&eax, &ebx, &ecx, &edx); 103 | printf("eax: %x ebx: %x ecx: %x edx: %x\n", eax, ebx, ecx, edx); 104 | } 105 | 106 | if (is_sgx_available != 1) 107 | { 108 | printf("\033[31m\nCPU SGX functions are deactivated or SGX is not supported!\033[0m\n"); 109 | return 1; 110 | } 111 | else if (is_sgx_enable != 1) 112 | { 113 | printf("\033[31m\nSGX is available for your CPU but not enabled in BIOS!\033[0m\n"); 114 | return 2; 115 | } 116 | 117 | printf("\033[32m\nSGX is available for your CPU and enabled in BIOS!\033[0m\n"); 118 | return 0; 119 | } 120 | -------------------------------------------------------------------------------- /install.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | localbasedir=$(cd `dirname $0`;pwd) 4 | localscriptdir=$localbasedir/scripts 5 | installdir=/opt/mannheimworld/spacex-script 6 | disksdir=/opt/mannheimworld/disks 7 | datadir=/opt/mannheimworld/data 8 | source $localscriptdir/utils.sh 9 | 10 | help() 11 | { 12 | cat << EOF 13 | Usage: 14 | help show help information 15 | --update update spacex script 16 | --registry {cn|en} use registry to accelerate docker pull 17 | EOF 18 | exit 0 19 | } 20 | 21 | install_depenencies() 22 | { 23 | if [ x"$update" == x"true" ]; then 24 | return 0 25 | fi 26 | 27 | log_info "------------Apt update--------------" 28 | apt-get update 29 | if [ $? -ne 0 ]; then 30 | log_err "Apt update failed" 31 | exit 1 32 | fi 33 | 34 | log_info "------------Install depenencies--------------" 35 | apt install -y git jq curl wget build-essential kmod linux-headers-`uname -r` vim 36 | 37 | if [ $? -ne 0 ]; then 38 | log_err "Install libs failed" 39 | exit 1 40 | fi 41 | 42 | docker -v 43 | if [ $? -ne 0 ]; then 44 | curl -fsSL https://get.docker.com | bash -s docker --mirror Aliyun 45 | if [ $? -ne 0 ]; then 46 | log_err "Install docker failed" 47 | exit 1 48 | fi 49 | fi 50 | 51 | docker-compose -v 52 | if [ $? -ne 0 ]; then 53 | apt install -y docker-compose 54 | if [ $? -ne 0 ]; then 55 | log_err "Install docker compose failed" 56 | exit 1 57 | fi 58 | fi 59 | 60 | sysctl -w net.core.rmem_max=2500000 61 | } 62 | 63 | download_docker_images() 64 | { 65 | if [ x"$update" == x"true" ]; then 66 | return 0 67 | fi 68 | 69 | log_info "-------Download spacex docker images----------" 70 | 71 | local docker_org="mannheimworld" 72 | 73 | 74 | local res=0 75 | docker pull $docker_org/config-generator:$node_type 76 | res=$(($?|$res)) 77 | docker tag $docker_org/config-generator:$node_type mannheimworld/config-generator 78 | 79 | docker pull $docker_org/spacex:$node_type 80 | res=$(($?|$res)) 81 | docker tag $docker_org/spacex:$node_type mannheimworld/spacex 82 | 83 | docker pull $docker_org/spacex-api:$node_type 84 | res=$(($?|$res)) 85 | docker tag $docker_org/spacex-api:$node_type mannheimworld/spacex-api 86 | 87 | docker pull $docker_org/spacex-storage:$node_type 88 | res=$(($?|$res)) 89 | docker tag $docker_org/spacex-storage:$node_type mannheimworld/spacex-storage 90 | 91 | docker pull $docker_org/spacex-sdatamanager:$node_type 92 | res=$(($?|$res)) 93 | docker tag $docker_org/spacex-sdatamanager:$node_type mannheimworld/spacex-sdatamanager 94 | 95 | docker pull $docker_org/go-ipfs:$node_type 96 | res=$(($?|$res)) 97 | docker tag $docker_org/go-ipfs:$node_type mannheimworld/go-ipfs 98 | 99 | if [ $res -ne 0 ]; then 100 | log_err "Install docker failed" 101 | exit 1 102 | fi 103 | } 104 | 105 | create_node_paths() 106 | { 107 | mkdir -p $installdir 108 | mkdir -p $disksdir 109 | chmod 777 $disksdir 110 | mkdir -p $datadir 111 | chmod 777 $datadir 112 | for((i=1;i<=128;i++)); 113 | do 114 | mkdir -p $disksdir/$i 115 | chmod 777 $disksdir/$i 116 | done 117 | } 118 | 119 | install_spacex_script() 120 | { 121 | log_info "--------------Install spacex script-------------" 122 | local bin_file=/usr/bin/spacex 123 | 124 | if [ -d "$installdir" ] && [ -f "$bin_file" ] && [ x"$update" == x"true" ]; then 125 | echo "Update spacex script" 126 | rm $bin_file 127 | rm -rf $installdir/scripts 128 | cp -rp $localbasedir/scripts $installdir/ 129 | rm $installdir/etc/watch-chain.yaml 130 | cp $localbasedir/etc/watch-chain.yaml $installdir/etc/watch-chain.yaml 131 | else 132 | if [ -f "$installdir/scripts/uninstall.sh" ]; then 133 | echo "Uninstall old spacex script" 134 | $installdir/scripts/uninstall.sh 135 | fi 136 | 137 | echo "Install new spacex script" 138 | create_node_paths 139 | cp -r $localbasedir/etc $installdir/ 140 | cp $localbasedir/config.yaml $installdir/ 141 | chown root:root $installdir/config.yaml 142 | chmod 0600 $installdir/config.yaml 143 | cp -r $localbasedir/scripts $installdir/ 144 | 145 | echo "Change spacex node configurations" 146 | sed -i 's/en/'$region'/g' $installdir/etc/region.conf 147 | fi 148 | 149 | echo "Install spacex command line tool" 150 | cp $localscriptdir/spacex.sh /usr/bin/spacex 151 | 152 | log_success "------------Install success-------------" 153 | } 154 | 155 | 156 | if [ $(id -u) -ne 0 ]; then 157 | log_err "Please run with sudo!" 158 | exit 1 159 | fi 160 | 161 | region="en" 162 | update="false" 163 | 164 | while true ; do 165 | case "$1" in 166 | --registry) 167 | if [ x"$2" == x"" ] || [[ x"$2" != x"cn" && x"$2" != x"en" ]]; then 168 | help 169 | fi 170 | region=$2 171 | shift 2 172 | ;; 173 | --update) 174 | update="true" 175 | shift 1 176 | ;; 177 | "") 178 | shift ; 179 | break ;; 180 | *) 181 | help 182 | break; 183 | ;; 184 | esac 185 | done 186 | 187 | install_depenencies 188 | download_docker_images 189 | install_spacex_script 190 | 191 | -------------------------------------------------------------------------------- /docs/guardian.md: -------------------------------------------------------------------------------- 1 | ## 1. Overview 2 | 3 | ### 1.1 Guardian Node Responsibility 4 | 5 | The Guardian node is the initiator of and in charge of the Group, participating in block generation. Effective storage of the miner can be clustered on the Guardian to participate in the block generation competition. Meantime, the organizers of the Guardian node are accountable for the Group's strategy of receiving meaningful files to improve the Group's overall competitiveness. Since the Guardian node itself does not store files, support for SGX is not necessary. The Guardian node account is connected to block node through the session key. 6 | 7 | ## 2. Ready to Deploy 8 | 9 | > Note: The account of Mannheim testnet RUBIK starting with the letter 'r'. 10 | 11 | ### 2.1 Create your Accounts 12 | 13 | The Guardian node participates in the block generation competition. It needs to create accounts and be bonded to the Controller&Stash account group. 14 | 15 | Notices: 16 | 17 | * The account should be unique and cannot be any other account for Guardian, Miner or Bridge; 18 | * Be sure to reserve a small number of HEIMs not locked in the Controller&Stash for sending transactions (≈ 1 HEIM). 19 | 20 | ### 2.2 Create and manager group 21 | 22 | #### 2.2.1 Create group 23 | 24 | > The account to create the Group must be a bound Stash account 25 | 26 | Enter RUBIK APPS, select 'Benefit', click on 'Create group',select the Guardian **Stash account**, click on 'Create', enter the password of the stash account and click on 'Sign and Submit' to send the transaction and create Group. 27 | 28 | #### 2.2.2 Lockup HEIM to reduce the fee of the work report 29 | 30 | **The work report on chain requires handling fees.** Under normal circumstances, each Miner will perform 24~32 workload reporting transactions per day, which brings a lot of handling fees. For this reason, the Mannheim network provides a Benefit module that exempts workload reporting fees. Group guardians can reduce or waive miner handling fees by locking HEIMs. **Each miner** needs to lock 18HEIM for fee reduction. However, considering the unstable reporting of workload, it is recommended to lock 24HEIM~30HEIM to ensure that the fee is completely free. For example, suppose your Group is ready to have 10 miners ready to join, then lock 30*10=300HEIM 31 | 32 | Enter [Spacex APPS](http://rubik.mannheim.world/#/explorer), select 'Account', select the 'Benefit' module, find the group created before, and click 'Increase lockup'. 33 | 34 | Enter the number of HEIMs that **need to be added**, and sign the transaction. 35 | 36 | ### 2.3 Download Node Package 37 | 38 | 1. Download 39 | 40 | ```plain 41 | wget https://github.com/mannheim-network/spacex-script/archive/refs/heads/testnet.zip 42 | ``` 43 | 2. Unzip 44 | 45 | ```plain 46 | tar -xvf testnet.zip 47 | ``` 48 | 3. Go to package directory 49 | 50 | ```plain 51 | cd spacex-script-testnet 52 | ``` 53 | 54 | ### 2.4 Install Spacex Service 55 | 56 | Notice: 57 | 58 | * The program will be installed under `/opt/mannheimworld`, please make sure this path is mounted with more than 250G of SSD space; 59 | 60 | * If you have run a previous Mannheim testnet program on this device, you need to close the previous Node and clear the data before this installation. 61 | 62 | * The installation process will involve the download of dependencies and docker images, which is time-consuming. Meantime, it may fail due to network problems. If it happens, please repeat the process until the installation is all complete. 63 | 64 | Installation: 65 | 66 | ```plain 67 | sudo ./install.sh 68 | ``` 69 | ## 3. Node Configuration 70 | 71 | ### 3.1 Edit Config File 72 | 73 | Execute the following command to edit the node configuration file: 74 | 75 | ```plain 76 | sudo spacex config set 77 | ``` 78 | ### 3.2 Change Node Name 79 | 80 | Follow the prompts to enter the name of your node, and press Enter to end. 81 | 82 | ### 3.3 Choose Mode 83 | 84 | Follow the prompts to enter a node mode 'guardian', and press Enter to end. 85 | 86 | ### 3.4 Review the Configuration (Optional) 87 | 88 | Execute following command to view the configuration file: 89 | 90 | ```plain 91 | sudo spacex config show 92 | ``` 93 | ## 4. Start Node 94 | 95 | ### 4.1 Preparation 96 | 97 | To start with, you need to ensure that the following ports are not occupied: 30888, 19944, and 19933. 98 | 99 | Then open the P2P port: 100 | 101 | ```plain 102 | sudo ufw allow 30888 103 | ``` 104 | ### 4.2 Start 105 | 106 | ```plain 107 | sudo spacex start 108 | ``` 109 | ### 4.3 Check Running Status 110 | 111 | ```plain 112 | sudo spacex logs chain 113 | ``` 114 | As detailed below, all is ready for synchronizing blocks. 115 | 116 | ## 5. Blockchain Validate 117 | 118 | ### 5.1 Get session key 119 | 120 | Please wait for the chain to synchronize to the latest block height, and execute the following command: 121 | 122 | ```plain 123 | sudo spacex tools rotate-keys 124 | ``` 125 | Copy the session key as shown below: 126 | 127 | ### 5.2 Set session key 128 | 129 | Enter [SPACEX APPs](http://rubik.mannheim.world/#/explorer), click on "Staking" button under "Network" in the navigation bar, and go to "Account action". Click on "Session Key". 130 | Fill in the sessionkey you have copied, and click on “Set session key”. 131 | 132 | ### 5.3 Be a Guardian/Candidate 133 | 134 | > Becoming a Guardian needs to shoulder the responsibility of maintaining the network, a large-scale disconnection will result in a certain degree of punishment (up to 7% of the effective pledge amount) 135 | 136 | Under "Network->Staking->Account action" page, Please click on "guardian" button. 137 | 138 | After one era, you can find your account listed in the "Staking" or "Waiting" list, which means you have completed all the steps. 139 | 140 | ## 6. Restart and Uninstall 141 | 142 | ### 6.1 Restart 143 | 144 | If the device or Guardian node related programs need to be somehow restarted, please refer to the following steps. 145 | 146 | **Please note**: This section only concerns restarting steps of Guardian nodes, not including the basic software and hardware environment settings and inspection related information, such as hard disk mounting, IPFS configurations, etc. Please ensure that the hardware and software configuration is correct, and perform the following steps: 147 | 148 | ```plain 149 | sudo spacex reload 150 | ``` 151 | ### 6.2 Uninstall and Data Cleanup 152 | 153 | If you have run a previous version of testnet, or if you want to redeploy your current node, you need to clear data from three sources: 154 | 155 | * Delete basic Spacex files under /opt/mannheimworld/data 156 | * Clean node data under /opt/mannheimworld/spacex-script by executing: 157 | 158 | ```plain 159 | sudo /opt/mannheimworld/spacex-script/scripts/uninstall.sh 160 | ``` 161 | -------------------------------------------------------------------------------- /scripts/config.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source /opt/mannheimworld/spacex-script/scripts/utils.sh 4 | 5 | config_help() 6 | { 7 | cat << EOF 8 | Spacex config usage: 9 | help show help information 10 | show show configurations 11 | set set and generate new configurations 12 | generate generate new configurations 13 | chain-port {port} set chain port and generate new configuration, default is 30888 14 | conn-chain {ws} set conneted chain ws and generate new configuration, default is ws://127.0.0.1:19944 15 | EOF 16 | } 17 | 18 | config_show() 19 | { 20 | cat $configfile | sed 's#isolation#bridge#g' | sed -e 's#owner#guardian#g' | sed -e 's#member#miner#g' 21 | } 22 | 23 | config_set_all() 24 | { 25 | local chain_name="" 26 | read -p "Enter spacex script name (default:spacex-script): " chain_name 27 | chain_name=`echo "$chain_name"` 28 | if [ x"$chain_name" == x"" ]; then 29 | chain_name="spacex-script" 30 | fi 31 | local tt=$(rand 100000 999999) 32 | chain_name="$chain_name-$tt" 33 | sed -i "22c \\ name: \"$chain_name\"" $configfile &>/dev/null 34 | log_success "Set spacex script name: '$chain_name' successfully" 35 | 36 | local mode="" 37 | while true 38 | do 39 | read -p "Enter spacex script mode from 'bridge/guardian/miner' (default:bridge): " mode 40 | mode=`echo "$mode"` 41 | if [ x"$mode" == x"" ]; then 42 | mode="bridge" 43 | break 44 | elif [ x"$mode" == x"bridge" ] || [ x"$mode" == x"guardian" ] || [ x"$mode" == x"miner" ]; then 45 | break 46 | else 47 | log_err "Input error, please input bridge/guardian/miner" 48 | fi 49 | done 50 | 51 | if [ x"$mode" == x"bridge" ]; then 52 | mode="isolation" 53 | fi 54 | 55 | if [ x"$mode" == x"guardian" ]; then 56 | mode="owner" 57 | fi 58 | 59 | if [ x"$mode" == x"miner" ]; then 60 | mode="member" 61 | fi 62 | 63 | 64 | if [ x"$mode" == x"owner" ]; then 65 | sed -i '4c \\ chain: "authority"' $configfile &>/dev/null 66 | sed -i '6c \\ storage: "disable"' $configfile &>/dev/null 67 | sed -i '8c \\ sdatamanager: "disable"' $configfile &>/dev/null 68 | sed -i '10c \\ ipfs: "disable"' $configfile &>/dev/null 69 | local old_mode=`cat $basedir/etc/mode.conf` 70 | sed -i 's/'$old_mode'/'$mode'/g' $basedir/etc/mode.conf 71 | log_success "Set spacex script mode: guardian successfully" 72 | log_success "Set configurations successfully" 73 | config_generate 74 | return 75 | elif [ x"$mode" == x"isolation" ]; then 76 | sed -i '4c \\ chain: "authority"' $configfile &>/dev/null 77 | sed -i '6c \\ storage: "enable"' $configfile &>/dev/null 78 | sed -i '8c \\ sdatamanager: "'$mode'"' $configfile &>/dev/null 79 | sed -i '10c \\ ipfs: "enable"' $configfile &>/dev/null 80 | log_success "Set spacex script mode: bridge successfully" 81 | else 82 | sed -i '4c \\ chain: "full"' $configfile &>/dev/null 83 | sed -i '6c \\ storage: "enable"' $configfile &>/dev/null 84 | sed -i '8c \\ sdatamanager: "'$mode'"' $configfile &>/dev/null 85 | sed -i '10c \\ ipfs: "enable"' $configfile &>/dev/null 86 | log_success "Set spacex script mode: miner successfully" 87 | fi 88 | 89 | local old_mode=`cat $basedir/etc/mode.conf` 90 | sed -i 's/'$old_mode'/'$mode'/g' $basedir/etc/mode.conf 91 | 92 | local identity_backup="" 93 | while true 94 | do 95 | if [ x"$mode" == x"member" ]; then 96 | read -p "Enter the backup of miner account: " identity_backup 97 | else 98 | read -p "Enter the backup of miner account: " identity_backup 99 | fi 100 | 101 | identity_backup=`echo "$identity_backup"` 102 | if [ x"$identity_backup" != x"" ]; then 103 | break 104 | else 105 | log_err "Input error, backup can't be empty" 106 | fi 107 | done 108 | sed -i "15c \\ backup: '$identity_backup'" $configfile &>/dev/null 109 | log_success "Set backup successfully" 110 | 111 | local identity_password="" 112 | while true 113 | do 114 | if [ x"$mode" == x"member" ]; then 115 | read -p "Enter the password of miner account: " identity_password 116 | else 117 | read -p "Enter the password of miner account: " identity_password 118 | fi 119 | 120 | identity_password=`echo "$identity_password"` 121 | if [ x"$identity_password" != x"" ]; then 122 | break 123 | else 124 | log_err "Input error, password can't be empty" 125 | fi 126 | done 127 | sed -i '17c \\ password: "'$identity_password'"' $configfile &>/dev/null 128 | 129 | log_success "Set password successfully" 130 | log_success "Set configurations successfully" 131 | 132 | # Generate configurations 133 | config_generate 134 | } 135 | 136 | config_conn_chain() 137 | { 138 | if [ x"$1" = x"" ]; then 139 | log_err "Please give conneted chain ws." 140 | config_help 141 | return 1 142 | fi 143 | 144 | sed -i '28c \\ ws: "'$1'"' $configfile &>/dev/null 145 | log_success "Set connected chain ws '$1' successfully" 146 | config_generate 147 | } 148 | 149 | config_chain_port() 150 | { 151 | if [ x"$1" = x"" ]; then 152 | log_err "Please give right chain port." 153 | config_help 154 | return 1 155 | fi 156 | sed -i "24c \\ port: '$1'" $configfile &>/dev/null 157 | log_success "Set chain port '$1' successfully" 158 | config_generate 159 | } 160 | 161 | config_generate() 162 | { 163 | log_info "Start generate configurations and docker compose file" 164 | local cg_image="mannheimworld/config-generator:latest" 165 | 166 | if [ ! -f "$configfile" ]; then 167 | log_err "config.yaml doesn't exists!" 168 | exit 1 169 | fi 170 | 171 | rm -rf $builddir 172 | mkdir -p $builddir 173 | 174 | cp -f $configfile $builddir/ 175 | local cidfile=`mktemp` 176 | rm $cidfile 177 | docker run --cidfile $cidfile -i --workdir /opt/output -v $builddir:/opt/output $cg_image node /opt/app/index.js 178 | local res="$?" 179 | local cid=`cat $cidfile` 180 | docker rm $cid 181 | 182 | if [ "$res" -ne "0" ]; then 183 | log_err "Failed to generate application configs, please check your config.yaml" 184 | exit 1 185 | fi 186 | 187 | <<'COMMENT' 188 | invalid_paths=0 189 | while IFS= read -r line || [ -n "$line" ]; do 190 | mark=${line:0:1} 191 | path=${line:2} 192 | if [ ! -e "$path" ]; then 193 | if [ "$mark" == "|" ]; then 194 | log_warn "$path doesn't exist!" 195 | elif [ "$mark" == "+" ]; then 196 | log_err "$path doesn't exist!" 197 | invalid_paths=1 198 | fi 199 | fi 200 | done <$builddir/.tmp/.paths 201 | 202 | if [ $invalid_paths -ne "0" ]; then 203 | log_err "some paths is not valid, please check your config!" 204 | exit 1 205 | fi 206 | 207 | COMMENT 208 | 209 | rm -f $builddir/config.yaml 210 | cp -r $builddir/.tmp/* $builddir/ 211 | rm -rf $builddir/.tmp 212 | chown -R root:root $builddir 213 | chmod -R 0600 $builddir 214 | chmod 0600 $configfile 215 | 216 | log_success "Configurations generated at: $builddir" 217 | } 218 | 219 | config() 220 | { 221 | case "$1" in 222 | show) 223 | config_show 224 | ;; 225 | set) 226 | config_set_all 227 | ;; 228 | conn-chain) 229 | shift 230 | config_conn_chain $@ 231 | ;; 232 | chain-port) 233 | shift 234 | config_chain_port $@ 235 | ;; 236 | generate) 237 | config_generate 238 | ;; 239 | *) 240 | config_help 241 | esac 242 | } 243 | -------------------------------------------------------------------------------- /docs/miner.md: -------------------------------------------------------------------------------- 1 | ## 1. Overview 2 | 3 | ### 1.1 Node Responsibility 4 | 5 | The Miner node acts as the storage provider in Group. There can be multiple Miner nodes in a Group, and their effective storage can be clustered on Owner to participate in block generation competition. Since Miner nodes store files and perform trusted quantification, support for SGX is necessary. The Miner node is connected to its account through configuring backup files. 6 | 7 | ### 1.2 Hardware Spec 8 | 9 | The Miner node runs chain modules (not participating in block generation), storage modules, IPFS, etc. It needs to be equipped with an SGX environment. Meantime, it stores user files, involving frequent network transmission, so the network bandwidth should also be in high standards. 10 | 11 | ## 2. Ready to Deploy 12 | 13 | > Note: The account of Mannheim testnet RUBIK starting with the letter 'r'. 14 | 15 | ### 2.1 Create your Accounts 16 | 17 | Create a Miner account (a single account). The Miner node account needs to meet the following three requirements: 18 | 19 | * Ensure Miner account has 1000 HEIMs as a deposit for starting node, 10% will destroy and 90% locked (60 days) when miner cancel the node; 20 | 21 | * Ensure Miner account has 0.1-1 HEIMs as a transaction fee (cannot be locked) for sending work reports. It is recommended you check the remaining status of reserves from time to time; 22 | * Cannot be the account of Owner; 23 | * The account should be unique, meaning that it cannot be those same as other Miner accounts, that is, one chain account only for one machine; 24 | 25 | ### 2.2 Setup BIOS 26 | 27 | The SGX (Software Guard Extensions) module of the machine is closed by default. In the BIOS settings of your machine, you can set SGX to 'enable', and turn off Secure Boot (some types of motherboard do not support this setting). If your SGX only supports software enabled, please refer to this link [https://github.com/intel/sgx-software-enable](https://github.com/intel/sgx-software-enable). 28 | 29 | ### 2.3 Download Spacex Node Package 30 | 31 | a. Download 32 | 33 | ```plain 34 | wget https://github.com/mannheim-network/spacex-script/archive/refs/heads/testnet.zip 35 | ``` 36 | b. Unzip 37 | ```plain 38 | tar -xvf testnet.zip 39 | ``` 40 | c. Go to package directory 41 | ```plain 42 | cd spacex-script-testnet 43 | ``` 44 | 45 | ### 2.4 Install Spacex Service 46 | 47 | Notices: 48 | 49 | * The program will be installed under '/opt/mannheimworld', please ensure that the **system disk has more than 2TB** of SSD space. **If you do not want to use the system disk, but use other SSD, please create the '/opt/mannheimworld' directory in advance, and hang the SSD in this directory, pay attention to the read and write permissions of the directory**; 50 | 51 | * If you have run a previous Spacex testnet program on this device, you need to close the previous Spacex Node and clear the data before this installation. For details, please refer to section 6.2; 52 | 53 | * The installation process will involve the download of dependencies and docker images, which is time-consuming. Meantime, it may fail due to network problems. If it happens, please repeat the process until the installation is all complete. 54 | 55 | Installation: 56 | 57 | ```plain 58 | sudo ./install.sh 59 | ``` 60 | ## 3. Node Configuration 61 | 62 | ### 3.1 Edit Config File 63 | 64 | Execute the following command to edit the node configuration file: 65 | 66 | ```plain 67 | sudo spacex config set 68 | ``` 69 | ### 3.2 Change Node Name 70 | 71 | Follow the prompts to enter the name of your node, and press Enter to end. 72 | 73 | ### 3.3 Choose Mode 74 | 75 | Follow the prompts to enter a node mode 'miner', and press Enter to end. 76 | 77 | ### 3.4 Config Account 78 | 79 | Enter the contents of the Miner's backup file into the terminal, you can follow this: copy the contents of the Miner's backup file generated when the account is created, copy it to the terminal, and enter. 80 | 81 | > Note 1: The account of Mannheim Network Rubik starting with the letter 'r'. For example, the value of "address" in the above picture is `r7H5Wbf...` which is a Mannheim testnet account. 82 | 83 | > Note 2: This backup file and its content is the credential of your account, it is very important, please do not disclose or lose it. 84 | 85 | Enter the password for the backup file as prompted and press Enter to end. 86 | 87 | ### 3.5 Config Hard Disks 88 | 89 | > Disk organization solution is not unitary. If there is a better solution, you can optimize it yourself. 90 | 91 | With Spacex as a decentralized storage network, the configuration of your hard disks becomes quite important. The node storage capacity will be reported to the Mannheim Network as reserved space, and this will determine the stake limit of this node. 92 | 93 | **Base hard disk mounting requirements:** 94 | 95 | * The order files and SRD (Sealed Random Data, the placeholder files) will be written in the /opt/mannheimworld/disks/1 ~ /opt/mannheimworld/disks/128 directory, depending on how you mount the hard disk. Each physical machine can be configured with up to 500TB of reserved space 96 | 97 | * Please pay attention to the read and write permissions of the directory after mounting 98 | 99 | **HDDs organization solution is not unitary. If there is a better solution, you can optimize it yourself** 100 | 101 | * Single HDD: mount it directly to /opt/mannheimworld/disks/1 102 | * Multiple HDDs (multi-directories): Mount the hard disks to the /opt/mannheimworld/disks/1 ~ /opt/mannheimworld/disks/128 directories respectively. For example, if there are three hard disks /dev/sdb, /dev/sdc and /dev/sdd, you can mount them to /opt/mannheimworld/disks/1, /opt/mannheimworld/disks/2, /opt/mannheimworld/disks/3 directories respectively. The efficiency of this method is relatively high, and the method is relatively simple, but the fault tolerance of the hard disk will be reduced 103 | * Multiple HDDs (single directory): For hard disks with poor stability, using RAID/LVM/mergerfs and other means to combine the hard disks and mount them to the /opt/mannheimworld/disks/1 directory is an option. This method can increase the fault tolerance of the hard disk, but it will also bring about a drop in efficiency 104 | * Multiple HDDs (mixed): Combine single directory and multiple directories to mount HDDs 105 | 106 | You can use following command to view the file directory: 107 | 108 | ```plain 109 | sudo spacex tools space-info 110 | ``` 111 | 112 | ### 3.6 External chain Configuration (Optional&recommend) 113 | 114 | Enable local storage services to use external chain nodes for information collection, workload reporting, etc. 115 | 116 | Advantage: 117 | - Miner nodes are more lightweight 118 | - One chain node serves multiple miners 119 | - The reporting workload is more stable 120 | - Avoid repeated synchronization of chain nodes 121 | 122 | Disadvantages: 123 | - The single point of failure 124 | - The number of Miner connections is limited (10 or less recommended) 125 | - Additional machine (cloud server recommended) 126 | 127 | Please refer to this [link](build-node.md) for configuration 128 | 129 | ## 4. Start Node 130 | 131 | ### 4.1 Preparation 132 | 133 | To start with, you need to ensure that the following ports are not occupied: 30888 19944 19933 (occupied by spacex chain), 56666 (occupied by spacex API), 12222 (occupied by spacex storage), and 5001 4001 37773 (occupied by IPFS). 134 | 135 | Then open the P2P port: 136 | 137 | ```plain 138 | sudo ufw allow 30888 139 | ``` 140 | ### 4.2 Start 141 | 142 | ```plain 143 | sudo spacex start 144 | ``` 145 | ### 4.3 Check Running Status 146 | 147 | ```plain 148 | sudo spacex status 149 | ``` 150 | 151 | If the following five services are running, it means that Spacex node started successfully.(The chain will not start when the external chain is configured) 152 | 153 | ### 4.4 Set Node Storage Capacity and Run SRD 154 | Please wait about 2 minutes and execute the following commands. 155 | 156 | 1 Assuming that the HDDs have 1000G of space, set it as follows, storage will reserve some space and automatically determine the size of the SRD: 157 | 158 | ```plain 159 | sudo spacex tools change-srd 1000 160 | ``` 161 | 162 | 2 These commands may fail to execute. This is because storage has not been fully started. Please wait a few minutes and try again. If it still does not work, please execute the subordinate monitoring commands to troubleshoot the error: 163 | 164 | ```plain 165 | sudo spacex logs storage 166 | ``` 167 | 168 | ### 4.5 Monitor 169 | 170 | Run following command to monitor your node, and press 'ctrl-c' to stop monitoring: 171 | 172 | ```plain 173 | sudo spacex logs storage 174 | ``` 175 | The monitoring log is as follows: 176 | 177 | * (1) Indicating that the block is being synchronized. The process takes a long time; 178 | * (2) Having successfully registered your on-chain identity; 179 | * (3) Storage capacity statistics calculation in progress, which takes place gradually; 180 | * (4) Indicating that the storage status has been reported successfully. The process takes a long time, about an hour. 181 | 182 | ## 5. Joining Group 183 | 184 | ### 5.1 Add allowlist 185 | 186 | Miner accounts need to be added to the whitelist of the group before they can be added to the group. Enter [Spacex APPS](http://rubik.mannheim.world/#/explorer), select 'Account', select the 'Benefit' module, find the group created before (or contact the group manager for operation), and click 'Add allowed accounts'. 187 | 188 | Select the Miner account that needs to be added to the group, click 'Submit' and send the transaction, and add the account to the whitelist of the Group. 189 | 190 | ### 5.2 Join group 191 | 192 | After the first work report,select 'Benefit', click on 'Join group',select the Miner account and the Stash account, click 'Join group', enter the password of the Miner account, and finally click 'Sign and Submit' to send the transaction. 193 | 194 | ### 5.3 Lockup HEIM to reduce the fee of the work report 195 | 196 | **The work report in mainnet requires handling fees.** Under normal circumstances, each Miner will perform 24 workload reporting transactions per day, which brings a lot of handling fees. For this reason, the Spacex network provides a Benefit module that exempts workload reporting fees. Group owners can reduce or waive miner handling fees by locking HEIMs. **Each Miner** needs to lock 18HEIM for fee reduction. However, considering the unstable reporting of workload, it is recommended to lock 24HEIM~30HEIM to ensure that the fee is completely free. 197 | 198 | Enter [Spacex APPS](http://rubik.mannheim.world/#/explorer), select 'Account', select the 'Benefit' module, find the group created before (or contact the group manager for operation), and click 'Increase lockup'. 199 | 200 | Enter the number of HEIMs that **need to be added**, and sign the transaction, as follows. 201 | 202 | ## 6. Restart and Uninstall 203 | 204 | ### 6.1 Restart 205 | 206 | If the device or Spacex node related programs need to be somehow restarted, please refer to the following steps. 207 | 208 | **Please note**: This section only concerns restarting steps of Spacex nodes, not including the basic software and hardware environment settings and inspection related information, such as hard disk mounting, IPFS configurations, etc. Please ensure that the hardware and software configuration is correct, and perform the following steps: 209 | 210 | ```plain 211 | sudo spacex reload 212 | ``` 213 | 214 | ### 6.2 Uninstall and Data Cleanup 215 | 216 | If you have run a previous version of Mannheim testnet, or if you want to redeploy your current node, you need to clear data from three sources: 217 | 218 | * Delete basic Spacex files under /opt/mannheimworld/data and /opt/mannheimworld/disks 219 | * Clean node data under /opt/mannheimworld/spacex-script by executing: 220 | 221 | ```plain 222 | sudo /opt/mannheimworld/spacex-script/scripts/uninstall.sh 223 | ``` -------------------------------------------------------------------------------- /scripts/tools.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source /opt/mannheimworld/spacex-script/scripts/utils.sh 4 | 5 | tools_help() 6 | { 7 | cat << EOF 8 | Spacex tools usage: 9 | help show help information 10 | space-info show information about data folders 11 | rotate-keys generate session key of chain node 12 | upgrade-image {chain|api|sdatamanager|ipfs|c-gen|sw} upgrade one docker image 13 | storage-ab-upgrade {code} storage AB upgrade 14 | workload show workload information 15 | file-info {all|valid|lost|pending|{cid}} {output-file} show file information 16 | delete-file {cid} delete one file 17 | change-srd {number} change storage's srd capacity(GB), for example: 'change-srd 100', 'change-srd -50' 18 | ipfs {...} ipfs command, for example 'ipfs pin ls', 'ipfs swarm peers' 19 | watch-chain generate watch chain node docker-compose file and show help 20 | set-storage-debug {true|false} set storage debug 21 | EOF 22 | } 23 | 24 | space_info() 25 | { 26 | local data_folder_info=(`df -h /opt/mannheimworld/data | sed -n '2p'`) 27 | cat << EOF 28 | >>>>>> Base data folder <<<<<< 29 | Path: /opt/mannheimworld/data 30 | File system: ${data_folder_info[0]} 31 | Total space: ${data_folder_info[1]} 32 | Used space: ${data_folder_info[2]} 33 | Avail space: ${data_folder_info[3]} 34 | EOF 35 | local has_disks=false 36 | for i in $(seq 1 128); do 37 | local disk_folder_info=(`df -h /opt/mannheimworld/disks/${i} | sed -n '2p'`) 38 | if [ x"${disk_folder_info[0]}" != x"${data_folder_info[0]}" ]; then 39 | printf "\n>>>>>> Storage folder ${i} <<<<<<\n" 40 | printf "Path: /opt/mannheimworld/disks/${i}\n" 41 | printf "File system: ${disk_folder_info[0]}\n" 42 | printf "Total space: ${disk_folder_info[1]}\n" 43 | printf "Used space: ${disk_folder_info[2]}\n" 44 | printf "Avail space: ${disk_folder_info[3]}\n" 45 | has_disks=true 46 | fi 47 | done 48 | 49 | if [ "$has_disks" == false ]; then 50 | log_err "Please mount the hard disk to storage folders, paths is from: /opt/mannheimworld/disks/1 ~ /opt/mannheimworld/disks/128" 51 | return 1 52 | fi 53 | 54 | cat << EOF 55 | 56 | PS: 57 | 1. Base data folder is used to store chain and db, 2TB SSD is recommended, you can mount SSD on /opt/mannheimworld/data 58 | 2. Please mount the hard disk to storage folders, paths is from: /opt/mannheimworld/disks/1 ~ /opt/mannheimworld/disks/128 59 | 3. SRD will not use all the space, it will reserve 50G of space 60 | EOF 61 | } 62 | 63 | rotate_keys() 64 | { 65 | check_docker_status spacex 66 | if [ $? -ne 0 ]; then 67 | log_info "Service chain is not started or exited now" 68 | return 0 69 | fi 70 | 71 | local res=`curl -H "Content-Type: application/json" -d '{"id":1, "jsonrpc":"2.0", "method": "author_rotateKeys", "params":[]}' http://localhost:19933 2>/dev/null` 72 | session_key=`echo $res | jq .result` 73 | if [ x"$session_key" = x"" ]; then 74 | log_err "Generate session key failed" 75 | return 1 76 | fi 77 | echo $session_key 78 | } 79 | 80 | change_srd() 81 | { 82 | if [ x"$1" == x"" ] || [[ ! $1 =~ ^[1-9][0-9]*$|^[-][1-9][0-9]*$|^0$ ]]; then 83 | log_err "The input of srd change must be integer number" 84 | tools_help 85 | return 1 86 | fi 87 | 88 | local a_or_b=`cat $basedir/etc/storage.ab` 89 | check_docker_status spacex-storage-$a_or_b 90 | if [ $? -ne 0 ]; then 91 | log_info "Service spacex storage is not started or exited now" 92 | return 0 93 | fi 94 | 95 | if [ ! -f "$builddir/storage/storage_config.json" ]; then 96 | log_err "No storage configuration file" 97 | return 1 98 | fi 99 | 100 | local base_url=`cat $builddir/storage/storage_config.json | jq .base_url` 101 | base_url=${base_url%?} 102 | base_url=${base_url:1} 103 | 104 | curl -XPOST ''$base_url'/srd/change' -H 'backup: '$backup'' --data-raw '{"change" : '$1'}' 105 | } 106 | 107 | workload() 108 | { 109 | local a_or_b=`cat $basedir/etc/storage.ab` 110 | check_docker_status spacex-storage-$a_or_b 111 | if [ $? -ne 0 ]; then 112 | log_info "Service spacex storage is not started or exited now" 113 | return 0 114 | fi 115 | 116 | local base_url=`cat $builddir/storage/storage_config.json | jq .base_url` 117 | base_url=${base_url%?} 118 | base_url=${base_url:1} 119 | 120 | curl $base_url/workload 121 | } 122 | 123 | file_info() 124 | { 125 | local a_or_b=`cat $basedir/etc/storage.ab` 126 | check_docker_status spacex-storage-$a_or_b 127 | if [ $? -ne 0 ]; then 128 | log_info "Service spacex storage is not started or exited now" 129 | return 0 130 | fi 131 | 132 | local base_url=`cat $builddir/storage/storage_config.json | jq .base_url` 133 | base_url=${base_url%?} 134 | base_url=${base_url:1} 135 | 136 | if [ x"$1" == x"" ]; then 137 | tools_help 138 | return 1 139 | fi 140 | 141 | local output="" 142 | 143 | if [ x"$2" != x"" ]; then 144 | output="--output $2" 145 | fi 146 | 147 | if [ ${#1} -eq 46 ];then 148 | curl -X GET ''$base_url'/file/info?cid='$1'' $output 149 | return $? 150 | fi 151 | 152 | if [ x"$1" != x"all" ] && [ x"$1" != x"valid" ] && [ x"$1" != x"lost" ] && [ x"$1" != x"pending" ]; then 153 | tools_help 154 | return 1 155 | fi 156 | 157 | curl -X GET ''$base_url'/file/info_by_type?type='$1'' $output 158 | return $? 159 | } 160 | 161 | delete_file() 162 | { 163 | local a_or_b=`cat $basedir/etc/storage.ab` 164 | check_docker_status spacex-storage-$a_or_b 165 | if [ $? -ne 0 ]; then 166 | log_info "Service spacex storage is not started or exited now" 167 | return 0 168 | fi 169 | 170 | local base_url=`cat $builddir/storage/storage_config.json | jq .base_url` 171 | base_url=${base_url%?} 172 | base_url=${base_url:1} 173 | curl --request POST ''$base_url'/storage/delete' --header 'Content-Type: application/json' --data-raw '{"cid":"'$1'"}' 174 | } 175 | 176 | set_stoarge_debug() 177 | { 178 | local a_or_b=`cat $basedir/etc/storage.ab` 179 | check_docker_status spacex-storage-$a_or_b 180 | if [ $? -ne 0 ]; then 181 | log_info "Service spacex storage is not started or exited now" 182 | return 0 183 | fi 184 | 185 | if [ x"$1" != x"true" ] && [ x"$1" != x"false" ]; then 186 | tools_help 187 | return 1 188 | fi 189 | 190 | local base_url=`cat $builddir/storage/storage_config.json | jq .base_url` 191 | base_url=${base_url%?} 192 | base_url=${base_url:1} 193 | curl --request POST ''$base_url'/debug' --header 'Content-Type: application/json' --data-raw '{"debug":'$1'}' 194 | } 195 | 196 | upgrade_image() 197 | { 198 | if [ x"$1" == x"chain" ]; then 199 | upgrade_docker_image spacex $2 200 | if [ $? -ne 0 ]; then 201 | return 1 202 | fi 203 | elif [ x"$1" == x"api" ]; then 204 | upgrade_docker_image spacex-api $2 205 | if [ $? -ne 0 ]; then 206 | return 1 207 | fi 208 | elif [ x"$1" == x"sdatamanager" ]; then 209 | upgrade_docker_image spacex-sdatamanager $2 210 | if [ $? -ne 0 ]; then 211 | return 1 212 | fi 213 | elif [ x"$1" == x"ipfs" ]; then 214 | upgrade_docker_image go-ipfs $2 215 | if [ $? -ne 0 ]; then 216 | return 1 217 | fi 218 | elif [ x"$1" == x"c-gen" ]; then 219 | upgrade_docker_image config-generator $2 220 | if [ $? -ne 0 ]; then 221 | return 1 222 | fi 223 | elif [ x"$1" == x"sw" ]; then 224 | upgrade_docker_image spacex-storage $2 225 | if [ $? -ne 0 ]; then 226 | return 1 227 | fi 228 | else 229 | tools_help 230 | fi 231 | } 232 | 233 | ipfs_cmd() 234 | { 235 | check_docker_status ipfs 236 | if [ $? -ne 0 ]; then 237 | log_info "Service ipfs is not started or exited now" 238 | return 0 239 | fi 240 | docker exec -i ipfs ipfs $@ 241 | } 242 | 243 | storage_ab_upgrade() 244 | { 245 | # Check input 246 | if [ x"$1" == x"" ]; then 247 | log_err "Please give storage code." 248 | return 1 249 | fi 250 | 251 | if [ ${#1} -ne 64 ];then 252 | log_err "Please give right storage code." 253 | return 1 254 | fi 255 | local code=$1 256 | 257 | # Check storage 258 | local a_or_b=`cat $basedir/etc/storage.ab` 259 | check_docker_status spacex-storage-$a_or_b 260 | if [ $? -ne 0 ]; then 261 | log_err "Service spacex storage is not started or exited now" 262 | return 1 263 | fi 264 | 265 | log_info "Start storage A/B upgragde...." 266 | 267 | # Get configurations 268 | local config_file=$builddir/storage/storage_config.json 269 | if [ x"$config_file" = x"" ]; then 270 | log_err "please give right config file" 271 | return 1 272 | fi 273 | 274 | api_base_url=`cat $config_file | jq .chain.base_url` 275 | storage_base_url=`cat $config_file | jq .base_url` 276 | 277 | if [ x"$api_base_url" = x"" ] || [ x"$storage_base_url" = x"" ]; then 278 | log_err "please give right config file" 279 | return 1 280 | fi 281 | 282 | api_base_url=`echo "$api_base_url" | sed -e 's/^"//' -e 's/"$//'` 283 | storage_base_url=`echo "$storage_base_url" | sed -e 's/^"//' -e 's/"$//'` 284 | 285 | log_info "Read configurations success." 286 | 287 | if [ x"$2" != x"--offline" ]; then 288 | # Check chain 289 | while : 290 | do 291 | system_health=`curl --max-time 30 $api_base_url/system/health 2>/dev/null` 292 | if [ x"$system_health" = x"" ]; then 293 | log_err "Service spacex chain or api is not started or exited now" 294 | return 1 295 | fi 296 | 297 | is_syncing=`echo $system_health | jq .isSyncing` 298 | if [ x"$is_syncing" = x"" ]; then 299 | log_err "Service spacex api dose not connet to spacex chain" 300 | return 1 301 | fi 302 | 303 | if [ x"$is_syncing" = x"true" ]; then 304 | printf "\n" 305 | for i in $(seq 1 60); do 306 | printf "spacex chain is syncing, please wait 60s, now is %s\r" "${i}s" 307 | sleep 1 308 | done 309 | continue 310 | fi 311 | break 312 | done 313 | fi 314 | 315 | # Get code from storage 316 | local id_info=`curl --max-time 30 $storage_base_url/enclave/id_info 2>/dev/null` 317 | if [ x"$id_info" = x"" ]; then 318 | log_err "Please check storage logs to find more information" 319 | return 1 320 | fi 321 | 322 | local mrenclave=`echo $id_info | jq .mrenclave` 323 | if [ x"$mrenclave" = x"" ] || [ ! ${#mrenclave} -eq 66 ]; then 324 | log_err "Please check storage logs to find more information" 325 | return 1 326 | fi 327 | mrenclave=`echo ${mrenclave: 1: 64}` 328 | log_info "storage self code: $mrenclave" 329 | 330 | if [ x"$mrenclave" == x"$code" ]; then 331 | log_success "storage is already latest" 332 | while : 333 | do 334 | check_docker_status spacex-storage-a 335 | local resa=$? 336 | check_docker_status spacex-storage-b 337 | local resb=$? 338 | if [ $resa -eq 0 ] && [ $resb -eq 0 ] ; then 339 | sleep 10 340 | continue 341 | fi 342 | break 343 | done 344 | 345 | check_docker_status spacex-storage-a 346 | if [ $? -eq 0 ]; then 347 | local aimage=(`docker ps -a | grep 'spacex-storage-a'`) 348 | aimage=${aimage[1]} 349 | if [ x"$aimage" != x"mannheimworld/spacex-storage:latest" ]; then 350 | docker tag $aimage mannheimworld/spacex-storage:latest 351 | fi 352 | fi 353 | 354 | check_docker_status spacex-storage-b 355 | if [ $? -eq 0 ]; then 356 | local bimage=(`docker ps -a | grep 'spacex-storage-b'`) 357 | bimage=${bimage[1]} 358 | if [ x"$bimage" != x"mannheimworld/spacex-storage:latest" ]; then 359 | docker tag $bimage mannheimworld/spacex-storage:latest 360 | fi 361 | fi 362 | return 0 363 | fi 364 | 365 | # Upgrade storage images 366 | local old_image=(`docker images | grep '^\b'mannheimworld/spacex-storage'\b ' | grep 'latest'`) 367 | old_image=${old_image[2]} 368 | 369 | local region=`cat $basedir/etc/region.conf` 370 | local docker_org="mannheimworld" 371 | if [ x"$region" == x"cn" ]; then 372 | docker_org=$aliyun_address/$docker_org 373 | fi 374 | 375 | local res=0 376 | docker pull $docker_org/spacex-storage:$code 377 | res=$(($?|$res)) 378 | docker tag $docker_org/spacex-storage:$code mannheimworld/spacex-storage:latest 379 | 380 | if [ $res -ne 0 ]; then 381 | log_err "Download storage docker image failed" 382 | return 1 383 | fi 384 | 385 | local new_image=(`docker images | grep '^\b'mannheimworld/spacex-storage'\b ' | grep 'latest'`) 386 | new_image=${new_image[2]} 387 | if [ x"$old_image" = x"$new_image" ]; then 388 | log_info "The current storage docker image is already the latest" 389 | return 1 390 | fi 391 | 392 | # Start A/B 393 | if [ x"$a_or_b" = x"a" ]; then 394 | a_or_b='b' 395 | else 396 | a_or_b='a' 397 | fi 398 | 399 | check_docker_status spacex-storage-a 400 | local resa=$? 401 | check_docker_status spacex-storage-b 402 | local resb=$? 403 | if [ $resa -eq 0 ] && [ $resb -eq 0 ] ; then 404 | log_info "storage A/B upgrade is already in progress" 405 | else 406 | docker stop spacex-storage-$a_or_b &>/dev/null 407 | docker rm spacex-storage-$a_or_b &>/dev/null 408 | 409 | shift 410 | EX_STORAGE_ARGS="--upgrade $@" docker-compose -f $composeyaml up -d spacex-storage-$a_or_b 411 | 412 | if [ $? -ne 0 ]; then 413 | log_err "Setup new storage failed" 414 | docker tag $old_image mannheimworld/spacex-storage:latest 415 | return 1 416 | fi 417 | fi 418 | 419 | # Change back to older image 420 | docker tag $old_image mannheimworld/spacex-storage:latest 421 | log_info "Please do not close this program and wait patiently, ." 422 | log_info "If you need more information, please use other terminal to execute 'sudo spacex logs storage-a' and 'sudo spacex logs storage-b'" 423 | 424 | # Check A/B status 425 | local acc=0 426 | while : 427 | do 428 | printf "storage is upgrading, please do not close this program. Wait %s\r" "${acc}s" 429 | ((acc++)) 430 | sleep 1 431 | 432 | # Get code from storage 433 | local id_info=`curl --max-time 30 $storage_base_url/enclave/id_info 2>/dev/null` 434 | if [ x"$id_info" != x"" ]; then 435 | local mrenclave=`echo $id_info | jq .mrenclave` 436 | if [ x"$mrenclave" != x"" ]; then 437 | mrenclave=`echo ${mrenclave: 1: 64}` 438 | if [ x"$mrenclave" == x"$code" ]; then 439 | break 440 | fi 441 | fi 442 | fi 443 | 444 | # Check upgrade storage status 445 | check_docker_status spacex-storage-$a_or_b 446 | if [ $? -ne 0 ]; then 447 | printf "\n" 448 | log_err "storage update failed, please use 'sudo spacex logs storage-a' and 'sudo spacex logs storage-b' to find more details" 449 | return 1 450 | fi 451 | done 452 | 453 | # Set new information 454 | docker tag $new_image mannheimworld/spacex-storage:latest 455 | 456 | if [ x"$a_or_b" = x"a" ]; then 457 | sed -i 's/b/a/g' $basedir/etc/storage.ab 458 | else 459 | sed -i 's/a/b/g' $basedir/etc/storage.ab 460 | fi 461 | 462 | printf "\n" 463 | log_success "storage update success, setup new storage 'spacex-storage-$a_or_b'" 464 | } 465 | 466 | watch_chain() 467 | { 468 | cp $basedir/etc/watch-chain.yaml watch-chain.yaml 469 | 470 | cat << EOF 471 | The 'watch-chain.yaml' file has been generated your current path, use docker-compose to start the watch chain node 472 | 473 | PS: 474 | 1. Watch chain node can provide ws and rpc services, please open 30888, 19933 and 19944 ports 475 | 2. You can edit 'watch-chain.yaml' to customize your watch chain 476 | 3. The simplest startup example: 'sudo docker-compose -f watch-chain.yaml up -d' 477 | 4. With external connect chain configuration, a topology structure where one chain node serves multiple members can be realized 478 | EOF 479 | } 480 | 481 | tools() 482 | { 483 | case "$1" in 484 | space-info) 485 | space_info 486 | ;; 487 | change-srd) 488 | change_srd $2 489 | ;; 490 | rotate-keys) 491 | rotate_keys 492 | ;; 493 | workload) 494 | workload 495 | ;; 496 | file-info) 497 | file_info $2 498 | ;; 499 | delete-file) 500 | delete_file $2 501 | ;; 502 | set-storage-debug) 503 | set_storage_debug $2 504 | ;; 505 | upgrade-image) 506 | upgrade_image $2 $3 507 | ;; 508 | storage-ab-upgrade) 509 | shift 510 | storage_ab_upgrade $@ 511 | ;; 512 | watch-chain) 513 | watch_chain 514 | ;; 515 | ipfs) 516 | shift 517 | ipfs_cmd $@ 518 | ;; 519 | *) 520 | tools_help 521 | esac 522 | } 523 | -------------------------------------------------------------------------------- /generator/pnpm-lock.yaml: -------------------------------------------------------------------------------- 1 | dependencies: 2 | bluebird: 3.7.2 3 | execa: 4.0.3 4 | fs-extra: 9.0.1 5 | joi: 17.1.1 6 | js-yaml: 3.14.0 7 | lodash: 4.17.19 8 | shelljs: 0.8.4 9 | winston: 3.3.3 10 | lockfileVersion: 5.1 11 | packages: 12 | /@dabh/diagnostics/2.0.2: 13 | dependencies: 14 | colorspace: 1.1.2 15 | enabled: 2.0.0 16 | kuler: 2.0.0 17 | dev: false 18 | resolution: 19 | integrity: sha512-+A1YivoVDNNVCdfozHSR8v/jyuuLTMXwjWuxPFlFlUapXoGc+Gj9mDlTDDfrwl7rXCl2tNZ0kE8sIBO6YOn96Q== 20 | /@hapi/address/4.1.0: 21 | dependencies: 22 | '@hapi/hoek': 9.0.4 23 | dev: false 24 | resolution: 25 | integrity: sha512-SkszZf13HVgGmChdHo/PxchnSaCJ6cetVqLzyciudzZRT0jcOouIF/Q93mgjw8cce+D+4F4C1Z/WrfFN+O3VHQ== 26 | /@hapi/formula/2.0.0: 27 | deprecated: This version has been deprecated and is no longer supported or maintained 28 | dev: false 29 | resolution: 30 | integrity: sha512-V87P8fv7PI0LH7LiVi8Lkf3x+KCO7pQozXRssAHNXXL9L1K+uyu4XypLXwxqVDKgyQai6qj3/KteNlrqDx4W5A== 31 | /@hapi/hoek/9.0.4: 32 | dev: false 33 | resolution: 34 | integrity: sha512-EwaJS7RjoXUZ2cXXKZZxZqieGtc7RbvQhUy8FwDoMQtxWVi14tFjeFCYPZAM1mBCpOpiBpyaZbb9NeHc7eGKgw== 35 | /@hapi/pinpoint/2.0.0: 36 | dev: false 37 | resolution: 38 | integrity: sha512-vzXR5MY7n4XeIvLpfl3HtE3coZYO4raKXW766R6DZw/6aLqR26iuZ109K7a0NtF2Db0jxqh7xz2AxkUwpUFybw== 39 | /@hapi/topo/5.0.0: 40 | dependencies: 41 | '@hapi/hoek': 9.0.4 42 | dev: false 43 | resolution: 44 | integrity: sha512-tFJlT47db0kMqVm3H4nQYgn6Pwg10GTZHb1pwmSiv1K4ks6drQOtfEF5ZnPjkvC+y4/bUPHK+bc87QvLcL+WMw== 45 | /argparse/1.0.10: 46 | dependencies: 47 | sprintf-js: 1.0.3 48 | dev: false 49 | resolution: 50 | integrity: sha512-o5Roy6tNG4SL/FOkCAN6RzjiakZS25RLYFrcMttJqbdd8BWrnA+fGz57iN5Pb06pvBGvl5gQ0B48dJlslXvoTg== 51 | /async/3.2.0: 52 | dev: false 53 | resolution: 54 | integrity: sha512-TR2mEZFVOj2pLStYxLht7TyfuRzaydfpxr3k9RpHIzMgw7A64dzsdqCxH1WJyQdoe8T10nDXd9wnEigmiuHIZw== 55 | /at-least-node/1.0.0: 56 | dev: false 57 | engines: 58 | node: '>= 4.0.0' 59 | resolution: 60 | integrity: sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg== 61 | /balanced-match/1.0.0: 62 | dev: false 63 | resolution: 64 | integrity: sha1-ibTRmasr7kneFk6gK4nORi1xt2c= 65 | /bluebird/3.7.2: 66 | dev: false 67 | resolution: 68 | integrity: sha512-XpNj6GDQzdfW+r2Wnn7xiSAd7TM3jzkxGXBGTtWKuSXv1xUV+azxAm8jdWZN06QTQk+2N2XB9jRDkvbmQmcRtg== 69 | /brace-expansion/1.1.11: 70 | dependencies: 71 | balanced-match: 1.0.0 72 | concat-map: 0.0.1 73 | dev: false 74 | resolution: 75 | integrity: sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA== 76 | /color-convert/1.9.3: 77 | dependencies: 78 | color-name: 1.1.3 79 | dev: false 80 | resolution: 81 | integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg== 82 | /color-name/1.1.3: 83 | dev: false 84 | resolution: 85 | integrity: sha1-p9BVi9icQveV3UIyj3QIMcpTvCU= 86 | /color-name/1.1.4: 87 | dev: false 88 | resolution: 89 | integrity: sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA== 90 | /color-string/1.5.3: 91 | dependencies: 92 | color-name: 1.1.4 93 | simple-swizzle: 0.2.2 94 | dev: false 95 | resolution: 96 | integrity: sha512-dC2C5qeWoYkxki5UAXapdjqO672AM4vZuPGRQfO8b5HKuKGBbKWpITyDYN7TOFKvRW7kOgAn3746clDBMDJyQw== 97 | /color/3.0.0: 98 | dependencies: 99 | color-convert: 1.9.3 100 | color-string: 1.5.3 101 | dev: false 102 | resolution: 103 | integrity: sha512-jCpd5+s0s0t7p3pHQKpnJ0TpQKKdleP71LWcA0aqiljpiuAkOSUFN/dyH8ZwF0hRmFlrIuRhufds1QyEP9EB+w== 104 | /colors/1.4.0: 105 | dev: false 106 | engines: 107 | node: '>=0.1.90' 108 | resolution: 109 | integrity: sha512-a+UqTh4kgZg/SlGvfbzDHpgRu7AAQOmmqRHJnxhRZICKFUT91brVhNNt58CMWU9PsBbv3PDCZUHbVxuDiH2mtA== 110 | /colorspace/1.1.2: 111 | dependencies: 112 | color: 3.0.0 113 | text-hex: 1.0.0 114 | dev: false 115 | resolution: 116 | integrity: sha512-vt+OoIP2d76xLhjwbBaucYlNSpPsrJWPlBTtwCpQKIu6/CSMutyzX93O/Do0qzpH3YoHEes8YEFXyZ797rEhzQ== 117 | /concat-map/0.0.1: 118 | dev: false 119 | resolution: 120 | integrity: sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= 121 | /core-util-is/1.0.2: 122 | dev: false 123 | resolution: 124 | integrity: sha1-tf1UIgqivFq1eqtxQMlAdUUDwac= 125 | /cross-spawn/7.0.3: 126 | dependencies: 127 | path-key: 3.1.1 128 | shebang-command: 2.0.0 129 | which: 2.0.2 130 | dev: false 131 | engines: 132 | node: '>= 8' 133 | resolution: 134 | integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w== 135 | /enabled/2.0.0: 136 | dev: false 137 | resolution: 138 | integrity: sha512-AKrN98kuwOzMIdAizXGI86UFBoo26CL21UM763y1h/GMSJ4/OHU9k2YlsmBpyScFo/wbLzWQJBMCW4+IO3/+OQ== 139 | /end-of-stream/1.4.4: 140 | dependencies: 141 | once: 1.4.0 142 | dev: false 143 | resolution: 144 | integrity: sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q== 145 | /esprima/4.0.1: 146 | dev: false 147 | engines: 148 | node: '>=4' 149 | hasBin: true 150 | resolution: 151 | integrity: sha512-eGuFFw7Upda+g4p+QHvnW0RyTX/SVeJBDM/gCtMARO0cLuT2HcEKnTPvhjV6aGeqrCB/sbNop0Kszm0jsaWU4A== 152 | /execa/4.0.3: 153 | dependencies: 154 | cross-spawn: 7.0.3 155 | get-stream: 5.1.0 156 | human-signals: 1.1.1 157 | is-stream: 2.0.0 158 | merge-stream: 2.0.0 159 | npm-run-path: 4.0.1 160 | onetime: 5.1.0 161 | signal-exit: 3.0.3 162 | strip-final-newline: 2.0.0 163 | dev: false 164 | engines: 165 | node: '>=10' 166 | resolution: 167 | integrity: sha512-WFDXGHckXPWZX19t1kCsXzOpqX9LWYNqn4C+HqZlk/V0imTkzJZqf87ZBhvpHaftERYknpk0fjSylnXVlVgI0A== 168 | /fast-safe-stringify/2.0.7: 169 | dev: false 170 | resolution: 171 | integrity: sha512-Utm6CdzT+6xsDk2m8S6uL8VHxNwI6Jub+e9NYTcAms28T84pTa25GJQV9j0CY0N1rM8hK4x6grpF2BQf+2qwVA== 172 | /fecha/4.2.0: 173 | dev: false 174 | resolution: 175 | integrity: sha512-aN3pcx/DSmtyoovUudctc8+6Hl4T+hI9GBBHLjA76jdZl7+b1sgh5g4k+u/GL3dTy1/pnYzKp69FpJ0OicE3Wg== 176 | /fn.name/1.1.0: 177 | dev: false 178 | resolution: 179 | integrity: sha512-GRnmB5gPyJpAhTQdSZTSp9uaPSvl09KoYcMQtsB9rQoOmzs9dH6ffeccH+Z+cv6P68Hu5bC6JjRh4Ah/mHSNRw== 180 | /fs-extra/9.0.1: 181 | dependencies: 182 | at-least-node: 1.0.0 183 | graceful-fs: 4.2.4 184 | jsonfile: 6.0.1 185 | universalify: 1.0.0 186 | dev: false 187 | engines: 188 | node: '>=10' 189 | resolution: 190 | integrity: sha512-h2iAoN838FqAFJY2/qVpzFXy+EBxfVE220PalAqQLDVsFOHLJrZvut5puAbCdNv6WJk+B8ihI+k0c7JK5erwqQ== 191 | /fs.realpath/1.0.0: 192 | dev: false 193 | resolution: 194 | integrity: sha1-FQStJSMVjKpA20onh8sBQRmU6k8= 195 | /get-stream/5.1.0: 196 | dependencies: 197 | pump: 3.0.0 198 | dev: false 199 | engines: 200 | node: '>=8' 201 | resolution: 202 | integrity: sha512-EXr1FOzrzTfGeL0gQdeFEvOMm2mzMOglyiOXSTpPC+iAjAKftbr3jpCMWynogwYnM+eSj9sHGc6wjIcDvYiygw== 203 | /glob/7.1.6: 204 | dependencies: 205 | fs.realpath: 1.0.0 206 | inflight: 1.0.6 207 | inherits: 2.0.4 208 | minimatch: 3.0.4 209 | once: 1.4.0 210 | path-is-absolute: 1.0.1 211 | dev: false 212 | resolution: 213 | integrity: sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA== 214 | /graceful-fs/4.2.4: 215 | dev: false 216 | resolution: 217 | integrity: sha512-WjKPNJF79dtJAVniUlGGWHYGz2jWxT6VhN/4m1NdkbZ2nOsEF+cI1Edgql5zCRhs/VsQYRvrXctxktVXZUkixw== 218 | /human-signals/1.1.1: 219 | dev: false 220 | engines: 221 | node: '>=8.12.0' 222 | resolution: 223 | integrity: sha512-SEQu7vl8KjNL2eoGBLF3+wAjpsNfA9XMlXAYj/3EdaNfAlxKthD1xjEQfGOUhllCGGJVNY34bRr6lPINhNjyZw== 224 | /inflight/1.0.6: 225 | dependencies: 226 | once: 1.4.0 227 | wrappy: 1.0.2 228 | dev: false 229 | resolution: 230 | integrity: sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk= 231 | /inherits/2.0.4: 232 | dev: false 233 | resolution: 234 | integrity: sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== 235 | /interpret/1.4.0: 236 | dev: false 237 | engines: 238 | node: '>= 0.10' 239 | resolution: 240 | integrity: sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA== 241 | /is-arrayish/0.3.2: 242 | dev: false 243 | resolution: 244 | integrity: sha512-eVRqCvVlZbuw3GrM63ovNSNAeA1K16kaR/LRY/92w0zxQ5/1YzwblUX652i4Xs9RwAGjW9d9y6X88t8OaAJfWQ== 245 | /is-stream/2.0.0: 246 | dev: false 247 | engines: 248 | node: '>=8' 249 | resolution: 250 | integrity: sha512-XCoy+WlUr7d1+Z8GgSuXmpuUFC9fOhRXglJMx+dwLKTkL44Cjd4W1Z5P+BQZpr+cR93aGP4S/s7Ftw6Nd/kiEw== 251 | /isarray/1.0.0: 252 | dev: false 253 | resolution: 254 | integrity: sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE= 255 | /isexe/2.0.0: 256 | dev: false 257 | resolution: 258 | integrity: sha1-6PvzdNxVb/iUehDcsFctYz8s+hA= 259 | /joi/17.1.1: 260 | dependencies: 261 | '@hapi/address': 4.1.0 262 | '@hapi/formula': 2.0.0 263 | '@hapi/hoek': 9.0.4 264 | '@hapi/pinpoint': 2.0.0 265 | '@hapi/topo': 5.0.0 266 | dev: false 267 | resolution: 268 | integrity: sha512-fww3Ae9cRyj6yHy90cpxvL2y39V5JCY2KaXV3KfALhoFfFcAuyQBPOq+2q6EZ2QNMn1FhkDy+eRkGVG7J+BvyA== 269 | /js-yaml/3.14.0: 270 | dependencies: 271 | argparse: 1.0.10 272 | esprima: 4.0.1 273 | dev: false 274 | hasBin: true 275 | resolution: 276 | integrity: sha512-/4IbIeHcD9VMHFqDR/gQ7EdZdLimOvW2DdcxFjdyyZ9NsbS+ccrXqVWDtab/lRl5AlUqmpBx8EhPaWR+OtY17A== 277 | /jsonfile/6.0.1: 278 | dependencies: 279 | universalify: 1.0.0 280 | dev: false 281 | optionalDependencies: 282 | graceful-fs: 4.2.4 283 | resolution: 284 | integrity: sha512-jR2b5v7d2vIOust+w3wtFKZIfpC2pnRmFAhAC/BuweZFQR8qZzxH1OyrQ10HmdVYiXWkYUqPVsz91cG7EL2FBg== 285 | /kuler/2.0.0: 286 | dev: false 287 | resolution: 288 | integrity: sha512-Xq9nH7KlWZmXAtodXDDRE7vs6DU1gTU8zYDHDiWLSip45Egwq3plLHzPn27NgvzL2r1LMPC1vdqh98sQxtqj4A== 289 | /lodash/4.17.19: 290 | dev: false 291 | resolution: 292 | integrity: sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ== 293 | /logform/2.2.0: 294 | dependencies: 295 | colors: 1.4.0 296 | fast-safe-stringify: 2.0.7 297 | fecha: 4.2.0 298 | ms: 2.1.2 299 | triple-beam: 1.3.0 300 | dev: false 301 | resolution: 302 | integrity: sha512-N0qPlqfypFx7UHNn4B3lzS/b0uLqt2hmuoa+PpuXNYgozdJYAyauF5Ky0BWVjrxDlMWiT3qN4zPq3vVAfZy7Yg== 303 | /merge-stream/2.0.0: 304 | dev: false 305 | resolution: 306 | integrity: sha512-abv/qOcuPfk3URPfDzmZU1LKmuw8kT+0nIHvKrKgFrwifol/doWcdA4ZqsWQ8ENrFKkd67Mfpo/LovbIUsbt3w== 307 | /mimic-fn/2.1.0: 308 | dev: false 309 | engines: 310 | node: '>=6' 311 | resolution: 312 | integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg== 313 | /minimatch/3.0.4: 314 | dependencies: 315 | brace-expansion: 1.1.11 316 | dev: false 317 | resolution: 318 | integrity: sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA== 319 | /ms/2.1.2: 320 | dev: false 321 | resolution: 322 | integrity: sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w== 323 | /npm-run-path/4.0.1: 324 | dependencies: 325 | path-key: 3.1.1 326 | dev: false 327 | engines: 328 | node: '>=8' 329 | resolution: 330 | integrity: sha512-S48WzZW777zhNIrn7gxOlISNAqi9ZC/uQFnRdbeIHhZhCA6UqpkOT8T1G7BvfdgP4Er8gF4sUbaS0i7QvIfCWw== 331 | /once/1.4.0: 332 | dependencies: 333 | wrappy: 1.0.2 334 | dev: false 335 | resolution: 336 | integrity: sha1-WDsap3WWHUsROsF9nFC6753Xa9E= 337 | /one-time/1.0.0: 338 | dependencies: 339 | fn.name: 1.1.0 340 | dev: false 341 | resolution: 342 | integrity: sha512-5DXOiRKwuSEcQ/l0kGCF6Q3jcADFv5tSmRaJck/OqkVFcOzutB134KRSfF0xDrL39MNnqxbHBbUUcjZIhTgb2g== 343 | /onetime/5.1.0: 344 | dependencies: 345 | mimic-fn: 2.1.0 346 | dev: false 347 | engines: 348 | node: '>=6' 349 | resolution: 350 | integrity: sha512-5NcSkPHhwTVFIQN+TUqXoS5+dlElHXdpAWu9I0HP20YOtIi+aZ0Ct82jdlILDxjLEAWwvm+qj1m6aEtsDVmm6Q== 351 | /path-is-absolute/1.0.1: 352 | dev: false 353 | engines: 354 | node: '>=0.10.0' 355 | resolution: 356 | integrity: sha1-F0uSaHNVNP+8es5r9TpanhtcX18= 357 | /path-key/3.1.1: 358 | dev: false 359 | engines: 360 | node: '>=8' 361 | resolution: 362 | integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q== 363 | /path-parse/1.0.6: 364 | dev: false 365 | resolution: 366 | integrity: sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw== 367 | /process-nextick-args/2.0.1: 368 | dev: false 369 | resolution: 370 | integrity: sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag== 371 | /pump/3.0.0: 372 | dependencies: 373 | end-of-stream: 1.4.4 374 | once: 1.4.0 375 | dev: false 376 | resolution: 377 | integrity: sha512-LwZy+p3SFs1Pytd/jYct4wpv49HiYCqd9Rlc5ZVdk0V+8Yzv6jR5Blk3TRmPL1ft69TxP0IMZGJ+WPFU2BFhww== 378 | /readable-stream/2.3.7: 379 | dependencies: 380 | core-util-is: 1.0.2 381 | inherits: 2.0.4 382 | isarray: 1.0.0 383 | process-nextick-args: 2.0.1 384 | safe-buffer: 5.1.2 385 | string_decoder: 1.1.1 386 | util-deprecate: 1.0.2 387 | dev: false 388 | resolution: 389 | integrity: sha512-Ebho8K4jIbHAxnuxi7o42OrZgF/ZTNcsZj6nRKyUmkhLFq8CHItp/fy6hQZuZmP/n3yZ9VBUbp4zz/mX8hmYPw== 390 | /readable-stream/3.6.0: 391 | dependencies: 392 | inherits: 2.0.4 393 | string_decoder: 1.3.0 394 | util-deprecate: 1.0.2 395 | dev: false 396 | engines: 397 | node: '>= 6' 398 | resolution: 399 | integrity: sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA== 400 | /rechoir/0.6.2: 401 | dependencies: 402 | resolve: 1.17.0 403 | dev: false 404 | engines: 405 | node: '>= 0.10' 406 | resolution: 407 | integrity: sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q= 408 | /resolve/1.17.0: 409 | dependencies: 410 | path-parse: 1.0.6 411 | dev: false 412 | resolution: 413 | integrity: sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w== 414 | /safe-buffer/5.1.2: 415 | dev: false 416 | resolution: 417 | integrity: sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g== 418 | /safe-buffer/5.2.1: 419 | dev: false 420 | resolution: 421 | integrity: sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ== 422 | /shebang-command/2.0.0: 423 | dependencies: 424 | shebang-regex: 3.0.0 425 | dev: false 426 | engines: 427 | node: '>=8' 428 | resolution: 429 | integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA== 430 | /shebang-regex/3.0.0: 431 | dev: false 432 | engines: 433 | node: '>=8' 434 | resolution: 435 | integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A== 436 | /shelljs/0.8.4: 437 | dependencies: 438 | glob: 7.1.6 439 | interpret: 1.4.0 440 | rechoir: 0.6.2 441 | dev: false 442 | engines: 443 | node: '>=4' 444 | hasBin: true 445 | resolution: 446 | integrity: sha512-7gk3UZ9kOfPLIAbslLzyWeGiEqx9e3rxwZM0KE6EL8GlGwjym9Mrlx5/p33bWTu9YG6vcS4MBxYZDHYr5lr8BQ== 447 | /signal-exit/3.0.3: 448 | dev: false 449 | resolution: 450 | integrity: sha512-VUJ49FC8U1OxwZLxIbTTrDvLnf/6TDgxZcK8wxR8zs13xpx7xbG60ndBlhNrFi2EMuFRoeDoJO7wthSLq42EjA== 451 | /simple-swizzle/0.2.2: 452 | dependencies: 453 | is-arrayish: 0.3.2 454 | dev: false 455 | resolution: 456 | integrity: sha1-pNprY1/8zMoz9w0Xy5JZLeleVXo= 457 | /sprintf-js/1.0.3: 458 | dev: false 459 | resolution: 460 | integrity: sha1-BOaSb2YolTVPPdAVIDYzuFcpfiw= 461 | /stack-trace/0.0.10: 462 | dev: false 463 | resolution: 464 | integrity: sha1-VHxws0fo0ytOEI6hoqFZ5f3eGcA= 465 | /string_decoder/1.1.1: 466 | dependencies: 467 | safe-buffer: 5.1.2 468 | dev: false 469 | resolution: 470 | integrity: sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg== 471 | /string_decoder/1.3.0: 472 | dependencies: 473 | safe-buffer: 5.2.1 474 | dev: false 475 | resolution: 476 | integrity: sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA== 477 | /strip-final-newline/2.0.0: 478 | dev: false 479 | engines: 480 | node: '>=6' 481 | resolution: 482 | integrity: sha512-BrpvfNAE3dcvq7ll3xVumzjKjZQ5tI1sEUIKr3Uoks0XUl45St3FlatVqef9prk4jRDzhW6WZg+3bk93y6pLjA== 483 | /text-hex/1.0.0: 484 | dev: false 485 | resolution: 486 | integrity: sha512-uuVGNWzgJ4yhRaNSiubPY7OjISw4sw4E5Uv0wbjp+OzcbmVU/rsT8ujgcXJhn9ypzsgr5vlzpPqP+MBBKcGvbg== 487 | /triple-beam/1.3.0: 488 | dev: false 489 | resolution: 490 | integrity: sha512-XrHUvV5HpdLmIj4uVMxHggLbFSZYIn7HEWsqePZcI50pco+MPqJ50wMGY794X7AOOhxOBAjbkqfAbEe/QMp2Lw== 491 | /universalify/1.0.0: 492 | dev: false 493 | engines: 494 | node: '>= 10.0.0' 495 | resolution: 496 | integrity: sha512-rb6X1W158d7pRQBg5gkR8uPaSfiids68LTJQYOtEUhoJUWBdaQHsuT/EUduxXYxcrt4r5PJ4fuHW1MHT6p0qug== 497 | /util-deprecate/1.0.2: 498 | dev: false 499 | resolution: 500 | integrity: sha1-RQ1Nyfpw3nMnYvvS1KKJgUGaDM8= 501 | /which/2.0.2: 502 | dependencies: 503 | isexe: 2.0.0 504 | dev: false 505 | engines: 506 | node: '>= 8' 507 | hasBin: true 508 | resolution: 509 | integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA== 510 | /winston-transport/4.4.0: 511 | dependencies: 512 | readable-stream: 2.3.7 513 | triple-beam: 1.3.0 514 | dev: false 515 | engines: 516 | node: '>= 6.4.0' 517 | resolution: 518 | integrity: sha512-Lc7/p3GtqtqPBYYtS6KCN3c77/2QCev51DvcJKbkFPQNoj1sinkGwLGFDxkXY9J6p9+EPnYs+D90uwbnaiURTw== 519 | /winston/3.3.3: 520 | dependencies: 521 | '@dabh/diagnostics': 2.0.2 522 | async: 3.2.0 523 | is-stream: 2.0.0 524 | logform: 2.2.0 525 | one-time: 1.0.0 526 | readable-stream: 3.6.0 527 | stack-trace: 0.0.10 528 | triple-beam: 1.3.0 529 | winston-transport: 4.4.0 530 | dev: false 531 | engines: 532 | node: '>= 6.4.0' 533 | resolution: 534 | integrity: sha512-oEXTISQnC8VlSAKf1KYSSd7J6IWuRPQqDdo8eoRNaYKLvwSb5+79Z3Yi1lrl6KDpU6/VWaxpakDAtb1oQ4n9aw== 535 | /wrappy/1.0.2: 536 | dev: false 537 | resolution: 538 | integrity: sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= 539 | specifiers: 540 | bluebird: ^3.7.2 541 | execa: ^4.0.3 542 | fs-extra: ^9.0.1 543 | joi: ^17.1.1 544 | js-yaml: ^3.14.0 545 | lodash: ^4.17.19 546 | shelljs: ^0.8.4 547 | winston: ^3.3.3 548 | -------------------------------------------------------------------------------- /scripts/spacex.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | source /opt/mannheimworld/spacex-script/scripts/utils.sh 4 | source /opt/mannheimworld/spacex-script/scripts/version.sh 5 | source /opt/mannheimworld/spacex-script/scripts/config.sh 6 | source /opt/mannheimworld/spacex-script/scripts/tools.sh 7 | export EX_STORAGE_ARGS='' 8 | 9 | 10 | start() 11 | { 12 | if [ ! -f "$composeyaml" ]; then 13 | log_err "No configuration file, please set config" 14 | exit 1 15 | fi 16 | 17 | if [ x"$1" = x"" ]; then 18 | log_info "Start spacex" 19 | 20 | if [ -f "$builddir/api/api_config.json" ]; then 21 | local chain_ws_url=`cat $builddir/api/api_config.json | jq .chain_ws_url` 22 | if [ x"$chain_ws_url" == x"\"ws://127.0.0.1:19944\"" ]; then 23 | start_chain 24 | if [ $? -ne 0 ]; then 25 | docker-compose -f $composeyaml down 26 | exit 1 27 | fi 28 | else 29 | log_info "API will connect to other chain: ${chain_ws_url}" 30 | fi 31 | else 32 | start_chain 33 | if [ $? -ne 0 ]; then 34 | docker-compose -f $composeyaml down 35 | exit 1 36 | fi 37 | fi 38 | 39 | start_storage 40 | if [ $? -ne 0 ]; then 41 | docker-compose -f $composeyaml down 42 | exit 1 43 | fi 44 | 45 | start_api 46 | if [ $? -ne 0 ]; then 47 | docker-compose -f $composeyaml down 48 | exit 1 49 | fi 50 | 51 | start_sdatamanager 52 | if [ $? -ne 0 ]; then 53 | docker-compose -f $composeyaml down 54 | exit 1 55 | fi 56 | 57 | start_ipfs 58 | if [ $? -ne 0 ]; then 59 | docker-compose -f $composeyaml down 60 | exit 1 61 | fi 62 | 63 | log_success "Start spacex success" 64 | return 0 65 | fi 66 | 67 | if [ x"$1" = x"chain" ]; then 68 | log_info "Start chain service" 69 | start_chain 70 | if [ $? -ne 0 ]; then 71 | exit 1 72 | fi 73 | log_success "Start chain service success" 74 | return 0 75 | fi 76 | 77 | if [ x"$1" = x"api" ]; then 78 | log_info "Start api service" 79 | start_api 80 | if [ $? -ne 0 ]; then 81 | exit 1 82 | fi 83 | log_success "Start api service success" 84 | return 0 85 | fi 86 | 87 | if [ x"$1" = x"storage" ]; then 88 | log_info "Start storage service" 89 | shift 90 | start_storage $@ 91 | if [ $? -ne 0 ]; then 92 | exit 1 93 | fi 94 | log_success "Start storage service success" 95 | return 0 96 | fi 97 | 98 | if [ x"$1" = x"sdatamanager" ]; then 99 | log_info "Start sdatamanager service" 100 | start_sdatamanager 101 | if [ $? -ne 0 ]; then 102 | exit 1 103 | fi 104 | log_success "Start sdatamanager service success" 105 | return 0 106 | fi 107 | 108 | if [ x"$1" = x"ipfs" ]; then 109 | log_info "Start ipfs service" 110 | start_ipfs 111 | if [ $? -ne 0 ]; then 112 | exit 1 113 | fi 114 | log_success "Start ipfs service success" 115 | return 0 116 | fi 117 | 118 | help 119 | return 1 120 | } 121 | 122 | stop() 123 | { 124 | if [ x"$1" = x"" ]; then 125 | log_info "Stop spacex" 126 | stop_chain 127 | stop_sdatamanager 128 | stop_api 129 | stop_storage 130 | stop_ipfs 131 | log_success "Stop spacex success" 132 | return 0 133 | fi 134 | 135 | if [ x"$1" = x"chain" ]; then 136 | log_info "Stop chain service" 137 | stop_chain 138 | log_success "Stop chain service success" 139 | return 0 140 | fi 141 | 142 | if [ x"$1" = x"api" ]; then 143 | log_info "Stop api service" 144 | stop_api 145 | log_success "Stop api service success" 146 | return 0 147 | fi 148 | 149 | if [ x"$1" = x"storage" ]; then 150 | log_info "Stop storage service" 151 | stop_storage 152 | log_success "Stop storage service success" 153 | return 0 154 | fi 155 | 156 | if [ x"$1" = x"sdatamanager" ]; then 157 | log_info "Cannot stop the sdatamanager service alone, this will affect your benefits" 158 | return 0 159 | fi 160 | 161 | if [ x"$1" = x"ipfs" ]; then 162 | log_info "Stop ipfs service" 163 | stop_ipfs 164 | log_success "Stop ipfs service success" 165 | return 0 166 | fi 167 | 168 | help 169 | return 1 170 | } 171 | 172 | start_chain() 173 | { 174 | if [ ! -f "$composeyaml" ]; then 175 | log_err "No configuration file, please set config" 176 | return 1 177 | fi 178 | 179 | check_docker_status spacex 180 | if [ $? -eq 0 ]; then 181 | return 0 182 | fi 183 | 184 | local config_file=$builddir/chain/chain_config.json 185 | if [ x"$config_file" = x"" ]; then 186 | log_err "Please give right chain config file" 187 | return 1 188 | fi 189 | 190 | local chain_port=`cat $config_file | jq .port` 191 | 192 | if [ x"$chain_port" = x"" ] || [ x"$chain_port" = x"null" ]; then 193 | chain_port=30888 194 | fi 195 | 196 | if [ $chain_port -lt 0 ] || [ $chain_port -gt 65535 ]; then 197 | log_err "The range of chain port is 0 ~ 65535" 198 | return 1 199 | fi 200 | 201 | local res=0 202 | check_port $chain_port 203 | res=$(($?|$res)) 204 | check_port 19933 205 | res=$(($?|$res)) 206 | check_port 19944 207 | res=$(($?|$res)) 208 | if [ $res -ne 0 ]; then 209 | return 1 210 | fi 211 | 212 | docker-compose -f $composeyaml up -d spacex 213 | if [ $? -ne 0 ]; then 214 | log_err "Start spacex-api failed" 215 | return 1 216 | fi 217 | return 0 218 | } 219 | 220 | stop_chain() 221 | { 222 | check_docker_status spacex 223 | if [ $? -ne 1 ]; then 224 | log_info "Stopping spacex chain service" 225 | docker stop spacex &>/dev/null 226 | docker rm spacex &>/dev/null 227 | fi 228 | return 0 229 | } 230 | 231 | 232 | ### start storage ### 233 | start_storage() 234 | { 235 | if [ ! -f "$composeyaml" ]; then 236 | log_err "No configuration file, please set config" 237 | return 1 238 | fi 239 | 240 | if [ -d "$builddir/storage" ]; then 241 | local a_or_b=`cat $basedir/etc/storage.ab` 242 | check_docker_status spacex-storage-$a_or_b 243 | if [ $? -eq 0 ]; then 244 | return 0 245 | fi 246 | 247 | check_port 12222 248 | if [ $? -ne 0 ]; then 249 | return 1 250 | fi 251 | 252 | if [ -f "$scriptdir/install_sgx.sh" ]; then 253 | $scriptdir/install_sgx.sh 254 | if [ $? -ne 0 ]; then 255 | log_err "Install sgx dirver failed" 256 | return 1 257 | fi 258 | fi 259 | 260 | if [ ! -e "/dev/isgx" ]; then 261 | log_err "Your device can't install sgx dirver, please check your CPU and BIOS to determine if they support SGX." 262 | return 1 263 | fi 264 | EX_STORAGE_ARGS=$@ docker-compose -f $composeyaml up -d spacex-storage-$a_or_b 265 | if [ $? -ne 0 ]; then 266 | log_err "Start spacex-storage-$a_or_b failed" 267 | return 1 268 | fi 269 | fi 270 | return 0 271 | } 272 | 273 | stop_storage() 274 | { 275 | check_docker_status spacex-storage-a 276 | if [ $? -ne 1 ]; then 277 | log_info "Stopping spacex storage A service" 278 | docker stop spacex-storage-a &>/dev/null 279 | docker rm spacex-storage-a &>/dev/null 280 | fi 281 | 282 | check_docker_status spacex-storage-b 283 | if [ $? -ne 1 ]; then 284 | log_info "Stopping spacex storage B service" 285 | docker stop spacex-storage-b &>/dev/null 286 | docker rm spacex-storage-b &>/dev/null 287 | fi 288 | 289 | return 0 290 | } 291 | 292 | start_api() 293 | { 294 | if [ ! -f "$composeyaml" ]; then 295 | log_err "No configuration file, please set config" 296 | return 1 297 | fi 298 | 299 | if [ -d "$builddir/storage" ]; then 300 | check_docker_status spacex-api 301 | if [ $? -eq 0 ]; then 302 | return 0 303 | fi 304 | 305 | check_port 56666 306 | if [ $? -ne 0 ]; then 307 | return 1 308 | fi 309 | 310 | docker-compose -f $composeyaml up -d spacex-api 311 | if [ $? -ne 0 ]; then 312 | log_err "Start spacex-api failed" 313 | return 1 314 | fi 315 | fi 316 | return 0 317 | } 318 | 319 | stop_api() 320 | { 321 | check_docker_status spacex-api 322 | if [ $? -ne 1 ]; then 323 | log_info "Stopping spacex API service" 324 | docker stop spacex-api &>/dev/null 325 | docker rm spacex-api &>/dev/null 326 | fi 327 | return 0 328 | } 329 | 330 | start_sdatamanager() 331 | { 332 | if [ ! -f "$composeyaml" ]; then 333 | log_err "No configuration file, please set config" 334 | return 1 335 | fi 336 | 337 | if [ -d "$builddir/sdatamanager" ]; then 338 | check_docker_status spacex-sdatamanager 339 | if [ $? -eq 0 ]; then 340 | return 0 341 | fi 342 | 343 | docker-compose -f $composeyaml up -d spacex-sdatamanager 344 | if [ $? -ne 0 ]; then 345 | log_err "Start spacex-sdatamanager failed" 346 | return 1 347 | fi 348 | 349 | local upgrade_pid=$(ps -ef | grep "/opt/mannheimworld/spacex-script/scripts/auto_sdatamanager.sh" | grep -v grep | awk '{print $2}') 350 | if [ x"$upgrade_pid" != x"" ]; then 351 | kill -9 $upgrade_pid 352 | fi 353 | 354 | if [ -f "$scriptdir/auto_sdatamanager.sh" ]; then 355 | nohup $scriptdir/auto_sdatamanager.sh &>$basedir/auto_sdatamanager.log & 356 | if [ $? -ne 0 ]; then 357 | log_err "Start spacex-sdatamanager upgrade failed" 358 | return 1 359 | fi 360 | fi 361 | fi 362 | return 0 363 | } 364 | 365 | stop_sdatamanager() 366 | { 367 | local upgrade_pid=$(ps -ef | grep "/opt/mannheimworld/spacex-script/scripts/auto_sdatamanager.sh" | grep -v grep | awk '{print $2}') 368 | 369 | if [ x"$upgrade_pid" != x"" ]; then 370 | kill -9 $upgrade_pid 371 | fi 372 | 373 | check_docker_status spacex-sdatamanager 374 | if [ $? -ne 1 ]; then 375 | log_info "Stopping spacex sdatamanager service" 376 | docker stop spacex-sdatamanager &>/dev/null 377 | docker rm spacex-sdatamanager &>/dev/null 378 | fi 379 | return 0 380 | } 381 | 382 | start_ipfs() 383 | { 384 | if [ ! -f "$composeyaml" ]; then 385 | log_err "No configuration file, please set config" 386 | return 1 387 | fi 388 | 389 | if [ -d "$builddir/ipfs" ]; then 390 | check_docker_status ipfs 391 | if [ $? -eq 0 ]; then 392 | return 0 393 | fi 394 | 395 | local res=0 396 | check_port 4001 397 | res=$(($?|$res)) 398 | check_port 5001 399 | res=$(($?|$res)) 400 | check_port 37773 401 | res=$(($?|$res)) 402 | if [ $res -ne 0 ]; then 403 | return 1 404 | fi 405 | 406 | docker-compose -f $composeyaml up -d ipfs 407 | if [ $? -ne 0 ]; then 408 | log_err "Start ipfs failed" 409 | return 1 410 | fi 411 | fi 412 | return 0 413 | } 414 | 415 | stop_ipfs() 416 | { 417 | check_docker_status ipfs 418 | if [ $? -ne 1 ]; then 419 | log_info "Stopping ipfs service" 420 | docker stop ipfs &>/dev/null 421 | docker rm ipfs &>/dev/null 422 | fi 423 | return 0 424 | } 425 | 426 | 427 | 428 | 429 | 430 | reload() { 431 | if [ x"$1" = x"" ]; then 432 | log_info "Reload all service" 433 | stop 434 | start 435 | log_success "Reload all service success" 436 | return 0 437 | fi 438 | 439 | if [ x"$1" = x"chain" ]; then 440 | log_info "Reload chain service" 441 | 442 | stop_chain 443 | start_chain 444 | 445 | log_success "Reload chain service success" 446 | return 0 447 | fi 448 | 449 | if [ x"$1" = x"api" ]; then 450 | log_info "Reload api service" 451 | 452 | stop_api 453 | start_api 454 | 455 | log_success "Reload api service success" 456 | return 0 457 | fi 458 | 459 | if [ x"$1" = x"storage" ]; then 460 | log_info "Reload storage service" 461 | 462 | stop_storage 463 | shift 464 | start_storage $@ 465 | 466 | log_success "Reload storage service success" 467 | return 0 468 | fi 469 | 470 | if [ x"$1" = x"sdatamanager" ]; then 471 | log_info "Reload sdatamanager service" 472 | 473 | stop_sdatamanager 474 | start_sdatamanager 475 | 476 | log_success "Reload sdatamanager service success" 477 | return 0 478 | fi 479 | 480 | if [ x"$1" = x"ipfs" ]; then 481 | log_info "Reload ipfs service" 482 | 483 | stop_ipfs 484 | start_ipfs 485 | 486 | log_success "Reload ipfs service success" 487 | return 0 488 | fi 489 | 490 | help 491 | return 1 492 | } 493 | 494 | ########################################logs################################################ 495 | 496 | logs_help() 497 | { 498 | cat << EOF 499 | Usage: spacex logs [OPTIONS] {chain|api|storage|storage-a|storage-b|sdatamanager|ipfs} 500 | 501 | Fetch the logs of a service 502 | 503 | Options: 504 | --details Show extra details provided to logs 505 | -f, --follow Follow log output 506 | --since string Show logs since timestamp (e.g. 2012-01-02T13:23:37) or relative (e.g. 42m for 42 minutes) 507 | --tail string Number of lines to show from the end of the logs (default "all") 508 | -t, --timestamps Show timestamps 509 | --until string Show logs before a timestamp (e.g. 2012-01-02T13:23:37) or relative (e.g. 42m for 42 minutes) 510 | EOF 511 | } 512 | 513 | logs() 514 | { 515 | local name="${!#}" 516 | local array=( "$@" ) 517 | local logs_help_flag=0 518 | unset "array[${#array[@]}-1]" 519 | 520 | if [ x"$name" == x"chain" ]; then 521 | check_docker_status spacex 522 | if [ $? -eq 1 ]; then 523 | log_info "Service spacex chain is not started now" 524 | return 0 525 | fi 526 | docker logs ${array[@]} -f spacex 527 | logs_help_flag=$? 528 | elif [ x"$name" == x"api" ]; then 529 | check_docker_status spacex-api 530 | if [ $? -eq 1 ]; then 531 | log_info "Service spacex API is not started now" 532 | return 0 533 | fi 534 | docker logs ${array[@]} -f spacex-api 535 | logs_help_flag=$? 536 | elif [ x"$name" == x"storage" ]; then 537 | local a_or_b=`cat $basedir/etc/storage.ab` 538 | check_docker_status spacex-storage-$a_or_b 539 | if [ $? -eq 1 ]; then 540 | log_info "Service spacex storage is not started now" 541 | return 0 542 | fi 543 | docker logs ${array[@]} -f spacex-storage-$a_or_b 544 | logs_help_flag=$? 545 | elif [ x"$name" == x"ipfs" ]; then 546 | check_docker_status ipfs 547 | if [ $? -eq 1 ]; then 548 | log_info "Service ipfs is not started now" 549 | return 0 550 | fi 551 | docker logs ${array[@]} -f ipfs 552 | logs_help_flag=$? 553 | elif [ x"$name" == x"sdatamanager" ]; then 554 | check_docker_status spacex-sdatamanager 555 | if [ $? -eq 1 ]; then 556 | log_info "Service spacex sdatamanager is not started now" 557 | return 0 558 | fi 559 | docker logs ${array[@]} -f spacex-sdatamanager 560 | logs_help_flag=$? 561 | elif [ x"$name" == x"storage-a" ]; then 562 | check_docker_status spacex-storage-a 563 | if [ $? -eq 1 ]; then 564 | log_info "Service spacex storage-a is not started now" 565 | return 0 566 | fi 567 | docker logs ${array[@]} -f spacex-storage-a 568 | logs_help_flag=$? 569 | elif [ x"$name" == x"storage-b" ]; then 570 | check_docker_status spacex-storage-b 571 | if [ $? -eq 1 ]; then 572 | log_info "Service spacex storage-b is not started now" 573 | return 0 574 | fi 575 | docker logs ${array[@]} -f spacex-storage-b 576 | logs_help_flag=$? 577 | elif [ x"$name" == x"sdatamanager-upshell" ]; then 578 | local upgrade_pid=$(ps -ef | grep "/opt/mannheimworld/spacex-script/scripts/auto_sdatamanager.sh" | grep -v grep | awk '{print $2}') 579 | if [ x"$upgrade_pid" == x"" ]; then 580 | log_info "Service spacex sdatamanager upgrade shell is not started now" 581 | return 0 582 | fi 583 | tail -f $basedir/auto_sdatamanager.log 584 | else 585 | logs_help 586 | return 1 587 | fi 588 | 589 | if [ $logs_help_flag -ne 0 ]; then 590 | logs_help 591 | return 1 592 | fi 593 | } 594 | 595 | 596 | #######################################status################################################ 597 | 598 | status() 599 | { 600 | if [ x"$1" == x"chain" ]; then 601 | chain_status 602 | elif [ x"$1" == x"api" ]; then 603 | api_status 604 | elif [ x"$1" == x"storage" ]; then 605 | storage_status 606 | elif [ x"$1" == x"sdatamanager" ]; then 607 | sdatamanager_status 608 | elif [ x"$1" == x"ipfs" ]; then 609 | ipfs_status 610 | elif [ x"$1" == x"" ]; then 611 | all_status 612 | else 613 | help 614 | fi 615 | } 616 | 617 | all_status() 618 | { 619 | local chain_status="stop" 620 | local api_status="stop" 621 | local storage_status="stop" 622 | local sdatamanager_status="stop" 623 | local ipfs_status="stop" 624 | 625 | check_docker_status spacex 626 | local res=$? 627 | if [ $res -eq 0 ]; then 628 | chain_status="running" 629 | elif [ $res -eq 2 ]; then 630 | chain_status="exited" 631 | fi 632 | 633 | check_docker_status spacex-api 634 | res=$? 635 | if [ $res -eq 0 ]; then 636 | api_status="running" 637 | elif [ $res -eq 2 ]; then 638 | api_status="exited" 639 | fi 640 | 641 | local a_or_b=`cat $basedir/etc/storage.ab` 642 | check_docker_status spacex-storage-$a_or_b 643 | res=$? 644 | if [ $res -eq 0 ]; then 645 | storage_status="running" 646 | elif [ $res -eq 2 ]; then 647 | storage_status="exited" 648 | fi 649 | 650 | check_docker_status spacex-sdatamanager 651 | res=$? 652 | if [ $res -eq 0 ]; then 653 | sdatamanager_status="running" 654 | elif [ $res -eq 2 ]; then 655 | sdatamanager_status="exited" 656 | fi 657 | 658 | check_docker_status ipfs 659 | res=$? 660 | if [ $res -eq 0 ]; then 661 | ipfs_status="running" 662 | elif [ $res -eq 2 ]; then 663 | ipfs_status="exited" 664 | fi 665 | 666 | cat << EOF 667 | ----------------------------------------- 668 | Service Status 669 | ----------------------------------------- 670 | chain ${chain_status} 671 | api ${api_status} 672 | storage ${storage_status} 673 | sdatamanager ${sdatamanager_status} 674 | ipfs ${ipfs_status} 675 | ----------------------------------------- 676 | EOF 677 | } 678 | 679 | chain_status() 680 | { 681 | local chain_status="stop" 682 | 683 | check_docker_status spacex 684 | local res=$? 685 | if [ $res -eq 0 ]; then 686 | chain_status="running" 687 | elif [ $res -eq 2 ]; then 688 | chain_status="exited" 689 | fi 690 | 691 | cat << EOF 692 | ----------------------------------------- 693 | Service Status 694 | ----------------------------------------- 695 | chain ${chain_status} 696 | ----------------------------------------- 697 | EOF 698 | } 699 | 700 | api_status() 701 | { 702 | local api_status="stop" 703 | 704 | check_docker_status spacex-api 705 | res=$? 706 | if [ $res -eq 0 ]; then 707 | api_status="running" 708 | elif [ $res -eq 2 ]; then 709 | api_status="exited" 710 | fi 711 | 712 | cat << EOF 713 | ----------------------------------------- 714 | Service Status 715 | ----------------------------------------- 716 | api ${api_status} 717 | ----------------------------------------- 718 | EOF 719 | } 720 | 721 | storage_status() 722 | { 723 | local storage_a_status="stop" 724 | local storage_b_status="stop" 725 | local a_or_b=`cat $basedir/etc/storage.ab` 726 | 727 | check_docker_status spacex-storage-a 728 | local res=$? 729 | if [ $res -eq 0 ]; then 730 | storage_a_status="running" 731 | elif [ $res -eq 2 ]; then 732 | storage_a_status="exited" 733 | fi 734 | 735 | check_docker_status spacex-storage-b 736 | res=$? 737 | if [ $res -eq 0 ]; then 738 | storage_b_status="running" 739 | elif [ $res -eq 2 ]; then 740 | storage_b_status="exited" 741 | fi 742 | 743 | cat << EOF 744 | ----------------------------------------- 745 | Service Status 746 | ----------------------------------------- 747 | storage-a ${storage_a_status} 748 | storage-b ${storage_b_status} 749 | main-progress ${a_or_b} 750 | ----------------------------------------- 751 | EOF 752 | } 753 | 754 | sdatamanager_status() 755 | { 756 | local sdatamanager_status="stop" 757 | local upgrade_shell_status="stop" 758 | 759 | check_docker_status spacex-sdatamanager 760 | res=$? 761 | if [ $res -eq 0 ]; then 762 | sdatamanager_status="running" 763 | elif [ $res -eq 2 ]; then 764 | sdatamanager_status="exited" 765 | fi 766 | 767 | local upgrade_pid=$(ps -ef | grep "/opt/mannheimworld/spacex-script/scripts/auto_sdatamanager.sh" | grep -v grep | awk '{print $2}') 768 | if [ x"$upgrade_pid" != x"" ]; then 769 | upgrade_shell_status="running->${upgrade_pid}" 770 | fi 771 | 772 | 773 | cat << EOF 774 | ----------------------------------------- 775 | Service Status 776 | ----------------------------------------- 777 | sdatamanager ${sdatamanager_status} 778 | upgrade-shell ${upgrade_shell_status} 779 | ----------------------------------------- 780 | EOF 781 | } 782 | 783 | ipfs_status() 784 | { 785 | local ipfs_status="stop" 786 | 787 | check_docker_status ipfs 788 | res=$? 789 | if [ $res -eq 0 ]; then 790 | ipfs_status="running" 791 | elif [ $res -eq 2 ]; then 792 | ipfs_status="exited" 793 | fi 794 | 795 | cat << EOF 796 | ----------------------------------------- 797 | Service Status 798 | ----------------------------------------- 799 | ipfs ${ipfs_status} 800 | ----------------------------------------- 801 | EOF 802 | } 803 | 804 | ######################################main entrance############################################ 805 | 806 | help() 807 | { 808 | cat << EOF 809 | Usage: 810 | help show help information 811 | version show version 812 | 813 | start {chain|api|storage|sdatamanager|ipfs} start all spacex service 814 | stop {chain|api|storage|sdatamanager|ipfs} stop all spacex service or stop one service 815 | 816 | status {chain|api|storage|sdatamanager|ipfs} check status or reload one service status 817 | reload {chain|api|storage|sdatamanager|ipfs} reload all service or reload one service 818 | logs {chain|api|storage|storage-a|storage-b|sdatamanager|ipfs} track service logs, ctrl-c to exit. use 'spacex logs help' for more details 819 | 820 | tools {...} use 'spacex tools help' for more details 821 | config {...} configuration operations, use 'spacex config help' for more details 822 | EOF 823 | } 824 | 825 | case "$1" in 826 | version) 827 | version 828 | ;; 829 | start) 830 | shift 831 | start $@ 832 | ;; 833 | stop) 834 | stop $2 835 | ;; 836 | reload) 837 | shift 838 | reload $@ 839 | ;; 840 | status) 841 | status $2 842 | ;; 843 | logs) 844 | shift 845 | logs $@ 846 | ;; 847 | config) 848 | shift 849 | config $@ 850 | ;; 851 | tools) 852 | shift 853 | tools $@ 854 | ;; 855 | *) 856 | help 857 | esac 858 | exit 0 859 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------