chain

package
v0.0.0-...-0c41aae Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2020 License: Apache-2.0 Imports: 26 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TimestampToleranceFuture   = config.ConsensusDuration / 4
	TimestampTolerancePast     = config.ConsensusDuration / 2
	TimestampToleranceVariance = config.ConsensusDuration / 6
	ProposingTimeTolerance     = config.ConsensusDuration / 2
	NumGenesisBlocks           = 4
)
View Source
const (
	MaxCollectableEntityNum = 20480
)

Variables

View Source
var (
	ErrIDRegistered           = errors.New("ID has be registered")
	ErrDuplicateGenerateIDTxn = errors.New("[VerifyTransactionWithBlock], duplicate GenerateID txns")
	ErrDuplicateIssueAssetTxn = errors.New("[VerifyTransactionWithBlock], duplicate IssueAsset txns")
)
View Source
var (
	MiningRewards = make(map[uint32]common.Fixed64)
)

Functions

func CanVerifyHeight

func CanVerifyHeight(height uint32) bool

func CheckAmount

func CheckAmount(amount int64) error

func CheckTransactionAttribute

func CheckTransactionAttribute(txn *transaction.Transaction) error

func CheckTransactionNonce

func CheckTransactionNonce(txn *transaction.Transaction) error

func CheckTransactionPayload

func CheckTransactionPayload(txn *transaction.Transaction, height uint32) error

func CheckTransactionSize

func CheckTransactionSize(txn *transaction.Transaction) error

func GetNextBlockSigner

func GetNextBlockSigner(height uint32, timestamp int64) ([]byte, []byte, pb.WinnerType, error)

GetNextBlockSigner gets the next block signer after block height at timestamp. Returns next signer's public key, chord ID, winner type, and error

func GetNextMiningSigChainTxnHash

func GetNextMiningSigChainTxnHash(height uint32) (common.Uint256, pb.WinnerType, error)

GetWinner returns the winner hash and winner type of a block height using sigchain from PoR server.

func GetRewardByHeight

func GetRewardByHeight(height uint32) common.Fixed64

func HeaderCheck

func HeaderCheck(b *block.Block) error

func NextBlockProposerCheck

func NextBlockProposerCheck(header *block.Header) error

func SignatureCheck

func SignatureCheck(header *block.Header) error

func SignerCheck

func SignerCheck(header *block.Header) error

func TimestampCheck

func TimestampCheck(header *block.Header, soft bool) error

func TransactionCheck

func TransactionCheck(ctx context.Context, block *block.Block) error

func VerifyHeader

func VerifyHeader(header *block.Header) bool

func VerifyTransaction

func VerifyTransaction(txn *transaction.Transaction, height uint32) error

VerifyTransaction verifys received single transaction

func VerifyTransactionWithLedger

func VerifyTransactionWithLedger(txn *transaction.Transaction, height uint32) error

VerifyTransactionWithLedger verifys a transaction with history transaction in ledger

Types

type BlockValidationState

type BlockValidationState struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func NewBlockValidationState

func NewBlockValidationState() *BlockValidationState

func (*BlockValidationState) CleanSubmittedTransactions

func (bvs *BlockValidationState) CleanSubmittedTransactions(txns []*transaction.Transaction) error

func (*BlockValidationState) Close

func (bvs *BlockValidationState) Close()

func (*BlockValidationState) Commit

func (bvs *BlockValidationState) Commit()

func (*BlockValidationState) GetSubscribers

func (bvs *BlockValidationState) GetSubscribers(topic string) []string

func (*BlockValidationState) GetSubscribersWithMeta

func (bvs *BlockValidationState) GetSubscribersWithMeta(topic string) map[string]string

func (*BlockValidationState) RefreshBlockValidationState

func (bvs *BlockValidationState) RefreshBlockValidationState(txns []*transaction.Transaction) map[Uint256]error

func (*BlockValidationState) Reset

func (bvs *BlockValidationState) Reset()

func (*BlockValidationState) VerifyTransactionWithBlock

func (bvs *BlockValidationState) VerifyTransactionWithBlock(txn *transaction.Transaction, height uint32) (e error)

VerifyTransactionWithBlock verifies a transaction with current transaction pool in memory

type Blockchain

type Blockchain struct {
	BlockHeight      uint32
	AssetID          Uint256
	BlockPersistTime map[Uint256]int64
	// contains filtered or unexported fields
}

func NewBlockchain

func NewBlockchain(height uint32, asset Uint256) *Blockchain

func NewBlockchainWithGenesisBlock

func NewBlockchainWithGenesisBlock(store ILedgerStore) (*Blockchain, error)

func (*Blockchain) AddBlock

func (bc *Blockchain) AddBlock(block *block.Block, fastAdd bool) error

func (*Blockchain) GetHeader

func (bc *Blockchain) GetHeader(hash Uint256) (*block.Header, error)

func (*Blockchain) SaveBlock

func (bc *Blockchain) SaveBlock(block *block.Block, fastAdd bool) error

type BuiltinMining

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

func NewBuiltinMining

func NewBuiltinMining(account *vault.Account, txnCollector *TxnCollector) *BuiltinMining

func (*BuiltinMining) BuildBlock

func (bm *BuiltinMining) BuildBlock(ctx context.Context, height uint32, chordID []byte, winnerHash common.Uint256, winnerType pb.WinnerType) (*block.Block, error)

func (*BuiltinMining) CreateCoinbaseTransaction

func (bm *BuiltinMining) CreateCoinbaseTransaction(reward common.Fixed64) *transaction.Transaction

func (*BuiltinMining) SignBlock

func (bm *BuiltinMining) SignBlock(b *block.Block, timestamp int64) error

