chain

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 5, 2019 License: MIT Imports: 34 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BlockMsgChBufferSize        = 1024
	EternalBlockMsgChBufferSize = 65536

	MaxTimeOffsetSeconds = 2 * 60 * 60
	MaxBlockSize         = 32000000
	CoinbaseLib          = 100

	PeriodDuration = 21 * 5 * 10000

	MaxBlocksPerSync = 1024

	Threshold = 32
)

const defines constants

View Source
const (
	// BlockTableName is the table name of db to store block chain data
	BlockTableName = "core"

	// WalletTableName is the table name of db to store wallet data
	WalletTableName = "wl"

	// Tail is the db key name of tail block
	Tail = "/tail"

	// Genesis is the db key name of genesis block
	Genesis = "/genesis"

	// Eternal is the db key name of eternal block
	Eternal = "/eternal"

	// Period is the db key name of current period
	Period = "/period/current"

	// MissCount is the db key name of minuer's block miss rate data
	// value: 4 bytes height + 4 bytes miss count + 10 bytes ts
	MissCount = "/missrate"

	// BlockPrefix is the key prefix of database key to store block content
	// /bk/{hex encoded block hash}
	// e.g.
	// key: /bk/005973c44c4879b137c3723c96d2e341eeaf83fe58845b2975556c9f3bd640bb
	// value: block binary
	BlockPrefix = "/bk"

	// TxPrefix is the key prefix of database key to store tx content
	TxPrefix = "/tx"

	// BlockHashPrefix is the key prefix of database key to store block hash of specified height
	// /bh/{hex encoded height}
	//e.g.
	// key: /bh/3e2d
	// value: block hash binary
	BlockHashPrefix = "/bh"

	// TxIndexPrefix is the key prefix of database key to store tx index
	// /ti/{hex encoded tx hash}
	// e.g.
	// key: /ti/1113b8bdad74cdc045e64e09b3e2f0502d1b7f9bd8123b28239a3360bd3a8757
	// value: 4 bytes height + 4 bytes index in txs
	TxIndexPrefix = "/ti"

	// UtxoPrefix is the key prefix of database key to store utxo content
	// /ut/{hex encoded tx hash}/{vout index}
	// e.g.
	// key: /ut/1113b8bdad74cdc045e64e09b3e2f0502d1b7f9bd8123b28239a3360bd3a8757/2
	// value: utxo wrapper
	UtxoPrefix = "/ut"

	// CandidatesPrefix is the key prefix of database key to store candidates
	CandidatesPrefix = "/candidates"
	// FilterPrefix is the key prefix of block bloom filter to store a filter bytes
	// /bf/{hex encoded block hash}
	// e.g.
	// key: /bf/1113b8bdad74cdc045e64e09b3e2f0502d1b7f9bd8123b28239a3360bd3a8757
	// value: crypto hash
	FilterPrefix = "/bf"
	// SplitAddressPrefix is the key prefix of split address
	SplitAddressPrefix = "/sap"

	// AddressUtxoPrefix is the key prefix of database key to store address related utxo
	AddressUtxoPrefix = "/aut"

	// AddressTokenUtxoPrefix is the key prefix of database key to store address related token utxo
	AddressTokenUtxoPrefix = "/atut"

	// AddrBalancePrefix is the key prefix of database key to store address box balance
	AddrBalancePrefix = "/bal"
	// AddrTokenBalancePrefix is the key prefix of database key to store address token balance
	AddrTokenBalancePrefix = "/tbal"
)

Variables

View Source
var (

	// TotalSupply is the total supply of box: 3 billion
	TotalSupply = (uint64)(3e9 * core.DuPerBox)

	// CoinbaseMaturity coinbase only spendable after this many blocks
	CoinbaseMaturity = (uint32)(0)

	// BaseSubsidy is the starting subsidy amount for mined blocks.
	// This value is halved every SubsidyReductionInterval blocks.
	BaseSubsidy = (uint64)(50 * core.DuPerBox)

	// CandidatePledge is pledge for candidate to mint.
	CandidatePledge = (uint64)(1e6 * core.DuPerBox)

	// MinNumOfVotes is Minimum number of votes
	MinNumOfVotes = (uint64)(100)
)
View Source
var EternalKey = []byte(Eternal)

