mirror of
https://github.com/urbit/shrub.git
synced 2024-12-19 00:13:12 +03:00
roller: wip finding map simplification
This commit is contained in:
parent
21139ea8de
commit
a392ccde58
@ -52,8 +52,7 @@
|
|||||||
:: but we don't know the nonce for the batch they'd belong to
|
:: but we don't know the nonce for the batch they'd belong to
|
||||||
::
|
::
|
||||||
%+ map [=keccak nonce=(unit @ud)]
|
%+ map [=keccak nonce=(unit @ud)]
|
||||||
:: TODO: map used for efficiency, but txs=(list l2-status) instead?
|
?(%confirmed %failed [=time =address:ethereum])
|
||||||
[seen=@ud txs=(map @ud l2-status)]
|
|
||||||
::
|
::
|
||||||
history=(jug address:ethereum roll-tx)
|
history=(jug address:ethereum roll-tx)
|
||||||
next-nonce=(unit @ud)
|
next-nonce=(unit @ud)
|
||||||
@ -157,7 +156,7 @@
|
|||||||
:: /x/pending -> %noun (list pend-tx)
|
:: /x/pending -> %noun (list pend-tx)
|
||||||
:: /x/pending/[~ship] -> %noun (list pend-tx)
|
:: /x/pending/[~ship] -> %noun (list pend-tx)
|
||||||
:: /x/pending/[0xadd.ress] -> %noun (list pend-tx)
|
:: /x/pending/[0xadd.ress] -> %noun (list pend-tx)
|
||||||
:: /x/tx/[0xke.ccak]/status -> %noun tx-status
|
:: /x/tx/[0xke.ccak]/[@ud]status -> %noun tx-status
|
||||||
:: /x/history/[0xadd.ress] -> %noun (list roll-tx)
|
:: /x/history/[0xadd.ress] -> %noun (list roll-tx)
|
||||||
:: /x/nonce/[~ship]/[proxy] -> %noun (unit @)
|
:: /x/nonce/[~ship]/[proxy] -> %noun (unit @)
|
||||||
:: /x/spawned/[~star] -> %noun (list ship)
|
:: /x/spawned/[~star] -> %noun (list ship)
|
||||||
@ -167,11 +166,11 @@
|
|||||||
:: /x/ships/[0xadd.ress] -> %noun (list ship)
|
:: /x/ships/[0xadd.ress] -> %noun (list ship)
|
||||||
:: /x/config -> %noun config
|
:: /x/config -> %noun config
|
||||||
:: /x/chain-id -> %atom @
|
:: /x/chain-id -> %atom @
|
||||||
:: /x/owned -> %noun (list ship)
|
:: /x/owned/[0xadd.ress] -> %noun (list ship)
|
||||||
:: /x/transfers -> %noun (list ship)
|
:: /x/transfers/[0xadd.ress] -> %noun (list ship)
|
||||||
:: /x/manager -> %noun (list ship)
|
:: /x/manager/[0xadd.ress] -> %noun (list ship)
|
||||||
:: /x/voting -> %noun (list ship)
|
:: /x/voting/[0xadd.ress] -> %noun (list ship)
|
||||||
:: /x/spawning -> %noun (list ship)
|
:: /x/spawning/[0xadd.ress] -> %noun (list ship)
|
||||||
:: /x/predicted -> %noun state:naive
|
:: /x/predicted -> %noun state:naive
|
||||||
::
|
::
|
||||||
++ on-peek
|
++ on-peek
|
||||||
@ -181,8 +180,7 @@
|
|||||||
?+ path ~
|
?+ path ~
|
||||||
[%x %pending ~] ``noun+!>(pending)
|
[%x %pending ~] ``noun+!>(pending)
|
||||||
[%x %pending @ ~] (pending-by i.t.t.path)
|
[%x %pending @ ~] (pending-by i.t.t.path)
|
||||||
:: TODO: implement this
|
[%x %tx @ @ %status ~] (status i.t.t.path i.t.t.t.path)
|
||||||
:: [%x %tx @ %status ~] (status i.t.t.path)
|
|
||||||
[%x %pending-tx @ ~] (transaction i.t.t.path)
|
[%x %pending-tx @ ~] (transaction i.t.t.path)
|
||||||
[%x %history @ ~] (history i.t.t.path)
|
[%x %history @ ~] (history i.t.t.path)
|
||||||
[%x %nonce @ @ ~] (nonce i.t.t.path i.t.t.t.path)
|
[%x %nonce @ @ ~] (nonce i.t.t.path i.t.t.t.path)
|
||||||
@ -224,23 +222,24 @@
|
|||||||
|= pend-tx
|
|= pend-tx
|
||||||
=(u.who ship.from.tx.raw-tx)
|
=(u.who ship.from.tx.raw-tx)
|
||||||
::
|
::
|
||||||
:: ++ status
|
++ status
|
||||||
:: |= wat=@t
|
|= wat=[@t @t]
|
||||||
:: ?~ keccak=(slaw %ux wat)
|
?~ keccak=(slaw %ux -.wat)
|
||||||
:: [~ ~]
|
[~ ~]
|
||||||
:: :+ ~ ~
|
?~ nonce=(slaw %ud +.wat)
|
||||||
:: :- %noun
|
[~ ~]
|
||||||
:: !> ^- tx-status
|
:+ ~ ~
|
||||||
:: ?^ status=(~(get by finding) u.keccak)
|
:- %noun
|
||||||
:: ?@ u.status [u.status ~]
|
!> ^- tx-status
|
||||||
:: [%sending `+.u.status]
|
?^ status=(~(get by finding) [u.keccak nonce])
|
||||||
:: :: TODO: potentially slow!
|
?@ u.status [u.status ~]
|
||||||
:: :: TODO: use ~(get by history) instead
|
[%sending `[+.u.status u.nonce]]
|
||||||
:: =; known=?
|
:: TODO: potentially slow!
|
||||||
:: [?:(known %pending %unknown) ~]
|
=; known=?
|
||||||
:: %+ lien pending
|
[?:(known %pending %unknown) ~]
|
||||||
:: |= pend-tx
|
%+ lien pending
|
||||||
:: =(u.keccak (hash-tx:lib raw.raw-tx))
|
|= pend-tx
|
||||||
|
=(u.keccak (hash-raw-tx:lib raw-tx))
|
||||||
::
|
::
|
||||||
++ transaction
|
++ transaction
|
||||||
|= wat=@t
|
|= wat=@t
|
||||||
@ -619,9 +618,7 @@
|
|||||||
[hash `new-nonce]
|
[hash `new-nonce]
|
||||||
?~ val=(~(get by finding) old-key)
|
?~ val=(~(get by finding) old-key)
|
||||||
finding
|
finding
|
||||||
?~ txs.u.val
|
?. ?=(^ u.val) finding
|
||||||
~? lverb [dap.bowl %empty-finding-tx]
|
|
||||||
finding
|
|
||||||
%. [new-key u.val]
|
%. [new-key u.val]
|
||||||
~(put by (~(del by finding) old-key))
|
~(put by (~(del by finding) old-key))
|
||||||
--
|
--
|
||||||
@ -803,13 +800,7 @@
|
|||||||
[%tx address.tx roll-tx(status %failed)]
|
[%tx address.tx roll-tx(status %failed)]
|
||||||
=? valid gud (snoc valid tx)
|
=? valid gud (snoc valid tx)
|
||||||
=? finding.state !gud
|
=? finding.state !gud
|
||||||
=+ index=~(wyt in local)
|
(~(put by finding) [hash nonce] %failed)
|
||||||
%+ ~(put by finding) [hash nonce]
|
|
||||||
:- 0
|
|
||||||
%. [index %failed]
|
|
||||||
?^ l2-txs=(~(get by finding) [hash nonce])
|
|
||||||
~(put by txs.u.l2-txs)
|
|
||||||
~(put by *(map @ud l2-status))
|
|
||||||
::
|
::
|
||||||
=? history.state !gud
|
=? history.state !gud
|
||||||
%. [address.tx roll-tx(status %failed)]
|
%. [address.tx roll-tx(status %failed)]
|
||||||
@ -887,10 +878,20 @@
|
|||||||
++ cancel-tx
|
++ cancel-tx
|
||||||
|= [sig=@ =keccak =l2-tx =ship]
|
|= [sig=@ =keccak =l2-tx =ship]
|
||||||
^- (quip card _state)
|
^- (quip card _state)
|
||||||
:: TODO: try with all the nonces in sending?
|
:: TODO: use an index for tracking pending-tx?
|
||||||
::
|
::
|
||||||
?^ status=(~(get by finding) keccak next-nonce)
|
:: ?^ status=(~(get by finding) keccak next-nonce)
|
||||||
~? lverb [dap.bowl %tx-not-pending status+u.status]
|
:: ~? lverb [dap.bowl %tx-not-pending status+u.status]
|
||||||
|
:: [~ state]
|
||||||
|
=^ time pending
|
||||||
|
=| nep=(list pend-tx)
|
||||||
|
|- ^- [(unit time) _nep]
|
||||||
|
?~ pending [~ nep]
|
||||||
|
?: =(keccak (hash-raw-tx:lib raw-tx.i.pending))
|
||||||
|
[`time.i.pending (weld (flop nep) t.pending)]
|
||||||
|
$(pending t.pending, nep [i.pending nep])
|
||||||
|
?~ time
|
||||||
|
~? lverb [dap.bowl %tx-not-pending]
|
||||||
[~ state]
|
[~ state]
|
||||||
:: "cancel: 0x1234abcd"
|
:: "cancel: 0x1234abcd"
|
||||||
::
|
::
|
||||||
@ -907,22 +908,11 @@
|
|||||||
?~ addr=(verify-sig:lib sig message)
|
?~ addr=(verify-sig:lib sig message)
|
||||||
~? lverb [dap.bowl %cancel-sig-fail]
|
~? lverb [dap.bowl %cancel-sig-fail]
|
||||||
[~ state]
|
[~ state]
|
||||||
=^ time pending
|
|
||||||
=| nep=(list pend-tx)
|
|
||||||
=| tx-time=time
|
|
||||||
|- ^- [time _pending]
|
|
||||||
?~ pending [tx-time nep]
|
|
||||||
=+ i.pending
|
|
||||||
=? tx-time =(keccak (hash-raw-tx:lib raw-tx))
|
|
||||||
time
|
|
||||||
=? nep !=(keccak (hash-raw-tx:lib raw-tx))
|
|
||||||
(snoc nep i.pending)
|
|
||||||
$(pending t.pending)
|
|
||||||
:: TODO: mark as failed instead? add a %cancelled to tx-status?
|
:: TODO: mark as failed instead? add a %cancelled to tx-status?
|
||||||
::
|
::
|
||||||
=. history
|
=. history
|
||||||
%+ ~(del ju history) u.addr
|
%+ ~(del ju history) u.addr
|
||||||
[ship %pending keccak time l2-tx]
|
[ship %pending keccak u.time l2-tx]
|
||||||
[~ state]
|
[~ state]
|
||||||
:: +take-tx: accept submitted l2 tx into the :pending list
|
:: +take-tx: accept submitted l2 tx into the :pending list
|
||||||
::
|
::
|
||||||
@ -999,15 +989,11 @@
|
|||||||
[0 | (turn pending (cork tail (cork tail tail)))]
|
[0 | (turn pending (cork tail (cork tail tail)))]
|
||||||
::
|
::
|
||||||
finding
|
finding
|
||||||
%+ roll pending
|
%- ~(gas by finding)
|
||||||
|= [pend-tx finding=_finding]
|
%+ turn pending
|
||||||
=/ key [(hash-raw-tx:lib raw-tx) `nonce]
|
|= pend-tx
|
||||||
=/ val [time address]
|
:_ [time address]
|
||||||
%+ ~(put by finding) key
|
[(hash-raw-tx:lib raw-tx) `nonce]
|
||||||
:- 0
|
|
||||||
?~ send-txs=(~(get by finding) key)
|
|
||||||
(~(put by *(map @ud l2-status)) 0 val)
|
|
||||||
(~(put by txs.u.send-txs) ~(wyt by txs.u.send-txs) val)
|
|
||||||
==
|
==
|
||||||
:_ state
|
:_ state
|
||||||
;: welp
|
;: welp
|
||||||
@ -1142,25 +1128,13 @@
|
|||||||
:: tx not submitted by this roller
|
:: tx not submitted by this roller
|
||||||
::
|
::
|
||||||
[~ state]
|
[~ state]
|
||||||
?~ txs.u.wer
|
?@ u.wer
|
||||||
~? lverb [dap.bowl %empty-finding-for keccak nonce+nonce]
|
~? &(?=(%confirmed u.wer) ?=(~ err.diff))
|
||||||
[~ state]
|
|
||||||
=/ [index=@ud l2-txs=(map @ud l2-status)] u.wer
|
|
||||||
:: if we had already seen all l2-tx, no-op
|
|
||||||
::
|
|
||||||
?: =(index ~(wyt by l2-txs))
|
|
||||||
~? lverb [dap.bowl %all-l2-txs-seen keccak nonce+nonce]
|
|
||||||
[~ state]
|
|
||||||
=/ current-tx=l2-status (~(got by l2-txs) index)
|
|
||||||
:: if we had already seen the tx, no-op
|
|
||||||
::
|
|
||||||
?@ current-tx
|
|
||||||
~? &(?=(%confirmed current-tx) ?=(~ err.diff))
|
|
||||||
[dap.bowl %weird-double-confirm from.tx.raw-tx.diff]
|
[dap.bowl %weird-double-confirm from.tx.raw-tx.diff]
|
||||||
[~ state]
|
[~ state]
|
||||||
=* address address.current-tx
|
=* address address.u.wer
|
||||||
=* time time.current-tx
|
|
||||||
=* ship ship.from.tx.raw-tx.diff
|
=* ship ship.from.tx.raw-tx.diff
|
||||||
|
=* time time.u.wer
|
||||||
=* tx tx.raw-tx.diff
|
=* tx tx.raw-tx.diff
|
||||||
=/ l2-tx (l2-tx +<.tx)
|
=/ l2-tx (l2-tx +<.tx)
|
||||||
:: remove the tx from the sending map
|
:: remove the tx from the sending map
|
||||||
@ -1184,8 +1158,6 @@
|
|||||||
::
|
::
|
||||||
=. finding
|
=. finding
|
||||||
%+ ~(put by finding) [keccak `nonce]
|
%+ ~(put by finding) [keccak `nonce]
|
||||||
:- +(index)
|
|
||||||
%+ ~(put by l2-txs) index
|
|
||||||
?~ err.diff %confirmed
|
?~ err.diff %confirmed
|
||||||
:: if we kept the forced flag around for longer, we could notify of
|
:: if we kept the forced flag around for longer, we could notify of
|
||||||
:: unexpected tx failures here. would that be useful? probably not?
|
:: unexpected tx failures here. would that be useful? probably not?
|
||||||
|
@ -206,8 +206,13 @@
|
|||||||
++ hash-tx keccak-256:keccak:crypto
|
++ hash-tx keccak-256:keccak:crypto
|
||||||
::
|
::
|
||||||
++ hash-raw-tx
|
++ hash-raw-tx
|
||||||
|= =raw-tx:naive
|
|= raw-tx:naive
|
||||||
^- @ux
|
^- @ux
|
||||||
(hash-tx raw.raw-tx)
|
%- hash-tx
|
||||||
|
%: cad:naive 3
|
||||||
|
65^sig
|
||||||
|
raw
|
||||||
|
~
|
||||||
|
==
|
||||||
::
|
::
|
||||||
--
|
--
|
||||||
|
Loading…
Reference in New Issue
Block a user