Visitar URL original
feat(framework): remove --keystore-factory support from FullNode by 0xbigapple · Pull Request #6978 · tronprotocol/java-tron · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -175,12 +175,6 @@ public class CommonParameter {
@Setter
public boolean solidityNode = false;

// If you are running KeystoreFactory,
// this flag is set to true
@Getter
@Setter
public boolean keystoreFactory = false;

// -- RPC / HTTP --
@Getter
@Setter
Expand Down
25 changes: 4 additions & 21 deletions crypto/src/main/java/org/tron/keystore/WalletUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,10 @@ public static boolean passwordValid(String password) {

/**
* Lazily-initialized Scanner shared across successive
* {@link #inputPassword()} calls on the non-TTY path so that
* {@link #inputPassword2Twice()} can read two lines in sequence
* without losing data. Each call to {@code new Scanner(System.in)}
* internally buffers bytes from the underlying {@link BufferedReader};
* constructing a second Scanner after the first has been discarded
* drops any buffered bytes the first pulled from stdin, causing
* {@code NoSuchElementException}.
* {@link #inputPassword()} calls on the non-TTY path. Each call to
* {@code new Scanner(System.in)} buffers ahead from stdin; constructing
* a second Scanner after the first has been discarded drops any bytes
* the first pulled, causing {@code NoSuchElementException}.
*/
private static Scanner sharedStdinScanner;

Expand Down Expand Up @@ -250,18 +247,4 @@ public static String inputPassword() {
}
}

public static String inputPassword2Twice() {
String password0;
while (true) {
System.out.println("Please input password.");
password0 = inputPassword();
System.out.println("Please input password again.");
String password1 = inputPassword();
if (password0.equals(password1)) {
break;
}
System.out.println("Two passwords do not match, please input again.");
}
return password0;
}
}
6 changes: 2 additions & 4 deletions framework/src/main/java/org/tron/core/config/args/Args.java
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public static void setParam(final String[] args, final String confFileName) {
Args.printHelp(jc);
exit(0);
}
cmd.validateRemovedOptions();