EternalKey is the db key to store eternal block content

View Source
var GenesisBlock = types.Block{
	Header: &types.BlockHeader{
		Version:       1,
		PrevBlockHash: crypto.HashType{},
		TimeStamp:     time.Date(2018, 1, 31, 0, 0, 0, 0, time.UTC).Unix(),
	},
	Height: 0,
}

GenesisBlock represents genesis block.

View Source
var GenesisKey = []byte(Genesis)

GenesisKey is the db key to store genesis block content

View Source
var GenesisPeriod = []map[string]string{
	{
		"addr":   "b1YaxM6pR9vWejxbEJ8cmHhebPcLHyKZn2F",
		"peerID": "12D3KooWPWfagC42R1DjpB8VMaQbwdqNLWtXwzhS1UuVuYHVjGc8",
	},
	{
		"addr":   "b1hE3LghriqzGnuuFtSNWNKRiwEGZACQwyx",
		"peerID": "12D3KooWSTL8TCZpRc6WjTZYtmzbAiDCbEUDuw9VzXCokSFER1v7",
	},

	{
		"addr":   "b1VGrGhmraZ1A96S9qj5FaWWgGgi7bsjY9P",
		"peerID": "12D3KooWPpJsKMsCgu9UpU2KH9PU1un37HZo81mhiMYs7Zkem8qC",
	},
	{
		"addr":   "b1aFeMqvL9AzWoxPi1ojPDM9veTrgBC9fg8",
		"peerID": "12D3KooWHWVZpXoXQqM5F6kLzdxdD2mStRn34UiKccdmtLTyU8iN",
	},

	{
		"addr":   "b1f3WDbds2vypDx1vzHiRnhX1mCEAdUYPFP",
		"peerID": "12D3KooWPXieg5ZEUzbHaKNFMsL3DxxUxoHytuojrKJk74G7weRg",
	},
	{
		"addr":   "b1qLJXfr3xcAL85LKGZbkpvDcfRFiUbg75g",
		"peerID": "12D3KooWEf6zh21ATMAF3JGhyCNJPreJUmUYiB4uchMoqKgjDjCi",
	},

	{
		"addr":   "b1qW9wwyd1VDN75Mao9e8k7nVVVmcc6mJ7w",
		"peerID": "12D3KooWGHyrGhQkPY6nUSnstYwuNFs5CmytofQfdkiR8DLygbrB",
	},
	{
		"addr":   "b1iGd3kcZKnT7zPf6k48j8juv8pRMe8Fw65",
		"peerID": "12D3KooWGUK3nyQwm7Wew3HWu6jX8vB1CyqUqQ7u9wNYUcF3FCXC",
	},

	{
		"addr":   "b1nyv68asDNhCUudpF2bvELyBPzEEoQU5KC",
		"peerID": "12D3KooWPkoxuH9sfmfBwBHxn7YgxFSfQAPBms9p1eWPd5BGh2T6",
	},
	{
		"addr":   "b1mDDEWqQnX4yPLq6UDCfXX8LVGhTYHDMB7",
		"peerID": "12D3KooWCy9vMmStynZJuqJ8Yj1r6XaVADtqBAfNWe4De4WDaHR7",
	},

	{
		"addr":   "b1mpGAYQjwSWoDzuXnZqCW9RaRBjKHMCVEx",
		"peerID": "12D3KooWEUHqAhaaSZrG9R8p85XnVJC4e3iz4dM26Z1LQfZsMu7F",
	},
	{
		"addr":   "b1g8TPMT4mFZEcDZWomPJWXit4suGHs1eoq",
		"peerID": "12D3KooWS9afhAEkmT437oNkPBGkNLHJ9EkL5r4h2aXc6bsZgaTD",
	},

	{
		"addr":   "b1UTAV44cCeCF1SZc23szgHxFiMMbma4PHB",
		"peerID": "12D3KooWNANjisCyouVwekviY7hodpyBJrT5YWsi1xSMYbtDAWhN",
	},
	{
		"addr":   "b1mr7Rk5fQkS3avFDtQpKhzPak87fzZu6ta",
		"peerID": "12D3KooWAMTzTN4DuJck63sfQvRjp4jT1hjoYF2ucbGEvwoy2pRK",
	},
	{
		"addr":   "b1k9dMK6xrsXYCBuJfjTN9eTsMCiRb18Hnt",
		"peerID": "12D3KooWCZVcNiuADTbzQwjNgj5hzbCpQJPo3JkBXwafXSggx4AG",
	},
}

