Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: create consensus page on solana topic #10

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
- [Hello Solana](solana/hello-solana.md)
- [Fetch balance](solana/fetch-balance.md)
- [NFT Memberships](solana/nft-memberships.md)
- [Consensus](solana/consensus.md)
- [ML](ml/mod.md)
- [Large Language Model](ml/large-language-model.md)
- [Inferences](ml/infer/mod.md)
Expand Down
Binary file added src/solana/asset/hash-event.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/solana/asset/net-design.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/solana/asset/poh-hashing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/solana/asset/poh-input.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/solana/asset/poh-tx.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/solana/asset/tx-flow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/solana/asset/tx-pipeline.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/solana/asset/verification.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/solana/asset/verify-diagram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
97 changes: 97 additions & 0 deletions src/solana/consensus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Consensus
Solana combine two consensus algorithms PoS and enhance with PoH
> 🚧 Main focus on Proof of History (PoH)

> 🚧 Listen Approach to Scalability to understand what solana achieve [here](https://www.youtube.com/watch?v=50yhHe_NQ0g&t)

## PoH (Proof of history)
> 🚧 Key point: ***Take notion of time into blockchain***,
PoH Create verifyable time ordering to allow validator nodes to determine the order of incoming blocks.

Look at this diagram (a bit confusion)
![](./asset/tx-flow.png)
> ref: https://solana.com/solana-whitepaper.pdf

![](/assets/kat.png) <span class="speech-bubble">If you're confused, that's fine! Let's break it down part by part.</span>

Explain diagram
Transaction coming into solana cluster and then

1. Select leader generator (PoH generator) by PoS engine (depending on weight of staking amount, ***more on later***).
2. Leader generates PoH with Hashing algroithm (SHA256)
3. Combine transaction hash with the hash generated by the leader node to produce an output that serves as input for the next hash.
3. validator node verify or recompute the hash that generate by leader and working in parallel with the same mechanism. to confirm each tx happening on correct time (state)

![](/assets/kat.png) <span class="speech-bubble">Time ordering and block is generate by leader node !</span>

> 🚧 Unlike other protocols, this one doesn't require validator nodes to produce and broadcast blocks to the entire network. Instead, validators continuously process the hash in pararell to ensure no malicious leader exists.

![](/assets/kat.png) <span class="speech-bubble">That mean schedule with out communication !</span>

## How Hashing ?
- PoH Hashing sequen
Leader node will generate hash (SHA256) and the hash can't predict output!
```mermaid
graph LR
A["🤖 Leader node"]--->B["1️⃣ Hash1 (SHA256)"]--->C["2️⃣ Hash2 (SHA256)"]--->D["3️⃣ Hash3 (SHA256)"]
```

- PoH Hashing + transaction hash
```mermaid
graph LR
A["🤖 Leader node"]--->B["1️⃣ Hash1 (SHA256)"]--->C["2️⃣ Hash2 (SHA256) + Transaction 💵"]--->D["3️⃣ Hash3 (SHA256)"]
```

Now user sending incoming transaction

![](./asset/poh-input.png)
> combine transaction hash with previos hash as an input.

There's a reason why Solana works this way. Let's see in the next topic. 👉

## Notion of the time in PoH
How solanana put the time to blockchain ? this is genious concept for solana PoH consensus,

> Solana uses a sequence of hashes to record event data at the current index of the hashing sequence, like capturing an event at a particular point in the sequence.

![](./asset/hash-event.png)

> ref: https://solana.com/solana-whitepaper.pdf

for example index 336 will use hash 335 output + tx hash (event) as input.

![](/assets/kat.png) <span class="speech-bubble">Now we can determine and know the period during which the transaction occurred: before hash 337 was created and after hash 335.</span>


## How fast ?
![](/assets/kat.png) <span class="speech-bubble">Generate hash (GPU) > Generate hash (CPU)</span>

Let's see transaction piplined
![](./asset/tx-pipeline.png)

> ref: https://youtu.be/50yhHe_NQ0g?t=253

The verification process happens in the GPU section (utilizing the GPU's multiple cores to recompute the hash in parallel). That's why it's not slow even though it recomputes the hash.

And exactly is implement by power of RUST!! 🦀

![](./asset/verification.png)

> ref: https://solana.com/solana-whitepaper.pdf

## How verifying ?

now we don't worry about recompute will be slow, cause solana use multicore from GPU to recompute for verifying,

now we focus on how it verifying process

![](./asset/verify-diagram.png)

> ref: https://youtu.be/079mUCjYpZs?t=798

> 🚧 Validator node will verify hash in pararell, by using the same machanism to recompute hash and after got final state that compute with final hash it will checking by sending final state to compare with final state from leader node and then Leader node will commit a block to the ledger.

![](./asset/net-design.png)

> ref: https://solana.com/solana-whitepaper.pdf