blockchain

package
v0.8.3 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2022 License: MIT Imports: 46 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// MaxStringLength is the maximum length of a string field.
	MaxStringLength = 100

	// Category Data length limit not exceeding 4096 characters
	MaxCategoryDataStringLength = 4096

	// Category Data length limit not exceeding 4096 characters
	MaxDraftDataStringLength = 1000000

	// MaxBudgetsCount indicates max budgets count of one proposal.
	MaxBudgetsCount = 128

	// ELIPBudgetsCount indicates budgets count of ELIP.
	ELIPBudgetsCount = 2

	// CRCProposalBudgetsPercentage indicates the percentage of the CRC member
	// address balance available for a single proposal budget.
	CRCProposalBudgetsPercentage = 10
)
View Source
const (
	// MaxBlockWeight defines the maximum block weight, where "block
	// weight" is interpreted as defined in BIP0141. A block's weight is
	// calculated as the sum of the of bytes in the existing transactions
	// and header, plus the weight of each byte within a transaction. The
	// weight of a "base" byte is 4, while the weight of a witness byte is
	// 1. As a result, for a block to be valid, the BlockWeight MUST be
	// less than, or equal to MaxBlockWeight.
	MaxBlockWeight = 4000000

	// MaxBlockBaseSize is the maximum number of bytes within a block
	// which can be allocated to non-witness data.
	MaxBlockBaseSize = 1000000

	// MaxBlockSigOpsCost is the maximum number of signature operations
	// allowed for a block. It is calculated via a weighted algorithm which
	// weights segregated witness sig ops lower than regular sig ops.
	MaxBlockSigOpsCost = 80000

	// WitnessScaleFactor determines the level of "discount" witness data
	// receives compared to "base" data. A scale factor of 4, denotes that
	// witness data is 1/4 as cheap as regular non-witness data.
	WitnessScaleFactor = 4

	// MinTxOutputWeight is the minimum possible weight for a transaction
	// output.
	MinTxOutputWeight = WitnessScaleFactor * wire.MinTxOutPayload

	// MaxOutputsPerBlock is the maximum number of transaction outputs there
	// can be in a block of max weight size.
	MaxOutputsPerBlock = MaxBlockWeight / MinTxOutputWeight
)
View Source
const BITSPERKEY = 10

used to compute the size of bloom filter bits array . too small will lead to high false positive rate.

View Source
const (
	BlocksCacheSize = 2
)
View Source
const (
	// HashSize of array used to store hashes.  See Hash.
	HashSize = 32
)
View Source
const (
	MaxTimeOffsetSeconds = 2 * 60 * 60
)

Variables

View Source
var (
	FoundationAddress Uint168
	DefaultLedger     *Ledger
)
View Source
var SMALL_CROSS_TRANSFER_RPEFIX = []byte("SMALL_CROSS_TRANSFER")

Functions

func AddChildrenWork

func AddChildrenWork(node *BlockNode, work *big.Int)

func BigToCompact

func BigToCompact(n *big.Int) uint32

func CalcPastMedianTime

func CalcPastMedianTime(node *BlockNode) time.Time

func CalcWork

func CalcWork(bits uint32) *big.Int

(1 << 256) / (difficultyNum + 1)

func CalculateTxsFee added in v0.3.3

func CalculateTxsFee(block *Block)

func CheckDPOSIllegalBlocks added in v0.3.0

func CheckDPOSIllegalBlocks(d *payload.DPOSIllegalBlocks) error

func CheckDPOSIllegalProposals added in v0.3.0

func CheckDPOSIllegalProposals(d *payload.DPOSIllegalProposals) error

func CheckDPOSIllegalVotes added in v0.3.0

func CheckDPOSIllegalVotes(d *payload.DPOSIllegalVotes) error

func CheckInactiveArbitrators added in v0.3.0

func CheckInactiveArbitrators(txn *Transaction) error

func CheckProofOfWork

func CheckProofOfWork(header *Header, powLimit *big.Int) error

func CheckRevertToDPOSTransaction added in v0.7.0

func CheckRevertToDPOSTransaction(txn *Transaction) error

func CheckSideChainPowConsensus added in v0.1.1

func CheckSideChainPowConsensus(txn *Transaction, arbitrator []byte) error

func CheckSidechainIllegalEvidence added in v0.3.0

func CheckSidechainIllegalEvidence(p *payload.SidechainIllegalData) error

func CompactToBig

func CompactToBig(compact uint32) *big.Int

func ConfirmContextCheck added in v0.3.0

func ConfirmContextCheck(confirm *payload.Confirm) error

func ConfirmSanityCheck added in v0.3.0

func ConfirmSanityCheck(confirm *payload.Confirm) error

func DBRemoveBlockIndex added in v0.5.0

func DBRemoveBlockIndex(dbTx database.Tx, hash *common.Uint256, height uint32) error