GenesisPeriod genesis period

View Source
var MissrateKey = []byte(MissCount)

MissrateKey is the db key to store miner's blocks miss rate

View Source
var PeriodKey = []byte(Period)

PeriodKey is the db key to store current period contex content

View Source
var TailKey = []byte(Tail)

TailKey is the db key to store tail block content

Functions

func AddrAllTokenUtxoKey added in v0.3.0

func AddrAllTokenUtxoKey(addr string, tid txlogic.TokenID) []byte

AddrAllTokenUtxoKey is the key prefix to explore all token utxos of an address

func AddrAllUtxoKey added in v0.3.0

func AddrAllUtxoKey(addr string) []byte

AddrAllUtxoKey is the key prefix to explore all utxos of an address

func AddrBalanceKey added in v0.3.0

func AddrBalanceKey(addr string) []byte

AddrBalanceKey is the key to store an address's balance

func AddrTokenBalanceKey added in v0.3.0

func AddrTokenBalanceKey(addr string, token types.OutPoint) []byte

AddrTokenBalanceKey is the key to store an address's token balance

func AddrTokenUtxoKey added in v0.3.0

func AddrTokenUtxoKey(addr string, tid txlogic.TokenID, op types.OutPoint) []byte

AddrTokenUtxoKey is the key to store an token utxo which belongs to the input param address

func AddrUtxoKey added in v0.3.0

func AddrUtxoKey(addr string, op types.OutPoint) []byte

AddrUtxoKey is the key to store an utxo which belongs to the input param address

func BlockHashKey

func BlockHashKey(height uint32) []byte

BlockHashKey returns the db key to store block hash content of the height

func BlockHeightFromBlockHashKey added in v0.3.0

func BlockHeightFromBlockHashKey(k []byte) uint32

BlockHeightFromBlockHashKey parse height info from a BlockHashKey

func BlockHeightPrefix added in v0.3.0

func BlockHeightPrefix() []byte

BlockHeightPrefix returns the db key prefix to store hash content of the height

func BlockKey

func BlockKey(h *crypto.HashType) []byte

BlockKey returns the db key to store block content of the hash

func CalcBlockSubsidy

func CalcBlockSubsidy(height uint32) uint64

CalcBlockSubsidy returns the subsidy amount a block at the provided height should have.

func CalcCandidatePledgeHeight added in v0.3.0

func CalcCandidatePledgeHeight(tailHeight int64) int64

CalcCandidatePledgeHeight calc current candidate pledge height

func CalcTxsHash

func CalcTxsHash(txs []*types.Transaction) *crypto.HashType

CalcTxsHash calculate txsHash in block.

func CandidatesKey

func CandidatesKey(h *crypto.HashType) []byte

CandidatesKey returns the db key to store candidates.

func CreateCoinbaseTx

func CreateCoinbaseTx(addr []byte, blockHeight uint32) (*types.Transaction, error)

CreateCoinbaseTx creates a coinbase give miner address and block height

func DeserializeUtxoWrap added in v0.3.0

func DeserializeUtxoWrap(serialized []byte) (*types.UtxoWrap, error)

DeserializeUtxoWrap returns UtxoWrap form serialized bytes.

func FilterHeightHashFromKey added in v0.3.0

