mirror of
https://github.com/ilyakooo0/urbit.git
synced 2025-01-02 20:15:27 +03:00
aggregator: refactor ownership index logic
This commit is contained in:
parent
5c787f2a0b
commit
722ce969a5
@ -1,6 +1,6 @@
|
||||
:: Aggregator JSON-RPC API
|
||||
::
|
||||
/- rpc=json-rpc, *aggregator
|
||||
/- rpc=json-rpc, *dice
|
||||
/+ naive,
|
||||
azimuth-rpc,
|
||||
json-rpc,
|
||||
|
@ -19,9 +19,10 @@
|
||||
::TODO questions:
|
||||
:: - it's a bit weird how we just assume the raw and tx in raw-tx to match...
|
||||
::
|
||||
/- *aggregator
|
||||
/- *dice
|
||||
/+ azimuth,
|
||||
naive,
|
||||
dice,
|
||||
lib=naive-transactions,
|
||||
default-agent,
|
||||
ethereum,
|
||||
@ -35,6 +36,7 @@
|
||||
:: sending: the l2 txs currently sending/awaiting l2 confirmation
|
||||
:: finding: raw-tx-hash reverse lookup for sending map
|
||||
:: history: status of l2 txs by ethereum address
|
||||
:: transfers: index that keeps track of transfer-proxy changes
|
||||
:: next-nonce: next l1 nonce to use
|
||||
:: next-batch: when then next l2 batch will be sent
|
||||
:: pre: predicted l2 state
|
||||
@ -72,7 +74,6 @@
|
||||
==
|
||||
::
|
||||
+$ init [nas=^state:naive own=owners]
|
||||
+$ owners (jug address:naive [ship point:naive])
|
||||
+$ config
|
||||
$% [%frequency frequency=@dr]
|
||||
[%setkey pk=@]
|
||||
@ -151,6 +152,7 @@
|
||||
:: /x/pending/[~ship] -> %noun (list pend-tx)
|
||||
:: /x/pending/[0xadd.ress] -> %noun (list pend-tx)
|
||||
:: /x/tx/[0xke.ccak]/status -> %noun tx-status
|
||||
:: /x/history/[0xadd.ress] -> %noun (list roller-tx)
|
||||
:: /x/nonce/[~ship]/[proxy] -> %noun (unit @)
|
||||
:: /x/spawned/[~ship] -> %noun (list [ship address])
|
||||
:: /x/next-batch -> %atom time
|
||||
@ -263,7 +265,7 @@
|
||||
|= wat=@t
|
||||
:+ ~ ~
|
||||
:- %noun
|
||||
!> ^- (list [ship point:naive])
|
||||
!> ^- (list ship)
|
||||
?~ addr=(slaw %ux wat)
|
||||
~
|
||||
%~ tap in
|
||||
@ -568,6 +570,7 @@
|
||||
%. [address.tx roller-tx(status [%failed ~])]
|
||||
~(put ju (~(del ju history.state) address.tx roller-tx))
|
||||
$(txs t.txs, local (~(put in local) hash))
|
||||
:: TODO: replace with (refactored) /lib/dice
|
||||
::
|
||||
++ try-apply
|
||||
|= [nas=^state:naive force=? =raw-tx:naive]
|
||||
@ -587,53 +590,11 @@
|
||||
[force state(pre ?:(force nas cache-nas))]
|
||||
=* predicted +.u.nex
|
||||
=* diffs -.u.nex
|
||||
|^
|
||||
:- &
|
||||
%_ state
|
||||
pre predicted
|
||||
own update-ownership
|
||||
own (update-ownership:dice diffs cache-nas predicted own.state)
|
||||
==
|
||||
::
|
||||
:: +update-ownership
|
||||
::
|
||||
:: updates ownership of azimuth points based on diffs received
|
||||
:: from /app/azimuth and a previous naive state
|
||||
::
|
||||
:: TODO: move to /lib
|
||||
::
|
||||
++ update-ownership
|
||||
%+ roll diffs
|
||||
|= [=diff:naive owners=_own.state]
|
||||
^+ owners
|
||||
=, orm:naive
|
||||
?. ?=([%point *] diff) owners
|
||||
=/ old=(unit point:naive) (get points.cache-nas ship.diff)
|
||||
=/ new=point:naive (need (get points.predicted ship.diff))
|
||||
=* event +>.diff
|
||||
=; [to=@ux from=@ux]
|
||||
=? owners !=(from 0x0)
|
||||
?> ?=(^ old)
|
||||
(~(del ju owners) from [ship.diff u.old])
|
||||
?: =(to 0x0) owners
|
||||
(~(put ju owners) to [ship.diff new])
|
||||
?+ -.event [0x0 0x0]
|
||||
%owner
|
||||
[+.event ?~(old 0x0 address.owner.own.u.old)]
|
||||
::
|
||||
%spawn-proxy
|
||||
[+.event ?~(old 0x0 address.spawn-proxy.own.u.old)]
|
||||
::
|
||||
%management-proxy
|
||||
[+.event ?~(old 0x0 address.management-proxy.own.u.old)]
|
||||
::
|
||||
:: FIXME: remove (galaxies are not on l2)
|
||||
:: %voting-proxy
|
||||
:: [+.event ?~(old 0x0 address.voting-proxy.own.u.old)]
|
||||
::
|
||||
%transfer-proxy
|
||||
[+.event ?~(old 0x0 address.transfer-proxy.own.u.old)]
|
||||
==
|
||||
--
|
||||
--
|
||||
::
|
||||
++ get-l1-address
|
||||
@ -711,6 +672,8 @@
|
||||
?~ addr=(verify-sig:lib sig message)
|
||||
~? lverb [dap.bowl %cancel-sig-fail]
|
||||
[~ state]
|
||||
:: TODO: mark as failed instead? add a %cancelled to tx-status?
|
||||
::
|
||||
=. history
|
||||
%+ ~(del ju history) u.addr
|
||||
[ship [%pending ~] keccak l2-tx]
|
||||
|
@ -1,5 +1,11 @@
|
||||
/- eth-watcher
|
||||
/+ ethereum, azimuth, naive, default-agent, verb, dbug
|
||||
/- eth-watcher, *dice
|
||||
/+ ethereum,
|
||||
azimuth,
|
||||
naive,
|
||||
dice,
|
||||
default-agent,
|
||||
verb,
|
||||
dbug
|
||||
/* snap %eth-logs /app/azimuth/logs/eth-logs
|
||||
::
|
||||
=/ last-snap :: maybe just use the last one?
|
||||
@ -30,7 +36,6 @@
|
||||
+$ tagged-diff [=id:block diff:naive]
|
||||
::
|
||||
+$ network ?(%mainnet %ropsten %local)
|
||||
+$ owners (jug address:naive [ship point:naive])
|
||||
--
|
||||
::
|
||||
|%
|
||||
@ -69,35 +74,6 @@
|
||||
?~ data *@ux
|
||||
?: =(data '0x') *@ux
|
||||
(hex-to-num:ethereum data)
|
||||
:: TODO: move to /lib
|
||||
::
|
||||
++ update-ownership
|
||||
|= [=diff:naive own=owners old=(unit point:naive) new=point:naive]
|
||||
^+ own
|
||||
?. ?=([%point *] diff) own
|
||||
=* event +>.diff
|
||||
=; [to=@ux from=@ux]
|
||||
=? own !=(from 0x0)
|
||||
?> ?=(^ old)
|
||||
(~(del ju own) from [ship.diff u.old])
|
||||
?: =(to 0x0) own
|
||||
(~(put ju own) to [ship.diff new])
|
||||
?+ -.event [0x0 0x0]
|
||||
%owner
|
||||
[+.event ?~(old 0x0 address.owner.own.u.old)]
|
||||
::
|
||||
%spawn-proxy
|
||||
[+.event ?~(old 0x0 address.spawn-proxy.own.u.old)]
|
||||
::
|
||||
%management-proxy
|
||||
[+.event ?~(old 0x0 address.management-proxy.own.u.old)]
|
||||
::
|
||||
%voting-proxy
|
||||
[+.event ?~(old 0x0 address.voting-proxy.own.u.old)]
|
||||
::
|
||||
%transfer-proxy
|
||||
[+.event ?~(old 0x0 address.transfer-proxy.own.u.old)]
|
||||
==
|
||||
::
|
||||
++ run-logs
|
||||
|= [state=app-state logs=(list event-log:rpc:ethereum)]
|
||||
@ -125,14 +101,11 @@
|
||||
%| ((slog 'naive-fail' p.res) `nas.state)
|
||||
==
|
||||
=. own.state
|
||||
%+ roll raw-effects
|
||||
|= [=diff:naive own=_own.state]
|
||||
^+ own
|
||||
=, orm:naive
|
||||
?. ?=([%point *] diff) own
|
||||
=/ old=(unit point:naive) (get points.nas.state ship.diff)
|
||||
=/ new=point:naive (need (get points.new-nas ship.diff))
|
||||
(update-ownership diff own old new)
|
||||
=, dice
|
||||
?. =(contract address.i.logs)
|
||||
=< own
|
||||
(apply-effects raw-effects nas.state own.state chain-id)
|
||||
(update-ownership raw-effects nas.state new-nas own.state)
|
||||
=. nas.state new-nas
|
||||
=/ effects-1
|
||||
=/ =id:block [block-hash block-number]:u.mined.i.logs
|
||||
|
@ -1,6 +1,6 @@
|
||||
:: azimuth-rpc: command parsing and utilities
|
||||
::
|
||||
/- rpc=json-rpc, *aggregator
|
||||
/- rpc=json-rpc, *dice
|
||||
/+ naive, json-rpc, lib=naive-transactions
|
||||
::
|
||||
=> :: Utilities
|
||||
@ -20,19 +20,6 @@
|
||||
%set-transfer-proxy
|
||||
==
|
||||
::
|
||||
++ pk
|
||||
^- @
|
||||
=; key=@t
|
||||
q:(need (de:base16:mimes:html key))
|
||||
:: 'a44de2416ee6beb2f323fab48b432925c9785808d33a6ca6d7ba00b45e9370c3'
|
||||
'2480c5256d843c73cba67cc966a11a647c943a41db2fa138de4e4f16d0861a6b'
|
||||
::
|
||||
++ fake-raw
|
||||
|= [nonce=@ud =tx:naive]
|
||||
:: ~& nonce+nonce
|
||||
^- octs
|
||||
(gen-tx:lib nonce tx pk)
|
||||
::
|
||||
++ parse-ship
|
||||
|= jon=json
|
||||
^- (unit @p)
|
||||
@ -259,7 +246,6 @@
|
||||
|= roller-tx
|
||||
^- json
|
||||
%- pairs
|
||||
:: [status=tx-status hash=keccak type=l2-tx]
|
||||
:~ ['status' s+status.status]
|
||||
['hash' s+(crip "0x{((x-co:co 20) hash)}")]
|
||||
['type' s+type]
|
||||
@ -431,7 +417,6 @@
|
||||
++ get-points
|
||||
|= [id=@t params=(map @t json) scry=$-(@ux (list [@p point:naive]))]
|
||||
^- response:rpc
|
||||
~& ~(wyt by params)
|
||||
?. =(~(wyt by params) 1)
|
||||
~(params error:json-rpc id)
|
||||
?~ address=(address:from-json params)
|
||||
@ -475,6 +460,7 @@
|
||||
:_ [%result id (l2-hash:to-json keccak)]
|
||||
%- some
|
||||
aggregator-action+!>([%submit | u.addr u.sig %don tx])
|
||||
::
|
||||
++ get-spawned
|
||||
|= [id=@t params=(map @t json) scry=$-(ship (list [ship @ux]))]
|
||||
^- response:rpc
|
||||
|
65
pkg/arvo/lib/dice.hoon
Normal file
65
pkg/arvo/lib/dice.hoon
Normal file
@ -0,0 +1,65 @@
|
||||
:: dice: helper functions for L2 Rollers
|
||||
::
|
||||
/- *dice
|
||||
/+ naive, *naive-transactions
|
||||
::
|
||||
|%
|
||||
++ apply-effects
|
||||
|= [=effects:naive nas=^state:naive own=owners chain-t=@]
|
||||
^+ [nas=nas own=own]
|
||||
%+ roll effects
|
||||
|= [=diff:naive nas=_nas own=_own]
|
||||
^+ [nas own]
|
||||
?. ?=([%tx *] diff) [nas own]
|
||||
=+ cache-nas=nas
|
||||
=* raw-tx raw-tx.diff
|
||||
=/ chain-t=@t (ud-to-ascii:naive chain-t)
|
||||
?. (verify-sig-and-nonce:naive verifier chain-t nas raw-tx)
|
||||
[nas own]
|
||||
=^ * points.nas
|
||||
(increment-nonce:naive nas from.tx.raw-tx)
|
||||
?~ nex=(receive-tx:naive nas tx.raw-tx)
|
||||
[cache-nas own]
|
||||
=* up-nas +.u.nex
|
||||
=* diffs -.u.nex
|
||||
:- up-nas
|
||||
(update-ownership diffs cache-nas up-nas own)
|
||||
::
|
||||
++ update-ownership
|
||||
|= $: =effects:naive
|
||||
cache-nas=^state:naive
|
||||
up-nas=^state:naive
|
||||
=owners
|
||||
==
|
||||
^+ owners
|
||||
%+ roll effects
|
||||
|= [=diff:naive owners=_owners]
|
||||
=, orm:naive
|
||||
?. ?=([%point *] diff) owners
|
||||
=/ old=(unit point:naive)
|
||||
(get points.cache-nas ship.diff)
|
||||
=/ new=point:naive
|
||||
(need (get points.up-nas ship.diff))
|
||||
=* event +>.diff
|
||||
=; [to=@ux from=@ux]
|
||||
=? owners !=(from 0x0)
|
||||
(~(del ju owners) from ship.diff)
|
||||
?: =(to 0x0) owners
|
||||
(~(put ju owners) to ship.diff)
|
||||
?+ -.event [0x0 0x0]
|
||||
%owner
|
||||
[+.event ?~(old 0x0 address.owner.own.u.old)]
|
||||
::
|
||||
%spawn-proxy
|
||||
[+.event ?~(old 0x0 address.spawn-proxy.own.u.old)]
|
||||
::
|
||||
%management-proxy
|
||||
[+.event ?~(old 0x0 address.management-proxy.own.u.old)]
|
||||
::
|
||||
%voting-proxy
|
||||
[+.event ?~(old 0x0 address.voting-proxy.own.u.old)]
|
||||
::
|
||||
%transfer-proxy
|
||||
[+.event ?~(old 0x0 address.transfer-proxy.own.u.old)]
|
||||
==
|
||||
--
|
@ -1,6 +1,10 @@
|
||||
:: dice: structures for L2 Rollers
|
||||
::
|
||||
/+ naive, ethereum
|
||||
::
|
||||
|%
|
||||
+$ owners (jug address:naive ship)
|
||||
::
|
||||
+$ roller-config
|
||||
$: next-batch=time
|
||||
frequency=@dr
|
||||
@ -57,4 +61,4 @@
|
||||
next-gas-price=@ud
|
||||
txs=(list raw-tx:naive)
|
||||
==
|
||||
--
|
||||
--
|
Loading…
Reference in New Issue
Block a user