DBRemoveBlockIndex uses an existing database transaction remove block index entries from the hash to height and height to hash mappings for the provided values.

func DBRemoveBlockNode added in v0.5.0

func DBRemoveBlockNode(dbTx database.Tx, header *types.Header) error

DBRemoveBlockNode stores the block header to the block index bucket. This overwrites the current entry if there exists one.

func DBRemoveProposalDraftData added in v0.7.0

func DBRemoveProposalDraftData(dbTx database.Tx, hash *common.Uint256) error

DBRemoveBlockIndex uses an existing database transaction remove block index entries from the hash to height and height to hash mappings for the provided values.

func DBStoreBlockNode added in v0.5.0

func DBStoreBlockNode(dbTx database.Tx, header *types.Header,
	status blockStatus) error

DBStoreBlockNode stores the block header to the block index bucket. This overwrites the current entry if there exists one.

func DeserializeBlockRow added in v0.5.0

func DeserializeBlockRow(blockRow []byte) (*types.Header, blockStatus, error)

DeserializeBlockRow parses a value in the block index bucket into a block header and block Status bitfield.

func GetBlockWeight added in v0.5.0

func GetBlockWeight(blk *types.Block) int64

GetBlockWeight computes the value of the weight metric for a given block. Currently the weight metric is simply the sum of the block's serialized size without any witness data scaled proportionally by the WitnessScaleFactor, and the block's serialized size including any witness data.

func GetTransactionWeight added in v0.5.0

func GetTransactionWeight(tx *types.Transaction) int64

GetTransactionWeight computes the value of the weight metric for a given transaction. Currently the weight metric is simply the sum of the transactions's serialized size without any witness data scaled proportionally by the WitnessScaleFactor, and the transaction's serialized size including any witness data.

func GetTxFee

func GetTxFee(tx *Transaction, assetId Uint256, references map[*Input]Output) Fixed64

func GetTxFeeMap

func GetTxFeeMap(tx *Transaction, references map[*Input]Output) (map[Uint256]Fixed64, error)

func GetTxProgramHashes

func GetTxProgramHashes(tx *Transaction, references map[*Input]Output) ([]common.Uint168, error)

func HashToBig

func HashToBig(hash *Uint256) *big.Int

func IllegalConfirmContextCheck added in v0.7.0

func IllegalConfirmContextCheck(confirm *payload.Confirm) error

func IllegalProposalContextCheck added in v0.7.0

func IllegalProposalContextCheck(proposal *payload.DPOSProposal) error

func IllegalVoteContextCheck added in v0.7.0

func IllegalVoteContextCheck(vote *payload.DPOSProposalVote) error

func IsFinalizedTransaction

func IsFinalizedTransaction(msgTx *Transaction, blockHeight uint32) bool

func LoadBlockDB added in v0.5.0

func LoadBlockDB(dataPath string, dbName string) (database.DB, error)

loadBlockDB loads (or creates when needed) the block database taking into account the selected database backend and returns a handle to it. It also contains additional logic such warning the user if there are multiple databases which consume space on the file system and ensuring the regression test database is clean when in regression test mode.

func PreProcessSpecialTx added in v0.3.2

func PreProcessSpecialTx(block *Block) error

func ProcessProposalDraftData added in v0.7.0

func ProcessProposalDraftData(dbTx database.Tx, Transactions []*Transaction) (err error)

func ProposalCheck added in v0.3.2

func ProposalCheck(proposal *payload.DPOSProposal) error

func ProposalCheckByHeight added in v0.3.2

func ProposalCheckByHeight(proposal *payload.DPOSProposal,
	height uint32) error

func ProposalContextCheck added in v0.3.0

func ProposalContextCheck(proposal *payload.DPOSProposal) error

func ProposalContextCheckByHeight added in v0.3.2

func ProposalContextCheckByHeight(proposal *payload.DPOSProposal,
	height uint32) error

func ProposalSanityCheck added in v0.3.0

func ProposalSanityCheck(proposal *payload.DPOSProposal) error

func RecordCRCProposalAmount added in v0.7.0

func RecordCRCProposalAmount(usedAmount *Fixed64, txn *Transaction)

func RollbackProcessProposalDraftData added in v0.7.0

func RollbackProcessProposalDraftData(dbTx database.Tx, Transactions []*Transaction) (err error)

func RunPrograms

func RunPrograms(data []byte, programHashes []common.Uint168, programs []*Program) error

func SortPrograms added in v0.1.1

func SortPrograms(programs []*Program)

func VoteCheck added in v0.3.2

func VoteCheck(vote *payload.DPOSProposalVote) error

func VoteCheckByHeight added in v0.3.2

func VoteCheckByHeight(vote *payload.DPOSProposalVote, height uint32) error

func VoteContextCheck added in v0.3.0

func VoteContextCheck(vote *payload.DPOSProposalVote) error

