chain

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Jul 12, 2019 License: MIT Imports: 40 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"

	// SectionTableName is the table name of db to store section data
	SectionTableName = "sec"

	// 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"

	// SecBloomBitSetPrefix is the key prefix of database key to store bloom bit set of section
	SecBloomBitSetPrefix = "/sec/bf"

	// SplitTxHashPrefix is the key prefix of database key to store split tx mapping
	SplitTxHashPrefix = "/split"

	// 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"

	// ReceiptPrefix is the key prefix of database key to store block receipts
	// of specified block hash
	// /br/{hex encoded block hash}
	// e.g.
	// key: /bk/005973c44c4879b137c3723c96d2e341eeaf83fe58845b2975556c9f3bd640bb
	// value: receipts binary
	ReceiptPrefix = "/rc"

	// 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"
)
View Source
const (
	TxGas                 uint64 = 2100
	TxGasContractCreation uint64 = 5300
	TxDataZeroGas         uint64 = 1
	TxDataNonZeroGas      uint64 = 6
)

define const

View Source
const (
	// SectionBloomLength represents the number of blooms used in a new section.
	SectionBloomLength = 65536 >> 3
)
View Source
const (
	VoutLimit = 1000
)

define const.

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)
)
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":   "b1ndoQmEd83y4Fza5PzbUQDYpT3mV772J5o",
		"peerID": "12D3KooWFQ2naj8XZUVyGhFzBTEMrMc6emiCEDKLjaJMsK7p8Cza",
	},
	{
		"addr":   "b1b8bzyci5VYUJVKRU2HRMMQiUXnoULkKAJ",
		"peerID": "12D3KooWKPRAK7vBBrVv9szEin55kBnJEEuHG4gDTQEM72ByZDpA",
	},
	{
		"addr":   "b1jh8DSdB6kB7N7RanrudV1hzzMCCcoX6L7",
		"peerID": "12D3KooWSdXLNeoRQQ2a7yiS6xLpTn3LdCr8B8fqPz94Bbi7itsi",
	},
	{
		"addr":   "b1UP5pbfJgZrF1ezoSHLdvkxvgF2BYLtGva",
		"peerID": "12D3KooWRHVAwymCVcA8jqyjpP3r3HBkCW2q5AZRTBvtaungzFSJ",
	},
	{
		"addr":   "b1ZWSdrg48g145VdcmBwMPVuDFdaxDLoktk",
		"peerID": "12D3KooWQSaxCgbWakLcU69f4gmNFMszwhyHbwx4xPAhV7erDC2P",
	},
	{
		"addr":   "b1fRtRnKF4qhQG7bSwqbgR2BMw9VfM2XpT4",
		"peerID": "12D3KooWNcJQzHaNpW5vZDQbTcoLXVCyGS755hTpendGzb5Hqtcu",
	},
}

GenesisPeriod genesis period

View Source
var MissrateKey = []byte(MissCount)

MissrateKey is the db key to store bookkeeper'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

View Source
var (
	// Transfers          map[types.AddressHash][]*TransferInfo
	// TransferToContract *types.Transaction
	Transfers = make(map[types.AddressHash][]*TransferInfo)
)

Transfers used to record the transfer information

Functions

func AddrAllTokenUtxoKey added in v0.3.0

