memunit

package
v1.0.9 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2020 License: GPL-3.0, GPL-3.0 Imports: 21 Imported by: 0

README

MemDag是专门用于存储非稳定单元的地方。 新产生的单元,没有群签名的情况下,都应先进入MemDag。MemDag负责存储所有分支,并确定最长链作为主链,但是不计算稳定单元。

#情形

  1. 加入了一个不稳定单元
    1. 该单元在当前最新单元的后面
    2. 该单元在当前最新单元的另一个分支上
    3. 该单元高度小于稳定单元:无效单元,舍弃
  2. 更新了一个稳定单元
    1. 该新稳定单元在MemDag中
    2. 该新稳定单元找不到
    3. 该新稳定单元没有现有稳定单元高

对外接口

增加一个单元

设置一个稳定单元

获得最新单元

获得主链上到稳定单元的所有单元

根据UnitHash或者Number获取一个单元

Documentation

Overview

* * This file is part of go-palletone. * go-palletone is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * go-palletone 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 General Public License for more details. * You should have received a copy of the GNU General Public License * along with go-palletone. If not, see <http://www.gnu.org/licenses/>. * / * * * @author PalletOne core developers <dev@pallet.one> * * @date 2018-2019 *

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ChainTempDb added in v1.0.1

type ChainTempDb struct {
	Tempdb         *ptndb.Tempdb
	UnitRep        comm2.IUnitRepository
	UtxoRep        comm2.IUtxoRepository
	StateRep       comm2.IStateRepository
	PropRep        comm2.IPropRepository
	UnitProduceRep comm2.IUnitProduceRepository
	Validator      validator.Validator
	Unit           *modules.Unit
}

func NewChainTempDb added in v1.0.1

func NewChainTempDb(db ptndb.Database,
	cache palletcache.ICache, tokenEngine tokenengine.ITokenEngine, saveHeaderOnly bool,
	builderFunc validator.ValidatorBuilderFunc, enableGasFee bool) (*ChainTempDb, error)

func (*ChainTempDb) AddUnit added in v1.0.1

func (chain_temp *ChainTempDb) AddUnit(unit *modules.Unit, saveHeaderOnly bool) (*ChainTempDb, error)

type ContractSupportRepository added in v1.0.6

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

func NewContractSupportRepository added in v1.0.6

func NewContractSupportRepository(db ptndb.Database, enableGasFee bool) *ContractSupportRepository

func (*ContractSupportRepository) GetAddr1TokenUtxos added in v1.0.6

func (c *ContractSupportRepository) GetAddr1TokenUtxos(addr common.Address, asset *modules.Asset) (map[modules.OutPoint]*modules.Utxo, error)

func (*ContractSupportRepository) GetAddrByOutPoint added in v1.0.6

func (c *ContractSupportRepository) GetAddrByOutPoint(outPoint *modules.OutPoint) (common.Address, error)

func (*ContractSupportRepository) GetAddrUtxos added in v1.0.6

func (c *ContractSupportRepository) GetAddrUtxos(addr common.Address) (map[modules.OutPoint]*modules.Utxo, error)

func (*ContractSupportRepository) GetChainParameters added in v1.0.6

func (c *ContractSupportRepository) GetChainParameters() *core.ChainParameters

func (*ContractSupportRepository) GetContract added in v1.0.6

func (c *ContractSupportRepository) GetContract(id []byte) (*modules.Contract, error)

func (*ContractSupportRepository) GetContractState added in v1.0.6

func (c *ContractSupportRepository) GetContractState(contractid []byte, field string) ([]byte, *modules.StateVersion, error)

func (*ContractSupportRepository) GetContractStatesById added in v1.0.6

func (c *ContractSupportRepository) GetContractStatesById(contractid []byte) (map[string]*modules.ContractStateValue, error)

func (*ContractSupportRepository) GetContractStatesByPrefix added in v1.0.6

func (c *ContractSupportRepository) GetContractStatesByPrefix(contractid []byte, prefix string) (map[string]*modules.ContractStateValue, error)

func (*ContractSupportRepository) GetContractTpl added in v1.0.6

func (c *ContractSupportRepository) GetContractTpl(tplId []byte) (*modules.ContractTemplate, error)