func VoteContextCheckByHeight added in v0.3.2

func VoteContextCheckByHeight(vote *payload.DPOSProposalVote,
	height uint32) error

func VoteSanityCheck added in v0.3.0

func VoteSanityCheck(vote *payload.DPOSProposalVote) error

Types

type BestState added in v0.5.0

type BestState struct {
	Hash        common.Uint256 // The hash of the block.
	Height      uint32         // The height of the block.
	Bits        uint32         // The difficulty bits of the block.
	BlockSize   uint64         // The size of the block.
	BlockWeight uint64         // The weight of the block.
	NumTxns     uint64         // The number of txns in the block.
	MedianTime  time.Time      // Median time as per CalcPastMedianTime.
}

BestState houses information about the current best block and other info related to the state of the main chain as it exists from the point of view of the current best block.

The BestSnapshot method can be used to obtain access to this information in a concurrent safe manner and the data will not be changed out from under the caller when chain state changes occur as the function name implies. However, the returned snapshot must be treated as immutable since it is shared by all callers.

type BlockChain added in v0.3.0

type BlockChain struct {
	UTXOCache   *UTXOCache
	GenesisHash Uint256

	BestChain *BlockNode
	Root      *BlockNode

	IndexLock sync.RWMutex
	Nodes     []*BlockNode
	DepNodes  map[Uint256][]*BlockNode

	TimeSource     MedianTimeSource
	MedianTimePast time.Time
	// contains filtered or unexported fields
}

func New added in v0.3.0

func New(db IChainStore, chainParams *config.Params, state *state.State,
	committee *crstate.Committee) (*BlockChain, error)

func (*BlockChain) AddOrphanBlock added in v0.3.0

func (b *BlockChain) AddOrphanBlock(block *Block)

func (*BlockChain) AddOrphanConfirm added in v0.3.0

func (b *BlockChain) AddOrphanConfirm(confirm *payload.Confirm)

func (*BlockChain) BlockExists added in v0.3.0

func (b *BlockChain) BlockExists(hash *Uint256) bool

func (*BlockChain) BlockLocatorFromHash added in v0.3.0

func (b *BlockChain) BlockLocatorFromHash(inhash *Uint256) []*Uint256

func (*BlockChain) CalcCurrentDifficulty added in v0.3.0

func (b *BlockChain) CalcCurrentDifficulty(currentBits uint32) string

func (*BlockChain) CalcNextRequiredDifficulty added in v0.3.0

func (b *BlockChain) CalcNextRequiredDifficulty(prevNode *BlockNode, newBlockTime time.Time) (uint32, error)

func (*BlockChain) CheckBlockContext added in v0.3.4

func (b *BlockChain) CheckBlockContext(block *Block, prevNode *BlockNode) error

func (*BlockChain) CheckBlockSanity added in v0.3.0

func (b *BlockChain) CheckBlockSanity(block *Block) error

func (*BlockChain) CheckTransactionContext added in v0.3.0

func (b *BlockChain) CheckTransactionContext(blockHeight uint32,
	txn *Transaction, proposalsUsedAmount common.Fixed64, timeStamp uint32) (map[*Input]Output, elaerr.ELAError)

CheckTransactionContext verifies a transaction with history transaction in ledger

func (*BlockChain) CheckTransactionSanity added in v0.3.0

func (b *BlockChain) CheckTransactionSanity(blockHeight uint32,
	txn *Transaction) elaerr.ELAError

CheckTransactionSanity verifies received single transaction

func (*BlockChain) ContainsTransaction added in v0.3.0

func (b *BlockChain) ContainsTransaction(hash Uint256) bool

func (*BlockChain) ConvertToArbitersStr added in v0.7.0

func (b *BlockChain) ConvertToArbitersStr(arbiters [][]byte) []string

func (*BlockChain) CreateCRAssetsRectifyTransaction added in v0.7.0

func (b *BlockChain) CreateCRAssetsRectifyTransaction() (*Transaction, error)

func (*BlockChain) CreateCRCAppropriationTransaction added in v0.5.0

func (b *BlockChain) CreateCRCAppropriationTransaction() (*Transaction, Fixed64, error)

func (*BlockChain) CreateCRRealWithdrawTransaction added in v0.7.0

func (b *BlockChain) CreateCRRealWithdrawTransaction(
	withdrawTransactionHashes []Uint256, outputs []*OutputInfo) (*Transaction, error)

func (*BlockChain) GetBestBlockHash added in v0.7.0

func (b *BlockChain) GetBestBlockHash() *Uint256

func (*BlockChain) GetBestChain added in v0.7.0

func (b *BlockChain) GetBestChain() *BlockNode

func (*BlockChain) GetBlockByHash added in v0.3.0

func (b *BlockChain) GetBlockByHash(hash Uint256) (*Block, error)

