mirror of
https://github.com/urbit/shrub.git
synced 2024-12-22 02:11:38 +03:00
naive: use cached naive state in aggregator
This commit is contained in:
parent
fbd96f69ee
commit
9f3202eded
@ -18,7 +18,6 @@
|
|||||||
::
|
::
|
||||||
::TODO remaining general work:
|
::TODO remaining general work:
|
||||||
:: - hook up timer callbacks
|
:: - hook up timer callbacks
|
||||||
:: - cache state, upate after every azimuth %fact
|
|
||||||
:: - properly support private key changes
|
:: - properly support private key changes
|
||||||
::
|
::
|
||||||
::TODO questions:
|
::TODO questions:
|
||||||
@ -27,7 +26,6 @@
|
|||||||
/- *aggregator
|
/- *aggregator
|
||||||
/+ azimuth, naive, default-agent, ethereum, dbug, verb, lib=naive-transactions
|
/+ azimuth, naive, default-agent, ethereum, dbug, verb, lib=naive-transactions
|
||||||
::
|
::
|
||||||
::TODO /sur file for public types
|
|
||||||
|%
|
|%
|
||||||
+$ state-0
|
+$ state-0
|
||||||
$: %0
|
$: %0
|
||||||
@ -36,11 +34,13 @@
|
|||||||
::TODO should maybe key by [address nonce] instead. same for wires
|
::TODO should maybe key by [address nonce] instead. same for wires
|
||||||
:: finding: raw-tx-hash reverse lookup for sending map
|
:: finding: raw-tx-hash reverse lookup for sending map
|
||||||
:: next-nonce: next l1 nonce to use
|
:: next-nonce: next l1 nonce to use
|
||||||
|
:: nas: cached naive state
|
||||||
::
|
::
|
||||||
pending=(list pend-tx)
|
pending=(list pend-tx)
|
||||||
sending=(map nonce:naive [next-gas-price=@ud txs=(list raw-tx:naive)])
|
sending=(map nonce:naive [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))
|
||||||
next-nonce=@ud
|
next-nonce=@ud
|
||||||
|
nas=^state:naive
|
||||||
::
|
::
|
||||||
:: pk: private key to send the roll
|
:: pk: private key to send the roll
|
||||||
:: frequency: time to wait between sending batches (TODO fancier)
|
:: frequency: time to wait between sending batches (TODO fancier)
|
||||||
@ -171,7 +171,8 @@
|
|||||||
=+ proxy=i.t.t.t.path
|
=+ proxy=i.t.t.t.path
|
||||||
?. ?=(proxy:naive proxy)
|
?. ?=(proxy:naive proxy)
|
||||||
[~ ~]
|
[~ ~]
|
||||||
=/ [* nas=^state:naive] pending-state:do
|
:: uses cached naive state
|
||||||
|
::
|
||||||
::TODO or should we ~ when !(~(has by points.nas) who) ?
|
::TODO or should we ~ when !(~(has by points.nas) who) ?
|
||||||
=/ =point:naive (~(gut by points.nas) u.who *point:naive)
|
=/ =point:naive (~(gut by points.nas) u.who *point:naive)
|
||||||
=+ (proxy-from-point:naive proxy point)
|
=+ (proxy-from-point:naive proxy point)
|
||||||
@ -258,6 +259,14 @@
|
|||||||
=^ cards state
|
=^ cards state
|
||||||
(on-naive-diff:do diff)
|
(on-naive-diff:do diff)
|
||||||
[cards this]
|
[cards this]
|
||||||
|
::
|
||||||
|
%naive-state
|
||||||
|
:: cache naive state, received upon innitializing subscription
|
||||||
|
::
|
||||||
|
~& > %get-naive-state
|
||||||
|
:: TODO: this assumes that %azimuth has already processed eth data
|
||||||
|
::
|
||||||
|
[~ this(nas !<(^state:naive q.cage.sign))]
|
||||||
==
|
==
|
||||||
==
|
==
|
||||||
::
|
::
|
||||||
@ -360,6 +369,8 @@
|
|||||||
++ pending-state
|
++ pending-state
|
||||||
^- [_pending ^state:naive]
|
^- [_pending ^state:naive]
|
||||||
:: load current, canonical state
|
:: load current, canonical state
|
||||||
|
:: TODO: safe to use the cached naive state instead?
|
||||||
|
:: problems if we eargerly update it with the submitted tx?
|
||||||
::
|
::
|
||||||
=+ .^ nas=^state:naive
|
=+ .^ nas=^state:naive
|
||||||
%gx
|
%gx
|
||||||
@ -386,31 +397,26 @@
|
|||||||
++ try-apply
|
++ try-apply
|
||||||
|= [nas=^state:naive force=? =raw-tx:naive]
|
|= [nas=^state:naive force=? =raw-tx:naive]
|
||||||
^- [success=? _nas]
|
^- [success=? _nas]
|
||||||
=/ chain-id=@t (scot %ud chain-id)
|
=/ chain-t=@t (ud-to-ascii:naive chain-id)
|
||||||
?. (verify-sig-and-nonce:naive verifier:lib chain-id nas raw-tx)
|
?. (verify-sig-and-nonce:naive verifier:lib chain-t nas raw-tx)
|
||||||
|
~& [%verify-sig-and-nonce %failed]
|
||||||
[force nas]
|
[force nas]
|
||||||
::
|
::
|
||||||
=^ out points.nas (increment-nonce:naive nas from.tx.raw-tx)
|
=^ * points.nas
|
||||||
|
(increment-nonce:naive nas from.tx.raw-tx)
|
||||||
::
|
::
|
||||||
?~ nex=(receive-tx:naive nas tx.raw-tx)
|
?~ nex=(receive-tx:naive nas tx.raw-tx)
|
||||||
[force nas]
|
[force nas]
|
||||||
[& +.u.nex]
|
[& +.u.nex]
|
||||||
::
|
::
|
||||||
++ get-address
|
++ get-l1-pointer
|
||||||
|= [=tx:naive nas=^state:naive]
|
|= [=tx:naive nas=^state:naive]
|
||||||
^- [address:ethereum nonce:naive]
|
^- l1-tx-pointer
|
||||||
?~ point=(~(get by points.nas) ship.from.tx)
|
?~ point=(~(get by points.nas) ship.from.tx)
|
||||||
!!
|
!!
|
||||||
:_ next-nonce
|
:_ next-nonce
|
||||||
=, own.u.point
|
|
||||||
=< address
|
=< address
|
||||||
?- proxy.from.tx
|
(proxy-from-point:naive proxy.from.tx u.point)
|
||||||
%own owner
|
|
||||||
%spawn spawn-proxy
|
|
||||||
%manage management-proxy
|
|
||||||
%vote voting-proxy
|
|
||||||
%transfer transfer-proxy
|
|
||||||
==
|
|
||||||
::
|
::
|
||||||
++ on-action
|
++ on-action
|
||||||
|= =action
|
|= =action
|
||||||
@ -439,10 +445,9 @@
|
|||||||
::
|
::
|
||||||
%setkey
|
%setkey
|
||||||
::TODO what about existing sending entries?
|
::TODO what about existing sending entries?
|
||||||
:- get-nonce
|
|
||||||
?~ pk=(de:base16:mimes:html pk.action)
|
?~ pk=(de:base16:mimes:html pk.action)
|
||||||
state
|
`state
|
||||||
state(pk q.u.pk)
|
[(get-nonce q.u.pk) state(pk q.u.pk)]
|
||||||
::
|
::
|
||||||
%submit
|
%submit
|
||||||
=^ success state
|
=^ success state
|
||||||
@ -451,8 +456,8 @@
|
|||||||
force.action
|
force.action
|
||||||
sig.action
|
sig.action
|
||||||
(part-tx-to-full tx.action)
|
(part-tx-to-full tx.action)
|
||||||
:: TODO: consider failure case
|
~? =(success |)
|
||||||
?> success
|
[dap.bowl %submit-failed action]
|
||||||
[~ state]
|
[~ state]
|
||||||
::
|
::
|
||||||
%cancel
|
%cancel
|
||||||
@ -465,17 +470,9 @@
|
|||||||
|= [force=? =raw-tx:naive]
|
|= [force=? =raw-tx:naive]
|
||||||
^- [success=? _state]
|
^- [success=? _state]
|
||||||
=/ [nep=_pending nas=^state:naive] pending-state
|
=/ [nep=_pending nas=^state:naive] pending-state
|
||||||
=^ success nas
|
=^ success nas (try-apply nas force raw-tx)
|
||||||
(try-apply nas force raw-tx)
|
|
||||||
::TODO want to notify about dropped pendings, or no? client prolly polls...
|
::TODO want to notify about dropped pendings, or no? client prolly polls...
|
||||||
=? pending success (snoc nep [force raw-tx])
|
=? pending success (snoc nep [force raw-tx])
|
||||||
=. finding
|
|
||||||
%+ ~(put by finding)
|
|
||||||
(hash-raw-tx raw-tx)
|
|
||||||
?: =(success %.n)
|
|
||||||
%failed
|
|
||||||
(get-address tx.raw-tx nas)
|
|
||||||
::TODO cache nas?
|
|
||||||
[success state]
|
[success state]
|
||||||
:: +set-timer: %wait until next whole :frequency
|
:: +set-timer: %wait until next whole :frequency
|
||||||
::
|
::
|
||||||
@ -496,12 +493,19 @@
|
|||||||
sending
|
sending
|
||||||
%+ ~(put by sending) nonce
|
%+ ~(put by sending) nonce
|
||||||
[0 (turn pending tail)]
|
[0 (turn pending tail)]
|
||||||
|
::
|
||||||
|
finding
|
||||||
|
%- ~(gas by finding)
|
||||||
|
%+ turn pending
|
||||||
|
|= [* =raw-tx:naive]
|
||||||
|
[(hash-raw-tx raw-tx) (get-l1-pointer tx.raw-tx nas)]
|
||||||
==
|
==
|
||||||
[(send-roll nonce) state]
|
[(send-roll nonce) state]
|
||||||
[[set-timer cards] state]
|
[[set-timer cards] state]
|
||||||
:: +get-nonce: retrieves the latest nonce
|
:: +get-nonce: retrieves the latest nonce
|
||||||
::
|
::
|
||||||
++ get-nonce
|
++ get-nonce
|
||||||
|
|= pk=@
|
||||||
^- (list card)
|
^- (list card)
|
||||||
(start-thread:spider /nonce [%aggregator-nonce !>([endpoint pk])])
|
(start-thread:spider /nonce [%aggregator-nonce !>([endpoint pk])])
|
||||||
::
|
::
|
||||||
@ -586,6 +590,10 @@
|
|||||||
:: unexpected tx failures here. would that be useful? probably not?
|
:: unexpected tx failures here. would that be useful? probably not?
|
||||||
:: ~? !forced [dap.bowl %aggregated-tx-failed-anyway err.diff]
|
:: ~? !forced [dap.bowl %aggregated-tx-failed-anyway err.diff]
|
||||||
%failed
|
%failed
|
||||||
|
:: update cached naive state
|
||||||
|
::
|
||||||
|
=^ * nas
|
||||||
|
(try-apply nas | raw-tx.diff)
|
||||||
[~ state]
|
[~ state]
|
||||||
::
|
::
|
||||||
--
|
--
|
||||||
|
Loading…
Reference in New Issue
Block a user