func AddrAllTokenUtxoKey(addr string, tid types.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 AddrTokenUtxoKey added in v0.3.0

func AddrTokenUtxoKey(addr string, tid types.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 ApplyMessage added in v0.5.0

func ApplyMessage(evm *vm.EVM, msg types.Message) ([]byte, uint64, uint64, bool, *types.Transaction, error)

ApplyMessage computes the new state by applying the given message against the old state within the environment.

func ApplyTransaction added in v0.5.0

func ApplyTransaction(
	tx *types.VMTransaction, header *types.BlockHeader, bc *BlockChain,
	statedb *state.StateDB, cfg vm.Config, utxoSet *UtxoSet,
) (*types.Receipt, uint64, uint64, []*types.Transaction, error)

ApplyTransaction attempts to apply a transaction to the given state database and uses the input parameters for its environment.

func BlockHashKey

func BlockHashKey(height uint32) []byte

BlockHashKey returns the db key to store block 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 CalcTxsHash

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

CalcTxsHash calculate txsHash in block.

func CanTransfer added in v0.5.0

func CanTransfer(db vm.StateDB, addr types.AddressHash, amount *big.Int) bool

CanTransfer checks whether there are enough funds in the address' account to make a transfer. This does not take the necessary gas in to account to make the transfer valid.

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 bookkeeper 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 FetchOutPointOwner added in v0.5.0

func FetchOutPointOwner(op *types.OutPoint, utxoSet *UtxoSet) (types.Address, error)

FetchOutPointOwner fetchs owner of outpoint in utxo set

func GetHashFn added in v0.5.0

func GetHashFn(bc *BlockChain) func(n uint64) *crypto.HashType

GetHashFn returns a GetHashFunc which retrieves header hashes by number

func IntrinsicGas added in v0.5.0

func IntrinsicGas(data []byte, contractCreation bool) (uint64, error)

IntrinsicGas computes the 'intrinsic gas' for a message with the given data.

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 LoadBlockByHash added in v0.5.0

func LoadBlockByHash(hash crypto.HashType, reader storage.Reader) (*types.Block, error)

LoadBlockByHash load block by hash from db.

func MakeRollbackContractUtxos added in v0.5.0

func MakeRollbackContractUtxos(
	block *types.Block, stateDB *state.StateDB, db storage.Table,
) (types.UtxoMap, error)

MakeRollbackContractUtxos makes finally contract utxos from block

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 NewEVMContext added in v0.5.0

func NewEVMContext(msg types.Message, header *types.BlockHeader, bc *BlockChain) vm.Context

NewEVMContext creates a new context for use in the EVM.

func ReceiptKey added in v0.5.0

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

ReceiptKey returns the db key to store receipt content of the block hash

func SecBloomBitSetKey added in v0.5.0

func SecBloomBitSetKey(section uint32, bit uint) []byte

SecBloomBitSetKey is the key to store bloom bit set

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 SplitTxHashKey added in v0.3.1

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

SplitTxHashKey returns the db key to store split tx mapping

func TokenPreAllocation added in v0.3.0

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

TokenPreAllocation is for token preallocation

func Transfer added in v0.5.0

func Transfer(db vm.StateDB, sender, recipient types.AddressHash, amount *big.Int, interpreterInvoke bool)

Transfer subtracts amount from sender and adds amount to recipient using the given Db

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 BalanceChangeMap added in v0.5.0

type BalanceChangeMap map[types.AddressHash]uint64

BalanceChangeMap defines the balance changes of accounts (add or subtract)

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) BroadcastOrRelayBlock added in v0.5.0

func (chain *BlockChain) BroadcastOrRelayBlock(block *types.Block, transferMode core.TransferMode)

BroadcastOrRelayBlock broadcast or relay block to other peers.

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() 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 map[crypto.HashType]*types.Transaction, db storage.Table) error

DelSplitTxs del split txs.

func (*BlockChain) DelTxIndex

func (chain *BlockChain) DelTxIndex(
	block *types.Block, splitTxs map[crypto.HashType]*types.Transaction, db storage.Table,
) 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, db storage.Table) 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) ExtractVMTransactions added in v0.5.0

func (chain *BlockChain) ExtractVMTransactions(
	tx *types.Transaction, ownerTxs ...*types.Transaction,
) (*types.VMTransaction, error)

ExtractVMTransactions extract Transaction to VMTransaction

func (*BlockChain) FetchNBlockAfterSpecificHash

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

FetchNBlockAfterSpecificHash get N block after specific hash.

func (*BlockChain) FilterLogs added in v0.5.0

func (chain *BlockChain) FilterLogs(logs []*types.Log, topicslist [][][]byte) ([]*types.Log, error)

FilterLogs filter logs by addrs and topicslist.

func (*BlockChain) Genesis added in v0.3.0

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

Genesis return chain genesis 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) GetBlockLogs added in v0.5.0

func (chain *BlockChain) GetBlockLogs(hash *crypto.HashType) ([]*types.Log, error)

GetBlockLogs get logs by block hash.

func (*BlockChain) GetDataFromDB added in v0.3.0

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

GetDataFromDB get data from db

func (*BlockChain) GetEvmByHeight added in v0.5.0

func (chain *BlockChain) GetEvmByHeight(msg types.Message, height uint32) (*vm.EVM, func() error, error)