Get block with block hash.

func (*BlockChain) GetBlockByHeight added in v0.5.0

func (b *BlockChain) GetBlockByHeight(height uint32) (*Block, error)

Get block by height

func (*BlockChain) GetBlockHash added in v0.5.0

func (b *BlockChain) GetBlockHash(height uint32) (Uint256, error)

Get block with block hash.

func (*BlockChain) GetBlockNode added in v0.5.0

func (b *BlockChain) GetBlockNode(height uint32) *BlockNode

Get block with block hash.

func (*BlockChain) GetCRCommittee added in v0.5.0

func (b *BlockChain) GetCRCommittee() *crstate.Committee

func (*BlockChain) GetCurrentBlockHash added in v0.5.0

func (b *BlockChain) GetCurrentBlockHash() Uint256

func (*BlockChain) GetDB added in v0.5.0

func (b *BlockChain) GetDB() IChainStore

func (*BlockChain) GetDposBlockByHash added in v0.3.0

func (b *BlockChain) GetDposBlockByHash(hash Uint256) (*DposBlock, error)

Get DPOS block with block hash.

func (*BlockChain) GetHeader added in v0.3.0

func (b *BlockChain) GetHeader(hash Uint256) (*Header, error)

func (*BlockChain) GetHeight added in v0.3.0

func (b *BlockChain) GetHeight() uint32

func (*BlockChain) GetNetworkHashPS added in v0.3.4

func (b *BlockChain) GetNetworkHashPS() *big.Int

GetNetworkHashPS return average network hashes per second based on the last 'lookup' blocks.

func (*BlockChain) GetOrphan added in v0.3.2

func (b *BlockChain) GetOrphan(hash *Uint256) *OrphanBlock

func (*BlockChain) GetOrphanBlockLocator added in v0.8.0

func (b *BlockChain) GetOrphanBlockLocator(inv []*msg.InvVect) []*Uint256

length of inv need to be >= 2

func (*BlockChain) GetOrphanConfirm added in v0.3.0

func (b *BlockChain) GetOrphanConfirm(hash *Uint256) (*payload.Confirm, bool)

func (*BlockChain) GetOrphanRoot added in v0.3.0

func (b *BlockChain) GetOrphanRoot(hash *Uint256) *Uint256

func (*BlockChain) GetState added in v0.3.0

func (b *BlockChain) GetState() *state.State

GetState returns the DPOS state instance that stores producers and votes information.

func (*BlockChain) HaveBlock added in v0.3.0

func (b *BlockChain) HaveBlock(hash *Uint256) (bool, error)

func (*BlockChain) Init added in v0.5.0

func (b *BlockChain) Init(interrupt <-chan struct{}) error

func (*BlockChain) InitCheckpoint added in v0.5.0

func (b *BlockChain) InitCheckpoint(interrupt <-chan struct{},
	barStart func(total uint32), increase func()) (err error)

InitCheckpoint go through all blocks since the genesis block to initialize all checkpoint.

func (*BlockChain) IsKnownOrphan added in v0.3.0

func (b *BlockChain) IsKnownOrphan(hash *Uint256) bool

func (*BlockChain) IsNextArbitratorsSame added in v0.7.0

func (b *BlockChain) IsNextArbitratorsSame(nextTurnDPOSInfo *payload.NextTurnDPOSInfo,
	nextArbitrators []*state.ArbiterInfo) bool

func (*BlockChain) LatestBlockLocator added in v0.3.0

func (b *BlockChain) LatestBlockLocator() ([]*Uint256, error)

func (*BlockChain) LoadBlockNode added in v0.3.0

func (b *BlockChain) LoadBlockNode(blockHeader *Header, hash *Uint256) (*BlockNode, error)

func (*BlockChain) LocateBlocks added in v0.3.0

func (b *BlockChain) LocateBlocks(locator []*Uint256, hashStop *Uint256, maxHashes uint32) []*Uint256

LocateBlocks returns the hashes of the blocks after the first known block in the locator until the provided stop hash is reached, or up to the provided max number of block hashes.

In addition, there are two special cases:

  • When no locators are provided, the stop hash is treated as a request for that block, so it will either return the stop hash itself if it is known, or nil if it is unknown
  • When locators are provided, but none of them are known, hashes starting after the genesis block will be returned

This function is safe for concurrent access.

func (*BlockChain) LookupNodeInIndex added in v0.3.0

func (b *BlockChain) LookupNodeInIndex(hash *Uint256) (*BlockNode, bool)

func (*BlockChain) MainChainHasBlock added in v0.5.0

func (b *BlockChain) MainChainHasBlock(height uint32, hash *Uint256) bool

MainChainHasBlock returns whether or not the block with the given hash is in the main chain.

func (*BlockChain) MedianAdjustedTime added in v0.3.0

func (b *BlockChain) MedianAdjustedTime() time.Time

