Radish alpha
r
rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5
Radicle web interface
Radicle
Git
Only compare httpd or node state for deciding to run `checkState`
Merged did:key:z6MkkfM3...sVz5 opened 2 years ago

Also adds a e2e test that allows us to avoid running into this race condition again.

check check-visual check-unit-test check-httpd-api-unit-test check-e2e check-build

👉 Preview
👉 Workflow runs
👉 Branch on GitHub

2 files changed +35 -16 92895082 d7521a46
modified src/App/Header/NodeInfo.svelte
@@ -1,5 +1,5 @@
<script lang="ts">
-
  import type { Node } from "@httpd-client";
+
  import type { HttpdNodeState } from "@app/lib/httpd";

  import { capitalize } from "lodash";

@@ -9,7 +9,7 @@
  import Popover from "@app/components/Popover.svelte";
  import ScopePolicyExplainer from "@app/components/ScopePolicyExplainer.svelte";

-
  export let node: Node;
+
  export let node: HttpdNodeState;
</script>

<style>
@@ -46,23 +46,21 @@
        Your node is running and syncing with the network.
      </div>

-
      {#if node.config?.scope && node.config?.policy}
+
      {#if node.scope && node.policy}
        <div class="scope-policy">
          <div style:display="flex">
            Seeding Policy: <span style:margin-left="auto" class="txt-semibold">
-
              {capitalize(node.config.policy)}
+
              {capitalize(node.policy)}
            </span>
          </div>
          <div style:display="flex" style:margin-bottom="1rem">
            Scope:
            <span style:margin-left="auto" class="txt-semibold">
-
              {capitalize(node.config.scope)}
+
              {capitalize(node.scope)}
            </span>
          </div>

-
          <ScopePolicyExplainer
-
            scope={node.config.scope}
-
            policy={node.config.policy} />
+
          <ScopePolicyExplainer scope={node.scope} policy={node.policy} />
        </div>
      {/if}
      <div class="label">
modified src/lib/httpd.ts
@@ -1,4 +1,4 @@
-
import type { Node } from "@httpd-client";
+
import type { Node, Policy, Scope } from "@httpd-client";

import { get, writable } from "svelte/store";
import { withTimeout, Mutex, E_CANCELED, E_TIMEOUT } from "async-mutex";
@@ -13,13 +13,23 @@ export interface Session {
  alias: string;
}

+
export interface HttpdNodeState {
+
  id: Node["id"];
+
  state: Node["state"];
+
  policy: Policy | undefined;
+
  scope: Scope | undefined;
+
}
+

export type HttpdState =
  | { state: "stopped" }
-
  | { state: "running"; node: Node }
+
  | {
+
      state: "running";
+
      node: HttpdNodeState;
+
    }
  | {
      state: "authenticated";
      session: Session;
-
      node: Node;
+
      node: HttpdNodeState;
    };

const HTTPD_STATE_STORAGE_KEY = "httpdState";
@@ -60,7 +70,7 @@ export async function authenticate(params: {
        sig: params.signature,
        pk: params.publicKey,
      });
-
      const node = await api.getNode();
+
      const { id, state, config } = await api.getNode();
      const sess = await api.session.getById(params.id);
      update({
        state: "authenticated",
@@ -69,7 +79,7 @@ export async function authenticate(params: {
          publicKey: params.publicKey,
          alias: sess.alias,
        },
-
        node,
+
        node: { id, state, policy: config?.policy, scope: config?.scope },
      });
      return true;
    } catch (error) {
@@ -91,10 +101,15 @@ export async function disconnect() {

      try {
        await api.session.delete(httpd.session.id);
-
        const node = await api.getNode();
+
        const { id, state, config } = await api.getNode();
        update({
          state: "running",
-
          node,
+
          node: {
+
            id,
+
            state,
+
            policy: config?.policy,
+
            scope: config?.scope,
+
          },
        });
      } catch (error) {
        console.error(error);
@@ -126,7 +141,13 @@ async function checkState() {
  await stateMutex
    .runExclusive(async () => {
      try {
-
        const node = await api.getNode();
+
        const { id, state, config } = await api.getNode();
+
        const node = {
+
          id,
+
          state,
+
          policy: config?.policy,
+
          scope: config?.scope,
+
        };

        if (httpdState && httpdState.state !== "stopped") {
          httpdState.node = node;