From 7684946e549bda7c01febcabb5f7b2e487354428 Mon Sep 17 00:00:00 2001 From: gsovereignty Date: Sun, 19 Nov 2023 21:14:52 +0800 Subject: [PATCH] Problem: not clear to user when their event is pending consensus --- src/components/modals/AddIdentity.svelte | 4 +- .../nostrocket_state/hard_state/handler.ts | 1 + .../nostrocket_state/hard_state/rockets.ts | 37 +++++++++++++++---- .../nostrocket_state/hard_state/types.ts | 1 + .../stores/nostrocket_state/master_state.ts | 18 ++++++--- src/lib/stores/nostrocket_state/types.ts | 1 + src/routes/rockets/+page.svelte | 5 ++- 7 files changed, 50 insertions(+), 17 deletions(-) diff --git a/src/components/modals/AddIdentity.svelte b/src/components/modals/AddIdentity.svelte index 7969ea9..7b58050 100644 --- a/src/components/modals/AddIdentity.svelte +++ b/src/components/modals/AddIdentity.svelte @@ -244,7 +244,9 @@ "df56b7c6a3d12ef1569f3c3a3704ac2e19faf65839891edd5b14aed12318d202", "84d26cfbad4acb37a1fb8ebc2eb6e8286c130863a8995897773fb6bda2c08107", "b4f36e2a63792324a92f3b7d973fcc33eaa7720aaeee71729ac74d7ba7677675", - "71df211931d26ee41121d295bd43cbc7e382505e333b5c13d4016ced9542d9d7" + "71df211931d26ee41121d295bd43cbc7e382505e333b5c13d4016ced9542d9d7", + //npub1ynpa8pjgnavltqq6tq8mhrnx4swsqsek2wlrylmrw6543vcgks2qaxtuuf + //npub149p5act9a5qm9p47elp8w8h3wpwn2d7s2xecw2ygnrxqp4wgsklq9g722q ] diff --git a/src/lib/stores/nostrocket_state/hard_state/handler.ts b/src/lib/stores/nostrocket_state/hard_state/handler.ts index 4ce3fd5..f59a7fd 100644 --- a/src/lib/stores/nostrocket_state/hard_state/handler.ts +++ b/src/lib/stores/nostrocket_state/hard_state/handler.ts @@ -9,6 +9,7 @@ export function HandleHardStateChangeRequest( consensusMode: ConsensusMode ): [Nostrocket, TypeOfFailure, boolean] { switch (ev.kind) { + case 1517: case 15171031: return HandleRocketIgnitionNote(ev, state, consensusMode); } diff --git a/src/lib/stores/nostrocket_state/hard_state/rockets.ts b/src/lib/stores/nostrocket_state/hard_state/rockets.ts index 4818f90..84ee1ed 100644 --- a/src/lib/stores/nostrocket_state/hard_state/rockets.ts +++ b/src/lib/stores/nostrocket_state/hard_state/rockets.ts @@ -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) { @@ -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]; @@ -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]; } @@ -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; diff --git a/src/lib/stores/nostrocket_state/hard_state/types.ts b/src/lib/stores/nostrocket_state/hard_state/types.ts index 86b230d..30a8886 100644 --- a/src/lib/stores/nostrocket_state/hard_state/types.ts +++ b/src/lib/stores/nostrocket_state/hard_state/types.ts @@ -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 } diff --git a/src/lib/stores/nostrocket_state/master_state.ts b/src/lib/stores/nostrocket_state/master_state.ts index 0d6f80f..ed5ec01 100644 --- a/src/lib/stores/nostrocket_state/master_state.ts +++ b/src/lib/stores/nostrocket_state/master_state.ts @@ -1,10 +1,10 @@ +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"; @@ -12,11 +12,11 @@ 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(); @@ -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, @@ -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; @@ -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; @@ -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, @@ -264,6 +269,7 @@ export function HandleHardStateChangeEvent( return true; } } + console.log(271) return false; } diff --git a/src/lib/stores/nostrocket_state/types.ts b/src/lib/stores/nostrocket_state/types.ts index 185d14a..0d4e844 100644 --- a/src/lib/stores/nostrocket_state/types.ts +++ b/src/lib/stores/nostrocket_state/types.ts @@ -42,6 +42,7 @@ export class Rocket { Merits: { [key: string]: Merit }; Event: NostrEvent; Participants: Map; + Consensus:boolean; constructor() { this.Maintainers = new Map(); this.Participants = new Map(); diff --git a/src/routes/rockets/+page.svelte b/src/routes/rockets/+page.svelte index 3d3bf49..de3db09 100644 --- a/src/routes/rockets/+page.svelte +++ b/src/routes/rockets/+page.svelte @@ -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"; @@ -14,9 +15,9 @@ {#each [...$consensusTipState.RocketMap] as [key, rocket]} - + -

{rocket.Name}

+

{#if !rocket.Consensus}[UNCONFIRMED] {/if}{rocket.Name}

View Open Problems
{#if rocket.ProblemID}View the root problem for this Rocket{:else}No Associated Problem{/if}