Skip to content
Discussions/App Development/Offset is null while getting Active contractsForum ↗

Offset is null while getting Active contracts

App Development7 posts344 viewsLast activity Sep 2021
AL
Alex_Martinez_VilaOP
Sep 2021

Hi, we are using the LedgerClient(gRPC) to retrieve current active contracts. As per documentation the response object should contain an offset value(unless the ledger is not empty).

In our case this value is coming as null always eventhough we have some data in the ledger.

This behavior is not reproducible for Sandbox but it is for Daml on Postgres.

What are the cases when the offset may come as null?

We are using daml version 1.11.1

ST
stefanobaghino-da
Sep 2021

The offset field will always be empty, apart from the last message, where instead of a list of active contracts you’ll receive the offset at which the active contracts you received were active. You can then use the “flat transaction” endpoints to keep a client-side representation of the active contract set you’re interested in.

I believe the following sentence can probably use better phrasing: “Each created event has a ledger offset where it occurs.” This is a generic statement about the fact that create events happen at a given offset. In the GetActiveContractsResponse object you’ll either the active contracts or, as the last message, the offset at which the active contract set you received was considered “current” (the documentation of the Protobuf definition probably does a better job at communicating this).

ST
stefanobaghino-da
Sep 2021

I made a PR that hopefully could help clarify what I mentioned in the message above, feel free to comment there if you think that further improvements are possible.

AL
Alex_Martinez_Vila
Sep 2021

Thanks for the quick reply. After reading your comments and the PR, and if I understood it well, that’s exaclty what we are doing. Get active contracts and then (having an offset) use transaction listener to keep updates.

Notice that we are using the getActiveContractSetClient until the stream of data is over, so when this last message with the offset should come?

In Documentation offset is required in the response.

ST
stefanobaghino-da
Sep 2021

The fact that the documentation you linked clearly states that only the last message has the offset seems to be at odds with the fact that the field is documented as required. This could be the legacy of an implementation where all contracts were reported in a single message (which made the first message also the one with the entire active contract set, making the offset effectively “required”).

ST
stefanobaghino-da
Sep 2021

I’m not 100% sure though, asking someone from the core team to give a better informed answer.

MA
Marcin_Ziolek
Sep 2021

What was the original reason for marking this field as required is not retrievable from the repository’s history. It could be that you are right @stefanobaghino-da.
But ultimately it doesn’t matter that much. This field is only going to be populated on the last message, therefore is not a “required” field per se. BTW this lat message will contain only the offset field set and nothing else.

← Back to Discussions