func (*ContractSupportRepository) GetContractTplCode added in v1.0.6

func (c *ContractSupportRepository) GetContractTplCode(tplId []byte) ([]byte, error)

func (*ContractSupportRepository) GetContractsWithJuryAddr added in v1.0.6

func (c *ContractSupportRepository) GetContractsWithJuryAddr(addr common.Hash) []*modules.Contract

func (*ContractSupportRepository) GetDb added in v1.0.6

func (*ContractSupportRepository) GetGlobalProp added in v1.0.6

func (c *ContractSupportRepository) GetGlobalProp() *modules.GlobalProperty

func (*ContractSupportRepository) GetHeaderByNumber added in v1.0.6

func (c *ContractSupportRepository) GetHeaderByNumber(number *modules.ChainIndex) (*modules.Header, error)

func (*ContractSupportRepository) GetImmutableChainParameters added in v1.0.6

func (c *ContractSupportRepository) GetImmutableChainParameters() *core.ImmutableChainParameters

func (*ContractSupportRepository) GetNewestUnit added in v1.0.6

func (*ContractSupportRepository) GetStableTransactionOnly added in v1.0.6

func (c *ContractSupportRepository) GetStableTransactionOnly(hash common.Hash) (*modules.Transaction, error)

func (*ContractSupportRepository) GetStableUnit added in v1.0.6

func (c *ContractSupportRepository) GetStableUnit(hash common.Hash) (*modules.Unit, error)

func (*ContractSupportRepository) GetStableUnitByNumber added in v1.0.6

func (c *ContractSupportRepository) GetStableUnitByNumber(number *modules.ChainIndex) (*modules.Unit, error)

func (*ContractSupportRepository) GetUtxoEntry added in v1.0.6

func (c *ContractSupportRepository) GetUtxoEntry(outpoint *modules.OutPoint) (*modules.Utxo, error)

func (*ContractSupportRepository) NewTemp added in v1.0.6

func (*ContractSupportRepository) SaveContract added in v1.0.6

func (c *ContractSupportRepository) SaveContract(contract *modules.Contract) error

func (*ContractSupportRepository) SaveTransaction added in v1.0.6

func (c *ContractSupportRepository) SaveTransaction(tx *modules.Transaction, txIndex int) error

func (*ContractSupportRepository) UnstableHeadUnitProperty added in v1.0.6

func (c *ContractSupportRepository) UnstableHeadUnitProperty(asset modules.AssetId) (*modules.UnitProperty, error)

type IMemDag

type IMemDag interface {
	//增加一个稳定单元
	AddStableUnit(unit *modules.Unit) error
	////设置MemDag的稳定单元
	//SetStableUnit(unit *modules.Unit, isGenesis bool)
	//增加一个单元到MemDag
	AddUnit(unit *modules.Unit, isProd bool) (common2.IUnitRepository, common2.IUtxoRepository,
		common2.IStateRepository, common2.IPropRepository, common2.IUnitProduceRepository, error)
	//保存Header
	SaveHeader(header *modules.Header) error
	//获取最新稳定单元的信息
	GetLastStableUnitInfo() (common.Hash, uint64)
	//获取主链的最新单元
	GetLastMainChainUnit() *modules.Unit
	//获取所有的不稳定单元
	GetChainUnits() map[common.Hash]*modules.Unit
	//设置要形成稳定单元的阈值,一般是2/3*Count(Mediator)
	SetStableThreshold(threshold int)
	//获得不稳定的Repository
	GetUnstableRepositories() (common2.IUnitRepository, common2.IUtxoRepository, common2.IStateRepository,
		common2.IPropRepository, common2.IUnitProduceRepository)
	//设置一个单元的群签名,使得该单元稳定
	SetUnitGroupSign(uHash common.Hash, groupSign []byte) error
	//通过Hash获得Header
	GetHeaderByHash(hash common.Hash) (*modules.Header, error)
	//通过高度获得Header
	GetHeaderByNumber(number *modules.ChainIndex) (*modules.Header, error)
	//获得MemDag的信息,包括分叉情况,孤儿块等
	Info() (*modules.MemdagStatus, error)
	//订阅切换主链事件
	SubscribeSwitchMainChainEvent(ob SwitchMainChainEventFunc)
	SubscribeToGroupSignEvent(ch chan<- modules.ToGroupSignEvent) event.Subscription
	SubscribeSaveStableUnitEvent(ch chan<- modules.SaveUnitEvent) event.Subscription
	SubscribeSaveUnitEvent(ch chan<- modules.SaveUnitEvent) event.Subscription

	SubscribeRollbackUnitEvent(ch chan<- modules.RollbackUnitEvent) event.Subscription

	//关闭
	Close()
}

