naive: update aggregator cached naive state eagerly

The aggregator keeps a cached naive state that is recreated using the 
canonical L2 state from the %azimuth agent, every time a new L2 tx comes 
in via +take-tx (used by clients of the aggregator).

This makes the cached state ahead of the canonical L2 state, but 
recreated every time a client sends a tx, using the list of pending (not 
sent out to an ethereum node) and sending (waiting confirmation from 
L1). This step drops any pending and sending transactions that do not 
apply correctly.

Hearing about a new L2 tx confirmed in L1 (+on-naive-diff) removes such 
transaction from the sending list, but does not update the cached state, 
since this was already done when the L2 tx was seen in +take-tx.
This commit is contained in:
yosoyubik 2021-06-05 14:24:37 +02:00
parent 9c70e006a1
commit a01289145b

View File

@ -405,25 +405,49 @@
==
:: +pending-state
::
:: derives tentative state from pending txs and canonical state,
:: discarding invalid pending txs in the process.
:: derives tentative state from pending/sending txs and
:: canonical state, discarding invalid txs in the process.
::
++ pending-state
|= nas=^state:naive
^- [_pending _nas]
:: apply our pending transactions
::TODO should also apply txs from sending map!
::
=| valid=_pending
|- ^+ [valid nas]
?~ pending [(flop valid) nas]
|^
=^ new-sending nas apply-sending
=. sending new-sending
(update-txs pending)
::
=^ gud=? nas (try-apply nas i.pending)
=? valid gud [i.pending valid]
=? finding =(gud %.n)
%- ~(put by finding)
[(hash-raw-tx raw-tx.i.pending) %failed]
$(pending t.pending)
++ apply-sending
=| valid=_sending
=+ sending=~(tap by sending)
|- ^+ [valid nas]
?~ sending [valid nas]
::
=* key p.i.sending
=* val q.i.sending
=^ new-valid nas
:: prepends force=%.n to all txs
::
(update-txs (turn txs.val (lead |)))
=. valid
%+ ~(put by valid) key
val(txs (turn new-valid tail))
$(sending t.sending)
::
++ update-txs
|= txs=(list [force=? =raw-tx:naive])
=/ valid=_txs ~
|- ^+ [valid nas]
?~ txs [valid nas]
=* tx i.txs
=^ gud=? nas (try-apply nas tx)
=? valid gud (snoc valid tx)
=? finding =(gud %.n)
%- ~(put by finding)
[(hash-raw-tx raw-tx.tx) %failed]
$(txs t.txs)
--
:: +try-apply:
::
++ try-apply
@ -632,10 +656,7 @@
:: unexpected tx failures here. would that be useful? probably not?
:: ~? !forced [dap.bowl %aggregated-tx-failed-anyway err.diff]
%failed
=/ [nep=_pending nas=_nas] (pending-state canonical-state)
:: update cached naive state with confirmed tx from diff
::
=^ * nas (try-apply nas | raw-tx.diff)
[~ state(pending nep)]
[~ state]
::
--