Skip to content

Instantly share code, notes, and snippets.

View jcnelson's full-sized avatar

Jude Nelson jcnelson

View GitHub Profile
@jcnelson
jcnelson / appchain.clar
Last active October 17, 2021 12:23
appchain.clar
;; Appchain MVP mining contract! Appchain peers scan the host chain (the chain that stores this contract and its state)
;; to discover one another and the appchain block metadata. From there, the appchain's miners proceed to work on their
;; chain by sending contract-call's to this contract to store more block metadata.
;;
;; This contract essentially mimics the way Bitcoin behaves towards Stacks -- it's just a dumb data storage contract that
;; holds onto the same data that would go into Bitcoin transactions for mining. The only difference is that the appchain
;; uses STX as its underlying base currency for mining and PoX, instead of BTC.
(define-constant ERR_NO_RECIPIENTS u0)
(define-constant ERR_NO_COMMIT_SPEND u1)
@jcnelson
jcnelson / appchains.md
Last active February 2, 2023 05:09
Appchains

Revisions

  • Oct 19 2021: deployed MVP v2 of the appchain mining contract and updated the links and examples in this document to use it instead.

Introduction

Blockchains don't scale. The fact that all nodes process all transactions means that the blockchain only goes as fast as the slowest node allowed on the network. If that's something like a Raspberry Pi, then that's as fast as the blockchain goes.

And that's okay! The upside is that the more people can run nodes, the more resilient the blockchain will be. It's much harder to break a 10,000-node blockchain where most nodes run on home computers all across the world than a 10,000-node blockchain where most nodes run in a few datacenters.

@jcnelson
jcnelson / subnets.md
Last active February 13, 2025 06:02
Subnets

This is not to be confused with "subnets" that Hiro Systems is building. This is my own stab at building an off-chain causally-consistent asset trading system.


Disclaimer: I'm trying to flesh out a system that has only been described at a very high level. The purpose of this document is to write down notes on how I currently and tentatively believe subnets will work. This document is not authoritative, and may be significantly revised or even deleted.

All the credit for this approach goes to Aaron Blankstein. This document is based off of a conversation I had with him. I'm merely filling in the gaps.

What do we know about Subnets?

@jcnelson
jcnelson / how-stacking-helps-the-network.md
Created November 16, 2021 13:50
How Stacking Helps the Network

PoX can't occur unless the network is sufficiently stable. The only way to get PoX to start for a reward cycle is to confirm a PoX anchor block with 80% confidence within a 100-block window called the "prepare phase." Miners collectively determine the anchor block when they mine blocks that descend from it -- if PoX begins, there will be exactly one Stacks block in which at least 80 of the 100 sortitions in the prepare phase are its descendants. By deciding on an anchor block, miners collectively determine what the PoX reward set will be. But in order to choose an anchor block, they have to have it in their chainstate; otherwise, they'd be unable to mine a block that descends from it. Miners don't know what the anchor block will be until the end of the prepare phase, so this means that they need all of the Stacks blocks in order to begin the next PoX reward cycle (since any Stacks block can be the anchor block -- even one from many reward cycles ago).

At the same time, because Stacks blocks are stored a

@jcnelson
jcnelson / stackable-nft.md
Last active September 9, 2022 08:32
NFTrees: a Mineable, Stackable NFT

NFTrees

EDIT: So, I went ahead and built this out. Enjoy! https://github.com/jcnelson/nftree

Instead of minting NFTs as they are purchased, an NFT project can instantiate them all on chain through a new NFT data structure called an NFTree. An NFTree is an authenticated filesystem of NFTs, composed of files (the NFTs themselves) organized into a hierarchy of directories. There is a root directory that contains all NFTs and other directories. Each directory contains the Merkle root of a Merkle tree constructed over its immediate children, thereby ensuring that each directory cryptographically represents its subtree in the filesystem.

Each file in the NFTree commits to the following metadata about the NFT:

  • Its cryptographic hash
  • Its size, in bytes
@jcnelson
jcnelson / toml
Last active November 22, 2022 17:35
Stacks 2.1 Testnet Configuration
[node]
working_dir = "$PATH_TO_YOUR_CHAINSTATE"
rpc_bind = "0.0.0.0:20443"
p2p_bind = "0.0.0.0:20444"
seed = "$YOUR_BTC_PRIVATE_KEY"
local_peer_seed = "$SOME_OTHER_PRIVATE_KEY"
prometheus_bind = "0.0.0.0:9153"
mine_microblocks = true
wait_time_for_microblocks = 0
bootstrap_node = "027e929237cc4c12980b109bd3180ca591f3b72896b6e3716f5d1dce0a5bdd2dc4@next.stacks.org:20444"
@jcnelson
jcnelson / radon-2.1.md
Last active February 7, 2023 23:27
Radon-2.1

How to Participate in the Radon 2.1 Testnet

This gist describes how you can spin up a Stacks 2.1 node on the Bitcoin mainnet, and join a Radon testnet.

The Radon testnet behaves like the Stacks 2.1 mainnet will behave. It is based on the current 2.05 chain state, and is mined with real Bitcoin.

It is as close to a production environment as we can manage without hard-forking the mainnet chain.

BIG WARNING

@jcnelson
jcnelson / Nakamoto-WG.md
Last active September 18, 2023 15:59
Nakamoto WG

Last updated: 18 Sept 2023

This document describes the Nakamoto Workging Group for the Stacks Blockchain.

Members

  • @jcnelson (lead)
  • @kantai
  • @jferrant
  • @xoloki