roller: clean up

This commit is contained in:
yosoyubik 2021-08-04 15:53:57 +02:00
parent 31e5dd206d
commit d559ad35bc
5 changed files with 50 additions and 56 deletions

View File

@ -74,6 +74,7 @@
== ==
:: ::
+$ init [nas=^state:naive own=owners] +$ init [nas=^state:naive own=owners]
::
+$ config +$ config
$% [%frequency frequency=@dr] $% [%frequency frequency=@dr]
[%setkey pk=@] [%setkey pk=@]
@ -82,14 +83,13 @@
== ==
:: ::
+$ action +$ action
$% :: we need to include the address here so pending txs show up $% :: we need to include the address in submit so pending txs show up
:: in the tx history, but because users can send the wrong :: in the tx history, but because users can send the wrong
:: address, in +update-tx:predicted state, we just replace :: address, in +apply-tx:predicted state, we just replace
:: the provided address, with the one used when the message was signed; :: the provided address, with the one used when the message was signed;
:: ::
:: we need to do it there to know the correct nonce that the signed :: we need to do it there to know the correct nonce that the signed
:: message should have included. :: message should have included.
:: note: currently turned off (extract-address is giving the wrong address)
:: ::
[%submit force=? =address:naive sig=@ tx=part-tx] [%submit force=? =address:naive sig=@ tx=part-tx]
[%cancel sig=@ keccak=@ =l2-tx =ship] [%cancel sig=@ keccak=@ =l2-tx =ship]
@ -159,6 +159,7 @@
:: /x/point/[~ship] -> %noun point:naive :: /x/point/[~ship] -> %noun point:naive
:: /x/points/[0xadd.ress] -> %noun (list [ship point:naive]) :: /x/points/[0xadd.ress] -> %noun (list [ship point:naive])
:: /x/config -> %noun config :: /x/config -> %noun config
:: /x/chain-id -> %atom @
:: ::
++ on-peek ++ on-peek
|= =path |= =path
@ -483,7 +484,7 @@
%don [(gen-tx-octs:lib +.part-tx) +.part-tx] %don [(gen-tx-octs:lib +.part-tx) +.part-tx]
%ful +.part-tx %ful +.part-tx
== ==
:: +canonical-state: load current l2 state from /app/azimuth :: +canonical-state: current l2 state from /app/azimuth
:: ::
++ canonical-state ++ canonical-state
.^ ^state:naive .^ ^state:naive
@ -493,7 +494,7 @@
(scot %da now.bowl) (scot %da now.bowl)
/nas/noun /nas/noun
== ==
:: +canonical-owners: load current azimuth point ownership :: +canonical-owners: current azimuth point ownership
:: ::
++ canonical-owners ++ canonical-owners
.^ owners .^ owners
@ -505,8 +506,8 @@
== ==
:: +predicted-state :: +predicted-state
:: ::
:: derives predicted state from pending/sending txs and :: derives predicted state from applying pending/sending txs to
:: canonical state, discarding invalid txs in the process. :: the canonical state, discarding invalid txs in the process.
:: ::
++ predicted-state ++ predicted-state
|= nas=^state:naive |= nas=^state:naive
@ -514,11 +515,11 @@
=. pre.state nas =. pre.state nas
|^ |^
=^ nes state apply-sending =^ nes state apply-sending
=^ nep state (update-txs pending %pending) =^ nep state apply-pending
%_ state state(sending nes, pending nep)
sending nes ::
pending nep ++ apply-pending
== (apply-txs pending %pending)
:: ::
++ apply-sending ++ apply-sending
=| valid=_sending =| valid=_sending
@ -529,7 +530,7 @@
=* key p.i.sending =* key p.i.sending
=* val q.i.sending =* val q.i.sending
=^ new-valid state =^ new-valid state
%+ update-txs %+ apply-txs
(turn txs.val |=(=raw-tx:naive [| 0x0 raw-tx])) (turn txs.val |=(=raw-tx:naive [| 0x0 raw-tx]))
%sending %sending
=. valid =. valid
@ -537,7 +538,7 @@
val(txs (turn new-valid (cork tail tail))) val(txs (turn new-valid (cork tail tail)))
$(sending t.sending) $(sending t.sending)
:: ::
++ update-txs ++ apply-txs
|= [txs=(list pend-tx) type=?(%pending %sending)] |= [txs=(list pend-tx) type=?(%pending %sending)]
=/ valid=_txs ~ =/ valid=_txs ~
=| local=(set keccak) =| local=(set keccak)
@ -565,8 +566,8 @@
(~(put by finding.state) [hash %failed]) (~(put by finding.state) [hash %failed])
=? history.state !gud =? history.state !gud
=/ =roller-tx =/ =roller-tx
[ship [type ~] hash (l2-tx +<.tx.raw-tx)] [ship type hash (l2-tx +<.tx.raw-tx)]
%. [address.tx roller-tx(status [%failed ~])] %. [address.tx roller-tx(status %failed)]
~(put ju (~(del ju history.state) address.tx roller-tx)) ~(put ju (~(del ju history.state) address.tx roller-tx))
$(txs t.txs, local (~(put in local) hash)) $(txs t.txs, local (~(put in local) hash))
:: ::
@ -658,7 +659,7 @@
:: ::
=. history =. history
%+ ~(del ju history) u.addr %+ ~(del ju history) u.addr
[ship [%pending ~] keccak l2-tx] [ship %pending keccak l2-tx]
=. pending =. pending
%+ skip pending %+ skip pending
|= pend-tx |= pend-tx
@ -682,7 +683,7 @@
:: =? history not-sent :: =? history not-sent
=. history =. history
%+ ~(put ju history) address %+ ~(put ju history) address
[ship.from.tx.raw-tx [%pending ~] hash (l2-tx +<.tx.raw-tx)] [ship.from.tx.raw-tx %pending hash (l2-tx +<.tx.raw-tx)]
=? transfers =(%transfer-point (l2-tx +<.tx.raw-tx)) =? transfers =(%transfer-point (l2-tx +<.tx.raw-tx))
(~(put by transfers) ship.from.tx.raw-tx address) (~(put by transfers) ship.from.tx.raw-tx address)
:: ?. not-sent ~& "skip" [~ state] :: ?. not-sent ~& "skip" [~ state]
@ -729,12 +730,12 @@
|= [pend-tx hist=_history] |= [pend-tx hist=_history]
=/ tx=roller-tx =/ tx=roller-tx
:^ ship.from.tx.raw-tx :^ ship.from.tx.raw-tx
[%pending ~] %pending
(hash-raw-tx:lib raw-tx) (hash-raw-tx:lib raw-tx)
(l2-tx +<.tx.raw-tx) (l2-tx +<.tx.raw-tx)
%+ ~(put ju (~(del ju hist) address tx)) %+ ~(put ju (~(del ju hist) address tx))
address address
tx(status [%sending ~]) tx(status %sending)
== ==
[(send-roll get-address nonce) state] [(send-roll get-address nonce) state]
=^ card next-batch set-timer =^ card next-batch set-timer
@ -842,7 +843,7 @@
:: ::
=. history =. history
=/ l2-tx (l2-tx +<.tx.raw-tx.diff) =/ l2-tx (l2-tx +<.tx.raw-tx.diff)
=/ tx=roller-tx [ship [%sending ~] keccak l2-tx] =/ tx=roller-tx [ship %sending keccak l2-tx]
?~ addr=(get-l1-address tx.raw-tx.diff pre) ?~ addr=(get-l1-address tx.raw-tx.diff pre)
history history
=/ =address:ethereum =/ =address:ethereum
@ -854,7 +855,7 @@
%+ ~(put ju (~(del ju history) address tx)) %+ ~(put ju (~(del ju history) address tx))
address address
%_ tx %_ tx
status ?~(err.diff [%confirmed ~] [%failed ~]) status ?~(err.diff %confirmed %failed)
== ==
:_ state(derive-p ?:(derive-p | derive-p)) :_ state(derive-p ?:(derive-p | derive-p))
?. derive-p ~ ?. derive-p ~

