Test-Driven Protocol Design

A suggestion for making the Nostr protocol more agile.

Laeserin

21. Juli 2024July 21, 2024 · 6 Min. Lesezeit6 min read

My suggestion for scaling up and staying humble

The original protocol design was "good enough for now"#

When Nostr was invented and got started with developing implementations, the Original Devs (ODs) were convinced this was going to be big... maybe... someday... hopefully.

But, whatever they did at the moment should definitely scale up a bit and be a bit flexible, to attract innovators and keep up the momentum. So, they designed the protocol to be open and left the specifications a bit vague and very high-level, so that nobody was forced into a particular implementation, in order to adhere to the spec. And they put the specs into a GitHub repository and managed them by a committee of collaborators, who were generally open to changes to the specs, including breaking changes.

That was smart. And it was "good enough for now"... back then. After all, Nostr (and the associated wiki and modular article specs) hadn't been invented, yet, so they couldn't write the protocol in the protocol before the protocol existed. They're good, but not that good.

What they specifically wrote, into the Nostr Protocol was:

To promote interoperability, we standards (sic) that everybody can follow, and we need them to define a single way of doing each thing without ever hurting backwards-compatibility, and for that purpose there is no way around getting everybody to agree on the same thing and keep a centralized index of these standards...

Standards may emerge in two ways: the first way is that someone starts doing something, then others copy it; the second way is that someone has an idea of a new standard that could benefit multiple clients and the protocol in general without breaking backwards-compatibility and the principle of having a single way of doing things, then they write that idea and submit it to this repository, other interested parties read it and give their feedback, then once most people reasonably agree we codify that in a NIP which client and relay developers that are interested in the feature can proceed to implement.

I disagree with this statement.

I don't disagree with what they meant, or what they wanted, I disagree with what they specifically wrote.

Standards (defined as prose specifications) are not the only -- or even best -- way to ensure interoperability or to check for backwards-compatibility. And, as they later note, basing a protocol off of implementations is arguably worse (but faster) than using specifications, as implementations have a life of their own and are sometimes simply shoddy or buggy, their content eventually differs from what ends up in the final standard, or there are soon multiple implementations covering the same spec "in theory", but not in practice, so that their events are incompatible.

And then the inevitable, heated discussion begins:

There is a third way: write the test first#

We actually do not need standards to define a single way of doing each thing. A test is another way, and I think it is the best (i.e. the most-efficient and most-effective) way.

Specifically, I think we can borrow the simple behavior-driven design (BDD) language called Gherkin (or something similar), which is used to write dynamic specifications: i.e. implementations that test adherence to a set of rules, rather than an implementation that uses the rules to perform some task for an end user.

Gherkin simply allows you to create standard scenarios and test data and write the tests up in a way that can be performed manually or through automation. For example ( source ): Gherkin example

(For a concrete example of such a TDD Protocol for Nostr, please see the nostr-voliere repo from ⁠Josua Schmid .)

This really is better#

This TDD Protocol design would have some downsides and some upsides, of course, like any change.

Downsides#

Upsides#

This is already a lot to think about, so I'm just going to end this here. Thank you for reading.

#BDD#Nostr#TDD#devs

Written by

Comments

No comments yet. Start the conversation.

Contents

3 sections

  1. The original protocol design was "good enough for now"
  2. There is a third way: write the test first
  3. This really is better