func (*BlockChain) MigrateOldDB added in v0.5.0

func (b *BlockChain) MigrateOldDB(
	interrupt <-chan struct{},
	barStart func(total uint32),
	increase func(),
	dataDir string,
	params *config.Params) (err error)

func (*BlockChain) ProcessBlock added in v0.3.0

func (b *BlockChain) ProcessBlock(block *Block, confirm *payload.Confirm) (bool, bool, error)

func (*BlockChain) ProcessIllegalBlock added in v0.3.0

func (b *BlockChain) ProcessIllegalBlock(payload *payload.DPOSIllegalBlocks)

func (*BlockChain) ProcessInactiveArbiter added in v0.3.2

func (b *BlockChain) ProcessInactiveArbiter(payload *payload.InactiveArbitrators)

func (*BlockChain) ProcessOrphans added in v0.3.0

func (b *BlockChain) ProcessOrphans(hash *Uint256) error

func (*BlockChain) RemoveOrphanBlock added in v0.3.0

func (b *BlockChain) RemoveOrphanBlock(orphan *OrphanBlock)

func (*BlockChain) ReorganizeChain added in v0.3.0

func (b *BlockChain) ReorganizeChain(block *Block) error

ReorganizeChain reorganize chain by specify a block, this method shall not be called normally because it can cause reorganizing without node work sum checking

func (*BlockChain) SetTip added in v0.5.0

func (b *BlockChain) SetTip(node *BlockNode)

SetTip sets the block chain to use the provided block node as the current tip and ensures the view is consistent by populating it with the nodes obtained by walking backwards all the way to genesis block as necessary. Further calls will only perform the minimum work needed, so switching between chain tips is efficient.

This function is safe for concurrent access.

type BlockNode

type BlockNode struct {
	Hash        *common.Uint256
	ParentHash  *common.Uint256
	Height      uint32
	Version     uint32
	Bits        uint32
	Timestamp   uint32
	WorkSum     *big.Int
	InMainChain bool
	Parent      *BlockNode
	Children    []*BlockNode

	// Status is a bitfield representing the validation state of the block. The
	// Status field, unlike the other fields, may be written to and so should
	// only be accessed using the concurrent-safe NodeStatus method on
	// blockIndex once the node has been added to the global index.
	Status blockStatus
}

BlockNode represents a block within the block chain and is primarily used to aid in selecting the best chain to be the main chain. The main chain is stored into the block database.

func NewBlockNode

func NewBlockNode(header *types.Header, hash *common.Uint256) *BlockNode

NewBlockNode returns a new block node for the given block header and block hash, calculating the height and workSum from the respective fields.

func RemoveChildNode

func RemoveChildNode(children []*BlockNode, node *BlockNode) []*BlockNode

type ChainStore

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

func (*ChainStore) CleanSmallCrossTransferTx added in v0.8.0

func (c *ChainStore) CleanSmallCrossTransferTx(txHash Uint256) error

func (*ChainStore) Close

func (c *ChainStore) Close()

func (*ChainStore) CloseLeveldb added in v0.5.0

func (c *ChainStore) CloseLeveldb()

func (*ChainStore) GetConfirm added in v0.2.2

func (c *ChainStore) GetConfirm(hash Uint256) (*payload.Confirm, error)

func (*ChainStore) GetFFLDB added in v0.5.0

func (c *ChainStore) GetFFLDB() IFFLDBChainStore

func (*ChainStore) GetHeight

func (c *ChainStore) GetHeight() uint32

func (*ChainStore) GetProposalDraftDataByDraftHash added in v0.7.0

func (c *ChainStore) GetProposalDraftDataByDraftHash(draftHash *Uint256) ([]byte, error)

func (*ChainStore) GetSmallCrossTransferTx added in v0.8.0

func (c *ChainStore) GetSmallCrossTransferTx() ([]string, error)

func (*ChainStore) GetSmallCrossTransferTxs added in v0.8.0

func (c *ChainStore) GetSmallCrossTransferTxs() ([]*Transaction, error)

func (*ChainStore) GetTransaction

func (c *ChainStore) GetTransaction(txID Uint256) (*Transaction, uint32, error)

func (*ChainStore) GetTxReference

func (c *ChainStore) GetTxReference(tx *Transaction) (map[*Input]*Output, error)

func (*ChainStore) IsDoubleSpend

func (c *ChainStore) IsDoubleSpend(txn *Transaction) bool

func (*ChainStore) IsSidechainReturnDepositTxHashDuplicate added in v0.8.0

func (c *ChainStore) IsSidechainReturnDepositTxHashDuplicate(sidechainReturnDepositTxHash Uint256) bool

func (*ChainStore) IsSidechainTxHashDuplicate added in v0.1.1

func (c *ChainStore) IsSidechainTxHashDuplicate(sidechainTxHash Uint256) bool

