azimuth, dice: simplify index update

This commit is contained in:
yosoyubik 2021-11-24 15:31:59 +01:00
parent 528a046b51
commit 2e94a0d446
4 changed files with 42 additions and 67 deletions

View File

@ -309,7 +309,8 @@
[(flop effects) state]
?~ mined.i.logs
$(logs t.logs)
=/ [raw-effects=effects:naive new-nas=_nas.state]
=+ cache=nas.state
=^ raw-effects nas.state
=/ =^input:naive
:- block-number.u.mined.i.logs
?: =(azimuth.net address.i.logs)
@ -321,28 +322,14 @@
[%bat *@]
[%bat u.input.u.mined.i.logs]
(%*(. naive lac |) verifier chain-id.net nas.state input)
:: TODO: move to /lib/dice ?
::
=/ [new-own=_own.state new-spo=_spo.state]
=< [own spo]
=/ =indices [own spo]:state
=. indices
?. =(azimuth.net address.i.logs)
%: apply-effects:dice
chain-id.net
raw-effects
nas.state
own.state
spo.state
==
%: update-indices:dice
raw-effects
nas.state
new-nas
own.state
spo.state
==
=: nas.state new-nas
own.state new-own
spo.state new-spo
(apply-effects:dice chain-id.net raw-effects cache indices)
=< indices
(update-indices:dice raw-effects cache nas.state indices)
=: own.state own.indices
spo.state spo.indices
==
=/ effects-1
=/ =id:block [block-hash block-number]:u.mined.i.logs

View File

@ -950,10 +950,13 @@
++ try-apply
|= [nas=^state:naive force=? =raw-tx:naive]
^- [[? ups=(list update)] _state]
=/ [success=? ups=(list update) predicted=_nas owners=_own sponsors=_spo]
=/ [success=? ups=(list update) predicted=_nas =indices]
(apply-raw-tx:dice force chain-id raw-tx nas own spo)
:- [success ups]
state(pre predicted, own owners, spo sponsors)
=: pre predicted
own own.indices
spo spo.indices
==
[[success ups] state]
::
++ get-l1-address
|= [=tx:naive nas=^state:naive]

View File

@ -9,66 +9,52 @@
(lte nonce.a nonce.b)
::
++ apply-effects
|= [chain-t=@ =effects:naive =indices]
|= [chain-t=@ =effects:naive nas=^state:naive =indices]
^+ indices
%+ roll effects
|= [=diff:naive indices=_indices]
?. ?=([%tx *] diff) indices::[nas own spo]
?. ?=([%tx *] diff) indices
=< indices
(apply-raw-tx | chain-t raw-tx.diff indices)
(apply-raw-tx | chain-t raw-tx.diff nas indices)
::
++ apply-raw-tx
|= [force=? chain-t=@ =raw-tx:naive =indices]
^- [? ups=(list update) indices=_indices]
=+ cache-nas=nas.indices
|= [force=? chain-t=@ =raw-tx:naive nas=^state:naive =indices]
^- [? ups=(list update) nas=_nas indices=_indices]
=+ cache=nas
=/ chain-t=@t (ud-to-ascii:naive chain-t)
?. (verify-sig-and-nonce:naive verifier chain-t nas.indices raw-tx)
?. (verify-sig-and-nonce:naive verifier chain-t nas raw-tx)
~& [%verify-sig-and-nonce %failed tx.raw-tx]
[force ~ indices]
=^ * points.nas.indices
(increment-nonce:naive nas.indices from.tx.raw-tx)
?~ nex=(receive-tx:naive nas.indices tx.raw-tx)
[force ~ nas indices]
=^ * points.nas
(increment-nonce:naive nas from.tx.raw-tx)
?~ nex=(receive-tx:naive nas tx.raw-tx)
~& [%receive-tx %failed]
=? nas.indices !force cache-nas
[force ~ indices]
[force ~ ?:(force nas cache) indices]
=* new-nas +.u.nex
=* effects -.u.nex
=/ [updates=(list update) own=_own.indices spo=_spo.indices]
(update-indices effects cache-nas new-nas [own spo]:indices)
=: nas.indices new-nas
own.indices own
spo.indices spo
==
[& updates indices]
=^ updates indices
(update-indices effects cache new-nas [own spo]:indices)
[& updates new-nas indices]
::
++ update-indices
|= $: =effects:naive
cache-nas=^state:naive
nas=^state:naive
=owners
=sponsors
==
^- [(list update) own=_owners spo=_sponsors]
|= [=effects:naive cache=^state:naive nas=^state:naive =indices]
^- [(list update) indices=_indices]
%+ roll effects
|= $: =diff:naive
ups=(list update)
owners=_owners
sponsors=_sponsors
==
|= [=diff:naive ups=(list update) indices=_indices]
=, orm:naive
?. ?=([%point *] diff) [ups owners sponsors]
=* ship ship.diff
?. ?=([%point *] diff) [ups indices]
=* ship ship.diff
=* sponsors spo.indices
=* owners own.indices
=/ old=(unit point:naive)
(get points.cache-nas ship)
(get points.cache ship)
=/ new=point:naive
(need (get points.nas ship))
=* event +>.diff
|^
=^ updates owners ownership
=+ sponsors=sponsorship
:+ (weld ups updates)
owners
sponsors
=. sponsors sponsorship
=^ updates owners ownership
[(weld ups updates) indices]
::
++ sponsorship
^+ sponsors

View File

@ -19,8 +19,7 @@
==
::
+$ indices
$: nas=^state:naive
own=owners
$: own=owners
spo=sponsors
==
::