graph-store: normalize @da in indices

As links is the only application currently using graph-store, we migrate
all indices to @da instead of a @da or a unix timestamp. Rolls over
current graphs and update log to rectify this. Additionally, applies the
link validator mark to graphs, as this was missing. Fixes a latent bug
in graph-store where the removal of a graph that triggered a mark build
would prevent the mark from being rebuilt. Fixes mark input and index
formatting from the frontend as well.
This commit is contained in:
Liam Fitzgerald 2020-10-29 14:07:47 +10:00
parent fbf505c0d9
commit b768cd3dd0
3 changed files with 126 additions and 15 deletions

View File

@ -34,23 +34,104 @@
^- (quip card _this) ^- (quip card _this)
=+ !<(old=versioned-state old-vase) =+ !<(old=versioned-state old-vase)
=| cards=(list card) =| cards=(list card)
|- |^
?- -.old ?- -.old
%0 %0
%_ $ %_ $
-.old %1 -.old %1
::
validators.old
(~(put in validators.old) %graph-validator-link)
::
cards
%+ weld cards
%+ turn
~(tap in (~(put in validators.old) %graph-validator-link))
|= validator=@t
^- card
=/ =wire /validator/[validator]
=/ =rave:clay [%sing %b [%da now.bowl] /[validator]]
[%pass wire %arvo %c %warp our.bowl [%home `rave]]
:: ::
graphs.old graphs.old
%- ~(run by graphs.old) %- ~(run by graphs.old)
|= [=graph:store q=(unit mark)] |= [=graph:store q=(unit mark)]
^- [graph:store (unit mark)] ^- [graph:store (unit mark)]
:- graph :- (convert-unix-timestamped-graph graph)
?^ q q ?^ q q
`%graph-validator-link `%graph-validator-link
::
update-logs.old
%- ~(run by update-logs.old)
convert-unix-timestamped-log
== ==
:: ::
%1 [cards this(state old)] %1 [cards this(state old)]
== ==
::
++ convert-unix-timestamped-log
|= =update-log:store
^- update-log:store
%+ gas:orm-log *update-log:store
%+ turn
(tap:orm-log update-log)
|= [=time =logged-update:store]
:- time
|^ ^- logged-update:store
:+ %0 p.logged-update
?+ -.q.logged-update q.logged-update
%add-nodes (add-nodes +.q.logged-update)
%remove-nodes (remove-nodes +.q.logged-update)
==
::
++ add-nodes
|= [rid=res nodes=(map index:store node:store)]
^- logged-update-0:store
:+ %add-nodes rid
%- ~(gas by *(map index:store node:store))
%+ turn
~(tap by nodes)
|= [=index:store =node:store]
^- [index:store node:store]
:- (turn index maybe-unix-to-da)
(convert-unix-timestamped-node node)
::
++ remove-nodes
|= [rid=res indices=(set index:store)]
^- logged-update-0:store
:+ %remove-nodes rid
%- ~(gas in *(set index:store))
%+ turn
~(tap in indices)
|=(=index:store (turn index maybe-unix-to-da))
--
::
++ maybe-unix-to-da
|= =atom
^- @
:: (bex 127) is roughly 226AD
?. (lte atom (bex 127))
atom
(add ~1970.1.1 (div (mul ~s1 atom) 1.000))
::
++ convert-unix-timestamped-node
|= =node:store
^- node:store
?. ?=(%graph -.children.node)
node
:+ post.node %graph
(convert-unix-timestamped-graph p.children.node)
::
++ convert-unix-timestamped-graph
|= =graph:store
%+ gas:orm *graph:store
%+ turn
(tap:orm graph)
|= [=atom =node:store]
^- [^atom node:store]
:- (maybe-unix-to-da atom)
(convert-unix-timestamped-node node)
--
:: ::
++ on-watch ++ on-watch
~/ %graph-store-watch ~/ %graph-store-watch
@ -124,7 +205,7 @@
:~ (give [/updates /keys ~] [%add-graph resource graph mark]) :~ (give [/updates /keys ~] [%add-graph resource graph mark])
?~ mark ~ ?~ mark ~
?: (~(has in validators) u.mark) ~ ?: (~(has in validators) u.mark) ~
=/ wire (weld /graph (en-path:res resource)) =/ wire /validator/[u.mark]
=/ =rave:clay [%sing %b [%da now.bowl] /[u.mark]] =/ =rave:clay [%sing %b [%da now.bowl] /[u.mark]]
[%pass wire %arvo %c %warp our.bowl [%home `rave]]~ [%pass wire %arvo %c %warp our.bowl [%home `rave]]~
== ==
@ -622,15 +703,15 @@
++ on-arvo ++ on-arvo
|= [=wire =sign-arvo] |= [=wire =sign-arvo]
^- (quip card _this) ^- (quip card _this)
?+ -.sign-arvo (on-arvo:def wire sign-arvo) ?+ wire (on-arvo:def wire sign-arvo)
%c ::
:: old wire, do nothing
[%graph *] [~ this]
::
[%validator @ ~]
:_ this :_ this
?> ?=([%graph @ *] wire) =* validator i.t.wire
=/ =resource:store (de-path:res t.wire) =/ =rave:clay [%sing %b [%da now.bowl] /[validator]]
=/ gra=(unit marked-graph:store) (~(get by graphs) resource)
?~ gra ~
?~ q.u.gra ~
=/ =rave:clay [%next %b [%da now.bowl] /[u.q.u.gra]]
[%pass wire %arvo %c %warp our.bowl [%home `rave]]~ [%pass wire %arvo %c %warp our.bowl [%home `rave]]~
== ==
:: ::

View File

@ -4,12 +4,12 @@ import { Patp, Path, PatpNoSig } from '~/types/noun';
import _ from 'lodash'; import _ from 'lodash';
import {makeResource, resourceFromPath} from '../lib/group'; import {makeResource, resourceFromPath} from '../lib/group';
import {GroupPolicy, Enc, Post, NodeMap} from '~/types'; import {GroupPolicy, Enc, Post, NodeMap} from '~/types';
import { numToUd } from '~/logic/lib/util'; import { numToUd, unixToDa } from '~/logic/lib/util';
export const createPost = (contents: Object[], parentIndex: string = '') => { export const createPost = (contents: Object[], parentIndex: string = '') => {
return { return {
author: `~${window.ship}`, author: `~${window.ship}`,
index: parentIndex + '/' + Date.now(), index: parentIndex + '/' + unixToDa(Date.now()).toString(),
'time-sent': Date.now(), 'time-sent': Date.now(),
contents, contents,
hash: null, hash: null,
@ -17,6 +17,16 @@ export const createPost = (contents: Object[], parentIndex: string = '') => {
}; };
}; };
function moduleToMark(mod: string): string | undefined {
if(mod === 'link') {
return 'graph-validator-link';
}
if(mod === 'publish') {
return 'graph-validator-publish';
}
return undefined;
}
export default class GraphApi extends BaseApi<StoreState> { export default class GraphApi extends BaseApi<StoreState> {
private storeAction(action: any): Promise<any> { private storeAction(action: any): Promise<any> {
@ -47,7 +57,8 @@ export default class GraphApi extends BaseApi<StoreState> {
title, title,
description, description,
associated, associated,
"module": mod "module": mod,
mark: moduleToMark(mod)
} }
}); });
} }
@ -67,7 +78,8 @@ export default class GraphApi extends BaseApi<StoreState> {
title, title,
description, description,
associated: { policy }, associated: { policy },
"module": mod "module": mod,
mark: moduleToMark(mod)
} }
}); });
} }

View File

@ -1,8 +1,26 @@
import _ from 'lodash'; import _ from 'lodash';
import f from 'lodash/fp'; import f from 'lodash/fp';
import bigInt from 'big-integer';
export const MOBILE_BROWSER_REGEX = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i; export const MOBILE_BROWSER_REGEX = /Android|webOS|iPhone|iPad|iPod|BlackBerry/i;
const DA_UNIX_EPOCH = bigInt("170141184475152167957503069145530368000"); // `@ud` ~1970.1.1
const DA_SECOND = bigInt("18446744073709551616"); // `@ud` ~s1
export function daToUnix(da) {
// ported from +time:enjs:format in hoon.hoon
const offset = DA_SECOND.divide(bigInt(2000));
const epochAdjusted = offset.add(da.subtract(DA_UNIX_EPOCH));
return Math.round(
epochAdjusted.multiply(bigInt(1000)).divide(DA_SECOND).toJSNumber()
);
}
export function unixToDa(unix) {
const timeSinceEpoch = bigInt(unix).multiply(DA_SECOND).divide(bigInt(1000));
return DA_UNIX_EPOCH.add(timeSinceEpoch);
}
export function appIsGraph(app) { export function appIsGraph(app) {
return app === 'link' || app === 'publish'; return app === 'link' || app === 'publish';
} }