Skip to content

Instantly share code, notes, and snippets.

@justusranvier
Last active February 26, 2022 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justusranvier/fbb16c477af135c8850a91419c019481 to your computer and use it in GitHub Desktop.
Save justusranvier/fbb16c477af135c8850a91419c019481 to your computer and use it in GitHub Desktop.
An Efficiently Searchable Network for Transactions

#Basis

OpenDHT

OpenDHT is a Kademlia-based DHT which creates a key-value store. Keys can be arbitrary, and values are allowed to collide. Network queries will return multiple values if more than one is associated with the same key.

#Design

The basic structure of OpenDHT can be used to create a network for efficient lookup of individual transactions by outpoint.

The purpose of the network is to answer two questions:

  1. Does the input to a transaction I've received actually exist?
  2. Has a given transaction output been spent?

Keys in this network are outpoint (txid + output index). A transaction matches an outpoint either if it creates the outpoint, or if it spends it.

This means for every query of a key in the network, the queriant would expect to receive zero, one, or two transactions in response.

Nodes which respond to a query package the transaction into a message which also contains the applicable merkle proofs to show which block mined the transaction(s) in question.

#Response format

The response to a query is in the form of a serialized protobuf message:

message QueryResult {
    repeated Transaction = 1;
}

message Transaction {
    optional MerkleProof = 1;
    bytes Data = 2;
}

message MerkleProof {
    oneof left {
        bytes lefthash = 1;
        MerkleProof leftchild = 2;
    }
    oneof right {
        bytes righthash = 3;
        MerkleProof rightchild = 4;
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment