Merge pull request #920 from urbit/dawn-take-error

adds more rudimentary error handle to pre-boot validation
This commit is contained in:
Joe Bryan 2018-12-07 14:28:13 -05:00 committed by GitHub
commit b4af89398c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 95 additions and 51 deletions

View File

@ -8236,34 +8236,55 @@
:: |take:dawn: parse responses for pre-boot validation
::
++ take
=, dejs:format
=, dejs-soft:format
|%
:: +bloq:take:dawn: parse block number
::
++ bloq
|= rep=octs
^- @ud
=/ jon=json (need (de-json:html q.rep))
=/ res=cord ((ot result+so ~) jon)
(hex-to-num:ethereum res)
^- (unit @ud)
=/ jon=(unit json) (de-json:html q.rep)
?~ jon
~&([%bloq-take-dawn %invalid-json] ~)
=/ res=(unit cord) ((ot result+so ~) u.jon)
?~ res
~&([%bloq-take-dawn %invalid-response rep] ~)
=/ out
%- mule |.
(hex-to-num:ethereum u.res)
?: ?=(%& -.out)
(some p.out)
~&([%bloq-take-dawn %invalid-block-number] ~)
:: +czar:take:dawn: parse galaxy table
::
++ czar
|= rep=octs
^- (map ship [=life =pass])
=/ jon=json (need (de-json:html q.rep))
=/ res=(list [@t @t])
((ar (ot id+so result+so ~)) jon)
%+ roll res
|= $: res=[id=@t result=@t]
^- (unit (map ship [=life =pass]))
=/ jon=(unit json) (de-json:html q.rep)
?~ jon
~&([%czar-take-dawn %invalid-json] ~)
=/ res=(unit (list [@t @t]))
((ar (ot id+so result+so ~)) u.jon)
?~ res
~&([%czar-take-dawn %invalid-response rep] ~)
=/ dat=(unit (list [who=ship enc=octs aut=octs sut=@ud rev=@ud]))
=- ?:(?=(%| -.out) ~ (some p.out))
^= out %- mule |.
%+ turn u.res
|= [id=@t result=@t]
^- [who=ship enc=octs aut=octs sut=@ud rev=@ud]
:- `@p`(slav %ud (rsh 3 4 id))
%+ decode-results:ethereum
result
~[[%bytes-n 32] [%bytes-n 32] %uint %uint]
?~ dat
~&([%bloq-take-dawn %invalid-galaxy-table] ~)
:- ~
%+ roll u.dat
|= $: [who=ship enc=octs aut=octs sut=@ud rev=@ud]
kyz=(map ship [=life =pass])
==
^+ kyz
=/ who=ship (slav %ud (rsh 3 4 id.res))
=+ ^- [enc=octs aut=octs sut=@ud rev=@ud]
%+ decode-results:ethereum
result.res
~[[%bytes-n 32] [%bytes-n 32] %uint %uint]
=/ pub=(unit pass)
(pass-from-eth:constitution:ethereum enc aut sut)
?~ pub kyz
@ -8272,24 +8293,40 @@
::
++ hull
|= [who=ship rep=octs]
^- hull:constitution:ethe
=/ jon=json (need (de-json:html q.rep))
=/ res=cord ((ot result+so ~) jon)
~? =(res '0x') 'bad result from node; is ships address correct?'
%+ hull-from-eth:constitution:ethereum
who
:_ *deed:eth-noun:constitution:ethereum
(decode-results:ethereum res hull:eth-type:constitution:ethe)
^- (unit hull:constitution:ethe)
=/ jon=(unit json) (de-json:html q.rep)
?~ jon
~&([%hull-take-dawn %invalid-json] ~)
=/ res=(unit cord) ((ot result+so ~) u.jon)
?~ res
~&([%hull-take-dawn %invalid-response rep] ~)
~? =(u.res '0x')
'bad result from node; is ships address correct?'
=/ out
%- mule |.
%+ hull-from-eth:constitution:ethereum
who
:_ *deed:eth-noun:constitution:ethereum
(decode-results:ethereum u.res hull:eth-type:constitution:ethe)
?: ?=(%& -.out)
(some p.out)
~&([%hull-take-dawn %invalid-hull] ~)
:: +turf:take:dawn: parse network domains
::
++ turf
|= rep=octs
^- (list ^turf)
=/ jon=json (need (de-json:html q.rep))
=/ res=(list [@t @t])
((ar (ot id+so result+so ~)) jon)
=/ dom=(list (pair @ud ^turf))
%+ turn res
^- (unit (list ^turf))
=/ jon=(unit json) (de-json:html q.rep)
?~ jon
~&([%turf-take-dawn %invalid-json] ~)
=/ res=(unit (list [@t @t]))
((ar (ot id+so result+so ~)) u.jon)
?~ res
~&([%turf-take-dawn %invalid-response rep] ~)
=/ dat=(unit (list (pair @ud ^turf)))
=- ?:(?=(%| -.out) ~ (some p.out))
^= out %- mule |.
%+ turn u.res
|= [id=@t result=@t]
^- (pair @ud ^turf)
:- (slav %ud (rsh 3 5 id))
@ -8298,6 +8335,10 @@
=/ hot=host:eyre
(scan dom thos:de-purl:html)
?>(?=(%& -.hot) p.hot)
?~ dat
~&([%turf-take-dawn %invalid-domains] ~)
:- ~
=* dom u.dat
:: sort by id, ascending, removing duplicates
::
=| tuf=(map ^turf @ud)
@ -8320,14 +8361,18 @@
::
++ bloq
|= snap=snapshot:jael
^- @ud
^- (unit @ud)
=- ?:(?=(%| -.out) ~ (some p.out))
^= out %- mule |.
latest-block.snap
:: +czar:snap:dawn: extract galaxy table
::
++ czar
|= snap=snapshot:jael
^- (map ship [=life =pass])
%- malt
^- (unit (map ship [=life =pass]))
=- ?:(?=(%| -.out) ~ (some p.out))
^= out %- mule |.
%- ~(gas by *(map ship [=life =pass]))
%+ turn (gulf 0 255)
|= gal=@
^- [ship [life pass]]
@ -8338,26 +8383,24 @@
::
++ hull
|= [who=ship snap=snapshot:jael]
^- hull:constitution:ethe
=/ res (~(get by hul.eth.snap) who)
?~ res
~& ['hull not found in snapshot; can\'t verify' who=who]
!!
u.res
^- (unit hull:constitution:ethe)
(~(get by hul.eth.snap) who)
:: +turf:snap:dawn: extract network domains
::
++ turf
|= snap=snapshot:jael
^- (list ^turf)
^- (unit (list ^turf))
=- ?:(?=(%| -.out) ~ (some p.out))
^= out %- mule |.
%+ murn
^- (list (pair))
^- (list host:eyre)
%+ murn
^- (list @t)
~[pri sec ter]:dns.eth.snap
|= dom=@t
^- (unit (pair))
^- (unit host:eyre)
(rush dom thos:de-purl:html)
|=([* a=*] ((soft ^turf) a))
|=(a=host:eyre ?:(?=(%| -.a) ~ (some p.a)))
--
:: +veri:dawn: validate keys, life, discontinuity, &c
::

