Skip to content

Protocols

The objects returned by chain_sync(), ledger_state_at(), mempool_snapshot() and mempool().

ChainSync

ChainSync(
    client: AsyncClient,
    points: Sequence[PointLike],
    *,
    pipeline: int = 50,
    resume: bool = True,
    raw: bool = False,
    remember: int = 64
)

Follow the chain from an intersection: yields a RollForward or RollBackward per step.

::

async with client.chain_sync(["origin"]) as sync:
    async for event in sync:
        if isinstance(event, RollForward):
            print(event.block.id)
        else:
            print("rolled back to", event.point)

The first event after the intersection is always a roll backward to it. Up to pipeline nextBlock requests are kept in flight, which makes catching up much faster. At the tip, Ogmios holds each request until a new block arrives, so there is no timeout.

If the connection drops and resume is on, it reconnects (retrying as the client's reconnect policy says) and finds an intersection again, starting from the most recent points it has seen, then carries on: you see a roll backward to that point, as after any intersection.

LedgerStateAt

LedgerStateAt(client: AsyncClient, point: PointLike)

Query the ledger as it was at a point: async with client.ledger_state_at(point) as ledger.

ledger has every ledger state query (await ledger.epoch()...), all answered for the acquired point. Ogmios only keeps recent ledger states (about the last 2160 blocks), and the state expires once it is too old: queries then raise :class:~pyogmios.errors.AcquiredExpiredError.

MempoolSnapshot

MempoolSnapshot(client: AsyncClient, *, full: bool = False)

A snapshot of the node's mempool: async with client.mempool_snapshot() as snapshot.

::

async with client.mempool_snapshot() as snapshot:
    print(await snapshot.size())
    async for transaction_id in snapshot:
        ...

acquire async

acquire() -> int

Take a new snapshot. After the first, this waits until the mempool has changed.

size async

size() -> MempoolSizeAndCapacity

The snapshot's size, capacity and number of transactions.

has async

has(transaction_id: str) -> bool

Whether the snapshot contains the transaction.

next async

next() -> Any

The next transaction in the snapshot (its id, or the transaction when full), or None.

MempoolMonitor

MempoolMonitor(client: AsyncClient, *, full: bool = False)

Every transaction that enters the mempool, as it arrives: async for tx in client.mempool().

Each snapshot's new transactions are yielded (ids, or full transactions with full=True), then it waits for the mempool to change. A transaction is yielded once, even if it stays in the mempool across snapshots.