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
|
|
|
::
|
|
|
|
|%
|
2021-11-06 12:27:00 +03:00
|
|
|
+$ app-state
|
|
|
|
$: %1
|
2021-05-13 18:21:35 +03:00
|
|
|
:: pending: the next l2 txs to be sent
|
2021-10-11 18:16:17 +03:00
|
|
|
:: sending: l2 txs awaiting l2 confirmation, ordered by nonce
|
2021-10-30 14:12:09 +03:00
|
|
|
:: finding: sig+raw-tx hash reverse lookup for txs in sending map
|
|
|
|
:: history: status of l2 txs by ethereum address, timestamp sorted
|
2021-11-06 12:27:00 +03:00
|
|
|
:: ship-quota: number of txs submited per ship in the current slice
|
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
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
|
|
|
pending=(list pend-tx)
|
2021-10-11 18:16:17 +03:00
|
|
|
sending=(tree [l1-tx-pointer send-tx])
|
2021-10-30 14:12:09 +03:00
|
|
|
finding=(map keccak ?(%confirmed %failed [=time l1-tx-pointer]))
|
2021-10-16 13:47:39 +03:00
|
|
|
history=(map address:ethereum (tree hist-tx))
|
2021-11-06 12:27:00 +03:00
|
|
|
ship-quota=(map ship @ud)
|
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
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
|
|
|
:: pk: private key to send the roll
|
2021-11-06 12:27:00 +03:00
|
|
|
:: quota: max numbers of transactions per unit of time (slice)
|
|
|
|
:: slice: unit of time where txs are allowed to be added to pending
|
|
|
|
:: derive: deferred derivation of predicted/ownership state
|
2021-05-13 18:21:35 +03:00
|
|
|
:: 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-11-06 12:27:00 +03:00
|
|
|
:: resend-time: time to resend a batch with higher gas prie
|
|
|
|
:: update-rate: frequency to update the roller's predicted state
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
|
|
|
pk=@
|
2021-11-06 12:27:00 +03:00
|
|
|
slice=@dr
|
|
|
|
quota=@ud
|
|
|
|
derive=?
|
2021-05-13 18:21:35 +03:00
|
|
|
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-11-06 12:27:00 +03:00
|
|
|
resend-time=@dr
|
|
|
|
update-rate=@dr
|
2021-05-13 18:21:35 +03:00
|
|
|
==
|
2021-10-31 17:14:15 +03:00
|
|
|
:: orp: ordered points in naive state by parent ship
|
|
|
|
::
|
|
|
|
++ orp ((on ship point:naive) por:naive)
|
|
|
|
:: ors: ordered sending map by (increasing) L1 nonce
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
2021-10-31 16:02:33 +03:00
|
|
|
++ ors ((on l1-tx-pointer send-tx) nonce-order:dice)
|
2021-10-31 17:14:15 +03:00
|
|
|
:: orh: ordered tx history by (decreasing) timestamp
|
|
|
|
::
|
2021-10-31 16:02:33 +03:00
|
|
|
++ orh ((on time roll-tx) gth)
|
|
|
|
+$ net ?(%mainnet %ropsten %local)
|
2021-08-04 16:53:57 +03:00
|
|
|
::
|
2021-06-03 10:11:33 +03:00
|
|
|
+$ config
|
|
|
|
$% [%frequency frequency=@dr]
|
2021-05-13 18:21:35 +03:00
|
|
|
[%setkey pk=@]
|
2021-09-20 08:24:10 +03:00
|
|
|
[%endpoint endpoint=@t =net]
|
2021-11-06 12:27:00 +03:00
|
|
|
[%resend-time time=@dr]
|
|
|
|
[%update-rate rate=@dr]
|
|
|
|
[%slice slice=@dr]
|
|
|
|
[%quota quota=@ud]
|
|
|
|
[%wipe-nep ~]
|
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
|
|
|
|
::
|
|
|
|
++ lverb &
|
|
|
|
--
|
|
|
|
::
|
2021-11-06 12:27:00 +03:00
|
|
|
=| app-state
|
2021-05-17 18:48:49 +03:00
|
|
|
=* 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)
|
2021-11-06 12:27:00 +03:00
|
|
|
=: frequency ~h1
|
|
|
|
quota 7
|
|
|
|
slice ~d7
|
|
|
|
resend-time ~m5
|
|
|
|
update-rate ~m1
|
|
|
|
contract naive:local-contracts:azimuth
|
|
|
|
chain-id chain-id:local-contracts:azimuth
|
|
|
|
==
|
|
|
|
=^ card next-batch set-roller:timer
|
2021-05-23 16:49:55 +03:00
|
|
|
:_ this
|
2021-06-09 14:05:17 +03:00
|
|
|
:~ card
|
2021-11-06 12:27:00 +03:00
|
|
|
(set-quota:timer slice)
|
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)
|
2021-11-06 12:27:00 +03:00
|
|
|
=| ship-quota=(map ship @ud)
|
|
|
|
=| cards=(list card)
|
|
|
|
=/ slice=@dr ~d7
|
|
|
|
=/ quota=@ud 7
|
|
|
|
=/ resend-time=@dr ~m5
|
|
|
|
=/ update-rate=@dr ~m1
|
|
|
|
|^
|
|
|
|
=+ !<(old-state=app-states old)
|
|
|
|
=? cards ?=(%0 -.old-state)
|
|
|
|
[(set-quota:timer slice)]~
|
|
|
|
=? old-state ?=(%0 -.old-state)
|
|
|
|
^- app-state
|
|
|
|
=, old-state
|
|
|
|
:* %1
|
|
|
|
pending sending finding history
|
|
|
|
ship-quota next-nonce next-batch
|
|
|
|
pre own pk slice quota derive
|
|
|
|
frequency endpoint contract chain-id
|
|
|
|
resend-time update-rate
|
|
|
|
==
|
|
|
|
?> ?=(%1 -.old-state)
|
|
|
|
[cards this(state old-state)]
|
|
|
|
::
|
|
|
|
++ app-states $%(state-0 app-state)
|
|
|
|
++ state-0
|
|
|
|
$: %0
|
|
|
|
pending=(list pend-tx)
|
|
|
|
sending=(tree [l1-tx-pointer send-tx])
|
|
|
|
finding=(map keccak ?(%confirmed %failed [=time l1-tx-pointer]))
|
|
|
|
history=(map address:ethereum (tree hist-tx))
|
|
|
|
next-nonce=(unit @ud)
|
|
|
|
next-batch=time
|
|
|
|
pre=^state:naive
|
|
|
|
own=owners
|
|
|
|
derive=?
|
|
|
|
pk=@
|
|
|
|
frequency=@dr
|
|
|
|
endpoint=(unit @t)
|
|
|
|
contract=@ux
|
|
|
|
chain-id=@
|
|
|
|
==
|
|
|
|
--
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
|
|
|
++ 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)
|
2021-10-16 08:26:57 +03:00
|
|
|
:: /x/tx/[0xke.ccak]/[@ud]status -> %noun tx-status
|
2021-10-16 13:47:39 +03:00
|
|
|
:: /x/history/[0xadd.ress] -> %noun (list hist-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-10-14 16:42:06 +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-10-16 08:26:57 +03:00
|
|
|
:: /x/owned/[0xadd.ress] -> %noun (list ship)
|
|
|
|
:: /x/transfers/[0xadd.ress] -> %noun (list ship)
|
|
|
|
:: /x/manager/[0xadd.ress] -> %noun (list ship)
|
|
|
|
:: /x/voting/[0xadd.ress] -> %noun (list ship)
|
|
|
|
:: /x/spawning/[0xadd.ress] -> %noun (list ship)
|
2021-09-05 13:36:19 +03:00
|
|
|
:: /x/predicted -> %noun state:naive
|
2021-11-06 12:27:00 +03:00
|
|
|
:: /x/quota -> %atom @ud
|
|
|
|
:: /x/slice -> %atom @dr
|
|
|
|
:: /x/over-quota/[~ship] -> %atom ?
|
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-10-16 08:26:57 +03:00
|
|
|
[%x %pending ~] ``noun+!>(pending)
|
|
|
|
[%x %pending @ ~] (pending-by i.t.t.path)
|
2021-10-30 14:12:09 +03:00
|
|
|
[%x %tx @ %status ~] (status i.t.t.path)
|
2021-10-16 08:26:57 +03:00
|
|
|
[%x %pending-tx @ ~] (transaction i.t.t.path)
|
|
|
|
[%x %history @ ~] (history i.t.t.path)
|
|
|
|
[%x %nonce @ @ ~] (nonce i.t.t.path i.t.t.t.path)
|
|
|
|
[%x %spawned @ ~] (spawned i.t.t.path)
|
|
|
|
[%x %unspawned @ ~] (unspawned i.t.t.path)
|
|
|
|
[%x %next-batch ~] ``atom+!>(next-batch)
|
|
|
|
[%x %point @ ~] (point i.t.t.path)
|
|
|
|
[%x %ships @ ~] (ships i.t.t.path)
|
|
|
|
[%x %config ~] config
|
|
|
|
[%x %chain-id ~] ``atom+!>(chain-id)
|
|
|
|
[%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)
|
|
|
|
[%x %predicted ~] ``noun+!>(pre)
|
2021-11-06 12:27:00 +03:00
|
|
|
[%x %quota ~] ``atom+!>(quota)
|
|
|
|
[%x %slice ~] ``atom+!>(slice)
|
|
|
|
[%x %over-quota @ ~] (over-quota 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-09-20 09:31:15 +03:00
|
|
|
:: TODO: use this instead? =(u.wer address)
|
|
|
|
::
|
|
|
|
?~ addr=(get-l1-address tx.raw-tx pre) |
|
|
|
|
=(u.wer u.addr)
|
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-10-16 08:26:57 +03:00
|
|
|
++ status
|
2021-10-30 14:12:09 +03:00
|
|
|
|= wat=@t
|
|
|
|
?~ keccak=(slaw %ux wat)
|
2021-10-16 08:26:57 +03:00
|
|
|
[~ ~]
|
|
|
|
:+ ~ ~
|
|
|
|
:- %noun
|
|
|
|
!> ^- tx-status
|
2021-10-30 14:12:09 +03:00
|
|
|
?^ status=(~(get by finding) u.keccak)
|
2021-10-16 08:26:57 +03:00
|
|
|
?@ u.status [u.status ~]
|
2021-10-30 14:12:09 +03:00
|
|
|
[%sending `+.u.status]
|
2021-10-16 08:26:57 +03:00
|
|
|
:: TODO: potentially slow!
|
|
|
|
=; known=?
|
|
|
|
[?:(known %pending %unknown) ~]
|
|
|
|
%+ lien pending
|
|
|
|
|= pend-tx
|
|
|
|
=(u.keccak (hash-raw-tx:lib raw-tx))
|
2021-06-16 18:03:21 +03:00
|
|
|
::
|
2021-09-07 13:59:36 +03:00
|
|
|
++ transaction
|
|
|
|
|= wat=@t
|
|
|
|
?~ keccak=(slaw %ux wat)
|
|
|
|
[~ ~]
|
|
|
|
:+ ~ ~
|
|
|
|
:- %noun
|
|
|
|
!> ^- (unit pend-tx)
|
|
|
|
:: TODO: potentially slow!
|
|
|
|
|-
|
|
|
|
?~ pending ~
|
|
|
|
=* tx i.pending
|
|
|
|
?: =(u.keccak (hash-tx:lib raw.raw-tx.tx))
|
|
|
|
`tx
|
|
|
|
$(pending t.pending)
|
|
|
|
::
|
2021-06-16 18:03:21 +03:00
|
|
|
++ history
|
|
|
|
|= wat=@t
|
|
|
|
:+ ~ ~
|
|
|
|
:- %noun
|
2021-10-16 13:47:39 +03:00
|
|
|
!> ^- (list hist-tx)
|
2021-06-16 18:03:21 +03:00
|
|
|
?~ addr=(slaw %ux wat) ~
|
2021-10-16 13:47:39 +03:00
|
|
|
?~ hist=(~(get by ^history) u.addr) ~
|
|
|
|
(tap:orh u.hist)
|
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 @)
|
2021-10-31 17:14:15 +03:00
|
|
|
?~ point=(get:orp points.pre u.who)
|
2021-06-14 15:18:57 +03:00
|
|
|
~
|
2021-09-29 15:38:20 +03:00
|
|
|
=/ nonce=@
|
|
|
|
=< nonce
|
|
|
|
(proxy-from-point:naive proxy u.point)
|
|
|
|
%- some
|
|
|
|
%+ roll pending
|
|
|
|
|= [pend-tx nonce=_nonce]
|
|
|
|
?:(=([u.who proxy] from.tx.raw-tx) +(nonce) nonce)
|
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)
|
|
|
|
:: range exclusive [star first-moon-last-planet]
|
|
|
|
::
|
2021-10-31 17:14:15 +03:00
|
|
|
%- tap:orp
|
|
|
|
(lot:orp points.pre [`u.star `(cat 3 u.star 0x1.ffff)])
|
2021-09-01 12:01:39 +03:00
|
|
|
::
|
|
|
|
++ unspawned
|
|
|
|
|= wat=@t
|
|
|
|
:+ ~ ~
|
|
|
|
:- %noun
|
|
|
|
!> ^- (list @p)
|
|
|
|
?~ star=(slaw %p wat) ~
|
|
|
|
=/ spawned=(set @p)
|
|
|
|
=; points
|
|
|
|
(~(gas in *(set @p)) (turn points head))
|
2021-10-31 17:14:15 +03:00
|
|
|
%- tap:orp
|
|
|
|
(lot:orp points.pre [`u.star `(cat 3 u.star 0x1.ffff)])
|
2021-09-01 12:01:39 +03:00
|
|
|
=/ 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))
|
2021-10-31 17:14:15 +03:00
|
|
|
``noun+!>((get:orp 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
|
2021-11-04 11:54:25 +03:00
|
|
|
update-rate
|
2021-06-29 08:45:44 +03:00
|
|
|
contract
|
|
|
|
chain-id
|
2021-11-06 12:27:00 +03:00
|
|
|
slice
|
|
|
|
quota
|
2021-06-29 08:45:44 +03:00
|
|
|
==
|
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-11-06 12:27:00 +03:00
|
|
|
::
|
|
|
|
++ over-quota
|
|
|
|
|= wat=@t
|
|
|
|
?~ who=(slaw %p wat) [~ ~]
|
|
|
|
=/ [exceeded=? *] (quota-exceeded u.who)
|
|
|
|
``atom+!>(exceeded)
|
|
|
|
::
|
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-11-06 12:27:00 +03:00
|
|
|
[%quota-timer ~]
|
|
|
|
?+ +<.sign-arvo (on-arvo:def wire sign-arvo)
|
|
|
|
%wake =^(cards state on-quota-timer:do [cards this])
|
|
|
|
==
|
2021-06-11 13:27:05 +03:00
|
|
|
::
|
|
|
|
[%predict ~]
|
|
|
|
?+ +<.sign-arvo (on-arvo:def wire sign-arvo)
|
|
|
|
%wake
|
2021-10-03 16:09:11 +03:00
|
|
|
=. own.state canonical-owners:do
|
2021-08-22 19:23:30 +03:00
|
|
|
=^ effects state
|
|
|
|
(predicted-state canonical-state):do
|
2021-10-03 16:09:11 +03:00
|
|
|
[(emit effects) this(derive &)]
|
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
|
|
|
=/ 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
|
2021-10-31 17:14:15 +03:00
|
|
|
[ship (need (get:orp points.pre ship))]
|
2021-08-22 19:23:30 +03:00
|
|
|
::
|
|
|
|
++ give-txs
|
|
|
|
|= wat=@t
|
|
|
|
^- cage
|
|
|
|
:- %txs
|
2021-10-16 13:47:39 +03:00
|
|
|
!> ^- (list hist-tx)
|
2021-08-22 19:23:30 +03:00
|
|
|
?~ addr=(slaw %ux wat) ~
|
2021-10-16 13:47:39 +03:00
|
|
|
?~ hist=(~(get by history) u.addr) ~
|
|
|
|
(tap:orh u.hist)
|
2021-08-22 19:23:30 +03:00
|
|
|
--
|
|
|
|
::
|
2021-05-13 18:21:35 +03:00
|
|
|
++ on-leave on-leave:def
|
2021-10-30 14:12:09 +03:00
|
|
|
::
|
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-10-11 18:16:17 +03:00
|
|
|
[%send @ @ *] (send-batch i.t.wire i.t.t.wire sign)
|
|
|
|
[%azimuth-events ~] (azimuth-event sign)
|
|
|
|
[%nonce ~] (nonce sign)
|
|
|
|
[%refresh-nonce @ ~] (refresh i.t.wire 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-10-02 09:44:37 +03:00
|
|
|
(on-batch-result:do address nonce %.n^[%error 'thread failed'])
|
2021-05-23 16:49:55 +03:00
|
|
|
[cards this]
|
|
|
|
::
|
|
|
|
%thread-done
|
2021-10-02 09:44:37 +03:00
|
|
|
=+ !<(result=(each @ud [term @t]) q.cage.sign)
|
2021-05-23 16:49:55 +03:00
|
|
|
=^ 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-10-31 17:14:15 +03:00
|
|
|
=^ nas own.state
|
|
|
|
!<([^state:naive owners] 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-10-02 09:44:37 +03:00
|
|
|
::
|
|
|
|
++ refresh
|
2021-10-11 18:16:17 +03:00
|
|
|
|= [nonce=@t =sign:agent:gall]
|
2021-10-02 09:44:37 +03:00
|
|
|
^- (quip card _this)
|
2021-10-16 13:47:39 +03:00
|
|
|
=/ failed-nonce=@ud (rash nonce dem)
|
2021-10-02 09:44:37 +03:00
|
|
|
?- -.sign
|
|
|
|
%poke-ack
|
|
|
|
?~ p.sign
|
|
|
|
%- (slog leaf+"Refresh 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-10-16 13:47:39 +03:00
|
|
|
=^ cards state
|
|
|
|
(on-out-of-sync:do nonce failed-nonce)
|
|
|
|
[cards this]
|
2021-10-02 09:44:37 +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)
|
2021-10-30 14:12:09 +03:00
|
|
|
=/ =beak byk.bowl(r da+now.bowl)
|
2021-05-13 18:21:35 +03:00
|
|
|
=/ tid=@ta (rap 3 thread '--' (scot %uv eny.bowl) ~)
|
2021-10-30 14:12:09 +03:00
|
|
|
=/ args [~ `tid beak 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
|
2021-10-11 18:16:17 +03:00
|
|
|
[%give %fact ~[/txs/[address]] tx+!>(roll-tx.up)]~
|
2021-08-27 16:59:10 +03:00
|
|
|
::
|
|
|
|
%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
|
2021-09-27 17:29:12 +03:00
|
|
|
?~ batch=(parse-raw-tx:naive 0 q.raw.part-tx)
|
2021-10-02 09:44:37 +03:00
|
|
|
~? lverb [dap.bowl %parse-failed]
|
2021-05-23 15:59:29 +03:00
|
|
|
:: 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)
|
2021-10-31 16:02:33 +03:00
|
|
|
=: pre nas
|
|
|
|
own canonical-owners
|
2021-10-14 16:42:06 +03:00
|
|
|
==
|
2021-06-05 15:24:37 +03:00
|
|
|
|^
|
2021-10-11 18:16:17 +03:00
|
|
|
=^ [nes=_sending updates-1=(list update)] state
|
|
|
|
apply-sending
|
|
|
|
=^ [nep=_pending updates-2=(list update)] state
|
|
|
|
apply-pending
|
|
|
|
:- (welp updates-1 updates-2)
|
2021-08-04 16:53:57 +03:00
|
|
|
state(sending nes, pending nep)
|
|
|
|
::
|
|
|
|
++ apply-pending
|
2021-10-13 13:56:47 +03:00
|
|
|
(apply-txs pending %pending next-nonce.state)
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
2021-06-05 15:24:37 +03:00
|
|
|
++ apply-sending
|
2021-08-22 19:23:30 +03:00
|
|
|
=| ups=(list update)
|
2021-10-11 18:16:17 +03:00
|
|
|
=/ valid=_sending ~
|
2021-10-16 13:47:39 +03:00
|
|
|
=+ sorted=(tap:ors sending)
|
2021-08-22 19:23:30 +03:00
|
|
|
|- ^+ [[valid ups] state]
|
2021-10-02 09:44:37 +03:00
|
|
|
?~ sorted [[valid ups] state]
|
2021-06-05 15:24:37 +03:00
|
|
|
::
|
2021-10-11 18:16:17 +03:00
|
|
|
=* key key.i.sorted
|
|
|
|
=* val val.i.sorted
|
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
|
2021-10-13 13:56:47 +03:00
|
|
|
(apply-txs txs %sending `nonce.key)
|
2021-10-11 18:16:17 +03:00
|
|
|
:: we only hear updates for this nonce if it has been sent
|
|
|
|
::
|
|
|
|
=. valid ::=? valid sent.val
|
2021-10-16 13:47:39 +03:00
|
|
|
%^ put:ors valid
|
2021-10-11 18:16:17 +03:00
|
|
|
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-10-02 09:44:37 +03:00
|
|
|
$(sorted t.sorted, ups (welp ups nups))
|
2021-06-05 15:24:37 +03:00
|
|
|
::
|
2021-08-04 16:53:57 +03:00
|
|
|
++ apply-txs
|
2021-10-13 13:56:47 +03:00
|
|
|
|= [txs=(list pend-tx) type=?(%pending %sending) nonce=(unit @ud)]
|
2021-06-05 15:24:37 +03:00
|
|
|
=/ valid=_txs ~
|
2021-08-22 19:23:30 +03:00
|
|
|
=| ups=(list update)
|
|
|
|
|- ^+ [[valid ups] state]
|
2021-10-31 16:02:33 +03:00
|
|
|
?~ txs [[(flop valid) ups] state]
|
2021-06-24 17:56:32 +03:00
|
|
|
::
|
2021-10-31 16:02:33 +03:00
|
|
|
=* tx i.txs
|
|
|
|
=* raw-tx raw-tx.i.txs
|
|
|
|
=* ship ship.from.tx.raw-tx.i.txs
|
|
|
|
=/ =keccak (hash-raw-tx:lib raw-tx)
|
2021-07-22 17:46:23 +03:00
|
|
|
=/ sign-address=(unit @ux)
|
2021-10-31 16:02:33 +03:00
|
|
|
(extract-address:lib raw-tx pre chain-id)
|
2021-08-22 19:23:30 +03:00
|
|
|
=^ [gud=? nups=_ups] state
|
2021-10-31 16:02:33 +03:00
|
|
|
(try-apply pre force.tx raw-tx)
|
2021-07-22 17:46:23 +03:00
|
|
|
:: 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-10-31 16:02:33 +03:00
|
|
|
=/ =roll-tx [ship type keccak (l2-tx +<.tx.raw-tx)]
|
2021-08-22 19:23:30 +03:00
|
|
|
=? nups !gud
|
|
|
|
%+ snoc nups
|
2021-10-11 18:16:17 +03:00
|
|
|
[%tx address.tx roll-tx(status %failed)]
|
2021-10-31 16:02:33 +03:00
|
|
|
=? valid gud [tx valid]
|
|
|
|
=? history !gud
|
2021-11-01 12:09:11 +03:00
|
|
|
=/ =time
|
|
|
|
?: ?=(%pending type) time.tx
|
|
|
|
=+ wer=(~(got by finding) keccak)
|
|
|
|
?>(?=(^ wer) time.wer)
|
2021-10-31 16:02:33 +03:00
|
|
|
=+ txs=(~(got by history) address.tx)
|
2021-11-01 12:09:11 +03:00
|
|
|
=. txs +:(del:orh txs time)
|
2021-10-31 16:02:33 +03:00
|
|
|
%+ ~(put by history) address.tx
|
|
|
|
%+ put:orh txs
|
2021-11-01 12:09:11 +03:00
|
|
|
[time roll-tx(status %failed)]
|
|
|
|
=? finding !gud (~(put by finding) keccak %failed)
|
2021-10-31 16:02:33 +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)
|
2021-10-31 17:14:15 +03:00
|
|
|
?~ point=(get:orp points.nas ship.from.tx) ~
|
2021-07-08 17:45:27 +03:00
|
|
|
=< `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
|
2021-11-06 12:27:00 +03:00
|
|
|
%frequency [~ state(frequency frequency.config)]
|
|
|
|
%resend-time [~ state(resend-time time.config)]
|
|
|
|
%update-rate [~ state(update-rate rate.config)]
|
|
|
|
%slice [~ state(slice slice.config)]
|
|
|
|
%quota [~ state(quota quota.config)]
|
2021-05-29 15:43:13 +03:00
|
|
|
::
|
2021-10-02 10:12:58 +03:00
|
|
|
%endpoint
|
2021-05-29 15:43:13 +03:00
|
|
|
:- ~
|
|
|
|
=/ [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
|
|
|
|
==
|
2021-10-02 10:12:58 +03:00
|
|
|
%_ state
|
|
|
|
contract contract
|
|
|
|
chain-id chain-id
|
|
|
|
endpoint `endpoint.config
|
|
|
|
==
|
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
|
2021-10-02 09:44:37 +03:00
|
|
|
[(get-nonce q.u.pk /nonce) 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)
|
2021-10-30 14:12:09 +03:00
|
|
|
?^ status=(~(get by finding) keccak)
|
|
|
|
~? lverb [dap.bowl %tx-not-pending status+u.status]
|
2021-06-21 12:27:36 +03:00
|
|
|
[~ 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-10-30 14:12:09 +03:00
|
|
|
=^ time pending
|
|
|
|
=| nep=(list pend-tx)
|
|
|
|
|- ^- [(unit time) _nep]
|
|
|
|
?~ pending [~ (flop nep)]
|
|
|
|
?: =(keccak (hash-raw-tx:lib raw-tx.i.pending))
|
|
|
|
[`time.i.pending (weld (flop nep) t.pending)]
|
|
|
|
$(pending t.pending, nep [i.pending nep])
|
|
|
|
?~ time
|
2021-10-31 16:02:33 +03:00
|
|
|
~? lverb [dap.bowl %weird-tx-not-pending]
|
2021-10-30 14:12:09 +03:00
|
|
|
[~ state]
|
2021-10-16 13:47:39 +03:00
|
|
|
:- ~
|
|
|
|
%_ state
|
|
|
|
history
|
2021-10-31 16:02:33 +03:00
|
|
|
=+ txs=(~(got by history) u.addr)
|
|
|
|
=. txs +:(del:orh txs u.time)
|
|
|
|
%+ ~(put by history) u.addr
|
|
|
|
%^ put:orh txs
|
|
|
|
u.time
|
|
|
|
[ship %cancelled keccak l2-tx]
|
2021-10-16 13:47:39 +03:00
|
|
|
==
|
2021-05-13 18:21:35 +03:00
|
|
|
:: +take-tx: accept submitted l2 tx into the :pending list
|
|
|
|
::
|
|
|
|
++ take-tx
|
2021-10-16 13:47:39 +03:00
|
|
|
|= =pend-tx
|
2021-06-11 13:27:05 +03:00
|
|
|
^- (quip card _state)
|
2021-11-06 12:27:00 +03:00
|
|
|
=* ship ship.from.tx.raw-tx.pend-tx
|
|
|
|
=/ [exceeded=? next-quota=@] (quota-exceeded ship)
|
|
|
|
?: exceeded [~ state]
|
|
|
|
=: pending (snoc pending pend-tx)
|
|
|
|
ship-quota (~(put by ship-quota) ship next-quota)
|
|
|
|
==
|
|
|
|
=^ cards history
|
|
|
|
(update-history [pend-tx]~ %pending)
|
2021-10-14 16:42:06 +03:00
|
|
|
:: toggle derivation
|
2021-06-11 13:27:05 +03:00
|
|
|
::
|
2021-10-03 16:09:11 +03:00
|
|
|
:_ state(derive ?:(derive | derive))
|
2021-10-31 16:02:33 +03:00
|
|
|
%+ weld (emit cards)
|
2021-10-03 16:09:11 +03:00
|
|
|
?. derive ~
|
2021-11-06 12:27:00 +03:00
|
|
|
:: update predicted state in 1m.
|
2021-06-11 13:27:05 +03:00
|
|
|
::
|
2021-11-04 11:54:25 +03:00
|
|
|
[(wait:b:sys /predict (add update-rate now.bowl))]~
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
2021-11-06 12:27:00 +03:00
|
|
|
++ timer
|
|
|
|
|%
|
|
|
|
:: +set-roller: %wait until next whole :frequency
|
|
|
|
::
|
|
|
|
++ set-roller
|
|
|
|
^- [=card =time]
|
|
|
|
=+ time=(mul +((div now.bowl frequency)) frequency)
|
|
|
|
[(wait:b:sys /timer time) time]
|
|
|
|
:: +set-roller: %wait until next whole :slice
|
|
|
|
::
|
|
|
|
++ set-quota
|
|
|
|
|= slice=@dr
|
|
|
|
^- card
|
|
|
|
=+ time=(mul +((div now.bowl slice)) slice)
|
|
|
|
(wait:b:sys /quota-timer 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)
|
2021-10-02 09:44:37 +03:00
|
|
|
~? lverb [dap.bowl %pending-empty] [~ state]
|
2021-06-09 16:37:37 +03:00
|
|
|
?~ next-nonce
|
2021-10-11 18:16:17 +03:00
|
|
|
~? lverb [dap.bowl %missing-roller-nonce] [~ state]
|
2021-10-14 16:42:06 +03:00
|
|
|
:: this guarantees that next-nonce is only incremented
|
2021-10-30 14:12:09 +03:00
|
|
|
:: when the thread that's sending the previous batch
|
2021-10-14 16:42:06 +03:00
|
|
|
:: has come back and confirms that it was sent to L1
|
2021-10-30 14:12:09 +03:00
|
|
|
::
|
2021-10-11 18:16:17 +03:00
|
|
|
?: out-of-sync
|
2021-10-30 14:12:09 +03:00
|
|
|
:: this would postpone sending the batch for a whole "frequency"
|
|
|
|
:: TODO: set up a timer to retry this in ~mX ?
|
2021-10-14 16:42:06 +03:00
|
|
|
::
|
2021-10-11 18:16:17 +03:00
|
|
|
~? lverb [dap.bowl %nonce-out-sync] [~ state]
|
2021-06-09 16:37:37 +03:00
|
|
|
=/ nonce=@ud u.next-nonce
|
2021-10-31 16:02:33 +03:00
|
|
|
=^ updates-2 history (update-history pending %sending)
|
2021-05-21 13:16:57 +03:00
|
|
|
=: pending ~
|
2021-10-03 16:09:11 +03:00
|
|
|
derive &
|
2021-10-14 16:42:06 +03:00
|
|
|
next-nonce `+(u.next-nonce)
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
|
|
|
sending
|
2021-10-16 13:47:39 +03:00
|
|
|
%^ put:ors sending
|
2021-06-01 17:18:32 +03:00
|
|
|
[get-address nonce]
|
2021-10-11 18:16:17 +03:00
|
|
|
[0 | (turn pending (cork tail (cork tail tail)))]
|
2021-06-01 14:56:56 +03:00
|
|
|
::
|
|
|
|
finding
|
2021-10-16 08:26:57 +03:00
|
|
|
%- ~(gas by finding)
|
|
|
|
%+ turn pending
|
|
|
|
|= pend-tx
|
2021-10-30 14:12:09 +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-11-06 12:27:00 +03:00
|
|
|
=^ card next-batch set-roller:timer
|
2021-06-09 14:05:17 +03:00
|
|
|
[[card cards] state]
|
2021-11-06 12:27:00 +03:00
|
|
|
:: +on-quota-timer: resets tx quota for all ships
|
|
|
|
::
|
|
|
|
++ on-quota-timer
|
|
|
|
^- (quip card _state)
|
|
|
|
:- [(set-quota:timer slice)]~
|
|
|
|
state(ship-quota *(map ship @ud))
|
2021-08-22 19:23:30 +03:00
|
|
|
::
|
|
|
|
++ update-history
|
2021-10-31 16:02:33 +03:00
|
|
|
|= [txs=(list pend-tx) =status]
|
2021-10-30 14:12:09 +03:00
|
|
|
^- [(list update) _history]
|
|
|
|
%+ roll txs
|
2021-10-31 16:02:33 +03:00
|
|
|
|= [pend-tx ups=(list update) sih=_history]
|
2021-10-11 18:16:17 +03:00
|
|
|
=/ =roll-tx
|
2021-08-22 19:23:30 +03:00
|
|
|
:* ship.from.tx.raw-tx
|
2021-10-16 13:47:39 +03:00
|
|
|
status
|
2021-08-22 19:23:30 +03:00
|
|
|
(hash-raw-tx:lib raw-tx)
|
|
|
|
(l2-tx +<.tx.raw-tx)
|
|
|
|
==
|
2021-10-31 16:02:33 +03:00
|
|
|
=/ txs=(tree hist-tx)
|
|
|
|
?~ txs=(~(get by sih) address) ~
|
|
|
|
u.txs
|
|
|
|
=? txs ?=(^ txs) +:(del:orh txs time)
|
|
|
|
:- (snoc ups tx+[address roll-tx])
|
2021-10-30 14:12:09 +03:00
|
|
|
%+ ~(put by sih) address
|
2021-10-31 16:02:33 +03:00
|
|
|
(put:orh txs [time roll-tx])
|
2021-05-29 15:40:13 +03:00
|
|
|
:: +get-nonce: retrieves the latest nonce
|
|
|
|
::
|
|
|
|
++ get-nonce
|
2021-10-02 09:44:37 +03:00
|
|
|
|= [pk=@ =wire]
|
2021-05-29 15:40:13 +03:00
|
|
|
^- (list card)
|
2021-10-02 09:44:37 +03:00
|
|
|
?~ endpoint ~?(lverb [dap.bowl %no-endpoint] ~)
|
|
|
|
(start-thread:spider wire [%roller-nonce !>([u.endpoint pk])])
|
2021-11-06 12:27:00 +03:00
|
|
|
::
|
|
|
|
++ quota-exceeded
|
|
|
|
|= =ship
|
|
|
|
^- [? @ud]
|
|
|
|
?~ quota=(~(get by ship-quota) ship)
|
|
|
|
[| 1]
|
|
|
|
[(gte u.quota quota.state) +(u.quota)]
|
2021-10-11 18:16:17 +03:00
|
|
|
:: +out-of-sync: checks if the previous nonce has been sent
|
|
|
|
::
|
|
|
|
++ out-of-sync
|
|
|
|
^- ?
|
2021-10-16 13:47:39 +03:00
|
|
|
?~ newest-batch=(ram:ors sending) |
|
2021-10-14 16:42:06 +03:00
|
|
|
!=(sent.val.u.newest-batch &)
|
2021-10-16 13:47:39 +03:00
|
|
|
:: +on-out-of-sync
|
|
|
|
::
|
|
|
|
++ on-out-of-sync
|
2021-10-30 14:12:09 +03:00
|
|
|
|= [nonce=@ud failed-nonce=@ud]
|
|
|
|
:: we only care about nonces >= than the one that failed
|
2021-10-16 13:47:39 +03:00
|
|
|
::
|
|
|
|
=/ failed-sending=(list [l1-tx-pointer send-tx])
|
|
|
|
%- tap:ors
|
|
|
|
:: (range exclusive)
|
|
|
|
::
|
|
|
|
(lot:ors sending [`[get-address (dec failed-nonce)] ~])
|
|
|
|
=/ confirmed-sending=_sending
|
|
|
|
(lot:ors sending [~ `[get-address failed-nonce]])
|
|
|
|
=/ [nes=_sending nif=_finding sih=_history]
|
2021-10-30 14:12:09 +03:00
|
|
|
%- tail
|
2021-10-16 13:47:39 +03:00
|
|
|
%+ roll failed-sending
|
|
|
|
|= $: [p=l1-tx-pointer q=send-tx]
|
|
|
|
new-nonce=_nonce
|
|
|
|
sending=_confirmed-sending
|
|
|
|
finding=_finding
|
|
|
|
history=_history
|
|
|
|
==
|
|
|
|
|^
|
|
|
|
=* nonce nonce.p
|
|
|
|
=* txs txs.q
|
|
|
|
:: TODO: this shouldn't be needed
|
|
|
|
?: (lth nonce.p failed-nonce)
|
|
|
|
~& ["weird case" nonce+nonce.p]
|
|
|
|
[new-nonce sending finding history]
|
2021-10-30 14:12:09 +03:00
|
|
|
:+ +(new-nonce)
|
2021-10-16 13:47:39 +03:00
|
|
|
update-sending
|
|
|
|
process-l2-txs
|
|
|
|
::
|
|
|
|
++ update-sending
|
|
|
|
(put:ors sending [p(nonce new-nonce) q(sent %.n)])
|
|
|
|
::
|
|
|
|
++ process-l2-txs
|
|
|
|
%+ roll txs.q
|
|
|
|
|= [=raw-tx:naive nif=_finding sih=_history]
|
2021-10-30 14:12:09 +03:00
|
|
|
=/ =keccak (hash-raw-tx:lib raw-tx)
|
|
|
|
|^
|
|
|
|
?~ val=(~(get by nif) keccak)
|
|
|
|
[nif sih]
|
|
|
|
?. ?=(^ u.val) [nif sih]
|
|
|
|
:- (update-finding u.val)
|
2021-10-31 16:02:33 +03:00
|
|
|
(update-history time.u.val address.u.val)
|
2021-10-16 13:47:39 +03:00
|
|
|
::
|
|
|
|
++ update-finding
|
2021-10-30 14:12:09 +03:00
|
|
|
|= val=[time l1-tx-pointer]
|
2021-10-16 13:47:39 +03:00
|
|
|
^+ nif
|
2021-10-30 14:12:09 +03:00
|
|
|
(~(put by nif) keccak val(nonce.+ new-nonce))
|
2021-10-16 13:47:39 +03:00
|
|
|
::
|
|
|
|
++ update-history
|
2021-10-31 16:02:33 +03:00
|
|
|
|= [=time =address:ethereum]
|
2021-10-16 13:47:39 +03:00
|
|
|
^+ sih
|
|
|
|
=* ship ship.from.tx.raw-tx
|
2021-10-31 16:02:33 +03:00
|
|
|
=/ l2-tx (l2-tx +<.tx.raw-tx)
|
|
|
|
=/ =roll-tx [ship %sending keccak l2-tx]
|
|
|
|
=+ txs=(~(got by sih) address)
|
|
|
|
=. txs +:(del:orh txs time)
|
2021-10-16 13:47:39 +03:00
|
|
|
%+ ~(put by sih) address
|
2021-10-31 16:02:33 +03:00
|
|
|
(put:orh txs [time roll-tx])
|
2021-10-30 14:12:09 +03:00
|
|
|
--
|
|
|
|
--
|
2021-10-31 16:02:33 +03:00
|
|
|
=: sending nes
|
|
|
|
finding nif
|
|
|
|
history sih
|
|
|
|
next-nonce `+(nonce)
|
|
|
|
==
|
|
|
|
[(send-roll get-address nonce) state]
|
2021-05-13 18:21:35 +03:00
|
|
|
:: +send-roll: start thread to submit roll from :sending to l1
|
|
|
|
::
|
|
|
|
++ send-roll
|
2021-10-02 09:44:37 +03:00
|
|
|
|= [=address:ethereum =nonce:naive]
|
2021-05-13 18:21:35 +03:00
|
|
|
^- (list card)
|
|
|
|
:: if this nonce isn't in the sending queue anymore, it's done
|
|
|
|
::
|
2021-10-16 13:47:39 +03:00
|
|
|
?. (has:ors sending [address nonce])
|
2021-06-01 17:18:32 +03:00
|
|
|
~? lverb [dap.bowl %done-sending [address nonce]]
|
2021-05-13 18:21:35 +03:00
|
|
|
~
|
2021-10-02 09:44:37 +03:00
|
|
|
?~ endpoint
|
|
|
|
~? lverb [dap.bowl %no-endpoint]
|
|
|
|
~
|
2021-10-31 16:02:33 +03:00
|
|
|
:: start the thread, passing in the l2 txs to use
|
|
|
|
:: TODO should go ahead and set resend timer in case thread hangs, or nah?
|
|
|
|
::
|
2021-05-13 18:21:35 +03:00
|
|
|
%+ 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-10-11 18:16:17 +03:00
|
|
|
::
|
|
|
|
=< [next-gas-price txs]
|
2021-10-16 13:47:39 +03:00
|
|
|
(got:ors 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-10-02 09:44:37 +03:00
|
|
|
|= [=address:ethereum nonce=@ud result=(each @ud [term @t])]
|
2021-05-13 18:21:35 +03:00
|
|
|
^- (quip card _state)
|
2021-10-02 09:44:37 +03:00
|
|
|
:: print error if there was one
|
|
|
|
::
|
|
|
|
~? ?=(%| -.result) [dap.bowl %send-error +.p.result]
|
2021-10-16 13:47:39 +03:00
|
|
|
=/ =send-tx (got:ors sending [address nonce])
|
2021-05-13 18:21:35 +03:00
|
|
|
=? sending ?=(%& -.result)
|
2021-10-16 13:47:39 +03:00
|
|
|
%^ put:ors sending
|
2021-10-11 18:16:17 +03:00
|
|
|
[address nonce]
|
2021-10-14 16:42:06 +03:00
|
|
|
:: update gas price for this tx in state
|
|
|
|
:: and set it as sent to L1
|
|
|
|
::
|
2021-10-13 13:56:47 +03:00
|
|
|
send-tx(next-gas-price p.result, sent &)
|
2021-10-14 16:42:06 +03:00
|
|
|
:_ state
|
2021-10-02 09:44:37 +03:00
|
|
|
?: ?| ?=(%& -.result)
|
2021-10-11 18:16:17 +03:00
|
|
|
:: a general error shouldn't innitiate
|
|
|
|
:: the out-of-sync nonce thread
|
|
|
|
::
|
2021-10-02 09:44:37 +03:00
|
|
|
?=([%| %error *] result)
|
2021-10-11 18:16:17 +03:00
|
|
|
:: this accounts for a resend with higher gas
|
|
|
|
:: for a previous nonce, so we shouldn't start
|
|
|
|
:: the out-of-sync nonce thread
|
|
|
|
::
|
|
|
|
?& sent.send-tx
|
|
|
|
?=([%| %not-sent *] result)
|
|
|
|
== ==
|
2021-10-02 09:44:37 +03:00
|
|
|
:_ ~
|
|
|
|
:: resend the l1 tx in five minutes
|
|
|
|
::
|
|
|
|
%+ wait:b:sys
|
|
|
|
/resend/(scot %ux address)/(scot %ud nonce)
|
|
|
|
(add resend-time now.bowl)
|
2021-10-11 18:16:17 +03:00
|
|
|
:: TODO: this only accounts for the case where the nonce is out of sync,
|
2021-10-03 17:15:42 +03:00
|
|
|
:: reaching this because of lower funds needs to be addressed manually
|
2021-10-02 09:44:37 +03:00
|
|
|
::
|
2021-10-03 17:15:42 +03:00
|
|
|
?> ?=(%not-sent -.p.result)
|
2021-10-11 18:16:17 +03:00
|
|
|
(get-nonce pk.state /refresh-nonce/(scot %ud nonce))
|
2021-05-13 18:21:35 +03:00
|
|
|
:: +on-naive-diff: process l2 tx confirmations
|
|
|
|
::
|
|
|
|
++ on-naive-diff
|
|
|
|
|= =diff:naive
|
|
|
|
^- (quip card _state)
|
2021-10-03 16:09:11 +03:00
|
|
|
?. |(?=(%point -.diff) ?=(%tx -.diff))
|
2021-05-13 18:21:35 +03:00
|
|
|
[~ state]
|
2021-10-03 16:09:11 +03:00
|
|
|
=; [cards=(list card) =_state]
|
|
|
|
:_ state(derive ?:(derive | derive))
|
|
|
|
%+ weld cards
|
|
|
|
?. derive ~
|
2021-11-06 12:27:00 +03:00
|
|
|
:: update predicted/ownership state in 1m.
|
2021-10-03 16:09:11 +03:00
|
|
|
::
|
2021-11-04 11:54:25 +03:00
|
|
|
[(wait:b:sys /predict (add update-rate now.bowl))]~
|
2021-10-03 16:09:11 +03:00
|
|
|
::
|
|
|
|
?: ?=(%point -.diff) [~ state]
|
|
|
|
?> ?=(%tx -.diff)
|
2021-07-15 15:23:08 +03:00
|
|
|
=/ =keccak (hash-raw-tx:lib raw-tx.diff)
|
2021-10-30 14:12:09 +03:00
|
|
|
?~ wer=(~(get by finding) keccak)
|
2021-10-13 13:56:47 +03:00
|
|
|
:: tx not submitted by this roller
|
|
|
|
::
|
|
|
|
[~ state]
|
2021-10-16 08:26:57 +03:00
|
|
|
?@ 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-10-30 14:12:09 +03:00
|
|
|
=* nonce nonce.u.wer
|
2021-10-16 08:26:57 +03:00
|
|
|
=* address address.u.wer
|
2021-08-22 19:23:30 +03:00
|
|
|
=* ship ship.from.tx.raw-tx.diff
|
2021-10-16 08:26:57 +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-10-16 13:47:39 +03:00
|
|
|
?~ sen=(get:ors sending [get-address nonce])
|
2021-10-11 18:16:17 +03:00
|
|
|
~? lverb [dap.bowl %weird-double-remove nonce+nonce]
|
2021-05-13 18:21:35 +03:00
|
|
|
sending
|
|
|
|
?~ nin=(find [raw-tx.diff]~ txs.u.sen)
|
2021-10-11 18:16:17 +03:00
|
|
|
~? lverb [dap.bowl %weird-unknown nonce+nonce]
|
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]]
|
2021-10-11 18:16:17 +03:00
|
|
|
=^ * sending
|
2021-10-16 13:47:39 +03:00
|
|
|
(del:ors sending [get-address nonce])
|
2021-10-11 18:16:17 +03:00
|
|
|
sending
|
|
|
|
^+ sending
|
2021-10-16 13:47:39 +03:00
|
|
|
(put:ors sending [get-address nonce] u.sen)
|
2021-05-13 18:21:35 +03:00
|
|
|
:: update the finding map with the new status
|
|
|
|
::
|
|
|
|
=. finding
|
2021-10-30 14:12:09 +03:00
|
|
|
%+ ~(put by finding) keccak
|
2021-05-13 18:21:35 +03:00
|
|
|
?~ 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-10-31 16:02:33 +03:00
|
|
|
%+ update-history
|
2021-10-16 13:47:39 +03:00
|
|
|
[| address time raw-tx.diff]~
|
2021-10-31 16:02:33 +03:00
|
|
|
?~(err.diff %confirmed %failed)
|
2021-10-03 16:09:11 +03:00
|
|
|
[(emit updates) state]
|
2021-05-13 18:21:35 +03:00
|
|
|
::
|
|
|
|
--
|