func FilterHeightHashFromKey(k []byte) (uint32, string)

FilterHeightHashFromKey parse height and hash info from a FilterKey

func FilterKey

func FilterKey(height uint32, hash crypto.HashType) []byte

FilterKey returns the db key to store bloom filter of block

func FilterKeyPrefix added in v0.3.0

func FilterKeyPrefix() []byte

FilterKeyPrefix returns the db key prefix to store bloom filter of block

func IsCoinBase

func IsCoinBase(tx *types.Transaction) bool

IsCoinBase determines whether or not a transaction is a coinbase.

func IsTxFinalized

func IsTxFinalized(tx *types.Transaction, blockHeight uint32, blockTime int64) bool

IsTxFinalized checks if a transaction is finalized.

func MarshalMissData added in v0.3.0

func MarshalMissData(height, miss uint32, ts int64) (data []byte, err error)

MarshalMissData writes miss rate data to bytes

func MarshalTxIndex

func MarshalTxIndex(height, index uint32) (data []byte, err error)

MarshalTxIndex writes Tx height and index to bytes

func SerializeUtxoWrap added in v0.3.0

func SerializeUtxoWrap(utxoWrap *types.UtxoWrap) ([]byte, error)

SerializeUtxoWrap returns the utxoWrap serialized to a format that is suitable for long-term storage.

func SplitAddrKey added in v0.3.0

func SplitAddrKey(hash []byte) []byte

SplitAddrKey returns the db key to store split address

func TokenPreAllocation added in v0.3.0

func TokenPreAllocation() ([]*types.Transaction, error)

TokenPreAllocation is for token preallocation

func TxIndexKey

func TxIndexKey(h *crypto.HashType) []byte

TxIndexKey returns the db key to store tx index of the hash

func TxKey added in v0.3.0

func TxKey(h *crypto.HashType) []byte

TxKey returns the db key to store tx content of the hash

func UnmarshalMissData added in v0.3.0

func UnmarshalMissData(data []byte) (height uint32, miss uint32, ts int64, err error)

UnmarshalMissData return tx index from bytes

func UnmarshalTxIndex

func UnmarshalTxIndex(data []byte) (height uint32, index uint32, err error)

UnmarshalTxIndex return tx index from bytes

func ValidateTransactionPreliminary

func ValidateTransactionPreliminary(tx *types.Transaction) error

ValidateTransactionPreliminary performs some preliminary checks on a transaction to ensure it is sane. These checks are context free.

func ValidateTxInputs

func ValidateTxInputs(utxoSet *UtxoSet, tx *types.Transaction, txHeight uint32) (uint64, error)

ValidateTxInputs validates the inputs of a tx. Returns the total tx fee.

func VerifyBlockTimeOut

func VerifyBlockTimeOut(block *types.Block) error

VerifyBlockTimeOut refuse to accept a block with wrong timestamp.

Types

type BlockChain

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

BlockChain define chain struct

func NewBlockChain

func NewBlockChain(parent goprocess.Process, notifiee p2p.Net, db storage.Storage, bus eventbus.Bus) (*BlockChain, error)

NewBlockChain return a blockchain.

func NewTestBlockChain

func NewTestBlockChain() *BlockChain

NewTestBlockChain generate a chain for testing

func (*BlockChain) Bus

func (chain *BlockChain) Bus() eventbus.Bus

Bus returns the goprocess of the BlockChain

func (*BlockChain) CalcRootHashForNBlocks

func (chain *BlockChain) CalcRootHashForNBlocks(hash crypto.HashType, num uint32) (*crypto.HashType, error)

CalcRootHashForNBlocks return root hash for N blocks.

func (*BlockChain) ChangeNewTail added in v0.3.0

func (chain *BlockChain) ChangeNewTail(tail *types.Block)

ChangeNewTail change chain tail block.

func (*BlockChain) Consensus added in v0.3.0

func (chain *BlockChain) Consensus() types.Consensus

Consensus return chain consensus.

func (*BlockChain) DB

func (chain *BlockChain) DB() storage.Table

