diff --git a/pkg/arvo/app/aggregator.hoon b/pkg/arvo/app/aggregator.hoon index 79d00cd081..d8c44488c1 100644 --- a/pkg/arvo/app/aggregator.hoon +++ b/pkg/arvo/app/aggregator.hoon @@ -16,8 +16,6 @@ :: when retrying, only do so if l2 txs remain in the "frozen" txs group. :: on %tx diff from naive, remove the matching tx from the frozen group. :: -::TODO remaining general work: -:: ::TODO questions: :: - it's a bit weird how we just assume the raw and tx in raw-tx to match... :: @@ -48,7 +46,7 @@ %+ map l1-tx-pointer [next-gas-price=@ud txs=(list raw-tx:naive)] :: - finding=(map keccak $?(%confirmed %failed l1-tx-pointer)) + finding=(map keccak ?(%confirmed %failed l1-tx-pointer)) history=(jug address:ethereum roller-tx) next-nonce=(unit @ud) next-batch=time @@ -138,6 +136,8 @@ :: /x/nonce/[~ship]/[proxy] -> %noun (unit @) :: /x/spawned/[~ship] -> %noun (list [ship address]) :: /x/next-batch -> %atom time + :: /x/point/[~ship] -> %noun point:naive + :: /x/points/[0xadd.ress] -> %noun (list [ship point:naive]) :: ++ on-peek |= =path @@ -152,6 +152,7 @@ [%x %spawned @ ~] (spawned i.t.t.path) [%x %next-batch ~] ``noun+!>(next-batch) [%x %point @ ~] (point i.t.t.path) + [%x %points @ ~] (points i.t.t.path) == :: ++ pending-by @@ -222,8 +223,8 @@ ?~ star=(slaw %p wat) ~ =/ range %+ lot:orm:naive points.pre - :: range exclusive [star first-planet-next-star] - :: TODO: make range inclusive? [first-planet last-planet] + :: range exclusive [star next-star-first-planet-] + :: TODO: make range inclusive ([first-planet last-planet])? :: [`u.star `(cat 3 +(u.star) 0x1)] %+ turn (tap:orm:naive range) @@ -237,6 +238,16 @@ ?~ ship=(rush wat ;~(pfix sig fed:ag)) ``noun+!>(*(unit point:naive)) ``noun+!>((get:orm:naive points.pre u.ship)) + :: + ++ points + |= wat=@t + :+ ~ ~ + :- %noun + !> ^- (list [ship point:naive]) + ?~ addr=(slaw %ux wat) + ~ + %~ tap in + (~(get ju owners.pre) u.addr) -- :: ++ on-arvo diff --git a/pkg/arvo/app/azimuth-rpc.hoon b/pkg/arvo/app/azimuth-rpc.hoon index 3c55d93792..3b7550b759 100644 --- a/pkg/arvo/app/azimuth-rpc.hoon +++ b/pkg/arvo/app/azimuth-rpc.hoon @@ -127,6 +127,7 @@ [~ ~(parse error:json-rpc id)] ?+ method [~ ~(method error:json-rpc id)] %get-point [~ (get-point id +.params point:scry)] + %get-points [~ (get-points id +.params points:scry)] %transfer-point (transfer-point id +.params) %cancel-tx (cancel-tx id +.params) %get-spawned [~ (get-spawned id +.params spawned:scry)] @@ -158,6 +159,13 @@ (~(scry agentio bowl) %aggregator /point/(scot %p ship)/noun) == :: + ++ points + |= =address:naive + .^ (list [ship point:naive]) + %gx + (~(scry agentio bowl) %aggregator /points/(scot %ux address)/noun) + == + :: ++ spawned |= =ship .^ (list [@p @ux]) diff --git a/pkg/arvo/lib/azimuth-rpc.hoon b/pkg/arvo/lib/azimuth-rpc.hoon index 894eeccb2a..9da10e4933 100644 --- a/pkg/arvo/lib/azimuth-rpc.hoon +++ b/pkg/arvo/lib/azimuth-rpc.hoon @@ -259,6 +259,17 @@ ['escape' (ship u.escape.net)]~ == == :: + ++ points + |= points=(list [@p point:naive]) + ^- json + :- %a + %+ turn points + |= [ship=@p =point:naive] + %- pairs + :~ ['ship' (^ship ship)] + ['point' (^point point)] + == + :: ++ ownership |= [=address:naive =nonce:naive] ^- json @@ -369,6 +380,16 @@ ~(not-found error:json-rpc id) [%result id (point:to-json u.point)] :: +++ 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) + ~(parse error:json-rpc id) + [%result id (points:to-json (scry u.address))] +:: ++ transfer-point |= [id=@t params=(map @t json)] ^- [(unit cage) response:rpc] diff --git a/pkg/arvo/lib/naive.hoon b/pkg/arvo/lib/naive.hoon index 29a9fc200d..ee1ff197d9 100644 --- a/pkg/arvo/lib/naive.hoon +++ b/pkg/arvo/lib/naive.hoon @@ -176,10 +176,12 @@ +$ state $: =points =operators + =owners dns=(list @t) == +$ points (tree [ship point]) +$ operators (jug address address) ++$ owners (jug address [ship point]) +$ effects (list diff) +$ proxy ?(%own %spawn %manage %vote %transfer) +$ roll (list raw-tx) @@ -466,6 +468,35 @@ == == == +:: +++ is-ownership-log + |= log=@ux + ^- ? + =, log-names + ?| =(log owner-changed) + =(log changed-transfer-proxy) + =(log changed-management-proxy) + =(log changed-voting-proxy) + =(log changed-spawn-proxy) + == +:: +++ address-from-log + |= [log=@ux point] + ^- (unit address) + =, log-names + ?: =(log owner-changed) + `address.owner.own + ?: =(log changed-transfer-proxy) + `address.transfer-proxy.own + ?: =(log changed-management-proxy) + `address.management-proxy.own + ?: =(log changed-voting-proxy) + `address.voting-proxy.own + ?. =(log changed-spawn-proxy) + :: TODO: better way to handle this? + :: + ~>(%slog.[0 %unknown-log] ~) + `address.spawn-proxy.own -- => |% :: Receive log from L1 transaction @@ -508,8 +539,19 @@ =/ the-point (get-point state ship) ?> ?=(^ the-point) =* point u.the-point - =- [effects state(points (put:orm points.state ship new-point))] - ^- [=effects new-point=^point] + =; [=effects new-point=^point] + =? owners.state (is-ownership-log log-name) + ?> ?=([@ ~] t.t.topics.log) + =* to i.t.t.topics.log + ?~ address=(address-from-log log-name new-point) + owners.state + ?: =(deposit-address to) + (~(put ju owners.state) u.address [ship new-point]) + :: remove point from previous owner and add it to new one + :: + %. [to ship new-point] + ~(put ju (~(del ju owners.state) u.address [ship point])) + [effects state(points (put:orm points.state ship new-point))] :: ?: =(log-name changed-spawn-proxy:log-names) ?> ?=(%l1 -.point) @@ -696,7 +738,9 @@ =/ res=(unit [=effects new-point=^point]) (fun u.point rest) ?~ res ~ - `[effects.u.res state(points (put:orm points.state ship new-point.u.res))] + :- ~ + :- effects.u.res + state(points (put:orm points.state ship new-point.u.res)) :: ++ process-transfer-point |= [=point to=address reset=?] @@ -705,6 +749,7 @@ :: ?. |(=(%own proxy.from.tx) =(%transfer proxy.from.tx)) (debug %bad-permission ~) + =/ previous-owner address.owner.own.point :: Execute transfer :: =/ effects-1 @@ -712,10 +757,17 @@ =: address.owner.own.point to address.transfer-proxy.own.point *address == + =; [=effects new-point=^point] + =. owners.state + :: remove point from previous owner and add it to new one + :: + %. [to ship new-point] + ~(put ju (~(del ju owners.state) previous-owner [ship point])) + `[effects point] :: Execute reset if requested :: ?. reset - `[effects-1 point] + [effects-1 point] :: =^ effects-2 net.point ?: =([0 0 0] +.keys.net.point) @@ -739,7 +791,7 @@ address.voting-proxy.own.point *address address.transfer-proxy.own.point *address == - `[:(welp effects-1 effects-2 effects-3 effects-4) point] + [:(welp effects-1 effects-2 effects-3 effects-4) point] :: ++ process-spawn |= [=ship to=address] @@ -766,7 +818,7 @@ ?. =(+((ship-rank parent)) (ship-rank ship)) (debug %bad-rank ~) :: TODO check spawnlimit :: - =/ [=effects new-point=point] + =^ [=effects new-point=point] owners.state =/ point=(unit point) (get-point state ship) ?> ?=(^ point) :: only parsed 4 bytes :: If spawning to self, just do it @@ -778,19 +830,30 @@ =(to address.spawn-proxy.own.u.parent-point) == == + =+ new-point=u.point(address.owner.own to) :: TODO: use get-point or duplicate sponsor logic :: - :- ~[[%point ship %dominion %l2] [%point ship %owner to]] - u.point(address.owner.own to) + :_ (~(put ju owners.state) to [ship new-point]) + :_ new-point + ~[[%point ship %dominion %l2] [%point ship %owner to]] :: Else spawn to parent and set transfer proxy :: - :- :~ [%point ship %dominion %l2] - [%point ship %owner address.owner.own.u.parent-point] - [%point ship %transfer-proxy to] + =* parent-address address.owner.own.u.parent-point + =/ new-point + %= u.point + address.owner.own parent-address + address.transfer-proxy.own to + == + :: TODO: use put instead so gas is not in /lib/std? + :: + :_ %- ~(gas ju owners.state) + :~ [to [ship new-point]] + [parent-address [ship new-point]] == - %= u.point - address.owner.own address.owner.own.u.parent-point - address.transfer-proxy.own to + :_ new-point + :~ [%point ship %dominion %l2] + [%point ship %owner parent-address] + [%point ship %transfer-proxy to] == `[effects state(points (put:orm points.state ship new-point))] :: @@ -872,24 +935,42 @@ |= [=point =address] ?. |(=(%own proxy.from.tx) =(%manage proxy.from.tx)) (debug %bad-permission ~) - :: - :+ ~ [%point ship.from.tx %management-proxy address]~ + =* ship ship.from.tx + =/ previous address.management-proxy.own.point + =; [=effects new-point=^point] + =. owners.state + %. [address ship new-point] + ~(put ju (~(del ju owners.state) previous [ship point])) + `[effects new-point] + :- [%point ship.from.tx %management-proxy address]~ point(address.management-proxy.own address) :: ++ process-set-spawn-proxy |= [=point =address] ?. |(=(%own proxy.from.tx) =(%spawn proxy.from.tx)) (debug %bad-permission ~) - :: - :+ ~ [%point ship.from.tx %spawn-proxy address]~ + =* ship ship.from.tx + =/ previous address.spawn-proxy.own.point + =; [=effects new-point=^point] + =. owners.state + %. [address ship new-point] + ~(put ju (~(del ju owners.state) previous [ship point])) + `[effects new-point] + :- [%point ship.from.tx %spawn-proxy address]~ point(address.spawn-proxy.own address) :: ++ process-set-transfer-proxy |= [=point =address] ?. |(=(%own proxy.from.tx) =(%transfer proxy.from.tx)) (debug %bad-permission ~) - :: - :+ ~ [%point ship.from.tx %transfer-proxy address]~ + =* ship ship.from.tx + =/ previous address.transfer-proxy.own.point + =; [=effects new-point=^point] + =. owners.state + %. [address ship new-point] + ~(put ju (~(del ju owners.state) previous [ship point])) + `[effects new-point] + :- [%point ship.from.tx %transfer-proxy address]~ point(address.transfer-proxy.own address) -- --