naive: wip aggregator compiles

got it to compile and tested poke and scry from /app/azimuth-rpc.hoon
This commit is contained in:
yosoyubik 2021-05-17 17:48:49 +02:00
parent 154baceb8b
commit 7c57a35ccc

View File

@ -26,7 +26,7 @@
::TODO questions: ::TODO questions:
:: - it's a bit weird how we just assume the raw and tx in raw-tx to match... :: - it's a bit weird how we just assume the raw and tx in raw-tx to match...
:: ::
/+ naive, ethereum /+ naive, default-agent, ethereum, dbug, verb
/= ttttt /tests/lib/naive ::TODO use new lib /= ttttt /tests/lib/naive ::TODO use new lib
:: ::
::TODO /sur file for public types ::TODO /sur file for public types
@ -40,7 +40,7 @@
:: next-nonce: next l1 nonce to use :: next-nonce: next l1 nonce to use
:: ::
pending=(list pend-tx) pending=(list pend-tx)
sending=(map nonce [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
:: ::
@ -88,14 +88,16 @@
:: ::
::TODO config? ::TODO config?
++ contract 0xb581.01cd.3bbb.cc6f.a40b.cdb0.4bb7.1623.b5c7.d39b ++ contract 0xb581.01cd.3bbb.cc6f.a40b.cdb0.4bb7.1623.b5c7.d39b
++ chain-id 0x1 ++ chain-id '1'
:: ::
++ resend-time ~m5 ++ resend-time ~m5
:: ::
++ lverb & ++ lverb &
-- --
:: ::
=| state=state-0 =| state-0
=* state -
::
%- agent:dbug %- agent:dbug
%+ verb | %+ verb |
^- agent:gall ^- agent:gall
@ -103,6 +105,7 @@
=< =<
|_ =bowl:gall |_ =bowl:gall
+* this . +* this .
do ~(. +> bowl)
def ~(. (default-agent this %|) bowl) def ~(. (default-agent this %|) bowl)
:: ::
++ on-init ++ on-init
@ -120,13 +123,13 @@
++ on-poke ++ on-poke
|= [=mark =vase] |= [=mark =vase]
^- (quip card _this) ^- (quip card _this)
=^ cards state
?+ mark (on-poke:def mark vase) ?+ mark (on-poke:def mark vase)
%noun $(mark %aggregator-action)
::
%aggregator-action %aggregator-action
!! =+ !<(poke=action vase)
::TODO (on-action:do poke)
== ==
[cards this]
:: +on-peek: scry paths :: +on-peek: scry paths
::TODO reevaluate wrt recent flow changes ::TODO reevaluate wrt recent flow changes
:: ::
@ -145,12 +148,20 @@
[%x %pending @ ~] [%x %pending @ ~]
=* wat i.t.t.path =* wat i.t.t.path
?~ who=(slaw %p wat) ?~ who=(slaw %p wat)
:: by-address
::
?~ wer=(slaw %ux wat) ?~ wer=(slaw %ux wat)
[~ ~] [~ ~]
=; pending=(list pend-tx)
``noun+!>(pending)
%+ skim pending %+ skim pending
|= pend-tx |= pend-tx
::TODO deduce address from sig.raw-tx ? ::TODO deduce address from sig.raw-tx ?
!! !!
:: by-ship
::
=; pending=(list pend-tx)
``noun+!>(pending)
%+ skim pending %+ skim pending
|= pend-tx |= pend-tx
=(u.who ship.from.tx.raw-tx) =(u.who ship.from.tx.raw-tx)
@ -163,12 +174,12 @@
!> ^- tx-status !> ^- tx-status
?^ status=(~(get by finding) u.keccak) ?^ status=(~(get by finding) u.keccak)
?@ u.status [u.status ~] ?@ u.status [u.status ~]
[%sending u.status] [%sending status]
::TODO potentially slow! ::TODO potentially slow!
=; known=? =; known=?
[?:(known %pending %unknown) ~] [?:(known %pending %unknown) ~]
%+ lien pending %+ lien pending
|= [* raw-tx] |= [* raw-tx:naive]
=(u.keccak (hash-tx raw)) =(u.keccak (hash-tx raw))
:: ::
[%x %nonce @ @ ~] [%x %nonce @ @ ~]
@ -177,9 +188,9 @@
=+ proxy=i.t.t.t.path =+ proxy=i.t.t.t.path
?. ?=(proxy:naive proxy) ?. ?=(proxy:naive proxy)
[~ ~] [~ ~]
=^ * nas pending-state:do =/ [* nas=^state:naive] pending-state:do
::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) who *point) =/ =point:naive (~(gut by points.nas) u.who *point:naive)
=+ (proxy-from-point:naive proxy point) =+ (proxy-from-point:naive proxy point)
``atom+!>(nonce) ``atom+!>(nonce)
== ==
@ -187,7 +198,7 @@
++ on-arvo ++ on-arvo
|= [=wire =sign-arvo] |= [=wire =sign-arvo]
^- (quip card _this) ^- (quip card _this)
?+ +<.sign (on-arvo:def wire sign) ?+ +<.sign-arvo (on-arvo:def wire sign-arvo)
%wake =^(cards state on-timer:do [cards this]) %wake =^(cards state on-timer:do [cards this])
== ==
:: ::
@ -220,24 +231,38 @@
|= [=wire thread=term arg=vase] |= [=wire thread=term arg=vase]
^- (list card) ^- (list card)
=/ tid=@ta (rap 3 thread '--' (scot %uv eny.bowl) ~) =/ tid=@ta (rap 3 thread '--' (scot %uv eny.bowl) ~)
=/ args [~ `tid thread arg] :~ (poke wire %spider-start !>([~ `tid thread arg]))
:~ [%pass wire %agent [our.bowl %spider] %watch /thread-result/[tid]] (watch wire %spider-start /thread-result/[tid])
[%pass wire %agent [our.bowl %spider] %poke %spider-start !>(args)]
== ==
::
++ poke
|= [=path =cage]
^- card
[%pass path %agent [our.bowl %spider] %poke cage]
::
++ watch
|= [=path =sub=path]
^- card
[%pass path %agent [our.bowl %spider] %watch sub-path]
::
++ leave
|= =path
^- card
[%pass path %agent [our.bowl %spider] %leave ~]
-- --
:: ::
++ hash-tx keccak-256:keccak:crypto ++ hash-tx keccak-256:keccak:crypto
:: ::
++ hash-raw-tx ++ hash-raw-tx
|= raw-tx |= =raw-tx:naive
(hash-tx raw) (hash-tx raw.raw-tx)
:: ::
++ part-tx-to-full ++ part-tx-to-full
|= =part-tx |= =part-tx
^- [octs tx:naive] ^- [octs tx:naive]
?- -.part-tx ?+ -.part-tx !!
%raw [+.part-tx (decode-tx:naive +.part-tx)] :: %raw [+.part-tx (decode-tx:naive +.part-tx)]
%don [(encode-tx:naive +.part-tx) +.part-tx] :: %don [(encode-tx:naive +.part-tx) +.part-tx]
%ful +.part-tx %ful +.part-tx
== ==
:: +pending-state :: +pending-state
@ -248,10 +273,10 @@
::TODO maybe want to cache locally, refresh on %fact from azimuth? ::TODO maybe want to cache locally, refresh on %fact from azimuth?
:: ::
++ pending-state ++ pending-state
^- [_pending state:naive] ^- (quip pend-tx ^state:naive)
:: load current, canonical state :: load current, canonical state
:: ::
=+ .^ nas=state:naive =+ .^ nas=^state:naive
%gx %gx
(scot %p our.bowl) (scot %p our.bowl)
%azimuth %azimuth
@ -262,7 +287,7 @@
::TODO should also apply txs from sending map! ::TODO should also apply txs from sending map!
:: ::
=| valid=_pending =| valid=_pending
|- ^+ nas |- ^+ [valid nas]
?~ pending [(flop valid) nas] ?~ pending [(flop valid) nas]
:: ::
=^ gud=? nas (try-apply nas i.pending) =^ gud=? nas (try-apply nas i.pending)
@ -271,12 +296,12 @@
:: +try-apply: :: +try-apply:
:: ::
++ try-apply ++ try-apply
|= [nas=state:naive force=? =raw-tx:naive] |= [nas=^state:naive force=? =raw-tx:naive]
^- [success=? _nas] ^- [success=? _nas]
?. (verify-sig-and-nonce:naive verifier:ttttt nas raw-tx) ?. (verify-sig-and-nonce:naive verifier:ttttt chain-id nas raw-tx)
[force nas] [force nas]
:: ::
=^ * nas (increment-nonce:naive nas from.tx.raw-tx) =^ out 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]
@ -284,15 +309,20 @@
:: ::
++ on-action ++ on-action
|= =action |= =action
^- (quip card _state)
?- -.action ?- -.action
%commit send-roll %commit !! :: TODO send-roll
%config [~ state(frequency frequency.action)] %config [~ state(frequency frequency.action)]
%setkey [~ state(pk pk.action)] ::TODO what about existing sending entries? %setkey [~ state(pk pk.action)] ::TODO what about existing sending entries?
:: ::
%submit %submit
=^ success state =^ success state
%+ take-tx force.action ^- [? _state]
%^ take-tx
force.action
sig.action
(part-tx-to-full tx.action) (part-tx-to-full tx.action)
:: TODO: consider failure case
?> success ?> success
[~ state] [~ state]
:: ::
@ -305,32 +335,36 @@
++ take-tx ++ take-tx
|= [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=?
(try-apply nas force raw-tx) :: TODO: actually use try-apply when proper Tx signing in place
::
:: =^ success nas
:: (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 [[force raw-tx] nep] ::TODO probably +snoc instead? =? pending success (snoc nep [force raw-tx])
::TODO cache nas? ::TODO cache nas?
[success state] [success state]
:: +set-timer: %wait until next whole :frequency :: +set-timer: %wait until next whole :frequency
:: ::
++ set-timer ++ set-timer
^- card ^- card
%+ wait /timer %+ wait:b:sys /timer
(mul +((div now.bowl frequency)) frequency) (mul +((div now.bowl frequency)) frequency)
:: +on-timer: every :frequency, freeze :pending txs roll and start sending it :: +on-timer: every :frequency, freeze :pending txs roll and start sending it
:: ::
++ on-timer ++ on-timer
^- (quip card _state)
=^ cards state =^ cards state
?~ pending [~ state] ?~ pending [~ state]
=/ nonce=@ud next-nonce =/ nonce=@ud next-nonce
=: pending ~ =: :: FIXME: what's up with this? `pending ~` also fails
:: pending *(list pend-tx)
next-nonce +(next-nonce) next-nonce +(next-nonce)
:: ::
sending sending
%+ ~(put by sending) nonce %+ ~(put by sending) nonce
%+ turn pending [0 (turn pending tail)]
(cork tail (lead 0))
== ==
[(send-roll nonce) state] [(send-roll nonce) state]
[[set-timer cards] state] [[set-timer cards] state]
@ -350,7 +384,14 @@
%+ start-thread:spider %+ start-thread:spider
/send/(scot %ud nonce) /send/(scot %ud nonce)
:- %aggregator-send :- %aggregator-send
!>([nonce ~(got by sending) nonce)]) ::TODO other args !>
:* endpoint
contract
chain-id
0x1234.5678
nonce
(~(got by sending) nonce)
==
:: +on-thread-result: await resend after thread success or failure :: +on-thread-result: await resend after thread success or failure
:: ::
++ on-thread-result ++ on-thread-result
@ -367,7 +408,7 @@
:: resend the l1 tx in five minutes :: resend the l1 tx in five minutes
:: ::
:_ state :_ state
[(wait /resend/(scot %ud nonce) (add resend-time now.bowl))]~ [(wait:b:sys /resend/(scot %ud nonce) (add resend-time now.bowl))]~
:: +on-naive-diff: process l2 tx confirmations :: +on-naive-diff: process l2 tx confirmations
:: ::
++ on-naive-diff ++ on-naive-diff
@ -382,7 +423,7 @@
:: ::
?@ u.wer ?@ u.wer
~? &(?=(%confirmed u.wer) ?=(~ err.diff)) ~? &(?=(%confirmed u.wer) ?=(~ err.diff))
[dap.bowl %weird-double-confirm from.tx] [dap.bowl %weird-double-confirm from.tx.raw-tx.diff]
[~ state] [~ state]
=* nonce nonce.u.wer =* nonce nonce.u.wer
:: remove the tx from the sending map :: remove the tx from the sending map
@ -393,6 +434,7 @@
sending sending
?~ nin=(find [raw-tx.diff]~ txs.u.sen) ?~ nin=(find [raw-tx.diff]~ txs.u.sen)
~& [dap.bowl %weird-unknown] ~& [dap.bowl %weird-unknown]
sending
=. txs.u.sen (oust [u.nin 1] txs.u.sen) =. txs.u.sen (oust [u.nin 1] txs.u.sen)
?~ txs.u.sen ?~ txs.u.sen
~? lverb [dap.bowl %done-with-nonce nonce] ~? lverb [dap.bowl %done-with-nonce nonce]