DB return chain db storage.

func (*BlockChain) DelSplitTxs added in v0.3.0

func (chain *BlockChain) DelSplitTxs(splitTxs []*types.Transaction, batch storage.Batch) error

DelSplitTxs del split txs.

func (*BlockChain) DelTxIndex

func (chain *BlockChain) DelTxIndex(block *types.Block, splitTxs []*types.Transaction, batch storage.Batch) error

DelTxIndex deletes tx index in block Delete split transaction copies saved earlier, both before and after split

func (*BlockChain) DeleteSplitAddrIndex added in v0.3.0

func (chain *BlockChain) DeleteSplitAddrIndex(block *types.Block, batch storage.Batch) error

DeleteSplitAddrIndex remove split address index from both db and cache

func (*BlockChain) EternalBlock

func (chain *BlockChain) EternalBlock() *types.Block

EternalBlock return chain eternal block.

func (*BlockChain) FetchNBlockAfterSpecificHash

func (chain *BlockChain) FetchNBlockAfterSpecificHash(hash crypto.HashType, num uint32) ([]*types.Block, error)

FetchNBlockAfterSpecificHash get N block after specific hash.

func (*BlockChain) Genesis added in v0.3.0

func (chain *BlockChain) Genesis() *types.Block

Genesis return chain tail block.

func (*BlockChain) GetBlockHash

func (chain *BlockChain) GetBlockHash(blockHeight uint32) (*crypto.HashType, error)

GetBlockHash finds the block in target height of main chain and returns it's hash

func (*BlockChain) GetBlockHeight

func (chain *BlockChain) GetBlockHeight() uint32

GetBlockHeight returns current height of main chain

func (*BlockChain) GetDataFromDB added in v0.3.0

func (chain *BlockChain) GetDataFromDB(key []byte) ([]byte, error)

GetDataFromDB get data from db

func (*BlockChain) GetParentBlock added in v0.3.0

func (chain *BlockChain) GetParentBlock(block *types.Block) *types.Block

GetParentBlock Finds the parent of a block. Return nil if nonexistent

func (*BlockChain) IsBusy added in v0.3.0

func (chain *BlockChain) IsBusy() bool

IsBusy return if the chain is processing a block

func (*BlockChain) IsCoinBase added in v0.3.0

func (chain *BlockChain) IsCoinBase(tx *types.Transaction) bool

IsCoinBase checks if an transaction is coinbase transaction

func (*BlockChain) LoadBlockByHash

func (chain *BlockChain) LoadBlockByHash(hash crypto.HashType) (*types.Block, error)

LoadBlockByHash load block by hash from db.

func (*BlockChain) LoadBlockByHeight

func (chain *BlockChain) LoadBlockByHeight(height uint32) (*types.Block, error)

LoadBlockByHeight load block by height from db.

func (*BlockChain) LoadBlockInfoByTxHash added in v0.3.0

func (chain *BlockChain) LoadBlockInfoByTxHash(hash crypto.HashType) (*types.Block, *types.Transaction, error)

LoadBlockInfoByTxHash returns block and txIndex of transaction with the input param hash

func (*BlockChain) LoadEternalBlock added in v0.3.0

func (chain *BlockChain) LoadEternalBlock() (*types.Block, error)

LoadEternalBlock returns the current highest eternal block

func (*BlockChain) LocateForkPointAndFetchHeaders

func (chain *BlockChain) LocateForkPointAndFetchHeaders(hashes []*crypto.HashType) ([]*crypto.HashType, error)

LocateForkPointAndFetchHeaders return block headers when get locate fork point request for sync service.

func (*BlockChain) Proc

func (chain *BlockChain) Proc() goprocess.Process

Proc returns the goprocess of the BlockChain

func (*BlockChain) ProcessBlock

func (chain *BlockChain) ProcessBlock(block *types.Block, transferMode core.TransferMode, fastConfirm bool, messageFrom peer.ID) error

ProcessBlock is used to handle new blocks.

func (*BlockChain) ReadBlockFromDB added in v0.3.0

