Rewrite programming model with developer focus

Previous version talked about concurrency, which is described
in detail in the Anatomy of a Fullnode chapter. App developers
probably don't care that their programs run in parallel with
other programs. From their perspective, there's no difference
between 10x parallelism and a 10x faster CPU.
This commit is contained in:
Greg Fitzgerald 2018-12-04 10:24:08 -07:00 committed by Grimes
parent e4049f3733
commit 13c7c3b3a6
2 changed files with 40 additions and 18 deletions

View File

@ -1,32 +1,46 @@
# Programming Model # Programming Model
With the Solana runtime, we can execute on-chain programs concurrently, and The Solana *runtime* can execute untrusted on-chain programs written in any
written in the clients choice of programming language. programming language that can target the Berkley Packet Filter (BPF) safe
execution environment. The Solana SDK offers the best support for C programs,
which is compiled to BPF using the [LLVM compiler
infrastructure](https://llvm.org). Alternatively, a client might choose to
bypass LLVM and use Python, Lua or C++ to generate BPF directly via the [BPF
Compiler Collection](https://github.com/iovisor/bcc) (BCC).
## Client Interactions with Solana ## Deploying Programs to a Cluster
<img alt="SDK tools" src="img/sdk-tools.svg" class="center"/> <img alt="SDK tools" src="img/sdk-tools.svg" class="center"/>
As shown in the diagram above an untrusted client, creates a program in the As shown in the diagram above a client creates a program and compiles it to an
language of their choice, (i.e. C/C++/Rust/Lua), and compiles it with LLVM to a ELF shared object containing BPF bytecode and sends it to the Solana cluster.
position independent shared object ELF, targeting BPF bytecode, and sends it to The cluster stores the program locally and makes it available to clients via a
the Solana cluster. Next, the client sends messages to the Solana cluster, *program ID*. The program ID is a public key generated by the client and is
which target that program. The Solana runtime loads the previously submitted used to reference the program in subsequent transactions.
ELF and passes it the client's message for interpretation.
## Persistent Storage ## Interacting with On-chain Programs
Solana supports several kinds of persistent storage, called *accounts*: After a program has been deployed, a client utilizes it by sending transactions
to the Solana cluster. A transaction contains one or more *instructions*. Each
instruction references the program ID that coresponds to the program that the
runtime should use to execute it. Instructions are executed atomically. If any
instruction is invalid, any changes made within the transaction are discarded.
## Storing State between Transactions
If the the program needs to store state between transactions, it does so using
*accounts*. Solana supports several kinds of accounts:
1. Executable 1. Executable
2. Owned by a client 2. Owned by a client
3. Owned by a program 3. Owned by a program
4. Credit-only 4. Credit-only
All accounts are identified by public keys and may hold arbirary data. All accounts are identified by public keys and may hold arbitrary data. When
When the client sends messages to programs, it requests access to storage the client sends messages to programs, it requests access to accounts using
using those keys. The runtime loads the account data and passes it to the those keys. The runtime loads the account and passes it to the program. The
program. The runtime also ensures accounts aren't written to if not owned runtime also ensures accounts aren't written to if not owned by the client or
by the client or program. Any writes to credit-only accounts are discarded program. Any writes to credit-only accounts are discarded unless the write was
unless the write was to credit tokens. Any user may credit other accounts to credit tokens. Any user may credit other accounts tokens, regardless of
tokens, regardless of account permission. account permission.

View File

@ -125,6 +125,10 @@ The number of [fullnodes](#fullnode) participating in a [cluster](#cluster).
The code that interprets [instructions](#instruction). The code that interprets [instructions](#instruction).
#### program ID
The public key of the [account](#account) containing a [program](#program).
#### public key #### public key
The public key of a [keypair](#keypair). The public key of a [keypair](#keypair).
@ -204,6 +208,10 @@ A type of [client](#client) that can verify it's pointing to a valid [cluster](#
Millions of [instructions](#instruction) per second. Millions of [instructions](#instruction) per second.
#### runtime
The component of a [fullnode](#fullnode) responsible for [program](#program) execution.
#### thin client #### thin client
A type of [client](#client) that trusts it is communicating with a valid [cluster](#cluster). A type of [client](#client) that trusts it is communicating with a valid [cluster](#cluster).