Offset Error in DAML code

Hi Everyone,

From the slack to discussions group. :slight_smile:

Here is the error i see in daml sdk even after running daml sandbox-calssic

could some one help where am missing here

java.lang.IllegalArgumentException: cannot parse HexString 0
        at com.daml.platform.ApiOffset$.$anonfun$fromString$1(ApiOffset.scala:19)
        at scala.util.Either.fold(Either.scala:192)
        at com.daml.platform.ApiOffset$.fromString(ApiOffset.scala:20)
        at com.daml.platform.index.LedgerBackedIndexService.$anonfun$convertOffset$1(LedgerBackedIndexService.scala:114)
        at com.daml.platform.index.LedgerBackedIndexService.between(LedgerBackedIndexService.scala:123)
        at com.daml.platform.index.LedgerBackedIndexService.transactionTrees(LedgerBackedIndexService.scala:76)
        at com.daml.platform.apiserver.TimedIndexService.$anonfun$transactionTrees$1(TimedIndexService.scala:93)
        at com.daml.metrics.Timed$.source(Timed.scala:46)
        at com.daml.platform.apiserver.TimedIndexService.transactionTrees(TimedIndexService.scala:93)
        at com.daml.platform.apiserver.services.transaction.ApiTransactionService.$anonfun$getTransactionTrees$1(ApiTransactionService.scala:94)
        at com.daml.logging.LoggingContext$.withEnrichedLoggingContext(LoggingContext.scala:23)
        at com.daml.platform.apiserver.services.transaction.ApiTransactionService.getTransactionTrees(ApiTransactionService.scala:87)
        at com.daml.platform.server.api.services.grpc.GrpcTransactionService.$anonfun$getTransactionTreesSource$3(GrpcTransactionService.scala:76)
        at scala.util.Either.fold(Either.scala:191)
        at com.daml.platform.server.api.services.grpc.GrpcTransactionService.$anonfun$getTransactionTreesSource$1(GrpcTransactionService.scala:74)
        at akka.stream.impl.fusing.Map$$anon$1.onPush(Ops.scala:54)
        at akka.stream.impl.fusing.GraphInterpreter.processPush(GraphInterpreter.scala:541)
        at akka.stream.impl.fusing.GraphInterpreter.processEvent(GraphInterpreter.scala:527)
        at akka.stream.impl.fusing.GraphInterpreter.execute(GraphInterpreter.scala:390)
        at akka.stream.impl.fusing.GraphInterpreterShell.runBatch(ActorGraphInterpreter.scala:624)
        at akka.stream.impl.fusing.ActorGraphInterpreter$SimpleBoundaryEvent.execute(ActorGraphInterpreter.scala:55)
        at akka.stream.impl.fusing.ActorGraphInterpreter$SimpleBoundaryEvent.execute$(ActorGraphInterpreter.scala:51)
        at akka.stream.impl.fusing.ActorGraphInterpreter$RequestMore.execute(ActorGraphInterpreter.scala:273)
        at akka.stream.impl.fusing.GraphInterpreterShell.processEvent(ActorGraphInterpreter.scala:599)
        at akka.stream.impl.fusing.ActorGraphInterpreter.akka$stream$impl$fusing$ActorGraphInterpreter$$processEvent(ActorGraphInterpreter.scala:768)
        at akka.stream.impl.fusing.ActorGraphInterpreter$$anonfun$receive$1.applyOrElse(ActorGraphInterpreter.scala:783)
        at akka.actor.Actor.aroundReceive(Actor.scala:533)
        at akka.actor.Actor.aroundReceive$(Actor.scala:531)
        at akka.stream.impl.fusing.ActorGraphInterpreter.aroundReceive(ActorGraphInterpreter.scala:690)
        at akka.actor.ActorCell.receiveMessage(ActorCell.scala:573)
        at akka.actor.ActorCell.invoke(ActorCell.scala:543)
        at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:269)
        at akka.dispatch.Mailbox.run(Mailbox.scala:230)
        at akka.dispatch.Mailbox.exec(Mailbox.scala:242)
        at java.util.concurrent.ForkJoinTask.doExec(Unknown Source)
        at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(Unknown Source)
        at java.util.concurrent.ForkJoinPool.runWorker(Unknown Source)
        at java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source)
2 Likes

Hello and welcome, @Sneha.

If I got it correctly from the previous discussion you saved the offsets from a previous run and you are trying to re-use those externally saved offsets to retrieve specific transactions.

As part of going from 0.x to 1.x, we changed what offset mean and how they work, which means that using an externally persisted offset across major version cannot be done directly.

The release notes for 1.0.0 go in greater detail about it, in particular here.

The following applies exclusively to the sandbox (as offsets don’t necessarily match across ledger implementations): you can still migrate your own persisted offsets to the new format to make sure they match the new ones. In order to do so, you have to convert the offsets you persisted to an hexadecimal number, turn it into a string and left-pad it with 0s so that the resulting string is 16 characters long (kudos to @gerolf for the suggestion in this regard).

1 Like

Thank you @stefanobaghino-da.
I will go through the link and also try the last point it seems interesting.
I will get back if i face any issue.
Thanks for the help.

1 Like

Thanks @stefanobaghino-da, it worked after leading zeros and making string to 16 characters.

Thanks to @gerolf

4 Likes

@stefanobaghino-da, in the link you have provide above doesn’t say anything about hexa value for offset. Is it mentioned somehwere?

Can you please point me over there.

1 Like

That is because that format is specific for the Sandbox (as you can see here the Ledger API reference also simply refers to it being an opaque string) and the user is normally not supposed to do any kind of processing on it.

Note that the migration mentioned above makes sense only when using the Sandbox and only when migrating from 0.x to 1.x. In general, referring to offsets across major versions is not necessarily supported.

2 Likes