func (chain *BlockChain) ReadBlockFromDB(hash *crypto.HashType) (*types.Block, int, error)

ReadBlockFromDB reads a block from db by hash and returns block and it's size

func (*BlockChain) RemoveBlock added in v0.3.0

func (chain *BlockChain) RemoveBlock(block *types.Block)

RemoveBlock store block to db.

func (*BlockChain) Run

func (chain *BlockChain) Run() error

Run launch blockchain.

func (*BlockChain) SetEternal

func (chain *BlockChain) SetEternal(block *types.Block) error

SetEternal set block eternal status.

func (*BlockChain) Setup

func (chain *BlockChain) Setup(consensus types.Consensus, syncManager types.SyncManager)

Setup prepare blockchain.

func (*BlockChain) Stop

func (chain *BlockChain) Stop()

Stop the blockchain service

func (*BlockChain) StoreBlock added in v0.3.0

func (chain *BlockChain) StoreBlock(block *types.Block) error

StoreBlock store block to db.

func (*BlockChain) StoreBlockInBatch added in v0.3.0

func (chain *BlockChain) StoreBlockInBatch(block *types.Block, batch storage.Batch) error

StoreBlockInBatch store block to db in batch mod.

func (*BlockChain) StoreEternalBlock

func (chain *BlockChain) StoreEternalBlock(block *types.Block) error

StoreEternalBlock store eternal block to db.

func (*BlockChain) StoreSplitTxs added in v0.3.0

func (chain *BlockChain) StoreSplitTxs(splitTxs []*types.Transaction, batch storage.Batch) error

StoreSplitTxs store split txs.

func (*BlockChain) StoreTailBlock

func (chain *BlockChain) StoreTailBlock(block *types.Block, batch storage.Batch) error

StoreTailBlock store tail block to db.

func (*BlockChain) TailBlock

func (chain *BlockChain) TailBlock() *types.Block

TailBlock return chain tail block.

func (*BlockChain) WriteSplitAddrIndex added in v0.3.0

func (chain *BlockChain) WriteSplitAddrIndex(block *types.Block, batch storage.Batch) error

WriteSplitAddrIndex writes split addr info index

func (*BlockChain) WriteTxIndex

func (chain *BlockChain) WriteTxIndex(block *types.Block, splitTxs []*types.Transaction, batch storage.Batch) error

WriteTxIndex builds tx index in block Save split transaction copies before and after split. The latter is needed when reverting a transaction during reorg, spending from utxo/coin received at a split address

type BloomFilterHolder

type BloomFilterHolder interface {
	ResetFilters(uint32) error
	ListMatchedBlockHashes([]byte) []crypto.HashType
	AddFilter(uint32, crypto.HashType, storage.Table, storage.Batch, func() bloom.Filter) error
}

BloomFilterHolder holds all bloom filters in main chain

func NewFilterHolder

func NewFilterHolder() BloomFilterHolder

NewFilterHolder creates an holder instance

type DummyDpos

type DummyDpos struct{}

DummyDpos dummy dpos

func (*DummyDpos) BroadcastEternalMsgToMiners

func (dpos *DummyDpos) BroadcastEternalMsgToMiners(block *types.Block) error

BroadcastEternalMsgToMiners broadcast etrnalmsg to miners

func (*DummyDpos) IsCandidateExist added in v0.3.0

func (dpos *DummyDpos) IsCandidateExist(addr types.AddressHash) bool

IsCandidateExist check candidate is exist.

func (*DummyDpos) RecoverMint

func (dpos *DummyDpos) RecoverMint()

RecoverMint revover mint

func (*DummyDpos) Run

func (dpos *DummyDpos) Run() error

Run dummy dpos

func (*DummyDpos) Stop

func (dpos *DummyDpos) Stop()

Stop dummy dpos

func (*DummyDpos) StopMint

func (dpos *DummyDpos) StopMint()

StopMint stop mint

func (*DummyDpos) StoreCandidateContext

func (dpos *DummyDpos) StoreCandidateContext(*types.Block, storage.Batch) error