GetEvmByHeight get evm by block height.

func (*BlockChain) GetLogs added in v0.5.0

func (chain *BlockChain) GetLogs(from, to uint32, topicslist [][][]byte) ([]*types.Log, error)

GetLogs filter logs.

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) GetTxReceipt added in v0.5.0

func (chain *BlockChain) GetTxReceipt(txHash *crypto.HashType) (*types.Receipt, error)

GetTxReceipt returns a tx receipt by using given tx hash.

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) 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, 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) ReceiptsCache added in v0.5.0

func (chain *BlockChain) ReceiptsCache() map[uint32]types.Receipts

ReceiptsCache returns chain receipts cache.

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) SetTailState added in v0.5.0

func (chain *BlockChain) SetTailState(root, utxoRoot *crypto.HashType) error

SetTailState returns chain tail statedb

func (*BlockChain) Setup

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

Setup prepare blockchain.

func (*BlockChain) SplitBlockOutputs added in v0.5.0

func (chain *BlockChain) SplitBlockOutputs(block *types.Block) map[crypto.HashType]*types.Transaction

SplitBlockOutputs split outputs of txs in the block where applicable return all split transactions, i.e., transactions containing at least one output to a split address

func (*BlockChain) StateProcessor added in v0.5.0

func (chain *BlockChain) StateProcessor() *StateProcessor

StateProcessor returns chain stateProcessor.

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) StoreBlockWithIndex added in v0.5.0

func (chain *BlockChain) StoreBlockWithIndex(block *types.Block, db storage.Table) error

StoreBlockWithIndex 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) StoreReceipts added in v0.5.0

func (chain *BlockChain) StoreReceipts(hash *crypto.HashType, receipts types.Receipts, db storage.Table) error

StoreReceipts store receipts to db in batch mod.

func (*BlockChain) StoreSplitTxs added in v0.3.0

func (chain *BlockChain) StoreSplitTxs(
	splitTxs map[crypto.HashType]*types.Transaction, db storage.Table,
) error

StoreSplitTxs store split txs.

func (*BlockChain) StoreTailBlock

func (chain *BlockChain) StoreTailBlock(block *types.Block, db storage.Table) error

StoreTailBlock store tail block to db.

func (*BlockChain) TailBlock

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

TailBlock return chain tail block.

func (*BlockChain) TailState added in v0.5.0

func (chain *BlockChain) TailState() *state.StateDB

TailState returns chain tail statedb

func (*BlockChain) UpdateContractUtxoState added in v0.5.0

func (chain *BlockChain) UpdateContractUtxoState(statedb *state.StateDB, utxoSet *UtxoSet) error

UpdateContractUtxoState updates contract utxo in statedb

func (*BlockChain) UpdateNormalTxBalanceState added in v0.5.0

func (chain *BlockChain) UpdateNormalTxBalanceState(block *types.Block, utxoset *UtxoSet, stateDB *state.StateDB)

UpdateNormalTxBalanceState updates the balance state of normal tx

func (*BlockChain) UtxoSetCache added in v0.5.0

func (chain *BlockChain) UtxoSetCache() map[uint32]*UtxoSet

UtxoSetCache returns chain utxoSet cache.

func (*BlockChain) ValidateExecuteResult added in v0.5.0

func (chain *BlockChain) ValidateExecuteResult(
	block *types.Block, utxoTxs []*types.Transaction, usedGas, gasRemainingFee, totalTxsFee uint64,
	receipts types.Receipts,
) error

ValidateExecuteResult validates evm execute result

func (*BlockChain) WriteSplitAddrIndex added in v0.3.0

func (chain *BlockChain) WriteSplitAddrIndex(block *types.Block, db storage.Table) error

WriteSplitAddrIndex writes split addr info index

func (*BlockChain) WriteTxIndex

func (chain *BlockChain) WriteTxIndex(block *types.Block, splitTxs map[crypto.HashType]*types.Transaction, db storage.Table) 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 Consensus added in v0.5.0

type Consensus interface {
	Run() error
	Stop()
	StopMint()
	RecoverMint()

	Verify(*types.Block) error
	Process(*types.Block, interface{}) error
	Finalize(*types.Block) error

	VerifyTx(*types.Transaction) error
}

Consensus define consensus interface

type DummyDpos