func (*ChainStore) IsTxHashDuplicate

func (c *ChainStore) IsTxHashDuplicate(txID Uint256) bool

func (*ChainStore) RollbackBlock

func (c *ChainStore) RollbackBlock(b *Block, node *BlockNode,
	confirm *payload.Confirm, medianTimePast time.Time) error

func (*ChainStore) SaveBlock

func (c *ChainStore) SaveBlock(b *Block, node *BlockNode,
	confirm *payload.Confirm, medianTimePast time.Time) error

func (*ChainStore) SaveSmallCrossTransferTx added in v0.8.0

func (c *ChainStore) SaveSmallCrossTransferTx(tx *Transaction) error

func (*ChainStore) SetHeight added in v0.5.0

func (c *ChainStore) SetHeight(height uint32)

type ChainStoreFFLDB added in v0.5.0

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

func (*ChainStoreFFLDB) Begin added in v0.5.0

func (c *ChainStoreFFLDB) Begin(writable bool) (database.Tx, error)

func (*ChainStoreFFLDB) BlockExists added in v0.5.0

func (c *ChainStoreFFLDB) BlockExists(hash *Uint256) (bool, uint32, error)

blockExists determines whether a block with the given hash exists either in the main chain or any side chains.

This function is safe for concurrent access.

func (*ChainStoreFFLDB) Close added in v0.5.0

func (c *ChainStoreFFLDB) Close() error

func (*ChainStoreFFLDB) GetBlock added in v0.5.0

func (c *ChainStoreFFLDB) GetBlock(hash Uint256) (*DposBlock, error)

func (*ChainStoreFFLDB) GetHeader added in v0.5.0

func (c *ChainStoreFFLDB) GetHeader(hash Uint256) (*Header, error)

func (*ChainStoreFFLDB) GetOldBlock added in v0.5.0

func (c *ChainStoreFFLDB) GetOldBlock(hash Uint256) (*Block, error)

func (*ChainStoreFFLDB) GetProposalDraftDataByDraftHash added in v0.7.0

func (c *ChainStoreFFLDB) GetProposalDraftDataByDraftHash(hash *Uint256) ([]byte, error)

GetProposalDraftDataByHash try get proposal draft data by draft hash

func (*ChainStoreFFLDB) GetTransaction added in v0.5.0

func (c *ChainStoreFFLDB) GetTransaction(txID Uint256) (*Transaction, uint32, error)

func (*ChainStoreFFLDB) GetUTXO added in v0.5.0

func (c *ChainStoreFFLDB) GetUTXO(programHash *Uint168) ([]*UTXO, error)

func (*ChainStoreFFLDB) GetUnspent added in v0.5.0

func (c *ChainStoreFFLDB) GetUnspent(txID Uint256) ([]uint16, error)

func (*ChainStoreFFLDB) InitIndex added in v0.5.0

func (c *ChainStoreFFLDB) InitIndex(chain indexers.IChain, interrupt <-chan struct{}) error

func (*ChainStoreFFLDB) IsBlockInStore added in v0.5.0

func (c *ChainStoreFFLDB) IsBlockInStore(hash *Uint256) bool

func (*ChainStoreFFLDB) IsSideChainReturnDepositExist added in v0.8.0

func (c *ChainStoreFFLDB) IsSideChainReturnDepositExist(txHash *Uint256) bool

func (*ChainStoreFFLDB) IsTx3Exist added in v0.5.0

func (c *ChainStoreFFLDB) IsTx3Exist(txHash *Uint256) bool

func (*ChainStoreFFLDB) RollbackBlock added in v0.5.0

func (c *ChainStoreFFLDB) RollbackBlock(b *Block, node *BlockNode,
	confirm *payload.Confirm, medianTimePast time.Time) error

func (*ChainStoreFFLDB) SaveBlock added in v0.5.0

func (c *ChainStoreFFLDB) SaveBlock(b *Block, node *BlockNode,
	confirm *payload.Confirm, medianTimePast time.Time) error

func (*ChainStoreFFLDB) Type added in v0.5.0

func (c *ChainStoreFFLDB) Type() string

func (*ChainStoreFFLDB) Update added in v0.5.0

func (c *ChainStoreFFLDB) Update(fn func(tx database.Tx) error) error

func (*ChainStoreFFLDB) View added in v0.5.0

func (c *ChainStoreFFLDB) View(fn func(tx database.Tx) error) error

type DataEntryPrefix

type DataEntryPrefix byte

DataEntryPrefix

