Skip to content

Commit a71128a

Browse files
add solana documentation (#41)
1 parent b7f6772 commit a71128a

5 files changed

+208
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
sequenceDiagram
2+
participant U as User Wallet
3+
participant N as Solana Node
4+
participant G as Gossip Network
5+
participant L as Leader
6+
participant V as Validators
7+
participant P as Proof of History
8+
9+
U->>U: Create Transaction
10+
U->>U: Sign Transaction
11+
U->>N: Submit Signed Transaction
12+
N->>N: Validate Transaction
13+
N->>G: Propagate Transaction
14+
G->>L: Deliver Transaction
15+
16+
L->>L: Bundle Transactions
17+
L->>P: Record PoH Timestamp
18+
L->>L: Process Transactions
19+
L->>P: Record PoH Timestamp
20+
L->>L: Create Block
21+
22+
L->>V: Broadcast Block
23+
V->>V: Verify Block
24+
V->>V: Vote on Block
25+
V->>V: Reach Consensus
26+
27+
V->>N: Confirm Transaction
28+
N->>U: Send Confirmation
29+
U->>U: Update UI
30+
31+
Note over U,P: Transaction Complete

docs/solana.md

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
# Solana Transaction Flow: High Level E2E flow of transactions through the Solana network
2+
3+
Let's walk through the process of sending 1 SOL to your friend on the Solana network.
4+
5+
## 1. Creating the Transaction
6+
7+
You open your Solana wallet app and enter:
8+
* Recipient: Your friend's wallet address
9+
* Amount: 1 SOL
10+
11+
The app creates a transaction that includes:
12+
* Instruction: "Transfer 1 SOL from my address to my friend's address"
13+
* A recent blockhash: Like a timestamp to ensure the transaction is fresh
14+
* Your signature: To prove it's really you making the transaction
15+
16+
```json
17+
Transaction {
18+
instruction: "Transfer 1 SOL from ABC123... to XYZ789...",
19+
blockhash: "Recent123...",
20+
signature: "YourSignature456..."
21+
}
22+
```
23+
24+
## 2. Sending the Transaction
25+
26+
Your wallet app sends this transaction to a Solana node (think of it as a computer in the Solana network).
27+
28+
The node checks:
29+
1. Is the signature valid?
30+
2. Is the blockhash recent?
31+
3. Do you have enough SOL?
32+
33+
If all checks pass, the node shares this transaction with other nodes.
34+
35+
## 3. Leader Selection
36+
37+
Solana has a schedule of which node (called a validator) will be the leader at each moment.
38+
39+
Let's say Validator Bob is the current leader. All nodes send your transaction to Bob.
40+
41+
## 4. Processing the Transaction
42+
43+
Bob receives your transaction and many others. He:
44+
1. Bundles these transactions into a block
45+
2. Processes each transaction in the block
46+
47+
For your transaction, Bob's computer:
48+
* Subtracts 1 SOL from your account
49+
* Adds 1 SOL to your friend's account
50+
51+
## 5. Proof of History and Consensus
52+
53+
As Bob processes transactions, he's also running a special clock called Proof of History (PoH).
54+
It's like a super-fast stopwatch that puts a timestamp on every action.
55+
56+
Bob sends out the processed block with all its transactions and PoH timestamps.
57+
58+
Other validators check Bob's work:
59+
* Did he process all transactions correctly?
60+
* Do the PoH timestamps make sense?
61+
62+
If most validators agree Bob did a good job, your transaction is confirmed.
63+
64+
## 6. Confirmation
65+
66+
Your wallet app checks with the network and sees that your transaction is confirmed.
67+
It shows you a message: "1 SOL sent successfully to your friend!"
68+
69+
Your friend's wallet balance increases by 1 SOL.
70+
71+
## Diagram
72+
73+
```mermaid
74+
graph TD
75+
A[User Wallet] -->|1. Create & Sign Transaction| B(Solana Node)
76+
B -->|2. Validate & Propagate| C{Gossip Network}
77+
C -->|3. Reach Leader| D[Current Leader]
78+
D -->|4. Bundle & Process| E[Create Block]
79+
E -->|5. Apply PoH| F[Proof of History]
80+
F -->|6. Broadcast| G[Validator Network]
81+
G -->|7. Verify & Vote| H{Consensus}
82+
H -->|8. Confirm| I[User Wallet]
83+
style A fill:#f9f,stroke:#333,stroke-width:2px
84+
style I fill:#f9f,stroke:#333,stroke-width:2px
85+
style D fill:#bbf,stroke:#333,stroke-width:2px
86+
style F fill:#bfb,stroke:#333,stroke-width:2px
87+
```
88+
89+
## Key Points:
90+
91+
1. Your transaction is bundled with others for efficiency.
92+
2. One leader (validator) processes transactions at a time.
93+
3. Other validators check the leader's work.
94+
4. The unique PoH "clock" helps keep everything in order.
95+
5. This process happens very fast - usually in less than a second!
96+

docs/solana_accounts.mermaid

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
graph TD
2+
A[Solana Accounts] --> B[User Accounts]
3+
A --> C[Program Accounts]
4+
A --> D[Data Accounts]
5+
B --> E[Public Key]
6+
B --> F[Private Key]
7+
B --> G[SOL Balance]
8+
C --> H[Executable Code]
9+
D --> I[Program State]
10+
D --> J[Token Balances]
11+
12+
style A fill:#f9f,stroke:#333,stroke-width:2px
13+
style B fill:#bbf,stroke:#333,stroke-width:2px
14+
style C fill:#bfb,stroke:#333,stroke-width:2px
15+
style D fill:#fbf,stroke:#333,stroke-width:2px
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
sequenceDiagram
2+
participant SenderWallet as Your Wallet
3+
participant Network as Solana Network
4+
participant RecipientWallet as Friend's Wallet
5+
6+
SenderWallet->>Network: Check transaction status
7+
Network-->>SenderWallet: Confirm transaction
8+
9+
Note over SenderWallet: Update UI
10+
SenderWallet->>SenderWallet: Show message: "1 SOL sent successfully to your friend!"
11+
SenderWallet->>SenderWallet: Update balance: -1 SOL
12+
13+
Network->>RecipientWallet: Notify of received transaction
14+
RecipientWallet->>RecipientWallet: Update balance: +1 SOL
15+
16+
Note over RecipientWallet: Update UI
17+
RecipientWallet->>RecipientWallet: Show notification: "Received 1 SOL"
18+
19+
Note over SenderWallet,RecipientWallet: Transaction Complete

docs/solana_consensus.mermaid

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
sequenceDiagram
2+
participant Bob as Bob (Leader)
3+
participant PoH as Proof of History
4+
participant Block as Processed Block
5+
participant V1 as Validator 1
6+
participant V2 as Validator 2
7+
participant V3 as Validator 3
8+
9+
Note over Bob,PoH: 1. Processing and PoH
10+
loop For each transaction
11+
Bob->>PoH: Get timestamp
12+
PoH-->>Bob: Provide timestamp
13+
Bob->>Bob: Process transaction
14+
Bob->>Block: Add transaction with timestamp
15+
end
16+
17+
Note over Bob,Block: 2. Block Creation
18+
Bob->>Block: Finalize block with PoH data
19+
20+
Note over Bob,V3: 3. Block Distribution
21+
Bob->>V1: Send processed block
22+
Bob->>V2: Send processed block
23+
Bob->>V3: Send processed block
24+
25+
Note over V1,V3: 4. Validation
26+
V1->>V1: Check transactions
27+
V1->>V1: Verify PoH timestamps
28+
V2->>V2: Check transactions
29+
V2->>V2: Verify PoH timestamps
30+
V3->>V3: Check transactions
31+
V3->>V3: Verify PoH timestamps
32+
33+
Note over V1,V3: 5. Consensus
34+
V1->>V1: Vote on block
35+
V2->>V2: Vote on block
36+
V3->>V3: Vote on block
37+
38+
Note over Bob,V3: 6. Confirmation
39+
alt If majority agrees
40+
V1->>Bob: Confirm block
41+
V2->>Bob: Confirm block
42+
V3->>Bob: Confirm block
43+
else If majority disagrees
44+
V1->>Bob: Reject block
45+
V2->>Bob: Reject block
46+
V3->>Bob: Reject block
47+
end

0 commit comments

Comments
 (0)