books: architecture skeleton (#224)

* upstream https://github.com/hinto-janai/cuprate-architecture

* tab -> 4 spaces
This commit is contained in:
hinto-janai 2024-07-18 16:35:52 -04:00 committed by GitHub
parent 88551c800c
commit 0a88ea13fc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
85 changed files with 401 additions and 14 deletions

View file

@ -1,4 +1,4 @@
## Cuprate's architecture (implementation) book ## Cuprate's architecture book
This book documents Cuprate's architecture and implementation. This book documents Cuprate's architecture and implementation.
See: See:

View file

@ -1,19 +1,17 @@
[book] [book]
authors = ["hinto-janai"] authors = ["Cuprate Contributors"]
language = "en" language = "en"
multilingual = false multilingual = false
src = "src" src = "src"
title = "Cuprate Architecture" title = "Cuprate Architecture"
git-repository-url = "https://github.com/Cuprate/architecture-book" git-repository-url = "https://github.com/Cuprate/architecture-book"
# TODO: fix after importing real files. [preprocessor.last-changed]
# command = "mdbook-last-changed"
# [preprocessor.last-changed] renderer = ["html"]
# command = "mdbook-last-changed"
# renderer = ["html"] [output.html]
# default-theme = "ayu"
# [output.html] preferred-dark-theme = "ayu"
# default-theme = "ayu" git-repository-url = "https://github.com/Cuprate/architecture-book"
# preferred-dark-theme = "ayu" additional-css = ["last-changed.css"]
# git-repository-url = "https://github.com/hinto-janai/cuprate-architecture"
# additional-css = ["last-changed.css"]

View file

@ -0,0 +1,7 @@
footer {
font-size: 0.8em;
text-align: center;
border-top: 1px solid;
margin-top: 4%;
padding: 5px 0;
}

View file

@ -1,3 +1,124 @@
# Summary # Summary
- [TODO](todo.md) [Cuprate Architecture](cuprate-architecture.md)
[🟡 Foreword](foreword.md)
---
- [🟠 Intro](intro/intro.md)
- [🟡 Who this book is for](intro/who-this-book-is-for.md)
- [🔴 Required knowledge](intro/required-knowledge.md)
- [🔴 How to use this book](intro/how-to-use-this-book.md)
---
- [⚪️ Bird's eye view](birds-eye-view/intro.md)
- [⚪️ Map](birds-eye-view/map.md)
- [⚪️ Components](birds-eye-view/components.md)
---
- [⚪️ Formats, protocols, types](formats-protocols-types/intro.md)
- [⚪️ monero_serai](formats-protocols-types/monero-serai.md)
- [⚪️ cuprate_types](formats-protocols-types/cuprate-types.md)
- [⚪️ cuprate_helper](formats-protocols-types/cuprate-helper.md)
- [⚪️ Epee](formats-protocols-types/epee.md)
- [⚪️ Levin](formats-protocols-types/levin.md)
---
- [⚪️ Storage](storage/intro.md)
- [⚪️ Database abstraction](storage/database-abstraction.md)
- [⚪️ Blockchain](storage/blockchain.md)
- [⚪️ Transaction pool](storage/transaction-pool.md)
- [⚪️ Pruning](storage/pruning.md)
---
- [🔴 RPC](rpc/intro.md)
- [⚪️ Types](rpc/types/intro.md)
- [⚪️ JSON](rpc/types/json.md)
- [⚪️ Binary](rpc/types/binary.md)
- [⚪️ Other](rpc/types/other.md)
- [⚪️ Interface](rpc/interface.md)
- [⚪️ Router](rpc/router.md)
- [⚪️ Handler](rpc/handler.md)
- [⚪️ Methods](rpc/methods/intro.md)
---
- [⚪️ ZMQ](zmq/intro.md)
- [⚪️ TODO](zmq/todo.md)
---
- [⚪️ Consensus](consensus/intro.md)
- [⚪️ Verifier](consensus/verifier.md)
- [⚪️ TODO](consensus/todo.md)
---
- [⚪️ Networking](networking/intro.md)
- [⚪️ P2P](networking/p2p.md)
- [⚪️ Dandelion++](networking/dandelion.md)
- [⚪️ Proxy](networking/proxy.md)
- [⚪️ Tor](networking/tor.md)
- [⚪️ i2p](networking/i2p.md)
- [⚪️ IPv4/IPv6](networking/ipv4-ipv6.md)
---
- [🔴 Instrumentation](instrumentation/intro.md)
- [⚪️ Logging](instrumentation/logging.md)
- [⚪️ Data collection](instrumentation/data-collection.md)
---
- [⚪️ Binary](binary/intro.md)
- [⚪️ CLI](binary/cli.md)
- [⚪️ Config](binary/config.md)
- [⚪️ Logging](binary/logging.md)
---
- [⚪️ Resource model](resource-model/intro.md)
- [⚪️ File system](resource-model/file-system.md)
- [⚪️ Sockets](resource-model/sockets.md)
- [⚪️ Memory](resource-model/memory.md)
- [🟡 Concurrency and parallelism](resource-model/concurrency-and-parallelism/intro.md)
- [⚪️ Map](resource-model/concurrency-and-parallelism/map.md)
- [⚪️ The RPC server](resource-model/concurrency-and-parallelism/the-rpc-server.md)
- [⚪️ The database](resource-model/concurrency-and-parallelism/the-database.md)
- [⚪️ The block downloader](resource-model/concurrency-and-parallelism/the-block-downloader.md)
- [⚪️ The verifier](resource-model/concurrency-and-parallelism/the-verifier.md)
- [⚪️ Thread exit](resource-model/concurrency-and-parallelism/thread-exit.md)
---
- [⚪️ External Monero libraries](external-monero-libraries/intro.md)
- [⚪️ Cryptonight](external-monero-libraries/cryptonight.md)
- [🔴 RandomX](external-monero-libraries/randomx.md)
- [🔴 monero_serai](external-monero-libraries/monero_serai.md)
---
- [⚪️ Benchmarking](benchmarking/intro.md)
- [⚪️ Criterion](benchmarking/criterion.md)
- [⚪️ Harness](benchmarking/harness.md)
- [⚪️ Testing](testing/intro.md)
- [⚪️ Monero data](testing/monero-data.md)
- [⚪️ RPC client](testing/rpc-client.md)
- [⚪️ Spawning `monerod`](testing/spawning-monerod.md)
- [⚪️ Known issues and tradeoffs](known-issues-and-tradeoffs/intro.md)
- [⚪️ Networking](known-issues-and-tradeoffs/networking.md)
- [⚪️ RPC](known-issues-and-tradeoffs/rpc.md)
- [⚪️ Storage](known-issues-and-tradeoffs/storage.md)
---
- [⚪️ Appendix](appendix/intro.md)
- [🔴 Contributing](appendix/contributing.md)
- [🔴 Crate documentation](appendix/crate-documentation.md)
- [🔴 Build targets](appendix/build-targets.md)
- [🔴 Protocol book](appendix/protocol-book.md)
- [⚪️ User book](appendix/user-book.md)

View file

@ -0,0 +1,7 @@
# Build targets
- x86
- ARM64
- Windows
- Linux
- macOS
- FreeBSD(?)

View file

@ -0,0 +1,2 @@
# Contributing
<https://github.com/Cuprate/cuprate/blob/main/CONTRIBUTING.md>

View file

@ -0,0 +1,4 @@
# Crate documentation
```bash
cargo doc --package $CUPRATE_CRATE
```

View file

@ -0,0 +1 @@
# Appendix

View file

@ -0,0 +1,2 @@
# Protocol book
<https://monero-book.cuprate.org>

View file

@ -0,0 +1 @@
# ⚪️ User book

View file

@ -0,0 +1 @@
# ⚪️ Criterion

View file

@ -0,0 +1 @@
# ⚪️ Harness

View file

@ -0,0 +1 @@
# ⚪️ Benchmarking

View file

@ -0,0 +1 @@
# ⚪️ CLI

View file

@ -0,0 +1 @@
# ⚪️ Config

View file

@ -0,0 +1 @@
# ⚪️ Binary

View file

@ -0,0 +1 @@
# ⚪️ Logging

View file

@ -0,0 +1 @@
# ⚪️ Components

View file

@ -0,0 +1 @@
# ⚪️ Bird's eye view

View file

@ -0,0 +1 @@
# ⚪️ Map

View file

@ -0,0 +1 @@
# ⚪️ Consensus

View file

@ -0,0 +1 @@
# ⚪️ TODO

View file

@ -0,0 +1 @@
# ⚪️ Verifier

View file

@ -0,0 +1,22 @@
# Cuprate Architecture
WIP
[Cuprate](https://github.com/Cuprate/cuprate)'s architecture book.
Sections are notated with colors indicating how complete they are:
| Color | Meaning |
|-------|---------|
| ⚪️ | Empty
| 🔴 | Severely lacking information
| 🟠 | Lacking some information
| 🟡 | Almost ready
| 🟢 | OK
---
Continue to the next chapter by clicking the right `>` button, or by selecting it on the left side.
All chapters are viewable by clicking the top-left `☰` button.
The entire book can searched by clicking the top-left 🔍 button.

View file

@ -0,0 +1 @@
# ⚪️ Cryptonight

View file

@ -0,0 +1 @@
# ⚪️ External Monero libraries

View file

@ -0,0 +1,2 @@
# monero_serai
<https://github.com/serai-dex/serai/tree/develop/coins/monero>

View file

@ -0,0 +1,2 @@
# RandomX
<https://github.com/tari-project/randomx-rs>

View file

@ -0,0 +1,36 @@
# Foreword
Monero[^1] is a large software project, coming in at 329k lines of C++, C, headers, and make files.[^2] It is directly responsible for 2.6 billion dollars worth of value.[^3] It has had over 400 contributors, more if counting unnamed contributions.[^4] It has over 10,000 node operators and a large active userbase.[^5]
The project wasn't always this big, but somewhere in the midst of contributors coming and going, various features being added, bugs being fixed, and celebrated cryptography being implemented - there was an aspect that was lost by the project that it could not easily gain again: **maintainability**.
Within large and complicated software projects, there is an important transfer of knowledge that must occur for long-term survival. Much like an organism that must eventually pass the torch onto the next generation, projects must do the same for future contributors.
However, newcomers often lack experience, past contributors might not be around, and current maintainers may be too busy. For whatever reason, this transfer of knowledge is not always smooth.
There is a solution to this problem: **documentation**.
The activity of writing the what, where, why, and how of the solutions to technical problems can be done in an author's lonesome.
The activity of reading these ideas can be done by future readers at any time without permission.
These readers may be new prospective contributors, it may be the current maintainers, it may be researchers, it may be users of various scale. Whoever it may be, documentation acts as the link between the past and present; a bottle of wisdom thrown into the river of time for future participants to open.
This book is the manifestation of this will, for Cuprate[^6], an alternative Monero node. It documents Cuprate's implementation from head-to-toe such that in the case of a contributor's untimely disappearance, the project can continue.
People come and go, documentation is forever.
— hinto-janai
---
[^1]: [`monero-project/monero`](https://github.com/monero-project/monero)
[^2]: `git ls-files | grep "\.cpp$\|\.h$\|\.c$\|CMake" | xargs cat | wc -l` on [`cc73fe7`](https://github.com/monero-project/monero/tree/cc73fe71162d564ffda8e549b79a350bca53c454)
[^3]: 2024-05-24: $143.55 USD * 18,151,608 XMR = $2,605,663,258
[^4]: `git log --all --pretty="%an" | sort -u | wc -l` on [`cc73fe7`](https://github.com/monero-project/monero/tree/cc73fe71162d564ffda8e549b79a350bca53c454)
[^5]: <https://monero.fail/map>
[^6]: <https://github.com/Cuprate/cuprate>

View file

@ -0,0 +1 @@
# ⚪️ cuprate_helper

View file

@ -0,0 +1 @@
# ⚪️ cuprate_types

View file

@ -0,0 +1 @@
# ⚪️ Epee

View file

@ -0,0 +1 @@
# ⚪️ Formats, protocols, types

View file

@ -0,0 +1 @@
# ⚪️ Levin

View file

@ -0,0 +1 @@
# ⚪️ monero_serai

View file

@ -0,0 +1 @@
# ⚪️ Data collection

View file

@ -0,0 +1,2 @@
# Instrumentation
Cuprate is built with [instrumentation](https://en.wikipedia.org/wiki/Instrumentation) in mind.

View file

@ -0,0 +1 @@
# ⚪️ Logging

View file

@ -0,0 +1,4 @@
# Systems
Cuprate is made up of multiple distinct internal systems that work together.
This section provides informal specifications and implementation details about each.

View file

@ -0,0 +1,5 @@
# How to use this book
## Maintainers
## Contributors
## Researchers

View file

@ -0,0 +1,15 @@
# Intro
[Cuprate](https://github.com/Cuprate/cuprate) is an alternative [Monero](https://getmonero.org) node implementation.
This book describes Cuprate's architecture, ranging from small things like database pruning to larger meta-components like the networking stack.
A brief overview of some aspects covered within this book:
- Component designs
- Implementation details
- File location and purpose
- Design decisions and tradeoffs
- Things in relation to `monerod`
- Dependency usage
## Source code
The source files for this book can be found on at: <https://github.com/Cuprate/architecture-book>.

View file

@ -0,0 +1,28 @@
# Required knowledge
## General
- Rust
- Monero
- System design
## Components
### Storage
- Embedded databases
- LMDB
- redb
### RPC
- `axum`
- `tower`
- `async`
- JSON-RPC 2.0
- Epee
### Networking
- `tower`
- `tokio`
- `async`
- Levin
### Instrumentation
- `tracing`

View file

@ -0,0 +1,31 @@
# Who this book is for
## Maintainers
As mentioned in [`Foreword`](../foreword.md), the group of people that benefit from this book's value the most by far are the current and future Cuprate maintainers.
Cuprate's system design is documented in this book such that if you were ever to build it again from scratch, you would have an excellent guide on how to do such, and also where improvements could be made.
Practically, what that means for maintainers is that it acts as _the_ reference. During maintenance, it is quite valuable to have a book that contains condensed knowledge on the behavior of components, or how certain code works, or why it was built a certain way.
## Contributors
Contributors also have access to the inner-workings of Cuprate via this book, which helps when making larger contributions.
Design decisions and implementation details notated in this book helps answer questions such as:
- Why is it done this way?
- Why can it _not_ be done this way?
- Were other methods attempted?
Cuprate's testing and benchmarking suites, unknown to new contributors, are also documented within this book.
## Researchers
This book contains the why, where, and how of the _implementation_ of formal research.
Although it is an informal specification, this book still acts as a more accessible overview of Cuprate compared to examining the codebase itself.
## Operators & users
This book is not a practical guide for using Cuprate itself.
For configuration, data collection (also important for researchers), and other practical usage, see [Cuprate's user book](https://user.cuprate.org).
## Observers
Anyone curious enough is free to learn the inner-workings of Cuprate via this book, and maybe even contribute someday.

View file

@ -0,0 +1 @@
# ⚪️ Known issues and tradeoffs

View file

@ -0,0 +1 @@
# ⚪️ Networking

View file

@ -0,0 +1 @@
# ⚪️ RPC

View file

@ -0,0 +1 @@
# ⚪️ Storage

View file

@ -0,0 +1 @@
# ⚪️ Dandelion++

View file

@ -0,0 +1 @@
# ⚪️ i2p

View file

@ -0,0 +1 @@
# ⚪️ Networking

View file

@ -0,0 +1 @@
# ⚪️ IPv4/IPv6

View file

@ -0,0 +1 @@
# ⚪️ P2P

View file

@ -0,0 +1 @@
# ⚪️ Proxy

View file

@ -0,0 +1 @@
# ⚪️ Tor

View file

@ -0,0 +1,32 @@
# Concurrency and parallelism
It is incumbent upon software like Cuprate to take advantage of today's highly parallel hardware as much as practically possible.
With that said, programs must setup guardrails when operating in a concurrent and parallel manner, [for correctness and safety](https://en.wikipedia.org/wiki/Concurrency_(computer_science)).
There are "synchronization primitives" that help with this, common ones being:
- [Locks](https://en.wikipedia.org/wiki/Lock_(computer_science))
- [Channels](https://en.wikipedia.org/wiki/Channel_(programming))
- [Atomics](https://en.wikipedia.org/wiki/Linearizability#Primitive_atomic_instructions)
These tools are relatively easy to use in isolation, but trickier to do so when considering the entire system. It is not uncommon for _the_ bottleneck to be the [poor orchastration](https://en.wikipedia.org/wiki/Starvation_(computer_science)) of these primitives.
## Analogy
A common analogy for a parallel system is an intersection.
Like a parallel computer system, an intersection contains:
1. **Parallelism:** multiple individual units that want to move around (cars, pedestrians, etc)
1. **Synchronization primitives:** traffic lights, car lights, walk signals
In theory, the amount of "work" the units can do is only limited by the speed of the units themselves, but in practice, the slow cascading reaction speeds between all units, the frequent hiccups that can occur, and the synchronization primitives themselves become bottlenecks far before the maximum speed of any unit is reached.
A car that hogs the middle of the intersection on the wrong light is akin to a system thread holding onto a lock longer than it should be - it degrades total system output.
Unlike humans however, computer systems at least have the potential to move at lightning speeds, but only if the above synchronization primitives are used correctly.
## Goal
To aid the long-term maintenance of highly concurrent and parallel code, this section documents:
1. All system threads spawned and maintained
1. All major sections where synchronization primitives are used
1. The asynchronous behavior of some components
and how these compose together efficiently in Cuprate.

View file

@ -0,0 +1 @@
# ⚪️ Map

View file

@ -0,0 +1 @@
# ⚪️ The block downloader

View file

@ -0,0 +1 @@
# ⚪️ The database

View file

@ -0,0 +1 @@
# ⚪️ The RPC server

View file

@ -0,0 +1 @@
# ⚪️ The verifier

View file

@ -0,0 +1 @@
# ⚪️ Thread exit

View file

@ -0,0 +1 @@
# ⚪️ File system

View file

@ -0,0 +1 @@
# ⚪️ Resource model

View file

@ -0,0 +1 @@
# ⚪️ Memory

View file

@ -0,0 +1 @@
# ⚪️ Sockets

View file

@ -0,0 +1 @@
# ⚪️ Handler

View file

@ -0,0 +1 @@
# ⚪️ Interface

View file

@ -0,0 +1,3 @@
# RPC
- <https://www.getmonero.org/resources/developer-guides/daemon-rpc.html#other-daemon-rpc-calls>
- <https://github.com/monero-project/monero/tree/master/src/rpc>

View file

@ -0,0 +1 @@
# ⚪️ Methods

View file

@ -0,0 +1 @@
# ⚪️ Router

View file

@ -0,0 +1 @@
# ⚪️ Binary

View file

@ -0,0 +1 @@
# ⚪️ Types

View file

@ -0,0 +1 @@
# ⚪️ JSON

View file

@ -0,0 +1 @@
# ⚪️ Other

View file

@ -0,0 +1 @@
# ⚪️ Blockchain

View file

@ -0,0 +1 @@
# ⚪️ Database abstraction

View file

@ -0,0 +1 @@
# ⚪️ Storage

View file

@ -0,0 +1 @@
# ⚪️ Pruning

View file

@ -0,0 +1 @@
# ⚪️ Transaction pool

View file

@ -0,0 +1 @@
# ⚪️ Testing

View file

@ -0,0 +1 @@
# ⚪️ Monero data

View file

@ -0,0 +1 @@
# ⚪️ RPC client

View file

@ -0,0 +1 @@
# ⚪️ Spawning monerod

View file

@ -0,0 +1 @@
# ⚪️ ZMQ