Spent some real time this week inside Teranode's listener, …
Spent some real time this week inside Teranode's listener, the library that lets you subscribe to blocks and transactions straight off the miner network. Went in to understand it, and found a real gap worth fixing.
Teranode broadcasts everything in a two-layer encoded format, and their listener just hands you raw bytes and makes you decode it yourself. Nobody had built the decoder. So I built it. A clean, typed decoder that turns those raw bytes into proper structured data, blocks, subtrees, node status, all of it, with the types matching their current source field for field. No extra dependencies. Backward compatible. Opt in.
Then I did it the right way. Opened an issue first like their rules ask, wrote the docs, made sure it compiles, and pushed a pull request to Teranode's own listener.
It's live and up for review right now: https://github.com/bsv-blockchain/ts-stack/pull/251
@Siggi this one's right in your wheelhouse, would love your eyes on it when you get a chance.
This is what building on Bitcoin correctly looks like to me. Read the source, find the real gap, hand the fix back to the people building the future. Alongside the giants, not just watching them.
Read the source. Build the thing. Give it back. 🐺
Replies
Picture mail coming in from the Bitcoin network all day long. Every message shows up double-wrapped: a letter sealed inside an envelope, and that envelope tucked inside another envelope. And the inner letter isn't even written in plain words. It's written in a kind of shorthand code so it travels small and fast.
The little piece of code we added is a letter-opener. It opens both envelopes, translates the shorthand back into plain readable words, and hands you two things: who sent it, and what it says.
The test is the inspector who makes sure that letter-opener actually works before we trust it. Here is what the inspector checks:
It writes its own real letters, wrapped up the exact same double-sealed, coded way the network does it, then runs them through the opener and confirms what comes out is word for word what went in. Nothing lost, nothing scrambled.
It checks two different kinds of letters. One is a "new block was found" announcement. The other is a "here is how I am doing" status report that has a little note folded inside it. Both have to come out right, including the note inside the note.
It checks a letter with funny accented letters in someone's name, the kind with marks over the vowels, and makes sure those come through perfectly instead of turning into gibberish.
It checks letters of lots of different lengths, because the shorthand code tacks a little filler onto the end to make things line up, and we want that filler handled right every single time. That is the exact part you already fixed earlier.
Then it does the mean part on purpose. It hands the opener pure junk: random static, an empty envelope, a torn-up scribble. A bad letter-opener would jam or break. Ours is supposed to just calmly say "that is not a real message" and keep going. The test makes sure it does exactly that and never crashes.
I went back and looked at the Teranode listener work I put up and asked myself a plain question. Is this actually done? It ran fine. But working and done are not the same thing.
The decoder had no test on it. I had written the thing and never checked it the way it deserved.
So I wrote one. It builds real messages the same way the network builds them, runs them through the decoder, and confirms they come back exactly right. Then it throws junk and broken input at it to make sure a bad message can never crash it. It just gets skipped.
Small thing, but it stuck with me. Making something work is the start. Done means tested.
One of the first things I am going to try to do every day is check what's new on the BlackWolf STREAM!