type DummyDpos struct{}

DummyDpos dummy dpos

func (*DummyDpos) Finalize added in v0.5.0

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

Finalize notify consensus to change new tail.

func (*DummyDpos) Process added in v0.5.0

func (dpos *DummyDpos) Process(*types.Block, interface{}) error

Process notify consensus to process new block.

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) Verify added in v0.5.0

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

Verify verify block.

func (*DummyDpos) VerifyTx added in v0.5.0

func (dpos *DummyDpos) VerifyTx(*types.Transaction) error

VerifyTx notify consensus to verify new tx.

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 LockTime

type LockTime struct {
	Seconds     int64
	BlockHeight uint32
}

LockTime represents the relative lock-time in seconds

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 SectionManager added in v0.5.0

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

SectionManager takes a number of bloom filters and generates the rotated bloom bits to be used for batched filtering.

func NewSectionManager added in v0.5.0

func NewSectionManager(chain *BlockChain, db storage.Storage) (mgr *SectionManager, err error)

NewSectionManager creates a rotated bloom section manager that can iteratively fill a batched bloom filter's bits.

func (*SectionManager) AddBloom added in v0.5.0

func (sm *SectionManager) AddBloom(index uint, bloom bloom.Filter) error

AddBloom takes a single bloom filter and sets the corresponding bit column in memory accordingly.

func (*SectionManager) Bitset added in v0.5.0

func (sm *SectionManager) Bitset(idx uint) ([]byte, error)

Bitset returns the bit vector belonging to the given bit index after all blooms have been added.

func (*SectionManager) GetLogs added in v0.5.0

func (sm *SectionManager) GetLogs(from, to uint32, topicslist [][][]byte) ([]*types.Log, error)

GetLogs get logs matchs key words.

type StateProcessor added in v0.5.0

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

StateProcessor is a basic Processor, which takes care of transitioning state from one point to another.

func NewStateProcessor added in v0.5.0

func NewStateProcessor(bc *BlockChain) *StateProcessor

NewStateProcessor initialises a new StateProcessor.

func (*StateProcessor) Process added in v0.5.0

func (sp *StateProcessor) Process(
	block *types.Block, stateDB *state.StateDB, utxoSet *UtxoSet,
) (types.Receipts, uint64, uint64, []*types.Transaction, error)

Process processes the state changes using the statedb.

type StateTransition added in v0.5.0

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

StateTransition the State Transitioning Model

func NewStateTransition added in v0.5.0

func NewStateTransition(evm *vm.EVM, msg types.Message) *StateTransition

NewStateTransition initialises and returns a new state transition object.

func (*StateTransition) TransitionDb added in v0.5.0

func (st *StateTransition) TransitionDb() (ret []byte, usedGas, gasRemaining uint64, failed bool, gasRefundTx *types.Transaction, err error)

TransitionDb will transition the state by applying the current message and returning the result including the used gas. There are three scenarios for executing a tx: case 1: the tx is invalid before it is actually executed by evm. The tx is not on chain and returns an error. case 2: error returned after tx is executed by evm (the error is not an insufficient balance error). The tx is on chain but it's failed and the gas is used. case 3: the tx execution successful. The tx is on chain and it`s successful.

type SyncManager added in v0.5.0

type SyncManager interface {
	StartSync()
	ActiveLightSync(peer.ID) error
	Run()
}

SyncManager define sync manager interface

type TransferInfo added in v0.5.0

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

TransferInfo used to record the transfer information occurred during the execution of the contract

func NewTransferInfo added in v0.5.0

func NewTransferInfo(from, to types.AddressHash, value *big.Int) *TransferInfo

NewTransferInfo creates a new transferInfo.

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) ApplyInternalTxs added in v0.5.0

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

ApplyInternalTxs applies internal txs in block

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) ImportUtxoMap added in v0.5.0

func (u *UtxoSet) ImportUtxoMap(m types.UtxoMap, overwrite bool)

ImportUtxoMap imports utxos from a UtxoMap

func (*UtxoSet) LoadBlockAllUtxos added in v0.3.0

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

LoadBlockAllUtxos loads all UTXOs txs in the block

func (*UtxoSet) LoadBlockUtxos

func (u *UtxoSet) LoadBlockUtxos(block *types.Block, needContract bool, 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(db storage.Table) 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