chain

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2022 License: Apache-2.0 Imports: 27 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 been registered")
	ErrDuplicateGenerateIDTxn = errors.New("duplicate GenerateID txns")
	ErrDuplicateIssueAssetTxn = errors.New("duplicate IssueAsset txns")
)
View Source
var (
	MiningRewards = make(map[uint32]common.Fixed64)
	DPB           = make(map[uint32][7]float64)
)

Functions

func CanVerifyHeight

func CanVerifyHeight(height uint32) bool

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)

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

func GetPercentageByDuration

func GetPercentageByDuration(duration uint32) [7]float64

func GetRewardByHeight

func GetRewardByHeight(height uint32) (common.Fixed64, [7]common.Fixed64)

func GetSwapRate

func GetSwapRate() int64

func HeaderCheck

func HeaderCheck(header *block.Header, fastSync bool) error

func NextBlockProposerCheck

func NextBlockProposerCheck(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, fastSync bool) error

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[common.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          common.Uint256
	BlockPersistTime map[common.Uint256]int64
	// contains filtered or unexported fields
}

func NewBlockchain

func NewBlockchain(height uint32, asset common.Uint256) *Blockchain

func NewBlockchainWithGenesisBlock

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

func (*Blockchain) AddBlock

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

func (*Blockchain) AddHeader

func (bc *Blockchain) AddHeader(header *block.Header, fastSync bool) error

func (*Blockchain) GetHeader

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

func (*Blockchain) SaveBlock

func (bc *Blockchain) SaveBlock(block *block.Block, pruning, fastSync 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(TotalReward common.Fixed64, distributedRewardsPerRole [7]common.Fixed64, height uint32) *transaction.Transaction

func (*BuiltinMining) SignBlock

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

type ILedgerStore

type ILedgerStore interface {
	SaveBlock(b *block.Block, pruning, fastSync bool) error
	GetBlock(hash common.Uint256) (*block.Block, error)
	GetBlockByHeight(height uint32) (*block.Block, error)
	GetBlockHash(height uint32) (common.Uint256, error)
	IsDoubleSpend(tx *transaction.Transaction) bool
	AddHeader(header *block.Header) error
	GetHeader(hash common.Uint256) (*block.Header, error)
	GetHeaderByHeight(height uint32) (*block.Header, error)
	GetTransaction(hash common.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, subscriberHashPrefix []byte, ctx context.Context) ([]string, error)
	GetSubscribersWithMeta(topic string, bucket, offset, limit uint32, subscriberHashPrefix []byte, ctx context.Context) (map[string]string, error)
	GetSubscribersCount(topic string, bucket uint32, subscriberHashPrefix []byte, ctx context.Context) (int, error)
	GetID(publicKey []byte, height uint32) ([]byte, error)
	GetIDVersion(publicKey []byte) ([]byte, byte, error)
	GetBalance(addr common.Uint160) common.Fixed64
	GetRDCBalance(addr common.Uint160) common.Fixed64
	GetBalanceByAssetID(addr common.Uint160, assetID common.Uint256) common.Fixed64
	GetNonce(addr common.Uint160) uint64
	GetNanoPay(addr common.Uint160, recipient common.Uint160, nonce uint64) (common.Fixed64, uint32, error)
	GetCurrentBlockHash() common.Uint256
	GetCurrentHeaderHash() common.Uint256
	GetHeaderHeight() uint32
	GetHeight() uint32
	GetHeightByBlockHash(hash common.Uint256) (uint32, error)
	GetHeaderHashByHeight(height uint32) common.Uint256
	GetHeaderWithCache(hash common.Uint256) (*block.Header, error)
	GetSigChainWithCache(hash common.Uint256) (*pb.SigChain, error)
	InitLedgerStoreWithGenesisBlock(genesisblock *block.Block) (uint32, error)
	GetDonation() (common.Fixed64, error)
	IsTxHashDuplicate(txhash common.Uint256) bool
	IsBlockInStore(hash common.Uint256) bool
	Rollback(b *block.Block) error
	GenerateStateRoot(ctx context.Context, b *block.Block, genesisBlockInitialized, needBeCommitted bool) (common.Uint256, error)
	GetAsset(assetID common.Uint256) (name, symbol string, totalSupply common.Fixed64, precision uint32, err error)
	GetDatabase() db.IStore
	ShouldFastSync(syncStopHeight uint32) bool
	GetSyncRootHeight() (uint32, error)
	GetFastSyncStateRoot() (common.Uint256, error)
	PrepareFastSync(fastSyncHeight uint32, fastSyncRootHash common.Uint256) error
	FastSyncDone(syncRootHash common.Uint256, fastSyncHeight uint32) 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 common.Uint256) bool

BlockInLedger checks if the block existed in ledger

func (*Ledger) GetBlockWithHash

func (l *Ledger) GetBlockWithHash(hash common.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 common.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[common.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 common.Uint256) *transaction.Transaction

type TxnSource

type TxnSource interface {
	GetAllTransactionLists() map[common.Uint160][]*transaction.Transaction
	GetTxnByCount(num int) (map[common.Uint256]*transaction.Transaction, error)
	GetTransaction(hash common.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