forked from hyperledger/besu
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Batching backward sync (hyperledger#3532)
* Backward sync now batches requests Signed-off-by: Jiri Peinlich <[email protected]>
- Loading branch information
1 parent
43e2a1c
commit 15557be
Showing
30 changed files
with
1,553 additions
and
416 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
...erledger/besu/ethereum/eth/manager/task/RetryingGetHeadersEndingAtFromPeerByHashTask.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright Hyperledger Besu Contributors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on | ||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
* | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.hyperledger.besu.ethereum.eth.manager.task; | ||
|
||
import static com.google.common.base.Preconditions.checkNotNull; | ||
|
||
import org.hyperledger.besu.datatypes.Hash; | ||
import org.hyperledger.besu.ethereum.core.BlockHeader; | ||
import org.hyperledger.besu.ethereum.eth.manager.EthContext; | ||
import org.hyperledger.besu.ethereum.eth.manager.EthPeer; | ||
import org.hyperledger.besu.ethereum.mainnet.ProtocolSchedule; | ||
import org.hyperledger.besu.plugin.services.MetricsSystem; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.concurrent.CompletableFuture; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
|
||
public class RetryingGetHeadersEndingAtFromPeerByHashTask | ||
extends AbstractRetryingPeerTask<List<BlockHeader>> { | ||
|
||
private final Hash referenceHash; | ||
private final ProtocolSchedule protocolSchedule; | ||
private final long minimumRequiredBlockNumber; | ||
private final int count; | ||
|
||
@VisibleForTesting | ||
RetryingGetHeadersEndingAtFromPeerByHashTask( | ||
final ProtocolSchedule protocolSchedule, | ||
final EthContext ethContext, | ||
final Hash referenceHash, | ||
final long minimumRequiredBlockNumber, | ||
final int count, | ||
final MetricsSystem metricsSystem) { | ||
super(ethContext, 3, List::isEmpty, metricsSystem); | ||
this.protocolSchedule = protocolSchedule; | ||
this.minimumRequiredBlockNumber = minimumRequiredBlockNumber; | ||
this.count = count; | ||
checkNotNull(referenceHash); | ||
this.referenceHash = referenceHash; | ||
} | ||
|
||
public static RetryingGetHeadersEndingAtFromPeerByHashTask endingAtHash( | ||
final ProtocolSchedule protocolSchedule, | ||
final EthContext ethContext, | ||
final Hash referenceHash, | ||
final long minimumRequiredBlockNumber, | ||
final int count, | ||
final MetricsSystem metricsSystem) { | ||
return new RetryingGetHeadersEndingAtFromPeerByHashTask( | ||
protocolSchedule, | ||
ethContext, | ||
referenceHash, | ||
minimumRequiredBlockNumber, | ||
count, | ||
metricsSystem); | ||
} | ||
|
||
@Override | ||
protected CompletableFuture<List<BlockHeader>> executePeerTask( | ||
final Optional<EthPeer> assignedPeer) { | ||
final AbstractGetHeadersFromPeerTask task = | ||
GetHeadersFromPeerByHashTask.endingAtHash( | ||
protocolSchedule, | ||
getEthContext(), | ||
referenceHash, | ||
minimumRequiredBlockNumber, | ||
count, | ||
getMetricsSystem()); | ||
assignedPeer.ifPresent(task::assignPeer); | ||
return executeSubTask(task::run) | ||
.thenApply( | ||
peerResult -> { | ||
result.complete(peerResult.getResult()); | ||
return peerResult.getResult(); | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.