const (
	// DATA
	DATABlockHash   DataEntryPrefix = 0x00
	DATAHeader      DataEntryPrefix = 0x01
	DATATransaction DataEntryPrefix = 0x02
	DATAConfirm     DataEntryPrefix = 0x03

	//SYSTEM
	SYSCurrentBlock      DataEntryPrefix = 0x40
	SYSCurrentBookKeeper DataEntryPrefix = 0x42

	// INDEX
	IXHeaderHashList DataEntryPrefix = 0x80
	IXUnspent        DataEntryPrefix = 0x90
	IXUnspentUTXO    DataEntryPrefix = 0x91
	IXSideChainTx    DataEntryPrefix = 0x92

	// ASSET
	STInfo DataEntryPrefix = 0xc0

	// DPOS
	DPOSIllegalProducer DataEntryPrefix = 0xd1

	//CONFIG
	CFGVersion DataEntryPrefix = 0xf0
)

type IChainStore

type IChainStore interface {
	GetFFLDB() IFFLDBChainStore

	SaveBlock(b *Block, node *BlockNode, confirm *payload.Confirm,
		medianTimePast time.Time) error
	IsDoubleSpend(tx *Transaction) bool

	GetConfirm(hash Uint256) (*payload.Confirm, error)

	RollbackBlock(b *Block, node *BlockNode,
		confirm *payload.Confirm, medianTimePast time.Time) error

	GetTransaction(txID Uint256) (*Transaction, uint32, error)
	GetTxReference(tx *Transaction) (map[*Input]*Output, error)

	SetHeight(height uint32)
	GetHeight() uint32

	IsTxHashDuplicate(txhash Uint256) bool
	IsSidechainTxHashDuplicate(sidechainTxHash Uint256) bool
	IsSidechainReturnDepositTxHashDuplicate(sidechainReturnDepositTxHash Uint256) bool

	GetProposalDraftDataByDraftHash(draftHash *Uint256) ([]byte, error)

	SaveSmallCrossTransferTx(tx *Transaction) error
	GetSmallCrossTransferTxs() ([]*Transaction, error)
	GetSmallCrossTransferTx() ([]string, error)
	CleanSmallCrossTransferTx(txHash Uint256) error

	Close()
	CloseLeveldb()
}

IChainStore provides func with store package.

func NewChainStore

func NewChainStore(dataDir string, params *config.Params) (IChainStore, error)

type IFFLDBChainStore added in v0.5.0

type IFFLDBChainStore interface {
	database.DB

	// SaveBlock will write block into file db.
	SaveBlock(b *Block, node *BlockNode, confirm *payload.Confirm,
		medianTimePast time.Time) error

	// RollbackBlock only remove block state and block index.
	RollbackBlock(b *Block, node *BlockNode,
		confirm *payload.Confirm, medianTimePast time.Time) error

	// Get block from file db.
	GetBlock(hash Uint256) (*DposBlock, error)

	// Get block from file db.
	GetOldBlock(hash Uint256) (*Block, error)

	// Get block header from file db.
	GetHeader(hash Uint256) (*Header, error)

	// If already exist in main chain(exist in file db and exist block index),
	// will return true.
	BlockExists(hash *Uint256) (bool, uint32, error)

	// If already exist in file db (rollback will not remove from file db), will
	// return true.
	IsBlockInStore(hash *Uint256) bool

	// Get a transaction by transaction hash.
	GetTransaction(txID Uint256) (*Transaction, uint32, error)

	// InitIndex use to initialize the index manager.
	InitIndex(chain indexers.IChain, interrupt <-chan struct{}) error

	// Get unspent by transaction hash.
	GetUnspent(txID Uint256) ([]uint16, error)

	// Get utxo by program hash.
	GetUTXO(programHash *Uint168) ([]*UTXO, error)

	// IsTx3Exist use to find if tx3 exist in db.
	IsTx3Exist(txHash *Uint256) bool

	// IsSideChainReturnDepositExist use to find if return deposit exist in db.
	IsSideChainReturnDepositExist(txHash *Uint256) bool

	// Get proposal draft data by draft hash.
	GetProposalDraftDataByDraftHash(draftHash *Uint256) ([]byte, error)
}

IChainStore provides func with store package.

func NewChainStoreFFLDB added in v0.5.0

func NewChainStoreFFLDB(dataDir string, params *config.Params) (IFFLDBChainStore, error)

type IIterator

type IIterator interface {
	Next() bool
	Prev() bool
	First() bool
	Last() bool
	Seek(key []byte) bool
	Key() []byte
	Value() []byte
	Release()
}

type IStore

type IStore interface {
	Put(key []byte, value []byte) error
	Get(key []byte) ([]byte, error)
	Delete(key []byte) error
	NewBatch()
	BatchPut(key []byte, value []byte)
	BatchDelete(key []byte)
	BatchCommit() error
	Close() error
	NewIterator(prefix []byte) IIterator
}

type IUTXOCacheStore added in v0.5.0

type IUTXOCacheStore interface {
	GetTransaction(txID common.Uint256) (*types.Transaction, uint32, error)
}

type Iterator

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

func (*Iterator) First

func (it *Iterator) First() bool

