Plutonomicon / cardano-transaction-lib

A Purescript library for building smart contract transactions on Cardano
https://plutonomicon.github.io/cardano-transaction-lib/
MIT License
92 stars 50 forks source link

Add optional feature to delay contract execution until node has synced #867

Open ngua opened 2 years ago

ngua commented 2 years ago

We can use Ogmios' health check endpoint (HTTP only though) to get the network synchronization value. The endpoint should be called and execution should be delayed until it returns 0.99

This should not be enabled by default. We can just add a function (waitUntilSynced?) that takes a Contract as an argument

klntsky commented 2 years ago

We should ping Ogmios devs to add it to ws interface if it is not there. I think it's best to enable it by default and throw an error instead of waiting (to minimize the amount of user confusion).

that takes a Contract as an argument

There's no need for taking Contract as argument, we can delay in Aff perfectly fine, without taking any arguments. Besides, we have multiple ways to run Contract, so adding waitUntilSynched will lead to either number of helper function explosion or incomplete interface.

klntsky commented 2 years ago

I think it's also better not to rely on just sync progress percentage. 99% can still be weeks in the past.

klntsky commented 2 years ago

We can estimate lag using slot-to-time conversion, like in QueryM.WaitUntilSlot.getLag, and just wait until lag value reaches certain threshold.