Skip to content

Commit 043d2f5

Browse files
committed
Deposit tree snapshots should only be queried/loaded once
1 parent 8f12937 commit 043d2f5

File tree

1 file changed

+22
-23
lines changed

1 file changed

+22
-23
lines changed

Diff for: beacon/pow/src/main/java/tech/pegasys/teku/beacon/pow/Eth1DepositManager.java

+22-23
Original file line numberDiff line numberDiff line change
@@ -118,31 +118,30 @@ public void start() {
118118
}
119119

120120
private SafeFuture<LoadDepositSnapshotResult> loadDepositSnapshot() {
121-
final LoadDepositSnapshotResult fileDepositSnapshotResult =
122-
depositSnapshotFileLoader.loadDepositSnapshot();
123-
if (fileDepositSnapshotResult.getDepositTreeSnapshot().isPresent()
124-
&& !takeBestDepositSnapshot) {
125-
LOG.debug("Deposit snapshot from file is provided, using it");
126-
return SafeFuture.completedFuture(fileDepositSnapshotResult);
127-
}
128-
129-
if (takeBestDepositSnapshot) {
130-
STATUS_LOG.loadingDepositSnapshotFromDb();
131-
return depositSnapshotStorageLoader
132-
.loadDepositSnapshot()
133-
.thenApply(
134-
storageDepositSnapshotResult -> {
135-
if (storageDepositSnapshotResult.getDepositTreeSnapshot().isPresent()) {
136-
final DepositTreeSnapshot storageSnapshot =
137-
storageDepositSnapshotResult.getDepositTreeSnapshot().get();
138-
STATUS_LOG.onDepositSnapshot(
139-
storageSnapshot.getDepositCount(), storageSnapshot.getExecutionBlockHash());
121+
STATUS_LOG.loadingDepositSnapshotFromDb();
122+
return depositSnapshotStorageLoader
123+
.loadDepositSnapshot()
124+
.thenApply(
125+
storageDepositSnapshotResult -> {
126+
if (storageDepositSnapshotResult.getDepositTreeSnapshot().isPresent()) {
127+
final DepositTreeSnapshot storageSnapshot =
128+
storageDepositSnapshotResult.getDepositTreeSnapshot().get();
129+
STATUS_LOG.onDepositSnapshot(
130+
storageSnapshot.getDepositCount(), storageSnapshot.getExecutionBlockHash());
131+
if (!takeBestDepositSnapshot) {
132+
return storageDepositSnapshotResult;
140133
}
134+
}
135+
136+
final LoadDepositSnapshotResult fileDepositSnapshotResult =
137+
depositSnapshotFileLoader.loadDepositSnapshot();
138+
if (takeBestDepositSnapshot) {
141139
return ObjectUtils.max(storageDepositSnapshotResult, fileDepositSnapshotResult);
142-
});
143-
} else {
144-
return depositSnapshotStorageLoader.loadDepositSnapshot();
145-
}
140+
}
141+
142+
LOG.debug("Deposit snapshot from file is provided, using it");
143+
return fileDepositSnapshotResult;
144+
});
146145
}
147146

148147
public void stop() {

0 commit comments

Comments
 (0)