func (*Iterator) Key

func (it *Iterator) Key() []byte

func (*Iterator) Last

func (it *Iterator) Last() bool

func (*Iterator) Next

func (it *Iterator) Next() bool

func (*Iterator) Prev

func (it *Iterator) Prev() bool

func (*Iterator) Release

func (it *Iterator) Release()

func (*Iterator) Seek

func (it *Iterator) Seek(key []byte) bool

func (*Iterator) Value

func (it *Iterator) Value() []byte

type Ledger

type Ledger struct {
	Blockchain  *BlockChain
	Store       IChainStore
	Arbitrators state.Arbitrators
	Committee   *crstate.Committee
}

Ledger - the struct for ledger

func (*Ledger) AppendDposBlocks added in v0.2.2

func (l *Ledger) AppendDposBlocks(confirms []*DposBlock) error

Append blocks and confirms directly

func (*Ledger) GetBlockWithHash

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

Get block with block hash.

func (*Ledger) GetBlockWithHeight

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

Get Block With Height.

func (*Ledger) GetDposBlocks added in v0.2.2

func (l *Ledger) GetDposBlocks(start, end uint32) ([]*DposBlock, error)

Get blocks and confirms by given height range, if end equals zero will be treat as current highest block height

func (*Ledger) GetLocalBlockChainHeight

func (l *Ledger) GetLocalBlockChainHeight() uint32

Get local block chain height.

func (*Ledger) GetTransactionWithHash

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

Get transaction with hash.

func (*Ledger) IsDoubleSpend

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

check weather the transaction contains the doubleSpend.

type LevelDB

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

func NewLevelDB

func NewLevelDB(file string) (*LevelDB, error)

func (*LevelDB) BatchCommit

func (ldb *LevelDB) BatchCommit() error

func (*LevelDB) BatchDelete

func (ldb *LevelDB) BatchDelete(key []byte)

func (*LevelDB) BatchPut

func (ldb *LevelDB) BatchPut(key []byte, value []byte)

func (*LevelDB) Close

func (ldb *LevelDB) Close() error

func (*LevelDB) Delete

func (ldb *LevelDB) Delete(key []byte) error

func (*LevelDB) Get

func (ldb *LevelDB) Get(key []byte) ([]byte, error)

func (*LevelDB) NewBatch

func (ldb *LevelDB) NewBatch()

func (*LevelDB) NewIterator

func (ldb *LevelDB) NewIterator(prefix []byte) IIterator

func (*LevelDB) Put

func (ldb *LevelDB) Put(key []byte, value []byte) error

type MedianTimeSource

type MedianTimeSource interface {
	// AdjustedTime returns the current time adjusted by the median time
	// offset as calculated from the time samples added by AddTimeSample.
	AdjustedTime() time.Time

	// AddTimeSample adds a time sample that is used when determining the
	// median time of the added samples.
	AddTimeSample(id string, timeVal time.Time)

	// Offset returns the number of seconds to adjust the local clock based
	// upon the median of the time samples added by AddTimeData.
	Offset() time.Duration

	// Reset the median time.
	Reset()
}

MedianTimeSource provides a mechanism to add several time samples which are used to determine a median time which is then used as an offset to the local clock.

func NewMedianTime

func NewMedianTime() MedianTimeSource

NewMedianTime returns a new instance of concurrency-safe implementation of the MedianTimeSource interface. The returned implementation contains the rules necessary for proper time handling in the chain consensus rules and expects the time samples to be added from the timestamp field of the version message received from remote peers that successfully connect and negotiate.

type OrphanBlock

type OrphanBlock struct {
	Block      *Block
	Expiration time.Time
}

type ProducerInfo added in v0.2.2

type ProducerInfo struct {
	Payload   *payload.ProducerInfo
	RegHeight uint32
	Vote      Fixed64
}

type ProducerState added in v0.2.2

type ProducerState byte

type UTXOCache added in v0.5.0

type UTXOCache struct {
	sync.Mutex
	// contains filtered or unexported fields
}

func NewUTXOCache added in v0.5.0

func NewUTXOCache(db IUTXOCacheStore, params *config.Params) *UTXOCache

func (*UTXOCache) CleanCache added in v0.5.0

func (up *UTXOCache) CleanCache()

func (*UTXOCache) CleanTxCache added in v0.5.0

func (up *UTXOCache) CleanTxCache()

func (*UTXOCache) GetTransaction added in v0.5.0

func (up *UTXOCache) GetTransaction(txID common.Uint256) (*types.Transaction, error)

func (*UTXOCache) GetTxReference added in v0.5.0

func (up *UTXOCache) GetTxReference(tx *types.Transaction) (map[*types.Input]types.Output, error)

Directories

Path Synopsis
Package indexers implements optional block chain indexes.
Package indexers implements optional block chain indexes.

Jump to

Keyboard shortcuts

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