ledger icon indicating copy to clipboard operation
ledger copied to clipboard

Feature proposal: Batch revert

Open igordreher opened this issue 2 years ago • 5 comments

Is your feature request related to a problem? Please describe. I would like to revert a bunch of related transactions together and only commit the reversion if none fails to revert.

Summary Having a way to revert transactions in batch is important to guarantee that a batch of transactions can only be reverted if all can.

Solution proposal Add an endpoint to revert a list of transactions and this would only revert the transactions if none fails to revert. Another possible solution would be to add an endpoint to check if a transaction can be reverted.

Describe alternatives you've considered Check if all transactions can be reverted (the source accounts have enough money) before reverting them one by one. This isn't a guarantee and it isn't clear what are all the rules that are used to verify if a transaction can be reverted (I didn't find it documented anywhere).

igordreher avatar May 31 '23 18:05 igordreher

@igordreher Hello! Can you elaborate on your use case? Today, the batch is used mainly to avoid network latencies, not to enforce the commitment of a set of transactions. The ledger use a single sql transaction, and thus, the whole is either committed or rollback, but this is not the main idea of the batch feature. For your information, we are working on a v2 where the batch will not be available. Instead we will probably implements a bulk request feature. With these bulk requests, you will be able to push a batch of transactions, but each one will be independent. So, reverting a batch of transactions feels like a non sense for me. Do you have seen you can create transactions with multiple postings? Using this instead of multiple transactions could allow you to revert all at once juste by reverting the single transaction you created at first.

gfyrag avatar May 31 '23 22:05 gfyrag

Hey @gfyrag, thanks for replying!

Do you have seen you can create transactions with multiple postings? Using this instead of multiple transactions could allow you to revert all at once juste by reverting the single transaction you created at first.

Yes and we use it already in some cases. But, we can't revert a single posting of a transaction.

Can you elaborate on your use case?

We are making a wrapper around Ledger with a design that depends on this behavior to guarantee a consistent relation between transactions. We want to be able to create related transactions atomically and have the option to revert a few of them or revert them all together. If we use a single transaction with various postings, we wouldn't be able to do this, since I can't revert only a portion of a transaction. We will not be able to undo only e.g. tax or discount (both distinct txids) of a batch transaction using multiple postings as they have the same txid. And there are moments we would like to revert these atomic transactions all together. If we try to do so, there is a risk this operation fails and can't be completed for reasons such as conflicting transactions happening at the same time.

About the batch not being available on v2, is there any remote possibility that this behavior remains available instead of being replaced? (Adding a bulk endpoint, instead of replacing the current batch endpoint) I ask this since I'm currently depending on this batch behavior

FYI @lucasfcnunes

igordreher avatar Jun 02 '23 14:06 igordreher

ping @gfyrag

lucasfcnunes avatar Jul 05 '23 14:07 lucasfcnunes

Any update??

NathanFirmo avatar Jul 05 '23 14:07 NathanFirmo

Nothing?

thiagolinsx avatar Nov 10 '23 13:11 thiagolinsx