不稳定单元和新单元的操作

type MemDag

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

func NewMemDag

func NewMemDag(token modules.AssetId, threshold int, saveHeaderOnly, enableGasFee bool, db ptndb.Database,
	stableUnitRep common2.IUnitRepository, propRep common2.IPropRepository,
	stableStateRep common2.IStateRepository, cache palletcache.ICache,
	tokenEngine tokenengine.ITokenEngine, builderFunc validator.ValidatorBuilderFunc) *MemDag

func (*MemDag) AddStableUnit added in v1.0.3

func (chain *MemDag) AddStableUnit(unit *modules.Unit) error

func (*MemDag) Close

func (pmg *MemDag) Close()

func (*MemDag) GetChainUnits

func (chain *MemDag) GetChainUnits() map[common.Hash]*modules.Unit

查询所有不稳定单元(不包括孤儿单元)

func (*MemDag) GetHeaderByHash

func (chain *MemDag) GetHeaderByHash(hash common.Hash) (*modules.Header, error)

func (*MemDag) GetHeaderByNumber

func (chain *MemDag) GetHeaderByNumber(number *modules.ChainIndex) (*modules.Header, error)

func (*MemDag) GetLastMainChainUnit

func (chain *MemDag) GetLastMainChainUnit() *modules.Unit

func (*MemDag) GetLastStableUnitHash added in v1.0.5

func (chain *MemDag) GetLastStableUnitHash() common.Hash

func (*MemDag) GetLastStableUnitHeight added in v1.0.5

func (chain *MemDag) GetLastStableUnitHeight() uint64

func (*MemDag) GetLastStableUnitInfo added in v1.0.1

func (chain *MemDag) GetLastStableUnitInfo() (common.Hash, uint64)

func (*MemDag) Info added in v1.0.4

func (chain *MemDag) Info() (*modules.MemdagStatus, error)

func (*MemDag) SaveHeader added in v1.0.4

func (chain *MemDag) SaveHeader(header *modules.Header) error

func (*MemDag) SetStableThreshold

func (pmg *MemDag) SetStableThreshold(count int)

func (*MemDag) SetUnitGroupSign

func (chain *MemDag) SetUnitGroupSign(uHash common.Hash, groupSign []byte) error

func (*MemDag) SubscribeRollbackUnitEvent added in v1.0.7

func (pmg *MemDag) SubscribeRollbackUnitEvent(ch chan<- modules.RollbackUnitEvent) event.Subscription

func (*MemDag) SubscribeSaveStableUnitEvent added in v1.0.6

func (pmg *MemDag) SubscribeSaveStableUnitEvent(ch chan<- modules.SaveUnitEvent) event.Subscription

func (*MemDag) SubscribeSaveUnitEvent added in v1.0.7

func (pmg *MemDag) SubscribeSaveUnitEvent(ch chan<- modules.SaveUnitEvent) event.Subscription

func (*MemDag) SubscribeSwitchMainChainEvent added in v1.0.4

func (pmg *MemDag) SubscribeSwitchMainChainEvent(ob SwitchMainChainEventFunc)

func (*MemDag) SubscribeToGroupSignEvent

func (pmg *MemDag) SubscribeToGroupSignEvent(ch chan<- modules.ToGroupSignEvent) event.Subscription

type SwitchMainChainEvent added in v1.0.4

type SwitchMainChainEvent struct {
	OldLastUnit *modules.Unit
	NewLastUnit *modules.Unit
}

type SwitchMainChainEventFunc added in v1.0.4

type SwitchMainChainEventFunc func(event *SwitchMainChainEvent)

Jump to

Keyboard shortcuts

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