From 6660d697ec5d627123452a8577514683d9f87c61 Mon Sep 17 00:00:00 2001 From: Philip Monk Date: Wed, 31 Oct 2018 14:34:21 -0700 Subject: [PATCH 1/2] allow booting from ethereum snapshot --- sys/vane/dill.hoon | 1 + sys/vane/gall.hoon | 2 -- sys/vane/jael.hoon | 62 +++++++++++++++------------------------ sys/zuse.hoon | 73 +++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 97 insertions(+), 41 deletions(-) diff --git a/sys/vane/dill.hoon b/sys/vane/dill.hoon index ee9836ba36..a496e45979 100644 --- a/sys/vane/dill.hoon +++ b/sys/vane/dill.hoon @@ -77,6 +77,7 @@ turf=(list turf) :: domains bloq=@ud :: block number node=(unit purl:eyre) :: gateway url + snap=(unit snapshot:able:jael) :: head start == :: [%fake our=ship] :: boot fake :: XX wegh :: diff --git a/sys/vane/gall.hoon b/sys/vane/gall.hoon index c24dae8010..a2c0f0ab53 100644 --- a/sys/vane/gall.hoon +++ b/sys/vane/gall.hoon @@ -1243,8 +1243,6 @@ $serv `%e $tend `%a $them `%e - $turf `%j - $vein `%j $wait `%b $want `%a $warp `%c diff --git a/sys/vane/jael.hoon b/sys/vane/jael.hoon index 848da43e6c..e3532273cc 100644 --- a/sys/vane/jael.hoon +++ b/sys/vane/jael.hoon @@ -84,12 +84,6 @@ $: pry/(map ship (map ship safe)) :: promises eve=logs :: on-chain events == :: -++ state-eth-node :: node config + meta - $: source=(each ship node-src) :: learning from - heard=(set event-id) :: processed events - latest-block=@ud :: last heard block - foreign-block=@ud :: node's latest block - == :: ++ state-snapshots :: rewind points $: interval=_100 :: block interval max-count=_10 :: max snaps @@ -97,21 +91,6 @@ last-block=@ud :: number of last snap snaps=(qeu [block-number=@ud snap=snapshot]) :: old states == :: -++ snapshot :: rewind point - $: eve=logs :: eth absolute state - kyz=(map ship public) :: public key state - $= eth :: - $: dns=dnses :: on-chain dns state - hul=(map ship hull) :: on-chain ship state - == :: - etn=state-eth-node :: eth connection state - == :: -++ node-src :: ethereum node comms - $: node=purl:eyre :: node url - filter-id=@ud :: current filter - poll-timer=@da :: next filter poll - == :: -:: :: ++ message :: p2p message $% [%hail p=remote] :: reset rights [%nuke ~] :: cancel trackers @@ -741,6 +720,11 @@ :: set initial domains :: =. tuf.own.sub turf.tac + :: if we're given a snapshot, restore it + :: + =. +>.$ + ?~ snap.tac +>.$ + (restore-snap u.snap.tac) :: =. moz %+ weld moz @@ -1040,6 +1024,18 @@ [snap.snap +>.^$] $ ~& [%wind block latest-block.etn.snap ~(wyt by hul.eth.snap)] + =. +>.$ (restore-snap snap) + %= +>.$ + moz + =- [[hen %pass /wind/look %j %look our -] moz] + ?- -.source.etn + %& &+p.source.etn + %| |+node.p.source.etn + == + == + :: :: ++restore-snap:of + ++ restore-snap :: restore snapshot + |= snap=snapshot :: keep the following in sync with ++extract-snap:file:su %= +>.$ eve.urb eve.snap @@ -1047,12 +1043,6 @@ kyz.puk.sub kyz.snap +.eth.sub eth.snap sap sap(last-block 0) - moz - =- [[hen %pass /wind/look %j %look our -] moz] - ?- -.source.etn - %& &+p.source.etn - %| |+node.p.source.etn - == == -- :: :: ++su @@ -1840,7 +1830,7 @@ ^+ +> :: TODO: ship or node as sample? :: - =. latest-block launch:contracts + =. latest-block (max latest-block launch:contracts) ?: |(=(our bos) ?=(^ nod.own)) ~| %jael-init-node (listen-to-node (need nod.own)) @@ -2260,16 +2250,12 @@ ?: =(~ snaps.sap.lex) `~ :^ ~ ~ %noun !> - %= sap.lex - snaps - %- ~(put to *(qeu [block-number=@ud snap=snapshot])) - |- ^- [@ud snapshot] - =^ snap snaps.sap.lex - ~(get to snaps.sap.lex) - ?: =(~ snaps.sap.lex) - snap - $ - == + |- ^- snapshot + =^ snap=[@ud snap=snapshot] snaps.sap.lex + ~(get to snaps.sap.lex) + ?: =(~ snaps.sap.lex) + snap.snap + $ == :: :: ++stay ++ stay :: preserve diff --git a/sys/zuse.hoon b/sys/zuse.hoon index 213174a587..85c34b730a 100644 --- a/sys/zuse.hoon +++ b/sys/zuse.hoon @@ -2035,6 +2035,12 @@ {$vine p/(list change)} :: all raw changes [%vent p=chain] :: ethereum changes == :: + ++ node-src :: ethereum node comms + $: node=purl:eyre :: node url + filter-id=@ud :: current filter + poll-timer=@da :: next filter poll + == :: + :: :: ++ note :: out request $-> =, eyre :: $% $: %b :: @@ -2068,11 +2074,27 @@ +$ seed [who=ship lyf=life key=ring sig=(unit oath:pki)] :: ++ sign :: in result $<- - $% {$b $wake ~} :: wakeup + $% {$b $wake ~} :: wakeup [%e %sigh p=cage] :: marked http response [%j %vent p=chain] :: ethereum changes [%a %woot p=ship q=coop] :: message result == :: + ++ snapshot :: rewind point + =, constitution:ethe :: + $: eve=logs :: eth absolute state + kyz=(map ship public) :: public key state + $= eth :: + $: dns=dnses :: on-chain dns state + hul=(map ship hull) :: on-chain ship state + == :: + etn=state-eth-node :: eth connection state + == :: + ++ state-eth-node :: node config + meta + $: source=(each ship node-src) :: learning from + heard=(set event-id:ethe) :: processed events + latest-block=@ud :: last heard block + foreign-block=@ud :: node's latest block + == :: ++ tally :: balance update %+ each balance :: complete action :: change @@ -2087,6 +2109,7 @@ turf=(list turf) :: domains bloq=@ud :: block number node=(unit purl:eyre) :: gateway url + snap=(unit snapshot) :: head start == :: [%fake our=ship] :: fake boot [%look our=ship src=(each ship purl:eyre)] :: set ethereum source @@ -8135,6 +8158,54 @@ (~(put by tuf) q.i.dom p.i.dom) $(dom t.dom) -- + :: |snap:dawn restore from snapshot + :: + ++ snap + !: + |% + :: +bloq:snap:dawn: extract block number + :: + ++ bloq + |= snap=snapshot:able:jael + ^- @ud + latest-block.etn.snap + :: +czar:snap:dawn: extract galaxy table + :: + ++ czar + |= snap=snapshot:able:jael + ^- (map ship [=life =pass]) + %- malt + %+ turn (gulf 0 255) + |= gal=@ + ^- [ship [life pass]] + :- gal + ~| czar-gal=gal + [life pass]:(need net:(~(got by hul.eth.snap) gal)) + :: +hull:snap:dawn: extract ship's contract state + :: + ++ hull + |= [who=ship snap=snapshot:able:jael] + ^- hull:constitution:ethe + =/ res (~(get by hul.eth.snap) who) + ?~ res + ~& ['hull not found in snapshot; can\'t verify' who=who] + !! + u.res + :: +turf:snap:dawn: extract network domains + :: + ++ turf + |= snap=snapshot:able:jael + ^- (list ^turf) + %+ murn + ^- (list (pair)) + %+ murn + ^- (list @t) + ~[pri sec ter]:dns.eth.snap + |= dom=@t + ^- (unit (pair)) + (rush pri.dns.eth.snap thos:de-purl:html) + |=([* a=*] ((soft ^turf) a)) + -- :: +veri:dawn: validate keys, life, discontinuity, &c :: ++ veri From 0db24cf20835c72e379a4820b00422b39feba19e Mon Sep 17 00:00:00 2001 From: Philip Monk Date: Wed, 31 Oct 2018 15:18:40 -0700 Subject: [PATCH 2/2] clean and add tests --- sys/vane/dill.hoon | 2 +- sys/zuse.hoon | 57 +++++++++++++++++++++------------------- tests/sys/vane/jael.hoon | 2 +- tests/sys/zuse/dawn.hoon | 35 ++++++++++++++++++++++++ 4 files changed, 67 insertions(+), 29 deletions(-) diff --git a/sys/vane/dill.hoon b/sys/vane/dill.hoon index a496e45979..16d00e0431 100644 --- a/sys/vane/dill.hoon +++ b/sys/vane/dill.hoon @@ -77,7 +77,7 @@ turf=(list turf) :: domains bloq=@ud :: block number node=(unit purl:eyre) :: gateway url - snap=(unit snapshot:able:jael) :: head start + snap=(unit snapshot:jael) :: head start == :: [%fake our=ship] :: boot fake :: XX wegh :: diff --git a/sys/zuse.hoon b/sys/zuse.hoon index 85c34b730a..e15df28554 100644 --- a/sys/zuse.hoon +++ b/sys/zuse.hoon @@ -2035,11 +2035,6 @@ {$vine p/(list change)} :: all raw changes [%vent p=chain] :: ethereum changes == :: - ++ node-src :: ethereum node comms - $: node=purl:eyre :: node url - filter-id=@ud :: current filter - poll-timer=@da :: next filter poll - == :: :: :: ++ note :: out request $-> =, eyre :: @@ -2079,22 +2074,6 @@ [%j %vent p=chain] :: ethereum changes [%a %woot p=ship q=coop] :: message result == :: - ++ snapshot :: rewind point - =, constitution:ethe :: - $: eve=logs :: eth absolute state - kyz=(map ship public) :: public key state - $= eth :: - $: dns=dnses :: on-chain dns state - hul=(map ship hull) :: on-chain ship state - == :: - etn=state-eth-node :: eth connection state - == :: - ++ state-eth-node :: node config + meta - $: source=(each ship node-src) :: learning from - heard=(set event-id:ethe) :: processed events - latest-block=@ud :: last heard block - foreign-block=@ud :: node's latest block - == :: ++ tally :: balance update %+ each balance :: complete action :: change @@ -2127,7 +2106,31 @@ [%west p=sack q=path r=*] :: remote request [%wind our=ship p=@ud] :: rewind before block == :: - -- + -- :: + :: :: + :::: :: + :: :: + ++ node-src :: ethereum node comms + $: node=purl:eyre :: node url + filter-id=@ud :: current filter + poll-timer=@da :: next filter poll + == :: + ++ snapshot :: rewind point + =, constitution:ethe :: + $: eve=logs:able :: eth absolute state + kyz=(map ship public:able) :: public key state + $= eth :: + $: dns=dnses :: on-chain dns state + hul=(map ship hull) :: on-chain ship state + == :: + etn=state-eth-node :: eth connection state + == :: + ++ state-eth-node :: node config + meta + $: source=(each ship node-src) :: learning from + heard=(set event-id:ethe) :: processed events + latest-block=@ud :: last heard block + foreign-block=@ud :: node's latest block + == :: :: :: :::: ++pki:jael :: (1h2) certificates :: :::: @@ -8166,13 +8169,13 @@ :: +bloq:snap:dawn: extract block number :: ++ bloq - |= snap=snapshot:able:jael + |= snap=snapshot:jael ^- @ud latest-block.etn.snap :: +czar:snap:dawn: extract galaxy table :: ++ czar - |= snap=snapshot:able:jael + |= snap=snapshot:jael ^- (map ship [=life =pass]) %- malt %+ turn (gulf 0 255) @@ -8184,7 +8187,7 @@ :: +hull:snap:dawn: extract ship's contract state :: ++ hull - |= [who=ship snap=snapshot:able:jael] + |= [who=ship snap=snapshot:jael] ^- hull:constitution:ethe =/ res (~(get by hul.eth.snap) who) ?~ res @@ -8194,7 +8197,7 @@ :: +turf:snap:dawn: extract network domains :: ++ turf - |= snap=snapshot:able:jael + |= snap=snapshot:jael ^- (list ^turf) %+ murn ^- (list (pair)) @@ -8203,7 +8206,7 @@ ~[pri sec ter]:dns.eth.snap |= dom=@t ^- (unit (pair)) - (rush pri.dns.eth.snap thos:de-purl:html) + (rush dom thos:de-purl:html) |=([* a=*] ((soft ^turf) a)) -- :: +veri:dawn: validate keys, life, discontinuity, &c diff --git a/tests/sys/vane/jael.hoon b/tests/sys/vane/jael.hoon index 700d98b246..c805743b6a 100644 --- a/tests/sys/vane/jael.hoon +++ b/tests/sys/vane/jael.hoon @@ -17,7 +17,7 @@ -8~kX.3ALiG.rQjOi.HZ9hj.84b6G.P5pCZ.UtNtt.Lh9TE.2DQJ2 =/ url (de-purl:html 'http://localhost:8545') =/ dan - [`seed:able:jael`[~nul 1 key ~] ~ ~ [/org/urbit ~] 0 url] + [`seed:able:jael`[~nul 1 key ~] ~ ~ [/org/urbit ~] 0 url ~] :: =^ results1 jael-gate =/ hen=duct diff --git a/tests/sys/zuse/dawn.hoon b/tests/sys/zuse/dawn.hoon index bec2aa53f8..8e55154523 100644 --- a/tests/sys/zuse/dawn.hoon +++ b/tests/sys/zuse/dawn.hoon @@ -28,6 +28,21 @@ %- crip %+ weld "0x" (render-hex-bytes:ethereum 20 `@`ships:contracts:constitution:ethe) +:: snapshot +:: +++ snap + ^- snapshot:jael + :* *logs:able:jael + ~ + :* ['urbit.org' 'urbit.org' ''] + %- malt + :* ~zod^hul + ~marzod^hul + (turn (gulf 1 255) |=(gal=@ gal^hul)) + == + == + %*(. *state-eth-node:jael latest-block 4.230.000) + == :: ++ test-give-bloq =/ oct @@ -167,6 +182,26 @@ !> [/org/urbit ~] !> (turf:take:dawn oct) :: +++ test-snap-bloq + %+ expect-eq + !> 4.230.000 + !> (bloq:snap:dawn snap) +:: +++ test-snap-hull + %+ expect-eq + !> hul + !> (hull:snap:dawn ~zod snap) +:: +++ test-snap-czar + %+ expect-eq + !> 256 + !> ~(wyt by (czar:snap:dawn snap)) +:: +++ test-snap-turf + %+ expect-eq + !> `(list turf)`~[~['org' 'urbit'] ~['org' 'urbit']] + !> (turf:snap:dawn snap) +:: ++ test-veri-good =/ sed [~zod 1 sec ~] %+ expect-eq