Skip to content

Commit

Permalink
Merge pull request tronprotocol#5011 from lurais/feature/auto_stop_opt
Browse files Browse the repository at this point in the history
feat(db): optimize the auto-stop logic
  • Loading branch information
halibobo1205 authored Mar 15, 2023
2 parents ecbb194 + 53ddc27 commit 0cb97fe
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,11 @@ public class CommonParameter {
public GenesisBlock genesisBlock;
@Getter
@Setter
@Parameter(names = {"--p2p-disable"}, description = "Switch for p2p module initialization. "
+ "(defalut: false)", arity = 1)
public boolean p2pDisable = false;
@Getter
@Setter
public List<InetSocketAddress> activeNodes;
@Getter
@Setter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void initServices(CommonParameter parameter) {
* start up the app.
*/
public void startup() {
if (!Args.getInstance().isSolidityNode()) {
if ((!Args.getInstance().isSolidityNode()) && (!Args.getInstance().isP2pDisable())) {
tronNetService.start();
}
consensusService.start();
Expand All @@ -67,7 +67,7 @@ public void startup() {
@Override
public void shutdown() {
logger.info("******** start to shutdown ********");
if (!Args.getInstance().isSolidityNode()) {
if (!Args.getInstance().isSolidityNode() && (!Args.getInstance().p2pDisable)) {
tronNetService.close();
}
consensusService.stop();
Expand Down
16 changes: 9 additions & 7 deletions framework/src/main/java/org/tron/core/Wallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -2639,13 +2639,15 @@ public TransactionInfoList getTransactionInfoByBlockNum(long blockNum) {

public NodeList listNodes() {
NodeList.Builder nodeListBuilder = NodeList.newBuilder();
TronNetService.getP2pService().getConnectableNodes().forEach(node -> {
nodeListBuilder.addNodes(Node.newBuilder().setAddress(
Address.newBuilder()
.setHost(ByteString
.copyFrom(ByteArray.fromString(node.getHost())))
.setPort(node.getPort())));
});
if (!Args.getInstance().p2pDisable) {
TronNetService.getP2pService().getConnectableNodes().forEach(node -> {
nodeListBuilder.addNodes(Node.newBuilder().setAddress(
Address.newBuilder()
.setHost(ByteString
.copyFrom(ByteArray.fromString(node.getHost())))
.setPort(node.getPort())));
});
}
return nodeListBuilder.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ public static void clearParam() {
PARAMETER.allowNewRewardAlgorithm = 0;
PARAMETER.allowNewReward = 0;
PARAMETER.memoFee = 0;
PARAMETER.p2pDisable = false;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion framework/src/main/java/org/tron/core/db/Manager.java
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ private void initAutoStop() {
exitCount, blockTime));
}

if (exitHeight == headNum) {
if (exitHeight == headNum && (!Args.getInstance().isP2pDisable())) {
logger.info("Auto-stop hit: shutDownBlockHeight: {}, currentHeaderNum: {}, exit now",
exitHeight, headNum);
System.exit(0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1736,14 +1736,7 @@ public void getTransactionCountByBlockNum(NumberMessage request,

@Override
public void listNodes(EmptyMessage request, StreamObserver<NodeList> responseObserver) {
NodeList.Builder nodeListBuilder = NodeList.newBuilder();
TronNetService.getP2pService().getConnectableNodes().forEach(node -> {
nodeListBuilder.addNodes(Node.newBuilder().setAddress(
Address.newBuilder()
.setHost(ByteString.copyFrom(ByteArray.fromString(node.getHost())))
.setPort(node.getPort())));
});
responseObserver.onNext(nodeListBuilder.build());
responseObserver.onNext(wallet.listNodes());
responseObserver.onCompleted();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class ArgsTest {

@Before
public void init() {
Args.setParam(new String[]{"--output-directory", "output-directory", "--debug"},
Constant.TEST_CONF);
Args.setParam(new String[]{"--output-directory", "output-directory", "--p2p-disable", "true",
"--debug"}, Constant.TEST_CONF);
}

@After
Expand All @@ -30,5 +30,6 @@ public void testConfig() {
Assert.assertEquals(Args.getInstance().getNodeDiscoveryPingTimeout(), 15_000);
Assert.assertEquals(Args.getInstance().getMaxFastForwardNum(), 3);
Assert.assertEquals(Args.getInstance().getBlockCacheTimeout(), 60);
Assert.assertEquals(Args.getInstance().p2pDisable, true);
}
}

0 comments on commit 0cb97fe

Please sign in to comment.