Skip to content

Commit

Permalink
2025.02.12 note
Browse files Browse the repository at this point in the history
完成打卡 ✅
  • Loading branch information
StarryDeserts committed Feb 12, 2025
1 parent 0af8a2c commit 54d0e9e
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 3 deletions.
Binary file added .starrydeserts_image/Layered-Architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
115 changes: 112 additions & 3 deletions StarryDeserts.md
Original file line number Diff line number Diff line change
Expand Up @@ -396,9 +396,7 @@ timezone: Pacific/Auckland # 新西兰标准时间 (UTC+12)

------

##### **代码示例**

### **R代码:基础费用模拟**
##### **R代码:基础费用模拟**

```R
calculate_base_fee_per_gas <- function(
Expand All @@ -423,4 +421,115 @@ calculate_base_fee_per_gas <- function(
}
```



### 2025.02.12

#### 以太坊执行层架构(第1天)

------

##### **客户端架构概览**

###### 核心职责

1. **区块链数据验证与存储**
- 维护本地区块链副本
- 通过默克尔树验证数据完整性
2. **网络通信**
- 使用DevP2P协议进行点对点通信
- 交易池(mempool)管理
3. **共识层协作**
- 实现Engine API接口
- 响应`forkChoiceUpdated``newPayload`调用

##### 分层架构

<img src=".starrydeserts_image/Layered-Architecture.png" alt="Layered-Architecture" style="zoom: 33%;" />

------

##### **EVM设计原理**

###### 虚拟机核心特征

- **硬件无关性**
通过`EVM字节码`实现跨平台一致性,类似JVM设计理念
- **沙盒环境**
每个交易在隔离环境中执行,保证状态变更原子性

###### 三明治复杂性模型

1. **外层(简单)**
- Solidity/Yul等高级语言
- JSON-RPC接口
2. **中间层(复杂)**
- 编译器(Solidity→EVM字节码)
- Gas计量系统
3. **内层(简单)**
- EVM指令集(约140个操作码)

------

##### **状态管理机制**

###### 全局状态组成

| 组件 | 存储内容 | 数据结构 |
| -------- | ----------------------- | --------------- |
| 账户状态 | 余额/Nonce/合约代码哈希 | Merkle-Patricia |
| 合约存储 | 智能合约变量数据 | Merkle-Patricia |
| 交易收据 | 交易执行日志 | Bloom Filter |

###### 状态转换公式
$$\sigma_{t+1} \equiv \Upsilon(\sigma_t, T)$$

- $$\sigma_t$$: 当前状态
- $$T$$: 交易集合
- $$\Upsilon$$: 状态转换函数

------

##### **交易生命周期**

###### 处理流程

1. **接收**
通过JSON-RPC接口接收签名交易
2. **验证**
- 签名有效性
- Nonce连续性
- Gas预算充足
3. **传播**
通过DevP2P协议广播至全网节点
4. **打包**
被矿工/验证者选入候选区块
5. **执行**
在EVM中触发状态转换

###### Gas计算模型
$$\text{总Gas成本} = \text{固有成本} + \sum(\text{操作码Gas} \times \text{执行次数})$$

------

##### **网络层(DevP2P)**

###### 关键协议

| 协议 | 功能 | 传输内容 |
| ------ | ------------ | ------------- |
| eth/66 | 区块同步 | 区块头/体数据 |
| eth/67 | 交易传播 | 原始交易数据 |
| les/4 | 轻客户端支持 | 状态证明 |

###### 节点发现机制

1. 使用Kademlia DHT协议
2. 通过ENR记录存储节点元数据
3. 维护动态路由表(Bucket结构)





<!-- Content_END -->

0 comments on commit 54d0e9e

Please sign in to comment.