Search in sources :

Example 6 with SyncInfo

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;
}
Also used : SyncInfo(org.aion.api.server.types.SyncInfo)

Example 7 with SyncInfo

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));
}
Also used : SyncInfo(org.aion.api.server.types.SyncInfo)

Aggregations

SyncInfo (org.aion.api.server.types.SyncInfo)7 Test (org.junit.Test)3 ByteString (com.google.protobuf.ByteString)1 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 BigInteger (java.math.BigInteger)1 ByteBuffer (java.nio.ByteBuffer)1 AbstractMap (java.util.AbstractMap)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Objects (java.util.Objects)1 Optional (java.util.Optional)1 Set (java.util.Set)1 BlockingQueue (java.util.concurrent.BlockingQueue)1 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)1