Skip to content

Commit 24cdcce

Browse files
committed
fix code
1 parent 0eb6c04 commit 24cdcce

File tree

6 files changed

+37
-39
lines changed

6 files changed

+37
-39
lines changed

src/main/java/org/tron/command/ConsensusCommand.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ public void getClient(Peer peer,String[] args) {
3737

3838
}
3939
public void loadBlock(Peer peer){
40-
System.out.println("BlockChain loadding ...");
41-
Client.loadBlock(peer);
40+
//System.out.println("BlockChain loading ...");
41+
//Client.loadBlock(peer);
4242
}
4343

4444
public void usage() {

src/main/java/org/tron/consensus/client/Client.java

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import org.tron.overlay.message.Message;
1010
import org.tron.overlay.message.Type;
1111
import org.tron.peer.Peer;
12+
13+
import java.net.InetAddress;
14+
import java.net.UnknownHostException;
1215
import java.util.Arrays;
1316
import java.util.Collection;
1417
import java.util.concurrent.CompletableFuture;
@@ -28,12 +31,12 @@ public class Client{
2831
client.serializer().register(PutCommand.class);
2932
client.serializer().register(GetQuery.class);
3033

31-
Collection<Address> cluster = Arrays.asList(
34+
/*Collection<Address> cluster = Arrays.asList(
3235
new Address("192.168.0.109", 5000)
3336
);
3437
CompletableFuture<CopycatClient> future = client.connect(cluster);
35-
future.join();
36-
/*InetAddress localhost = null;
38+
future.join();*/
39+
InetAddress localhost = null;
3740
try {
3841
localhost = InetAddress.getLocalHost();
3942
Collection<Address> cluster = Arrays.asList(
@@ -44,7 +47,7 @@ public class Client{
4447
future.join();
4548
} catch (UnknownHostException e) {
4649
e.printStackTrace();
47-
}*/
50+
}
4851
}
4952

5053
public static CopycatClient getClient() {
@@ -61,10 +64,6 @@ public static void putMessage(String[] args) {
6164
public static void getMessage1(String key) {
6265
Object result = client.submit(new GetQuery(key)).join();
6366
System.out.println("Consensus " + key + " is: " + result);
64-
// client.submit(new GetQuery(key)).thenAccept(result -> {
65-
// System.out.println("Consensus " + key + " is: " + result);
66-
// });
67-
6867
}
6968

7069
public static void putMessage1(Message message) {
@@ -121,15 +120,14 @@ public static void getMessage(Peer peer,String key) {
121120
-> {
122121
//System.out.println("Consensus " + key + " is: " + result);
123122
//System.out.println("type: " + result.getClass().getSimpleName());
124-
peer.addReceiveTransaction(String
125-
.valueOf(transaction));
123+
peer.addReceiveTransaction(String.valueOf(transaction));
126124
});
127125
preTime[0] = time.toString();
128126
}else {
129127
preTime[0] = preTime[0];
130128
}
131129
try {
132-
Thread.sleep(4000);
130+
Thread.sleep(3000);
133131
}catch (Exception e){
134132
e.printStackTrace();
135133
}
@@ -158,22 +156,21 @@ public static void getMessage(Peer peer,String key) {
158156
e.printStackTrace();
159157
}
160158
}
159+
161160
i = i-1;
162161
String finalBlock_key = "block" + i;
163-
164162
client.submit(new GetQuery(finalBlock_key)).thenAccept(block -> {
165163
/*System.out.println("Consensus " + key + " is: " +
166-
block);*/
164+
block);*/
167165
if (!String.valueOf(block).equals(preMessage[0])) {
168-
peer.addReceiveBlock(String.valueOf
169-
(block));
166+
peer.addReceiveBlock(String.valueOf(block));
170167
preMessage[0] = String.valueOf(block);
171168
}else {
172169
preMessage[0] = preMessage[0];
173170
}
174171
});
175172
try {
176-
Thread.sleep(4000);
173+
Thread.sleep(3000);
177174
} catch (Exception e) {
178175
e.printStackTrace();
179176
}

src/main/java/org/tron/consensus/server/Server.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,8 @@ public static void serverRun() {
4545
//server.join(cluster).join();
4646

4747
System.out.println("Server xxd: " + server.cluster().members());
48-
4948
CopycatServer.State state = server.state();
5049
System.out.println("Server state: " + state);
51-
server.onStateChange(state1 -> {
52-
if (state == CopycatServer.State.LEADER) {
53-
System.out.println("Server state: " + state);
54-
}
55-
});
56-
//server.context();
57-
5850
} catch (UnknownHostException e) {
5951
e.printStackTrace();
6052
}

src/main/java/org/tron/core/Blockchain.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public Blockchain(String address, String type) {
8888
.getHash()
8989
.toByteArray();
9090
blockDB.put(LAST_HASH, lastHash);
91-
// put message to consensus 2018/1/2
91+
// put message to consensus
9292
if (type.equals(Peer.PEER_SERVER)) {
9393
String value = ByteArray.toHexString(genesisBlock.toByteArray());
9494
Message message = new Message(value, Type.BLOCK);
@@ -170,7 +170,6 @@ public HashMap<String, TXOutputs> findUTXO() {
170170
}
171171
}
172172

173-
174173
TXOutputs outs = utxo.get(txid);
175174

176175
if (outs == null) {

src/main/java/org/tron/peer/Peer.java

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,26 +81,19 @@ private void init() {
8181

8282
private void initLoadBlock(){
8383
if (this.type.equals(Peer.PEER_NORMAL)){
84+
System.out.println("BlockChain loading ...");
8485
Client.loadBlock(this);
8586
}
8687
}
88+
8789
private void initBlockchian() {
8890
new ConsensusCommand().server();
8991
if (Blockchain.dbExists()) {
9092
blockchain = new Blockchain();
9193
} else {
9294
//blockchain = new Blockchain(ByteArray.toHexString(wallet.getAddress()));
93-
if (this.type.equals(Peer.PEER_SERVER)){
94-
System.out.println("peer-server");
95-
blockchain = new Blockchain(ByteArray.toHexString(wallet
96-
.getAddress()), this.type);
97-
}
98-
if (this.type.equals(Peer.PEER_NORMAL)){
99-
System.out.println("BlockChain loadding ...");
100-
blockchain = new Blockchain(ByteArray.toHexString(wallet
101-
.getAddress()), this.type);
102-
103-
}
95+
blockchain = new Blockchain(ByteArray.toHexString(wallet
96+
.getAddress()), this.type);
10497
}
10598
}
10699

src/test/resources/seednode.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"type": "FeatureCollection",
3+
"features": [{
4+
"type": "Feature",
5+
"properties": {
6+
"name": "Tron",
7+
"ID_0": 102,
8+
"ID_1": 18,
9+
"ISO": "HKG"
10+
},
11+
"geometry": {
12+
"type": "Polygon",
13+
"coordinates": [[[114.084511, 22.519991], [114.075668, 22.517466], [114.078194, 22.516203], [114.079460, 22.516623], [114.082825, 22.519150], [114.084511, 22.519991]]]
14+
},
15+
"nodeIP":"192.168.0.100"
16+
}]
17+
}

0 commit comments

Comments
 (0)