Comment thread
317787106 marked this conversation as resolved.
Resolved
// Resolve config file path
configFilePath = StringUtils.isNoneBlank(cmd.shellConfFileName)
Expand Down Expand Up @@ -856,9 +857,6 @@ private static void applyCLIParams(CLIParameter cmd, JCommander jc) {
if (assigned.contains("--solidity")) {
PARAMETER.solidityNode = cmd.solidityNode;
}
if (assigned.contains("--keystore-factory")) {
PARAMETER.keystoreFactory = cmd.keystoreFactory;
}
if (assigned.contains("--rpc-thread")) {
PARAMETER.rpcThreadNum = cmd.rpcThreadNum;
}
Expand Down Expand Up @@ -1290,7 +1288,7 @@ private static String getCommitIdAbbrev() {

private static Map<String, String[]> getOptionGroup() {
String[] tronOption = new String[] {"version", "help", "shellConfFileName", "logbackPath",
"eventSubscribe", "solidityNode", "keystoreFactory"};
"eventSubscribe", "solidityNode"};
String[] dbOption = new String[] {"outputDirectory"};
String[] witnessOption = new String[] {"witness", "privateKey"};
String[] vmOption = new String[] {"debug"};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.ArrayList;
import java.util.List;
import lombok.NoArgsConstructor;
import org.tron.core.exception.TronError;

/**
* CLI parameter definitions parsed by JCommander.
Expand Down Expand Up @@ -50,8 +51,15 @@ public class CLIParameter {
@Parameter(names = {"--solidity"}, description = "running a solidity node for java tron")
public boolean solidityNode;

@Parameter(names = {"--keystore-factory"}, description = "running KeystoreFactory")
public boolean keystoreFactory;
/**
* Tombstone for the removed --keystore-factory, rejected by {@link #validateRemovedOptions()}.
* Keep declared — undeclared, JCommander parses the flag into seedNodes. Boxed so null means
* absent: JCommander toggles arity-0 booleans per occurrence, so a repeated flag parses back
* to false.
*/
@Deprecated
@Parameter(names = {"--keystore-factory"}, description = "removed; use Toolkit.jar keystore")
public Boolean keystoreFactory;

@Deprecated
@Parameter(names = {"--fast-forward"})
Expand Down Expand Up @@ -181,4 +189,23 @@ public class CLIParameter {
@Deprecated
@Parameter(names = {"--history-balance-lookup"})
public boolean historyBalanceLookup;

/**
* Rejects removed options before config loading. A removed option keeps a nullable tombstone
* field and adds one line here.
*/
public void validateRemovedOptions() {
rejectIfPresent(keystoreFactory, "--keystore-factory",
"Use: java -jar Toolkit.jar keystore <new|import|list|update>");
}

private void rejectIfPresent(Object value, String option, String migration) {
if (value == null) {
return;
}
// stderr, not logger: the default logback config has no console appender
System.err.println(option + " was removed.");
System.err.println(migration);
throw new TronError(option + " was removed. " + migration, TronError.ErrCode.PARAMETER_INIT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ public static LocalWitnesses initFromKeystore(
"Tip: keystores created via `FullNode.jar --keystore-factory` in "
+ "non-TTY mode were encrypted with only the first "
+ "whitespace-separated word of the password. Try restarting "
+ "with only that first word as `-p`, then reset the password "
+ "via `java -jar Toolkit.jar keystore update`.");
+ "with only that first word as the password, then reset the "
+ "password via `java -jar Toolkit.jar keystore update`.");
}
throw new TronError(e, TronError.ErrCode.WITNESS_KEYSTORE_LOAD);
}
Expand Down
4 changes: 0 additions & 4 deletions framework/src/main/java/org/tron/program/FullNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,6 @@ public static void main(String[] args) {

LogService.load(parameter.getLogbackPath());

if (parameter.isKeystoreFactory()) {
KeystoreFactory.start();
return;
}
if (parameter.isSolidityNode()) {
logger.info("Solidity node is running.");
if (StringUtils.isEmpty(parameter.getTrustNodeAddr())) {
Expand Down
157 changes: 0 additions & 157 deletions framework/src/main/java/org/tron/program/KeystoreFactory.java

This file was deleted.

51 changes: 48 additions & 3 deletions framework/src/test/java/org/tron/core/config/args/ArgsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,16 @@
import com.typesafe.config.ConfigFactory;
import io.grpc.internal.GrpcUtil;
import io.grpc.netty.NettyServerBuilder;
import java.io.ByteArrayOutputStream;
import java.io.PrintStream;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import lombok.extern.slf4j.Slf4j;
import org.junit.After;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -53,9 +56,53 @@ public class ArgsTest {
@Rule
public ExpectedException thrown = ExpectedException.none();

@After
public void tearDown() {
Args.clearParam();
}

@Test
public void testRemovedKeystoreFactoryExitsWithMigrationGuidance() throws Exception {
ByteArrayOutputStream errorOutput = new ByteArrayOutputStream();
PrintStream capturedError = new PrintStream(errorOutput, true, "UTF-8");
PrintStream originalError = System.err;

try {
System.setErr(capturedError);

TronError exception = Assert.assertThrows(TronError.class,
() -> Args.setParam(new String[] {"--keystore-factory"}, TestConstants.TEST_CONF));

Assert.assertEquals(TronError.ErrCode.PARAMETER_INIT, exception.getErrCode());
} finally {
System.setErr(originalError);
capturedError.close();
}

String errorMessage = errorOutput.toString("UTF-8");
Assert.assertTrue(errorMessage.contains("--keystore-factory was removed."));
Assert.assertTrue(errorMessage.contains("Toolkit.jar keystore <new|import|list|update>"));
}

@Test
public void testRemovedKeystoreFactoryRepeatedFlagStillExits() {
Assert.assertThrows(TronError.class,
() -> Args.setParam(new String[] {"--keystore-factory", "--keystore-factory"},
TestConstants.TEST_CONF));
}

@Test
public void testRemovedKeystoreFactoryTakesPrecedenceOverInvalidConfig() {
TronError exception = Assert.assertThrows(TronError.class,
() -> Args.setParam(new String[] {"--keystore-factory", "-c", "no-such-file.conf"},
TestConstants.TEST_CONF));

Assert.assertEquals(TronError.ErrCode.PARAMETER_INIT, exception.getErrCode());
}

@Test
public void get() {
Args.setParam(new String[] {"--keystore-factory"}, TestConstants.TEST_CONF);
Args.setParam(new String[] {}, TestConstants.TEST_CONF);

CommonParameter parameter = Args.getInstance();

Expand Down Expand Up @@ -127,8 +174,6 @@ public void get() {
Assert.assertEquals(address,
ByteArray.toHexString(Args.getLocalWitnesses()
.getWitnessAccountAddress()));

Assert.assertTrue(parameter.isKeystoreFactory());
}

@Test
Expand Down
Loading
Loading