Skip to content

Commit

Permalink
improve validator-engine-console error detection
Browse files Browse the repository at this point in the history
  • Loading branch information
neodix42 committed Oct 20, 2024
1 parent 76eedb4 commit 903f792
Show file tree
Hide file tree
Showing 9 changed files with 72 additions and 21 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/pre-release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Create pre-release [dev branch]
name: Create pre-release

on: [ workflow_dispatch ]

Expand All @@ -18,7 +18,6 @@ jobs:
run: |
mkdir artifacts
git fetch -a
git checkout dev
mvn clean compile package -DskipTests
cp target/MyLocalTon.jar artifacts/MyLocalTon-x86-64.jar
Expand All @@ -44,8 +43,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ github.run_number }}
release_name: MyLocalTon DEV v${{ github.run_number }}
draft: true
release_name: MyLocalTon v${{ github.run_number }}
draft: false
prerelease: true

- name: Upload binaries to pre-release
Expand All @@ -56,3 +55,4 @@ jobs:
tag: v${{ github.run_number }}
overwrite: true
file_glob: true
prerelease: true
4 changes: 2 additions & 2 deletions src/main/java/org/ton/actions/MyLocalTon.java
Original file line number Diff line number Diff line change
Expand Up @@ -741,7 +741,7 @@ public void runBlockchainMonitor(Node node) {

executorService.execute(() -> {
Thread.currentThread().setName("MyLocalTon - Dump Block " + prevBlockSeqno.get());
log.debug("Get last block");
// log.debug("Get last block");
ResultLastBlock lastBlock = LiteClientParser.parseLast(liteClient.executeLast(node));
// MasterChainInfo lastBlockM = tonlib.getLast(); // todo next release

Expand All @@ -760,7 +760,7 @@ public void runBlockchainMonitor(Node node) {
} else {
log.debug("last block is null");
}
log.debug("Thread is done {}", Thread.currentThread().getName());
// log.debug("Thread is done {}", Thread.currentThread().getName());
});

executorService.shutdown();
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/ton/db/DbPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,8 @@ public List<TxEntity> loadTxsBefore(long datetimeFrom) {
}

public void updateWalletStateAndSeqno(WalletEntity walletEntity, RawAccountState accountState, long seqno, WalletVersion walletVersion) {
log.debug("updating account state in db, {}, state {}", walletEntity.getFullAddress().toUpperCase(), accountState);
// log.debug("updating account state in db {}", walletEntity.getFullAddress().toUpperCase());
log.debug("updating account state in db");
try {

ExecutorService threadPoolService = Executors.newFixedThreadPool(allDBs.size());
Expand Down
30 changes: 22 additions & 8 deletions src/main/java/org/ton/executors/dhtserver/DhtServer.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.ton.actions.MyLocalTon;
import org.ton.executors.generaterandomid.RandomIdExecutor;
import org.ton.settings.Node;
import org.ton.utils.MyLocalTonUtils;
Expand Down Expand Up @@ -56,13 +57,13 @@ public List<String> initDhtServer(Node node) throws Exception {

Files.createDirectories(Paths.get(node.getDhtServerDir()));

log.info("Initializing DHT server"); // creating key in dht-server/keyring/hex and config.json
log.info("Initializing DHT server on node {}", node.getNodeName()); // creating key in dht-server/keyring/hex and config.json
Pair<Process, Future<String>> dhtServerInit = new DhtServerExecutor().execute(node,
"-v", MyLocalTonUtils.getTonLogLevel(node.getTonLogLevel()),
"-t", "1",
"-C", EXAMPLE_GLOBAL_CONFIG,
"-l", node.getDhtServerDir() + MyLocalTonUtils.toUtcNoSpace(System.currentTimeMillis()),
"-D", node.getDhtServerDir(),
"--verbosity", MyLocalTonUtils.getTonLogLevel(node.getTonLogLevel()),
"--threads", "4",
"--global-config", EXAMPLE_GLOBAL_CONFIG,
"--logname", node.getDhtServerDir() + MyLocalTonUtils.toUtcNoSpace(System.currentTimeMillis()),
"--db", node.getDhtServerDir(),
"-I", node.getPublicIp() + ":" + node.getDhtPort());

log.debug("dht-server result: {}", dhtServerInit.getRight().get()); // wait for process to exit
Expand All @@ -83,6 +84,17 @@ public List<String> initDhtServer(Node node) throws Exception {
}
}

public void copyDhtServersFromGenesisGlobalConfig(String myGlobalConfigLocation) throws IOException {
String globalConfigContent = FileUtils.readFileToString(new File(MyLocalTon.getInstance().getSettings().getGenesisNode().getNodeGlobalConfigLocation()), StandardCharsets.UTF_8);
String myConfigContent = FileUtils.readFileToString(new File(myGlobalConfigLocation), StandardCharsets.UTF_8);
log.debug("Replace current list of dht nodes with a new one");
String myNodes = MyLocalTonUtils.sbb( myConfigContent, "\"nodes\": [");
String globalNodes = MyLocalTonUtils.sbb( globalConfigContent, "\"nodes\": [");
String replacedLocalConfig = StringUtils.replace(myConfigContent, myNodes, globalNodes);
FileUtils.writeStringToFile(new File(myGlobalConfigLocation), replacedLocalConfig, StandardCharsets.UTF_8);
// log.debug("dht-nodes updated: {}", Files.readString(Paths.get(myGlobalConfig), StandardCharsets.UTF_8));
}

/**
* Adds dht nodes into "nodes:[]" structure inside my-ton-global.config.json
*
Expand All @@ -101,13 +113,15 @@ public void addDhtNodesToGlobalConfig(List<String> dhtNodes, String myGlobalConf
log.debug("Replace NODES placeholder with dht-server entry");
String replaced = StringUtils.replace(globalConfigContent, "\"nodes\": []", "\"nodes\": [" + String.join(",", dhtNodes) + "]");
FileUtils.writeStringToFile(new File(myGlobalConfig), replaced, StandardCharsets.UTF_8);
log.debug("dht-nodes added: {}", Files.readString(Paths.get(myGlobalConfig), StandardCharsets.UTF_8));
// log.debug("dht-nodes added {}", Files.readString(Paths.get(myGlobalConfig), StandardCharsets.UTF_8));
log.debug("dht-nodes added");
} else { // modify existing
log.debug("Replace current list of dht nodes with a new one");
String existingNodes = MyLocalTonUtils.sbb(globalConfigContent, "\"nodes\": [");
String replacedLocalConfig = StringUtils.replace(globalConfigContent, existingNodes, StringUtils.substring(existingNodes, 0, -1) + "," + String.join(",", dhtNodes) + "]");
FileUtils.writeStringToFile(new File(myGlobalConfig), replacedLocalConfig, StandardCharsets.UTF_8);
log.debug("dht-nodes updated: {}", Files.readString(Paths.get(myGlobalConfig), StandardCharsets.UTF_8));
// log.debug("dht-nodes updated: {}", Files.readString(Paths.get(myGlobalConfig), StandardCharsets.UTF_8));
log.debug("dht-nodes updated");
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/ton/executors/fift/Fift.java
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ public void signValidatorElectionRequest(Node node, long startElectionTime, BigD
signatureFromElectionRequest);

String resultStr = result.getRight().get();
log.debug(resultStr); // make debug
// log.debug(resultStr); // make debug

resultStr = resultStr.replace("\r\n", SPACE).replace("\n", SPACE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,8 @@ private boolean generateZeroState(Node node) throws IOException {

String createStateResult = new CreateStateExecutor().execute(node, node.getTonBinDir() + "smartcont" + File.separator + "gen-zerostate.fif");

log.debug("creating zero-state output: {}", createStateResult);
// log.debug("creating zero-state output: {}", createStateResult);
log.debug("creating zero-state output");

String mainWalletAddrBoth = sb(createStateResult, "wallet address = ", "(Saving address to file");
String electorSmcAddrBoth = sb(createStateResult, "elector smart contract address = ", "(Saving address to file");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,37 @@ public void getStats(Node node) throws ExecutionException, InterruptedException
ValidatorEngineConsoleExecutor validatorConsole = new ValidatorEngineConsoleExecutor();
Pair<Process, Future<String>> result = validatorConsole.execute(node, "-k", node.getTonBinDir() + "certs" + File.separator + "client", "-p", node.getTonBinDir() + "certs" + File.separator + "server.pub", "-v", "0", "-a", node.getPublicIp() + ":" + node.getConsolePort().toString(), "-rc", "getstats");
log.debug(result.getRight().get());
if(!result.getRight().get().contains("conn ready")) {
throw new Error("validator-engine-console on "+node.getNodeName()+" cannot importf");
}
}

public void importF(Node node, String validatorIdHex) throws ExecutionException, InterruptedException {
ValidatorEngineConsoleExecutor validatorConsole = new ValidatorEngineConsoleExecutor();
Pair<Process, Future<String>> result = validatorConsole.execute(node, "-k", node.getTonBinDir() + "certs" + File.separator + "client", "-p", node.getTonBinDir() + "certs" + File.separator + "server.pub", "-v", "0", "-a", node.getPublicIp() + ":" + node.getConsolePort().toString(), "-rc", "importf " + node.getTonDbKeyringDir() + validatorIdHex);
log.debug(result.getRight().get());
if(!result.getRight().get().contains("conn ready")) {
throw new Error("validator-engine-console on "+node.getNodeName()+" cannot importf");
}
}

public void changeFullNodeAddr(Node node, String newNodeKey) throws ExecutionException, InterruptedException {
ValidatorEngineConsoleExecutor validatorConsole = new ValidatorEngineConsoleExecutor();
Pair<Process, Future<String>> result = validatorConsole.execute(node, "-k", node.getTonBinDir() + "certs" + File.separator + "client", "-p", node.getTonBinDir() + "certs" + File.separator + "server.pub", "-v", "0", "-a", node.getPublicIp() + ":" + node.getConsolePort().toString(), "-rc", "changefullnodeaddr " + newNodeKey);
log.debug(result.getRight().get());
if(!result.getRight().get().contains("conn ready")) {
throw new Error("validator-engine-console on "+node.getNodeName()+" cannot changefullnodeaddr");
}
}

public void addValidatorAddr(Node node, String validatorIdHex, String newValAdnl, long electionEnd) throws ExecutionException, InterruptedException {
log.debug("{} add validator addr", node.getNodeName());
ValidatorEngineConsoleExecutor validatorConsole = new ValidatorEngineConsoleExecutor();
Pair<Process, Future<String>> result = validatorConsole.execute(node, "-k", node.getTonBinDir() + "certs" + File.separator + "client", "-p", node.getTonBinDir() + "certs" + File.separator + "server.pub", "-v", "0", "-a", node.getPublicIp() + ":" + node.getConsolePort().toString(), "-rc", "addvalidatoraddr " + validatorIdHex + " " + newValAdnl + " " + electionEnd);
log.debug(result.getRight().get());
if(!result.getRight().get().contains("conn ready")) {
throw new Error("validator-engine-console on "+node.getNodeName()+" cannot addvalidatoraddr");
}
log.debug("{} added validator addr", node.getNodeName());
}

Expand All @@ -42,6 +54,9 @@ public void addPermKey(Node node, String validatorIdHex, long electionId, long e
ValidatorEngineConsoleExecutor validatorConsole = new ValidatorEngineConsoleExecutor();
Pair<Process, Future<String>> result = validatorConsole.execute(node, "-k", node.getTonBinDir() + "certs" + File.separator + "client", "-p", node.getTonBinDir() + "certs" + File.separator + "server.pub", "-v", "0", "-a", node.getPublicIp() + ":" + node.getConsolePort().toString(), "-rc", "addpermkey " + validatorIdHex + " " + electionId + " " + electionEnd);
log.debug(result.getRight().get());
if(!result.getRight().get().contains("conn ready")) {
throw new Error("validator-engine-console on "+node.getNodeName()+" cannot permkey");
}
log.debug("{} added permkey", node.getNodeName());
}

Expand All @@ -50,13 +65,19 @@ public void addTempKey(Node node, String validatorIdHex, long electionEnd) throw
ValidatorEngineConsoleExecutor validatorConsole = new ValidatorEngineConsoleExecutor();
Pair<Process, Future<String>> result = validatorConsole.execute(node, "-k", node.getTonBinDir() + "certs" + File.separator + "client", "-p", node.getTonBinDir() + "certs" + File.separator + "server.pub", "-v", "0", "-a", node.getPublicIp() + ":" + node.getConsolePort().toString(), "-rc", "addtempkey " + validatorIdHex + " " + validatorIdHex + " " + electionEnd);
log.debug(result.getRight().get());
if(!result.getRight().get().contains("conn ready")) {
throw new Error("validator-engine-console on "+node.getNodeName()+" cannot tempkey");
}
log.debug("{} added tempkey", node.getNodeName());
}

public void addAdnl(Node node, String newValAdnl) throws ExecutionException, InterruptedException {
log.debug("{} add adnl", node.getNodeName());
Pair<Process, Future<String>> result = new ValidatorEngineConsoleExecutor().execute(node, "-k", node.getTonBinDir() + "certs" + File.separator + "client", "-p", node.getTonBinDir() + "certs" + File.separator + "server.pub", "-v", "0", "-a", node.getPublicIp() + ":" + node.getConsolePort().toString(), "-rc", "addadnl " + newValAdnl + " 0");
log.debug(result.getRight().get());
if(!result.getRight().get().contains("conn ready")) {
throw new Error("validator-engine-console on "+node.getNodeName()+" cannot addadnl");
}
log.debug("{} added adnl", node.getNodeName());
}

Expand All @@ -66,7 +87,6 @@ public String generateNewNodeKey(Node node) throws ExecutionException, Interrupt
log.debug(result.getRight().get());

if(!result.getRight().get().contains("created new key")) {
log.error("validator-engine-console on "+node.getNodeName()+" cannot create new key");
throw new Error("validator-engine-console on "+node.getNodeName()+" cannot create new key");
}

Expand All @@ -77,7 +97,9 @@ public String exportPubKey(Node node, String newkey) throws ExecutionException,
ValidatorEngineConsoleExecutor validatorConsole = new ValidatorEngineConsoleExecutor();
Pair<Process, Future<String>> result = validatorConsole.execute(node, "-k", node.getTonBinDir() + "certs" + File.separator + "client", "-p", node.getTonBinDir() + "certs" + File.separator + "server.pub", "-v", "0", "-a", node.getPublicIp() + ":" + node.getConsolePort().toString(), "-rc", "exportpub " + newkey);
log.debug(result.getRight().get());

if(!result.getRight().get().contains("conn ready")) {
throw new Error("validator-engine-console on "+node.getNodeName()+" cannot exportpub");
}
return result.getRight().get().substring(result.getRight().get().indexOf("got public key:") + 15).trim();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;

//@Component
@Slf4j
public class ValidatorEngineConsoleExecutor {

Expand All @@ -41,7 +40,7 @@ public Pair<Process, Future<String>> execute(Node node, String... command) {
p.waitFor(5, TimeUnit.SECONDS);
Future<String> future = executorService.submit(() -> {
try {
Thread.currentThread().setName("validator-engine-console" + node.getNodeName());
Thread.currentThread().setName("validator-engine-console " + node.getNodeName());

String resultInput = IOUtils.toString(p.getInputStream(), Charset.defaultCharset());
log.debug("{} stopped", "validator-engine-console " + node.getNodeName());
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/org/ton/main/App.java
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,21 @@ public static void main(MyLocalTonSettings settings, MyLocalTon myLocalTon, Stri

MyLocalTon.getInstance().createFullnode(node, true, true);

// DhtServer newDhtServer = new DhtServer();
// List<String> newDhtNodes = newDhtServer.initDhtServer(node);
// newDhtServer.addDhtNodesToGlobalConfig(newDhtNodes, genesisNode.getNodeGlobalConfigLocation());
// newDhtServer.startDhtServer(node, node.getNodeLocalConfigLocation());

settings.getActiveNodes().add(node.getNodeName());

// for (int x = 2; x <= 7; x++) {
// Node nodeTemp = settings.getNodeByName("node" + x);
// if (settings.getActiveNodes().contains(nodeTemp.getNodeName())) {
// newDhtServer.copyDhtServersFromGenesisGlobalConfig(nodeTemp.getNodeLocalConfigLocation());
// newDhtServer.copyDhtServersFromGenesisGlobalConfig(nodeTemp.getNodeGlobalConfigLocation());
// }
// }

MyLocalTon.getInstance().saveSettingsToGson();

log.info("Creating new validator controlling smart-contract (wallet) for node {}", node.getNodeName());
Expand Down

0 comments on commit 903f792

Please sign in to comment.