naive: add get-next-nonce thread

This commit is contained in:
yosoyubik 2021-05-29 14:40:13 +02:00
parent 8851e52f45
commit 8b51b526d3
2 changed files with 70 additions and 16 deletions

View File

@ -195,21 +195,20 @@
++ on-agent ++ on-agent
|= [=wire =sign:agent:gall] |= [=wire =sign:agent:gall]
^- (quip card _this) ^- (quip card _this)
~& wire+wire
|^ |^
?: ?=([%send @t *] wire) ?+ wire (on-agent:def wire sign)
(process-thread i.t.wire sign) [%send @t *] (process-send-batch i.t.wire sign)
?. =(%azimuth -.wire) [%azimuth ~] (process-azimuth-update sign)
(on-agent:def wire sign) [%nonce ~] (process-nonce sign)
(process-azimuth-update wire sign) ==
:: ::
++ process-thread ++ process-send-batch
|= [nonce=@t =sign:agent:gall] |= [nonce=@t =sign:agent:gall]
^- (quip card _this) ^- (quip card _this)
?- -.sign ?- -.sign
%poke-ack %poke-ack
?~ p.sign ?~ p.sign
%- (slog leaf+"Thread started successfully" ~) %- (slog leaf+"Send batch thread started successfully" ~)
[~ this] [~ this]
%- (slog leaf+"{(trip dap.bowl)} couldn't start thread" u.p.sign) %- (slog leaf+"{(trip dap.bowl)} couldn't start thread" u.p.sign)
:_ this :_ this
@ -231,20 +230,19 @@
=+ !<([=term =tang] q.cage.sign) =+ !<([=term =tang] q.cage.sign)
%- (slog leaf+"{(trip dap.bowl)} failed" leaf+<term> tang) %- (slog leaf+"{(trip dap.bowl)} failed" leaf+<term> tang)
=^ cards state =^ cards state
(on-thread-result:do (rash nonce dem) %.n^'thread failed') (on-batch-result:do (rash nonce dem) %.n^'thread failed')
[cards this] [cards this]
:: ::
%thread-done %thread-done
=+ !<(result=(each @ud @t) q.cage.sign) =+ !<(result=(each @ud @t) q.cage.sign)
=^ cards state =^ cards state
(on-thread-result:do (rash nonce dem) result) (on-batch-result:do (rash nonce dem) result)
[cards this] [cards this]
== ==
== ==
:: TODO: not tested
:: ::
++ process-azimuth-update ++ process-azimuth-update
|= [=^wire =sign:agent:gall] |= =sign:agent:gall
^- (quip card _this) ^- (quip card _this)
?+ -.sign [~ this] ?+ -.sign [~ this]
%watch-ack %watch-ack
@ -255,13 +253,48 @@
:: ::
%fact %fact
?+ p.cage.sign (on-agent:def wire sign) ?+ p.cage.sign (on-agent:def wire sign)
%azimuth-udiffs %naive-diffs
=+ !<(=diff:naive q.cage.sign) =+ !<(=diff:naive q.cage.sign)
=^ cards state =^ cards state
(on-naive-diff:do diff) (on-naive-diff:do diff)
[cards this] [cards this]
== ==
== ==
::
++ process-nonce
|= =sign:agent:gall
^- (quip card _this)
?- -.sign
%poke-ack
?~ p.sign
%- (slog leaf+"Nonce thread started successfully" ~)
[~ this]
%- (slog leaf+"{(trip dap.bowl)} couldn't start thread" u.p.sign)
:_ this
[(leave:spider:do wire)]~
::
%watch-ack
?~ p.sign
[~ this]
=/ =tank leaf+"{(trip dap.bowl)} couldn't start listen to thread"
%- (slog tank u.p.sign)
[~ this]
::
%kick
[~ this]
::
%fact
?+ p.cage.sign (on-agent:def wire sign)
%thread-fail
=+ !<([=term =tang] q.cage.sign)
%- (slog leaf+"{(trip dap.bowl)} failed" leaf+<term> tang)
[~ this]
::
%thread-done
=+ !<(nonce=@ud q.cage.sign)
[~ this(next-nonce nonce)]
==
==
-- --
-- --
:: ::
@ -375,7 +408,7 @@
:: ::
%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) state(pk q.u.pk)
@ -432,6 +465,12 @@
== ==
[(send-roll nonce) state] [(send-roll nonce) state]
[[set-timer cards] state] [[set-timer cards] state]
:: +get-nonce: retrieves the latest nonce
::
++ get-nonce
^- (list card)
(start-thread:spider /nonce [%aggregator-nonce !>([endpoint pk])])
::
:: +send-roll: start thread to submit roll from :sending to l1 :: +send-roll: start thread to submit roll from :sending to l1
:: ::
++ send-roll ++ send-roll
@ -456,9 +495,9 @@
nonce nonce
(~(got by sending) nonce) (~(got by sending) nonce)
== ==
:: +on-thread-result: await resend after thread success or failure :: +on-batch-result: await resend after thread success or failure
:: ::
++ on-thread-result ++ on-batch-result
|= [nonce=@ud result=(each @ud @t)] |= [nonce=@ud result=(each @ud @t)]
^- (quip card _state) ^- (quip card _state)
:: update gas price for this tx in state :: update gas price for this tx in state

View File

@ -0,0 +1,15 @@
:: aggregator/nonce: get next nonce
::
/- rpc=json-rpc
/+ ethereum, ethio, strandio
::
|= args=vase
=+ !<([endpoint=@t pk=@] args)
=/ m (strand:strandio ,vase)
^- form:m
::
=/ =address:ethereum
(address-from-prv:key:ethereum pk)
;< expected-nonce=@ud bind:m
(get-next-nonce:ethio endpoint address)
(pure:m !>(expected-nonce))