Skip to content

Commit 09a0a60

Browse files
Merge pull request #157 from StarryDeserts/main
2025.02.13 note
2 parents 25d63de + be6b949 commit 09a0a60

File tree

2 files changed

+108
-0
lines changed

2 files changed

+108
-0
lines changed
77.9 KB
Loading

StarryDeserts.md

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,114 @@ $$\text{总Gas成本} = \text{固有成本} + \sum(\text{操作码Gas} \times \t
530530

531531

532532

533+
### 2025.02.13
534+
535+
#### 以太坊执行层架构学习笔记(第2天)
536+
537+
------
538+
539+
##### **引擎API(Engine API)**
540+
541+
###### 核心接口
542+
543+
```go
544+
type EngineAPI interface {
545+
NewPayloadV1(payload ExecutionPayload) (PayloadStatusV1, error)
546+
ForkchoiceUpdatedV1(state ForkchoiceState, attr PayloadAttributes) (ForkchoiceUpdatedResult, error)
547+
}
548+
```
549+
550+
###### 工作流程
551+
552+
1. **共识层触发**
553+
- 接收`ForkchoiceUpdated`调用
554+
- 确定规范链头(head block)
555+
2. **有效载荷验证**
556+
- 检查父块哈希一致性
557+
- 验证时间戳序列
558+
3. **状态同步**
559+
- 执行区块内交易
560+
- 更新全局状态树
561+
562+
------
563+
564+
##### **同步机制**
565+
566+
###### 同步模式对比
567+
568+
| 模式 | 特点 | 适用场景 |
569+
| -------- | ------------------------ | ---------------- |
570+
| 全量同步 | 从创世块开始验证所有交易 | 新节点初始化 |
571+
| 快速同步 | 下载最新状态快照 | 追赶网络最新状态 |
572+
| 轻同步 | 仅同步区块头+Merkle证明 | 移动设备/浏览器 |
573+
574+
###### 状态同步公式
575+
576+
$$\text{同步进度} = \frac{\text{已验证区块高度}}{\text{网络最新高度}} \times 100\%$$
577+
578+
------
579+
580+
##### **有效载荷验证流程**
581+
582+
###### 验证步骤
583+
584+
1. **区块头验证**
585+
586+
$$H_{\text{gasLimit}} \in \left[P(H)_{\text{gasLimit}} \pm \left\lfloor \frac{P(H)_{\text{gasLimit}}}{1024} \right\rfloor\right]$$
587+
588+
2. **随机数验证**
589+
590+
- $$H_{\text{difficulty}} = 0$$ (PoS区块)
591+
- $$H_{\text{nonce}} = 0x0000000000000000$$
592+
593+
3. **时间戳验证**
594+
595+
596+
597+
$$H_{\text{timestamp}} > P(H)_{\text{timestamp}}$$
598+
599+
###### 客户端实现差异
600+
601+
| 检查项 | Geth实现位置 | Reth实现位置 |
602+
| ------------ | ------------------------- | ------------------- |
603+
| Gas限制验证 | `core/block_validator.go` | `crates/engine/src` |
604+
| 基础费用计算 | `core/fee_history.go` | `crates/revm/src` |
605+
606+
------
607+
608+
##### **交易池管理**
609+
610+
###### 双池架构
611+
612+
<img src=".starrydeserts_image/Dual-pool_architecture.png" alt="Dual-pool_architecture" style="zoom: 33%;" />
613+
614+
###### 淘汰机制对比
615+
616+
| 池类型 | 排序依据 | 淘汰策略 |
617+
| ------ | ------------------------- | ------------------ |
618+
| Legacy | 有效小费(Effective Tip) | 大顶堆淘汰低优先级 |
619+
| Blob | 对数时间衰减 | 滑动窗口淘汰 |
620+
621+
------
622+
623+
##### **共识引擎集成**
624+
625+
###### 多引擎支持
626+
627+
```go
628+
type ConsensusEngine interface {
629+
VerifyHeaders(chain BlockChain, headers []*Header) (chan<- struct{}, <-chan error)
630+
Finalize(chain BlockChain, header *Header, state *state.StateDB, txs []*Transaction)
631+
}
632+
```
633+
634+
###### 验证流程示例
635+
636+
1. 分离PoW/PoS区块头
637+
2. 预合并区块使用Ethash验证
638+
3. 后合并区块通过Beacon链验证
639+
4. 检查终态性(Finality)标记
640+
533641

534642

535643
<!-- Content_END -->

0 commit comments

Comments
 (0)