2021-08-16 14:01:23 +03:00
|
|
|
:: roller: Azimuth L2 roll aggregator
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
|
|
|
:: general flow is as described below, to ensure transactions actually go
|
|
|
|
:: through once we start sending it out, in the dumbest reasonable way.
|
|
|
|
::
|
|
|
|
:: periodic timer fires:
|
|
|
|
:: if there are no pending l2 txs, do nothing.
|
|
|
|
:: else kick off tx submission flow:
|
|
|
|
:: "freeze" pending txs, store alongside nonce, then increment nonce,
|
|
|
|
:: kick off thread for sending the corresponding l1 tx:
|
|
|
|
:: if nonce doesn't match on-chain expected nonce, bail.
|
|
|
|
:: if we can't afford the tx fee, bail.
|
|
|
|
:: construct, sign, submit the l1 tx.
|
|
|
|
:: if thread bailed, retry in five minutes.
|
|
|
|
:: if thread succeeded, retry in five minutes with higher gas price.
|
|
|
|
:: 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 questions:
|
|
|
|
:: - it's a bit weird how we just assume the raw and tx in raw-tx to match...
|
|
|
|
::
|
2021-07-22 07:34:42 +03:00
|
|
|
/- *dice
|
2021-06-14 16:00:15 +03:00
|
|
|
/+ azimuth,
|
|
|
|
naive,
|
2021-07-22 07:34:42 +03:00
|
|
|
dice,
|
2021-06-14 16:00:15 +03:00
|
|
|
lib=naive-transactions,
|
|
|
|
default-agent,
|
|
|
|
ethereum,
|
|
|
|
dbug,
|
|
|
|
verb
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
|
|
|
|%
|
|
|
|
+$ state-0
|
|
|
|
$: %0
|
|
|
|
:: pending: the next l2 txs to be sent
|
|
|
|
:: sending: the l2 txs currently sending/awaiting l2 confirmation
|
|
|
|
:: finding: raw-tx-hash reverse lookup for sending map
|
2021-06-16 18:03:21 +03:00
|
|
|
:: history: status of l2 txs by ethereum address
|
2021-05-13 18:21:35 +03:00
|
|
|
:: next-nonce: next l1 nonce to use
|
2021-06-09 14:05:17 +03:00
|
|
|
:: next-batch: when then next l2 batch will be sent
|
2021-06-09 14:30:36 +03:00
|
|
|
:: pre: predicted l2 state
|
2021-07-08 17:45:27 +03:00
|
|
|
:: own: ownership of azimuth points
|
|
|
|
:: derive-p: flag (derive predicted state)
|
|
|
|
:: derive-o: flag (derive ownership state)
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
|
|
|
pending=(list pend-tx)
|
2021-06-01 17:18:32 +03:00
|
|
|
::
|
|
|
|
$= sending
|
|
|
|
%+ map l1-tx-pointer
|
|
|
|
[next-gas-price=@ud txs=(list raw-tx:naive)]
|
|
|
|
::
|
2021-08-27 17:05:59 +03:00
|
|
|
finding=(map keccak ?(%confirmed %failed [=time l1-tx-pointer]))
|
2021-06-16 18:03:21 +03:00
|
|
|
history=(jug address:ethereum roller-tx)
|
2021-06-09 16:37:37 +03:00
|
|
|
next-nonce=(unit @ud)
|
2021-06-09 14:05:17 +03:00
|
|
|
next-batch=time
|
2021-06-09 14:30:36 +03:00
|
|
|
pre=^state:naive
|
2021-07-08 17:45:27 +03:00
|
|
|
own=owners
|
|
|
|
derive-p=?
|
|
|
|
derive-o=?
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
|
|
|
:: pk: private key to send the roll
|
|
|
|
:: frequency: time to wait between sending batches (TODO fancier)
|
|
|
|
:: endpoint: ethereum rpc endpoint to use
|
2021-05-29 15:43:13 +03:00
|
|
|
:: contract: ethereum contract address
|
|
|
|
:: chain-id: mainnet, ropsten, local (https://chainid.network/)
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
|
|
|
pk=@
|
|
|
|
frequency=@dr
|
2021-06-09 16:37:37 +03:00
|
|
|
endpoint=(unit @t)
|
2021-05-29 15:43:13 +03:00
|
|
|
contract=@ux
|
|
|
|
chain-id=@
|
2021-05-13 18:21:35 +03:00
|
|
|
==
|
|
|
|
::
|
2021-08-04 16:53:57 +03:00
|
|
|
+$ init [nas=^state:naive own=owners]
|
|
|
|
::
|
2021-06-03 10:11:33 +03:00
|
|
|
+$ config
|
|
|
|
$% [%frequency frequency=@dr]
|
2021-05-13 18:21:35 +03:00
|
|
|
[%setkey pk=@]
|
2021-05-21 13:16:57 +03:00
|
|
|
[%endpoint endpoint=@t]
|
2021-05-29 15:43:13 +03:00
|
|
|
[%network net=?(%mainnet %ropsten %local)]
|
2021-06-03 10:11:33 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
+$ action
|
2021-08-04 16:53:57 +03:00
|
|
|
$% :: we need to include the address in submit so pending txs show up
|
2021-07-20 12:22:16 +03:00
|
|
|
:: in the tx history, but because users can send the wrong
|
2021-08-04 16:53:57 +03:00
|
|
|
:: address, in +apply-tx:predicted state, we just replace
|
2021-07-20 12:22:16 +03:00
|
|
|
:: the provided address, with the one used when the message was signed;
|
|
|
|
::
|
|
|
|
:: we need to do it there to know the correct nonce that the signed
|
|
|
|
:: message should have included.
|
|
|
|
::
|
|
|
|
[%submit force=? =address:naive sig=@ tx=part-tx]
|
2021-07-15 15:26:44 +03:00
|
|
|
[%cancel sig=@ keccak=@ =l2-tx =ship]
|
2021-06-03 10:11:33 +03:00
|
|
|
[%commit ~] ::TODO maybe pk=(unit @) later
|
|
|
|
[%config config]
|
2021-05-13 18:21:35 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
+$ card card:agent:gall
|
|
|
|
::
|
2021-06-29 08:45:44 +03:00
|
|
|
:: TODO: add to config
|
|
|
|
::
|
2021-05-13 18:21:35 +03:00
|
|
|
++ resend-time ~m5
|
|
|
|
::
|
|
|
|
++ lverb &
|
|
|
|
--
|
|
|
|
::
|
2021-05-17 18:48:49 +03:00
|
|
|
=| state-0
|
|
|
|
=* state -
|
|
|
|
::
|
2021-05-13 18:21:35 +03:00
|
|
|
%- agent:dbug
|
|
|
|
%+ verb |
|
|
|
|
^- agent:gall
|
|
|
|
::
|
|
|
|
=<
|
|
|
|
|_ =bowl:gall
|
|
|
|
+* this .
|
2021-05-17 18:48:49 +03:00
|
|
|
do ~(. +> bowl)
|
2021-05-13 18:21:35 +03:00
|
|
|
def ~(. (default-agent this %|) bowl)
|
|
|
|
::
|
|
|
|
++ on-init
|
|
|
|
^- (quip card _this)
|
|
|
|
=. frequency ~h1
|
2021-05-29 15:43:13 +03:00
|
|
|
=. contract naive:local-contracts:azimuth
|
|
|
|
=. chain-id chain-id:local-contracts:azimuth
|
2021-06-09 14:05:17 +03:00
|
|
|
=^ card next-batch set-timer
|
2021-05-23 16:49:55 +03:00
|
|
|
:_ this
|
2021-06-09 14:05:17 +03:00
|
|
|
:~ card
|
2021-07-08 17:45:27 +03:00
|
|
|
[%pass /azimuth-events %agent [our.bowl %azimuth] %watch /event]
|
2021-06-07 14:07:35 +03:00
|
|
|
==
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
|
|
|
++ on-save !>(state)
|
|
|
|
++ on-load
|
|
|
|
|= old=vase
|
|
|
|
^- (quip card _this)
|
|
|
|
[~ this(state !<(state-0 old))]
|
|
|
|
::
|
|
|
|
++ on-poke
|
|
|
|
|= [=mark =vase]
|
|
|
|
^- (quip card _this)
|
2021-05-17 18:48:49 +03:00
|
|
|
=^ cards state
|
|
|
|
?+ mark (on-poke:def mark vase)
|
2021-08-16 14:01:23 +03:00
|
|
|
%roller-action
|
2021-05-17 18:48:49 +03:00
|
|
|
=+ !<(poke=action vase)
|
|
|
|
(on-action:do poke)
|
|
|
|
==
|
|
|
|
[cards this]
|
2021-05-13 18:21:35 +03:00
|
|
|
:: +on-peek: scry paths
|
|
|
|
::
|
|
|
|
:: /x/pending -> %noun (list pend-tx)
|
|
|
|
:: /x/pending/[~ship] -> %noun (list pend-tx)
|
|
|
|
:: /x/pending/[0xadd.ress] -> %noun (list pend-tx)
|
|
|
|
:: /x/tx/[0xke.ccak]/status -> %noun tx-status
|
2021-07-22 07:34:42 +03:00
|
|
|
:: /x/history/[0xadd.ress] -> %noun (list roller-tx)
|
2021-06-14 15:18:57 +03:00
|
|
|
:: /x/nonce/[~ship]/[proxy] -> %noun (unit @)
|
2021-09-01 12:01:39 +03:00
|
|
|
:: /x/spawned/[~star] -> %noun (list ship)
|
|
|
|
:: /x/unspawned/[~star] -> %noun (list ship)
|
2021-06-09 14:05:17 +03:00
|
|
|
:: /x/next-batch -> %atom time
|
2021-06-24 17:54:23 +03:00
|
|
|
:: /x/point/[~ship] -> %noun point:naive
|
2021-08-27 17:00:43 +03:00
|
|
|
:: /x/ships/[0xadd.ress] -> %noun (list ship)
|
2021-06-29 08:45:44 +03:00
|
|
|
:: /x/config -> %noun config
|
2021-08-04 16:53:57 +03:00
|
|
|
:: /x/chain-id -> %atom @
|
2021-08-27 17:00:43 +03:00
|
|
|
:: /x/owned -> %noun (list ship)
|
|
|
|
:: /x/transfers -> %noun (list ship)
|
|
|
|
:: /x/manager -> %noun (list ship)
|
|
|
|
:: /x/voting -> %noun (list ship)
|
|
|
|
:: /x/spawning -> %noun (list ship)
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
|
|
|
++ on-peek
|
|
|
|
|= =path
|
|
|
|
^- (unit (unit cage))
|
2021-06-04 12:41:59 +03:00
|
|
|
|^
|
2021-05-13 18:21:35 +03:00
|
|
|
?+ path ~
|
2021-06-09 14:05:17 +03:00
|
|
|
[%x %pending ~] ``noun+!>(pending)
|
2021-06-04 12:41:59 +03:00
|
|
|
[%x %pending @ ~] (pending-by i.t.t.path)
|
|
|
|
[%x %tx @ %status ~] (status i.t.t.path)
|
2021-06-16 18:03:21 +03:00
|
|
|
[%x %history @ ~] (history i.t.t.path)
|
2021-06-04 12:41:59 +03:00
|
|
|
[%x %nonce @ @ ~] (nonce i.t.t.path i.t.t.t.path)
|
|
|
|
[%x %spawned @ ~] (spawned i.t.t.path)
|
2021-09-01 12:01:39 +03:00
|
|
|
[%x %unspawned @ ~] (unspawned i.t.t.path)
|
2021-07-22 13:05:28 +03:00
|
|
|
[%x %next-batch ~] ``atom+!>(next-batch)
|
2021-06-22 16:00:24 +03:00
|
|
|
[%x %point @ ~] (point i.t.t.path)
|
2021-08-27 18:08:24 +03:00
|
|
|
[%x %ships @ ~] (ships i.t.t.path)
|
2021-06-29 08:45:44 +03:00
|
|
|
[%x %config ~] config
|
2021-07-22 13:05:28 +03:00
|
|
|
[%x %chain-id ~] ``atom+!>(chain-id)
|
2021-08-27 17:00:43 +03:00
|
|
|
[%x %owned @ ~] (points-proxy %own i.t.t.path)
|
|
|
|
[%x %transfers @ ~] (points-proxy %transfer i.t.t.path)
|
|
|
|
[%x %manager @ ~] (points-proxy %manage i.t.t.path)
|
|
|
|
[%x %voting @ ~] (points-proxy %vote i.t.t.path)
|
|
|
|
[%x %spawning @ ~] (points-proxy %spawn i.t.t.path)
|
2021-06-04 12:41:59 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
++ pending-by
|
|
|
|
|= wat=@t
|
2021-05-13 18:21:35 +03:00
|
|
|
?~ who=(slaw %p wat)
|
2021-05-17 18:48:49 +03:00
|
|
|
:: by-address
|
|
|
|
::
|
2021-05-13 18:21:35 +03:00
|
|
|
?~ wer=(slaw %ux wat)
|
|
|
|
[~ ~]
|
2021-05-17 18:48:49 +03:00
|
|
|
=; pending=(list pend-tx)
|
|
|
|
``noun+!>(pending)
|
2021-06-09 14:05:17 +03:00
|
|
|
%+ skim pending
|
2021-05-13 18:21:35 +03:00
|
|
|
|= pend-tx
|
2021-07-08 17:45:27 +03:00
|
|
|
=(u.wer (need (get-l1-address tx.raw-tx pre)))
|
2021-05-17 18:48:49 +03:00
|
|
|
:: by-ship
|
|
|
|
::
|
|
|
|
=; pending=(list pend-tx)
|
|
|
|
``noun+!>(pending)
|
2021-06-09 14:05:17 +03:00
|
|
|
%+ skim pending
|
2021-05-13 18:21:35 +03:00
|
|
|
|= pend-tx
|
|
|
|
=(u.who ship.from.tx.raw-tx)
|
|
|
|
::
|
2021-06-04 12:41:59 +03:00
|
|
|
++ status
|
|
|
|
|= wat=@t
|
|
|
|
?~ keccak=(slaw %ux wat)
|
2021-05-13 18:21:35 +03:00
|
|
|
[~ ~]
|
|
|
|
:+ ~ ~
|
|
|
|
:- %noun
|
|
|
|
!> ^- tx-status
|
|
|
|
?^ status=(~(get by finding) u.keccak)
|
|
|
|
?@ u.status [u.status ~]
|
2021-08-27 17:05:59 +03:00
|
|
|
[%sending `+.u.status]
|
2021-05-13 18:21:35 +03:00
|
|
|
::TODO potentially slow!
|
|
|
|
=; known=?
|
|
|
|
[?:(known %pending %unknown) ~]
|
2021-06-09 14:05:17 +03:00
|
|
|
%+ lien pending
|
2021-06-16 18:03:21 +03:00
|
|
|
|= pend-tx
|
2021-07-15 15:23:08 +03:00
|
|
|
=(u.keccak (hash-tx:lib raw.raw-tx))
|
2021-06-16 18:03:21 +03:00
|
|
|
::
|
|
|
|
++ history
|
|
|
|
|= wat=@t
|
|
|
|
:+ ~ ~
|
|
|
|
:- %noun
|
|
|
|
!> ^- (list roller-tx)
|
|
|
|
?~ addr=(slaw %ux wat) ~
|
|
|
|
%~ tap in
|
|
|
|
(~(get ju ^history) u.addr)
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
2021-06-04 12:41:59 +03:00
|
|
|
++ nonce
|
|
|
|
|= [who=@t proxy=@t]
|
|
|
|
?~ who=(slaw %p who)
|
2021-05-13 18:21:35 +03:00
|
|
|
[~ ~]
|
|
|
|
?. ?=(proxy:naive proxy)
|
|
|
|
[~ ~]
|
2021-06-14 15:18:57 +03:00
|
|
|
:+ ~ ~
|
|
|
|
:- %noun
|
|
|
|
!> ^- (unit @)
|
|
|
|
?~ point=(get:orm:naive points.pre u.who)
|
|
|
|
~
|
|
|
|
=< `nonce
|
|
|
|
(proxy-from-point:naive proxy u.point)
|
2021-06-04 12:41:59 +03:00
|
|
|
::
|
|
|
|
++ spawned
|
|
|
|
|= wat=@t
|
|
|
|
:+ ~ ~
|
|
|
|
:- %noun
|
2021-09-01 12:01:39 +03:00
|
|
|
!> ^- (list @p)
|
2021-06-04 12:41:59 +03:00
|
|
|
?~ star=(slaw %p wat) ~
|
2021-09-01 12:01:39 +03:00
|
|
|
=; range
|
|
|
|
(turn range head)
|
|
|
|
=, orm:naive
|
|
|
|
:: range exclusive [star first-moon-last-planet]
|
|
|
|
::
|
|
|
|
%- tap
|
|
|
|
(lot points.pre [`u.star `(cat 3 u.star 0x1.ffff)])
|
|
|
|
::
|
|
|
|
++ unspawned
|
|
|
|
|= wat=@t
|
|
|
|
:+ ~ ~
|
|
|
|
:- %noun
|
|
|
|
!> ^- (list @p)
|
|
|
|
?~ star=(slaw %p wat) ~
|
|
|
|
=/ spawned=(set @p)
|
|
|
|
=; points
|
|
|
|
(~(gas in *(set @p)) (turn points head))
|
|
|
|
=, orm:naive
|
|
|
|
%- tap
|
|
|
|
(lot points.pre [`u.star `(cat 3 u.star 0x1.ffff)])
|
|
|
|
=/ children=(list @p)
|
|
|
|
(turn (gulf 0x1 0xffff) |=(a=@ (cat 3 u.star a)))
|
|
|
|
%+ murn children
|
|
|
|
|= =ship
|
|
|
|
?: (~(has in spawned) ship) ~
|
|
|
|
`ship
|
2021-06-22 16:00:24 +03:00
|
|
|
::
|
|
|
|
++ point
|
|
|
|
|= wat=@t
|
|
|
|
?~ ship=(rush wat ;~(pfix sig fed:ag))
|
|
|
|
``noun+!>(*(unit point:naive))
|
|
|
|
``noun+!>((get:orm:naive points.pre u.ship))
|
2021-06-24 17:54:23 +03:00
|
|
|
::
|
2021-08-27 17:00:43 +03:00
|
|
|
++ ships
|
2021-06-24 17:54:23 +03:00
|
|
|
|= wat=@t
|
|
|
|
:+ ~ ~
|
|
|
|
:- %noun
|
2021-07-22 07:34:42 +03:00
|
|
|
!> ^- (list ship)
|
2021-06-24 17:54:23 +03:00
|
|
|
?~ addr=(slaw %ux wat)
|
|
|
|
~
|
2021-08-23 17:32:26 +03:00
|
|
|
=/ proxies=(list proxy:naive)
|
|
|
|
~[%own %spawn %manage %vote %transfer]
|
|
|
|
%+ roll proxies
|
|
|
|
|= [=proxy:naive ships=(list ship)]
|
|
|
|
%+ weld ships
|
|
|
|
~(tap in (~(get ju own) [proxy u.addr]))
|
2021-06-29 08:45:44 +03:00
|
|
|
::
|
|
|
|
++ config
|
|
|
|
:+ ~ ~
|
|
|
|
:- %noun
|
|
|
|
!> ^- roller-config
|
|
|
|
:* next-batch
|
|
|
|
frequency
|
|
|
|
resend-time
|
|
|
|
contract
|
|
|
|
chain-id
|
|
|
|
==
|
2021-08-27 17:00:43 +03:00
|
|
|
::
|
|
|
|
++ points-proxy
|
|
|
|
|= [=proxy:naive wat=@t]
|
|
|
|
:+ ~ ~
|
|
|
|
:- %noun
|
|
|
|
!> ^- (list ship)
|
|
|
|
?~ addr=(slaw %ux wat)
|
|
|
|
~
|
|
|
|
~(tap in (~(get ju own) [proxy u.addr]))
|
2021-06-04 12:41:59 +03:00
|
|
|
--
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
|
|
|
++ on-arvo
|
|
|
|
|= [=wire =sign-arvo]
|
|
|
|
^- (quip card _this)
|
2021-06-07 14:09:16 +03:00
|
|
|
?+ wire (on-arvo:def wire sign-arvo)
|
|
|
|
[%timer ~]
|
|
|
|
?+ +<.sign-arvo (on-arvo:def wire sign-arvo)
|
|
|
|
%wake =^(cards state on-timer:do [cards this])
|
|
|
|
==
|
2021-06-11 13:27:05 +03:00
|
|
|
::
|
|
|
|
[%predict ~]
|
|
|
|
?+ +<.sign-arvo (on-arvo:def wire sign-arvo)
|
|
|
|
%wake
|
2021-08-22 19:23:30 +03:00
|
|
|
=^ effects state
|
|
|
|
(predicted-state canonical-state):do
|
|
|
|
[(emit effects) this(derive-p &)]
|
2021-07-08 17:45:27 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
[%owners ~]
|
|
|
|
?+ +<.sign-arvo (on-arvo:def wire sign-arvo)
|
|
|
|
%wake
|
|
|
|
=. own.state canonical-owners:do
|
|
|
|
`this(derive-o &)
|
2021-06-11 13:27:05 +03:00
|
|
|
==
|
2021-06-07 14:09:16 +03:00
|
|
|
::
|
|
|
|
[%resend @ @ ~]
|
|
|
|
=/ [address=@ux nonce=@ud]
|
|
|
|
[(slav %ux i.t.wire) (rash i.t.t.wire dem)]
|
|
|
|
?+ +<.sign-arvo (on-arvo:def wire sign-arvo)
|
|
|
|
%wake [(send-roll:do address nonce) this]
|
|
|
|
==
|
2021-05-13 18:21:35 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
++ on-fail
|
|
|
|
|= [=term =tang]
|
|
|
|
::TODO if crashed during timer, set new timer? how to detect?
|
|
|
|
(on-fail:def term tang)
|
|
|
|
::
|
2021-08-22 19:23:30 +03:00
|
|
|
++ on-watch
|
|
|
|
|= =path
|
|
|
|
^- (quip card _this)
|
|
|
|
:_ this
|
|
|
|
|^
|
|
|
|
?+ path (on-watch:def path)
|
|
|
|
[%txs @ ~] [%give %fact ~ (give-txs i.t.path)]~
|
|
|
|
[%points @ ~] [%give %fact ~ (give-points i.t.path)]~
|
|
|
|
==
|
|
|
|
::
|
|
|
|
++ give-points
|
|
|
|
|= wat=@t
|
|
|
|
^- cage
|
|
|
|
:- %points
|
|
|
|
!> ^- (list [ship point:naive])
|
|
|
|
?~ addr=(slaw %ux wat) ~
|
2021-08-23 17:32:26 +03:00
|
|
|
:: %+ roll
|
|
|
|
:: ~(tap in (~(get ju own) u.addr))
|
|
|
|
=/ proxies=(list proxy:naive)
|
|
|
|
~[%own %spawn %manage %vote %transfer]
|
|
|
|
%+ roll proxies
|
|
|
|
|= [=proxy:naive points=(list [ship point:naive])]
|
|
|
|
%+ weld points
|
|
|
|
::
|
|
|
|
%+ roll ~(tap in (~(get ju own) [proxy u.addr]))
|
|
|
|
|= [=ship points=_points]
|
2021-08-22 19:23:30 +03:00
|
|
|
%+ snoc points
|
|
|
|
[ship (need (get:orm:naive points.pre ship))]
|
|
|
|
::
|
|
|
|
++ give-txs
|
|
|
|
|= wat=@t
|
|
|
|
^- cage
|
|
|
|
:- %txs
|
|
|
|
!> ^- (list roller-tx)
|
|
|
|
?~ addr=(slaw %ux wat) ~
|
|
|
|
%~ tap in
|
|
|
|
(~(get ju history) u.addr)
|
|
|
|
--
|
|
|
|
::
|
2021-05-13 18:21:35 +03:00
|
|
|
++ on-leave on-leave:def
|
2021-05-21 13:16:57 +03:00
|
|
|
++ on-agent
|
|
|
|
|= [=wire =sign:agent:gall]
|
|
|
|
^- (quip card _this)
|
2021-05-23 16:49:55 +03:00
|
|
|
|^
|
2021-05-29 15:40:13 +03:00
|
|
|
?+ wire (on-agent:def wire sign)
|
2021-07-08 17:45:27 +03:00
|
|
|
[%send @ @ *] (send-batch i.t.wire i.t.t.wire sign)
|
|
|
|
[%azimuth-events ~] (azimuth-event sign)
|
|
|
|
[%nonce ~] (nonce sign)
|
2021-05-29 15:40:13 +03:00
|
|
|
==
|
2021-05-21 13:16:57 +03:00
|
|
|
::
|
2021-06-03 10:24:28 +03:00
|
|
|
++ send-batch
|
2021-06-01 17:18:32 +03:00
|
|
|
|= [address=@t nonce=@t =sign:agent:gall]
|
2021-05-23 16:49:55 +03:00
|
|
|
^- (quip card _this)
|
2021-06-03 10:26:13 +03:00
|
|
|
=/ [address=@ux nonce=@ud]
|
|
|
|
[(slav %ux address) (rash nonce dem)]
|
2021-05-23 16:49:55 +03:00
|
|
|
?- -.sign
|
|
|
|
%poke-ack
|
|
|
|
?~ p.sign
|
2021-05-29 15:40:13 +03:00
|
|
|
%- (slog leaf+"Send batch thread started successfully" ~)
|
2021-05-23 16:49:55 +03:00
|
|
|
[~ 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)
|
2021-05-21 13:16:57 +03:00
|
|
|
[~ this]
|
2021-05-23 16:49:55 +03:00
|
|
|
::
|
|
|
|
%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)
|
|
|
|
=^ cards state
|
2021-06-03 10:26:13 +03:00
|
|
|
(on-batch-result:do address nonce %.n^'thread failed')
|
2021-05-23 16:49:55 +03:00
|
|
|
[cards this]
|
|
|
|
::
|
|
|
|
%thread-done
|
|
|
|
=+ !<(result=(each @ud @t) q.cage.sign)
|
|
|
|
=^ cards state
|
2021-06-03 10:26:13 +03:00
|
|
|
(on-batch-result:do address nonce result)
|
2021-05-23 16:49:55 +03:00
|
|
|
[cards this]
|
|
|
|
==
|
|
|
|
==
|
2021-05-21 13:16:57 +03:00
|
|
|
::
|
2021-07-08 17:45:27 +03:00
|
|
|
++ azimuth-event
|
2021-05-29 15:40:13 +03:00
|
|
|
|= =sign:agent:gall
|
2021-05-23 16:49:55 +03:00
|
|
|
^- (quip card _this)
|
|
|
|
?+ -.sign [~ this]
|
|
|
|
%watch-ack
|
|
|
|
?~ p.sign [~ this]
|
|
|
|
=/ =tank leaf+"{(trip dap.bowl)} couldn't start listen to %azimuth"
|
|
|
|
%- (slog tank u.p.sign)
|
|
|
|
[~ this]
|
2021-05-21 13:16:57 +03:00
|
|
|
::
|
2021-05-23 16:49:55 +03:00
|
|
|
%fact
|
|
|
|
?+ p.cage.sign (on-agent:def wire sign)
|
2021-05-29 15:40:13 +03:00
|
|
|
%naive-diffs
|
2021-05-23 16:49:55 +03:00
|
|
|
=+ !<(=diff:naive q.cage.sign)
|
|
|
|
=^ cards state
|
|
|
|
(on-naive-diff:do diff)
|
|
|
|
[cards this]
|
2021-06-01 14:56:56 +03:00
|
|
|
::
|
|
|
|
%naive-state
|
2021-07-08 17:45:27 +03:00
|
|
|
~& > %received-azimuth-state
|
|
|
|
:: cache naive and ownership state
|
2021-06-01 14:56:56 +03:00
|
|
|
::
|
2021-07-08 17:45:27 +03:00
|
|
|
=^ nas own.state !<(init q.cage.sign)
|
2021-08-22 19:23:30 +03:00
|
|
|
=^ effects state
|
|
|
|
(predicted-state:do nas)
|
|
|
|
[(emit effects) this]
|
2021-05-23 16:49:55 +03:00
|
|
|
==
|
2021-05-21 13:16:57 +03:00
|
|
|
==
|
2021-05-29 15:40:13 +03:00
|
|
|
::
|
2021-06-03 10:24:28 +03:00
|
|
|
++ nonce
|
2021-05-29 15:40:13 +03:00
|
|
|
|= =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)
|
2021-06-09 16:37:37 +03:00
|
|
|
[~ this(next-nonce `nonce)]
|
2021-05-29 15:40:13 +03:00
|
|
|
==
|
|
|
|
==
|
2021-05-23 16:49:55 +03:00
|
|
|
--
|
2021-05-13 18:21:35 +03:00
|
|
|
--
|
|
|
|
::
|
|
|
|
|_ =bowl:gall
|
|
|
|
::TODO /lib/sys.hoon?
|
|
|
|
++ sys
|
|
|
|
|%
|
|
|
|
++ b
|
|
|
|
|%
|
|
|
|
++ wait
|
|
|
|
|= [=wire =time]
|
|
|
|
^- card
|
|
|
|
[%pass wire %arvo %b %wait time]
|
|
|
|
--
|
|
|
|
--
|
|
|
|
::TODO /lib/spider.hoon?
|
|
|
|
++ spider
|
|
|
|
|%
|
|
|
|
++ start-thread
|
|
|
|
|= [=wire thread=term arg=vase]
|
|
|
|
^- (list card)
|
|
|
|
=/ tid=@ta (rap 3 thread '--' (scot %uv eny.bowl) ~)
|
2021-05-23 16:49:55 +03:00
|
|
|
=/ args [~ `tid thread arg]
|
2021-05-21 13:16:57 +03:00
|
|
|
:~ [%pass wire %agent [our.bowl %spider] %watch /thread-result/[tid]]
|
2021-05-23 16:49:55 +03:00
|
|
|
[%pass wire %agent [our.bowl %spider] %poke %spider-start !>(args)]
|
2021-05-13 18:21:35 +03:00
|
|
|
==
|
2021-05-17 18:48:49 +03:00
|
|
|
::
|
|
|
|
++ leave
|
|
|
|
|= =path
|
|
|
|
^- card
|
|
|
|
[%pass path %agent [our.bowl %spider] %leave ~]
|
2021-05-13 18:21:35 +03:00
|
|
|
--
|
|
|
|
::
|
2021-08-22 19:23:30 +03:00
|
|
|
::
|
|
|
|
++ emit
|
|
|
|
|= updates=(list update)
|
|
|
|
|- ^- (list card)
|
|
|
|
?~ updates ~
|
|
|
|
=* up i.updates
|
2021-08-27 16:59:10 +03:00
|
|
|
=/ [address=@t last-owner=(unit @t)]
|
|
|
|
?- -.up
|
|
|
|
%tx
|
|
|
|
:_ ~
|
|
|
|
(scot %ux address.up)
|
|
|
|
::
|
|
|
|
%point
|
|
|
|
:- (scot %ux address.new.up)
|
|
|
|
?~(old.up ~ `(scot %ux address.u.old.up))
|
2021-08-23 17:32:26 +03:00
|
|
|
==
|
2021-08-27 16:59:10 +03:00
|
|
|
%+ weld
|
|
|
|
$(updates t.updates)
|
|
|
|
^- (list card)
|
2021-08-22 19:23:30 +03:00
|
|
|
?- -.i.updates
|
2021-08-27 16:59:10 +03:00
|
|
|
%tx
|
|
|
|
[%give %fact ~[/txs/[address]] tx+!>(roller-tx.up)]~
|
|
|
|
::
|
|
|
|
%point
|
|
|
|
%+ weld
|
|
|
|
[%give %fact ~[/points/[address]] point+!>([ship point]:up)]~
|
|
|
|
?~ last-owner ~
|
|
|
|
[%give %fact ~[/points/[u.last-owner]] point+!>([ship point]:up)]~
|
2021-08-22 19:23:30 +03:00
|
|
|
==
|
|
|
|
::
|
2021-05-13 18:21:35 +03:00
|
|
|
++ part-tx-to-full
|
|
|
|
|= =part-tx
|
|
|
|
^- [octs tx:naive]
|
2021-05-29 15:46:19 +03:00
|
|
|
?- -.part-tx
|
2021-05-23 15:59:29 +03:00
|
|
|
%raw
|
|
|
|
?~ batch=(parse-raw-tx:naive q.raw.part-tx)
|
|
|
|
~& %parse-failed
|
|
|
|
:: TODO: maybe return a unit if parsing fails?
|
|
|
|
::
|
|
|
|
!!
|
|
|
|
[raw tx]:-.u.batch
|
2021-05-29 15:44:16 +03:00
|
|
|
::
|
|
|
|
%don [(gen-tx-octs:lib +.part-tx) +.part-tx]
|
2021-05-13 18:21:35 +03:00
|
|
|
%ful +.part-tx
|
|
|
|
==
|
2021-08-04 16:53:57 +03:00
|
|
|
:: +canonical-state: current l2 state from /app/azimuth
|
2021-06-03 10:24:28 +03:00
|
|
|
::
|
|
|
|
++ canonical-state
|
|
|
|
.^ ^state:naive
|
|
|
|
%gx
|
|
|
|
(scot %p our.bowl)
|
|
|
|
%azimuth
|
|
|
|
(scot %da now.bowl)
|
2021-07-07 18:35:07 +03:00
|
|
|
/nas/noun
|
2021-06-03 10:24:28 +03:00
|
|
|
==
|
2021-08-04 16:53:57 +03:00
|
|
|
:: +canonical-owners: current azimuth point ownership
|
2021-07-08 17:45:27 +03:00
|
|
|
::
|
|
|
|
++ canonical-owners
|
|
|
|
.^ owners
|
|
|
|
%gx
|
|
|
|
(scot %p our.bowl)
|
|
|
|
%azimuth
|
|
|
|
(scot %da now.bowl)
|
2021-07-19 08:10:31 +03:00
|
|
|
/own/noun
|
2021-07-08 17:45:27 +03:00
|
|
|
==
|
2021-06-07 12:20:31 +03:00
|
|
|
:: +predicted-state
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
2021-08-04 16:53:57 +03:00
|
|
|
:: derives predicted state from applying pending/sending txs to
|
|
|
|
:: the canonical state, discarding invalid txs in the process.
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
2021-06-07 12:20:31 +03:00
|
|
|
++ predicted-state
|
2021-06-03 10:24:28 +03:00
|
|
|
|= nas=^state:naive
|
2021-08-22 19:23:30 +03:00
|
|
|
^- (quip update _state)
|
|
|
|
=. pre.state nas
|
|
|
|
:: recreate ownership based on succesful txs
|
|
|
|
::
|
2021-06-05 15:24:37 +03:00
|
|
|
|^
|
2021-08-22 19:23:30 +03:00
|
|
|
=^ [nes=_sending ups-1=(list update)]
|
|
|
|
state apply-sending
|
|
|
|
=^ [nep=_pending ups-2=(list update)]
|
|
|
|
state apply-pending
|
|
|
|
:- (welp ups-1 ups-2)
|
2021-08-04 16:53:57 +03:00
|
|
|
state(sending nes, pending nep)
|
|
|
|
::
|
|
|
|
++ apply-pending
|
|
|
|
(apply-txs pending %pending)
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
2021-06-05 15:24:37 +03:00
|
|
|
++ apply-sending
|
|
|
|
=| valid=_sending
|
2021-08-22 19:23:30 +03:00
|
|
|
=| ups=(list update)
|
2021-06-05 15:24:37 +03:00
|
|
|
=+ sending=~(tap by sending)
|
2021-08-22 19:23:30 +03:00
|
|
|
|- ^+ [[valid ups] state]
|
|
|
|
?~ sending [[valid ups] state]
|
2021-06-05 15:24:37 +03:00
|
|
|
::
|
|
|
|
=* key p.i.sending
|
|
|
|
=* val q.i.sending
|
2021-08-27 17:05:59 +03:00
|
|
|
=+ txs=(turn txs.val |=(=raw-tx:naive [| 0x0 *time raw-tx]))
|
2021-08-22 19:23:30 +03:00
|
|
|
=^ [new-valid=_txs nups=_ups] state
|
|
|
|
(apply-txs txs %sending)
|
2021-06-05 15:24:37 +03:00
|
|
|
=. valid
|
|
|
|
%+ ~(put by valid) key
|
2021-08-27 17:05:59 +03:00
|
|
|
:: TODO: too much functional hackery?
|
|
|
|
val(txs (turn new-valid (cork tail (cork tail tail))))
|
2021-08-22 19:23:30 +03:00
|
|
|
$(sending t.sending, ups (welp ups nups))
|
2021-06-05 15:24:37 +03:00
|
|
|
::
|
2021-08-04 16:53:57 +03:00
|
|
|
++ apply-txs
|
2021-06-22 16:15:33 +03:00
|
|
|
|= [txs=(list pend-tx) type=?(%pending %sending)]
|
2021-06-05 15:24:37 +03:00
|
|
|
=/ valid=_txs ~
|
2021-08-22 19:23:30 +03:00
|
|
|
=| ups=(list update)
|
2021-08-12 11:17:42 +03:00
|
|
|
:: =| local=(set keccak)
|
2021-08-22 19:23:30 +03:00
|
|
|
|- ^+ [[valid ups] state]
|
|
|
|
?~ txs [[valid ups] state]
|
2021-06-24 17:56:32 +03:00
|
|
|
::
|
2021-08-22 19:23:30 +03:00
|
|
|
=* tx i.txs
|
|
|
|
=* raw-tx raw-tx.i.txs
|
|
|
|
=* ship ship.from.tx.raw-tx.i.txs
|
2021-08-27 17:05:59 +03:00
|
|
|
=* time time.i.txs
|
2021-07-15 15:23:08 +03:00
|
|
|
=/ hash=@ux (hash-raw-tx:lib raw-tx)
|
2021-08-12 11:17:42 +03:00
|
|
|
:: TODO: add tests to validate if this is necessary
|
|
|
|
::
|
|
|
|
:: ?: (~(has in local) hash)
|
|
|
|
:: :: if tx was already seen here, skip
|
|
|
|
:: ::
|
|
|
|
:: $(txs t.txs)
|
2021-07-22 17:46:23 +03:00
|
|
|
=/ sign-address=(unit @ux)
|
|
|
|
(extract-address:lib raw-tx pre.state chain-id)
|
2021-08-22 19:23:30 +03:00
|
|
|
=^ [gud=? nups=_ups] state
|
2021-07-22 17:46:23 +03:00
|
|
|
(try-apply pre.state force.tx raw-tx)
|
|
|
|
:: TODO: only replace address if !=(address.tx sign-address)?
|
2021-07-20 12:22:16 +03:00
|
|
|
::
|
2021-07-22 17:46:23 +03:00
|
|
|
=? tx &(gud ?=(^ sign-address))
|
|
|
|
tx(address u.sign-address)
|
2021-08-22 19:23:30 +03:00
|
|
|
::
|
|
|
|
=/ =roller-tx
|
2021-08-27 17:05:59 +03:00
|
|
|
[ship type hash time (l2-tx +<.tx.raw-tx)]
|
2021-08-22 19:23:30 +03:00
|
|
|
=? nups !gud
|
|
|
|
%+ snoc nups
|
|
|
|
[%tx address.tx roller-tx(status %failed)]
|
2021-06-05 15:24:37 +03:00
|
|
|
=? valid gud (snoc valid tx)
|
2021-06-28 08:46:09 +03:00
|
|
|
=? finding.state !gud
|
|
|
|
(~(put by finding.state) [hash %failed])
|
|
|
|
=? history.state !gud
|
2021-08-04 16:53:57 +03:00
|
|
|
%. [address.tx roller-tx(status %failed)]
|
2021-06-28 08:46:09 +03:00
|
|
|
~(put ju (~(del ju history.state) address.tx roller-tx))
|
2021-08-12 11:17:42 +03:00
|
|
|
:: $(txs t.txs, local (~(put in local) hash))
|
2021-08-22 19:23:30 +03:00
|
|
|
$(txs t.txs, ups (weld ups nups))
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
2021-06-11 13:27:05 +03:00
|
|
|
++ try-apply
|
|
|
|
|= [nas=^state:naive force=? =raw-tx:naive]
|
2021-08-22 19:23:30 +03:00
|
|
|
^- [[? ups=(list update)] _state]
|
|
|
|
=/ [success=? predicted=_nas ups=(list update) owners=_own]
|
2021-07-22 13:05:28 +03:00
|
|
|
(apply-raw-tx:dice force raw-tx nas own chain-id)
|
2021-08-22 19:23:30 +03:00
|
|
|
:- [success ups]
|
2021-07-22 13:05:28 +03:00
|
|
|
state(pre predicted, own owners)
|
2021-06-11 13:27:05 +03:00
|
|
|
--
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
2021-06-09 16:37:37 +03:00
|
|
|
++ get-l1-address
|
2021-05-29 15:46:19 +03:00
|
|
|
|= [=tx:naive nas=^state:naive]
|
2021-07-08 17:45:27 +03:00
|
|
|
^- (unit address:ethereum)
|
|
|
|
?~ point=(get:orm:naive points.nas ship.from.tx) ~
|
|
|
|
=< `address
|
2021-06-01 14:56:56 +03:00
|
|
|
(proxy-from-point:naive proxy.from.tx u.point)
|
2021-05-29 15:46:19 +03:00
|
|
|
::
|
2021-05-13 18:21:35 +03:00
|
|
|
++ on-action
|
|
|
|
|= =action
|
2021-05-17 18:48:49 +03:00
|
|
|
^- (quip card _state)
|
2021-05-13 18:21:35 +03:00
|
|
|
?- -.action
|
2021-06-03 10:11:33 +03:00
|
|
|
%commit on-timer
|
|
|
|
%config (on-config +.action)
|
2021-06-21 12:27:36 +03:00
|
|
|
%cancel (cancel-tx +.action)
|
2021-07-20 12:22:16 +03:00
|
|
|
::
|
|
|
|
%submit
|
|
|
|
%- take-tx
|
2021-08-27 17:05:59 +03:00
|
|
|
:* force.action
|
2021-07-20 12:22:16 +03:00
|
|
|
address.action
|
2021-08-27 17:05:59 +03:00
|
|
|
now.bowl
|
|
|
|
sig.action
|
|
|
|
(part-tx-to-full tx.action)
|
|
|
|
==
|
2021-06-03 10:11:33 +03:00
|
|
|
==
|
|
|
|
::
|
|
|
|
++ on-config
|
|
|
|
|= =config
|
|
|
|
^- (quip card _state)
|
|
|
|
?- -.config
|
|
|
|
%frequency [~ state(frequency frequency.config)]
|
2021-06-09 16:37:37 +03:00
|
|
|
%endpoint [~ state(endpoint `endpoint.config)]
|
2021-05-29 15:43:13 +03:00
|
|
|
::
|
|
|
|
%network
|
|
|
|
:- ~
|
|
|
|
=/ [contract=@ux chain-id=@]
|
|
|
|
=< [naive chain-id]
|
|
|
|
=, azimuth
|
2021-06-03 10:11:33 +03:00
|
|
|
?- net.config
|
2021-05-29 15:43:13 +03:00
|
|
|
%mainnet mainnet-contracts
|
|
|
|
%ropsten ropsten-contracts
|
|
|
|
%local local-contracts
|
|
|
|
==
|
|
|
|
state(contract contract, chain-id chain-id)
|
2021-05-21 13:16:57 +03:00
|
|
|
::
|
|
|
|
%setkey
|
2021-06-03 10:11:33 +03:00
|
|
|
?~ pk=(de:base16:mimes:html pk.config)
|
2021-06-01 14:56:56 +03:00
|
|
|
`state
|
|
|
|
[(get-nonce q.u.pk) state(pk q.u.pk)]
|
2021-05-13 18:21:35 +03:00
|
|
|
==
|
2021-06-01 17:18:32 +03:00
|
|
|
:: TODO: move address to state?
|
|
|
|
::
|
|
|
|
++ get-address
|
|
|
|
^- address:ethereum
|
|
|
|
(address-from-prv:key:ethereum pk)
|
2021-06-21 12:27:36 +03:00
|
|
|
:: +cancel-tx: cancel a pending transaction
|
|
|
|
::
|
|
|
|
++ cancel-tx
|
2021-07-15 15:26:44 +03:00
|
|
|
|= [sig=@ =keccak =l2-tx =ship]
|
2021-06-21 12:27:36 +03:00
|
|
|
^- (quip card _state)
|
|
|
|
?^ status=(~(get by finding) keccak)
|
|
|
|
~? lverb [dap.bowl %tx-not-pending status+u.status]
|
|
|
|
[~ state]
|
|
|
|
:: "cancel: 0x1234abcd"
|
|
|
|
::
|
|
|
|
=/ message=octs
|
|
|
|
%: cad:naive 3
|
|
|
|
8^'cancel: '
|
|
|
|
::
|
|
|
|
=; hash=@t
|
|
|
|
(met 3 hash)^hash
|
|
|
|
(crip "0x{((x-co:co 20) keccak)}")
|
|
|
|
::
|
|
|
|
~
|
|
|
|
==
|
2021-07-16 17:15:24 +03:00
|
|
|
?~ addr=(verify-sig:lib sig message)
|
2021-06-21 12:27:36 +03:00
|
|
|
~? lverb [dap.bowl %cancel-sig-fail]
|
|
|
|
[~ state]
|
2021-08-27 17:05:59 +03:00
|
|
|
=^ time pending
|
|
|
|
=| nep=(list pend-tx)
|
|
|
|
=| tx-time=time
|
|
|
|
|- ^- [time _pending]
|
|
|
|
?~ pending [tx-time nep]
|
|
|
|
=+ i.pending
|
|
|
|
=? tx-time =(keccak (hash-raw-tx:lib raw-tx))
|
|
|
|
time
|
|
|
|
=? nep !=(keccak (hash-raw-tx:lib raw-tx))
|
|
|
|
(snoc nep i.pending)
|
|
|
|
$(pending t.pending)
|
2021-07-22 07:34:42 +03:00
|
|
|
:: TODO: mark as failed instead? add a %cancelled to tx-status?
|
|
|
|
::
|
2021-06-21 12:27:36 +03:00
|
|
|
=. history
|
|
|
|
%+ ~(del ju history) u.addr
|
2021-08-27 17:05:59 +03:00
|
|
|
[ship %pending keccak time l2-tx]
|
2021-06-21 12:27:36 +03:00
|
|
|
[~ state]
|
2021-05-13 18:21:35 +03:00
|
|
|
:: +take-tx: accept submitted l2 tx into the :pending list
|
|
|
|
::
|
|
|
|
++ take-tx
|
2021-07-20 12:22:16 +03:00
|
|
|
|= pend-tx
|
2021-06-11 13:27:05 +03:00
|
|
|
^- (quip card _state)
|
2021-07-15 15:23:08 +03:00
|
|
|
=/ hash=@ux (hash-raw-tx:lib raw-tx)
|
2021-06-28 08:46:09 +03:00
|
|
|
:: TODO: what if this hash/tx is already in the history?
|
2021-07-08 17:45:27 +03:00
|
|
|
:: e.g. if previously failed, but now it will go through
|
|
|
|
:: a) check in :finding that hash doesn't exist and if so, skip ?
|
|
|
|
:: b) extract the status from :finding, use it to delete
|
|
|
|
:: the entry in :history, and then insert it as %pending ?
|
2021-06-28 08:46:09 +03:00
|
|
|
::
|
|
|
|
:: =/ not-sent=? !(~(has by finding) hash)
|
|
|
|
:: =? pending not-sent
|
2021-08-27 17:05:59 +03:00
|
|
|
=. pending (snoc pending [force address time raw-tx])
|
2021-06-28 08:46:09 +03:00
|
|
|
:: =? history not-sent
|
2021-08-22 19:23:30 +03:00
|
|
|
=^ update-cards history
|
|
|
|
=/ =roller-tx
|
|
|
|
:* ship.from.tx.raw-tx
|
|
|
|
%pending
|
|
|
|
hash
|
2021-08-27 17:05:59 +03:00
|
|
|
time
|
2021-08-22 19:23:30 +03:00
|
|
|
(l2-tx +<.tx.raw-tx)
|
|
|
|
==
|
|
|
|
:- [%tx address roller-tx]~
|
|
|
|
(~(put ju history) [address roller-tx])
|
2021-06-28 08:46:09 +03:00
|
|
|
:: ?. not-sent ~& "skip" [~ state]
|
2021-06-11 13:27:05 +03:00
|
|
|
:: toggle flush flag
|
|
|
|
::
|
2021-07-08 17:45:27 +03:00
|
|
|
:_ state(derive-p ?:(derive-p | derive-p))
|
2021-08-22 19:23:30 +03:00
|
|
|
%+ weld (emit update-cards)
|
2021-07-08 17:45:27 +03:00
|
|
|
?. derive-p ~
|
2021-06-11 13:27:05 +03:00
|
|
|
:: derive predicted state in 5m.
|
|
|
|
::
|
|
|
|
[(wait:b:sys /predict (add ~m5 now.bowl))]~
|
2021-05-13 18:21:35 +03:00
|
|
|
:: +set-timer: %wait until next whole :frequency
|
|
|
|
::
|
|
|
|
++ set-timer
|
2021-06-09 14:05:17 +03:00
|
|
|
^- [=card =time]
|
|
|
|
=+ time=(mul +((div now.bowl frequency)) frequency)
|
|
|
|
[(wait:b:sys /timer time) time]
|
2021-05-13 18:21:35 +03:00
|
|
|
:: +on-timer: every :frequency, freeze :pending txs roll and start sending it
|
|
|
|
::
|
|
|
|
++ on-timer
|
2021-05-17 18:48:49 +03:00
|
|
|
^- (quip card _state)
|
2021-08-22 19:23:30 +03:00
|
|
|
=^ updates-1 state
|
|
|
|
(predicted-state canonical-state)
|
2021-05-13 18:21:35 +03:00
|
|
|
=^ cards state
|
2021-08-22 19:23:30 +03:00
|
|
|
?: =(~ pending)
|
|
|
|
[(emit updates-1) state]
|
2021-06-09 16:37:37 +03:00
|
|
|
?~ next-nonce
|
|
|
|
~&([dap.bowl %no-nonce] [~ state])
|
|
|
|
=/ nonce=@ud u.next-nonce
|
2021-08-22 19:23:30 +03:00
|
|
|
=^ updates-2 history update-history
|
2021-09-01 12:01:39 +03:00
|
|
|
:: TODO: move to +on-batch-result to prevent the case the
|
|
|
|
:: tx succeds but we get a "Runtime Error: revert"?
|
|
|
|
::
|
2021-05-21 13:16:57 +03:00
|
|
|
=: pending ~
|
2021-07-20 12:22:16 +03:00
|
|
|
derive-p &
|
2021-06-09 16:37:37 +03:00
|
|
|
next-nonce `+(u.next-nonce)
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
|
|
|
sending
|
2021-06-01 17:18:32 +03:00
|
|
|
%+ ~(put by sending)
|
|
|
|
[get-address nonce]
|
2021-08-27 17:05:59 +03:00
|
|
|
[0 (turn pending (cork tail (cork tail tail)))]
|
2021-06-01 14:56:56 +03:00
|
|
|
::
|
|
|
|
finding
|
|
|
|
%- ~(gas by finding)
|
|
|
|
%+ turn pending
|
2021-06-16 18:03:21 +03:00
|
|
|
|= pend-tx
|
2021-08-27 17:05:59 +03:00
|
|
|
(hash-raw-tx:lib raw-tx)^[time address nonce]
|
2021-05-13 18:21:35 +03:00
|
|
|
==
|
2021-08-22 19:23:30 +03:00
|
|
|
:_ state
|
|
|
|
;: welp
|
|
|
|
(emit updates-1)
|
|
|
|
(emit updates-2)
|
|
|
|
(send-roll get-address nonce)
|
|
|
|
==
|
2021-06-09 14:05:17 +03:00
|
|
|
=^ card next-batch set-timer
|
|
|
|
[[card cards] state]
|
2021-08-22 19:23:30 +03:00
|
|
|
::
|
|
|
|
++ update-history
|
|
|
|
%+ roll pending
|
|
|
|
|= [pend-tx ups=(list update) his=_history]
|
|
|
|
=/ =roller-tx
|
|
|
|
:* ship.from.tx.raw-tx
|
|
|
|
%pending
|
|
|
|
(hash-raw-tx:lib raw-tx)
|
2021-08-27 17:05:59 +03:00
|
|
|
time
|
2021-08-22 19:23:30 +03:00
|
|
|
(l2-tx +<.tx.raw-tx)
|
|
|
|
==
|
|
|
|
=+ tx=[address roller-tx(status %sending)]
|
|
|
|
:- (snoc ups tx+tx)
|
|
|
|
%. tx
|
|
|
|
~(put ju (~(del ju his) address roller-tx))
|
2021-05-29 15:40:13 +03:00
|
|
|
:: +get-nonce: retrieves the latest nonce
|
|
|
|
::
|
|
|
|
++ get-nonce
|
2021-06-01 14:56:56 +03:00
|
|
|
|= pk=@
|
2021-05-29 15:40:13 +03:00
|
|
|
^- (list card)
|
2021-06-09 16:37:37 +03:00
|
|
|
?~ endpoint ~&([dap.bowl %no-endpoint] ~)
|
2021-08-16 14:01:23 +03:00
|
|
|
(start-thread:spider /nonce [%roller-nonce !>([u.endpoint pk])])
|
2021-05-29 15:40:13 +03:00
|
|
|
::
|
2021-05-13 18:21:35 +03:00
|
|
|
:: +send-roll: start thread to submit roll from :sending to l1
|
|
|
|
::
|
|
|
|
++ send-roll
|
2021-06-01 17:18:32 +03:00
|
|
|
|= [=address:ethereum nonce=@ud]
|
2021-05-13 18:21:35 +03:00
|
|
|
^- (list card)
|
|
|
|
:: if this nonce isn't in the sending queue anymore, it's done
|
|
|
|
::
|
2021-06-01 17:18:32 +03:00
|
|
|
?. (~(has by sending) [address nonce])
|
|
|
|
~? lverb [dap.bowl %done-sending [address nonce]]
|
2021-05-13 18:21:35 +03:00
|
|
|
~
|
|
|
|
:: start the thread, passing in the l2 txs to use
|
|
|
|
::
|
2021-06-09 16:37:37 +03:00
|
|
|
?~ endpoint ~&([dap.bowl %no-endpoint] ~)
|
2021-05-13 18:21:35 +03:00
|
|
|
::TODO should go ahead and set resend timer in case thread hangs, or nah?
|
|
|
|
%+ start-thread:spider
|
2021-06-03 10:26:13 +03:00
|
|
|
/send/(scot %ux address)/(scot %ud nonce)
|
2021-08-16 14:01:23 +03:00
|
|
|
:- %roller-send
|
2021-05-21 16:07:08 +03:00
|
|
|
!> ^- rpc-send-roll
|
2021-06-09 16:37:37 +03:00
|
|
|
:* u.endpoint
|
2021-05-17 18:48:49 +03:00
|
|
|
contract
|
|
|
|
chain-id
|
2021-05-21 13:16:57 +03:00
|
|
|
pk
|
2021-05-17 18:48:49 +03:00
|
|
|
nonce
|
2021-06-01 17:18:32 +03:00
|
|
|
(~(got by sending) [address nonce])
|
2021-05-17 18:48:49 +03:00
|
|
|
==
|
2021-05-29 15:40:13 +03:00
|
|
|
:: +on-batch-result: await resend after thread success or failure
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
2021-05-29 15:40:13 +03:00
|
|
|
++ on-batch-result
|
2021-06-01 17:18:32 +03:00
|
|
|
|= [=address:ethereum nonce=@ud result=(each @ud @t)]
|
2021-05-13 18:21:35 +03:00
|
|
|
^- (quip card _state)
|
|
|
|
:: update gas price for this tx in state
|
|
|
|
::
|
|
|
|
=? sending ?=(%& -.result)
|
2021-06-01 17:18:32 +03:00
|
|
|
%+ ~(jab by sending) [address nonce]
|
2021-05-13 18:21:35 +03:00
|
|
|
(cork tail (lead p.result))
|
|
|
|
:: print error if there was one
|
|
|
|
::
|
|
|
|
~? ?=(%| -.result) [dap.bowl %send-error p.result]
|
|
|
|
:: resend the l1 tx in five minutes
|
|
|
|
::
|
|
|
|
:_ state
|
2021-06-01 17:18:32 +03:00
|
|
|
:_ ~
|
|
|
|
%+ wait:b:sys
|
2021-06-03 10:26:13 +03:00
|
|
|
/resend/(scot %ux address)/(scot %ud nonce)
|
2021-06-01 17:18:32 +03:00
|
|
|
(add resend-time now.bowl)
|
2021-05-13 18:21:35 +03:00
|
|
|
:: +on-naive-diff: process l2 tx confirmations
|
|
|
|
::
|
|
|
|
++ on-naive-diff
|
|
|
|
|= =diff:naive
|
|
|
|
^- (quip card _state)
|
2021-07-08 17:45:27 +03:00
|
|
|
?: ?=(%point -.diff)
|
|
|
|
:_ state(derive-o ?:(derive-o | derive-o))
|
|
|
|
?. derive-o ~
|
|
|
|
:: calculate ownership in 5m.
|
|
|
|
::
|
|
|
|
[(wait:b:sys /owners (add ~m5 now.bowl))]~
|
2021-05-13 18:21:35 +03:00
|
|
|
?. ?=(%tx -.diff)
|
|
|
|
[~ state]
|
2021-07-15 15:23:08 +03:00
|
|
|
=/ =keccak (hash-raw-tx:lib raw-tx.diff)
|
2021-05-13 18:21:35 +03:00
|
|
|
?~ wer=(~(get by finding) keccak)
|
2021-08-22 19:23:30 +03:00
|
|
|
~& "keccak not in finding"
|
2021-05-13 18:21:35 +03:00
|
|
|
[~ state]
|
|
|
|
:: if we had already seen the tx, no-op
|
|
|
|
::
|
|
|
|
?@ u.wer
|
|
|
|
~? &(?=(%confirmed u.wer) ?=(~ err.diff))
|
2021-05-17 18:48:49 +03:00
|
|
|
[dap.bowl %weird-double-confirm from.tx.raw-tx.diff]
|
2021-05-13 18:21:35 +03:00
|
|
|
[~ state]
|
2021-08-22 19:23:30 +03:00
|
|
|
=* nonce nonce.u.wer
|
|
|
|
=* address address.u.wer
|
|
|
|
=* ship ship.from.tx.raw-tx.diff
|
2021-08-27 17:05:59 +03:00
|
|
|
=* time time.u.wer
|
2021-08-22 19:23:30 +03:00
|
|
|
=* tx tx.raw-tx.diff
|
|
|
|
=/ l2-tx (l2-tx +<.tx)
|
2021-05-13 18:21:35 +03:00
|
|
|
:: remove the tx from the sending map
|
|
|
|
::
|
|
|
|
=. sending
|
2021-06-01 17:18:32 +03:00
|
|
|
?~ sen=(~(get by sending) [get-address nonce])
|
2021-05-13 18:21:35 +03:00
|
|
|
~& [dap.bowl %weird-double-remove]
|
|
|
|
sending
|
|
|
|
?~ nin=(find [raw-tx.diff]~ txs.u.sen)
|
|
|
|
~& [dap.bowl %weird-unknown]
|
2021-05-17 18:48:49 +03:00
|
|
|
sending
|
2021-05-13 18:21:35 +03:00
|
|
|
=. txs.u.sen (oust [u.nin 1] txs.u.sen)
|
|
|
|
?~ txs.u.sen
|
2021-06-01 17:18:32 +03:00
|
|
|
~? lverb [dap.bowl %done-with-nonce [get-address nonce]]
|
|
|
|
(~(del by sending) [get-address nonce])
|
|
|
|
(~(put by sending) [get-address nonce] u.sen)
|
2021-05-13 18:21:35 +03:00
|
|
|
:: update the finding map with the new status
|
|
|
|
::
|
|
|
|
=. finding
|
|
|
|
%+ ~(put by finding) keccak
|
|
|
|
?~ err.diff %confirmed
|
|
|
|
:: if we kept the forced flag around for longer, we could notify of
|
|
|
|
:: unexpected tx failures here. would that be useful? probably not?
|
|
|
|
:: ~? !forced [dap.bowl %aggregated-tx-failed-anyway err.diff]
|
|
|
|
%failed
|
2021-06-21 12:27:36 +03:00
|
|
|
::
|
2021-08-22 19:23:30 +03:00
|
|
|
=^ updates history
|
2021-08-27 17:05:59 +03:00
|
|
|
=/ =roller-tx [ship %sending keccak time l2-tx]
|
2021-08-22 19:23:30 +03:00
|
|
|
=. history
|
|
|
|
(~(del ju history) address roller-tx)
|
|
|
|
=. status.roller-tx
|
|
|
|
?~(err.diff %confirmed %failed)
|
|
|
|
:- [%tx address roller-tx]~
|
|
|
|
(~(put ju history) [address roller-tx])
|
|
|
|
::
|
2021-07-08 17:45:27 +03:00
|
|
|
:_ state(derive-p ?:(derive-p | derive-p))
|
2021-08-22 19:23:30 +03:00
|
|
|
%+ weld (emit updates)
|
2021-07-08 17:45:27 +03:00
|
|
|
?. derive-p ~
|
2021-06-11 13:27:05 +03:00
|
|
|
:: derive predicted state in 5m.
|
2021-06-01 14:56:56 +03:00
|
|
|
::
|
2021-06-11 13:27:05 +03:00
|
|
|
[(wait:b:sys /predict (add ~m5 now.bowl))]~
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
|
|
|
--
|