Open g4s8 opened 5 years ago
@g4s8 even though this particular problem is fixed already, the problem is bigger than that. WTS can't 100% guarantee failure atomicity, since Zold network is distributed. In other words, we can accept some payment, send it to the network and then crash somewhere. We have to invent some mechanism to double check the status of the payment after it's failed... I'm thinking.
@yegor256 maybe wts will generate unique id (or hash) for transaction before sending to the network and return it to client, so client (0crat in this case) will be able to check that transaction was added to ledger by id/hash?
@g4s8 but WTS may fail to return the ID, just like it happened in the stacktrace above
@g4s8 so how about we just give programmable access to the General Ledger? The client-side scenario will look like this:
/do-pay
/job
/gl-find
to find the payment, maybe it's thereWDYT?
@yegor256 it may work, but I have some doubts: can client check job status after WTS API failure but before transaction is listed in GL?
@g4s8 let's ask the client to check GL status for at least 10 minutes?
@yegor256 it should work, but in this scenario we need to store job id to be able to check payment status between client restarts
@g4s8 how about we add this: When a client sends /do-pay
it also sends some unique ID of the request (anything the client makes up) and WTS keeps it in the database. Later, if the client comes back again with do-pay
and the previous request is not fully closed, WTS doesn't allow to send any more payments until the client retrieves the info about the job, and returns that unique ID back to the client, suggesting to do something with the previous job. Something like this.
This way the client doesn't need to persist anything, the WTS will do it for them.
@yegor256 but client have to store some details in any case - e.g. if 0crat is paying a debt, it can generate unique id for debt payment to check it later, but debt may change between /do-pay
call and status check.
Maybe WTS can allow to store some additional details about payment in do-pay? E.g. 0crat may send debt details or payment details (including author, reason, etc, to parse it later in case of error) in /do-pay
, then retrieve a list of all payment jobs periodically (e.g. every hour) and check the status of each job, and the status can be OK
, RUNNING
or ERROR
, if status is OK
0crat notifies a user about a payment and wts removes this job (or 0crat may ask to remove via API), if PENDING
0crat will skip it, if ERROR
0crat will parse payment details for this job and add this payment back to debts (WTS also removes this job).
@g4s8 how about this idea. Every time you send a payment you add a date
field to it. You create that date locally and send it over. And you send your requests via ReHTTP.net. The presence of the date
inside the payment details will guarantee that the transaction will be added to the Zold wallet only once, no matter how many times WTS will receive the POST request, because all requests except the right one will be rejected -- their date
field will conflict with the existing one. WDYT?
@yegor256 I think it should work
0crat failed to pay because of this error:
Update: actually I received the payment to zold wallet, so I'll remove it manually from 0crat debt.