SyncStatus
What a node reports about its sync: the literal false once it is in sync, or its progress as
three block numbers while it is syncing.
import { Effect } from "effect";import { Eth } from "@ethect/core/rpc";
const remaining = Effect.gen(function* () { const status = yield* Eth.syncing(); if (status === false) return 0n; // status: SyncStatus.Progress return status.highestBlock - status.currentBlock;});Schemas
Section titled “Schemas”| Schema | Type | Describes | Returned by |
|---|---|---|---|
SyncStatus.schema |
SyncStatus.SyncStatus |
false, or a SyncStatus.Progress |
Eth.syncing, and as one of the forms Eth.subscribe.syncing pushes |
SyncStatus.progressSchema |
SyncStatus.Progress |
how far a syncing node has come | as the other member of SyncStatus.SyncStatus |
Import a type to name it in your own signatures.
import type { SyncStatus } from "@ethect/core/rpc";
/** How much of the way from where it started the node has come. */const percent = ({ startingBlock = 0n, ...sync }: SyncStatus.Progress) => sync.highestBlock === startingBlock ? 100 : Number( ((sync.currentBlock - startingBlock) * 100n) / (sync.highestBlock - startingBlock), );Fields
Section titled “Fields”SyncStatus.Progress.
| Field | Type | Notes |
|---|---|---|
startingBlock |
bigint (optional) |
the block the sync started from. Not sent by every client. |
currentBlock |
bigint |
the block the node has reached |
highestBlock |
bigint |
the block the node is syncing towards |
Behavior
Section titled “Behavior”false, nevertrue. A node in sync answersfalse. A node that is syncing answers the progress object, nottrue: compare with=== falseto narrow the type.startingBlockcan be absent. A client that does not say where it started gives a progress without the key. Test it withprogress.startingBlock !== undefined.- Other fields are dropped. A node that reports more than these three still decodes. The extra fields are not in the result.
- Numbers. The three fields are block numbers, so they are
bigint. See values on the wire.