StoreCandidateContext store candidate context

func (*DummyDpos) TryToUpdateEternalBlock added in v0.3.0

func (dpos *DummyDpos) TryToUpdateEternalBlock(src *types.Block)

TryToUpdateEternalBlock try to update eternal block.

func (*DummyDpos) UpdateCandidateContext added in v0.3.0

func (dpos *DummyDpos) UpdateCandidateContext(block *types.Block) error

UpdateCandidateContext update candidate context in memory.

func (*DummyDpos) ValidateMiner

func (dpos *DummyDpos) ValidateMiner() bool

ValidateMiner validate miner

func (*DummyDpos) VerifyCandidates added in v0.3.0

func (dpos *DummyDpos) VerifyCandidates(block *types.Block) error

VerifyCandidates vefiry if the block candidates hash is right.

func (*DummyDpos) VerifyMinerEpoch

func (dpos *DummyDpos) VerifyMinerEpoch(*types.Block) error

VerifyMinerEpoch verify miner epoch

func (*DummyDpos) VerifySign

func (dpos *DummyDpos) VerifySign(*types.Block) (bool, error)

VerifySign verify sign

type DummySyncManager

type DummySyncManager struct{}

DummySyncManager is only used to test

func NewDummySyncManager

func NewDummySyncManager() *DummySyncManager

NewDummySyncManager returns a new DummySyncManager

func (*DummySyncManager) ActiveLightSync

func (dm *DummySyncManager) ActiveLightSync(pid peer.ID) error

ActiveLightSync active light sync from remote peer.

func (*DummySyncManager) Run

func (dm *DummySyncManager) Run()

Run starts run

func (*DummySyncManager) StartSync

func (dm *DummySyncManager) StartSync()

StartSync starts sync

type FilterEntry

type FilterEntry struct {
	Filter    bloom.Filter
	Height    uint32
	BlockHash crypto.HashType
}

FilterEntry represents a bloom filter for the block of the given hash

type LockTime

type LockTime struct {
	Seconds     int64
	BlockHeight uint32
}

LockTime represents the relative lock-time in seconds

type MemoryBloomFilterHolder

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

MemoryBloomFilterHolder holds all bloom filters in main chain in an array format in memory

func (*MemoryBloomFilterHolder) AddFilter

func (holder *MemoryBloomFilterHolder) AddFilter(
	height uint32,
	hash crypto.HashType,
	db storage.Table,
	batch storage.Batch,
	onCacheMiss func() bloom.Filter) error

AddFilter adds a filter of block at height. Filter is loaded from db instance if it is stored, otherwise, it's calculated using onCacheMiss function

func (*MemoryBloomFilterHolder) ListMatchedBlockHashes

func (holder *MemoryBloomFilterHolder) ListMatchedBlockHashes(word []byte) []crypto.HashType

ListMatchedBlockHashes search all blocks' bloom filter, and returns block hashes that might contain a certain word

func (*MemoryBloomFilterHolder) ResetFilters

func (holder *MemoryBloomFilterHolder) ResetFilters(height uint32) error

ResetFilters resets filterEntry array to a height

type ScriptItem added in v0.3.0

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

ScriptItem saves scripts for parallel validation

func CheckTxScripts added in v0.3.0

func CheckTxScripts(utxoSet *UtxoSet, tx *types.Transaction, skipValidation bool) ([]*ScriptItem, error)

CheckTxScripts verifies unlocking script for each input to ensure it is authorized to spend the utxo Coinbase tx will not reach here

type UpdateMsg

type UpdateMsg struct {
	// block connected/disconnected from main chain
	AttachBlocks []*types.Block
	DetachBlocks []*types.Block
}

UpdateMsg sent from blockchain to, e.g., mempool

type UtxoSet

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

UtxoSet contains all utxos

func GetExtendedTxUtxoSet

func GetExtendedTxUtxoSet(tx *types.Transaction, db storage.Table,
	spendableTxs *sync.Map) (*UtxoSet, error)

