use of org.aion.api.server.types.SyncInfo in project aion by aionnetwork.
the class ApiAion method getSyncInfo.
/**
* Returns a {@link SyncInfo} object that reports whether or not syncing has started.
*
* <p>Since a node is never really 'done' syncing, we consider a node to be done if it is within
* {@value SYNC_TOLERANCE} blocks of the network best block number.
*
* @param localBestBlockNumber The current block number of the local node.
* @param networkBestBlockNumber The current block number of the network.
* @return the syncing statistics.
*/
protected SyncInfo getSyncInfo(long localBestBlockNumber, long networkBestBlockNumber) {
SyncInfo sync = new SyncInfo();
sync.done = localBestBlockNumber + SYNC_TOLERANCE >= networkBestBlockNumber;
sync.chainStartingBlkNumber = this.ac.getInitialStartingBlockNumber().orElse(0L);
sync.chainBestBlkNumber = localBestBlockNumber;
sync.networkBestBlkNumber = networkBestBlockNumber;
return sync;
}
use of org.aion.api.server.types.SyncInfo in project aion by aionnetwork.
the class ApiWeb3Aion method eth_syncing.
/**
* Returns an {@link RpcMsg} containing 'false' if the node is done syncing to the network
* (since a node is never really 'done' syncing, we consider a node to be done if it is within
* {@value SYNC_TOLERANCE} blocks of the network best block number).
*
* <p>Otherwise, if the sync is still syncing, a {@link RpcMsg} is returned with some basic
* statistics relating to the sync: the block number the node was at when syncing began; the
* current block number of the node; the current block number of the network.
*
* <p>If either the local block number or network block number cannot be determined, an {@link
* RpcMsg} is returned with an {@link RpcError#INTERNAL_ERROR} code and its 'result' will be a
* more descriptive string indicating what went wrong.
*
* @return the syncing statistics.
*/
public RpcMsg eth_syncing() {
Optional<Long> localBestBlockNumber = this.ac.getLocalBestBlockNumber();
Optional<Long> networkBestBlockNumber = this.ac.getNetworkBestBlockNumber();
// Check that we actually have real values in our hands.
if (!localBestBlockNumber.isPresent()) {
return new RpcMsg("Unable to determine the local node's best block number!", RpcError.INTERNAL_ERROR);
}
if (!networkBestBlockNumber.isPresent()) {
return new RpcMsg("Unable to determine the network's best block number!", RpcError.INTERNAL_ERROR);
}
SyncInfo syncInfo = getSyncInfo(localBestBlockNumber.get(), networkBestBlockNumber.get());
return (syncInfo.done) ? new RpcMsg(false) : new RpcMsg(syncInfoToJson(syncInfo));
}
Aggregations