relayer/docs/queries-latest-version.md
-- TODO: change this to uniform names. (internal_decryption_id to internal_indexer_id) to bytea and enable hashmap ! we store as bytea not text (possibility of hash index) OK. -- TODO: Change tx_sent to receipt_received status (MORE CLARITY.) OK. -- DESIGNS COMMENTS: RETURN AS MINIMAL FIELDS AS POSSIBLE. -- use consistent structure for internal_req_id and external_req_id (or int ext) Ok.
At startup of the relayer: (purpose, take the state where we left at.) 2 queries -> 1. 1. query all tables mixed and ordered by updated_at for status = 'queued', returns: int_indexer_id, req -> We will trigger readiness checker on this one. ()
2. query all tables mixed and ordered by updated_at for status = 'processing'
returns: int_indexer_id, req
-> will trigger transaction helper -> (readiness has already passed.)
POST REQUEST => we receive a payload (v2)
internal_indexer_id from payloaduser_decrypt_req table.
ext_reference_id to the user with 202 OK.req, ext_reference_id, int_indexer_id. use ON CONFLICT METHOD for insert. if conflict get ext_reference_id.
v2 routes -> return ext reqId with 202 Created..NEW FLOW POST:
Compute internal_indexer_id from payload
Check if it there in the user_decrypt_req table.
If it already exists: return the ext_reference_id to the user with 202 OK.
If not.
req, ext_reference_id, int_indexer_id. use ON CONFLICT METHOD for insert. if conflict get ext_reference_id.
v2 routes -> return ext reqId with 202 Created..Gateway readiness checker is triggered (large timeout, ~30 min coverage)
int_indexer_id for field req_status = processing -> Transaction::Sendint_indexer_id req_status = timed_out + err_reason
-> UserDecrypt::Failed emitted.RelayerEvent Transaction::Send is emitted.
receipt_received + gw_req_tx_hash + gw_reference_id by int_indexer_id(we have the receipt at this point) -> We process the receipt. and we dispatchfailure and err_reason by int_indexer_id -> Dispatch error event as before to the orchestrator-- Execute every one min in sql queries pg_cron. (We do at the end not now, just write the query.)
// later do it as a pg_cron !!! 5. If status == 'receipt_received' and now - updated_at > 30 min. - update by int_indexer_id req_status = timed_out + err_reason='response timed out' (SAME QUERY IN POST MODE.)
user_decrypt_req table gw_consensus_tx_hash = value, where gw_reference_id if consensus_tx_hash is null, and status = 'receipt_received' and return (status, updated_at, err_reason, int_indexer_id,)
Rationale: Want to update the table when status = 'receipt_received' in either case. I want the actual status in the raw. for example: -> if the status is timed_out, i want to get status and updated at, in this case row affected will be zero. (we need err_reason and int_indexer_id)
in one query:
select user_decrypt_req where gw_reference_id and if consensus_tx_hash=null, and if status = 'receipt_received' update consensus_tx_hash = value received -> return (status, updated_at, err_reason, int_indexer_id,)
OR:
update user_decrypt_req table gw_consensus_tx_hash = value, where gw_reference_id if consensus_tx_hash is null, and status = 'receipt_received'
select (status, updated_at, err_reason, int_indexer_id,) where gw_reference_id = value
here. 6. IF THIS IS A SHARE: [2 transactions / 2 calls]
// This lead to possibility of non relevant shares (DOCUMENT THIS !!!!! ON CODE.) // This also does not respect the status due to timeout on request context (ud tables.) // Even for timeouts, we are registering incoming shares.
transaction/call 1. insert into `user_decrypt_share` -> gw_reference_id, share_index, share, kms_signature, extra_data -> Return the count of total shares by `gw_reference_id` (QUERY)
transaction/call 2. if count = threshold -> update `user_decrypt_req` table status = `completed` on `gw_reference_id` status != 'timeout' (ONLY ONE SINGLE TX QUERY)
- return all the shares (IN THE SAME TX QUERY) + `int_indexer_id` + status + updated_at + err_reason
7. INternally: we forward event is received as it is already done in our internal logic. (timeout logic etc...)
GET REQUEST will pass to get route: ext_req_id
user_decrypt_req by ext_reference_id and join on gw_reference_id to get all lines of user_decrypt_share 1 query. (need status field on query return + shares + updated at field)completed -> construct the response with the fields we queried.processing -> return updated_at and ext_request_id and status with 202.queued or receipt_received -> return back ext_reference_id with status and updated_at field.timed_out 504 return ext_req_id + status.failure 400 return ext_req_id + status + err_reason.DONE FOR U.D.
NOTE: PAUSING STRATEGY.
POST REQUEST => we receive a payload (v2)
internal_indexer_id from payloadpublic_decrypt_req table.
ext_req_id to the user with 202 OK.req, ext_reference_id, internal_indexer_id. use ON CONFLICT METHOD for insert. if conflict get ext_reference_id.
v2 routes -> return ext reqId with 202 Created..NEW POST FLOW (v2)
Compute int_indexer_id from payload
Check if it there in the public_decrypt_req table.
If it already exists: return the ext_req_id to the user with 202 OK.
In new API, if already exists, we can return the result to user. so we need res + status as well. Build it.
If not.
Call host ACL readiness checker as an async function. (DUMMY always pass for next implem - we will do it later with a host listener - substreams/poller...)
req, ext_reference_id, internal_indexer_id. use ON CONFLICT METHOD for insert. if conflict get ext_reference_id.
v2 routes -> return ext reqId with 202 Created..Gateway readiness checker is triggered (large timeout, ~30 min coverage)
int_indexer_id for field req_status = processing -> Transaction::Sendint_indexer_id req_status = timed_out + err_reason
-> PublicDecrypt::Failed emitted.RelayerEvent Transaction::Send is emitted.
receipt_received + gw_req_tx_hash + gw_reference_id by int_indexer_id (we have the receipt at this point) -> We process the receipt. and we dispatchfailure and err_reason by int_indexer_id -> Dispatch error event as before to the orchestratorListener receive public_decrypt share events transaction.
INternally: we forward event is received as it is already done in our internal logic.
GET REQUEST will pass to get route: ext_reference_id
public_decrypt_req by ext_reference_id (need status res and err_reason and updated_at and ext_request_id)completed -> we return 200 with response.processing -> return updated_at and ext_request_id and status with 202.queued or receipt_received -> return back ext_reference_id with status and updated_at field.timed_out 504 return ext_req_id + status.failure 400 return ext_req_id + status + err_reason.TIME OUT STRATEGY:
-- Execute every one min in sql queries pg_cron. (We do at the end not now, just write the query.)
// later do it as a pg_cron !!! 5. If status == 'receipt_received' and now - updated_at > 30 min. - update by int_indexer_id req_status = timed_out + err_reason='response timed out' (SAME QUERY IN POST MODE.)
POST REQUEST => we receive a payload (v2)
internal_request_id.ext_reference_id, int_request_id, request into input_proof_req
v2 routes -> return ext_reference_id with 202 Created..RelayerEvent Transaction::Send is emitted.
receipt_received + gw_req_tx_hash + gw_reference_id by int_request_id(we have the receipt at this point) -> We process the receipt. and we dispatchfailure and err_reason by int_request_id -> Dispatch error event as before to the orchestratorListener receive input_proof share events transaction.
input_proof_req table: res = received value from gw where gateway_reference_id = value in the event and req_status = completed and accepted = true + gw_response_tx_hash (return int_request_id)int_request_id) (adding res to it as well...)INternally: we forward event is received as it is already done in our internal logic.
GET REQUEST will pass to get route: ext_reference_id
input_proof_req by ext_reference_id (need status response and err_reason and updated_at, and accepted and req_status)completed -> we return 200 with response and acceptedqueued or receipt_received -> return back ext_req_id with status and updated_at field. and accepted=nulltimed_out 504 return ext_req_id + status.failure 400 return ext_req_id + status + err_reason.TIME OUT STRATEGY:
-- Execute every one min in sql queries pg_cron. (We do at the end not now, just write the query.)
// later do it as a pg_cron !!! 5. If status == 'receipt_received' and now - updated_at > 30 min. - update by int_indexer_id req_status = timed_out + err_reason='response timed out' (SAME QUERY IN POST MODE.)