type ILedgerStore

type ILedgerStore interface {
	SaveBlock(b *block.Block, fastAdd bool) error
	GetBlock(hash Uint256) (*block.Block, error)
	GetBlockByHeight(height uint32) (*block.Block, error)
	GetBlockHash(height uint32) (Uint256, error)
	IsDoubleSpend(tx *transaction.Transaction) bool
	AddHeader(header *block.Header) error
	GetHeader(hash Uint256) (*block.Header, error)
	GetHeaderByHeight(height uint32) (*block.Header, error)
	GetTransaction(hash Uint256) (*transaction.Transaction, error)
	GetName_legacy(registrant []byte) (string, error)
	GetRegistrant(name string) ([]byte, uint32, error)
	GetRegistrant_legacy(name string) ([]byte, error)
	IsSubscribed(topic string, bucket uint32, subscriber []byte, identifier string) (bool, error)
	GetSubscription(topic string, bucket uint32, subscriber []byte, identifier string) (string, uint32, error)
	GetSubscribers(topic string, bucket, offset, limit uint32) ([]string, error)
	GetSubscribersWithMeta(topic string, bucket, offset, limit uint32) (map[string]string, error)
	GetSubscribersCount(topic string, bucket uint32) int
	GetID(publicKey []byte) ([]byte, error)
	GetBalance(addr Uint160) Fixed64
	GetBalanceByAssetID(addr Uint160, assetID Uint256) Fixed64
	GetNonce(addr Uint160) uint64
	GetNanoPay(addr Uint160, recipient Uint160, nonce uint64) (Fixed64, uint32, error)
	GetCurrentBlockHash() Uint256
	GetCurrentHeaderHash() Uint256
	GetHeaderHeight() uint32
	GetHeight() uint32
	GetHeightByBlockHash(hash Uint256) (uint32, error)
	GetHeaderHashByHeight(height uint32) Uint256
	GetHeaderWithCache(hash Uint256) (*block.Header, error)
	InitLedgerStoreWithGenesisBlock(genesisblock *block.Block) (uint32, error)
	GetDonation() (Fixed64, error)
	IsTxHashDuplicate(txhash Uint256) bool
	IsBlockInStore(hash Uint256) bool
	Rollback(b *block.Block) error
	GenerateStateRoot(ctx context.Context, b *block.Block, genesisBlockInitialized, needBeCommitted bool) (Uint256, error)
	GetAsset(assetID Uint256) (name, symbol string, totalSupply Fixed64, precision uint32, err error)

	Close()
}

ILedgerStore provides func with store package.

type Ledger

type Ledger struct {
	Blockchain *Blockchain
	Store      ILedgerStore
}
var DefaultLedger *Ledger

func GetDefaultLedger

func GetDefaultLedger() (*Ledger, error)

get the default ledger

func (*Ledger) BlockInLedger

func (l *Ledger) BlockInLedger(hash Uint256) bool

BlockInLedger checks if the block existed in ledger

func (*Ledger) GetBlockWithHash

func (l *Ledger) GetBlockWithHash(hash Uint256) (*block.Block, error)

Get block with block hash.

func (*Ledger) GetBlockWithHeight

func (l *Ledger) GetBlockWithHeight(height uint32) (*block.Block, error)

Get Block With Height.

func (*Ledger) GetLocalBlockChainHeight

func (l *Ledger) GetLocalBlockChainHeight() uint32

Get local block chain height.

func (*Ledger) GetTransactionWithHash

func (l *Ledger) GetTransactionWithHash(hash Uint256) (*transaction.Transaction, error)

Get transaction with hash.

func (*Ledger) IsDoubleSpend

func (l *Ledger) IsDoubleSpend(Tx *transaction.Transaction) bool

double spend checking for transaction

type Mining

type Mining interface {
	BuildBlock(ctx context.Context, height uint32, chordID []byte, winnerHash common.Uint256, winnerType pb.WinnerType) (*block.Block, error)
	SignBlock(b *block.Block, timestamp int64) error
}

type TransactionArray

type TransactionArray []*transaction.Transaction

func (TransactionArray) Iterate

func (iterable TransactionArray) Iterate(handler func(item *transaction.Transaction) error) error

type TxnCollection

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

func NewTxnCollection

func NewTxnCollection(txnLists map[Uint160][]*transaction.Transaction) *TxnCollection

func (*TxnCollection) Peek

func (*TxnCollection) Pop

func (*TxnCollection) Update

func (tc *TxnCollection) Update() error

type TxnCollector

type TxnCollector struct {
	TxnNum    int
	TxnSource TxnSource
}

TxnCollector collects transactions from transaction pool

func NewTxnCollector

func NewTxnCollector(source TxnSource, num int) *TxnCollector

func (*TxnCollector) Cleanup

func (tc *TxnCollector) Cleanup(txns []*transaction.Transaction) error

func (*TxnCollector) Collect

func (tc *TxnCollector) Collect() (*TxnCollection, error)

func (*TxnCollector) GetTransaction

func (tc *TxnCollector) GetTransaction(hash Uint256) *transaction.Transaction

type TxnSource

type TxnSource interface {
	GetAllTransactionLists() map[Uint160][]*transaction.Transaction
	GetTxnByCount(num int) (map[Uint256]*transaction.Transaction, error)
	GetTransaction(hash Uint256) *transaction.Transaction
	AppendTxnPool(txn *transaction.Transaction) error
	CleanSubmittedTransactions(txns []*transaction.Transaction) error
}

Transaction pool should be a concrete entity of this interface

type VBlock

type VBlock struct {
	Block       *block.Block
	ReceiveTime int64
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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