Skip to content

Commit

Permalink
problem: many lines are too long: solution: lint.
Browse files Browse the repository at this point in the history
  • Loading branch information
gsovereignty committed Nov 11, 2023
1 parent 766117d commit adfde36
Show file tree
Hide file tree
Showing 42 changed files with 1,645 additions and 1,322 deletions.
50 changes: 28 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,64 +6,69 @@ Problem: spaceman is not maintainable and it's getting annoying
npm install
npm run dev
```

## Contributing

Please avoid ambiguity over Types: use TypeScript and avoid plain untyped JS.

When returning multiple values and one of those values is an indication of validation, put it **last** in the list:
When returning multiple values and one of those values is an indication of validation, put it **last** in the list:

```
//rocketIgnitionEvent takes a state change request event and the current state;
//rocketIgnitionEvent takes a state change request event and the current state;
//returns the new state and a boolean indicating successful state change
//function rocketIgnitionEvent(ev: NDKEvent, state: Nostrocket): [Nostrocket, boolean]
```


## Terminology
**note**: a nostr event.

**State Change Request**: a *note* requesting a change to the current nostrocket state, for example a Merit Request, logging a Problem, adding a pubkey to the Identity Tree, etc.
**note**: a nostr event.

**Consensus Chain**: a linked list of notes called [Consensus Notes](https://github.com/nostrocket/NIPS/blob/main/Rockets.md#consensus-event). Each note in the list points (with a labelled `e` tag) to at least one *State Change Request*. We build our local state by parsing these State Change Requests against the Nostrocket Unprotocol.
**State Change Request**: a _note_ requesting a change to the current nostrocket state, for example a Merit Request, logging a Problem, adding a pubkey to the Identity Tree, etc.

**Hard State**: this is the state which exists as a [Consensus Chain](https://github.com/nostrocket/NIPS/blob/main/Rockets.md#consensus-over-state) and SHOULD be eventually consistent across all participant's instances of a Rocket.
**Consensus Chain**: a linked list of notes called [Consensus Notes](https://github.com/nostrocket/NIPS/blob/main/Rockets.md#consensus-event). Each note in the list points (with a labelled `e` tag) to at least one _State Change Request_. We build our local state by parsing these State Change Requests against the Nostrocket Unprotocol.

A *State Change Request* that indends to modify *Hard State* only does so when someone with *Votepower* within that particular Rocket includes it in their *Consensus Chain*.
**Hard State**: this is the state which exists as a [Consensus Chain](https://github.com/nostrocket/NIPS/blob/main/Rockets.md#consensus-over-state) and SHOULD be eventually consistent across all participant's instances of a Rocket.

This type of state should be used sparingly. Any state that doesn't require a high degree of consensus among participants should *not* use Hard State.
A _State Change Request_ that indends to modify _Hard State_ only does so when someone with _Votepower_ within that particular Rocket includes it in their _Consensus Chain_.

Hard State is currently used for state that is in the critical path to Votepower: Rocket creation; Merit requests, votes on merit requests, transfer of merits to other pubkeys.
This type of state should be used sparingly. Any state that doesn't require a high degree of consensus among participants should _not_ use Hard State.

**Hard State Change Request** is a *State Change Request* intended to modify *Hard State*.
Hard State is currently used for state that is in the critical path to Votepower: Rocket creation; Merit requests, votes on merit requests, transfer of merits to other pubkeys.

**Soft State**: There is no consensus over this state and it is not included in a Consensus Chain, but it can be considered *eventually consistent enough* for most nostrocket activity. Examples of where it's currently used: Identity Tree, Problem Tracker (logging new problems, modifying problems, etc).
**Hard State Change Request** is a _State Change Request_ intended to modify _Hard State_.

**Soft State Change Request** is a *State Change Request* intended to modify *Soft State*.
**Soft State**: There is no consensus over this state and it is not included in a Consensus Chain, but it can be considered _eventually consistent enough_ for most nostrocket activity. Examples of where it's currently used: Identity Tree, Problem Tracker (logging new problems, modifying problems, etc).

**Session State**: This is for convenience only, it is local to the browser and not persisted as notes. The only current example of this in nostrocket is the current user's profile, which we use for producing notes etc.
**Soft State Change Request** is a _State Change Request_ intended to modify _Soft State_.

**Session State**: This is for convenience only, it is local to the browser and not persisted as notes. The only current example of this in nostrocket is the current user's profile, which we use for producing notes etc.

## How it fits together

All Nostrocket notes SHOULD point to `note1r0cketrztzx06l3uxd4c2j86fxsfvfls8klsd3aylm38hsqewtyqyp7wj7` so they can be found easily.

Hard State begins with a `kind 15171031` [Rocket Ignition Event](https://github.com/nostrocket/NIPS/blob/main/Rockets.md). Nostrocket itself is a Rocket created by one of these events.

The pubkey that signs a Rocket Ignition Event is called the *Ignition Pubkey*. The Ignition Pubkey that creates a new Rocket always begins with a Votepower of `1` (only applicable within that particular Rocket).
The pubkey that signs a Rocket Ignition Event is called the _Ignition Pubkey_. The Ignition Pubkey that creates a new Rocket always begins with a Votepower of `1` (only applicable within that particular Rocket).

As the Ignition Pubkey is the only pubkey with Votepower when a new Rocket is created, anyone wanting to view the current Hard State for that particular Rocket should begin by following this pubkey's Consensus Chain, adding and removing further pubkeys along the way as the state of the Rocket changes (the client does this automagically). For additional mallorysistance, users can add their Bitcoin node details to validate OP_RETURNS signed by pubkeys with votepower.

Before adding State Change Requests to their Consensus Chain, a pubkey with votepower MUST validate the request against the Nostrocket Unprotocol (encoded into Oxygen logic) within the context of the current global Hard State AND their current subjective view of Soft State.
Before adding State Change Requests to their Consensus Chain, a pubkey with votepower MUST validate the request against the Nostrocket Unprotocol (encoded into Oxygen logic) within the context of the current global Hard State AND their current subjective view of Soft State.

Thus, while there's no consensus over Soft State, it's still somewhat relevant (but not critical) to consensus over Hard State.
Thus, while there's no consensus over Soft State, it's still somewhat relevant (but not critical) to consensus over Hard State.

Soft State is simply updated by Soft State Change Requests if they pass local validation after being received from a Relay. This validation can involve validation against the Nostrocket Unprotocol, the current Hard and Soft state, and user settings.

## Note Sources and Routing
Everything in Oxygen is *Note driven*. These notes come from relays, and are handled differently depending on whether they are *Consensus Notes*, *Hard State Change Requests*, or *Soft State Change Requests*.

First, we subscribe to all Relays using all relevant filters. Then we buffer, route, and handle the incoming notes appropriately.
Everything in Oxygen is _Note driven_. These notes come from relays, and are handled differently depending on whether they are _Consensus Notes_, _Hard State Change Requests_, or _Soft State Change Requests_.

First, we subscribe to all Relays using all relevant filters. Then we buffer, route, and handle the incoming notes appropriately.

We take the stream of notes from our Relays, filter out anything that doesn't look valid, and buffer the result in mempool.
We take the stream of notes from our Relays, filter out anything that doesn't look valid, and buffer the result in mempool.

### Hard State

We listen to the mempool for any valid Consensus Notes (signed by a pubkey with votepower in our current Hard State AND points to that pubkey's last Consensus Note for that particular Rocket). We find the Hard State Change Request that this Consensus Note has included in an `e` tag with the label `request`, and then we fetch that Note from mempool (it SHOULD be in mempool). We handle that Hard State Change Request. If it fails, we halt and catch fire. If the currently logged in user has votepower, we publish Consensus Events to add these Hard State Change Events to our own Consensus Chain at this time.

We keep repeating this until there are no new Consensus Notes. Each pubkey can also publish their latest Consensus Note ID and height in a replaceable event so that we know when we've reached the tip. We keep listening for these Consensus Notes and handle them whenever they come in.
Expand All @@ -73,10 +78,11 @@ The **Consensus Lead** is the pubkey with the highest Votepower from the set of
If we (the currently logged in user) has the Consensus Lead, then once we've reached the current tip of a valid Consensus Chain, we start producing Consensus Events to add any waiting Hard State Change Requests (in mempool) to our Consensus Chain (after validating them of course). We do not update our local state directly during this process, we instead wait for our own Consensus Notes to arrive from a Relay and handle them as per the above. This is to keep the logic all in the same place and make things more simple.

### Soft State

We can handle Soft State Change Requests asynchronously in the background at the same time as Hard State Change Requests.

We listen to mempool for all seeminlgy valid Soft State Change Requests, and simply handle them by validating them against the Nostrocket Unprotocol in the context of the current Hard and Soft state.

### Best Practices
* If a Note sucessfully causes any kind of State to change, remove it from our mempool, and add it to a list (or cuckoo filter) of notes that have been handled, so that we don't handle them more than once.

- If a Note sucessfully causes any kind of State to change, remove it from our mempool, and add it to a list (or cuckoo filter) of notes that have been handled, so that we don't handle them more than once.
2 changes: 1 addition & 1 deletion postcss.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ export default {
tailwindcss: {},
autoprefixer: {},
},
}
};
15 changes: 8 additions & 7 deletions src/components/elements/Profile.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
}
}
</script>

<Column max={4} lg={4} md={4} sm={16} aspectRatio="2x1">
<Row style="height:99%;padding:2px;">
<Tile style="width:100%; height:100%;overflow:hidden;">
Expand All @@ -26,13 +27,13 @@
<AspectRatio ratio="1x1" style="width:100%;">
<Tile light>
<a href="https://nostr.band/?q={profile.npub}">
<div style="text-align:center;overflow:hidden;">
<h6>{profile.profile?.name}</h6>
</div>
<div style="margin:2%;">
<ImageLoader fadeIn ratio="1x1" src={avatarUrl} />
</div>
</a>
<div style="text-align:center;overflow:hidden;">
<h6>{profile.profile?.name}</h6>
</div>
<div style="margin:2%;">
<ImageLoader fadeIn ratio="1x1" src={avatarUrl} />
</div>
</a>
<!-- <img src={profile.profile?.image} width="100%" height="auto" alt="[profile pic here]"> -->
<!-- <Avatar ndk={$ndk} user={profile}/> -->
</Tile>
Expand Down
Loading

0 comments on commit adfde36

Please sign in to comment.