Skip to content

Commit

Permalink
contacts: fix incorrect profile timestamp after migration
Browse files Browse the repository at this point in the history
During %0 to %1 migration, empty profiles have been wrongly
migrated with bunted timestamp, causing the subscribers
to crash on resubscription due to a failing assert. We
fix this by introducing several changes:
- bump the state number to %2
- initalize the profile with correct now.bowl timestamp in +on-init
- deploy migration to fix affected profiles
- re-enable the assertion prohibiting subscriptions
  to a future-dated profile

Additionally, the +subs:pub arm is amended to never generate
an empty path list for a fact.
  • Loading branch information
mikolajpp committed Oct 29, 2024
1 parent 430d56d commit 6f47856
Showing 1 changed file with 74 additions and 49 deletions.
123 changes: 74 additions & 49 deletions desk/app/contacts.hoon
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
::
+| %types
+$ card card:agent:gall
+$ state-1 $: %1
+$ state-2 $: %2
rof=profile
=book
=peers
Expand All @@ -30,7 +30,7 @@
%- agent:dbug
%+ verb |
^- agent:gall
=| state-1
=| state-2
=* state -
=< |_ =bowl:gall
+* this .
Expand Down Expand Up @@ -132,7 +132,10 @@
++ subs
^- (set path)
%- ~(rep by sup.bowl)
|= [[duct ship pat=path] acc=(set path)]
:: default .acc prevents invalid empty fact path in the case
:: of no subscribers
::
|= [[duct ship pat=path] acc=_(sy `path`/v1/contact ~)]
?.(?=([%v1 %contact *] pat) acc (~(put in acc) pat))
++ fact
|= [pat=(set path) u=update]
Expand Down Expand Up @@ -208,7 +211,6 @@
|= con=contact
=/ p=profile [(mono wen.rof now.bowl) con]
=. rof p
::
=. cor
(p-news-0 our.bowl (contact:to-0 con))
=. cor
Expand Down Expand Up @@ -239,8 +241,10 @@
++ p-init
|= wen=(unit @da)
?~ wen (give (fact ~ full+rof))
?: (gte u.wen wen.rof) cor
(give (fact ~ full+rof))
?: =(u.wen wen.rof) cor
::
:: no future subs
?>((lth u.wen wen.rof) (give (fact ~ full+rof)))
:: +p-news-0: [legacy] publish news
::
++ p-news-0
Expand Down Expand Up @@ -442,6 +446,7 @@
+| %implementation
::
++ init
=. wen.rof now.bowl
(emit %pass /migrate %agent [our dap]:bowl %poke noun+!>(%migrate))
::
++ load
Expand All @@ -451,60 +456,80 @@
=? cor !=(okay cool) l-epic
?- -.old
::
%1
=. state old
=/ cards
%+ roll ~(tap by peers)
|= [[who=ship foreign] caz=(list card)]
:: intent to connect, resubscribe
::
?: ?& =(%want sag)
!(~(has by wex.bowl) [/contact who dap.bowl])
==
=/ =path [%v1 %contact ?~(for / /at/(scot %da wen.for))]
:_ caz
[%pass /contact %agent [who dap.bowl] %watch path]
caz
(emil cards)
%2
=. state old
inflate-io
::
%0
=. rof ?~(rof.old *profile (profile:from-0 rof.old))
:: migrate peers. for each peer
:: 1. leave /epic, if any
:: 2. subscribe if desired
:: 3. put into peers
%1
=. state old(- %2)
:: fix incorrectly bunted timestamp for
:: an empty profile migrated from %0
::
=? cor &(=(*@da wen.rof) ?=(~ con.rof))
(p-commit-self:pub ~)
inflate-io
::
=^ caz=(list card) peers
%+ roll ~(tap by rol.old)
|= [[who=ship foreign-0:c0] caz=(list card) =_peers]
:: leave /epic if any
%0
=. rof ?~(rof.old *profile (profile:from-0 rof.old))
:: migrate peers. for each peer
:: 1. leave /epic, if any
:: 2. subscribe if desired
:: 3. put into peers
::
=? caz (~(has by wex.bowl) [/epic who dap.bowl])
=^ caz=(list card) peers
%+ roll ~(tap by rol.old)
|= [[who=ship foreign-0:c0] caz=(list card) =_peers]
:: leave /epic if any
::
=? caz (~(has by wex.bowl) [/epic who dap.bowl])
:_ caz
[%pass /epic %agent [who dap.bowl] %leave ~]
=/ fir=$@(~ profile)
?~ for ~
(profile:from-0 for)
:: no intent to connect
::
?: =(~ sag)
:- caz
(~(put by peers) who fir ~)
:_ (~(put by peers) who fir %want)
?: (~(has by wex.bowl) [/contact who dap.bowl])
caz
=/ =path [%v1 %contact ?~(fir / /at/(scot %da wen.fir))]
:_ caz
[%pass /epic %agent [who dap.bowl] %leave ~]
=/ fir=$@(~ profile)
?~ for ~
(profile:from-0 for)
:: no intent to connect
::
?: =(~ sag)
:- caz
(~(put by peers) who fir ~)
:_ (~(put by peers) who fir %want)
?: (~(has by wex.bowl) [/contact who dap.bowl])
caz
=/ =path [%v1 %contact ?~(fir / /at/(scot %da wen.fir))]
:_ caz
[%pass /contact %agent [who dap.bowl] %watch path]
(emil caz)
[%pass /contact %agent [who dap.bowl] %watch path]
(emil caz)
==
+$ state-0 [%0 rof=$@(~ profile-0:c0) rol=rolodex:c0]
+$ state-1 $: %1
rof=profile
=^book
=^peers
retry=(map ship @da) :: retry sub at time
==
+$ versioned-state
$% state-0
$% state-2
state-1
state-0
==
::
++ l-epic (give %fact [/epic ~] epic+!>(okay))
::
++ inflate-io
^+ cor
=/ cards
%+ roll ~(tap by peers)
|= [[who=ship foreign] caz=(list card)]
:: intent to connect, resubscribe
::
?: ?& =(%want sag)
!(~(has by wex.bowl) [/contact who dap.bowl])
==
=/ =path [%v1 %contact ?~(for / /at/(scot %da wen.for))]
:_ caz
[%pass /contact %agent [who dap.bowl] %watch path]
caz
(emil cards)
--
::
++ poke
Expand Down

0 comments on commit 6f47856

Please sign in to comment.