Skip to content

Commit

Permalink
Problem: not clear to user when their event is pending consensus
Browse files Browse the repository at this point in the history
  • Loading branch information
gsovereignty committed Nov 19, 2023
1 parent ddf5731 commit 7684946
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 17 deletions.
4 changes: 3 additions & 1 deletion src/components/modals/AddIdentity.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@
"df56b7c6a3d12ef1569f3c3a3704ac2e19faf65839891edd5b14aed12318d202",
"84d26cfbad4acb37a1fb8ebc2eb6e8286c130863a8995897773fb6bda2c08107",
"b4f36e2a63792324a92f3b7d973fcc33eaa7720aaeee71729ac74d7ba7677675",
"71df211931d26ee41121d295bd43cbc7e382505e333b5c13d4016ced9542d9d7"
"71df211931d26ee41121d295bd43cbc7e382505e333b5c13d4016ced9542d9d7",
//npub1ynpa8pjgnavltqq6tq8mhrnx4swsqsek2wlrylmrw6543vcgks2qaxtuuf
//npub149p5act9a5qm9p47elp8w8h3wpwn2d7s2xecw2ygnrxqp4wgsklq9g722q
]
</script>

Expand Down
1 change: 1 addition & 0 deletions src/lib/stores/nostrocket_state/hard_state/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export function HandleHardStateChangeRequest(
consensusMode: ConsensusMode
): [Nostrocket, TypeOfFailure, boolean] {
switch (ev.kind) {
case 1517:
case 15171031:
return HandleRocketIgnitionNote(ev, state, consensusMode);
}
Expand Down
37 changes: 29 additions & 8 deletions src/lib/stores/nostrocket_state/hard_state/rockets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ export function HandleRocketIgnitionNote(
state: Nostrocket,
consensusMode: ConsensusMode
): [Nostrocket, TypeOfFailure, boolean] {
if (!get(nostrocketParticipants).includes(ev.pubkey) && consensusMode != ConsensusMode.Scum) {
return [state, TypeOfFailure.SoftStateFailure, false]
if (consensusMode == 2) {console.log(ev.id)}
let r: Rocket | undefined = state.RocketMap.get(ev.id);
if (!r) {
r = new Rocket();
}
let newRocketName = labelledTag(ev, "name", "t");
if (!newRocketName) {
Expand All @@ -24,13 +26,25 @@ export function HandleRocketIgnitionNote(
//validate regex
return [state, TypeOfFailure.HardStateFailure, false];
}
if (!nameIsUnique(newRocketName, state)) {
if (!nameIsUnique(newRocketName, state) && r.UID != ev.id && consensusMode == ConsensusMode.ProvisionalScum) {
//if this is a consensus event, overwrite existing.
//if this is not a consensus event, fail.
return [state, TypeOfFailure.HardStateFailure, false];
}

if (
!get(nostrocketParticipants).includes(ev.pubkey) &&
consensusMode != ConsensusMode.Scum &&
consensusMode != ConsensusMode.ProvisionalScum
) {
console.log(ev.id)
return [state, TypeOfFailure.SoftStateFailure, false];
}
let taggedProblemID = labelledTag(ev, "problem", "e");
//if we are producing a consensus event, fail hard if can't verify problem creator == this pubkey
//if we are following a consensus event, only fail hard if problem creator is validated as someone other than this pubkey, fail soft if can't find the problem
if (taggedProblemID) {
console.log(ev.id)
if (taggedProblemID.length != 64) {
//problem tag is optional, but MUST be valid if defined
return [state, TypeOfFailure.HardStateFailure, false];
Expand All @@ -41,23 +55,30 @@ export function HandleRocketIgnitionNote(
}
if (problem) {
if (problem.CreatedBy != ev.pubkey) {
console.log(ev.id)
//if we have this problem locally, and it isn't created by the same pubkey as this event
return [state, TypeOfFailure.HardStateFailure, false];
}
}
}
let r = new Rocket();
if (consensusMode == ConsensusMode.ProvisionalScum) {
r.Consensus = false;
} else {
r.Consensus = true;
}
r.UID = ev.id;
r.CreatedBy = ev.pubkey;
r.Event = ev.rawEvent();
r.Maintainers.set(ev.pubkey, []);
if (taggedProblemID) {
r.ProblemID = taggedProblemID;
if(state.Problems.get(taggedProblemID)){
state.Problems.get(taggedProblemID)!.Rocket = r.UID
}}
if (state.Problems.get(taggedProblemID)) {
state.Problems.get(taggedProblemID)!.Rocket = r.UID;
}
}
r.Name = newRocketName;
state.RocketMap.set(ev.id, r);
if (consensusMode == 2) {console.log(ev.id)}
return [state, 0, true];
}

Expand All @@ -67,7 +88,7 @@ export function nameIsUnique(name: string, state?: Nostrocket): boolean {
}
for (let [s, r] of state.RocketMap) {
if (r.Name.toLowerCase() == name.toLowerCase()) {
return false
return false;
}
}
return true;
Expand Down
1 change: 1 addition & 0 deletions src/lib/stores/nostrocket_state/hard_state/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export enum ConsensusMode {
Producer = 0, //we have votepower and are attempting to add an event to consensus state
FollowerWithVotepower = 1, //we have votepower but we won't sign someone else's consensus event unless we can validate it
Scum = 2, //Just trust the votepower for now, and maybe roll things back if we need to
ProvisionalScum = 3, //this does not make it into consensus yet
}
18 changes: 12 additions & 6 deletions src/lib/stores/nostrocket_state/master_state.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@

import { labelledTag } from "$lib/helpers/shouldBeInNDK";
import { pubkeyHasVotepower } from "$lib/protocol_validators/rockets";
import { ndk_profiles } from "$lib/stores/event_sources/relays/profiles";
import { profiles } from "$lib/stores/hot_resources/profiles";
import { NDKRelaySet, type NDKUser } from "@nostr-dev-kit/ndk";
import { labelledTag } from "$lib/helpers/shouldBeInNDK";
import { pubkeyHasVotepower, validate } from "$lib/protocol_validators/rockets";
import type { NDKEvent } from "@nostr-dev-kit/ndk";
import type { NDKUser } from "@nostr-dev-kit/ndk";
import { Mutex } from "async-mutex";
import { derived, get, writable, type Readable } from "svelte/store";
import { kindsThatNeedConsensus } from "../event_sources/kinds";
import { allNostrocketEvents } from "../event_sources/relays/ndk";
import { changeStateMutex } from "./mutex";
import { Nostrocket, type Account } from "./types";

import { ignitionPubkey, nostrocketIgnitionEvent } from "../../../settings";
import { HandleHardStateChangeRequest } from "./hard_state/handler";
import { ConsensusMode } from "./hard_state/types";
import { HandleProblemEvent } from "./soft_state/simplifiedProblems";
import { ignitionPubkey, nostrocketIgnitionEvent, profileRelays } from "../../../settings";
import { HandleIdentityEvent } from "./soft_state/identity";
import { HandleProblemEvent } from "./soft_state/simplifiedProblems";

let r: Nostrocket = new Nostrocket();

Expand Down Expand Up @@ -90,7 +90,7 @@ async function watchMempool() {
) {
attempted.set(e[e.length - 1].id, true);
lastNumberOfEventsHandled = eventsHandled;
changeStateMutex("state:244").then((release) => {
changeStateMutex("state:93").then((release) => {
let current = get(consensusTipState);
let newstate = processSoftStateChangeReqeustsFromMempool(
current,
Expand All @@ -115,6 +115,9 @@ function processSoftStateChangeReqeustsFromMempool(
let copyOfState = currentState.Copy()
//todo clone not ref
switch (e.kind) {
case 1517:
case 15171031:
HandleHardStateChangeRequest(e, currentState, ConsensusMode.ProvisionalScum)
case 1592: {
if (HandleIdentityEvent(e, copyOfState)) {
currentState = copyOfState;
Expand Down Expand Up @@ -216,6 +219,7 @@ consensusNotes.subscribe((x) => {
if (requestEvent) {
let ok = HandleHardStateChangeEvent(requestEvent, current);
if (!ok) {
console.log("failed: ", requestEvent)
failed.update((f) => {
f.add(consensusNote.id);
return f;
Expand Down Expand Up @@ -255,6 +259,7 @@ export function HandleHardStateChangeEvent(
if (needsConsensus) {
let ok = false;
let typeOfFailure;
console.log(262, requestEvent.id);
[state, typeOfFailure, ok] = HandleHardStateChangeRequest(
requestEvent,
state,
Expand All @@ -264,6 +269,7 @@ export function HandleHardStateChangeEvent(
return true;
}
}
console.log(271)
return false;
}

Expand Down
1 change: 1 addition & 0 deletions src/lib/stores/nostrocket_state/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class Rocket {
Merits: { [key: string]: Merit };
Event: NostrEvent;
Participants: Map<Account, Account[]>;
Consensus:boolean;
constructor() {
this.Maintainers = new Map<Account, Account[]>();
this.Participants = new Map<Account, Account[]>();
Expand Down
5 changes: 3 additions & 2 deletions src/routes/rockets/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import { Rocket } from "carbon-pictograms-svelte";
import CreateRocket from "../../components/modals/CreateRocket.svelte";
import { consensusTipState } from "$lib/stores/nostrocket_state/master_state";
import { ConsensusMode } from "$lib/stores/nostrocket_state/hard_state/types";
</script>

<Row>
Expand All @@ -14,9 +15,9 @@
<Row>
{#each [...$consensusTipState.RocketMap] as [key, rocket]}
<Column max={8}>
<Tile style="margin:1px;">
<Tile style="margin:1px;" light={!rocket.Consensus}>
<!-- <Avatar ndk={$ndk} pubkey={rocket.CreatedBy} /> -->
<h3><Rocket />{rocket.Name}</h3>
<h3><Rocket />{#if !rocket.Consensus}[UNCONFIRMED] {/if}{rocket.Name}</h3>
<p>
<a href="{base}/problems/rocket/{rocket.Name}">View Open Problems</a><br />
{#if rocket.ProblemID}<a href="{base}/problems/{rocket.ProblemID}">View the root problem for this Rocket</a>{:else}No Associated Problem{/if}
Expand Down

0 comments on commit 7684946

Please sign in to comment.