|
1 | 1 | package org.tron.core.zen; |
2 | 2 |
|
3 | 3 | import com.google.protobuf.ByteString; |
| 4 | +import com.typesafe.config.Config; |
4 | 5 | import io.netty.util.internal.StringUtil; |
5 | 6 | import lombok.Getter; |
6 | 7 | import lombok.Setter; |
|
11 | 12 | import org.tron.common.utils.ByteArray; |
12 | 13 | import org.tron.common.utils.ByteUtil; |
13 | 14 | import org.tron.common.utils.Utils; |
| 15 | +import org.tron.core.config.Configuration; |
14 | 16 | import org.tron.core.exception.CipherException; |
15 | 17 | import org.tron.core.exception.ZksnarkException; |
16 | 18 | import org.tron.core.zen.address.KeyIo; |
@@ -62,9 +64,22 @@ public class ShieldedTRC20Wrapper { |
62 | 64 | @Getter |
63 | 65 | @Setter |
64 | 66 | public List<ShieldedTRC20NoteInfo> spendUtxoList = new ArrayList<>(); |
| 67 | + @Getter |
| 68 | + @Setter |
| 69 | + public static long defaultBlockNumberToScan = 0; |
65 | 70 |
|
66 | 71 | private boolean loadShieldedStatus = false; |
67 | 72 |
|
| 73 | + static { |
| 74 | + Config config = Configuration.getByPath("config.conf"); |
| 75 | + if (config.hasPath("blockNumberStartToScan")) { |
| 76 | + try { |
| 77 | + defaultBlockNumberToScan = config.getLong("blockNumberStartToScan"); |
| 78 | + } catch (Exception e) { |
| 79 | + } |
| 80 | + } |
| 81 | + } |
| 82 | + |
68 | 83 | private ShieldedTRC20Wrapper() { |
69 | 84 | thread = new Thread(new scanIvkRunable()); |
70 | 85 | } |
@@ -206,7 +221,7 @@ private void resetShieldedTRC20Note() throws ZksnarkException { |
206 | 221 | byte[] key = ByteUtil.merge(entry.getValue().getIvk(), |
207 | 222 | entry.getValue().getFullViewingKey().getAk(), |
208 | 223 | entry.getValue().getFullViewingKey().getNk()); |
209 | | - ivkMapScanBlockNum.put(ByteArray.toHexString(key), 0L); |
| 224 | + ivkMapScanBlockNum.put(ByteArray.toHexString(key), defaultBlockNumberToScan); |
210 | 225 | } |
211 | 226 |
|
212 | 227 | utxoMapNote.clear(); |
@@ -234,8 +249,8 @@ private void scanBlockByIvk() throws CipherException { |
234 | 249 | long start = entry.getValue(); |
235 | 250 | long end = start; |
236 | 251 | while (end < blockNum) { |
237 | | - if (blockNum - start > 1000) { |
238 | | - end = start + 1000; |
| 252 | + if (blockNum - start > 200) { // scan 200 blocks at a time |
| 253 | + end = start + 200; |
239 | 254 | } else { |
240 | 255 | end = blockNum; |
241 | 256 | } |
@@ -293,10 +308,10 @@ private void scanBlockByIvk() throws CipherException { |
293 | 308 | } |
294 | 309 | } |
295 | 310 | start = end; |
| 311 | + ivkMapScanBlockNum.put(entry.getKey(), start); |
| 312 | + updateIvkAndBlockNumFile(); |
296 | 313 | } |
297 | | - ivkMapScanBlockNum.put(entry.getKey(), blockNum); |
298 | 314 | } |
299 | | - updateIvkAndBlockNumFile(); |
300 | 315 | } |
301 | 316 | } |
302 | 317 |
|
@@ -369,7 +384,7 @@ public boolean addNewShieldedTRC20Address(final ShieldedAddressInfo addressInfo, |
369 | 384 | boolean newAddress) |
370 | 385 | throws CipherException, ZksnarkException { |
371 | 386 | appendAddressInfoToFile(addressInfo); |
372 | | - long blockNum = 0; |
| 387 | + long blockNum = defaultBlockNumberToScan; |
373 | 388 | if (newAddress) { |
374 | 389 | try { |
375 | 390 | Block block = WalletApi.getBlock(-1); |
|
0 commit comments