Skip to content

Commit 83837ff

Browse files
committed
refactor: modify private key length and account
1 parent 0906d7c commit 83837ff

15 files changed

Lines changed: 516 additions & 306 deletions

File tree

‎src/main/java/org/tron/core/config/Parameter.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ interface ChainConstant {
1212
int BLOCK_PRODUCED_INTERVAL = 3; // 3sec
1313

1414
double SOLIDIFIED_THRESHOLD = 0.3;
15+
int PRIVATE_KEY_LENGTH = 64;
1516
}
1617

1718
interface NodeConstant {

‎src/main/java/org/tron/core/config/args/Args.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.tron.core.Constant;
3737
import org.tron.core.Wallet;
3838
import org.tron.core.config.Configuration;
39+
import org.tron.core.config.Parameter.ChainConstant;
3940
import org.tron.core.db.AccountStore;
4041

4142
@Slf4j
@@ -378,7 +379,7 @@ private static List<Node> nodeActive(final com.typesafe.config.Config config) {
378379
private static void privateKey(final com.typesafe.config.Config config) {
379380
if (config.hasPath("private.key")) {
380381
INSTANCE.privateKey = config.getString("private.key");
381-
if (INSTANCE.privateKey.length() != 64) {
382+
if (INSTANCE.privateKey.length() != ChainConstant.PRIVATE_KEY_LENGTH) {
382383
throw new RuntimeException(
383384
"The peer.privateKey needs to be Hex encoded and 32 byte length");
384385
}

‎src/main/java/org/tron/core/config/args/LocalWitnesses.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
import lombok.extern.slf4j.Slf4j;
2222
import org.apache.commons.collections4.CollectionUtils;
2323
import org.apache.commons.lang3.StringUtils;
24+
import org.tron.core.config.Parameter;
25+
import org.tron.core.config.Parameter.ChainConstant;
2426

2527
@Slf4j
2628
public class LocalWitnesses {
@@ -57,9 +59,9 @@ private void validate(String privateKey) {
5759
privateKey = privateKey.substring(2);
5860
}
5961

60-
if (StringUtils.isNotBlank(privateKey) && privateKey.length() != 66) {
62+
if (StringUtils.isNotBlank(privateKey) && privateKey.length() != ChainConstant.PRIVATE_KEY_LENGTH) {
6163
throw new IllegalArgumentException(
62-
"Private key(" + privateKey + ") must be 66-bits hex string.");
64+
"Private key(" + privateKey + ") must be " + ChainConstant.PRIVATE_KEY_LENGTH + "-bits hex string.");
6365
}
6466
}
6567

‎src/main/java/org/tron/core/db/Manager.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -892,6 +892,7 @@ public void updateSignedWitness(BlockCapsule block) {
892892
//TODO: add verification
893893
WitnessCapsule witnessCapsule = witnessStore
894894
.get(block.getInstance().getBlockHeader().getRawData().getWitnessAddress().toByteArray());
895+
System.out.println("xxd " + ByteArray.toHexString(block.getInstance().getBlockHeader().getRawData().getWitnessAddress().toByteArray()));
895896
long latestSlotNum = 0;
896897
witnessCapsule.getInstance().toBuilder().setLatestBlockNum(block.getNum())
897898
.setLatestSlotNum(latestSlotNum)

‎src/main/resources/config-test.conf‎

Lines changed: 75 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
net {
2-
// type = mainnet
2+
// type = mainnet
33
type = testnet
44
}
55

66

77
storage {
88
# Directory for storing persistent data
9-
directory = "database-test"
9+
directory = "database"
1010
}
1111

1212
node.discovery = {
@@ -34,7 +34,7 @@ node {
3434
maxActiveNodes = 30
3535

3636
p2p {
37-
version = 1005 # 32: testnet; 101: debug
37+
version = 43 # 43: testnet; 101: debug
3838
}
3939

4040
}
@@ -52,7 +52,17 @@ seed.node = {
5252
# "ip:port"
5353
# ]
5454
ip.list = [
55-
# "192.168.10.55:18888",
55+
"47.254.16.55:18888",
56+
"47.254.18.49:18888",
57+
"18.188.111.53:18888",
58+
"54.219.41.56:18888",
59+
"35.169.113.187:18888",
60+
"34.214.241.188:18888",
61+
"47.254.146.147:18888",
62+
"47.254.144.25:18888",
63+
"47.91.246.252:18888",
64+
"47.91.216.69:18888",
65+
"39.106.220.120:18888"
5666
]
5767
}
5868

@@ -68,59 +78,96 @@ genesis.block = {
6878
{
6979
accountName = "Devaccount"
7080
accountType = "AssetIssue"
71-
address = "a0abd4b9367799eaa3197fecb144eb71de1e049150"
72-
balance = "10000"
81+
address = "a099357684bc659f5166046b56c95a0e99f1265cbd"
82+
balance = "10000000000000000"
7383
},
74-
# the account of foundation.
7584
{
7685
accountName = "Zion"
7786
accountType = "AssetIssue"
78-
address = "a055ddae14564f82d5b94c7a131b5fcfd31ad6515a"
79-
balance = "100000000000000000"
87+
address = "a0b4750e2cd76e19dca331bf5d089b71c3c2798548"
88+
balance = "15000000000000000"
8089
},
81-
82-
# the account of payment
8390
{
8491
accountName = "Sun"
8592
accountType = "AssetIssue"
86-
address = "a04948c2e8a756d9437037dcd8c7e0c73d560ca38d"
87-
balance = "9223372036854775807"
93+
address = "a025a3aae39b24a257f95769c701e8d6978ebe9fc5"
94+
balance = "10000000000000000"
8895
},
89-
90-
# the account of coin burn
9196
{
9297
accountName = "Blackhole"
9398
accountType = "AssetIssue"
94-
address = "a0548794500882809695a8a687866e76d4271a146a"
99+
address = "a0559ccf55fadffdf814a42aff331de9688c132612"
95100
balance = "-9223372036854775808"
96101
}
97102
]
98103

99104
witnesses = [
100105
{
101-
#privateKey:00f31db24bfbd1a2ef19beddca0a0fa37632eded9ac666a05d3bd925f01dde1f62
102-
#publicKey:04af91bdf9d8d565073b860b11a15f608ea46d0891a622d15027c3a9329f1b49f59ade694044a5b19a1aa005871bba5120ddf363ee00e47902f7d87c87d50f4b25
103-
address:a0299f3db80a24b20a254b89ce639d59132f157f13
104-
url = "http://Uranus.org",
105-
voteCount = 100
106+
address: a0904fe896536f4bebc64c95326b5054a2c3d27df6
107+
url = "http://Mercury.org",
108+
voteCount = 105
109+
},
110+
{
111+
address: a0807337f180b62a77576377c1d0c9c24df5c0dd62
112+
url = "http://Venus.org",
113+
voteCount = 104
114+
},
115+
{
116+
address: a05430a3f089154e9e182ddd6fe136a62321af22a7
117+
url = "http://Earth.org",
118+
voteCount = 103
119+
},
120+
{
121+
address: a08beaa1a8e2d45367af7bae7c490b9932a4fa4301
122+
url = "http://Mars.org",
123+
voteCount = 102
124+
},
125+
{
126+
address: a0b070b2b58f4328e293dc9d6012f59c263d3a1df6
127+
url = "http://Jupiter.org",
128+
voteCount = 101
129+
},
130+
{
131+
address: a00a9309758508413039e4bc5a3d113f3ecc55031d
132+
url = "http://Saturn.org",
133+
voteCount = 100
106134
},
107135
{
108-
#privateKey:00bfa39780b1cf6c2592a55286bc63f0c5290125c3f5a32075a5febcbb60a8204f
109-
#publicKey:04d0cc249fb8aa7e1c1a76e3f8ef0cba4ec9cf97dbfaa1f93a62f5acf23a6a3b1953e72df7ae1c2e7948abe2568b01f43025c84d6795413d7f1e3606992727211d
110-
address:a0448d53b2df0cd78158f6f0aecdf60c1c10b15413
136+
address: a06a17a49648a8ad32055c06f60fa14ae46df94cc1
111137
url = "http://Uranus.org",
112-
voteCount = 100
138+
voteCount = 99
139+
},
140+
{
141+
address: a0ec6525979a351a54fa09fea64beb4cce33ffbb7a
142+
url = "http://Neptune.org",
143+
voteCount = 98
144+
},
145+
{
146+
address: a0fab5fbf6afb681e4e37e9d33bddb7e923d6132e5
147+
url = "http://Pluto.org",
148+
voteCount = 97
149+
},
150+
{
151+
address: a014eebe4d30a6acb505c8b00b218bdc4733433c68
152+
url = "http://Altair.org",
153+
voteCount = 96
154+
},
155+
{
156+
address: a04711bf7afbdf44557defbdf4c4e7aa6138c6331f
157+
url = "http://AlphaLyrae.org",
158+
voteCount = 95
113159
}
114160
]
161+
115162
timestamp = "0" #2017-8-26 12:00:00
116163

117164
parentHash = "0x0000000000000000000000000000000000000000000000000000000000000000"
118165
}
119166

120167
localwitness = [
121-
00bfa39780b1cf6c2592a55286bc63f0c5290125c3f5a32075a5febcbb60a8204f
168+
122169
]
123170

124171
block = {
125-
needSyncCheck = false # first node : false, other : true
126-
}
172+
needSyncCheck = true # first node : false, other : true
173+
}

‎src/main/resources/config.conf‎

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ node {
3434
maxActiveNodes = 30
3535

3636
p2p {
37-
version = 42 # 32: testnet; 101: debug
37+
version = 43 # 43: testnet; 101: debug
3838
}
3939

4040
}
@@ -78,87 +78,82 @@ genesis.block = {
7878
{
7979
accountName = "Devaccount"
8080
accountType = "AssetIssue"
81-
address = "a0abd4b9367799eaa3197fecb144eb71de1e049150"
82-
balance = "10000"
81+
address = "a099357684bc659f5166046b56c95a0e99f1265cbd"
82+
balance = "10000000000000000"
8383
},
84-
# the account of foundation.
8584
{
8685
accountName = "Zion"
8786
accountType = "AssetIssue"
88-
address = "a055ddae14564f82d5b94c7a131b5fcfd31ad6515a"
89-
balance = "25000000000000000"
87+
address = "a0b4750e2cd76e19dca331bf5d089b71c3c2798548"
88+
balance = "15000000000000000"
9089
},
91-
92-
# the account of payment
9390
{
9491
accountName = "Sun"
9592
accountType = "AssetIssue"
96-
address = "a04948c2e8a756d9437037dcd8c7e0c73d560ca38d"
93+
address = "a025a3aae39b24a257f95769c701e8d6978ebe9fc5"
9794
balance = "10000000000000000"
9895
},
99-
100-
# the account of coin burn
10196
{
10297
accountName = "Blackhole"
10398
accountType = "AssetIssue"
104-
address = "a0548794500882809695a8a687866e76d4271a146a"
99+
address = "a0559ccf55fadffdf814a42aff331de9688c132612"
105100
balance = "-9223372036854775808"
106101
}
107102
]
108103

109104
witnesses = [
110105
{
111-
address: a08a164d6e6d3d4dd6f9f6b8b6460a7e63bb3bb96d
106+
address: a0904fe896536f4bebc64c95326b5054a2c3d27df6
112107
url = "http://Mercury.org",
113108
voteCount = 105
114109
},
115110
{
116-
address: a0847f673b00aa31774f3825a6059069adc535a218
111+
address: a0807337f180b62a77576377c1d0c9c24df5c0dd62
117112
url = "http://Venus.org",
118113
voteCount = 104
119114
},
120115
{
121-
address: a05b672d3a5b88073b42b4e00fe587130487f401e3
116+
address: a05430a3f089154e9e182ddd6fe136a62321af22a7
122117
url = "http://Earth.org",
123118
voteCount = 103
124119
},
125120
{
126-
address: a002bb840e4c8f0c95c3be39b03843c56e5128b182
121+
address: a08beaa1a8e2d45367af7bae7c490b9932a4fa4301
127122
url = "http://Mars.org",
128123
voteCount = 102
129124
},
130125
{
131-
address: a0b32b3710eaaaf485096cf2d328d0cb4656b16cdb
126+
address: a0b070b2b58f4328e293dc9d6012f59c263d3a1df6
132127
url = "http://Jupiter.org",
133128
voteCount = 101
134129
},
135130
{
136-
address: a019c7aa7243f904176cf48f34ec00ec378b34a0dc
131+
address: a00a9309758508413039e4bc5a3d113f3ecc55031d
137132
url = "http://Saturn.org",
138133
voteCount = 100
139134
},
140135
{
141-
address: a0c0107ebb420f1316a6b14377ee7416f13fc607bf
136+
address: a06a17a49648a8ad32055c06f60fa14ae46df94cc1
142137
url = "http://Uranus.org",
143138
voteCount = 99
144139
},
145140
{
146-
address: a08b46a8fcd532c50f9a26d9df80e82533d04320fa
141+
address: a0ec6525979a351a54fa09fea64beb4cce33ffbb7a
147142
url = "http://Neptune.org",
148143
voteCount = 98
149144
},
150145
{
151-
address: a0e12f18b0d1eab50f9c3cabb25a1c0941739e8593
146+
address: a0fab5fbf6afb681e4e37e9d33bddb7e923d6132e5
152147
url = "http://Pluto.org",
153148
voteCount = 97
154149
},
155150
{
156-
address: a025ec27e5ddce23b6acbadbd5c38d579986ebf066
151+
address: a014eebe4d30a6acb505c8b00b218bdc4733433c68
157152
url = "http://Altair.org",
158153
voteCount = 96
159154
},
160155
{
161-
address: a01e5ac6a87bd9b3ac25ad092e0a030f72598aef2c
156+
address: a04711bf7afbdf44557defbdf4c4e7aa6138c6331f
162157
url = "http://AlphaLyrae.org",
163158
voteCount = 95
164159
}

‎src/test/java/org/tron/core/config/ConfigurationTest.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ public void getShouldNotFindConfiguration() {
7575
public void getShouldReturnConfiguration() {
7676
Config config = Configuration.getByPath("config-test.conf");
7777
assertTrue(config.hasPath("storage"));
78-
assertTrue(config.hasPath("overlay"));
7978
assertTrue(config.hasPath("seed.node"));
8079
assertTrue(config.hasPath("genesis.block"));
8180
}

‎src/test/java/org/tron/core/config/args/ArgsTest.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,21 @@ public void get() {
3636
Args args = Args.getInstance();
3737
Assert.assertEquals("configFile-test", args.getStorage().getDirectory());
3838

39-
Assert.assertEquals(7, args.getSeedNode().getIpList().size());
39+
Assert.assertEquals(11, args.getSeedNode().getIpList().size());
4040

4141
GenesisBlock genesisBlock = args.getGenesisBlock();
4242

43-
Assert.assertEquals(3, genesisBlock.getAssets().size());
43+
Assert.assertEquals(4, genesisBlock.getAssets().size());
4444

45-
Assert.assertEquals(4, genesisBlock.getWitnesses().size());
45+
Assert.assertEquals(11, genesisBlock.getWitnesses().size());
4646

4747
Assert.assertEquals("0", genesisBlock.getTimestamp());
4848

4949
Assert.assertEquals("0x0000000000000000000000000000000000000000000000000000000000000000",
5050
genesisBlock.getParentHash());
5151

5252
Assert.assertEquals(
53-
Lists.newArrayList("00f31db24bfbd1a2ef19beddca0a0fa37632eded9ac666a05d3bd925f01dde1f62"),
53+
Lists.newArrayList("f31db24bfbd1a2ef19beddca0a0fa37632eded9ac666a05d3bd925f01dde1f62"),
5454
args.getLocalWitnesses().getPrivateKeys());
5555

5656
Assert.assertTrue(args.isNodeDiscoveryEnable());

‎src/test/java/org/tron/core/config/args/LocalWitnessTest.java‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public void setLocalWitness() {
2929
localWitness
3030
.setPrivateKeys(
3131
Lists.newArrayList(
32-
"00f31db24bfbd1a2ef19beddca0a0fa37632eded9ac666a05d3bd925f01dde1f62"));
32+
"f31db24bfbd1a2ef19beddca0a0fa37632eded9ac666a05d3bd925f01dde1f62"));
3333
}
3434

3535
@Test
@@ -51,16 +51,16 @@ public void whenSetBadFormatPrivateKey() {
5151
public void whenSetPrefixPrivateKey() {
5252
localWitness
5353
.setPrivateKeys(Lists
54-
.newArrayList("0x00f31db24bfbd1a2ef19beddca0a0fa37632eded9ac666a05d3bd925f01dde1f62"));
54+
.newArrayList("0xf31db24bfbd1a2ef19beddca0a0fa37632eded9ac666a05d3bd925f01dde1f62"));
5555
localWitness
5656
.setPrivateKeys(Lists
57-
.newArrayList("0X00f31db24bfbd1a2ef19beddca0a0fa37632eded9ac666a05d3bd925f01dde1f62"));
57+
.newArrayList("0Xf31db24bfbd1a2ef19beddca0a0fa37632eded9ac666a05d3bd925f01dde1f62"));
5858
}
5959

6060
@Test
6161
public void getPrivateKey() {
6262
Assert.assertEquals(Lists
63-
.newArrayList("00f31db24bfbd1a2ef19beddca0a0fa37632eded9ac666a05d3bd925f01dde1f62"),
63+
.newArrayList("f31db24bfbd1a2ef19beddca0a0fa37632eded9ac666a05d3bd925f01dde1f62"),
6464
localWitness.getPrivateKeys());
6565
}
6666
}

0 commit comments

Comments
 (0)