mirror of
https://github.com/urbit/shrub.git
synced 2024-12-19 00:13:12 +03:00
aggregator: refactor +apply-effects in /lib/dice
This commit is contained in:
parent
38d207c797
commit
875561217f
@ -160,7 +160,7 @@
|
||||
%get-nonce `(nonce id +.params nonce:scry)
|
||||
%get-history `(history id +.params addr:history:scry)
|
||||
%get-roller-config `(get-config id +.params config:scry)
|
||||
%unsign-transaction `(unsign-transaction id +.params chain-id:scry)
|
||||
%hash-transaction `(hash-transaction id +.params chain-id:scry)
|
||||
==
|
||||
--
|
||||
::
|
||||
|
@ -171,10 +171,11 @@
|
||||
[%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 %next-batch ~] ``noun+!>(next-batch)
|
||||
[%x %next-batch ~] ``atom+!>(next-batch)
|
||||
[%x %point @ ~] (point i.t.t.path)
|
||||
[%x %points @ ~] (points i.t.t.path)
|
||||
[%x %config ~] config
|
||||
[%x %chain-id ~] ``atom+!>(chain-id)
|
||||
==
|
||||
::
|
||||
++ pending-by
|
||||
@ -570,31 +571,14 @@
|
||||
%. [address.tx roller-tx(status [%failed ~])]
|
||||
~(put ju (~(del ju history.state) address.tx roller-tx))
|
||||
$(txs t.txs, local (~(put in local) hash))
|
||||
:: TODO: replace with (refactored) /lib/dice
|
||||
::
|
||||
++ try-apply
|
||||
|= [nas=^state:naive force=? =raw-tx:naive]
|
||||
^- [success=? _state]
|
||||
=/ cache-nas nas
|
||||
=/ chain-t=@t (ud-to-ascii:naive chain-id)
|
||||
?. (verify-sig-and-nonce:naive verifier:lib chain-t nas raw-tx)
|
||||
~& [%verify-sig-and-nonce %failed]
|
||||
[force state]
|
||||
=^ * points.nas
|
||||
(increment-nonce:naive nas from.tx.raw-tx)
|
||||
?~ nex=(receive-tx:naive nas tx.raw-tx)
|
||||
:: TODO: confirm this works:
|
||||
:: before, we incremented nonce all the time,
|
||||
:: even if nex failed. now, only when =(& force)
|
||||
::
|
||||
[force state(pre ?:(force nas cache-nas))]
|
||||
=* predicted +.u.nex
|
||||
=* diffs -.u.nex
|
||||
:- &
|
||||
%_ state
|
||||
pre predicted
|
||||
own (update-ownership:dice diffs cache-nas predicted own.state)
|
||||
==
|
||||
^- [? _state]
|
||||
=/ [success=? predicted=_nas owners=_own]
|
||||
(apply-raw-tx:dice force raw-tx nas own chain-id)
|
||||
:- success
|
||||
state(pre predicted, own owners)
|
||||
--
|
||||
::
|
||||
++ get-l1-address
|
||||
|
@ -556,7 +556,7 @@
|
||||
~(params error:json-rpc id)
|
||||
[%result id (config:to-json roller-config)]
|
||||
::
|
||||
++ unsign-transaction
|
||||
++ hash-transaction
|
||||
|= [id=@t params=(map @t json) chain-id=@]
|
||||
^- response:rpc
|
||||
?. =((lent ~(tap by params)) 4)
|
||||
@ -574,5 +574,5 @@
|
||||
?~ tx ~(parse error:json-rpc id)
|
||||
:+ %result id
|
||||
%- l2-hash:to-json
|
||||
(unsign-tx:lib u.nonce chain-id (gen-tx-octs:lib u.tx))
|
||||
(unsigned-tx:lib u.nonce chain-id (gen-tx-octs:lib u.tx))
|
||||
--
|
||||
|
@ -11,24 +11,30 @@
|
||||
|= [=diff:naive nas=_nas own=_own]
|
||||
^+ [nas own]
|
||||
?. ?=([%tx *] diff) [nas own]
|
||||
=< [nas own]
|
||||
(apply-raw-tx | raw-tx.diff nas own chain-t)
|
||||
::
|
||||
++ apply-raw-tx
|
||||
|= [force=? =raw-tx:naive nas=^state:naive own=owners chain-t=@]
|
||||
^- [? nas=_nas own=_own]
|
||||
=+ cache-nas=nas
|
||||
=* raw-tx raw-tx.diff
|
||||
=/ chain-t=@t (ud-to-ascii:naive chain-t)
|
||||
?. (verify-sig-and-nonce:naive verifier chain-t nas raw-tx)
|
||||
[nas own]
|
||||
[force nas own]
|
||||
=^ * points.nas
|
||||
(increment-nonce:naive nas from.tx.raw-tx)
|
||||
?~ nex=(receive-tx:naive nas tx.raw-tx)
|
||||
[cache-nas own]
|
||||
=* up-nas +.u.nex
|
||||
=* diffs -.u.nex
|
||||
:- up-nas
|
||||
(update-ownership diffs cache-nas up-nas own)
|
||||
[force ?:(force nas cache-nas) own]
|
||||
=* new-nas +.u.nex
|
||||
=* effects -.u.nex
|
||||
:+ &
|
||||
new-nas
|
||||
(update-ownership effects cache-nas new-nas own)
|
||||
::
|
||||
++ update-ownership
|
||||
|= $: =effects:naive
|
||||
cache-nas=^state:naive
|
||||
up-nas=^state:naive
|
||||
nas=^state:naive
|
||||
=owners
|
||||
==
|
||||
^+ owners
|
||||
@ -39,7 +45,7 @@
|
||||
=/ old=(unit point:naive)
|
||||
(get points.cache-nas ship.diff)
|
||||
=/ new=point:naive
|
||||
(need (get points.up-nas ship.diff))
|
||||
(need (get points.nas ship.diff))
|
||||
=* event +>.diff
|
||||
=; [to=@ux from=@ux]
|
||||
=? owners !=(from 0x0)
|
||||
|
@ -50,9 +50,9 @@
|
||||
[(end bite sig) (rsh bite sig)]
|
||||
--
|
||||
::
|
||||
++ unsign-tx
|
||||
++ unsigned-tx
|
||||
|= [chain-id=@ud =nonce tx=octs]
|
||||
^- @u
|
||||
^- @
|
||||
=/ prepared-data (prepare-for-sig chain-id nonce tx)
|
||||
=/ len (rsh [3 2] (scot %ui p.prepared-data))
|
||||
%- hash-tx
|
||||
@ -65,7 +65,7 @@
|
||||
::
|
||||
++ sign-tx
|
||||
|= [pk=@ =nonce tx=octs] ^- octs
|
||||
=/ sign-data (unsign-tx 1.337 nonce tx)
|
||||
=/ sign-data (unsigned-tx 1.337 nonce tx)
|
||||
=+ (ecdsa-raw-sign:secp256k1:secp:crypto sign-data pk)
|
||||
(cad:naive 3 1^v 32^s 32^r tx ~)
|
||||
::
|
||||
|
Loading…
Reference in New Issue
Block a user