Go-ethereum 源码解析之 go-ethereum/core/events.go
// Copyright 2017 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
package core
import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
)
// NewTxsEvent is posted when a batch of transactions enter the transaction pool.
type NewTxsEvent struct{ Txs []*types.Transaction }
// PendingLogsEvent is posted pre mining and notifies of pending logs.
type PendingLogsEvent struct {
Logs []*types.Log
}
// NewMinedBlockEvent is posted when a block has been imported.
type NewMinedBlockEvent struct{ Block *types.Block }
// RemovedLogsEvent is posted when a reorg happens
type RemovedLogsEvent struct{ Logs []*types.Log }
type ChainEvent struct {
Block *types.Block
Hash common.Hash
Logs []*types.Log
}
type ChainSideEvent struct {
Block *types.Block
}
type ChainHeadEvent struct{ Block *types.Block }
Appendix A. 总体批注
文件 core/events.go 定义了打包新区块时需要关注的各种事件。这些事件有些是由网络中其它节点向本地节点广播的,有些是由本地节点向网络中其它节点广播的。
网络节点向本地节点广播的事件
- NewTxsEvent
本地节点向网络节点广播的事件
- ChainHeadEvent
- ChainSideEvent
- NewMinedBlockEvent
- NewTxsEvent
Appendix B. 详细批注
1. type NewTxsEvent struct
事件 NewTxsEvent 在一组交易进入交易池时被发布。
- Txs []*types.Transaction: 交易列表
2. type PendingLogsEvent struct
事件 PendingLogsEvent 在挖矿前发布,并通知待处理日志。
3. type NewMinedBlockEvent struct
事件 NewMinedBlockEvent 在一个新区块被导入时发布。本地节点在接收到网络中其它节点打包出的新区块时,本地节点触发此事件。
4. type RemovedLogsEvent struct
事件 RemovedLogsEvent 在重新组织时被发布。
5. type ChainEvent struct
事件 ChainEvent 表示本地节点挖出了新区块。
- Block *types.Block: 区块
- Hash common.Hash: 区块哈希
- Logs []*types.Log: 日志列表
6. type ChainSideEvent struct
事件 ChainSideEvent 表示本地节点挖出了叔区块。
- Block *types.Block: 叔区块
7. type ChainHeadEvent struct
事件 ChainHeadEvent 表示本地节点挖出了新区块。
- Block *types.Block: 区块
Reference
Contributor
- Windstamp, https://github.com/windstamp