From 614370db8673be487595f927192506fc646da876 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Sat, 8 Jan 2022 16:44:58 +0900 Subject: [PATCH 01/21] Extract deleteSnapshot() from writeSnapshot() --- block-pool/index.js | 2 +- common/file-util.js | 45 ++++++++++++++++++++++++--------------------- node/index.js | 20 +++++++++++++------- 3 files changed, 38 insertions(+), 29 deletions(-) diff --git a/block-pool/index.js b/block-pool/index.js index 21f738f58..3675e99a6 100644 --- a/block-pool/index.js +++ b/block-pool/index.js @@ -576,7 +576,7 @@ class BlockPool { return validLastVotes; } tempDb.destroyDb(); - throw Error(`[${LOG_HEADER}] lastBlock doesn't have enough votes`); + throw Error(`[${LOG_HEADER}] lastBlock doesn't have enough votes: ${lastBlock.number}`); } /** diff --git a/common/file-util.js b/common/file-util.js index ba7a2157e..3ed36642e 100644 --- a/common/file-util.js +++ b/common/file-util.js @@ -256,28 +256,31 @@ class FileUtil { const LOG_HEADER = 'writeSnapshot'; const filePath = FileUtil.getSnapshotPathByBlockNumber(snapshotPath, blockNumber, isDebug); - if (snapshot === null) { // Delete - if (fs.existsSync(filePath)) { - try { - fs.unlinkSync(filePath); - } catch (err) { - logger.error(`[${LOG_HEADER}] Failed to delete ${filePath}: ${err.stack}`); - } + return new Promise((resolve) => { + new JsonStreamStringify({ docs: ObjectUtil.toChunks(snapshot, snapshotChunkSize) }) + .pipe(zlib.createGzip()) + .pipe(fs.createWriteStream(filePath, { flags: 'w' })) + .on('finish', () => { + logger.debug(`[${LOG_HEADER}] Snapshot written at ${filePath}`); + resolve(); + }) + .on('error', (e) => { + logger.error(`[${LOG_HEADER}] Failed to write snapshot at ${filePath}: ${e}`); + resolve(); + }); + }); + } + + static deleteSnapshot(snapshotPath, blockNumber, isDebug = false) { + const LOG_HEADER = 'deleteSnapshot'; + + const filePath = FileUtil.getSnapshotPathByBlockNumber(snapshotPath, blockNumber, isDebug); + if (fs.existsSync(filePath)) { + try { + fs.unlinkSync(filePath); + } catch (err) { + logger.error(`[${LOG_HEADER}] Failed to delete snapshot at ${filePath}: ${err.stack}`); } - } else { - return new Promise((resolve) => { - new JsonStreamStringify({ docs: ObjectUtil.toChunks(snapshot, snapshotChunkSize) }) - .pipe(zlib.createGzip()) - .pipe(fs.createWriteStream(filePath, { flags: 'w' })) - .on('finish', () => { - logger.debug(`[${LOG_HEADER}] Snapshot written at ${filePath}`); - resolve(); - }) - .on('error', (e) => { - logger.error(`[${LOG_HEADER}] Failed to write snapshot at ${filePath}: ${e}`); - resolve(); - }); - }); } } diff --git a/node/index.js b/node/index.js index e26a6050d..187cf7ed5 100644 --- a/node/index.js +++ b/node/index.js @@ -346,16 +346,22 @@ class BlockchainNode { async updateSnapshots(blockNumber) { if (blockNumber % NodeConfigs.SNAPSHOTS_INTERVAL_BLOCK_NUMBER === 0) { - const snapshot = this.buildBlockchainSnapshot(blockNumber, this.stateManager.getFinalRoot()); - const snapshotChunkSize = this.getBlockchainParam('resource/snapshot_chunk_size'); - await FileUtil.writeSnapshot(this.snapshotDir, blockNumber, snapshot, snapshotChunkSize); - await FileUtil.writeSnapshot( - this.snapshotDir, - blockNumber - NodeConfigs.MAX_NUM_SNAPSHOTS * NodeConfigs.SNAPSHOTS_INTERVAL_BLOCK_NUMBER, - null, snapshotChunkSize); + this.deleteSnapshot( + blockNumber - NodeConfigs.MAX_NUM_SNAPSHOTS * NodeConfigs.SNAPSHOTS_INTERVAL_BLOCK_NUMBER); + await this.writeSnapshot(blockNumber); } } + async writeSnapshot(blockNumber) { + const snapshot = this.buildBlockchainSnapshot(blockNumber, this.stateManager.getFinalRoot()); + const snapshotChunkSize = this.getBlockchainParam('resource/snapshot_chunk_size'); + await FileUtil.writeSnapshot(this.snapshotDir, blockNumber, snapshot, snapshotChunkSize); + } + + deleteSnapshot(blockNumber) { + FileUtil.deleteSnapshot(this.snapshotDir, blockNumber); + } + buildBlockchainSnapshot(blockNumber, stateRoot) { const block = this.bc.getBlockByNumber(blockNumber); const blockTimestamp = block.timestamp; From 6ab02870cb7d8ccca776ead10f79b526fa25c747 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Sat, 8 Jan 2022 18:18:46 +0900 Subject: [PATCH 02/21] Fix undefined variable --- common/file-util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/file-util.js b/common/file-util.js index 3ed36642e..770288f92 100644 --- a/common/file-util.js +++ b/common/file-util.js @@ -247,7 +247,7 @@ class FileUtil { const h2nPath = FileUtil.getH2nPath(chainPath, blockHash); return Number(fs.readFileSync(h2nPath).toString()); } catch (err) { - logger.error(`[${LOG_HEADER}] Error while reading ${filePath}: ${err}`); + logger.error(`[${LOG_HEADER}] Error while reading ${h2nPath}: ${err}`); return -1; } } From a20456042917ebbbd02e57c97bcd2d62acb5bff9 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Sat, 8 Jan 2022 19:01:28 +0900 Subject: [PATCH 03/21] Finalize state version and write snapshot whenever block is finalized --- node/index.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/node/index.js b/node/index.js index 187cf7ed5..de5d3eb3a 100644 --- a/node/index.js +++ b/node/index.js @@ -855,6 +855,9 @@ class BlockchainNode { }); }); } + const versionToFinalize = this.bp.hashToDb.get(blockToFinalize.hash).stateVersion; + this.cloneAndFinalizeVersion(versionToFinalize, blockToFinalize.number); + if (this.eh) { this.eh.emitBlockFinalized(blockToFinalize.number); } @@ -866,8 +869,6 @@ class BlockchainNode { } } if (lastFinalizedBlock) { - const versionToFinalize = this.bp.hashToDb.get(lastFinalizedBlock.hash).stateVersion; - this.cloneAndFinalizeVersion(versionToFinalize, lastFinalizedBlock.number); this.bp.cleanUpAfterFinalization(this.bc.lastBlock(), recordedInvalidBlocks); } } From b540bf511a3f9fbc6c91e83f69f9650127f6146c Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Sat, 8 Jan 2022 19:04:21 +0900 Subject: [PATCH 04/21] Log messages for block or snapshot overwriting --- blockchain/index.js | 10 ++++++++++ common/file-util.js | 24 ++++++++++++++++++++---- consensus/index.js | 2 +- node/index.js | 10 ++++++++-- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/blockchain/index.js b/blockchain/index.js index fa90541e1..e57e89bb1 100644 --- a/blockchain/index.js +++ b/blockchain/index.js @@ -226,7 +226,17 @@ class Blockchain { } writeBlock(block) { + const LOG_HEADER = 'writeBlock'; + + if (FileUtil.hasBlockFile(this.blockchainPath, block)) { + logger.error( + `[${LOG_HEADER}] Overwriting block file for block ${block.number} of hash ${block.hash}`); + } FileUtil.writeBlockFile(this.blockchainPath, block); + if (FileUtil.hasH2nFile(this.blockchainPath, block.hash, block.number)) { + logger.error( + `[${LOG_HEADER}] Overwriting h2n file for block ${block.number} of hash ${block.hash}`); + } FileUtil.writeH2nFile(this.blockchainPath, block.hash, block.number); } diff --git a/common/file-util.js b/common/file-util.js index 770288f92..8921360a4 100644 --- a/common/file-util.js +++ b/common/file-util.js @@ -214,6 +214,11 @@ class FileUtil { } } + static hasBlockFile(chainPath, blockNumber) { + const blockPath = FileUtil.getBlockPath(chainPath, blockNumber); + return fs.existsSync(blockPath); + } + static writeH2nFile(chainPath, blockHash, blockNumber) { const LOG_HEADER = 'writeH2nFile'; @@ -241,6 +246,11 @@ class FileUtil { } } + static hasH2nFile(chainPath, blockHash) { + const h2nPath = FileUtil.getH2nPath(chainPath, blockHash); + return fs.existsSync(h2nPath); + } + static readH2nFile(chainPath, blockHash) { const LOG_HEADER = 'readH2nFile'; try { @@ -252,8 +262,9 @@ class FileUtil { } } - static async writeSnapshot(snapshotPath, blockNumber, snapshot, snapshotChunkSize, isDebug = false) { - const LOG_HEADER = 'writeSnapshot'; + static async writeSnapshotFile( + snapshotPath, blockNumber, snapshot, snapshotChunkSize, isDebug = false) { + const LOG_HEADER = 'writeSnapshotFile'; const filePath = FileUtil.getSnapshotPathByBlockNumber(snapshotPath, blockNumber, isDebug); return new Promise((resolve) => { @@ -271,8 +282,8 @@ class FileUtil { }); } - static deleteSnapshot(snapshotPath, blockNumber, isDebug = false) { - const LOG_HEADER = 'deleteSnapshot'; + static deleteSnapshotFile(snapshotPath, blockNumber, isDebug = false) { + const LOG_HEADER = 'deleteSnapshotFile'; const filePath = FileUtil.getSnapshotPathByBlockNumber(snapshotPath, blockNumber, isDebug); if (fs.existsSync(filePath)) { @@ -284,6 +295,11 @@ class FileUtil { } } + static hasSnapshotFile(snapshotPath, blockNumber, isDebug = false) { + const filePath = FileUtil.getSnapshotPathByBlockNumber(snapshotPath, blockNumber, isDebug); + return fs.existsSync(filePath); + } + static getAccountFromKeystoreFile(keystorePath, password) { const keystore = JSON.parse(fs.readFileSync(keystorePath)); return ainUtil.privateToAccount(ainUtil.v3KeystoreToPrivate(keystore, password)); diff --git a/consensus/index.js b/consensus/index.js index 6efe02996..ee2418cd0 100644 --- a/consensus/index.js +++ b/consensus/index.js @@ -757,7 +757,7 @@ class Consensus { const snapshot = node.buildBlockchainSnapshot(number, db.stateRoot); const snapshotChunkSize = node.getBlockchainParam('resource/snapshot_chunk_size'); // NOTE(liayoo): This write is not awaited. - FileUtil.writeSnapshot(node.snapshotDir, number, snapshot, snapshotChunkSize, true); + FileUtil.writeSnapshotFile(node.snapshotDir, number, snapshot, snapshotChunkSize, true); } throw new ConsensusError({ code: ConsensusErrorCode.INVALID_STATE_PROOF_HASH, diff --git a/node/index.js b/node/index.js index de5d3eb3a..3d17fc564 100644 --- a/node/index.js +++ b/node/index.js @@ -353,13 +353,19 @@ class BlockchainNode { } async writeSnapshot(blockNumber) { + const LOG_HEADER = 'writeSnapshot'; + const snapshot = this.buildBlockchainSnapshot(blockNumber, this.stateManager.getFinalRoot()); const snapshotChunkSize = this.getBlockchainParam('resource/snapshot_chunk_size'); - await FileUtil.writeSnapshot(this.snapshotDir, blockNumber, snapshot, snapshotChunkSize); + if (FileUtil.hasSnapshotFile(this.snapshotDir, blockNumber)) { + logger.error( + `[${LOG_HEADER}] Overwriting snapshot file for block ${blockNumber}`); + } + await FileUtil.writeSnapshotFile(this.snapshotDir, blockNumber, snapshot, snapshotChunkSize); } deleteSnapshot(blockNumber) { - FileUtil.deleteSnapshot(this.snapshotDir, blockNumber); + FileUtil.deleteSnapshotFile(this.snapshotDir, blockNumber); } buildBlockchainSnapshot(blockNumber, stateRoot) { From 33ce0fa786ecd74f086fea0f54e0a327feac9d0e Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Sat, 8 Jan 2022 20:15:49 +0900 Subject: [PATCH 05/21] Fix a typo --- blockchain/index.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/blockchain/index.js b/blockchain/index.js index e57e89bb1..7f8b44998 100644 --- a/blockchain/index.js +++ b/blockchain/index.js @@ -233,7 +233,8 @@ class Blockchain { `[${LOG_HEADER}] Overwriting block file for block ${block.number} of hash ${block.hash}`); } FileUtil.writeBlockFile(this.blockchainPath, block); - if (FileUtil.hasH2nFile(this.blockchainPath, block.hash, block.number)) { + + if (FileUtil.hasH2nFile(this.blockchainPath, block.hash)) { logger.error( `[${LOG_HEADER}] Overwriting h2n file for block ${block.number} of hash ${block.hash}`); } From 9653dd549d77ecaf1d8b9e0ae35a8ba60cd83659 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Sat, 8 Jan 2022 20:35:19 +0900 Subject: [PATCH 06/21] Do not write to file for loaded blocks --- node/index.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/node/index.js b/node/index.js index 3d17fc564..eb7eaf1c6 100644 --- a/node/index.js +++ b/node/index.js @@ -703,7 +703,7 @@ class BlockchainNode { this.bc.addBlockToChainAndWriteToDisk(block, false); this.cloneAndFinalizeVersion(this.bp.hashToDb.get(block.hash).stateVersion, 0); } else { - this.tryFinalizeChain(isGenesisStart); + this.tryFinalizeChain(isGenesisStart, false); } } } catch (e) { @@ -829,7 +829,7 @@ class BlockchainNode { } } - tryFinalizeChain(isGenesisStart = false) { + tryFinalizeChain(isGenesisStart = false, writeToDisk = true) { const LOG_HEADER = 'tryFinalizeChain'; const finalizableChain = this.bp.getFinalizableChain(isGenesisStart); if (!finalizableChain || !finalizableChain.length) { @@ -847,7 +847,7 @@ class BlockchainNode { if (blockToFinalize.number <= this.bc.lastBlockNumber()) { continue; } - if (this.bc.addBlockToChainAndWriteToDisk(blockToFinalize, true)) { + if (this.bc.addBlockToChainAndWriteToDisk(blockToFinalize, writeToDisk)) { lastFinalizedBlock = blockToFinalize; logger.debug(`[${LOG_HEADER}] Finalized a block of number ${blockToFinalize.number} and ` + `hash ${blockToFinalize.hash}`); From c6dde8d5a94844a8649f13a0385a66da26d3d28a Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Sat, 8 Jan 2022 21:13:03 +0900 Subject: [PATCH 07/21] Fix undefined variable error --- common/file-util.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/file-util.js b/common/file-util.js index 8921360a4..8abcbcc26 100644 --- a/common/file-util.js +++ b/common/file-util.js @@ -253,8 +253,8 @@ class FileUtil { static readH2nFile(chainPath, blockHash) { const LOG_HEADER = 'readH2nFile'; + const h2nPath = FileUtil.getH2nPath(chainPath, blockHash); try { - const h2nPath = FileUtil.getH2nPath(chainPath, blockHash); return Number(fs.readFileSync(h2nPath).toString()); } catch (err) { logger.error(`[${LOG_HEADER}] Error while reading ${h2nPath}: ${err}`); From db0d1b0827b773b8b05f28489c2ccd32df020980 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Sat, 8 Jan 2022 22:35:52 +0900 Subject: [PATCH 08/21] Kill jobs after file copy and ubuntu package install --- deploy_blockchain_genesis_gcp.sh | 80 ++++++++++++++++---------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/deploy_blockchain_genesis_gcp.sh b/deploy_blockchain_genesis_gcp.sh index 8f782654a..4190c10f7 100644 --- a/deploy_blockchain_genesis_gcp.sh +++ b/deploy_blockchain_genesis_gcp.sh @@ -188,46 +188,6 @@ NODE_7_ZONE="asia-southeast1-b" NODE_8_ZONE="us-central1-a" NODE_9_ZONE="europe-west4-a" -if [[ $KILL_OPTION = "--skip-kill" ]]; then - printf "\nSkipping process kill...\n" -else - # kill any processes still alive - printf "\nKilling all trackers and blockchain nodes...\n" - gcloud compute ssh $TRACKER_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $TRACKER_ZONE - gcloud compute ssh $NODE_0_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_0_ZONE - gcloud compute ssh $NODE_1_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_1_ZONE - gcloud compute ssh $NODE_2_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_2_ZONE - gcloud compute ssh $NODE_3_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_3_ZONE - gcloud compute ssh $NODE_4_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_4_ZONE - gcloud compute ssh $NODE_5_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_5_ZONE - gcloud compute ssh $NODE_6_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_6_ZONE - gcloud compute ssh $NODE_7_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_7_ZONE - gcloud compute ssh $NODE_8_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_8_ZONE - gcloud compute ssh $NODE_9_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_9_ZONE - - if [[ $NUM_SHARDS -gt 0 ]]; then - for i in $(seq $NUM_SHARDS) - do - printf "shard #$i\n" - - SHARD_TRACKER_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-tracker-taiwan" - SHARD_NODE_0_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-0-taiwan" - SHARD_NODE_1_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-1-oregon" - SHARD_NODE_2_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-2-singapore" - - gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $TRACKER_ZONE - gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_0_ZONE - gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_1_ZONE - gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_2_ZONE - done - fi -fi - -# If --kill-only, do not proceed any further -if [[ $KILL_OPTION = "--kill-only" ]]; then - exit -fi - # deploy files to GCP instances if [[ $KEEP_CODE_OPTION = "" ]]; then printf "\nDeploying parent blockchain...\n\n" @@ -281,6 +241,46 @@ if [[ $SETUP_OPTION = "--setup" ]]; then gcloud compute ssh $NODE_9_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_9_ZONE fi +if [[ $KILL_OPTION = "--skip-kill" ]]; then + printf "\nSkipping process kill...\n" +else + # kill any processes still alive + printf "\nKilling all trackers and blockchain nodes...\n" + gcloud compute ssh $TRACKER_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $TRACKER_ZONE + gcloud compute ssh $NODE_0_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_0_ZONE + gcloud compute ssh $NODE_1_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_1_ZONE + gcloud compute ssh $NODE_2_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_2_ZONE + gcloud compute ssh $NODE_3_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_3_ZONE + gcloud compute ssh $NODE_4_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_4_ZONE + gcloud compute ssh $NODE_5_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_5_ZONE + gcloud compute ssh $NODE_6_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_6_ZONE + gcloud compute ssh $NODE_7_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_7_ZONE + gcloud compute ssh $NODE_8_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_8_ZONE + gcloud compute ssh $NODE_9_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_9_ZONE + + if [[ $NUM_SHARDS -gt 0 ]]; then + for i in $(seq $NUM_SHARDS) + do + printf "shard #$i\n" + + SHARD_TRACKER_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-tracker-taiwan" + SHARD_NODE_0_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-0-taiwan" + SHARD_NODE_1_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-1-oregon" + SHARD_NODE_2_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-2-singapore" + + gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $TRACKER_ZONE + gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_0_ZONE + gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_1_ZONE + gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_2_ZONE + done + fi +fi + +# If --kill-only, do not proceed any further +if [[ $KILL_OPTION = "--kill-only" ]]; then + exit +fi + printf "\nStarting blockchain servers...\n\n" if [[ $KEEP_CODE_OPTION = "" ]]; then GO_TO_PROJECT_ROOT_CMD="cd ." From 929bc0540de668fd02ece5cc05fdbebe8d6bdd5f Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Sun, 9 Jan 2022 01:56:55 +0900 Subject: [PATCH 09/21] Set default values of deploy options --- deploy_blockchain_genesis_gcp.sh | 49 +++++++-------- deploy_blockchain_incremental_gcp.sh | 54 +++++++--------- deploy_blockchain_sandbox_gcp.sh | 16 +++-- start_node_genesis_gcp.sh | 70 ++++++++++----------- start_node_incremental_gcp.sh | 93 +++++++++++++++------------- start_tracker_genesis_gcp.sh | 6 +- start_tracker_incremental_gcp.sh | 8 ++- 7 files changed, 148 insertions(+), 148 deletions(-) diff --git a/deploy_blockchain_genesis_gcp.sh b/deploy_blockchain_genesis_gcp.sh index 4190c10f7..129d03149 100644 --- a/deploy_blockchain_genesis_gcp.sh +++ b/deploy_blockchain_genesis_gcp.sh @@ -1,8 +1,8 @@ #!/bin/bash if [[ $# -lt 3 ]] || [[ $# -gt 8 ]]; then - printf "Usage: bash deploy_blockchain_genesis_gcp.sh [dev|staging|sandbox|spring|summer|mainnet] <# of Shards> [--setup] [--keystore|--mnemonic|--private-key] [--keep-code] [--keep-data] [--kill-only|--skip-kill]\n" - printf "Example: bash deploy_blockchain_genesis_gcp.sh dev lia 0 --setup --keystore\n" + printf "Usage: bash deploy_blockchain_genesis_gcp.sh [dev|staging|sandbox|spring|summer|mainnet] <# of Shards> [--setup] [--keystore|--mnemonic|--private-key] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--full-sync|--fast-sync] [--kill-only|--skip-kill]\n" + printf "Example: bash deploy_blockchain_genesis_gcp.sh dev lia 0 --setup --keystore --no-keep-code\n" printf "\n" exit fi @@ -40,28 +40,24 @@ function parse_options() { local option="$1" if [[ $option = '--setup' ]]; then SETUP_OPTION="$option" + elif [[ $option = '--private-key' ]]; then + ACCOUNT_INJECTION_OPTION="$option" elif [[ $option = '--keystore' ]]; then - if [[ "$ACCOUNT_INJECTION_OPTION" ]]; then - printf "Multiple account injection options given\n" - exit - fi ACCOUNT_INJECTION_OPTION="$option" elif [[ $option = '--mnemonic' ]]; then - if [[ "$ACCOUNT_INJECTION_OPTION" ]]; then - printf "Multiple account injection options given\n" - exit - fi - ACCOUNT_INJECTION_OPTION="$option" - elif [[ $option = '--private-key' ]]; then - if [[ "$ACCOUNT_INJECTION_OPTION" ]]; then - printf "Multiple account injection options given\n" - exit - fi ACCOUNT_INJECTION_OPTION="$option" elif [[ $option = '--keep-code' ]]; then KEEP_CODE_OPTION="$option" + elif [[ $option = '--no-keep-code' ]]; then + KEEP_CODE_OPTION="$option" elif [[ $option = '--keep-data' ]]; then KEEP_DATA_OPTION="$option" + elif [[ $option = '--no-keep-data' ]]; then + KEEP_DATA_OPTION="$option" + elif [[ $option = '--full-sync' ]]; then + SYNC_MODE_OPTION="$option" + elif [[ $option = '--fast-sync' ]]; then + SYNC_MODE_OPTION="$option" elif [[ $option = '--kill-only' ]]; then if [[ "$KILL_OPTION" ]]; then printf "You cannot use both --skip-kill and --kill-only\n" @@ -82,9 +78,10 @@ function parse_options() { # Parse options. SETUP_OPTION="" -ACCOUNT_INJECTION_OPTION="" -KEEP_CODE_OPTION="" -KEEP_DATA_OPTION="" +ACCOUNT_INJECTION_OPTION="--private-key" +KEEP_CODE_OPTION="--keep-code" +KEEP_DATA_OPTION="--keep-data" +SYNC_MODE_OPTION="--fast-sync" KILL_OPTION="" ARG_INDEX=4 @@ -97,6 +94,7 @@ printf "SETUP_OPTION=$SETUP_OPTION\n" printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" +printf "SYNC_MODE_OPTION=$SYNC_MODE_OPTION\n" printf "KILL_OPTION=$KILL_OPTION\n" if [[ "$ACCOUNT_INJECTION_OPTION" = "" ]]; then @@ -189,7 +187,7 @@ NODE_8_ZONE="us-central1-a" NODE_9_ZONE="europe-west4-a" # deploy files to GCP instances -if [[ $KEEP_CODE_OPTION = "" ]]; then +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf "\nDeploying parent blockchain...\n\n" printf "\nDeploying files to parent tracker (${TRACKER_TARGET_ADDR})...\n\n" gcloud compute scp --recurse $FILES_FOR_TRACKER ${TRACKER_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $TRACKER_ZONE @@ -282,12 +280,12 @@ if [[ $KILL_OPTION = "--kill-only" ]]; then fi printf "\nStarting blockchain servers...\n\n" -if [[ $KEEP_CODE_OPTION = "" ]]; then +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then GO_TO_PROJECT_ROOT_CMD="cd ." else GO_TO_PROJECT_ROOT_CMD="cd \$(find /home/ain-blockchain* -maxdepth 0 -type d)" fi -if [[ $KEEP_DATA_OPTION = "" ]]; then +if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then # restart after removing chains, snapshots, and log files (but keep the keys) CHAINS_DIR=/home/ain_blockchain_data/chains SNAPSHOTS_DIR=/home/ain_blockchain_data/snapshots @@ -327,14 +325,15 @@ do NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR NODE_ZONE=NODE_${node_index}_ZONE + printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" - printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" + printf "SYNC_MODE_OPTION=$SYNC_MODE_OPTION\n" printf "JSON_RPC_OPTION=$JSON_RPC_OPTION\n" printf "REST_FUNC_OPTION=$REST_FUNC_OPTION\n" printf "\n" - START_NODE_CMD="gcloud compute ssh ${!NODE_TARGET_ADDR} --command '$START_NODE_CMD_BASE $SEASON 0 $node_index $KEEP_CODE_OPTION $KEEP_DATA_OPTION $ACCOUNT_INJECTION_OPTION $JSON_RPC_OPTION $REST_FUNC_OPTION' --project $PROJECT_ID --zone ${!NODE_ZONE}" + START_NODE_CMD="gcloud compute ssh ${!NODE_TARGET_ADDR} --command '$START_NODE_CMD_BASE $SEASON 0 $node_index $KEEP_CODE_OPTION $KEEP_DATA_OPTION $SYNC_MODE_OPTION $ACCOUNT_INJECTION_OPTION $JSON_RPC_OPTION $REST_FUNC_OPTION' --project $PROJECT_ID --zone ${!NODE_ZONE}" printf "START_NODE_CMD=$START_NODE_CMD\n" eval $START_NODE_CMD inject_account "$node_index" @@ -359,7 +358,7 @@ if [[ $NUM_SHARDS -gt 0 ]]; then SHARD_NODE_2_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-2-singapore" # deploy files to GCP instances - if [[ $KEEP_CODE_OPTION = "" ]]; then + if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf "\nDeploying files to shard_$i tracker (${SHARD_TRACKER_TARGET_ADDR})...\n\n" gcloud compute scp --recurse $FILES_FOR_TRACKER ${SHARD_TRACKER_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $TRACKER_ZONE printf "\nDeploying files to shard_$i node 0 (${SHARD_NODE_0_TARGET_ADDR})...\n\n" diff --git a/deploy_blockchain_incremental_gcp.sh b/deploy_blockchain_incremental_gcp.sh index c08081bbe..3de1ec60c 100644 --- a/deploy_blockchain_incremental_gcp.sh +++ b/deploy_blockchain_incremental_gcp.sh @@ -1,8 +1,8 @@ #!/bin/bash if [[ $# -lt 3 ]] || [[ $# -gt 9 ]]; then - printf "Usage: bash deploy_blockchain_incremental_gcp.sh [dev|staging|sandbox|spring|summer|mainnet] <# of Shards> [--setup] [--canary] [--full-sync] [--keystore|--mnemonic|--private-key] [--keep-code] [--keep-data]\n" - printf "Example: bash deploy_blockchain_incremental_gcp.sh dev lia 0 --setup --canary --full-sync --keystore\n" + printf "Usage: bash deploy_blockchain_incremental_gcp.sh [dev|staging|sandbox|spring|summer|mainnet] <# of Shards> [--setup] [--canary] [--keystore|--mnemonic|--private-key] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--full-sync|--fast-sync]\n" + printf "Example: bash deploy_blockchain_incremental_gcp.sh dev lia 0 --setup --canary --keystore --no-keep-code --full-sync\n" printf "\n" exit fi @@ -41,30 +41,24 @@ function parse_options() { SETUP_OPTION="$option" elif [[ $option = '--canary' ]]; then RUN_MODE_OPTION="$option" - elif [[ $option = '--full-sync' ]]; then - FULL_SYNC_OPTION="$option" + elif [[ $option = '--private-key' ]]; then + ACCOUNT_INJECTION_OPTION="$option" elif [[ $option = '--keystore' ]]; then - if [[ "$ACCOUNT_INJECTION_OPTION" ]]; then - printf "Multiple account injection options given\n" - exit - fi ACCOUNT_INJECTION_OPTION="$option" elif [[ $option = '--mnemonic' ]]; then - if [[ "$ACCOUNT_INJECTION_OPTION" ]]; then - printf "Multiple account injection options given\n" - exit - fi - ACCOUNT_INJECTION_OPTION="$option" - elif [[ $option = '--private-key' ]]; then - if [[ "$ACCOUNT_INJECTION_OPTION" ]]; then - printf "Multiple account injection options given\n" - exit - fi ACCOUNT_INJECTION_OPTION="$option" elif [[ $option = '--keep-code' ]]; then KEEP_CODE_OPTION="$option" + elif [[ $option = '--no-keep-code' ]]; then + KEEP_CODE_OPTION="$option" elif [[ $option = '--keep-data' ]]; then KEEP_DATA_OPTION="$option" + elif [[ $option = '--no-keep-data' ]]; then + KEEP_DATA_OPTION="$option" + elif [[ $option = '--full-sync' ]]; then + SYNC_MODE_OPTION="$option" + elif [[ $option = '--fast-sync' ]]; then + SYNC_MODE_OPTION="$option" else printf "Invalid option: $option\n" exit @@ -73,11 +67,11 @@ function parse_options() { # Parse options. SETUP_OPTION="" +ACCOUNT_INJECTION_OPTION="--private-key" +KEEP_CODE_OPTION="--keep-code" +KEEP_DATA_OPTION="--keep-data" +SYNC_MODE_OPTION="--fast-sync" RUN_MODE_OPTION="" -FULL_SYNC_OPTION="" -ACCOUNT_INJECTION_OPTION="" -KEEP_CODE_OPTION="" -KEEP_DATA_OPTION="" ARG_INDEX=4 while [ $ARG_INDEX -le $# ] @@ -88,10 +82,10 @@ done printf "SETUP_OPTION=$SETUP_OPTION\n" printf "RUN_MODE_OPTION=$RUN_MODE_OPTION\n" -printf "FULL_SYNC_OPTION=$FULL_SYNC_OPTION\n" printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" +printf "SYNC_MODE_OPTION=$SYNC_MODE_OPTION\n" if [[ "$ACCOUNT_INJECTION_OPTION" = "" ]]; then printf "Must provide an ACCOUNT_INJECTION_OPTION\n" @@ -152,7 +146,7 @@ function deploy_tracker() { printf "TRACKER_TARGET_ADDR='$TRACKER_TARGET_ADDR'\n" printf "TRACKER_ZONE='$TRACKER_ZONE'\n" - if [[ $KEEP_CODE_OPTION = "" ]]; then + if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then # 1. Copy files for tracker printf "\n\n[[[ Copying files for tracker ]]]\n\n" SCP_CMD="gcloud compute scp --recurse $FILES_FOR_TRACKER ${TRACKER_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $TRACKER_ZONE" @@ -190,7 +184,7 @@ function deploy_node() { printf "node_target_addr='$node_target_addr'\n" printf "node_zone='$node_zone'\n" - if [[ $KEEP_CODE_OPTION = "" ]]; then + if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then # 1. Copy files for node printf "\n\n<<< Copying files for node $node_index >>>\n\n" SCP_CMD="gcloud compute scp --recurse $FILES_FOR_NODE ${node_target_addr}:~/ --project $PROJECT_ID --zone $node_zone" @@ -217,15 +211,15 @@ function deploy_node() { REST_FUNC_OPTION="" fi + printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" - printf "FULL_SYNC_OPTION=$FULL_SYNC_OPTION\n" - printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" + printf "SYNC_MODE_OPTION=$SYNC_MODE_OPTION\n" printf "JSON_RPC_OPTION=$JSON_RPC_OPTION\n" printf "REST_FUNC_OPTION=$REST_FUNC_OPTION\n" printf "\n" - START_NODE_CMD="gcloud compute ssh $node_target_addr --command '$START_NODE_CMD_BASE $SEASON 0 $node_index $KEEP_CODE_OPTION $KEEP_DATA_OPTION $FULL_SYNC_OPTION $ACCOUNT_INJECTION_OPTION $JSON_RPC_OPTION $REST_FUNC_OPTION' --project $PROJECT_ID --zone $node_zone" + START_NODE_CMD="gcloud compute ssh $node_target_addr --command '$START_NODE_CMD_BASE $SEASON 0 $node_index $KEEP_CODE_OPTION $KEEP_DATA_OPTION $SYNC_MODE_OPTION $ACCOUNT_INJECTION_OPTION $JSON_RPC_OPTION $REST_FUNC_OPTION' --project $PROJECT_ID --zone $node_zone" printf "START_NODE_CMD=$START_NODE_CMD\n\n" eval $START_NODE_CMD @@ -285,12 +279,12 @@ NODE_TARGET_ADDR_LIST=( ) printf "\nStarting blockchain servers...\n\n" -if [[ $KEEP_CODE_OPTION = "" ]]; then +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then GO_TO_PROJECT_ROOT_CMD="cd ." else GO_TO_PROJECT_ROOT_CMD="cd \$(find /home/ain-blockchain* -maxdepth 0 -type d)" fi -if [[ $KEEP_DATA_OPTION = "" ]]; then +if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then # restart after removing chains, snapshots, and log files (but keep the keys) CHAINS_DIR=/home/ain_blockchain_data/chains SNAPSHOTS_DIR=/home/ain_blockchain_data/snapshots diff --git a/deploy_blockchain_sandbox_gcp.sh b/deploy_blockchain_sandbox_gcp.sh index d77752287..249473818 100644 --- a/deploy_blockchain_sandbox_gcp.sh +++ b/deploy_blockchain_sandbox_gcp.sh @@ -1,7 +1,7 @@ #!/bin/bash if [[ $# -lt 3 ]] || [[ $# -gt 7 ]]; then - printf "Usage: bash deploy_blockchain_sandbox_gcp.sh <# start node> <# end node> [--setup] [--keep-code] [--keep-data] [--kill-only|--skip-kill]\n" + printf "Usage: bash deploy_blockchain_sandbox_gcp.sh <# start node> <# end node> [--setup] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--kill-only|--skip-kill]\n" printf "Example: bash deploy_blockchain_sandbox_gcp.sh lia 10 99 --setup\n" printf "\n" exit @@ -33,8 +33,12 @@ function parse_options() { SETUP_OPTION="$option" elif [[ $option = '--keep-code' ]]; then KEEP_CODE_OPTION="$option" + elif [[ $option = '--no-keep-code' ]]; then + KEEP_CODE_OPTION="$option" elif [[ $option = '--keep-data' ]]; then KEEP_DATA_OPTION="$option" + elif [[ $option = '--no-keep-data' ]]; then + KEEP_DATA_OPTION="$option" elif [[ $option = '--kill-only' ]]; then if [[ "$KILL_OPTION" ]]; then printf "You cannot use both --skip-kill and --kill-only\n" @@ -55,8 +59,8 @@ function parse_options() { # Parse options. SETUP_OPTION="" -KEEP_CODE_OPTION="" -KEEP_DATA_OPTION="" +KEEP_CODE_OPTION="--no-keep-code" +KEEP_DATA_OPTION="--no-keep-data" KILL_OPTION="" ARG_INDEX=4 @@ -341,7 +345,7 @@ if [[ $KILL_OPTION = "--kill-only" ]]; then fi # deploy files to GCP instances -if [[ $KEEP_CODE_OPTION = "" ]]; then +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf "\nDeploying parent blockchain...\n" index=$START_NODE_IDX while [ $index -le $END_NODE_IDX ] @@ -387,12 +391,12 @@ if [[ $SETUP_OPTION = "--setup" ]]; then fi printf "\nStarting blockchain servers...\n\n" -if [[ $KEEP_CODE_OPTION = "" ]]; then +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then GO_TO_PROJECT_ROOT_CMD="cd ." else GO_TO_PROJECT_ROOT_CMD="cd \$(find /home/ain-blockchain* -maxdepth 0 -type d)" fi -if [[ $KEEP_DATA_OPTION = "" ]]; then +if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then # restart after removing chains, snapshots, and log files (but keep the keys) CHAINS_DIR=/home/ain_blockchain_data/chains SNAPSHOTS_DIR=/home/ain_blockchain_data/snapshots diff --git a/start_node_genesis_gcp.sh b/start_node_genesis_gcp.sh index fca2e5d26..14ac10529 100644 --- a/start_node_genesis_gcp.sh +++ b/start_node_genesis_gcp.sh @@ -2,8 +2,8 @@ # NOTE(minsulee2): Since exit really exits terminals, those are replaced to return 1. if [[ $# -lt 3 ]] || [[ $# -gt 9 ]]; then - printf "Usage: bash start_node_genesis_gcp.sh [dev|staging|sandbox|spring|summer|mainnet] [--keep-code] [--keep-data] [--full-sync] [--keystore|--mnemonic|--private-key] [--json-rpc] [--rest-func]\n" - printf "Example: bash start_node_genesis_gcp.sh spring 0 0 --keep-code --full-sync --keystore\n" + printf "Usage: bash start_node_genesis_gcp.sh [dev|staging|sandbox|spring|summer|mainnet] [--keystore|--mnemonic|--private-key] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--full-sync|--fast-sync] [--json-rpc] [--rest-func]\n" + printf "Example: bash start_node_genesis_gcp.sh spring 0 0 --keystore --no-keep-code --full-sync\n" printf "\n" return 1 fi @@ -11,30 +11,24 @@ printf "\n[[[[[ start_node_genesis_gcp.sh ]]]]]\n\n" function parse_options() { local option="$1" - if [[ $option = '--keep-code' ]]; then - KEEP_CODE_OPTION="$option" - elif [[ $option = '--keep-data' ]]; then - KEEP_DATA_OPTION="$option" - elif [[ $option = '--full-sync' ]]; then - FULL_SYNC_OPTION="$option" + if [[ $option = '--private-key' ]]; then + ACCOUNT_INJECTION_OPTION="private_key" elif [[ $option = '--keystore' ]]; then - if [[ "$ACCOUNT_INJECTION_OPTION" ]]; then - printf "Multiple account injection options given\n" - return 1 - fi ACCOUNT_INJECTION_OPTION="keystore" elif [[ $option = '--mnemonic' ]]; then - if [[ "$ACCOUNT_INJECTION_OPTION" ]]; then - printf "Multiple account injection options given\n" - return 1 - fi ACCOUNT_INJECTION_OPTION="mnemonic" - elif [[ $option = '--private-key' ]]; then - if [[ "$ACCOUNT_INJECTION_OPTION" ]]; then - printf "Multiple account injection options given\n" - return 1 - fi - ACCOUNT_INJECTION_OPTION="private_key" + elif [[ $option = '--keep-code' ]]; then + KEEP_CODE_OPTION="$option" + elif [[ $option = '--no-keep-code' ]]; then + KEEP_CODE_OPTION="$option" + elif [[ $option = '--keep-data' ]]; then + KEEP_DATA_OPTION="$option" + elif [[ $option = '--no-keep-data' ]]; then + KEEP_DATA_OPTION="$option" + elif [[ $option = '--full-sync' ]]; then + SYNC_MODE_OPTION="$option" + elif [[ $option = '--fast-sync' ]]; then + SYNC_MODE_OPTION="$option" elif [[ $option = '--json-rpc' ]]; then JSON_RPC_OPTION="$option" elif [[ $option = '--rest-func' ]]; then @@ -64,10 +58,10 @@ if [[ "$3" -lt 0 ]] || [[ "$3" -gt 100 ]]; then fi NODE_INDEX="$3" -KEEP_CODE_OPTION="" -KEEP_DATA_OPTION="" -FULL_SYNC_OPTION="" -ACCOUNT_INJECTION_OPTION="" +ACCOUNT_INJECTION_OPTION="--private-key" +KEEP_CODE_OPTION="--keep-code" +KEEP_DATA_OPTION="--keep-data" +SYNC_MODE_OPTION="--fast-sync" JSON_RPC_OPTION="" REST_FUNC_OPTION="" @@ -82,15 +76,15 @@ printf "SEASON=$SEASON\n" printf "SHARD_INDEX=$SHARD_INDEX\n" printf "NODE_INDEX=$NODE_INDEX\n" +printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" -printf "FULL_SYNC_OPTION=$FULL_SYNC_OPTION\n" -printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" +printf "SYNC_MODE_OPTION=$SYNC_MODE_OPTION\n" printf "JSON_RPC_OPTION=$JSON_RPC_OPTION\n" printf "REST_FUNC_OPTION=$REST_FUNC_OPTION\n" # NOTE(liayoo): Currently this script supports [--keystore|--mnemonic] option only for the parent chain. -if [[ $ACCOUNT_INJECTION_OPTION != "private_key" ]] && [[ "$SHARD_INDEX" -gt 0 ]]; then +if [[ $ACCOUNT_INJECTION_OPTION != "--private_key" ]] && [[ "$SHARD_INDEX" -gt 0 ]]; then printf 'Invalid account injection option\n' return 1 fi @@ -100,18 +94,18 @@ if [[ "$ACCOUNT_INJECTION_OPTION" = "" ]]; then return 1 fi +export ACCOUNT_INJECTION_OPTION="$ACCOUNT_INJECTION_OPTION" +if [[ $SYNC_MODE_OPTION = "--full-sync" ]]; then + export SYNC_MODE=full +else + export SYNC_MODE=fast +fi if [[ $SEASON = "staging" ]]; then # for performance test pipeline export ENABLE_EXPRESS_RATE_LIMIT=false else export ENABLE_EXPRESS_RATE_LIMIT=true fi -if [[ $FULL_SYNC_OPTION = "" ]]; then - export SYNC_MODE=fast -else - export SYNC_MODE=full -fi -export ACCOUNT_INJECTION_OPTION="$ACCOUNT_INJECTION_OPTION" if [[ $JSON_RPC_OPTION ]]; then export ENABLE_JSON_RPC_API=true else @@ -126,7 +120,7 @@ fi printf '\n' printf 'Killing old jobs..\n' sudo killall node -if [[ $KEEP_DATA_OPTION = "" ]]; then +if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then printf '\n' printf 'Removing old data..\n' sudo rm -rf /home/ain_blockchain_data/chains @@ -138,7 +132,7 @@ else sudo mkdir -p /home/ain_blockchain_data sudo chmod -R 777 /home/ain_blockchain_data fi -if [[ $KEEP_CODE_OPTION = "" ]]; then +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf '\n' printf 'Setting up working directory..\n' cd @@ -269,7 +263,7 @@ printf "PEER_WHITELIST=$PEER_WHITELIST\n" if [[ $ACCOUNT_INJECTION_OPTION = "keystore" ]]; then KEYSTORE_FILENAME="keystore_node_$NODE_INDEX.json" printf "KEYSTORE_FILENAME=$KEYSTORE_FILENAME\n" - if [[ $KEEP_CODE_OPTION = "" ]]; then + if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then sudo mkdir -p /home/ain_blockchain_data/keys/8080 sudo mv ./$KEYSTORE_DIR/$KEYSTORE_FILENAME /home/ain_blockchain_data/keys/8080/ fi diff --git a/start_node_incremental_gcp.sh b/start_node_incremental_gcp.sh index 11b5793ba..65c5936ed 100644 --- a/start_node_incremental_gcp.sh +++ b/start_node_incremental_gcp.sh @@ -1,8 +1,8 @@ #!/bin/bash if [[ $# -lt 3 ]] || [[ $# -gt 9 ]]; then - printf "Usage: bash start_node_incremental_gcp.sh [dev|staging|sandbox|spring|summer|mainnet] [--keep-code] [--keep-data] [--full-sync] [--keystore|--mnemonic|--private-key] [--json-rpc] [--rest-func]\n" - printf "Example: bash start_node_incremental_gcp.sh spring 0 0 --keep-code --full-sync --keystore\n" + printf "Usage: bash start_node_incremental_gcp.sh [dev|staging|sandbox|spring|summer|mainnet] [--keystore|--mnemonic|--private-key] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--full-sync|--fast-sync] [--json-rpc] [--rest-func]\n" + printf "Example: bash start_node_incremental_gcp.sh spring 0 0 --keystore --no-keep-code --full-sync\n" printf "\n" exit fi @@ -10,30 +10,24 @@ printf "\n[[[[[ start_node_incremental_gcp.sh ]]]]]\n\n" function parse_options() { local option="$1" - if [[ $option = '--keep-code' ]]; then - KEEP_CODE_OPTION="$option" - elif [[ $option = '--keep-data' ]]; then - KEEP_DATA_OPTION="$option" - elif [[ $option = '--full-sync' ]]; then - FULL_SYNC_OPTION="$option" + if [[ $option = '--private-key' ]]; then + ACCOUNT_INJECTION_OPTION="private_key" elif [[ $option = '--keystore' ]]; then - if [[ "$ACCOUNT_INJECTION_OPTION" ]]; then - printf "Multiple account injection options given\n" - exit - fi ACCOUNT_INJECTION_OPTION="keystore" elif [[ $option = '--mnemonic' ]]; then - if [[ "$ACCOUNT_INJECTION_OPTION" ]]; then - printf "Multiple account injection options given\n" - exit - fi ACCOUNT_INJECTION_OPTION="mnemonic" - elif [[ $option = '--private-key' ]]; then - if [[ "$ACCOUNT_INJECTION_OPTION" ]]; then - printf "Multiple account injection options given\n" - return 1 - fi - ACCOUNT_INJECTION_OPTION="private_key" + elif [[ $option = '--keep-code' ]]; then + KEEP_CODE_OPTION="$option" + elif [[ $option = '--no-keep-code' ]]; then + KEEP_CODE_OPTION="$option" + elif [[ $option = '--keep-data' ]]; then + KEEP_DATA_OPTION="$option" + elif [[ $option = '--no-keep-data' ]]; then + KEEP_DATA_OPTION="$option" + elif [[ $option = '--full-sync' ]]; then + SYNC_MODE_OPTION="$option" + elif [[ $option = '--fast-sync' ]]; then + SYNC_MODE_OPTION="$option" elif [[ $option = '--rest-func' ]]; then REST_FUNC_OPTION="$option" elif [[ $option = '--json-rpc' ]]; then @@ -62,10 +56,10 @@ if [[ "$3" -lt 0 ]] || [[ "$3" -gt 9 ]]; then fi NODE_INDEX="$3" -KEEP_CODE_OPTION="" -KEEP_DATA_OPTION="" -FULL_SYNC_OPTION="" -ACCOUNT_INJECTION_OPTION="" +ACCOUNT_INJECTION_OPTION="--private-key" +KEEP_CODE_OPTION="--keep-code" +KEEP_DATA_OPTION="--keep-data" +SYNC_MODE_OPTION="--fast-sync" JSON_RPC_OPTION="" REST_FUNC_OPTION="" @@ -80,10 +74,10 @@ printf "SEASON=$SEASON\n" printf "SHARD_INDEX=$SHARD_INDEX\n" printf "NODE_INDEX=$NODE_INDEX\n" +printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" -printf "FULL_SYNC_OPTION=$FULL_SYNC_OPTION\n" -printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" +printf "SYNC_MODE_OPTION=$SYNC_MODE_OPTION\n" printf "JSON_RPC_OPTION=$JSON_RPC_OPTION\n" printf "REST_FUNC_OPTION=$REST_FUNC_OPTION\n" @@ -220,27 +214,38 @@ printf "KEYSTORE_DIR=$KEYSTORE_DIR\n" printf "PEER_CANDIDATE_JSON_RPC_URL=$PEER_CANDIDATE_JSON_RPC_URL\n" printf "PEER_WHITELIST=$PEER_WHITELIST\n" -if [[ $SEASON = "staging" ]]; then - # for performance test pipeline - export ENABLE_EXPRESS_RATE_LIMIT=false +# NOTE(liayoo): Currently this script supports [--keystore|--mnemonic] option only for the parent chain. +if [[ $ACCOUNT_INJECTION_OPTION != "--private_key" ]] && [[ "$SHARD_INDEX" -gt 0 ]]; then + printf 'Invalid account injection option\n' + return 1 +fi + +if [[ "$ACCOUNT_INJECTION_OPTION" = "" ]]; then + printf "Must provide an ACCOUNT_INJECTION_OPTION\n" + return 1 +fi + +export ACCOUNT_INJECTION_OPTION="$ACCOUNT_INJECTION_OPTION" +if [[ $SYNC_MODE_OPTION = "--full-sync" ]]; then + export SYNC_MODE=full else - export ENABLE_EXPRESS_RATE_LIMIT=true + export SYNC_MODE=fast fi -if [[ $FULL_SYNC_OPTION = "" ]]; then - export SYNC_MODE=fast +if [[ $SEASON = "staging" ]]; then + # for performance test pipeline + export ENABLE_EXPRESS_RATE_LIMIT=false else - export SYNC_MODE=full + export ENABLE_EXPRESS_RATE_LIMIT=true fi -export ACCOUNT_INJECTION_OPTION="$ACCOUNT_INJECTION_OPTION" if [[ $JSON_RPC_OPTION ]]; then - export ENABLE_JSON_RPC_API=true + export ENABLE_JSON_RPC_API=true else - export ENABLE_JSON_RPC_API=false + export ENABLE_JSON_RPC_API=false fi if [[ $REST_FUNC_OPTION ]]; then - export ENABLE_REST_FUNCTION_CALL=true + export ENABLE_REST_FUNCTION_CALL=true else - export ENABLE_REST_FUNCTION_CALL=false + export ENABLE_REST_FUNCTION_CALL=false fi # NOTE(liayoo): Currently this script supports [--keystore|--mnemonic] option only for the parent chain. @@ -262,7 +267,7 @@ printf "NEW_DIR_PATH=$NEW_DIR_PATH\n" # 3. Set up working directory & install modules printf "\n#### [Step 3] Set up working directory & install modules ####\n\n" -if [[ $KEEP_DATA_OPTION = "" ]]; then +if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then printf '\n' printf 'Removing old data..\n' sudo rm -rf /home/ain_blockchain_data/chains @@ -274,7 +279,7 @@ else sudo mkdir -p /home/ain_blockchain_data sudo chmod -R 777 /home/ain_blockchain_data fi -if [[ $KEEP_CODE_OPTION = "" ]]; then +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf '\n' printf 'Creating new working directory..\n' MKDIR_CMD="sudo mkdir $NEW_DIR_PATH" @@ -304,7 +309,7 @@ sleep 10 # 5. Remove old working directory keeping the chain data printf "\n#### [Step 5] Remove old working directory keeping the chain data if necessary ####\n\n" -if [[ $KEEP_CODE_OPTION = "" ]]; then +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf '\n' printf 'Removing old working directory..\n' RM_CMD="sudo rm -rf $OLD_DIR_PATH" @@ -321,7 +326,7 @@ printf "\n#### [Step 6] Start new node server ####\n\n" if [[ $ACCOUNT_INJECTION_OPTION = "keystore" ]]; then KEYSTORE_FILENAME="keystore_node_$NODE_INDEX.json" printf "KEYSTORE_FILENAME=$KEYSTORE_FILENAME\n" - if [[ $KEEP_CODE_OPTION = "" ]]; then + if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then sudo mkdir -p /home/ain_blockchain_data/keys/8080 sudo mv $NEW_DIR_PATH/$KEYSTORE_DIR/$KEYSTORE_FILENAME /home/ain_blockchain_data/keys/8080/ fi diff --git a/start_tracker_genesis_gcp.sh b/start_tracker_genesis_gcp.sh index a4d06b52f..8788232ec 100644 --- a/start_tracker_genesis_gcp.sh +++ b/start_tracker_genesis_gcp.sh @@ -1,7 +1,7 @@ #!/bin/bash if [[ $# -gt 1 ]]; then - printf "Usage: bash start_tracker_genesis_gcp.sh [--keep-code]\n" + printf "Usage: bash start_tracker_genesis_gcp.sh [--keep-code|--no-keep-code]\n" printf "Example: bash start_tracker_genesis_gcp.sh --keep-code\n" printf "\n" exit @@ -13,6 +13,8 @@ KEEP_CODE_OPTION="" if [[ $# = 1 ]]; then if [[ $1 = '--keep-code' ]]; then KEEP_CODE_OPTION=$1 + elif [[ $1 = '--no-keep-code' ]]; then + KEEP_CODE_OPTION=$1 else printf "Invalid option: $1\n" exit @@ -26,7 +28,7 @@ printf 'Killing jobs..\n' killall node -if [[ $KEEP_CODE_OPTION = "" ]]; then +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf '\n' printf 'Creating new working directory..\n' cd diff --git a/start_tracker_incremental_gcp.sh b/start_tracker_incremental_gcp.sh index dad2c5810..ad563087f 100644 --- a/start_tracker_incremental_gcp.sh +++ b/start_tracker_incremental_gcp.sh @@ -1,7 +1,7 @@ #!/bin/bash if [[ "$#" -lt 1 ]] || [[ "$#" -gt 2 ]]; then - printf "Usage: bash start_tracker_incremental_gcp.sh [--keep-code]\n" + printf "Usage: bash start_tracker_incremental_gcp.sh [--keep-code|--no-keep-code]\n" printf "Example: bash start_tracker_incremental_gcp.sh 5 --keep-code\n" printf "\n" exit @@ -17,6 +17,8 @@ KEEP_CODE_OPTION="" if [[ $# = 2 ]]; then if [[ $2 = '--keep-code' ]]; then KEEP_CODE_OPTION=$2 + elif [[ $2 = '--no-keep-code' ]]; then + KEEP_CODE_OPTION=$2 else printf "Invalid option: $2\n" exit @@ -39,7 +41,7 @@ printf "NEW_DIR_PATH=$NEW_DIR_PATH\n" # 3. Set up working directory & install modules printf "\n#### [Step 3] Set up working directory & install modules ####\n\n" -if [[ $KEEP_CODE_OPTION = "" ]]; then +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf '\n' printf 'Creating new working directory..\n' MKDIR_CMD="sudo mkdir $NEW_DIR_PATH" @@ -69,7 +71,7 @@ sleep 10 # 5. Remove old working directory keeping the chain data printf "\n#### [Step 5] Remove old working directory keeping the chain data ####\n\n" -if [[ $KEEP_CODE_OPTION = "" ]]; then +if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf '\n' printf 'Removing old working directory..\n' RM_CMD="sudo rm -rf $OLD_DIR_PATH" From c9f287d9dc924b3a076d7a43581838cedfb05073 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Sun, 9 Jan 2022 02:59:50 +0900 Subject: [PATCH 10/21] Add BEGIN_PARENT_NODE_INDEX option to incremeental deploy script --- deploy_blockchain_genesis_gcp.sh | 1 + deploy_blockchain_incremental_gcp.sh | 19 ++++++++++++------- start_node_genesis_gcp.sh | 1 + start_node_incremental_gcp.sh | 1 + start_tracker_genesis_gcp.sh | 2 +- start_tracker_incremental_gcp.sh | 2 +- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/deploy_blockchain_genesis_gcp.sh b/deploy_blockchain_genesis_gcp.sh index 129d03149..8545fe4ad 100644 --- a/deploy_blockchain_genesis_gcp.sh +++ b/deploy_blockchain_genesis_gcp.sh @@ -34,6 +34,7 @@ if ! [[ $3 =~ $number_re ]] ; then fi NUM_SHARDS=$3 printf "NUM_SHARDS=$NUM_SHARDS\n" +printf "\n" function parse_options() { diff --git a/deploy_blockchain_incremental_gcp.sh b/deploy_blockchain_incremental_gcp.sh index 3de1ec60c..6f93bb5e0 100644 --- a/deploy_blockchain_incremental_gcp.sh +++ b/deploy_blockchain_incremental_gcp.sh @@ -1,7 +1,7 @@ #!/bin/bash -if [[ $# -lt 3 ]] || [[ $# -gt 9 ]]; then - printf "Usage: bash deploy_blockchain_incremental_gcp.sh [dev|staging|sandbox|spring|summer|mainnet] <# of Shards> [--setup] [--canary] [--keystore|--mnemonic|--private-key] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--full-sync|--fast-sync]\n" +if [[ $# -lt 4 ]] || [[ $# -gt 10 ]]; then + printf "Usage: bash deploy_blockchain_incremental_gcp.sh [dev|staging|sandbox|spring|summer|mainnet] <# of Shards> [--setup] [--canary] [--keystore|--mnemonic|--private-key] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--full-sync|--fast-sync]\n" printf "Example: bash deploy_blockchain_incremental_gcp.sh dev lia 0 --setup --canary --keystore --no-keep-code --full-sync\n" printf "\n" exit @@ -24,16 +24,19 @@ fi printf "SEASON=$SEASON\n" printf "PROJECT_ID=$PROJECT_ID\n" -printf "GCP_USER=$GCP_USER\n" GCP_USER="$2" +printf "GCP_USER=$GCP_USER\n" number_re='^[0-9]+$' if ! [[ $3 =~ $number_re ]] ; then printf "Invalid <# of Shards> argument: $3\n" exit fi -printf "NUM_SHARDS=$NUM_SHARDS\n" NUM_SHARDS=$3 +printf "NUM_SHARDS=$NUM_SHARDS\n" +BEGIN_PARENT_NODE_INDEX=$4 +printf "BEGIN_PARENT_NODE_INDEX=$BEGIN_PARENT_NODE_INDEX\n" +printf "\n" function parse_options() { local option="$1" @@ -73,7 +76,7 @@ KEEP_DATA_OPTION="--keep-data" SYNC_MODE_OPTION="--fast-sync" RUN_MODE_OPTION="" -ARG_INDEX=4 +ARG_INDEX=5 while [ $ARG_INDEX -le $# ] do parse_options "${!ARG_INDEX}" @@ -300,8 +303,10 @@ fi if [[ $RUN_MODE_OPTION = "--canary" ]]; then deploy_node "0" else - deploy_tracker "$NUM_PARENT_NODES" - for j in `seq 0 $(( ${NUM_PARENT_NODES} - 1 ))` + if [[ $BEGIN_PARENT_NODE_INDEX = 0 ]]; then + deploy_tracker "$NUM_PARENT_NODES" + fi + for j in `seq $BEGIN_PARENT_NODE_INDEX $(( ${NUM_PARENT_NODES} - 1 ))` do deploy_node "$j" sleep 40 diff --git a/start_node_genesis_gcp.sh b/start_node_genesis_gcp.sh index 14ac10529..c38bffb79 100644 --- a/start_node_genesis_gcp.sh +++ b/start_node_genesis_gcp.sh @@ -75,6 +75,7 @@ done printf "SEASON=$SEASON\n" printf "SHARD_INDEX=$SHARD_INDEX\n" printf "NODE_INDEX=$NODE_INDEX\n" +printf "\n" printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" diff --git a/start_node_incremental_gcp.sh b/start_node_incremental_gcp.sh index 65c5936ed..79f6ea451 100644 --- a/start_node_incremental_gcp.sh +++ b/start_node_incremental_gcp.sh @@ -73,6 +73,7 @@ done printf "SEASON=$SEASON\n" printf "SHARD_INDEX=$SHARD_INDEX\n" printf "NODE_INDEX=$NODE_INDEX\n" +printf "\n" printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" diff --git a/start_tracker_genesis_gcp.sh b/start_tracker_genesis_gcp.sh index 8788232ec..e7794fa6e 100644 --- a/start_tracker_genesis_gcp.sh +++ b/start_tracker_genesis_gcp.sh @@ -8,7 +8,7 @@ if [[ $# -gt 1 ]]; then fi printf "\n[[[[[ start_tracker_genesis_gcp.sh ]]]]]\n\n" -KEEP_CODE_OPTION="" +KEEP_CODE_OPTION="--keep-code" if [[ $# = 1 ]]; then if [[ $1 = '--keep-code' ]]; then diff --git a/start_tracker_incremental_gcp.sh b/start_tracker_incremental_gcp.sh index ad563087f..0a4f83000 100644 --- a/start_tracker_incremental_gcp.sh +++ b/start_tracker_incremental_gcp.sh @@ -12,7 +12,7 @@ printf "\n[[[[[ start_tracker_incremental_gcp.sh ]]]]]\n\n" printf "\n#### [Step 1] Configure env vars ####\n\n" NUM_NODES="$1" -KEEP_CODE_OPTION="" +KEEP_CODE_OPTION="--keep-code" if [[ $# = 2 ]]; then if [[ $2 = '--keep-code' ]]; then From ee587cecb28e1f0ea33870c76853155ac3e77a1d Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Sun, 9 Jan 2022 05:32:57 +0900 Subject: [PATCH 11/21] Replace --canary with BEGIN_PARENT_NODE_INDEX and END_PARENT_NODE_INDEX --- deploy_blockchain_incremental_gcp.sh | 56 +++++++++++----------------- start_node_incremental_gcp.sh | 39 ++++++++++--------- start_tracker_incremental_gcp.sh | 24 ++++++------ 3 files changed, 55 insertions(+), 64 deletions(-) diff --git a/deploy_blockchain_incremental_gcp.sh b/deploy_blockchain_incremental_gcp.sh index 6f93bb5e0..fe75e7868 100644 --- a/deploy_blockchain_incremental_gcp.sh +++ b/deploy_blockchain_incremental_gcp.sh @@ -1,8 +1,8 @@ #!/bin/bash -if [[ $# -lt 4 ]] || [[ $# -gt 10 ]]; then - printf "Usage: bash deploy_blockchain_incremental_gcp.sh [dev|staging|sandbox|spring|summer|mainnet] <# of Shards> [--setup] [--canary] [--keystore|--mnemonic|--private-key] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--full-sync|--fast-sync]\n" - printf "Example: bash deploy_blockchain_incremental_gcp.sh dev lia 0 --setup --canary --keystore --no-keep-code --full-sync\n" +if [[ $# -lt 5 ]] || [[ $# -gt 11 ]]; then + printf "Usage: bash deploy_blockchain_incremental_gcp.sh [dev|staging|sandbox|spring|summer|mainnet] <# of Shards> [--setup] [--keystore|--mnemonic|--private-key] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--full-sync|--fast-sync]\n" + printf "Example: bash deploy_blockchain_incremental_gcp.sh dev lia 0 0 1 --setup --keystore --no-keep-code --full-sync\n" printf "\n" exit fi @@ -36,14 +36,14 @@ NUM_SHARDS=$3 printf "NUM_SHARDS=$NUM_SHARDS\n" BEGIN_PARENT_NODE_INDEX=$4 printf "BEGIN_PARENT_NODE_INDEX=$BEGIN_PARENT_NODE_INDEX\n" +END_PARENT_NODE_INDEX=$5 +printf "END_PARENT_NODE_INDEX=$END_PARENT_NODE_INDEX\n" printf "\n" function parse_options() { local option="$1" if [[ $option = '--setup' ]]; then SETUP_OPTION="$option" - elif [[ $option = '--canary' ]]; then - RUN_MODE_OPTION="$option" elif [[ $option = '--private-key' ]]; then ACCOUNT_INJECTION_OPTION="$option" elif [[ $option = '--keystore' ]]; then @@ -74,9 +74,8 @@ ACCOUNT_INJECTION_OPTION="--private-key" KEEP_CODE_OPTION="--keep-code" KEEP_DATA_OPTION="--keep-data" SYNC_MODE_OPTION="--fast-sync" -RUN_MODE_OPTION="" -ARG_INDEX=5 +ARG_INDEX=6 while [ $ARG_INDEX -le $# ] do parse_options "${!ARG_INDEX}" @@ -84,7 +83,6 @@ do done printf "SETUP_OPTION=$SETUP_OPTION\n" -printf "RUN_MODE_OPTION=$RUN_MODE_OPTION\n" printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" @@ -124,7 +122,6 @@ fi FILES_FOR_TRACKER="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ logger/ tracker-server/ traffic/ package.json setup_blockchain_ubuntu.sh start_tracker_genesis_gcp.sh start_tracker_incremental_gcp.sh" FILES_FOR_NODE="blockchain/ blockchain-configs/ block-pool/ client/ common/ consensus/ db/ event-handler/ json_rpc/ logger/ node/ p2p/ tools/ traffic/ tx-pool/ $KEYSTORE_DIR package.json setup_blockchain_ubuntu.sh start_node_genesis_gcp.sh start_node_incremental_gcp.sh wait_until_node_sync_gcp.sh" -NUM_PARENT_NODES=10 NUM_SHARD_NODES=3 TRACKER_ZONE="asia-east1-b" @@ -142,8 +139,6 @@ NODE_ZONE_LIST=( ) function deploy_tracker() { - local num_nodes="$1" - printf "\n* >> Deploying tracker ********************************************************\n\n" printf "TRACKER_TARGET_ADDR='$TRACKER_TARGET_ADDR'\n" @@ -172,7 +167,7 @@ function deploy_tracker() { printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" printf "\n" - START_TRACKER_CMD="gcloud compute ssh $TRACKER_TARGET_ADDR --command '$START_TRACKER_CMD_BASE $num_nodes $KEEP_CODE_OPTION' --project $PROJECT_ID --zone $TRACKER_ZONE" + START_TRACKER_CMD="gcloud compute ssh $TRACKER_TARGET_ADDR --command '$START_TRACKER_CMD_BASE $KEEP_CODE_OPTION' --project $PROJECT_ID --zone $TRACKER_ZONE" printf "START_TRACKER_CMD=$START_TRACKER_CMD\n\n" eval $START_TRACKER_CMD } @@ -226,7 +221,7 @@ function deploy_node() { printf "START_NODE_CMD=$START_NODE_CMD\n\n" eval $START_NODE_CMD - # 4. Init account if necessary (if --keystore specified) + # 4. Inject node account if [[ $ACCOUNT_INJECTION_OPTION = "--keystore" ]]; then local node_ip_addr=${IP_ADDR_LIST[${node_index}]} printf "\n* >> Initializing account for node $node_index ********************\n\n" @@ -256,7 +251,7 @@ function deploy_node() { echo $PRIVATE_KEY | node inject_account_gcp.js $node_ip_addr $ACCOUNT_INJECTION_OPTION fi - #5. Wait until node is synced + # 5. Wait until node is synced printf "\n\n<<< Waiting until node $node_index is synced >>>\n\n" WAIT_CMD="gcloud compute ssh $node_target_addr --command 'cd \$(find /home/ain-blockchain* -maxdepth 0 -type d); . wait_until_node_sync_gcp.sh' --project $PROJECT_ID --zone $node_zone" printf "WAIT_CMD=$WAIT_CMD\n\n" @@ -300,18 +295,15 @@ else START_NODE_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_node_incremental_gcp.sh" fi -if [[ $RUN_MODE_OPTION = "--canary" ]]; then - deploy_node "0" -else - if [[ $BEGIN_PARENT_NODE_INDEX = 0 ]]; then - deploy_tracker "$NUM_PARENT_NODES" - fi - for j in `seq $BEGIN_PARENT_NODE_INDEX $(( ${NUM_PARENT_NODES} - 1 ))` - do - deploy_node "$j" - sleep 40 - done +# Tracker server is deployed with node 0 +if [[ $BEGIN_PARENT_NODE_INDEX = 0 ]]; then + deploy_tracker fi +for j in `seq $BEGIN_PARENT_NODE_INDEX $(( $END_PARENT_NODE_INDEX - 1 ))` + do + deploy_node "$j" + sleep 40 + done if [[ $NUM_SHARDS -gt 0 ]]; then for i in $(seq $NUM_SHARDS) @@ -326,14 +318,10 @@ if [[ $NUM_SHARDS -gt 0 ]]; then "${GCP_USER}@${SEASON}-shard-${i}-node-1-oregon" \ "${GCP_USER}@${SEASON}-shard-${i}-node-2-singapore") - if [[ $RUN_MODE_OPTION = "--canary" ]]; then - deploy_node "0" - else - deploy_tracker "$NUM_SHARD_NODES" - for j in `seq 0 $(( ${NUM_SHARD_NODES} - 1 ))` - do - deploy_node "$j" - done - fi + deploy_tracker "$NUM_SHARD_NODES" + for j in `seq 0 $(( ${NUM_SHARD_NODES} - 1 ))` + do + deploy_node "$j" + done done fi diff --git a/start_node_incremental_gcp.sh b/start_node_incremental_gcp.sh index 79f6ea451..7b7789c18 100644 --- a/start_node_incremental_gcp.sh +++ b/start_node_incremental_gcp.sh @@ -268,18 +268,6 @@ printf "NEW_DIR_PATH=$NEW_DIR_PATH\n" # 3. Set up working directory & install modules printf "\n#### [Step 3] Set up working directory & install modules ####\n\n" -if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then - printf '\n' - printf 'Removing old data..\n' - sudo rm -rf /home/ain_blockchain_data/chains - sudo rm -rf /home/ain_blockchain_data/snapshots - sudo rm -rf /home/ain_blockchain_data/logs - sudo mkdir -p /home/ain_blockchain_data - sudo chmod -R 777 /home/ain_blockchain_data -else - sudo mkdir -p /home/ain_blockchain_data - sudo chmod -R 777 /home/ain_blockchain_data -fi if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf '\n' printf 'Creating new working directory..\n' @@ -308,8 +296,25 @@ printf "KILL_CMD=$KILL_CMD\n\n" eval $KILL_CMD sleep 10 -# 5. Remove old working directory keeping the chain data -printf "\n#### [Step 5] Remove old working directory keeping the chain data if necessary ####\n\n" +# 5. Set up data directory +printf "\n#### [Step 5] Set up data directory ####\n\n" +if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then + printf '\n' + printf 'Removing old data..\n' + sudo rm -rf /home/ain_blockchain_data/chains + sudo rm -rf /home/ain_blockchain_data/snapshots + sudo rm -rf /home/ain_blockchain_data/logs + sudo mkdir -p /home/ain_blockchain_data + sudo chmod -R 777 /home/ain_blockchain_data +else + printf '\n' + printf 'Keeping existing data..\n' + sudo mkdir -p /home/ain_blockchain_data + sudo chmod -R 777 /home/ain_blockchain_data +fi + +# 6. Remove old working directory keeping the chain data +printf "\n#### [Step 6] Remove old working directory if necessary ####\n\n" if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf '\n' printf 'Removing old working directory..\n' @@ -318,11 +323,11 @@ if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then eval $RM_CMD else printf '\n' - printf 'Keeping old working directory..\n' + printf 'Keeping existing working directory..\n' fi -# 6. Start a new node server -printf "\n#### [Step 6] Start new node server ####\n\n" +# 7. Start a new node server +printf "\n#### [Step 7] Start new node server ####\n\n" if [[ $ACCOUNT_INJECTION_OPTION = "keystore" ]]; then KEYSTORE_FILENAME="keystore_node_$NODE_INDEX.json" diff --git a/start_tracker_incremental_gcp.sh b/start_tracker_incremental_gcp.sh index 0a4f83000..16db6bc5d 100644 --- a/start_tracker_incremental_gcp.sh +++ b/start_tracker_incremental_gcp.sh @@ -1,8 +1,8 @@ #!/bin/bash -if [[ "$#" -lt 1 ]] || [[ "$#" -gt 2 ]]; then - printf "Usage: bash start_tracker_incremental_gcp.sh [--keep-code|--no-keep-code]\n" - printf "Example: bash start_tracker_incremental_gcp.sh 5 --keep-code\n" +if [[ "$#" -gt 1 ]]; then + printf "Usage: bash start_tracker_incremental_gcp.sh [--keep-code|--no-keep-code]\n" + printf "Example: bash start_tracker_incremental_gcp.sh --keep-code\n" printf "\n" exit fi @@ -11,21 +11,19 @@ printf "\n[[[[[ start_tracker_incremental_gcp.sh ]]]]]\n\n" # 1. Configure env vars printf "\n#### [Step 1] Configure env vars ####\n\n" -NUM_NODES="$1" KEEP_CODE_OPTION="--keep-code" -if [[ $# = 2 ]]; then - if [[ $2 = '--keep-code' ]]; then - KEEP_CODE_OPTION=$2 - elif [[ $2 = '--no-keep-code' ]]; then - KEEP_CODE_OPTION=$2 +if [[ $# = 1 ]]; then + if [[ $1 = '--keep-code' ]]; then + KEEP_CODE_OPTION=$1 + elif [[ $1 = '--no-keep-code' ]]; then + KEEP_CODE_OPTION=$1 else - printf "Invalid option: $2\n" + printf "Invalid option: $1\n" exit fi fi -printf "NUM_NODES=$NUM_NODES\n" printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" # 2. Get currently used directory & new directory @@ -69,8 +67,8 @@ printf "KILL_CMD=$KILL_CMD\n\n" eval $KILL_CMD sleep 10 -# 5. Remove old working directory keeping the chain data -printf "\n#### [Step 5] Remove old working directory keeping the chain data ####\n\n" +# 5. Remove old working directory +printf "\n#### [Step 5] Remove old working directory ####\n\n" if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf '\n' printf 'Removing old working directory..\n' From 3a202fc0bc546c63ec195fe5c598cae0d64b383f Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Sun, 9 Jan 2022 17:19:34 +0900 Subject: [PATCH 12/21] Use ~/ain-blockchain instead of ~ directory for deployment --- deploy_blockchain_genesis_gcp.sh | 39 +++++++++++++------- deploy_blockchain_incremental_gcp.sh | 8 +++-- start_node_genesis_gcp.sh | 53 +++++++++++++++------------- start_node_incremental_gcp.sh | 42 ++++++++++++---------- start_tracker_genesis_gcp.sh | 25 +++++++------ start_tracker_incremental_gcp.sh | 27 +++++++------- 6 files changed, 112 insertions(+), 82 deletions(-) diff --git a/deploy_blockchain_genesis_gcp.sh b/deploy_blockchain_genesis_gcp.sh index 8545fe4ad..9bc108c76 100644 --- a/deploy_blockchain_genesis_gcp.sh +++ b/deploy_blockchain_genesis_gcp.sh @@ -191,27 +191,38 @@ NODE_9_ZONE="europe-west4-a" if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf "\nDeploying parent blockchain...\n\n" printf "\nDeploying files to parent tracker (${TRACKER_TARGET_ADDR})...\n\n" - gcloud compute scp --recurse $FILES_FOR_TRACKER ${TRACKER_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $TRACKER_ZONE + gcloud compute ssh $TRACKER_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $TRACKER_ZONE + gcloud compute scp --recurse $FILES_FOR_TRACKER ${TRACKER_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $TRACKER_ZONE printf "\nDeploying files to parent node 0 (${NODE_0_TARGET_ADDR})...\n\n" - gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_0_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_0_ZONE + gcloud compute ssh $NODE_0_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_0_ZONE + gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_0_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $NODE_0_ZONE printf "\nDeploying files to parent node 1 (${NODE_1_TARGET_ADDR})...\n\n" - gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_1_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_1_ZONE + gcloud compute ssh $NODE_1_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_1_ZONE + gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_1_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $NODE_1_ZONE printf "\nDeploying files to parent node 2 (${NODE_2_TARGET_ADDR})...\n\n" - gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_2_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_2_ZONE + gcloud compute ssh $NODE_2_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_2_ZONE + gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_2_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $NODE_2_ZONE printf "\nDeploying files to parent node 3 (${NODE_3_TARGET_ADDR})...\n\n" - gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_3_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_3_ZONE + gcloud compute ssh $NODE_3_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_3_ZONE + gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_3_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $NODE_3_ZONE printf "\nDeploying files to parent node 4 (${NODE_4_TARGET_ADDR})...\n\n" - gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_4_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_4_ZONE + gcloud compute ssh $NODE_4_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_4_ZONE + gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_4_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $NODE_4_ZONE printf "\nDeploying files to parent node 5 (${NODE_5_TARGET_ADDR})...\n\n" - gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_5_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_5_ZONE + gcloud compute ssh $NODE_5_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_5_ZONE + gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_5_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $NODE_5_ZONE printf "\nDeploying files to parent node 6 (${NODE_6_TARGET_ADDR})...\n\n" - gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_6_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_6_ZONE + gcloud compute ssh $NODE_6_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_6_ZONE + gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_6_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $NODE_6_ZONE printf "\nDeploying files to parent node 7 (${NODE_7_TARGET_ADDR})...\n\n" - gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_7_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_7_ZONE + gcloud compute ssh $NODE_7_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_7_ZONE + gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_7_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $NODE_7_ZONE printf "\nDeploying files to parent node 8 (${NODE_8_TARGET_ADDR})...\n\n" - gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_8_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_8_ZONE + gcloud compute ssh $NODE_8_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_8_ZONE + gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_8_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $NODE_8_ZONE printf "\nDeploying files to parent node 9 (${NODE_9_TARGET_ADDR})...\n\n" - gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_9_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_9_ZONE + gcloud compute ssh $NODE_9_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_9_ZONE + gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_9_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $NODE_9_ZONE fi # ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) @@ -282,7 +293,7 @@ fi printf "\nStarting blockchain servers...\n\n" if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then - GO_TO_PROJECT_ROOT_CMD="cd ." + GO_TO_PROJECT_ROOT_CMD="cd ./ain-blockchain" else GO_TO_PROJECT_ROOT_CMD="cd \$(find /home/ain-blockchain* -maxdepth 0 -type d)" fi @@ -361,12 +372,16 @@ if [[ $NUM_SHARDS -gt 0 ]]; then # deploy files to GCP instances if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf "\nDeploying files to shard_$i tracker (${SHARD_TRACKER_TARGET_ADDR})...\n\n" + gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $TRACKER_ZONE gcloud compute scp --recurse $FILES_FOR_TRACKER ${SHARD_TRACKER_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $TRACKER_ZONE printf "\nDeploying files to shard_$i node 0 (${SHARD_NODE_0_TARGET_ADDR})...\n\n" + gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_0_ZONE gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_0_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_0_ZONE printf "\nDeploying files to shard_$i node 1 (${SHARD_NODE_1_TARGET_ADDR})...\n\n" + gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_1_ZONE gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_1_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_1_ZONE printf "\nDeploying files to shard_$i node 2 (${SHARD_NODE_2_TARGET_ADDR})...\n\n" + gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_2_ZONE gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_2_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_2_ZONE fi diff --git a/deploy_blockchain_incremental_gcp.sh b/deploy_blockchain_incremental_gcp.sh index fe75e7868..56a05c28e 100644 --- a/deploy_blockchain_incremental_gcp.sh +++ b/deploy_blockchain_incremental_gcp.sh @@ -147,7 +147,8 @@ function deploy_tracker() { if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then # 1. Copy files for tracker printf "\n\n[[[ Copying files for tracker ]]]\n\n" - SCP_CMD="gcloud compute scp --recurse $FILES_FOR_TRACKER ${TRACKER_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $TRACKER_ZONE" + gcloud compute ssh $TRACKER_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $TRACKER_ZONE + SCP_CMD="gcloud compute scp --recurse $FILES_FOR_TRACKER ${TRACKER_TARGET_ADDR}:~/ain-blockchain --project $PROJECT_ID --zone $TRACKER_ZONE" printf "SCP_CMD=$SCP_CMD\n\n" eval $SCP_CMD fi @@ -185,7 +186,8 @@ function deploy_node() { if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then # 1. Copy files for node printf "\n\n<<< Copying files for node $node_index >>>\n\n" - SCP_CMD="gcloud compute scp --recurse $FILES_FOR_NODE ${node_target_addr}:~/ --project $PROJECT_ID --zone $node_zone" + gcloud compute ssh $node_target_addr --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $node_zone + SCP_CMD="gcloud compute scp --recurse $FILES_FOR_NODE ${node_target_addr}:~/ain-blockchain --project $PROJECT_ID --zone $node_zone" printf "SCP_CMD=$SCP_CMD\n\n" eval $SCP_CMD fi @@ -278,7 +280,7 @@ NODE_TARGET_ADDR_LIST=( printf "\nStarting blockchain servers...\n\n" if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then - GO_TO_PROJECT_ROOT_CMD="cd ." + GO_TO_PROJECT_ROOT_CMD="cd ./ain-blockchain" else GO_TO_PROJECT_ROOT_CMD="cd \$(find /home/ain-blockchain* -maxdepth 0 -type d)" fi diff --git a/start_node_genesis_gcp.sh b/start_node_genesis_gcp.sh index c38bffb79..af7b9bd9f 100644 --- a/start_node_genesis_gcp.sh +++ b/start_node_genesis_gcp.sh @@ -121,37 +121,41 @@ fi printf '\n' printf 'Killing old jobs..\n' sudo killall node -if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then - printf '\n' - printf 'Removing old data..\n' - sudo rm -rf /home/ain_blockchain_data/chains - sudo rm -rf /home/ain_blockchain_data/snapshots - sudo rm -rf /home/ain_blockchain_data/logs - sudo mkdir -p /home/ain_blockchain_data - sudo chmod -R 777 /home/ain_blockchain_data -else - sudo mkdir -p /home/ain_blockchain_data - sudo chmod -R 777 /home/ain_blockchain_data -fi if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf '\n' printf 'Setting up working directory..\n' - cd - sudo rm -rf ../ain-blockchain* - sudo mkdir ../ain-blockchain - sudo chmod -R 777 ../ain-blockchain - mv * ../ain-blockchain - cd ../ain-blockchain + sudo rm -rf /home/ain-blockchain* + CODE_CMD="cd ~; sudo mv ain-blockchain /home; sudo chmod -R 777 /home/ain-blockchain; sudo chown -R root:root /home/ain-blockchain; cd /home/ain-blockchain" + printf "\nCODE_CMD=$CODE_CMD\n" + eval $CODE_CMD printf '\n' printf 'Installing node modules..\n' - sudo yarn install --ignore-engines + INSTALL_CMD="sudo yarn install --ignore-engines" + printf "\nINSTALL_CMD=$INSTALL_CMD\n" + eval $INSTALL_CMD else printf '\n' printf 'Using old directory..\n' - OLD_DIR_PATH=$(find ../ain-blockchain* -maxdepth 0 -type d) + OLD_DIR_PATH=$(find /home/ain-blockchain* -maxdepth 0 -type d) printf "OLD_DIR_PATH=$OLD_DIR_PATH\n" - sudo chmod -R 777 $OLD_DIR_PATH + CODE_CMD="sudo chmod -R 777 $OLD_DIR_PATH; sudo chown -R root:root $OLD_DIR_PATH" + printf "\nCODE_CMD=$CODE_CMD\n" + eval $CODE_CMD +fi +if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then + printf '\n' + printf 'Removing old data..\n' + sudo rm -rf /home/ain_blockchain_data/chains + sudo rm -rf /home/ain_blockchain_data/snapshots + sudo rm -rf /home/ain_blockchain_data/logs + DATA_CMD="sudo mkdir -p /home/ain_blockchain_data; sudo chmod -R 777 /home/ain_blockchain_data; sudo chown -R root:root /home/ain_blockchain_data" + printf "\nDATA_CMD=$DATA_CMD\n" + eval $DATA_CMD +else + DATA_CMD="sudo mkdir -p /home/ain_blockchain_data; sudo chmod -R 777 /home/ain_blockchain_data; sudo chown -R root:root /home/ain_blockchain_data" + printf "\nDATA_CMD=$DATA_CMD\n" + eval $DATA_CMD fi @@ -265,8 +269,9 @@ if [[ $ACCOUNT_INJECTION_OPTION = "keystore" ]]; then KEYSTORE_FILENAME="keystore_node_$NODE_INDEX.json" printf "KEYSTORE_FILENAME=$KEYSTORE_FILENAME\n" if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then - sudo mkdir -p /home/ain_blockchain_data/keys/8080 - sudo mv ./$KEYSTORE_DIR/$KEYSTORE_FILENAME /home/ain_blockchain_data/keys/8080/ + KEYSTORE_CMD="sudo mkdir -p /home/ain_blockchain_data/keys/8080; sudo mv ./$KEYSTORE_DIR/$KEYSTORE_FILENAME /home/ain_blockchain_data/keys/8080/; sudo chmod -R 777 /home/ain_blockchain_data/keys/8080; sudo chown -R root:root /home/ain_blockchain_data/keys/8080" + printf "KEYSTORE_CMD=$KEYSTORE_CMD\n" + eval $KEYSTORE_CMD fi export KEYSTORE_FILE_PATH=/home/ain_blockchain_data/keys/8080/$KEYSTORE_FILENAME printf "KEYSTORE_FILE_PATH=$KEYSTORE_FILE_PATH\n" @@ -283,7 +288,7 @@ fi printf "\nStarting up Blockchain Node server..\n\n" START_CMD="nohup node --async-stack-traces --max-old-space-size=$MAX_OLD_SPACE_SIZE_MB client/index.js >/dev/null 2>error_logs.txt &" -printf "START_CMD=$START_CMD\n" +printf "\nSTART_CMD=$START_CMD\n" printf "START_CMD=$START_CMD\n" >> start_commands.txt eval $START_CMD diff --git a/start_node_incremental_gcp.sh b/start_node_incremental_gcp.sh index 7b7789c18..847ec1e7b 100644 --- a/start_node_incremental_gcp.sh +++ b/start_node_incremental_gcp.sh @@ -258,12 +258,14 @@ fi # 2. Get currently used directory & new directory printf "\n#### [Step 2] Get currently used directory & new directory ####\n\n" -OLD_DIR_PATH=$(find ../ain-blockchain* -maxdepth 0 -type d) +OLD_DIR_PATH=$(find /home/ain-blockchain* -maxdepth 0 -type d) printf "OLD_DIR_PATH=$OLD_DIR_PATH\n" date=$(date '+%Y-%m-%dT%H-%M') printf "date=$date\n" -NEW_DIR_PATH="../ain-blockchain-$date" +NEW_DIR_NAME="ain-blockchain-$date" +printf "NEW_DIR_NAME=$NEW_DIR_NAME\n" +NEW_DIR_PATH="/home/$NEW_DIR_NAME" printf "NEW_DIR_PATH=$NEW_DIR_PATH\n" # 3. Set up working directory & install modules @@ -271,21 +273,22 @@ printf "\n#### [Step 3] Set up working directory & install modules ####\n\n" if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf '\n' printf 'Creating new working directory..\n' - MKDIR_CMD="sudo mkdir $NEW_DIR_PATH" - printf "MKDIR_CMD=$MKDIR_CMD\n" - eval $MKDIR_CMD - - sudo chmod -R 777 $NEW_DIR_PATH - mv * $NEW_DIR_PATH + CODE_CMD="cd ~; sudo mv ain-blockchain $NEW_DIR_NAME; sudo mv $NEW_DIR_NAME /home; sudo chmod -R 777 $NEW_DIR_PATH; sudo chown -R root:root $NEW_DIR_PATH" + printf "\nCODE_CMD=$CODE_CMD\n" + eval $CODE_CMD printf '\n' printf 'Installing node modules..\n' cd $NEW_DIR_PATH - sudo yarn install --ignore-engines + INSTALL_CMD="sudo yarn install --ignore-engines" + printf "\nINSTALL_CMD=$INSTALL_CMD\n" + eval $INSTALL_CMD else printf '\n' printf 'Using old working directory..\n' - sudo chmod -R 777 $OLD_DIR_PATH + CODE_CMD="sudo chmod -R 777 $OLD_DIR_PATH; sudo chown -R root:root $OLD_DIR_PATH" + printf "\nCODE_CMD=$CODE_CMD\n" + eval $CODE_CMD fi # 4. Kill old node server @@ -304,13 +307,15 @@ if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then sudo rm -rf /home/ain_blockchain_data/chains sudo rm -rf /home/ain_blockchain_data/snapshots sudo rm -rf /home/ain_blockchain_data/logs - sudo mkdir -p /home/ain_blockchain_data - sudo chmod -R 777 /home/ain_blockchain_data + DATA_CMD="sudo mkdir -p /home/ain_blockchain_data; sudo chmod -R 777 /home/ain_blockchain_data; sudo chown -R root:root /home/ain_blockchain_data" + printf "\nDATA_CMD=$DATA_CMD\n" + eval $DATA_CMD else printf '\n' printf 'Keeping existing data..\n' - sudo mkdir -p /home/ain_blockchain_data - sudo chmod -R 777 /home/ain_blockchain_data + DATA_CMD="sudo mkdir -p /home/ain_blockchain_data; sudo chmod -R 777 /home/ain_blockchain_data; sudo chown -R root:root /home/ain_blockchain_data" + printf "\nDATA_CMD=$DATA_CMD\n" + eval $DATA_CMD fi # 6. Remove old working directory keeping the chain data @@ -319,7 +324,7 @@ if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf '\n' printf 'Removing old working directory..\n' RM_CMD="sudo rm -rf $OLD_DIR_PATH" - printf "RM_CMD=$RM_CMD\n" + printf "\nRM_CMD=$RM_CMD\n" eval $RM_CMD else printf '\n' @@ -333,8 +338,9 @@ if [[ $ACCOUNT_INJECTION_OPTION = "keystore" ]]; then KEYSTORE_FILENAME="keystore_node_$NODE_INDEX.json" printf "KEYSTORE_FILENAME=$KEYSTORE_FILENAME\n" if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then - sudo mkdir -p /home/ain_blockchain_data/keys/8080 - sudo mv $NEW_DIR_PATH/$KEYSTORE_DIR/$KEYSTORE_FILENAME /home/ain_blockchain_data/keys/8080/ + KEYSTORE_CMD="sudo mkdir -p /home/ain_blockchain_data/keys/8080; sudo mv $NEW_DIR_PATH/$KEYSTORE_DIR/$KEYSTORE_FILENAME /home/ain_blockchain_data/keys/8080/; sudo chmod -R 777 /home/ain_blockchain_data/keys/8080; sudo chown -R root:root /home/ain_blockchain_data/keys/8080" + printf "KEYSTORE_CMD=$KEYSTORE_CMD\n" + eval $KEYSTORE_CMD fi export KEYSTORE_FILE_PATH=/home/ain_blockchain_data/keys/8080/$KEYSTORE_FILENAME printf "KEYSTORE_FILE_PATH=$KEYSTORE_FILE_PATH\n" @@ -350,7 +356,7 @@ else fi START_CMD="nohup node --async-stack-traces --max-old-space-size=$MAX_OLD_SPACE_SIZE_MB client/index.js >/dev/null 2>error_logs.txt &" -printf "START_CMD=$START_CMD\n" +printf "\nSTART_CMD=$START_CMD\n" printf "START_CMD=$START_CMD\n" >> start_commands.txt eval $START_CMD diff --git a/start_tracker_genesis_gcp.sh b/start_tracker_genesis_gcp.sh index e7794fa6e..1fa162b08 100644 --- a/start_tracker_genesis_gcp.sh +++ b/start_tracker_genesis_gcp.sh @@ -31,31 +31,30 @@ killall node if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf '\n' printf 'Creating new working directory..\n' - cd - sudo rm -rf /home/ain_blockchain_data - sudo mkdir /home/ain_blockchain_data - sudo chmod -R 777 /home/ain_blockchain_data - sudo rm -rf ../ain-blockchain* - sudo mkdir ../ain-blockchain - sudo chmod -R 777 ../ain-blockchain - mv * ../ain-blockchain - cd ../ain-blockchain + sudo rm -rf /home/ain-blockchain* + CODE_CMD="cd ~; sudo mv ain-blockchain /home; sudo chmod -R 777 /home/ain-blockchain; sudo chown -R root:root /home/ain-blockchain; cd /home/ain-blockchain" + printf "\nCODE_CMD=$CODE_CMD\n" + eval $CODE_CMD printf '\n' printf 'Installing node modules..\n' - sudo yarn install --ignore-engines + INSTALL_CMD="sudo yarn install --ignore-engines" + printf "\nINSTALL_CMD=$INSTALL_CMD\n" + eval $INSTALL_CMD else printf '\n' printf 'Using old directory..\n' - OLD_DIR_PATH=$(find ../ain-blockchain* -maxdepth 0 -type d) + OLD_DIR_PATH=$(find /home/ain-blockchain* -maxdepth 0 -type d) printf "OLD_DIR_PATH=$OLD_DIR_PATH\n" - sudo chmod -R 777 $OLD_DIR_PATH + CODE_CMD="sudo chmod -R 777 $OLD_DIR_PATH; sudo chown -R root:root $OLD_DIR_PATH" + printf "\nCODE_CMD=$CODE_CMD\n" + eval $CODE_CMD fi printf "\nStarting up Blockchain Tracker server..\n\n" START_CMD="nohup node --async-stack-traces tracker-server/index.js >/dev/null 2>error_logs.txt &" -printf "START_CMD=$START_CMD\n" +printf "\nSTART_CMD=$START_CMD\n" printf "START_CMD=$START_CMD\n" >> start_commands.txt eval $START_CMD diff --git a/start_tracker_incremental_gcp.sh b/start_tracker_incremental_gcp.sh index 16db6bc5d..fade12225 100644 --- a/start_tracker_incremental_gcp.sh +++ b/start_tracker_incremental_gcp.sh @@ -29,12 +29,14 @@ printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" # 2. Get currently used directory & new directory printf "\n#### [Step 2] Get currently used directory & new directory ####\n\n" -OLD_DIR_PATH=$(find ../ain-blockchain* -maxdepth 0 -type d) +OLD_DIR_PATH=$(find /home/ain-blockchain* -maxdepth 0 -type d) printf "OLD_DIR_PATH=$OLD_DIR_PATH\n" date=$(date '+%Y-%m-%dT%H:%M') printf "date=$date\n" -NEW_DIR_PATH="../ain-blockchain-$date" +NEW_DIR_NAME="ain-blockchain-$date" +printf "NEW_DIR_NAME=$NEW_DIR_NAME\n" +NEW_DIR_PATH="/home/$NEW_DIR_NAME" printf "NEW_DIR_PATH=$NEW_DIR_PATH\n" # 3. Set up working directory & install modules @@ -42,21 +44,22 @@ printf "\n#### [Step 3] Set up working directory & install modules ####\n\n" if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf '\n' printf 'Creating new working directory..\n' - MKDIR_CMD="sudo mkdir $NEW_DIR_PATH" - printf "MKDIR_CMD=$MKDIR_CMD\n" - eval $MKDIR_CMD - - sudo chmod -R 777 $NEW_DIR_PATH - mv * $NEW_DIR_PATH + CODE_CMD="cd ~; sudo mv ain-blockchain $NEW_DIR_NAME; sudo mv $NEW_DIR_NAME /home; sudo chmod -R 777 $NEW_DIR_PATH; sudo chown -R root:root $NEW_DIR_PATH" + printf "\nCODE_CMD=$CODE_CMD\n" + eval $CODE_CMD printf '\n' printf 'Installing node modules..\n' cd $NEW_DIR_PATH - sudo yarn install --ignore-engines + INSTALL_CMD="sudo yarn install --ignore-engines" + printf "\nINSTALL_CMD=$INSTALL_CMD\n" + eval $INSTALL_CMD else printf '\n' printf 'Using old working directory..\n' - sudo chmod -R 777 $OLD_DIR_PATH + CODE_CMD="sudo chmod -R 777 $OLD_DIR_PATH; sudo chown -R root:root $OLD_DIR_PATH" + printf "\nCODE_CMD=$CODE_CMD\n" + eval $CODE_CMD fi # 4. Kill old tracker server @@ -73,7 +76,7 @@ if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf '\n' printf 'Removing old working directory..\n' RM_CMD="sudo rm -rf $OLD_DIR_PATH" - printf "RM_CMD=$RM_CMD\n" + printf "\nRM_CMD=$RM_CMD\n" eval $RM_CMD else printf '\n' @@ -84,7 +87,7 @@ fi printf "\n#### [Step 6] Start new tracker server ####\n\n" START_CMD="nohup node --async-stack-traces tracker-server/index.js >/dev/null 2>error_logs.txt &" -printf "START_CMD=$START_CMD\n" +printf "\nSTART_CMD=$START_CMD\n" printf "START_CMD=$START_CMD\n" >> start_commands.txt eval $START_CMD From a98a0accedee11abaef6584ba76819397f0bec7d Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Sun, 9 Jan 2022 17:35:52 +0900 Subject: [PATCH 13/21] Require stronger confirmation for mainnet deployment --- deploy_blockchain_genesis_gcp.sh | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/deploy_blockchain_genesis_gcp.sh b/deploy_blockchain_genesis_gcp.sh index 9bc108c76..777621d29 100644 --- a/deploy_blockchain_genesis_gcp.sh +++ b/deploy_blockchain_genesis_gcp.sh @@ -104,12 +104,23 @@ if [[ "$ACCOUNT_INJECTION_OPTION" = "" ]]; then fi # Get confirmation. -printf "\n" -read -p "Do you want to proceed? >> (y/N) " -n 1 -r -printf "\n\n" -if [[ ! $REPLY =~ ^[Yy]$ ]] -then - [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell +if [[ "$SEASON" = "mainnet" ]]; then + printf "\n" + printf "Do you want to proceed for $SEASON? >> Enter [mainnet]: " + read CONFIRM + printf "\n\n" + if [[ ! $CONFIRM = "mainnet" ]] + then + [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell + fi +else + printf "\n" + read -p "Do you want to proceed for $SEASON? >> Enter [y/N]: " -n 1 -r + printf "\n\n" + if [[ ! $REPLY =~ ^[Yy]$ ]] + then + [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell + fi fi # Read node ip addresses From 81586756c4016550bf0acff003d8cae59afbef1f Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Sun, 9 Jan 2022 18:34:03 +0900 Subject: [PATCH 14/21] Deploy tracker with BEGIN_PARENT_NODE_INDEX = -1 and make END_PARENT_NODE_INDEX inclusive --- deploy_blockchain_incremental_gcp.sh | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/deploy_blockchain_incremental_gcp.sh b/deploy_blockchain_incremental_gcp.sh index 56a05c28e..6f8cb2b50 100644 --- a/deploy_blockchain_incremental_gcp.sh +++ b/deploy_blockchain_incremental_gcp.sh @@ -2,7 +2,8 @@ if [[ $# -lt 5 ]] || [[ $# -gt 11 ]]; then printf "Usage: bash deploy_blockchain_incremental_gcp.sh [dev|staging|sandbox|spring|summer|mainnet] <# of Shards> [--setup] [--keystore|--mnemonic|--private-key] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--full-sync|--fast-sync]\n" - printf "Example: bash deploy_blockchain_incremental_gcp.sh dev lia 0 0 1 --setup --keystore --no-keep-code --full-sync\n" + printf "Example: bash deploy_blockchain_incremental_gcp.sh dev lia 0 -1 1 --setup --keystore --no-keep-code --full-sync\n" + printf "Note: is inclusive\n" printf "\n" exit fi @@ -297,15 +298,21 @@ else START_NODE_CMD_BASE="$GO_TO_PROJECT_ROOT_CMD && . start_node_incremental_gcp.sh" fi -# Tracker server is deployed with node 0 -if [[ $BEGIN_PARENT_NODE_INDEX = 0 ]]; then +# Tracker server is deployed with BEGIN_PARENT_NODE_INDEX = -1 +if [[ $BEGIN_PARENT_NODE_INDEX = -1 ]]; then deploy_tracker fi -for j in `seq $BEGIN_PARENT_NODE_INDEX $(( $END_PARENT_NODE_INDEX - 1 ))` - do - deploy_node "$j" - sleep 40 - done +begin_index = $BEGIN_PARENT_NODE_INDEX +if [[ $begin_index -lt 0 ]]; then + begin_index = 0 +fi +if [[ $begin_index -le $END_PARENT_NODE_INDEX ]] && [[ $END_PARENT_NODE_INDEX -ge 0 ]]; then + for j in `seq $(( $begin_index )) $(( $END_PARENT_NODE_INDEX ))` + do + deploy_node "$j" + sleep 40 + done +fi if [[ $NUM_SHARDS -gt 0 ]]; then for i in $(seq $NUM_SHARDS) From 818b092a1dc25c680a82971af9cb318495ef78a9 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Sun, 9 Jan 2022 19:14:27 +0900 Subject: [PATCH 15/21] Fix an assignment bug and cp instead of mv for keystore files --- deploy_blockchain_incremental_gcp.sh | 5 +++-- start_node_genesis_gcp.sh | 9 +++++---- start_node_incremental_gcp.sh | 10 +++++----- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/deploy_blockchain_incremental_gcp.sh b/deploy_blockchain_incremental_gcp.sh index 6f8cb2b50..50ae4d4ee 100644 --- a/deploy_blockchain_incremental_gcp.sh +++ b/deploy_blockchain_incremental_gcp.sh @@ -3,6 +3,7 @@ if [[ $# -lt 5 ]] || [[ $# -gt 11 ]]; then printf "Usage: bash deploy_blockchain_incremental_gcp.sh [dev|staging|sandbox|spring|summer|mainnet] <# of Shards> [--setup] [--keystore|--mnemonic|--private-key] [--keep-code|--no-keep-code] [--keep-data|--no-keep-data] [--full-sync|--fast-sync]\n" printf "Example: bash deploy_blockchain_incremental_gcp.sh dev lia 0 -1 1 --setup --keystore --no-keep-code --full-sync\n" + printf "Note: = -1 is for tracker\n" printf "Note: is inclusive\n" printf "\n" exit @@ -302,9 +303,9 @@ fi if [[ $BEGIN_PARENT_NODE_INDEX = -1 ]]; then deploy_tracker fi -begin_index = $BEGIN_PARENT_NODE_INDEX +begin_index=$BEGIN_PARENT_NODE_INDEX if [[ $begin_index -lt 0 ]]; then - begin_index = 0 + begin_index=0 fi if [[ $begin_index -le $END_PARENT_NODE_INDEX ]] && [[ $END_PARENT_NODE_INDEX -ge 0 ]]; then for j in `seq $(( $begin_index )) $(( $END_PARENT_NODE_INDEX ))` diff --git a/start_node_genesis_gcp.sh b/start_node_genesis_gcp.sh index af7b9bd9f..4f2ecf1db 100644 --- a/start_node_genesis_gcp.sh +++ b/start_node_genesis_gcp.sh @@ -123,7 +123,7 @@ printf 'Killing old jobs..\n' sudo killall node if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf '\n' - printf 'Setting up working directory..\n' + printf 'Setting up new working directory..\n' sudo rm -rf /home/ain-blockchain* CODE_CMD="cd ~; sudo mv ain-blockchain /home; sudo chmod -R 777 /home/ain-blockchain; sudo chown -R root:root /home/ain-blockchain; cd /home/ain-blockchain" printf "\nCODE_CMD=$CODE_CMD\n" @@ -136,7 +136,7 @@ if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then eval $INSTALL_CMD else printf '\n' - printf 'Using old directory..\n' + printf 'Reusing existing working directory..\n' OLD_DIR_PATH=$(find /home/ain-blockchain* -maxdepth 0 -type d) printf "OLD_DIR_PATH=$OLD_DIR_PATH\n" CODE_CMD="sudo chmod -R 777 $OLD_DIR_PATH; sudo chown -R root:root $OLD_DIR_PATH" @@ -145,7 +145,7 @@ else fi if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then printf '\n' - printf 'Removing old data..\n' + printf 'Setting up new data directory..\n' sudo rm -rf /home/ain_blockchain_data/chains sudo rm -rf /home/ain_blockchain_data/snapshots sudo rm -rf /home/ain_blockchain_data/logs @@ -153,6 +153,7 @@ if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then printf "\nDATA_CMD=$DATA_CMD\n" eval $DATA_CMD else + printf 'Reusing existing data directory..\n' DATA_CMD="sudo mkdir -p /home/ain_blockchain_data; sudo chmod -R 777 /home/ain_blockchain_data; sudo chown -R root:root /home/ain_blockchain_data" printf "\nDATA_CMD=$DATA_CMD\n" eval $DATA_CMD @@ -269,7 +270,7 @@ if [[ $ACCOUNT_INJECTION_OPTION = "keystore" ]]; then KEYSTORE_FILENAME="keystore_node_$NODE_INDEX.json" printf "KEYSTORE_FILENAME=$KEYSTORE_FILENAME\n" if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then - KEYSTORE_CMD="sudo mkdir -p /home/ain_blockchain_data/keys/8080; sudo mv ./$KEYSTORE_DIR/$KEYSTORE_FILENAME /home/ain_blockchain_data/keys/8080/; sudo chmod -R 777 /home/ain_blockchain_data/keys/8080; sudo chown -R root:root /home/ain_blockchain_data/keys/8080" + KEYSTORE_CMD="sudo mkdir -p /home/ain_blockchain_data/keys/8080; sudo cp ./$KEYSTORE_DIR/$KEYSTORE_FILENAME /home/ain_blockchain_data/keys/8080/; sudo chmod -R 777 /home/ain_blockchain_data/keys/8080; sudo chown -R root:root /home/ain_blockchain_data/keys/8080" printf "KEYSTORE_CMD=$KEYSTORE_CMD\n" eval $KEYSTORE_CMD fi diff --git a/start_node_incremental_gcp.sh b/start_node_incremental_gcp.sh index 847ec1e7b..a156c7658 100644 --- a/start_node_incremental_gcp.sh +++ b/start_node_incremental_gcp.sh @@ -272,7 +272,7 @@ printf "NEW_DIR_PATH=$NEW_DIR_PATH\n" printf "\n#### [Step 3] Set up working directory & install modules ####\n\n" if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf '\n' - printf 'Creating new working directory..\n' + printf 'Setting up new working directory..\n' CODE_CMD="cd ~; sudo mv ain-blockchain $NEW_DIR_NAME; sudo mv $NEW_DIR_NAME /home; sudo chmod -R 777 $NEW_DIR_PATH; sudo chown -R root:root $NEW_DIR_PATH" printf "\nCODE_CMD=$CODE_CMD\n" eval $CODE_CMD @@ -285,7 +285,7 @@ if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then eval $INSTALL_CMD else printf '\n' - printf 'Using old working directory..\n' + printf 'Reusing existing working directory..\n' CODE_CMD="sudo chmod -R 777 $OLD_DIR_PATH; sudo chown -R root:root $OLD_DIR_PATH" printf "\nCODE_CMD=$CODE_CMD\n" eval $CODE_CMD @@ -303,7 +303,7 @@ sleep 10 printf "\n#### [Step 5] Set up data directory ####\n\n" if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then printf '\n' - printf 'Removing old data..\n' + printf 'Setting up new data directory..\n' sudo rm -rf /home/ain_blockchain_data/chains sudo rm -rf /home/ain_blockchain_data/snapshots sudo rm -rf /home/ain_blockchain_data/logs @@ -312,7 +312,7 @@ if [[ $KEEP_DATA_OPTION = "--no-keep-data" ]]; then eval $DATA_CMD else printf '\n' - printf 'Keeping existing data..\n' + printf 'Reusing existing data directory..\n' DATA_CMD="sudo mkdir -p /home/ain_blockchain_data; sudo chmod -R 777 /home/ain_blockchain_data; sudo chown -R root:root /home/ain_blockchain_data" printf "\nDATA_CMD=$DATA_CMD\n" eval $DATA_CMD @@ -338,7 +338,7 @@ if [[ $ACCOUNT_INJECTION_OPTION = "keystore" ]]; then KEYSTORE_FILENAME="keystore_node_$NODE_INDEX.json" printf "KEYSTORE_FILENAME=$KEYSTORE_FILENAME\n" if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then - KEYSTORE_CMD="sudo mkdir -p /home/ain_blockchain_data/keys/8080; sudo mv $NEW_DIR_PATH/$KEYSTORE_DIR/$KEYSTORE_FILENAME /home/ain_blockchain_data/keys/8080/; sudo chmod -R 777 /home/ain_blockchain_data/keys/8080; sudo chown -R root:root /home/ain_blockchain_data/keys/8080" + KEYSTORE_CMD="sudo mkdir -p /home/ain_blockchain_data/keys/8080; sudo cp $NEW_DIR_PATH/$KEYSTORE_DIR/$KEYSTORE_FILENAME /home/ain_blockchain_data/keys/8080/; sudo chmod -R 777 /home/ain_blockchain_data/keys/8080; sudo chown -R root:root /home/ain_blockchain_data/keys/8080" printf "KEYSTORE_CMD=$KEYSTORE_CMD\n" eval $KEYSTORE_CMD fi From 3607fe601e6ad236b448837c78cc511f9c27baa5 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Sun, 9 Jan 2022 19:37:13 +0900 Subject: [PATCH 16/21] Update sandbox script for directory change --- deploy_blockchain_genesis_gcp.sh | 7 +++---- deploy_blockchain_incremental_gcp.sh | 21 ++++++++++++++++----- deploy_blockchain_sandbox_gcp.sh | 7 ++++--- start_tracker_incremental_gcp.sh | 6 +++--- 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/deploy_blockchain_genesis_gcp.sh b/deploy_blockchain_genesis_gcp.sh index 777621d29..3fa685e52 100644 --- a/deploy_blockchain_genesis_gcp.sh +++ b/deploy_blockchain_genesis_gcp.sh @@ -106,7 +106,7 @@ fi # Get confirmation. if [[ "$SEASON" = "mainnet" ]]; then printf "\n" - printf "Do you want to proceed for $SEASON? >> Enter [mainnet]: " + printf "Do you want to proceed for $SEASON? Enter [mainnet]: " read CONFIRM printf "\n\n" if [[ ! $CONFIRM = "mainnet" ]] @@ -115,10 +115,9 @@ if [[ "$SEASON" = "mainnet" ]]; then fi else printf "\n" - read -p "Do you want to proceed for $SEASON? >> Enter [y/N]: " -n 1 -r + read -p "Do you want to proceed for $SEASON? [y/N]: " -n 1 -r printf "\n\n" - if [[ ! $REPLY =~ ^[Yy]$ ]] - then + if [[ ! $REPLY =~ ^[Yy]$ ]]; then [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell fi fi diff --git a/deploy_blockchain_incremental_gcp.sh b/deploy_blockchain_incremental_gcp.sh index 50ae4d4ee..178035041 100644 --- a/deploy_blockchain_incremental_gcp.sh +++ b/deploy_blockchain_incremental_gcp.sh @@ -96,11 +96,22 @@ if [[ "$ACCOUNT_INJECTION_OPTION" = "" ]]; then fi # Get confirmation. -printf "\n" -read -p "Do you want to proceed? >> (y/N) " -n 1 -r -printf "\n\n" -if [[ ! $REPLY =~ ^[Yy]$ ]]; then - [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell +if [[ "$SEASON" = "mainnet" ]]; then + printf "\n" + printf "Do you want to proceed for $SEASON? Enter [mainnet]: " + read CONFIRM + printf "\n\n" + if [[ ! $CONFIRM = "mainnet" ]] + then + [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell + fi +else + printf "\n" + read -p "Do you want to proceed for $SEASON? [y/N]: " -n 1 -r + printf "\n\n" + if [[ ! $REPLY =~ ^[Yy]$ ]]; then + [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell + fi fi # Read node ip addresses diff --git a/deploy_blockchain_sandbox_gcp.sh b/deploy_blockchain_sandbox_gcp.sh index 249473818..6bc76d396 100644 --- a/deploy_blockchain_sandbox_gcp.sh +++ b/deploy_blockchain_sandbox_gcp.sh @@ -352,8 +352,9 @@ if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then do NODE_TARGET_ADDR=NODE_${index}_TARGET_ADDR NODE_ZONE=NODE_${index}_ZONE - - DEPLOY_BLOCKCHAIN_CMD="gcloud compute scp --recurse $FILES_FOR_NODE ${!NODE_TARGET_ADDR}:~/ --project $PROJECT_ID --zone ${!NODE_ZONE}" + + gcloud compute ssh ${!NODE_TARGET_ADDR} --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone ${!NODE_ZONE} + DEPLOY_BLOCKCHAIN_CMD="gcloud compute scp --recurse $FILES_FOR_NODE ${!NODE_TARGET_ADDR}:~/ain-blockchain --project $PROJECT_ID --zone ${!NODE_ZONE}" # NOTE(minsulee2): Keep printf for extensibility experiment debugging purpose # printf "DEPLOY_BLOCKCHAIN_CMD=$DEPLOY_BLOCKCHAIN_CMD\n" if [[ $index < "$(($NUM_NODES - 1))" ]]; then @@ -392,7 +393,7 @@ fi printf "\nStarting blockchain servers...\n\n" if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then - GO_TO_PROJECT_ROOT_CMD="cd ." + GO_TO_PROJECT_ROOT_CMD="cd ./ain-blockchain" else GO_TO_PROJECT_ROOT_CMD="cd \$(find /home/ain-blockchain* -maxdepth 0 -type d)" fi diff --git a/start_tracker_incremental_gcp.sh b/start_tracker_incremental_gcp.sh index fade12225..aef2f715e 100644 --- a/start_tracker_incremental_gcp.sh +++ b/start_tracker_incremental_gcp.sh @@ -43,7 +43,7 @@ printf "NEW_DIR_PATH=$NEW_DIR_PATH\n" printf "\n#### [Step 3] Set up working directory & install modules ####\n\n" if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf '\n' - printf 'Creating new working directory..\n' + printf 'Setting up new data directory..\n' CODE_CMD="cd ~; sudo mv ain-blockchain $NEW_DIR_NAME; sudo mv $NEW_DIR_NAME /home; sudo chmod -R 777 $NEW_DIR_PATH; sudo chown -R root:root $NEW_DIR_PATH" printf "\nCODE_CMD=$CODE_CMD\n" eval $CODE_CMD @@ -56,7 +56,7 @@ if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then eval $INSTALL_CMD else printf '\n' - printf 'Using old working directory..\n' + printf 'Reusing existing working directory..\n' CODE_CMD="sudo chmod -R 777 $OLD_DIR_PATH; sudo chown -R root:root $OLD_DIR_PATH" printf "\nCODE_CMD=$CODE_CMD\n" eval $CODE_CMD @@ -80,7 +80,7 @@ if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then eval $RM_CMD else printf '\n' - printf 'Keeping old working directory..\n' + printf 'Keeping existing working directory..\n' fi # 6. Start new tracker server From 0a1917de1b411292640ca553b2e374c12c0dbc22 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Sun, 9 Jan 2022 20:04:03 +0900 Subject: [PATCH 17/21] Update tests and fix test config --- package.json | 42 ++++++++++++++++++------------------ test/unit/state-util.test.js | 25 +++++++++++---------- 2 files changed, 33 insertions(+), 34 deletions(-) diff --git a/package.json b/package.json index 27e57076e..2bd98dce3 100644 --- a/package.json +++ b/package.json @@ -26,27 +26,27 @@ "test_integration_he_protocol": "BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/3-nodes ./node_modules/mocha/bin/mocha --timeout 640000 test/integration/he_protocol.test.js", "test_integration_he_sharding": "BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/3-nodes ./node_modules/mocha/bin/mocha --timeout 640000 test/integration/he_sharding.test.js", "test_integration_sharding": "BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/3-nodes ./node_modules/mocha/bin/mocha --timeout 640000 test/integration/sharding.test.js", - "test_unit": "ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ./node_modules/mocha/bin/mocha --timeout 160000 \"test/unit/*.test.js\"", - "test_unit_block_pool": "ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/block-pool.test.js", - "test_unit_blockchain": "ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/blockchain.test.js", - "test_unit_common_util": "ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/common-util.test.js", - "test_unit_consensus": "ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/consensus.test.js", - "test_unit_db": "ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/db.test.js", - "test_unit_event_handler": "ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/event-handler.test.js", - "test_unit_functions": "ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/functions.test.js", - "test_unit_object_util": "ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/object-util.test.js", - "test_unit_p2p": "ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node --timeout 320000 test/unit/p2p.test.js", - "test_unit_p2p_util": "ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node --timeout 160000 test/unit/p2p-util.test.js", - "test_unit_radix_node": "ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node --timeout 160000 test/unit/radix-node.test.js", - "test_unit_radix_tree": "ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node --timeout 160000 test/unit/radix-tree.test.js", - "test_unit_rule_util": "ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node --timeout 160000 test/unit/rule-util.test.js", - "test_unit_state_manager": "ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node --timeout 160000 test/unit/state-manager.test.js", - "test_unit_state_node": "ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node --timeout 160000 test/unit/state-node.test.js", - "test_unit_state_util": "ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node --timeout 160000 test/unit/state-util.test.js", - "test_unit_traffic_db": "ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node --timeout 160000 test/unit/traffic-database.test.js", - "test_unit_traffic_sm": "ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node --timeout 160000 test/unit/traffic-stats-manager.test.js", - "test_unit_tx": "ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/transaction.test.js", - "test_unit_tx_pool": "ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/tx-pool.test.js", + "test_unit": "BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha --timeout 160000 \"test/unit/*.test.js\"", + "test_unit_block_pool": "BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/block-pool.test.js", + "test_unit_blockchain": "BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/blockchain.test.js", + "test_unit_common_util": "BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/common-util.test.js", + "test_unit_consensus": "BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/consensus.test.js", + "test_unit_db": "BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/db.test.js", + "test_unit_event_handler": "BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/event-handler.test.js", + "test_unit_functions": "BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-nodeE NABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/functions.test.js", + "test_unit_object_util": "BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/object-util.test.js", + "test_unit_p2p": "BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha --timeout 320000 test/unit/p2p.test.js", + "test_unit_p2p_util": "BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/p2p-util.test.js", + "test_unit_radix_node": "BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/radix-node.test.js", + "test_unit_radix_tree": "BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/radix-tree.test.js", + "test_unit_rule_util": "BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/rule-util.test.js", + "test_unit_state_manager": "BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/state-manager.test.js", + "test_unit_state_node": "BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/state-node.test.js", + "test_unit_state_util": "BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/state-util.test.js", + "test_unit_traffic_db": "BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/traffic-database.test.js", + "test_unit_traffic_sm": "BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/traffic-stats-manager.test.js", + "test_unit_tx": "BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/transaction.test.js", + "test_unit_tx_pool": "BLOCKCHAIN_CONFIGS_DIR=blockchain-configs/1-node ENABLE_REST_FUNCTION_CALL=true UNSAFE_PRIVATE_KEY=b22c95ffc4a5c096f7d7d0487ba963ce6ac945bdc91c79b64ce209de289bec96 ./node_modules/mocha/bin/mocha --timeout 160000 test/unit/tx-pool.test.js", "tracker": "npm run clean & node ./tracker-server/index.js" }, "dependencies": { diff --git a/test/unit/state-util.test.js b/test/unit/state-util.test.js index d47c266d8..e13f82ffd 100644 --- a/test/unit/state-util.test.js +++ b/test/unit/state-util.test.js @@ -351,12 +351,12 @@ describe("state-util", () => { expect(isValidServiceName('0_0')).to.equal(false); }) - it("when upper-case string input with blockNumber = 0 returning false", () => { - expect(isValidServiceName('A', 0)).to.equal(true); - expect(isValidServiceName('aA', 0)).to.equal(true); - expect(isValidServiceName('A_', 0)).to.equal(true); - expect(isValidServiceName('A0', 0)).to.equal(true); - expect(isValidServiceName('a0A', 0)).to.equal(true); + it("when upper-case string input with blockNumber = 1 returning false", () => { + expect(isValidServiceName('A', 1)).to.equal(true); + expect(isValidServiceName('aA', 1)).to.equal(true); + expect(isValidServiceName('A_', 1)).to.equal(true); + expect(isValidServiceName('A0', 1)).to.equal(true); + expect(isValidServiceName('a0A', 1)).to.equal(true); }) it("when upper-case string input with blockNumber = 2 returning false", () => { @@ -367,12 +367,12 @@ describe("state-util", () => { expect(isValidServiceName('a0A', 2)).to.equal(false); }) - it("when lower-case string input with blockNumber = 0 returning true", () => { - expect(isValidServiceName('a', 0)).to.equal(true); - expect(isValidServiceName('aa', 0)).to.equal(true); - expect(isValidServiceName('a_', 0)).to.equal(true); - expect(isValidServiceName('a0', 0)).to.equal(true); - expect(isValidServiceName('a0a', 0)).to.equal(true); + it("when lower-case string input with blockNumber = 1 returning true", () => { + expect(isValidServiceName('a', 1)).to.equal(true); + expect(isValidServiceName('aa', 1)).to.equal(true); + expect(isValidServiceName('a_', 1)).to.equal(true); + expect(isValidServiceName('a0', 1)).to.equal(true); + expect(isValidServiceName('a0a', 1)).to.equal(true); }) it("when lower-case string input with blockNumber = 2 returning true", () => { @@ -391,7 +391,6 @@ describe("state-util", () => { }) it("when reserved service name input returning false", () => { - expect(isValidServiceName('balance_total_sum', 0)).to.equal(false); expect(isValidServiceName('balance_total_sum', 1)).to.equal(false); expect(isValidServiceName('balance_total_sum', 2)).to.equal(false); }) From 480ec19eedcf8596779cfbf7560e081e1283f58b Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Sun, 9 Jan 2022 23:27:08 +0900 Subject: [PATCH 18/21] Export ACCOUNT_INJECTION_OPTION env variable properly --- start_node_genesis_gcp.sh | 14 ++++++++++---- start_node_incremental_gcp.sh | 14 ++++++++++---- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/start_node_genesis_gcp.sh b/start_node_genesis_gcp.sh index 4f2ecf1db..f7fdbfee0 100644 --- a/start_node_genesis_gcp.sh +++ b/start_node_genesis_gcp.sh @@ -12,11 +12,11 @@ printf "\n[[[[[ start_node_genesis_gcp.sh ]]]]]\n\n" function parse_options() { local option="$1" if [[ $option = '--private-key' ]]; then - ACCOUNT_INJECTION_OPTION="private_key" + ACCOUNT_INJECTION_OPTION="$option" elif [[ $option = '--keystore' ]]; then - ACCOUNT_INJECTION_OPTION="keystore" + ACCOUNT_INJECTION_OPTION="$option" elif [[ $option = '--mnemonic' ]]; then - ACCOUNT_INJECTION_OPTION="mnemonic" + ACCOUNT_INJECTION_OPTION="$option" elif [[ $option = '--keep-code' ]]; then KEEP_CODE_OPTION="$option" elif [[ $option = '--no-keep-code' ]]; then @@ -95,7 +95,13 @@ if [[ "$ACCOUNT_INJECTION_OPTION" = "" ]]; then return 1 fi -export ACCOUNT_INJECTION_OPTION="$ACCOUNT_INJECTION_OPTION" +if [[ $ACCOUNT_INJECTION_OPTION = "--keystore" ]]; then + export ACCOUNT_INJECTION_OPTION=keystore +elif [[ $ACCOUNT_INJECTION_OPTION = "--mnemonic" ]]; then + export ACCOUNT_INJECTION_OPTION=mnemonic +else + export ACCOUNT_INJECTION_OPTION=private_key +fi if [[ $SYNC_MODE_OPTION = "--full-sync" ]]; then export SYNC_MODE=full else diff --git a/start_node_incremental_gcp.sh b/start_node_incremental_gcp.sh index a156c7658..b64c0abc5 100644 --- a/start_node_incremental_gcp.sh +++ b/start_node_incremental_gcp.sh @@ -11,11 +11,11 @@ printf "\n[[[[[ start_node_incremental_gcp.sh ]]]]]\n\n" function parse_options() { local option="$1" if [[ $option = '--private-key' ]]; then - ACCOUNT_INJECTION_OPTION="private_key" + ACCOUNT_INJECTION_OPTION="$option" elif [[ $option = '--keystore' ]]; then - ACCOUNT_INJECTION_OPTION="keystore" + ACCOUNT_INJECTION_OPTION="$option" elif [[ $option = '--mnemonic' ]]; then - ACCOUNT_INJECTION_OPTION="mnemonic" + ACCOUNT_INJECTION_OPTION="$option" elif [[ $option = '--keep-code' ]]; then KEEP_CODE_OPTION="$option" elif [[ $option = '--no-keep-code' ]]; then @@ -226,7 +226,13 @@ if [[ "$ACCOUNT_INJECTION_OPTION" = "" ]]; then return 1 fi -export ACCOUNT_INJECTION_OPTION="$ACCOUNT_INJECTION_OPTION" +if [[ $ACCOUNT_INJECTION_OPTION = "--keystore" ]]; then + export ACCOUNT_INJECTION_OPTION=keystore +elif [[ $ACCOUNT_INJECTION_OPTION = "--mnemonic" ]]; then + export ACCOUNT_INJECTION_OPTION=mnemonic +else + export ACCOUNT_INJECTION_OPTION=private_key +fi if [[ $SYNC_MODE_OPTION = "--full-sync" ]]; then export SYNC_MODE=full else From fd6890fb9492cc896a8a5de7f58cb40d7d6923ad Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Mon, 10 Jan 2022 00:55:22 +0900 Subject: [PATCH 19/21] Use loop for iterating nodes in genesis deploy script --- deploy_blockchain_genesis_gcp.sh | 260 ++++++++++++--------------- deploy_blockchain_incremental_gcp.sh | 56 +++--- deploy_blockchain_sandbox_gcp.sh | 15 +- start_node_genesis_gcp.sh | 3 +- start_node_incremental_gcp.sh | 3 +- 5 files changed, 147 insertions(+), 190 deletions(-) diff --git a/deploy_blockchain_genesis_gcp.sh b/deploy_blockchain_genesis_gcp.sh index 3fa685e52..42ee8fa75 100644 --- a/deploy_blockchain_genesis_gcp.sh +++ b/deploy_blockchain_genesis_gcp.sh @@ -86,8 +86,7 @@ SYNC_MODE_OPTION="--fast-sync" KILL_OPTION="" ARG_INDEX=4 -while [ $ARG_INDEX -le $# ] -do +while [ $ARG_INDEX -le $# ]; do parse_options "${!ARG_INDEX}" ((ARG_INDEX++)) done @@ -197,102 +196,74 @@ NODE_7_ZONE="asia-southeast1-b" NODE_8_ZONE="us-central1-a" NODE_9_ZONE="europe-west4-a" +# Number of blockchain nodes to deploy +NUM_NODES=10 + +printf "###############################################################################\n" +printf "# Deploying parent blockchain #\n" +printf "###############################################################################\n\n" + # deploy files to GCP instances if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then - printf "\nDeploying parent blockchain...\n\n" - printf "\nDeploying files to parent tracker (${TRACKER_TARGET_ADDR})...\n\n" + printf "\n* >> Deploying files for parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" gcloud compute ssh $TRACKER_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $TRACKER_ZONE gcloud compute scp --recurse $FILES_FOR_TRACKER ${TRACKER_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $TRACKER_ZONE - printf "\nDeploying files to parent node 0 (${NODE_0_TARGET_ADDR})...\n\n" - gcloud compute ssh $NODE_0_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_0_ZONE - gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_0_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $NODE_0_ZONE - printf "\nDeploying files to parent node 1 (${NODE_1_TARGET_ADDR})...\n\n" - gcloud compute ssh $NODE_1_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_1_ZONE - gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_1_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $NODE_1_ZONE - printf "\nDeploying files to parent node 2 (${NODE_2_TARGET_ADDR})...\n\n" - gcloud compute ssh $NODE_2_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_2_ZONE - gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_2_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $NODE_2_ZONE - printf "\nDeploying files to parent node 3 (${NODE_3_TARGET_ADDR})...\n\n" - gcloud compute ssh $NODE_3_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_3_ZONE - gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_3_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $NODE_3_ZONE - printf "\nDeploying files to parent node 4 (${NODE_4_TARGET_ADDR})...\n\n" - gcloud compute ssh $NODE_4_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_4_ZONE - gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_4_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $NODE_4_ZONE - printf "\nDeploying files to parent node 5 (${NODE_5_TARGET_ADDR})...\n\n" - gcloud compute ssh $NODE_5_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_5_ZONE - gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_5_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $NODE_5_ZONE - printf "\nDeploying files to parent node 6 (${NODE_6_TARGET_ADDR})...\n\n" - gcloud compute ssh $NODE_6_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_6_ZONE - gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_6_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $NODE_6_ZONE - printf "\nDeploying files to parent node 7 (${NODE_7_TARGET_ADDR})...\n\n" - gcloud compute ssh $NODE_7_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_7_ZONE - gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_7_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $NODE_7_ZONE - printf "\nDeploying files to parent node 8 (${NODE_8_TARGET_ADDR})...\n\n" - gcloud compute ssh $NODE_8_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_8_ZONE - gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_8_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $NODE_8_ZONE - printf "\nDeploying files to parent node 9 (${NODE_9_TARGET_ADDR})...\n\n" - gcloud compute ssh $NODE_9_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_9_ZONE - gcloud compute scp --recurse $FILES_FOR_NODE ${NODE_9_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $NODE_9_ZONE + + for node_index in `seq 0 $(( $NUM_NODES - 1 ))`; do + NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR + NODE_ZONE=NODE_${node_index}_ZONE + + printf "\n* >> Deploying files for parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh ${!NODE_TARGET_ADDR} --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone ${!NODE_ZONE} + gcloud compute scp --recurse $FILES_FOR_NODE ${!NODE_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone ${!NODE_ZONE} + done fi # ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) if [[ $SETUP_OPTION = "--setup" ]]; then - printf "\n\n##########################\n# Setting up parent tracker #\n###########################\n\n" - gcloud compute ssh $TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE - printf "\n\n##########################\n# Setting up parent node 0 #\n##########################\n\n" - gcloud compute ssh $NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_0_ZONE - printf "\n\n##########################\n# Setting up parent node 1 #\n##########################\n\n" - gcloud compute ssh $NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_1_ZONE - printf "\n\n##########################\n# Setting up parent node 2 #\n##########################\n\n" - gcloud compute ssh $NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_2_ZONE - printf "\n\n##########################\n# Setting up parent node 3 #\n##########################\n\n" - gcloud compute ssh $NODE_3_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_3_ZONE - printf "\n\n##########################\n# Setting up parent node 4 #\n##########################\n\n" - gcloud compute ssh $NODE_4_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_4_ZONE - printf "\n\n##########################\n# Setting up parent node 5 #\n##########################\n\n" - gcloud compute ssh $NODE_5_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_5_ZONE - printf "\n\n##########################\n# Setting up parent node 6 #\n##########################\n\n" - gcloud compute ssh $NODE_6_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_6_ZONE - printf "\n\n##########################\n# Setting up parent node 7 #\n##########################\n\n" - gcloud compute ssh $NODE_7_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_7_ZONE - printf "\n\n##########################\n# Setting up parent node 8 #\n##########################\n\n" - gcloud compute ssh $NODE_8_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_8_ZONE - printf "\n\n##########################\n# Setting up parent node 9 #\n##########################\n\n" - gcloud compute ssh $NODE_9_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_9_ZONE + printf "\n* >> Setting up parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $TRACKER_TARGET_ADDR --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE + + for node_index in `seq 0 $(( $NUM_NODES - 1 ))`; do + NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR + NODE_ZONE=NODE_${node_index}_ZONE + + printf "\n* >> Setting up parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh ${!NODE_TARGET_ADDR} --command "cd ./ain-blockchain; . setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone ${!NODE_ZONE} + done fi if [[ $KILL_OPTION = "--skip-kill" ]]; then printf "\nSkipping process kill...\n" else # kill any processes still alive - printf "\nKilling all trackers and blockchain nodes...\n" + printf "\nKilling all tracker and blockchain node jobs...\n" + + printf "\n* >> Killing tracker job (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" gcloud compute ssh $TRACKER_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $TRACKER_ZONE - gcloud compute ssh $NODE_0_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_0_ZONE - gcloud compute ssh $NODE_1_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_1_ZONE - gcloud compute ssh $NODE_2_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_2_ZONE - gcloud compute ssh $NODE_3_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_3_ZONE - gcloud compute ssh $NODE_4_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_4_ZONE - gcloud compute ssh $NODE_5_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_5_ZONE - gcloud compute ssh $NODE_6_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_6_ZONE - gcloud compute ssh $NODE_7_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_7_ZONE - gcloud compute ssh $NODE_8_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_8_ZONE - gcloud compute ssh $NODE_9_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_9_ZONE + + for node_index in `seq 0 $(( $NUM_NODES - 1 ))`; do + NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR + NODE_ZONE=NODE_${node_index}_ZONE + + printf "\n* >> Killing node $node_index job (${!NODE_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh ${!NODE_TARGET_ADDR} --command "sudo killall node" --project $PROJECT_ID --zone ${!NODE_ZONE} + done if [[ $NUM_SHARDS -gt 0 ]]; then - for i in $(seq $NUM_SHARDS) - do - printf "shard #$i\n" - - SHARD_TRACKER_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-tracker-taiwan" - SHARD_NODE_0_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-0-taiwan" - SHARD_NODE_1_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-1-oregon" - SHARD_NODE_2_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-2-singapore" - - gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $TRACKER_ZONE - gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_0_ZONE - gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_1_ZONE - gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_2_ZONE - done + for i in $(seq $NUM_SHARDS); do + printf "shard #$i\n" + + SHARD_TRACKER_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-tracker-taiwan" + SHARD_NODE_0_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-0-taiwan" + SHARD_NODE_1_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-1-oregon" + SHARD_NODE_2_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-2-singapore" + + gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $TRACKER_ZONE + gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_0_ZONE + gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_1_ZONE + gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "sudo killall node" --project $PROJECT_ID --zone $NODE_2_ZONE + done fi fi @@ -323,7 +294,7 @@ printf "\n" printf "START_TRACKER_CMD_BASE=$START_TRACKER_CMD_BASE\n" printf "START_NODE_CMD_BASE=$START_NODE_CMD_BASE\n" -printf "\n\n###########################\n# Starting parent tracker #\n###########################\n\n" +printf "\n* >> Starting parent tracker (${TRACKER_TARGET_ADDR}) *********************************************************\n\n" printf "\n" printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" @@ -332,11 +303,8 @@ START_TRACKER_CMD="gcloud compute ssh $TRACKER_TARGET_ADDR --command '$START_TRA printf "START_TRACKER_CMD=$START_TRACKER_CMD\n" eval $START_TRACKER_CMD -NUM_NODES=10 -node_index=0 -while [ $node_index -lt $NUM_NODES ] -do - printf "\n\n##########################\n# Starting parent node $node_index #\n##########################\n\n" +for node_index in `seq 0 $(( $NUM_NODES - 1 ))`; do + printf "\n* >> Starting parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" if [[ $node_index -gt 4 ]]; then JSON_RPC_OPTION="--json-rpc" REST_FUNC_OPTION="--rest-func" @@ -359,70 +327,70 @@ do printf "START_NODE_CMD=$START_NODE_CMD\n" eval $START_NODE_CMD inject_account "$node_index" - ((node_index++)) done if [[ $NUM_SHARDS -gt 0 ]]; then - printf "\nDeploying shard blockchains..." - for i in $(seq $NUM_SHARDS) - do - printf "shard #$i\n" + for i in $(seq $NUM_SHARDS); do + printf "###############################################################################\n" + printf "# Deploying shard $i blockchain #\n" + printf "###############################################################################\n\n" - # generate genesis config files in ./blockchain/shard_$i - if [[ $SETUP_OPTION = "--setup" ]]; then - node ./tools/generateShardGenesisFiles.js $SEASON 10 $i - fi - SHARD_TRACKER_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-tracker-taiwan" - SHARD_NODE_0_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-0-taiwan" - SHARD_NODE_1_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-1-oregon" - SHARD_NODE_2_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-2-singapore" + # generate genesis config files in ./blockchain/shard_$i + if [[ $SETUP_OPTION = "--setup" ]]; then + node ./tools/generateShardGenesisFiles.js $SEASON 10 $i + fi - # deploy files to GCP instances - if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then - printf "\nDeploying files to shard_$i tracker (${SHARD_TRACKER_TARGET_ADDR})...\n\n" - gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $TRACKER_ZONE - gcloud compute scp --recurse $FILES_FOR_TRACKER ${SHARD_TRACKER_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $TRACKER_ZONE - printf "\nDeploying files to shard_$i node 0 (${SHARD_NODE_0_TARGET_ADDR})...\n\n" - gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_0_ZONE - gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_0_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_0_ZONE - printf "\nDeploying files to shard_$i node 1 (${SHARD_NODE_1_TARGET_ADDR})...\n\n" - gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_1_ZONE - gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_1_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_1_ZONE - printf "\nDeploying files to shard_$i node 2 (${SHARD_NODE_2_TARGET_ADDR})...\n\n" - gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_2_ZONE - gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_2_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_2_ZONE - fi - - # ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) - if [[ $SETUP_OPTION = "--setup" ]]; then - printf "\n\n###########################\n# Setting up shard_$i tracker #\n###########################\n\n" - gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE - printf "\n\n##########################\n# Setting up shard_$i node 0 #\n##########################\n\n" - gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_0_ZONE - printf "\n\n##########################\n# Setting up shard_$i node 1 #\n##########################\n\n" - gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_1_ZONE - printf "\n\n##########################\n# Setting up shard_$i node 2 #\n##########################\n\n" - gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_2_ZONE - fi - - # ssh into each instance, install packages and start up the server - printf "\n\n###########################\n# Starting shard_$i tracker #\n###########################\n\n" - START_TRACKER_CMD="gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command '$START_TRACKER_CMD_BASE $KEEP_CODE_OPTION' --project $PROJECT_ID --zone $TRACKER_ZONE" - printf "START_TRACKER_CMD=$START_TRACKER_CMD\n" - eval $START_TRACKER_CMD - printf "\n\n##########################\n# Starting shard_$i node 0 #\n##########################\n\n" - START_NODE_CMD="gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $SEASON $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION' --project $PROJECT_ID --zone $NODE_0_ZONE" - printf "START_NODE_CMD=$START_NODE_CMD\n" - eval $START_NODE_CMD - printf "\n\n##########################\n# Starting shard_$i node 1 #\n##########################\n\n" - START_NODE_CMD="gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $SEASON $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION' --project $PROJECT_ID --zone $NODE_1_ZONE" - printf "START_NODE_CMD=$START_NODE_CMD\n" - eval $START_NODE_CMD - printf "\n\n##########################\n# Starting shard_$i node 2 #\n##########################\n\n" - START_NODE_CMD="gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $SEASON $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION' --project $PROJECT_ID --zone $NODE_2_ZONE" - printf "START_NODE_CMD=$START_NODE_CMD\n" - eval $START_NODE_CMD - done + SHARD_TRACKER_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-tracker-taiwan" + SHARD_NODE_0_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-0-taiwan" + SHARD_NODE_1_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-1-oregon" + SHARD_NODE_2_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-node-2-singapore" + + # deploy files to GCP instances + if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then + printf "\n* >> Deploying files to shard_$i tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $TRACKER_ZONE + gcloud compute scp --recurse $FILES_FOR_TRACKER ${SHARD_TRACKER_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $TRACKER_ZONE + printf "\n* >> Deploying files to shard_$i node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_0_ZONE + gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_0_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_0_ZONE + printf "\n* >> Deploying files to shard_$i node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_1_ZONE + gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_1_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_1_ZONE + printf "\n* >> Deploying files to shard_$i node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $NODE_2_ZONE + gcloud compute scp --recurse $FILES_FOR_NODE ${SHARD_NODE_2_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $NODE_2_ZONE + fi + + # ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) + if [[ $SETUP_OPTION = "--setup" ]]; then + printf "\n* >> Setting up shard_$i tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $TRACKER_ZONE + printf "\n* >> Setting up shard_$i node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_0_ZONE + printf "\n* >> Setting up shard_$i node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_1_ZONE + printf "\n* >> Setting up shard_$i node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" + gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command ". setup_blockchain_ubuntu.sh" --project $PROJECT_ID --zone $NODE_2_ZONE + fi + + # ssh into each instance, install packages and start up the server + printf "\n* >> Starting shard_$i tracker (${SHARD_TRACKER_TARGET_ADDR}) *********************************************************\n\n" + START_TRACKER_CMD="gcloud compute ssh $SHARD_TRACKER_TARGET_ADDR --command '$START_TRACKER_CMD_BASE $KEEP_CODE_OPTION' --project $PROJECT_ID --zone $TRACKER_ZONE" + printf "START_TRACKER_CMD=$START_TRACKER_CMD\n" + eval $START_TRACKER_CMD + printf "\n* >> Starting shard_$i node 0 (${SHARD_NODE_0_TARGET_ADDR}) *********************************************************\n\n" + START_NODE_CMD="gcloud compute ssh $SHARD_NODE_0_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $SEASON $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION' --project $PROJECT_ID --zone $NODE_0_ZONE" + printf "START_NODE_CMD=$START_NODE_CMD\n" + eval $START_NODE_CMD + printf "\n* >> Starting shard_$i node 1 (${SHARD_NODE_1_TARGET_ADDR}) *********************************************************\n\n" + START_NODE_CMD="gcloud compute ssh $SHARD_NODE_1_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $SEASON $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION' --project $PROJECT_ID --zone $NODE_1_ZONE" + printf "START_NODE_CMD=$START_NODE_CMD\n" + eval $START_NODE_CMD + printf "\n* >> Starting shard_$i node 2 (${SHARD_NODE_2_TARGET_ADDR}) *********************************************************\n\n" + START_NODE_CMD="gcloud compute ssh $SHARD_NODE_2_TARGET_ADDR --command '$START_NODE_CMD_BASE $SEASON $SEASON $i 0 $KEEP_CODE_OPTION $KEEP_DATA_OPTION' --project $PROJECT_ID --zone $NODE_2_ZONE" + printf "START_NODE_CMD=$START_NODE_CMD\n" + eval $START_NODE_CMD + done fi diff --git a/deploy_blockchain_incremental_gcp.sh b/deploy_blockchain_incremental_gcp.sh index 178035041..70540ccec 100644 --- a/deploy_blockchain_incremental_gcp.sh +++ b/deploy_blockchain_incremental_gcp.sh @@ -78,8 +78,7 @@ KEEP_DATA_OPTION="--keep-data" SYNC_MODE_OPTION="--fast-sync" ARG_INDEX=6 -while [ $ARG_INDEX -le $# ] -do +while [ $ARG_INDEX -le $# ]; do parse_options "${!ARG_INDEX}" ((ARG_INDEX++)) done @@ -152,7 +151,7 @@ NODE_ZONE_LIST=( ) function deploy_tracker() { - printf "\n* >> Deploying tracker ********************************************************\n\n" + printf "\n* >> Deploying files for tracker ********************************************************\n\n" printf "TRACKER_TARGET_ADDR='$TRACKER_TARGET_ADDR'\n" printf "TRACKER_ZONE='$TRACKER_ZONE'\n" @@ -191,7 +190,7 @@ function deploy_node() { local node_target_addr=${NODE_TARGET_ADDR_LIST[${node_index}]} local node_zone=${NODE_ZONE_LIST[${node_index}]} - printf "\n* >> Deploying node $node_index *********************************************************\n\n" + printf "\n* >> Deploying files for node $node_index ($node_target_addr) *********************************************************\n\n" printf "node_target_addr='$node_target_addr'\n" printf "node_zone='$node_zone'\n" @@ -209,7 +208,7 @@ function deploy_node() { if [[ $SETUP_OPTION = "--setup" ]]; then # 2. Set up node printf "\n\n<<< Setting up node $node_index >>>\n\n" - SETUP_CMD="gcloud compute ssh $node_target_addr --command '. setup_blockchain_ubuntu.sh' --project $PROJECT_ID --zone $node_zone" + SETUP_CMD="gcloud compute ssh $node_target_addr --command 'cd ./ain-blockchain; . setup_blockchain_ubuntu.sh' --project $PROJECT_ID --zone $node_zone" printf "SETUP_CMD=$SETUP_CMD\n\n" eval $SETUP_CMD fi @@ -239,14 +238,14 @@ function deploy_node() { # 4. Inject node account if [[ $ACCOUNT_INJECTION_OPTION = "--keystore" ]]; then local node_ip_addr=${IP_ADDR_LIST[${node_index}]} - printf "\n* >> Initializing account for node $node_index ********************\n\n" + printf "\n* >> Initializing account for node $node_index ($node_target_addr) ********************\n\n" printf "node_ip_addr='$node_ip_addr'\n" echo $PASSWORD | node inject_account_gcp.js $node_ip_addr $ACCOUNT_INJECTION_OPTION elif [[ $ACCOUNT_INJECTION_OPTION = "--mnemonic" ]]; then local node_ip_addr=${IP_ADDR_LIST[${node_index}]} local MNEMONIC=${MNEMONIC_LIST[${node_index}]} - printf "\n* >> Injecting an account for node $node_index ********************\n\n" + printf "\n* >> Injecting an account for node $node_index ($node_target_addr) ********************\n\n" printf "node_ip_addr='$node_ip_addr'\n" { @@ -256,7 +255,7 @@ function deploy_node() { } | node inject_account_gcp.js $node_ip_addr $ACCOUNT_INJECTION_OPTION else local node_ip_addr=${IP_ADDR_LIST[${node_index}]} - printf "\n* >> Injecting an account for node $node_index ********************\n\n" + printf "\n* >> Injecting an account for node $node_index ($node_target_addr) ********************\n\n" printf "node_ip_addr='$node_ip_addr'\n" local GENESIS_ACCOUNTS_PATH="blockchain-configs/base/genesis_accounts.json" if [[ "$SEASON" = "spring" ]] || [[ "$SEASON" = "summer" ]]; then @@ -319,30 +318,27 @@ if [[ $begin_index -lt 0 ]]; then begin_index=0 fi if [[ $begin_index -le $END_PARENT_NODE_INDEX ]] && [[ $END_PARENT_NODE_INDEX -ge 0 ]]; then - for j in `seq $(( $begin_index )) $(( $END_PARENT_NODE_INDEX ))` - do - deploy_node "$j" - sleep 40 - done + for j in `seq $(( $begin_index )) $(( $END_PARENT_NODE_INDEX ))`; do + deploy_node "$j" + sleep 40 + done fi if [[ $NUM_SHARDS -gt 0 ]]; then - for i in $(seq $NUM_SHARDS) - do - printf "###############################################################################\n" - printf "# Deploying shard $i blockchain #\n" - printf "###############################################################################\n\n" - - TRACKER_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-tracker-taiwan" - NODE_TARGET_ADDR_LIST=( \ - "${GCP_USER}@${SEASON}-shard-${i}-node-0-taiwan" \ - "${GCP_USER}@${SEASON}-shard-${i}-node-1-oregon" \ - "${GCP_USER}@${SEASON}-shard-${i}-node-2-singapore") - - deploy_tracker "$NUM_SHARD_NODES" - for j in `seq 0 $(( ${NUM_SHARD_NODES} - 1 ))` - do - deploy_node "$j" - done + for i in $(seq $NUM_SHARDS); do + printf "###############################################################################\n" + printf "# Deploying shard $i blockchain #\n" + printf "###############################################################################\n\n" + + TRACKER_TARGET_ADDR="${GCP_USER}@${SEASON}-shard-${i}-tracker-taiwan" + NODE_TARGET_ADDR_LIST=( \ + "${GCP_USER}@${SEASON}-shard-${i}-node-0-taiwan" \ + "${GCP_USER}@${SEASON}-shard-${i}-node-1-oregon" \ + "${GCP_USER}@${SEASON}-shard-${i}-node-2-singapore") + + deploy_tracker "$NUM_SHARD_NODES" + for j in `seq 0 $(( ${NUM_SHARD_NODES} - 1 ))`; do + deploy_node "$j" + done done fi diff --git a/deploy_blockchain_sandbox_gcp.sh b/deploy_blockchain_sandbox_gcp.sh index 6bc76d396..1cc5e42be 100644 --- a/deploy_blockchain_sandbox_gcp.sh +++ b/deploy_blockchain_sandbox_gcp.sh @@ -64,8 +64,7 @@ KEEP_DATA_OPTION="--no-keep-data" KILL_OPTION="" ARG_INDEX=4 -while [ $ARG_INDEX -le $# ] -do +while [ $ARG_INDEX -le $# ]; do parse_options "${!ARG_INDEX}" ((ARG_INDEX++)) done @@ -320,8 +319,7 @@ else # kill any processes still alive printf "\nKilling all blockchain nodes...\n" index=$START_NODE_IDX - while [ $index -le $END_NODE_IDX ] - do + while [ $index -le $END_NODE_IDX ]; do NODE_TARGET_ADDR=NODE_${index}_TARGET_ADDR NODE_ZONE=NODE_${index}_ZONE @@ -348,8 +346,7 @@ fi if [[ $KEEP_CODE_OPTION = "--no-keep-code" ]]; then printf "\nDeploying parent blockchain...\n" index=$START_NODE_IDX - while [ $index -le $END_NODE_IDX ] - do + while [ $index -le $END_NODE_IDX ]; do NODE_TARGET_ADDR=NODE_${index}_TARGET_ADDR NODE_ZONE=NODE_${index}_ZONE @@ -372,8 +369,7 @@ fi if [[ $SETUP_OPTION = "--setup" ]]; then printf "\n\n##########################\n# Setting up blockchain nodes #\n##########################\n" index=$START_NODE_IDX - while [ $index -le $END_NODE_IDX ] - do + while [ $index -le $END_NODE_IDX ]; do NODE_TARGET_ADDR=NODE_${index}_TARGET_ADDR NODE_ZONE=NODE_${index}_ZONE @@ -413,8 +409,7 @@ printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n" printf "KEEP_DATA_OPTION=$KEEP_DATA_OPTION\n" node_index=$START_NODE_IDX -while [ $node_index -le $END_NODE_IDX ] -do +while [ $node_index -le $END_NODE_IDX ]; do printf "\n\n##########################\n# Starting parent node $node_index #\n##########################\n\n" if [[ $node_index -gt 4 ]]; then JSON_RPC_OPTION="--json-rpc" diff --git a/start_node_genesis_gcp.sh b/start_node_genesis_gcp.sh index f7fdbfee0..a11660326 100644 --- a/start_node_genesis_gcp.sh +++ b/start_node_genesis_gcp.sh @@ -66,8 +66,7 @@ JSON_RPC_OPTION="" REST_FUNC_OPTION="" ARG_INDEX=4 -while [ $ARG_INDEX -le $# ] -do +while [ $ARG_INDEX -le $# ]; do parse_options "${!ARG_INDEX}" ((ARG_INDEX++)) done diff --git a/start_node_incremental_gcp.sh b/start_node_incremental_gcp.sh index b64c0abc5..a253d7686 100644 --- a/start_node_incremental_gcp.sh +++ b/start_node_incremental_gcp.sh @@ -64,8 +64,7 @@ JSON_RPC_OPTION="" REST_FUNC_OPTION="" ARG_INDEX=4 -while [ $ARG_INDEX -le $# ] -do +while [ $ARG_INDEX -le $# ]; do parse_options "${!ARG_INDEX}" ((ARG_INDEX++)) done From c75c56ad973fc0e06622359b05fa43600a275cba Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Mon, 10 Jan 2022 01:31:11 +0900 Subject: [PATCH 20/21] Use ~/ain-blockchain directory for monitoring deploy --- deploy_blockchain_genesis_gcp.sh | 2 +- deploy_blockchain_sandbox_gcp.sh | 2 +- deploy_monitoring_gcp.sh | 12 ++++++------ setup_monitoring_gcp.sh | 13 ++++++------- 4 files changed, 14 insertions(+), 15 deletions(-) diff --git a/deploy_blockchain_genesis_gcp.sh b/deploy_blockchain_genesis_gcp.sh index 42ee8fa75..1363817c2 100644 --- a/deploy_blockchain_genesis_gcp.sh +++ b/deploy_blockchain_genesis_gcp.sh @@ -246,7 +246,7 @@ else NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR NODE_ZONE=NODE_${node_index}_ZONE - printf "\n* >> Killing node $node_index job (${!NODE_TARGET_ADDR}) *********************************************************\n\n" + printf "\n* >> Killing node $node_index job (${!NODE_TARGET_ADDR}) *********************************************************\n\n" gcloud compute ssh ${!NODE_TARGET_ADDR} --command "sudo killall node" --project $PROJECT_ID --zone ${!NODE_ZONE} done diff --git a/deploy_blockchain_sandbox_gcp.sh b/deploy_blockchain_sandbox_gcp.sh index 1cc5e42be..e0200413d 100644 --- a/deploy_blockchain_sandbox_gcp.sh +++ b/deploy_blockchain_sandbox_gcp.sh @@ -76,7 +76,7 @@ printf "KILL_OPTION=$KILL_OPTION\n" # Get confirmation. printf "\n" -read -p "Do you want to proceed? >> (y/N) " -n 1 -r +read -p "Do you want to proceed for $SEASON? [y/N]: " -n 1 -r printf "\n\n" if [[ ! $REPLY =~ ^[Yy]$ ]] then diff --git a/deploy_monitoring_gcp.sh b/deploy_monitoring_gcp.sh index 670b30217..c1d0610b6 100644 --- a/deploy_monitoring_gcp.sh +++ b/deploy_monitoring_gcp.sh @@ -32,10 +32,9 @@ printf "OPTIONS=$OPTIONS\n" # Get confirmation. printf "\n" -read -p "Do you want to proceed? >> (y/N) " -n 1 -r +read -p "Do you want to proceed for $SEASON? [y/N]: " -n 1 -r printf "\n\n" -if [[ ! $REPLY =~ ^[Yy]$ ]] -then +if [[ ! $REPLY =~ ^[Yy]$ ]]; then [[ "$0" = "$BASH_SOURCE" ]] && exit 1 || return 1 # handle exits from shell or function but don't exit interactive shell fi @@ -51,14 +50,15 @@ gcloud compute ssh $MONITORING_TARGET_ADDR --command "sudo killall grafana-serve # deploy files to GCP instances printf "\nDeploying monitoring..." printf "\nDeploying files to ${MONITORING_TARGET_ADDR}..." -gcloud compute scp --recurse $FILES_FOR_MONITORING ${MONITORING_TARGET_ADDR}:~/ --project $PROJECT_ID --zone $MONITORING_ZONE +gcloud compute ssh ${MONITORING_TARGET_ADDR} --command "sudo rm -rf ~/ain-blockchain; sudo mkdir ~/ain-blockchain; sudo chmod -R 777 ~/ain-blockchain" --project $PROJECT_ID --zone $MONITORING_ZONE +gcloud compute scp --recurse $FILES_FOR_MONITORING ${MONITORING_TARGET_ADDR}:~/ain-blockchain/ --project $PROJECT_ID --zone $MONITORING_ZONE # ssh into each instance, set up the ubuntu VM instance (ONLY NEEDED FOR THE FIRST TIME) if [[ $OPTIONS = "--setup" ]]; then printf "\n\n##########################\n# Setting up monitoring #\n###########################\n\n" - gcloud compute ssh $MONITORING_TARGET_ADDR --command ". setup_monitoring_ubuntu.sh" --project $PROJECT_ID + gcloud compute ssh $MONITORING_TARGET_ADDR --command "cd ./ain-blockchain; . setup_monitoring_ubuntu.sh" --project $PROJECT_ID fi # ssh into each instance, install packages and start up the server printf "\n\n############################\n# Running monitoring #\n############################\n\n" -gcloud compute ssh $MONITORING_TARGET_ADDR --command ". setup_monitoring_gcp.sh ${SEASON} && . start_monitoring_gcp.sh" --project $PROJECT_ID --zone $MONITORING_ZONE +gcloud compute ssh $MONITORING_TARGET_ADDR --command "cd ./ain-blockchain; . setup_monitoring_gcp.sh ${SEASON} && . start_monitoring_gcp.sh" --project $PROJECT_ID --zone $MONITORING_ZONE diff --git a/setup_monitoring_gcp.sh b/setup_monitoring_gcp.sh index 37359eabf..58f840ed6 100644 --- a/setup_monitoring_gcp.sh +++ b/setup_monitoring_gcp.sh @@ -22,13 +22,12 @@ killall grafana-server printf 'Setting up working directory..\n' -cd -sudo rm -rf ../ain-blockchain -sudo mkdir ../ain-blockchain -sudo chmod 777 ../ain-blockchain -mv * ../ain-blockchain -cd ../ain-blockchain - +sudo rm -rf /home/ain-blockchain +cd ~ +sudo mv ain-blockchain /home +sudo chmod -R 777 /home/ain-blockchain +sudo chown -R root:root /home/ain-blockchain +cd /home/ain-blockchain printf 'Installing Prometheus..\n' curl -s https://api.github.com/repos/prometheus/prometheus/releases/latest \ From f374ecce044c8a8bc6b74750f1cd06b854e8ec43 Mon Sep 17 00:00:00 2001 From: Dongil Seo Date: Mon, 10 Jan 2022 02:13:22 +0900 Subject: [PATCH 21/21] Fix messaging --- deploy_blockchain_genesis_gcp.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/deploy_blockchain_genesis_gcp.sh b/deploy_blockchain_genesis_gcp.sh index 1363817c2..73a2d5b69 100644 --- a/deploy_blockchain_genesis_gcp.sh +++ b/deploy_blockchain_genesis_gcp.sh @@ -304,7 +304,11 @@ printf "START_TRACKER_CMD=$START_TRACKER_CMD\n" eval $START_TRACKER_CMD for node_index in `seq 0 $(( $NUM_NODES - 1 ))`; do + NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR + NODE_ZONE=NODE_${node_index}_ZONE + printf "\n* >> Starting parent node $node_index (${!NODE_TARGET_ADDR}) *********************************************************\n\n" + if [[ $node_index -gt 4 ]]; then JSON_RPC_OPTION="--json-rpc" REST_FUNC_OPTION="--rest-func" @@ -312,8 +316,6 @@ for node_index in `seq 0 $(( $NUM_NODES - 1 ))`; do JSON_RPC_OPTION="" REST_FUNC_OPTION="" fi - NODE_TARGET_ADDR=NODE_${node_index}_TARGET_ADDR - NODE_ZONE=NODE_${node_index}_ZONE printf "ACCOUNT_INJECTION_OPTION=$ACCOUNT_INJECTION_OPTION\n" printf "KEEP_CODE_OPTION=$KEEP_CODE_OPTION\n"