View File

@ -104,7 +104,7 @@
'{"id":"0","jsonrpc":"2.0","result":"0x20"}'
=/ boq 32
%+ expect-eq
!> boq
!> [~ boq]
!> (bloq:take:dawn oct)
::
++ test-take-czar
@ -138,7 +138,8 @@
638.361.167.187.097.711.481.986.932.531.569.955.478.938.087.263.286.158.
823.313.739.767.009.446.819.531.923.255.637.798.148.055.143.938.146
%+ expect-eq
!> %- ~(gas by *(map ship [=life =pass]))
!> :- ~
%- ~(gas by *(map ship [=life =pass]))
[[~zod 1 zod.kyz] [~nec 1 nec.kyz] ~]
!> (czar:take:dawn oct)
::
@ -161,7 +162,7 @@
'"}'
==
%+ expect-eq
!> hul
!> [~ hul]
!> (hull:take:dawn ~zod oct)
::
++ test-take-turf
@ -183,27 +184,27 @@
'"}]'
==
%+ expect-eq
!> [/org/urbit ~]
!> [~ [/org/urbit ~]]
!> (turf:take:dawn oct)
::
++ test-snap-bloq
%+ expect-eq
!> 4.230.000
!> [~ 4.230.000]
!> (bloq:snap:dawn snap)
::
++ test-snap-hull
%+ expect-eq
!> hul
!> [~ hul]
!> (hull:snap:dawn ~zod snap)
::
++ test-snap-czar
%+ expect-eq
!> 256
!> ~(wyt by (czar:snap:dawn snap))
!> ~(wyt by (need (czar:snap:dawn snap)))
::
++ test-snap-turf
%+ expect-eq
!> `(list turf)`~[~['org' 'urbit'] ~['org' 'urbit']]
!> [~ `(list turf)`~[~['org' 'urbit'] ~['org' 'urbit']]]
!> (turf:snap:dawn snap)
::
++ test-veri-good