Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit 2de81aa

Browse files
committed
Don't renew timer when sync.makeDoneByTimeout is used
1 parent ee86a70 commit 2de81aa

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

ethereumj-core/src/main/java/org/ethereum/sync/SyncManager.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void accept(BlockWrapper blockWrapper) {
108108
private long importStart;
109109
private EthereumListener.SyncState syncDoneType = EthereumListener.SyncState.COMPLETE;
110110
private ScheduledExecutorService logExecutor = Executors.newSingleThreadScheduledExecutor();
111-
private LocalDateTime lastSyncAction;
111+
private LocalDateTime initRegularTime;
112112

113113
private AtomicInteger blocksInMem = new AtomicInteger(0);
114114

@@ -171,15 +171,17 @@ void initRegularSync(EthereumListener.SyncState syncDoneType) {
171171

172172
if (config.makeDoneByTimeout() >= 0) {
173173
logger.info("Custom long sync done timeout set to {} second(s)", config.makeDoneByTimeout());
174-
this.lastSyncAction = LocalDateTime.now();
174+
this.initRegularTime = LocalDateTime.now();
175175
ScheduledExecutorService shortSyncAwait = Executors.newSingleThreadScheduledExecutor();
176176
shortSyncAwait.scheduleAtFixedRate(() -> {
177177
try {
178-
if (LocalDateTime.now().minusSeconds(config.makeDoneByTimeout()).isAfter(lastSyncAction) &&
178+
if (LocalDateTime.now().minusSeconds(config.makeDoneByTimeout()).isAfter(initRegularTime) &&
179179
getLastKnownBlockNumber() == blockchain.getBestBlock().getNumber()) {
180180
logger.info("Sync done triggered by timeout");
181181
makeSyncDone();
182182
shortSyncAwait.shutdown();
183+
} else if (syncDone) {
184+
shortSyncAwait.shutdown();
183185
}
184186
} catch (Exception e) {
185187
logger.error("Unexpected", e);
@@ -296,9 +298,6 @@ private void produceQueue() {
296298
if (wrapper.isNewBlock() && !syncDone) {
297299
makeSyncDone();
298300
}
299-
if (config.makeDoneByTimeout() >= 0 && !syncDone) {
300-
this.lastSyncAction = LocalDateTime.now();
301-
}
302301
}
303302

304303
if (importResult == IMPORTED_NOT_BEST)

ethereumj-core/src/main/resources/ethereumj.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ sync {
307307
exitOnBlockConflict = false
308308

309309
# Make long sync done (switch to short sync) in XX seconds
310-
# if there are no new blocks and all known blocks already downloaded.
310+
# if all known blocks already downloaded.
311311
# Useful in private networks where auto-switch could fail.
312312
# Recommended value for private networks: 60 (seconds)
313313
makeDoneByTimeout = -1

0 commit comments

Comments
 (0)