mirror of
https://github.com/ilyakooo0/urbit.git
synced 2024-12-01 03:23:09 +03:00
azimuth: load azimuth state from state snapshot
This commit is contained in:
parent
d5c44598ba
commit
ad16155c77
@ -7,19 +7,19 @@
|
||||
verb,
|
||||
dbug
|
||||
:: Generally don't update the snapshot until we have clay tombstoning.
|
||||
:: To update, run:
|
||||
::
|
||||
/* state-naive %naive /app/azimuth/state/naive
|
||||
:: To update, run from dojo:
|
||||
:: -azimuth-snap-state %default 'state'
|
||||
::
|
||||
:: To recreate from a list of logs:
|
||||
:: =e -build-file %/lib/ethereum/hoon
|
||||
:: =l .^((list event-log:rpc:e) %gx /=azimuth=/logs/noun)
|
||||
:: */app/azimuth/logs/eth-logs ð-logs l
|
||||
:: -azimuth-snap-logs %default 'state'
|
||||
::
|
||||
/* snap %eth-logs /app/azimuth/logs/eth-logs
|
||||
::
|
||||
=/ last-snap :: maybe just use the last one?
|
||||
%+ roll `(list event-log:rpc:ethereum)`snap ::~
|
||||
|= [log=event-log:rpc:ethereum last=@ud]
|
||||
?~ mined.log
|
||||
last
|
||||
(max block-number.u.mined.log last)
|
||||
=/ snap=snap-state state-naive
|
||||
=/ last-snap number.id.snap
|
||||
::
|
||||
=, jael
|
||||
|%
|
||||
@ -62,8 +62,17 @@
|
||||
::
|
||||
++ on-init
|
||||
^- (quip card _this)
|
||||
%- %- slog
|
||||
=, snap
|
||||
:~ leaf+"azimuth: loading {<~(wyt by points.nas)>} points"
|
||||
leaf+"azimuth: loading {<~(wyt by sponsors)>} sponsors"
|
||||
leaf+"azimuth: loading {<~(wyt by owners)>} owners"
|
||||
==
|
||||
::
|
||||
=: net.state %default
|
||||
logs.state snap
|
||||
nas.state nas.snap
|
||||
own.state owners.snap
|
||||
spo.state sponsors.snap
|
||||
url.state 'http://eth-mainnet.urbit.org:8545'
|
||||
==
|
||||
:_ this
|
||||
@ -126,13 +135,6 @@
|
||||
^- (quip card _this)
|
||||
?: =(%noun mark)
|
||||
?+ q.vase !!
|
||||
%rerun
|
||||
~& [%rerunning (lent logs.state)]
|
||||
=. points.nas.state ~
|
||||
=. own.state ~
|
||||
=. spo.state ~
|
||||
=^ * state (run-logs:do logs.state)
|
||||
`this
|
||||
::
|
||||
%resub
|
||||
:_ this :_ ~
|
||||
@ -141,8 +143,11 @@
|
||||
==
|
||||
::
|
||||
%resnap
|
||||
=. logs.state snap
|
||||
$(mark %noun, vase !>(%rerun))
|
||||
=: nas.state nas.snap
|
||||
own.state owners.snap
|
||||
spo.state sponsors.snap
|
||||
==
|
||||
`this
|
||||
==
|
||||
?: =(%eth-logs mark)
|
||||
=+ !<(logs=(list event-log:rpc:ethereum) vase)
|
||||
@ -160,12 +165,12 @@
|
||||
:: TODO: only wipe out state when switching networks?
|
||||
:: ?: =(net.state net.poke)
|
||||
:: [~ this]
|
||||
=: nas.state *^state:naive
|
||||
=: nas.state ?:(?=(%default net.poke) nas.snap *^state:naive)
|
||||
own.state ?:(?=(%default net.poke) owners.snap ~)
|
||||
spo.state ?:(?=(%default net.poke) sponsors.snap ~)
|
||||
net.state net.poke
|
||||
url.state url.poke
|
||||
own.state ~
|
||||
spo.state ~
|
||||
logs.state ?:(?=(%default net.poke) snap ~)
|
||||
logs.state ~
|
||||
==
|
||||
[start:do this]
|
||||
==
|
||||
@ -190,10 +195,11 @@
|
||||
:: sure Jael gets the updates from the snapshot
|
||||
::
|
||||
%- %- slog :_ ~
|
||||
leaf+"azimuth: loading snapshot with {<(lent logs.state)>} events"
|
||||
=^ snap-cards state
|
||||
(%*(run-logs do nas.state *^state:naive) logs.state)
|
||||
[(weld (jael-update:do (to-udiffs:do snap-cards)) start:do) this]
|
||||
:- %leaf
|
||||
"azimuth: processing snapshot ({<~(wyt by points.nas.state)>} points)"
|
||||
=/ snap-cards=udiffs:point
|
||||
(%*(run-state do logs.state ~) id.snap points.nas.state)
|
||||
[(weld (jael-update:do snap-cards) start:do) this]
|
||||
::
|
||||
++ on-leave on-leave:def
|
||||
++ on-peek
|
||||
@ -232,13 +238,15 @@
|
||||
?: ?=(%disavow -.diff)
|
||||
[(jael-update:do [*ship id.diff %disavow ~]~) this]
|
||||
::
|
||||
:: TODO: skip running the logs if we receive a history diff?
|
||||
::
|
||||
=. logs.state
|
||||
?- -.diff
|
||||
:: %history loglist.diff
|
||||
%history (welp logs.state loglist.diff)
|
||||
%logs (welp logs.state loglist.diff)
|
||||
==
|
||||
=? nas.state ?=(%history -.diff) *^state:naive
|
||||
:: =? nas.state ?=(%history -.diff) *^state:naive :: should go
|
||||
=^ effects state (run-logs:do loglist.diff)
|
||||
::
|
||||
:_ this
|
||||
@ -288,16 +296,27 @@
|
||||
^- (list ?(@ux (list @ux)))
|
||||
~
|
||||
::
|
||||
++ data-to-hex
|
||||
|= data=@t
|
||||
?~ data *@ux
|
||||
?: =(data '0x') *@ux
|
||||
(hex-to-num:ethereum data)
|
||||
++ run-state
|
||||
|= [=id:block =points:naive]
|
||||
::%- road |. :: count memory usage in a separate road
|
||||
^- =udiffs:point
|
||||
%- flop
|
||||
%+ roll (tap:orp:dice points)
|
||||
|= [[=ship naive-point=point:naive] =udiffs:point]
|
||||
=, naive-point
|
||||
=/ =pass
|
||||
(pass-from-eth:azimuth [32^crypt 32^auth suite]:keys.net)
|
||||
^- (list [@p udiff:point])
|
||||
:* [ship id %rift rift.net]
|
||||
[ship id %keys life.keys.net suite.keys.net pass]
|
||||
[ship id %spon ?:(has.sponsor.net `who.sponsor.net ~)]
|
||||
udiffs
|
||||
==
|
||||
::
|
||||
++ run-logs
|
||||
|= [logs=(list event-log:rpc:ethereum)]
|
||||
^- (quip tagged-diff _state)
|
||||
=+ net=(get-network net.state)
|
||||
=+ net=(get-network:dice net.state)
|
||||
=| effects=(list tagged-diff)
|
||||
!. :: saves 700MB replaying snapshot
|
||||
=- =/ res (mule -)
|
||||
@ -315,7 +334,7 @@
|
||||
=/ =^input:naive
|
||||
:- block-number.u.mined.i.logs
|
||||
?: =(azimuth.net address.i.logs)
|
||||
=/ data (data-to-hex data.i.logs)
|
||||
=/ data (data-to-hex:dice data.i.logs)
|
||||
=/ =event-log:naive
|
||||
[address.i.logs data topics.i.logs]
|
||||
[%log event-log]
|
||||
@ -381,26 +400,13 @@
|
||||
^- card
|
||||
[%give %fact ~[/event] %naive-diffs !>(+.tag)]
|
||||
::
|
||||
++ get-network
|
||||
|= =net
|
||||
^- [azimuth=@ux naive=@ux chain-id=@ launch=@]
|
||||
=< [azimuth naive chain-id launch]
|
||||
=, azimuth
|
||||
?- net
|
||||
%mainnet mainnet-contracts
|
||||
%ropsten ropsten-contracts
|
||||
%local local-contracts
|
||||
%default contracts
|
||||
==
|
||||
::
|
||||
++ start
|
||||
^- (list card)
|
||||
=+ net=(get-network net.state)
|
||||
=+ net=(get-network:dice net.state)
|
||||
=/ args=vase !>
|
||||
:+ %watch /[dap.bowl]
|
||||
^- config:eth-watcher
|
||||
:* url.state =(%czar (clan:title our.bowl)) refresh ~h30
|
||||
(max launch.net ?:(=(net.state %default) last-snap 0))
|
||||
(max launch.net ?:(=(net.state %default) +(last-snap) 0))
|
||||
~[azimuth.net]
|
||||
~[naive.net]
|
||||
(topics whos.state)
|
||||
|
BIN
pkg/arvo/app/azimuth/state.naive
Normal file
BIN
pkg/arvo/app/azimuth/state.naive
Normal file
Binary file not shown.
@ -1,7 +1,7 @@
|
||||
:: dice: helper functions for L2 Rollers
|
||||
::
|
||||
/- *dice
|
||||
/+ naive, *naive-transactions
|
||||
/+ naive, *naive-transactions, ethereum, azimuth
|
||||
::
|
||||
|%
|
||||
:: orp: ordered points in naive state by parent ship
|
||||
@ -18,6 +18,34 @@
|
||||
|= [a=[* =nonce:naive] b=[* =nonce:naive]]
|
||||
(lte nonce.a nonce.b)
|
||||
::
|
||||
++ data-to-hex
|
||||
|= data=@t
|
||||
?~ data *@ux
|
||||
?: =(data '0x') *@ux
|
||||
(hex-to-num:ethereum data)
|
||||
::
|
||||
++ get-network
|
||||
|= =net
|
||||
^- [azimuth=@ux naive=@ux chain-id=@ launch=@]
|
||||
=< [azimuth naive chain-id launch]
|
||||
=, azimuth
|
||||
?- net
|
||||
%mainnet mainnet-contracts
|
||||
%ropsten ropsten-contracts
|
||||
%local local-contracts
|
||||
%default contracts
|
||||
==
|
||||
::
|
||||
++ last-block-id
|
||||
|= logs=(list event-log:rpc:ethereum)
|
||||
^- id:block:jael
|
||||
%+ roll logs
|
||||
|= [log=event-log:rpc:ethereum =id:block:jael]
|
||||
?~ mined.log id
|
||||
?. (gth block-number.u.mined.log number.id)
|
||||
id
|
||||
[block-hash block-number]:u.mined.log
|
||||
::
|
||||
++ tx-effects
|
||||
|= [chain-t=@ =effects:naive nas=^state:naive =indices]
|
||||
^+ indices
|
||||
@ -65,18 +93,17 @@
|
||||
=/ old=(unit point:naive) (get:orp cache ship)
|
||||
=/ new=point:naive (need (get:orp points ship))
|
||||
=^ update-1 sponsors
|
||||
(sponsorship diff ship new old sponsors)
|
||||
(sponsorship-diff diff ship new old sponsors)
|
||||
=^ update-2 owners
|
||||
(ownership diff ship new old owners)
|
||||
(ownership-diff diff ship new old owners)
|
||||
=/ update-3=_updates
|
||||
(point-data-updates diff ship new old)
|
||||
:_ indices
|
||||
:(welp update-3 update-2 update-1 updates)
|
||||
[(flop updates) indices]
|
||||
::
|
||||
++ sponsorship
|
||||
++ sponsorship-diff
|
||||
|= [=diff:naive =ship new=point:naive old=(unit point:naive) =sponsors]
|
||||
::^+ sponsors
|
||||
^- (quip update _sponsors)
|
||||
?. ?=([%point *] diff) `sponsors
|
||||
=* event +>.diff
|
||||
@ -159,7 +186,7 @@
|
||||
(proxy-updates diff ship new old)
|
||||
==
|
||||
::
|
||||
++ ownership
|
||||
++ ownership-diff
|
||||
|= [=diff:naive =ship new=point:naive old=(unit point:naive) =owners]
|
||||
^- (quip update _owners)
|
||||
?. ?=([%point *] diff) `owners
|
||||
@ -201,6 +228,56 @@
|
||||
`[%transfer address.transfer-proxy.own.u.old]
|
||||
==
|
||||
::
|
||||
++ create-indices
|
||||
|= nas=^state:naive
|
||||
^- [sponsors owners]
|
||||
%+ roll (tap:orp points.nas)
|
||||
|= [[=ship =point:naive] =sponsors =owners]
|
||||
|^
|
||||
=? sponsors has.sponsor.net.point
|
||||
^+ sponsors
|
||||
(add-resident who.sponsor.net.point)
|
||||
=? sponsors ?=(^ escape.net.point)
|
||||
(add-request u.escape.net.point)
|
||||
[sponsors add-ownership]
|
||||
::
|
||||
++ add-resident
|
||||
|= sponsor=@p
|
||||
^+ sponsors
|
||||
:: galaxies have themselves as their sponsors
|
||||
::
|
||||
?: =(sponsor ship) sponsors
|
||||
%+ ~(put by sponsors) sponsor
|
||||
?~ sponsees=(~(get by sponsors) sponsor)
|
||||
:_ *(set @p)
|
||||
(~(put in *(set @p)) ship)
|
||||
:_ requests.u.sponsees
|
||||
(~(put in residents.u.sponsees) ship)
|
||||
::
|
||||
++ add-request
|
||||
|= sponsor=@p
|
||||
^+ sponsors
|
||||
:: galaxies have themselves as their sponsors
|
||||
::
|
||||
?: =(sponsor ship) sponsors
|
||||
%+ ~(put by sponsors) sponsor
|
||||
?~ receiver=(~(get by sponsors) sponsor)
|
||||
:- *(set @p)
|
||||
(~(put in *(set @p)) ship)
|
||||
:- residents.u.receiver
|
||||
(~(put in requests.u.receiver) ship)
|
||||
::
|
||||
++ add-ownership
|
||||
^+ owners
|
||||
=/ proxies=(list proxy:naive)
|
||||
~[%own %spawn %manage %vote %transfer]
|
||||
%+ roll proxies
|
||||
|= [=proxy:naive own=_owners]
|
||||
?~ owner=(get-owner point proxy)
|
||||
own
|
||||
(~(put ju own) u.owner ship)
|
||||
--
|
||||
::
|
||||
++ proxy-updates
|
||||
|= [=diff:naive =ship =point:naive old=(unit point:naive)]
|
||||
^- (list update)
|
||||
|
21
pkg/arvo/mar/naive.hoon
Normal file
21
pkg/arvo/mar/naive.hoon
Normal file
@ -0,0 +1,21 @@
|
||||
:: naive state
|
||||
::
|
||||
/- *dice
|
||||
/+ naive
|
||||
::
|
||||
|_ snap=snap-state
|
||||
++ grab
|
||||
|%
|
||||
++ noun snap-state
|
||||
++ mime
|
||||
|= [mite =octs]
|
||||
(noun (cue q.octs))
|
||||
--
|
||||
::
|
||||
++ grow
|
||||
|%
|
||||
++ mime
|
||||
[/application/x-naive (as-octs:mimes:html (jam snap))]
|
||||
--
|
||||
++ grad %mime
|
||||
--
|
@ -1,13 +1,14 @@
|
||||
:: dice: structures for L2 rollers
|
||||
:: dice: structures for Azimuth L2 rollers
|
||||
::
|
||||
/+ naive, ethereum
|
||||
::
|
||||
|%
|
||||
+$ owner [=proxy:naive =address:naive]
|
||||
+$ owners (jug owner ship)
|
||||
+$ sponsors (map ship [residents=(set ship) requests=(set ship)])
|
||||
+$ history (map address:ethereum (tree hist-tx))
|
||||
+$ net ?(%mainnet %ropsten %local %default)
|
||||
+$ owner [=proxy:naive =address:naive]
|
||||
+$ owners (jug owner ship)
|
||||
+$ sponsors (map ship [residents=(set ship) requests=(set ship)])
|
||||
+$ history (map address:ethereum (tree hist-tx))
|
||||
+$ net ?(%mainnet %ropsten %local %default)
|
||||
+$ snap-state [%0 =id:block:jael nas=^state:naive =owners =sponsors]
|
||||
::
|
||||
+$ config
|
||||
$% [%frequency frequency=@dr]
|
||||
|
67
pkg/arvo/ted/azimuth/snap-logs.hoon
Normal file
67
pkg/arvo/ted/azimuth/snap-logs.hoon
Normal file
@ -0,0 +1,67 @@
|
||||
:: Creates a snapshop of the naive state and its indices (owners and sposnors)
|
||||
::
|
||||
/- spider, *dice
|
||||
/+ strand,
|
||||
azimuth,
|
||||
strandio,
|
||||
naive,
|
||||
lib=naive-transactions,
|
||||
ethereum,
|
||||
dice
|
||||
/* logs %eth-logs /app/azimuth/logs/eth-logs
|
||||
=, strand=strand:spider
|
||||
::
|
||||
=> |% +$ card card:agent:gall
|
||||
+$ task task:clay
|
||||
+$ id id:block:jael
|
||||
+$ events (list event-log:rpc:ethereum)
|
||||
--
|
||||
::
|
||||
^- thread:spider
|
||||
|= arg=vase
|
||||
=/ m (strand ,vase)
|
||||
^- form:m
|
||||
=+ !<([~ =net name=@t] arg)
|
||||
::
|
||||
=/ [azimuth-contract=@ux chain-id=@]
|
||||
[azimuth chain-id]:(get-network:dice net)
|
||||
::
|
||||
%- %- slog :_ ~
|
||||
leaf+"azimuth: creating snapshot with {<(lent logs)>} events"
|
||||
::
|
||||
=/ [=id nas=^state:naive]
|
||||
%+ roll `events`logs
|
||||
|= [log=event-log:rpc:ethereum =id nas=^state:naive]
|
||||
?~ mined.log
|
||||
id^nas
|
||||
=/ =^input:naive
|
||||
:- block-number.u.mined.log
|
||||
?: =(azimuth-contract address.log)
|
||||
:- %log
|
||||
[address.log (data-to-hex:dice data.log) topics.log]
|
||||
?~ input.u.mined.log
|
||||
[%bat *@]
|
||||
[%bat u.input.u.mined.log]
|
||||
=. id
|
||||
?. (gth block-number.u.mined.log number.id)
|
||||
id
|
||||
[block-hash block-number]:u.mined.log
|
||||
=^ * nas
|
||||
(%*(. naive lac |) verifier:lib chain-id nas input)
|
||||
id^nas
|
||||
::
|
||||
=/ [=sponsors =owners] (create-indices:dice nas)
|
||||
::
|
||||
::
|
||||
%- %- slog
|
||||
:~ leaf+"points: {<~(wyt by points.nas)>}"
|
||||
leaf+"sponsors: {<~(wyt by sponsors)>}"
|
||||
leaf+"owners: {<~(wyt by owners)>}"
|
||||
==
|
||||
::
|
||||
=/ =path /app/azimuth/[name]/naive
|
||||
=/ =cage naive+!>([%0 id nas owners sponsors])
|
||||
=/ =task [%info %base %& [path %ins cage]~]
|
||||
=/ =card [%pass /next %arvo %c task]
|
||||
;< ~ bind:m (send-raw-card:strandio card)
|
||||
(pure:m !>('naive logs processed'))
|
44
pkg/arvo/ted/azimuth/snap-state.hoon
Normal file
44
pkg/arvo/ted/azimuth/snap-state.hoon
Normal file
@ -0,0 +1,44 @@
|
||||
:: =e -build-file %/lib/ethereum/hoon
|
||||
:: =n -build-file %/lib/naive/hoon
|
||||
:: =d -build-file %/sur/dice/hoon
|
||||
:: =l .^((list event-log:rpc:e) %gx /=azimuth=/logs/noun)
|
||||
:: =nas .^(^state:n %gx /=azimuth=/nas/noun)
|
||||
:: =own .^(owners:d %gx /=azimuth=/own/noun)
|
||||
:: =spo .^(sponsors:d %gx /=azimuth=/spo/noun)
|
||||
:: =block-id =+ last=(rear l) [block-hash block-number]:(need mined.last)
|
||||
:: */app/azimuth/state/naive &naive [block-id nas own spo]
|
||||
::
|
||||
/- spider, *dice
|
||||
/+ strand, strandio, naive, ethereum, dice
|
||||
=, strand=strand:spider
|
||||
=, jael
|
||||
::
|
||||
=> |% +$ card card:agent:gall
|
||||
+$ task task:clay
|
||||
+$ events (list event-log:rpc:ethereum)
|
||||
--
|
||||
::
|
||||
^- thread:spider
|
||||
|= arg=vase
|
||||
=/ m (strand ,vase)
|
||||
^- form:m
|
||||
=+ !<([~ =net name=@t] arg)
|
||||
::
|
||||
;< nas=^state:naive bind:m (scry:strandio ^state:naive /gx/azimuth/nas/noun)
|
||||
;< =owners bind:m (scry:strandio owners /gx/azimuth/own/noun)
|
||||
;< =sponsors bind:m (scry:strandio sponsors /gx/azimuth/spo/noun)
|
||||
;< =events bind:m (scry:strandio events /gx/azimuth/logs/noun)
|
||||
=/ =id:block (last-block-id:dice events)
|
||||
::
|
||||
%- %- slog
|
||||
:~ leaf+"points: {<~(wyt by points.nas)>}"
|
||||
leaf+"sponsors: {<~(wyt by sponsors)>}"
|
||||
leaf+"owners: {<~(wyt by owners)>}"
|
||||
==
|
||||
::
|
||||
=/ =path /app/azimuth/[name]/naive
|
||||
=/ =cage naive+!>([%0 id nas owners sponsors])
|
||||
=/ =task [%info %base %& [path %ins cage]~]
|
||||
=/ =card [%pass /next %arvo %c task]
|
||||
;< ~ bind:m (send-raw-card:strandio card)
|
||||
(pure:m !>('naive state saved'))
|
Loading…
Reference in New Issue
Block a user