Skip to content

Commit f66a2c9

Browse files
committed
fix code
1 parent 0890048 commit f66a2c9

File tree

4 files changed

+46
-32
lines changed

4 files changed

+46
-32
lines changed

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

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
import java.util.Collection;
3131
import java.util.concurrent.CompletableFuture;
3232

33-
public class Client{
33+
public class Client {
3434

3535
private static CopycatClient client = null;
3636

@@ -101,18 +101,20 @@ public static void putMessage1(Message message) {
101101
//System.out.println("Block: consensus success");
102102

103103
int i = 1;
104-
boolean f = true;
105-
while(f){
104+
final boolean[] f = {true};
105+
while (f[0]) {
106106
String block_key = "block" + i;
107107
Object block = client.submit(new GetQuery(block_key)).join();
108108
try {
109109
if (!(block == null)) {
110-
f =true;
111-
i = i+1;
112-
}else {
113-
client.submit(new PutCommand(block_key, message.getMessage()));
110+
System.out.println("1234");
111+
f[0] = true;
112+
i = i + 1;
113+
} else {
114+
client.submit(new PutCommand(block_key, message
115+
.getMessage()));
114116
System.out.println("Block: consensus success");
115-
f = false;
117+
f[0] = false;
116118
}
117119
} catch (NullPointerException e) {
118120
e.printStackTrace();
@@ -122,27 +124,30 @@ public static void putMessage1(Message message) {
122124
}
123125
}
124126

125-
public static void getMessage(Peer peer,String key) {
127+
public static void getMessage(Peer peer, String key) {
126128
final String[] preMessage = {null};
127129
final String[] preTime = {null};
128130
if (key.equals("transaction")) {
129131
Thread thread = new Thread(() -> {
130-
while(true){
132+
while (true) {
131133
Object time = client.submit(new GetQuery("time")).join();
132-
if(!time.toString().equals(preTime[0])) {
134+
if (!time.toString().equals(preTime[0])) {
133135
client.submit(new GetQuery(key)).thenAccept(transaction
134136
-> {
135-
//System.out.println("Consensus " + key + " is: " + result);
136-
//System.out.println("type: " + result.getClass().getSimpleName());
137-
peer.addReceiveTransaction(String.valueOf(transaction));
137+
//System.out.println("Consensus " + key + " is: "
138+
// + result);
139+
//System.out.println("type: " + result.getClass()
140+
// .getSimpleName());
141+
peer.addReceiveTransaction(String.valueOf
142+
(transaction));
138143
});
139144
preTime[0] = time.toString();
140-
}else {
145+
} else {
141146
preTime[0] = preTime[0];
142147
}
143148
try {
144149
Thread.sleep(3000);
145-
}catch (Exception e){
150+
} catch (Exception e) {
146151
e.printStackTrace();
147152
}
148153
}
@@ -152,34 +157,36 @@ public static void getMessage(Peer peer,String key) {
152157

153158
if (key.equals("block")) {
154159
Thread thread = new Thread(() -> {
155-
while(true){
160+
while (true) {
156161
int i = 1;
157-
boolean f = true;
162+
final boolean[] f = {true};
158163
String block_key;
159-
while(f){
164+
while (f[0]) {
160165
block_key = "block" + i;
161-
Object block = client.submit(new GetQuery(block_key)).join();
166+
Object block = client.submit(new GetQuery(block_key))
167+
.join();
162168
try {
163169
if (!(block == null)) {
164-
f =true;
165-
i = i+1;
166-
}else {
167-
f = false;
170+
f[0] = true;
171+
i = i + 1;
172+
} else {
173+
f[0] = false;
168174
}
169175
} catch (NullPointerException e) {
170176
e.printStackTrace();
171177
}
172178
}
173179

174-
i = i-1;
180+
i = i - 1;
175181
String finalBlock_key = "block" + i;
176-
client.submit(new GetQuery(finalBlock_key)).thenAccept(block -> {
182+
client.submit(new GetQuery(finalBlock_key)).thenAccept
183+
(block -> {
177184
/*System.out.println("Consensus " + key + " is: " +
178185
block);*/
179186
if (!String.valueOf(block).equals(preMessage[0])) {
180187
peer.addReceiveBlock(String.valueOf(block));
181188
preMessage[0] = String.valueOf(block);
182-
}else {
189+
} else {
183190
preMessage[0] = preMessage[0];
184191
}
185192
});
@@ -193,17 +200,19 @@ public static void getMessage(Peer peer,String key) {
193200
thread.start();
194201
}
195202
}
203+
196204
public static void loadBlock(Peer peer) {
197205
int i = 2;
198206
final boolean[] f = {true};
199207
while (f[0]) {
200208
String block_key = "block" + i;
201-
client.submit(new GetQuery(block_key)).thenAccept((Object block) -> {
209+
client.submit(new GetQuery(block_key)).thenAccept((Object block)
210+
-> {
202211
if (!(block == null)) {
203212
peer.addReceiveBlock(String.valueOf
204213
(block));
205214
f[0] = true;
206-
} else{
215+
} else {
207216
f[0] = false;
208217
}
209218
});

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,10 @@ public Blockchain(String address, String type) {
105105
.getHash()
106106
.toByteArray();
107107
blockDB.putData(LAST_HASH, lastHash);
108+
109+
this.lastHash = lastHash;
110+
this.currentHash = lastHash;
111+
108112
// put message to consensus
109113
if (type.equals(Peer.PEER_SERVER)) {
110114
String value = ByteArray.toHexString(genesisBlock.toByteArray());

src/main/resources/genesis.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"transaction": {
3-
"7e08ca9a5e2cc63bd305328aa56948c50b348c06": 10
3+
"c24d5c11412ea75c592fa8e0340dcac0c8238580": 10
44
},
55

66
"timestamp": "0",

src/main/resources/tron.conf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,6 @@ database-test {
1818
# Kafka
1919
kafka {
2020
host = "127.0.0.1"
21-
port = ":9092"
22-
}
21+
port = ":5000"
22+
}
23+

0 commit comments

Comments
 (0)