diff --git a/qa/SidechainTestFramework/scutil.py b/qa/SidechainTestFramework/scutil.py index 66481b2ece..5ed399c041 100755 --- a/qa/SidechainTestFramework/scutil.py +++ b/qa/SidechainTestFramework/scutil.py @@ -132,7 +132,7 @@ def launch_bootstrap_tool(command_name, json_parameters): raise Exception("Bootstrap tool error occurred") -def launch_db_tool(dirName, command_name, json_parameters): +def launch_db_tool(dirName, storageNames, command_name, json_parameters): ''' we use "blockchain" postfix for specifying the dataDir (see qa/resources/template.conf: dataDir = "%(DIRECTORY)s/sc_node%(NODE_NUMBER)s/blockchain" @@ -142,8 +142,8 @@ def launch_db_tool(dirName, command_name, json_parameters): json_param = json.dumps(json_parameters) java_ps = subprocess.Popen(["java", "-jar", os.getenv("SIDECHAIN_SDK", - "..") + "/tools/dbtool/target/sidechains-sdk-dbtools-0.5.0-SNAPSHOT.jar", - storagesPath, command_name, json_param], stdout=subprocess.PIPE) + "..") + "/tools/dbtool/target/sidechains-sdk-dbtools-0.4.0-SNAPSHOT.jar", + storagesPath, storageNames, command_name, json_param], stdout=subprocess.PIPE) db_tool_output = java_ps.communicate()[0] try: jsone_node = json.loads(db_tool_output) diff --git a/qa/sc_storage_recovery_with_csw.py b/qa/sc_storage_recovery_with_csw.py index 4cfe71b9d2..d4f0baaebe 100644 --- a/qa/sc_storage_recovery_with_csw.py +++ b/qa/sc_storage_recovery_with_csw.py @@ -54,13 +54,14 @@ """ WITHDRAWAL_EPOCH_LENGTH = 10 +CUSTOM_STORAGE_NAMES = "appState1,appState2,appWallet1,appWallet2" def checkStoragesVersion(node, storages_list, expectedVersion): for name in storages_list: # get the last version of the storage json_params = {"storage": name} - ret = launch_db_tool(node.dataDir, "lastVersionID", json_params) + ret = launch_db_tool(node.dataDir, CUSTOM_STORAGE_NAMES, "lastVersionID", json_params) version = ret['version'] #print("{} --> {}".format(name, version)) # check we got the expected version @@ -71,13 +72,13 @@ def rollbackStorages(node, storages_list, numberOfVersionsToRollback): for name in storages_list: # get the version list up to the desired number json_params = {"storage": name, "numberOfVersionToRetrieve": numberOfVersionsToRollback} - versionsList = launch_db_tool(node.dataDir, "versionsList", json_params)["versionsList"] + versionsList = launch_db_tool(node.dataDir, CUSTOM_STORAGE_NAMES, "versionsList", json_params)["versionsList"] # get the target version to rollback to rollbackVersion = versionsList[-1] json_params = {"storage": name, "versionToRollback": rollbackVersion} print("...Rollbacking storage \"{}\" to version {}".format(name, rollbackVersion)) - ret = launch_db_tool(node.dataDir, "rollback", json_params) + ret = launch_db_tool(node.dataDir, CUSTOM_STORAGE_NAMES, "rollback", json_params) #print("{} --> {}".format(name, rollbackVersion)) # check that we did it correctly assert_equal(ret["versionCurrent"], rollbackVersion) @@ -183,7 +184,7 @@ def run_test(self): # Check that wallet forging stake has the same block id in the rollback versions and precisely # one commit behind json_params = {"storage": "walletForgingStake", "numberOfVersionToRetrieve": 2} - versionsList = launch_db_tool(sc_node2.dataDir, "versionsList", json_params)["versionsList"] + versionsList = launch_db_tool(sc_node2.dataDir, CUSTOM_STORAGE_NAMES, "versionsList", json_params)["versionsList"] assert_true(genesis_sc_block_id in versionsList) assert_equal(genesis_sc_block_id, versionsList[-1]) @@ -317,7 +318,7 @@ def run_test(self): checkStoragesVersion(sc_node2, ["wallet"], rolbackBlockVersionId) json_params = {"storage": "walletForgingStake", "numberOfVersionToRetrieve": 2} - versionsList = launch_db_tool(sc_node2.dataDir, "versionsList", json_params)["versionsList"] + versionsList = launch_db_tool(sc_node2.dataDir, CUSTOM_STORAGE_NAMES, "versionsList", json_params)["versionsList"] assert_true(rolbackBlockVersionId in versionsList) # -- wallet forging stake is ahead by one version assert_equal(rolbackBlockVersionId, versionsList[-1]) diff --git a/qa/sc_storage_recovery_without_csw.py b/qa/sc_storage_recovery_without_csw.py index 495ee78416..ad1d3e47c4 100644 --- a/qa/sc_storage_recovery_without_csw.py +++ b/qa/sc_storage_recovery_without_csw.py @@ -52,13 +52,13 @@ """ WITHDRAWAL_EPOCH_LENGTH = 10 - +CUSTOM_STORAGE_NAMES = "appState1,appState2,appWallet1,appWallet2" def checkStoragesVersion(node, storages_list, expectedVersion): for name in storages_list: # get the last version of the storage json_params = {"storage": name} - ret = launch_db_tool(node.dataDir, "lastVersionID", json_params) + ret = launch_db_tool(node.dataDir, CUSTOM_STORAGE_NAMES, "lastVersionID", json_params) version = ret['version'] # print("{} --> {}".format(name, version)) # check we got the expected version @@ -69,13 +69,13 @@ def rollbackStorages(node, storages_list, numberOfVersionsToRollback): for name in storages_list: # get the version list up to the desired number json_params = {"storage": name, "numberOfVersionToRetrieve": numberOfVersionsToRollback} - versionsList = launch_db_tool(node.dataDir, "versionsList", json_params)["versionsList"] + versionsList = launch_db_tool(node.dataDir, CUSTOM_STORAGE_NAMES, "versionsList", json_params)["versionsList"] # get the target version to rollback to rollbackVersion = versionsList[-1] json_params = {"storage": name, "versionToRollback": rollbackVersion} print("...Rollbacking storage \"{}\" to version {}".format(name, rollbackVersion)) - ret = launch_db_tool(node.dataDir, "rollback", json_params) + ret = launch_db_tool(node.dataDir, CUSTOM_STORAGE_NAMES, "rollback", json_params) # print("{} --> {}".format(name, rollbackVersion)) # check that we did it correctly assert_equal(ret["versionCurrent"], rollbackVersion) @@ -180,7 +180,7 @@ def run_test(self): # Check that wallet forging stake has the same block id in the rollback versions and precisely # one commit behind json_params = {"storage": "walletForgingStake", "numberOfVersionToRetrieve": 2} - versionsList = launch_db_tool(sc_node2.dataDir, "versionsList", json_params)["versionsList"] + versionsList = launch_db_tool(sc_node2.dataDir, CUSTOM_STORAGE_NAMES, "versionsList", json_params)["versionsList"] assert_true(genesis_sc_block_id in versionsList) assert_equal(genesis_sc_block_id, versionsList[-1]) @@ -298,7 +298,7 @@ def run_test(self): checkStoragesVersion(sc_node2, ["wallet"], rolbackBlockVersionId) json_params = {"storage": "walletForgingStake", "numberOfVersionToRetrieve": 2} - versionsList = launch_db_tool(sc_node2.dataDir, "versionsList", json_params)["versionsList"] + versionsList = launch_db_tool(sc_node2.dataDir, CUSTOM_STORAGE_NAMES, "versionsList", json_params)["versionsList"] assert_true(rolbackBlockVersionId in versionsList) # -- wallet forging stake is ahead by one version assert_equal(rolbackBlockVersionId, versionsList[-1]) diff --git a/tools/dbtool/src/main/java/com/horizen/DbTool.java b/tools/dbtool/src/main/java/com/horizen/DbTool.java index b24cc905fe..4ebb74ddfa 100644 --- a/tools/dbtool/src/main/java/com/horizen/DbTool.java +++ b/tools/dbtool/src/main/java/com/horizen/DbTool.java @@ -1,13 +1,13 @@ package com.horizen; -import java.io.File; -import java.util.*; -import com.horizen.settings.SettingsReader; import com.horizen.tools.utils.ConsolePrinter; import com.horizen.tools.utils.MessagePrinter; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import java.io.File; +import java.util.*; + public class DbTool { public static final Set storageNames = new HashSet<>(Arrays.asList( "secret", @@ -19,8 +19,7 @@ public class DbTool { "stateForgerBox", "stateUtxoMerkleTree", "history", - "consensusData", - "appState1", "appState2", "appWallet1", "appWallet2" // simple app tests + "consensusData" )); public static void main(String args[]) { @@ -35,6 +34,7 @@ public static void main(String args[]) { Logger log = LogManager.getLogger(com.horizen.DbTool.class); + // read database folder path from input arguments if (args.length == 0) { log.error("Please provide DB folder path as first parameter!"); return; @@ -45,12 +45,18 @@ public static void main(String args[]) { } String dataDirAbsolutePath = args[0]; + // read custom storage names list from input arguments + List customStorageNames = Arrays.asList(args[1].split(",")); + for(String customStorageName: customStorageNames) { + storageNames.add(customStorageName); + } + MessagePrinter printer = new ConsolePrinter(); DbToolCommandProcessor processor = new DbToolCommandProcessor(printer, dataDirAbsolutePath, log); - if(args.length > 1) + if(args.length > 2) try { - StringBuilder cmd = new StringBuilder(args[1]); - for(int i=2; i []\n" + + "\tFrom command line: []\n" + "\tFor interactive mode: []\n" + "\tRead command arguments from file: -f \n" + "Supported commands:\n" +