View File

@ -77,7 +77,7 @@
:: ::
++ run-logs ++ run-logs
|= [state=app-state logs=(list event-log:rpc:ethereum)] |= [state=app-state logs=(list event-log:rpc:ethereum)]
^- [(list tagged-diff) _state] ^- (quip tagged-diff _state)
=/ [contract=@ux * chain-id=@ *] (get-network net) =/ [contract=@ux * chain-id=@ *] (get-network net)
?~ logs ?~ logs
`state `state
@ -342,14 +342,7 @@
%logs (welp logs.state loglist.diff) %logs (welp logs.state loglist.diff)
== ==
=? nas.state ?=(%history -.diff) *^state:naive =? nas.state ?=(%history -.diff) *^state:naive
=^ effects state =^ effects state (run-logs state loglist.diff)
=; nas=^state:naive
(run-logs state(nas nas) loglist.diff)
?- -.diff
:: %history *^state:naive
%history nas.state
%logs nas.state
==
:: ::
:_ this :_ this
%+ weld %+ weld

View File

@ -189,17 +189,16 @@
^- json ^- json
%- pairs %- pairs
:~ ['force' b+force] :~ ['force' b+force]
['address' s+(crip "0x{((x-co:co 20) address)}")] (en-address address)
:: ::
:- 'rawTx' :- 'rawTx'
%- pairs %- pairs
:~ ['tx' (tx:to-json tx.raw-tx)] :~ ['tx' (tx:to-json tx.raw-tx)]
:: ['sig' (hex (as-octs:mimes:html sig.raw-tx))]
:+ 'sig' %s
%- crip
"0x{((x-co:co (met 3 sig.raw-tx)) sig.raw-tx)}"
== == == ==
:: ::
++ en-address |=(a=@ux address+(hex 20 a))
::
++ tx ++ tx
|= =tx:naive |= =tx:naive
^- json ^- json
@ -235,7 +234,6 @@
== == == ==
:: ::
++ en-ship |=(s=@p ship+(ship s)) ++ en-ship |=(s=@p ship+(ship s))
++ en-address |=(a=@ux address+s+(crip "0x{((x-co:co 20) a)}"))
++ en-spawn |=([s=@p a=@ux] ~[(en-ship s) (en-address a)]) ++ en-spawn |=([s=@p a=@ux] ~[(en-ship s) (en-address a)])
++ en-transfer |=([a=@ux r=?] ~[(en-address a) reset+b+r]) ++ en-transfer |=([a=@ux r=?] ~[(en-address a) reset+b+r])
++ en-keys ++ en-keys
@ -261,8 +259,8 @@
|= roller-tx |= roller-tx
^- json ^- json
%- pairs %- pairs
:~ ['status' s+status.status] :~ ['status' s+status]
['hash' s+(crip "0x{((x-co:co 20) hash)}")] ['hash' (hex (as-octs:mimes:html hash))]
['type' s+type] ['type' s+type]
== ==
:: ::
@ -325,7 +323,7 @@
|= [=address:naive =nonce:naive] |= [=address:naive =nonce:naive]
^- json ^- json
%- pairs %- pairs
:~ ['address' s+(crip "0x{((x-co:co 20) address)}")] :~ (en-address address)
['nonce' (numb nonce)] ['nonce' (numb nonce)]
== ==
:: ::
@ -334,10 +332,10 @@
^- json ^- json
:- %a :- %a
%+ turn children %+ turn children
|= [child=@p addr=@ux] |= [child=@p address=@ux]
%- pairs %- pairs
:~ ['ship' (ship child)] :~ ['ship' (ship child)]
['address' s+(crip "0x{((x-co:co 20) addr)}")] (en-address address)
== ==
:: ::
++ tx-status |=(=^tx-status ^-(json s+status.tx-status)) ++ tx-status |=(=^tx-status ^-(json s+status.tx-status))
@ -349,9 +347,14 @@
:~ ['nextBatch' (time next-batch)] :~ ['nextBatch' (time next-batch)]
['frequency' (numb (div frequency ~s1))] ['frequency' (numb (div frequency ~s1))]
['refreshTime' (numb (div refresh-time ~s1))] ['refreshTime' (numb (div refresh-time ~s1))]
['contract' s+(crip "0x{((x-co:co 20) contract)}")] ['contract' (hex 20 contract)]
['chainId' (numb chain-id)] ['chainId' (numb chain-id)]
== ==
::
++ hex
|= [p=@ q=@]
^- json
s+(crip "0x{((x-co:co p) q)}")
-- --
:: ::
++ to-hex ++ to-hex
@ -367,11 +370,6 @@
=((lent ~(tap by params)) 4) =((lent ~(tap by params)) 4)
-- --
:: ::
++ l2-hash
|= =keccak
^- json
s+(crip "0x{((x-co:co 20) keccak)}")
::
++ build-l2-tx ++ build-l2-tx
|= [=l2-tx from=[@p proxy:naive] params=(map @t json)] |= [=l2-tx from=[@p proxy:naive] params=(map @t json)]
^- (unit tx:naive) ^- (unit tx:naive)
@ -479,8 +477,8 @@
[~ ~(parse error:json-rpc id)] [~ ~(parse error:json-rpc id)]
=/ tx=(unit tx:naive) (build-l2-tx action u.from params) =/ tx=(unit tx:naive) (build-l2-tx action u.from params)
?~ tx [~ ~(parse error:json-rpc id)] ?~ tx [~ ~(parse error:json-rpc id)]
=/ =keccak (hash-tx:lib (gen-tx-octs:lib u.tx)) =+ (gen-tx-octs:lib u.tx)
:_ [%result id (l2-hash:to-json keccak)] :_ [%result id (hex:to-json p (hash-tx:lib p q))]
%- some %- some
aggregator-action+!>([%submit | u.addr u.sig %don tx]) aggregator-action+!>([%submit | u.addr u.sig %don tx])
:: ::
@ -573,7 +571,6 @@
=/ tx=(unit tx:naive) (build-l2-tx u.l2-tx u.from params) =/ tx=(unit tx:naive) (build-l2-tx u.l2-tx u.from params)
?~ tx ~(parse error:json-rpc id) ?~ tx ~(parse error:json-rpc id)
:+ %result id :+ %result id
%- l2-hash:to-json =- (hex:to-json p (hash-tx:lib p q))
%- hash-tx:lib
(unsigned-tx:lib u.nonce chain-id (gen-tx-octs:lib u.tx)) (unsigned-tx:lib u.nonce chain-id (gen-tx-octs:lib u.tx))
-- --

View File

@ -15,8 +15,11 @@
:: ::
+$ keccak @ux +$ keccak @ux
:: ::
+$ status
?(%unknown %pending %sending %confirmed %failed)
::
+$ tx-status +$ tx-status
$: status=?(%unknown %pending %sending %confirmed %failed) $: =status
pointer=(unit l1-tx-pointer) pointer=(unit l1-tx-pointer)
== ==
:: ::
@ -41,7 +44,7 @@
:: ::
:: TODO: add submission time? :: TODO: add submission time?
:: ::
+$ roller-tx [=ship status=tx-status hash=keccak type=l2-tx] +$ roller-tx [=ship =status hash=keccak type=l2-tx]
:: ::
+$ pend-tx [force=? =address:naive =raw-tx:naive] +$ pend-tx [force=? =address:naive =raw-tx:naive]
:: ::

View File

@ -1,6 +1,6 @@
:: aggregator/send: send rollup tx :: aggregator/send: send rollup tx
:: ::
/- rpc=json-rpc, *aggregator /- rpc=json-rpc, *dice
/+ naive, ethereum, ethio, strandio /+ naive, ethereum, ethio, strandio
:: ::
:: ::