GetExtendedTxUtxoSet returns tx's utxo set from both db & txs in spendableTxs

func NewUtxoSet

func NewUtxoSet() *UtxoSet

NewUtxoSet new utxo set

func NewUtxoSetFromMap

func NewUtxoSetFromMap(utxoMap types.UtxoMap) *UtxoSet

NewUtxoSetFromMap returns the underlying utxos as a map

func (*UtxoSet) AddUtxo

func (u *UtxoSet) AddUtxo(tx *types.Transaction, txOutIdx uint32, blockHeight uint32) error

AddUtxo adds a tx's outputs as utxos

func (*UtxoSet) All added in v0.3.0

func (u *UtxoSet) All() types.UtxoMap

All returns all utxo contained including spent utxo

func (*UtxoSet) ApplyBlock

func (u *UtxoSet) ApplyBlock(block *types.Block) error

ApplyBlock updates utxos with all transactions in the passed block

func (*UtxoSet) ApplyBlockWithScriptFilter

func (u *UtxoSet) ApplyBlockWithScriptFilter(block *types.Block, targetScript []byte) error

ApplyBlockWithScriptFilter adds or remove all utxos that transactions use or generate with the specified script bytes

func (*UtxoSet) ApplyTx

func (u *UtxoSet) ApplyTx(tx *types.Transaction, blockHeight uint32) error

ApplyTx updates utxos with the passed tx: adds all utxos in outputs and delete all utxos in inputs.

func (*UtxoSet) ApplyTxWithScriptFilter

func (u *UtxoSet) ApplyTxWithScriptFilter(tx *types.Transaction, blockHeight uint32, targetScript []byte) error

ApplyTxWithScriptFilter adds or remove an utxo if the transaction uses or generates an utxo with the specified script bytes

func (*UtxoSet) FindUtxo

func (u *UtxoSet) FindUtxo(outPoint types.OutPoint) *types.UtxoWrap

FindUtxo returns information about an outpoint.

func (*UtxoSet) GetUtxos

func (u *UtxoSet) GetUtxos() types.UtxoMap

GetUtxos returns the unspent utxos

func (*UtxoSet) LoadBlockAllUtxos added in v0.3.0

func (u *UtxoSet) LoadBlockAllUtxos(block *types.Block, db storage.Table) error

LoadBlockAllUtxos loads all UTXOs txs in the block

func (*UtxoSet) LoadBlockUtxos

func (u *UtxoSet) LoadBlockUtxos(block *types.Block, db storage.Table) error

LoadBlockUtxos loads UTXOs txs in the block spend

func (*UtxoSet) LoadTxUtxos

func (u *UtxoSet) LoadTxUtxos(tx *types.Transaction, db storage.Table) error

LoadTxUtxos loads the unspent transaction outputs related to tx

func (*UtxoSet) RevertBlock

func (u *UtxoSet) RevertBlock(block *types.Block, chain *BlockChain) error

RevertBlock undoes utxo changes made with all the transactions in the passed block It undoes the effect of ApplyBlock on utxo set

func (*UtxoSet) RevertTx

func (u *UtxoSet) RevertTx(tx *types.Transaction, chain *BlockChain) error

RevertTx updates utxos with the passed tx: delete all utxos in outputs and add all utxos in inputs. It undoes the effect of ApplyTx on utxo set

func (*UtxoSet) SpendUtxo

func (u *UtxoSet) SpendUtxo(outPoint types.OutPoint)

SpendUtxo mark a utxo as the spent state.

func (*UtxoSet) TxInputAmount added in v0.3.0

func (u *UtxoSet) TxInputAmount(tx *types.Transaction) uint64

TxInputAmount returns total amount from tx's inputs Return 0 if a tx is not fully funded, i.e., if not all of its spending utxos exist

func (*UtxoSet) WriteUtxoSetToDB

func (u *UtxoSet) WriteUtxoSetToDB(batch storage.Batch) error

WriteUtxoSetToDB store utxo set to database.

Jump to

Keyboard shortcuts

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