core

package
v1.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuildMerkleTree

func BuildMerkleTree(txs []common.Transaction) []byte

func LoadConfig

func LoadConfig(filepath string)

LoadConfig 在启动时运行一次,加载配置文件

Types

type BlockBuffer

type BlockBuffer struct {
	// contains filtered or unexported fields
}

BlockBuffer 维护一个树形结构的缓冲区,保存当前视图下的区块信息

func NewBlockBuffer

func NewBlockBuffer(latest *common.Block, popChan chan *common.Block) (*BlockBuffer, error)

func (*BlockBuffer) AppendBlock

func (b *BlockBuffer) AppendBlock(block *common.Block)

AppendBlock 添加区块到该缓冲区处理队列 传入一个区块,区块会被添加到 channel 中

func (*BlockBuffer) GetPriorityLeaf

func (b *BlockBuffer) GetPriorityLeaf(nowHeight int64) *common.Block

GetPriorityLeaf 获取当前视图下的最优树叶

func (*BlockBuffer) PopSelectedBlock

func (b *BlockBuffer) PopSelectedBlock() *common.Block

PopSelectedBlock 推出头部的最优区块什么时候触发? 应该来说是在 bufferedHeight - latestBlockHeight >= maxSize 的情况下触发? 以及,收到其他节点发来的已选取区块时触发该逻辑,但是需要确定一下高度和哈希值

func (*BlockBuffer) Process

func (b *BlockBuffer) Process()

Process 是 BlockBuffer 的线程函数,它依次接收区块进行处理

type BlockChain

type BlockChain struct {
	// contains filtered or unexported fields
}

func NewBlockchain

func NewBlockchain(db *utils.LevelDB) *BlockChain

NewBlockchain 创建一个 BlockChain 实,需要传入一个 LevelDB 实例 db

func (*BlockChain) AppendBlockTask

func (bc *BlockChain) AppendBlockTask(block *common.Block)

AppendBlockTask 向区块缓冲视图中添加区块处理任务

func (*BlockChain) BlockProcessRoutine

func (bc *BlockChain) BlockProcessRoutine()

BlockProcessRoutine 接收处理 channel 中的区块

func (*BlockChain) BufferFull

func (bc *BlockChain) BufferFull() bool

func (*BlockChain) BufferedHeight

func (bc *BlockChain) BufferedHeight() int64

func (*BlockChain) GetBlockByHash

func (bc *BlockChain) GetBlockByHash(hash *common.Hash) (*common.Block, error)

func (*BlockChain) GetBlockByHeight

func (bc *BlockChain) GetBlockByHeight(height int64) (*common.Block, error)

GetBlockByHeight 根据高度拉取区块,需要考虑一下同步时是否换用其他的函数?

func (*BlockChain) GetLatestBlock

func (bc *BlockChain) GetLatestBlock() (*common.Block, error)

GetLatestBlock 获取当前的最新区块

func (*BlockChain) GetTransactionByHash

func (bc *BlockChain) GetTransactionByHash(hash common.Hash) (*common.Transaction, error)

GetTransactionByHash 通过交易的哈希值来获取交易

func (*BlockChain) Height

func (bc *BlockChain) Height() int64

func (*BlockChain) InsertBlock

func (bc *BlockChain) InsertBlock(block *common.Block)

func (*BlockChain) NewGenesisBlock

func (bc *BlockChain) NewGenesisBlock()

NewGenesisBlock 创建创世区块

func (*BlockChain) PackageNewBlock

func (bc *BlockChain) PackageNewBlock(txs []common.Transaction, timestamp int64, params *common.GeneralParams, packageInterval int64) (*common.Block, error)

PackageNewBlock 打包新的区块,传入交易序列

func (*BlockChain) ReadAddressData

func (bc *BlockChain) ReadAddressData(address, key string) ([]byte, error)

type DataProcessor

type DataProcessor struct {
	// contains filtered or unexported fields
}

func NewDataProcessor

func NewDataProcessor() *DataProcessor

func (*DataProcessor) Run

func (dp *DataProcessor) Run()

type DataTask

type DataTask struct {
	Type    string
	Hash    common.Hash
	Height  int64
	Address []byte
	Key     []byte
	Value   []byte
}

type TxPool

type TxPool struct {
	// contains filtered or unexported fields
}

func GetTxPoolInst

func GetTxPoolInst() *TxPool

func NewTxPool

func NewTxPool(chain *BlockChain) *TxPool

func (*TxPool) Add

func (pool *TxPool) Add(transaction *common.Transaction)

func (*TxPool) CleanPool

func (pool *TxPool) CleanPool()

func (*TxPool) Contain

func (pool *TxPool) Contain(hash string) bool

func (*TxPool) Get

func (pool *TxPool) Get(hash string) *common.Transaction

func (*TxPool) Package

func (pool *TxPool) Package() []common.Transaction

Package 用于打包交易,这里返回的是 Transaction 的切片 todo: 需要具体观察打包交易时的效率问题

func (*TxPool) RemoveTx

func (pool *TxPool) RemoveTx(hash common.Hash)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL