blocknodes

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Dec 22, 2021 License: ISC Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type BeaconBlockNode

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

BeaconBlockNode 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 NewBeaconBlockNode

func NewBeaconBlockNode(blockHeader wire.BlockHeader, parent IBlockNode, serialID int64) *BeaconBlockNode

NewBeaconBlockNode returns a new block node for the given block header and parent node, calculating the height and workSum from the respective fields on the parent. This function is NOT safe for concurrent access.

func (*BeaconBlockNode) ActualMMRRoot added in v0.4.2

func (node *BeaconBlockNode) ActualMMRRoot() chainhash.Hash

func (*BeaconBlockNode) Ancestor

func (node *BeaconBlockNode) Ancestor(height int32) IBlockNode

Ancestor returns the ancestor block node at the provided height by following the chain backwards from this node. The returned block will be nil when a height is requested that is after the height of the passed node or is less than zero.

This function is safe for concurrent access.

func (*BeaconBlockNode) Bits

func (node *BeaconBlockNode) Bits() uint32

func (*BeaconBlockNode) CalcMedianVoteK

func (node *BeaconBlockNode) CalcMedianVoteK() uint32

func (*BeaconBlockNode) CalcPastMedianTime

func (node *BeaconBlockNode) CalcPastMedianTime() time.Time

CalcPastMedianTime calculates the median time of the previous few blocks prior to, and including, the block node.

This function is safe for concurrent access.

func (*BeaconBlockNode) CalcPastMedianTimeForN

func (node *BeaconBlockNode) CalcPastMedianTimeForN(nBlocks int) time.Time

CalcPastMedianTimeForN calculates the median time of the previous N blocks prior to, and including, the block node.

This function is safe for concurrent access.

func (*BeaconBlockNode) ExpansionApproved

func (node *BeaconBlockNode) ExpansionApproved() bool

nolint: gomnd

func (*BeaconBlockNode) GetHash

func (node *BeaconBlockNode) GetHash() chainhash.Hash

func (*BeaconBlockNode) Header

func (node *BeaconBlockNode) Header() wire.BlockHeader

Header constructs a block header from the node and returns it.

This function is safe for concurrent access.

func (*BeaconBlockNode) Height

func (node *BeaconBlockNode) Height() int32

func (*BeaconBlockNode) K

func (node *BeaconBlockNode) K() uint32

func (*BeaconBlockNode) NewHeader

func (node *BeaconBlockNode) NewHeader() wire.BlockHeader

func (*BeaconBlockNode) Parent

func (node *BeaconBlockNode) Parent() IBlockNode

func (*BeaconBlockNode) PowWeight added in v0.4.2

func (node *BeaconBlockNode) PowWeight() *big.Int

func (*BeaconBlockNode) PrevHash added in v0.4.2

func (node *BeaconBlockNode) PrevHash() chainhash.Hash

func (*BeaconBlockNode) PrevMMRRoot added in v0.4.2

func (node *BeaconBlockNode) PrevMMRRoot() chainhash.Hash

func (*BeaconBlockNode) RelativeAncestor

func (node *BeaconBlockNode) RelativeAncestor(distance int32) IBlockNode

RelativeAncestor returns the ancestor block node a relative 'distance' blocks before this node. This is equivalent to calling Ancestor with the node's height minus provided distance.

This function is safe for concurrent access.

func (*BeaconBlockNode) SerialID

func (node *BeaconBlockNode) SerialID() int64

func (*BeaconBlockNode) SetActualMMRRoot added in v0.4.2

func (node *BeaconBlockNode) SetActualMMRRoot(mmrRoot chainhash.Hash)

func (*BeaconBlockNode) SetStatus

func (node *BeaconBlockNode) SetStatus(status BlockStatus)

func (*BeaconBlockNode) Status

func (node *BeaconBlockNode) Status() BlockStatus

func (*BeaconBlockNode) Timestamp

func (node *BeaconBlockNode) Timestamp() int64

func (*BeaconBlockNode) Version

func (node *BeaconBlockNode) Version() int32

func (*BeaconBlockNode) VoteK

func (node *BeaconBlockNode) VoteK() uint32

func (*BeaconBlockNode) WorkSum

func (node *BeaconBlockNode) WorkSum() *big.Int

type BlockStatus

type BlockStatus byte

BlockStatus is a bit field representing the validation state of the block.

const (

	// StatusDataStored indicates that the block's payload is stored on disk.
	StatusDataStored BlockStatus = 1 << iota

	// StatusValid indicates that the block has been fully validated.
	StatusValid

	// StatusValidateFailed indicates that the block has failed validation.
	StatusValidateFailed

	// StatusInvalidAncestor indicates that one of the block's ancestors has
	// has failed validation, thus the block is also invalid.
	StatusInvalidAncestor

	// StatusNone indicates that the block has no validation state flags set.
	//
	// NOTE: This must be defined last in order to avoid influencing iota.
	StatusNone BlockStatus = 0
)

func (BlockStatus) HaveData

func (status BlockStatus) HaveData() bool

HaveData returns whether the full block data is stored in the database. This will return false for a block node where only the header is downloaded or kept.

func (BlockStatus) KnownInvalid

func (status BlockStatus) KnownInvalid() bool

KnownInvalid returns whether the block is known to be invalid. This may be because the block itself failed validation or any of its ancestors is invalid. This will return false for invalid blocks that have not been proven invalid yet.

func (BlockStatus) KnownValid

func (status BlockStatus) KnownValid() bool

KnownValid returns whether the block is known to be valid. This will return false for a valid block that has not been fully validated yet.

type IBlockNode

type IBlockNode interface {
	// GetHash returns hash of the block (including aux data).
	GetHash() chainhash.Hash
	// PrevMMRRoot is the root of the MMR tree before this node was added to the chain.
	PrevMMRRoot() chainhash.Hash
	// ActualMMRRoot is the root of the MMR tree after adding this node to the chain.
	ActualMMRRoot() chainhash.Hash
	// PrevHash returns hash of parent node.
	PrevHash() chainhash.Hash

	Height() int32
	SerialID() int64
	Version() int32
	Bits() uint32
	K() uint32
	VoteK() uint32
	Status() BlockStatus
	WorkSum() *big.Int
	PowWeight() *big.Int
	Timestamp() int64
	ExpansionApproved() bool

	SetStatus(status BlockStatus)
	SetActualMMRRoot(chainhash.Hash)

	Header() wire.BlockHeader
	Parent() IBlockNode
	Ancestor(height int32) IBlockNode
	CalcPastMedianTime() time.Time
	CalcPastMedianTimeForN(nBlocks int) time.Time
	CalcMedianVoteK() uint32
	RelativeAncestor(distance int32) IBlockNode

	NewHeader() wire.BlockHeader // required only for tests
}

type ShardBlockNode

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

ShardBlockNode 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 NewShardBlockNode

func NewShardBlockNode(blockHeader wire.BlockHeader, parent IBlockNode, serialID int64) *ShardBlockNode

NewShardBlockNode returns a new block node for the given block ShardBlockHeader and parent node, calculating the height and workSum from the respective fields on the parent. This function is NOT safe for concurrent access.

func (*ShardBlockNode) ActualMMRRoot added in v0.4.2

func (node *ShardBlockNode) ActualMMRRoot() chainhash.Hash

func (*ShardBlockNode) Ancestor

func (node *ShardBlockNode) Ancestor(height int32) IBlockNode

Ancestor returns the ancestor block node at the provided height by following the chain backwards from this node. The returned block will be nil when a height is requested that is after the height of the passed node or is less than zero.

This function is safe for concurrent access.

func (*ShardBlockNode) Bits

func (node *ShardBlockNode) Bits() uint32

func (*ShardBlockNode) CalcMedianVoteK

func (node *ShardBlockNode) CalcMedianVoteK() uint32

nolint: gomnd

func (*ShardBlockNode) CalcPastMedianTime

func (node *ShardBlockNode) CalcPastMedianTime() time.Time

CalcPastMedianTime calculates the median time of the previous few blocks prior to, and including, the block node.

This function is safe for concurrent access.

func (*ShardBlockNode) CalcPastMedianTimeForN

func (node *ShardBlockNode) CalcPastMedianTimeForN(nBlocks int) time.Time

CalcPastMedianTimeForN calculates the median time of the previous N blocks prior to, and including, the block node.

This function is safe for concurrent access.

func (*ShardBlockNode) ExpansionApproved

func (node *ShardBlockNode) ExpansionApproved() bool

func (*ShardBlockNode) GetHash

func (node *ShardBlockNode) GetHash() chainhash.Hash

func (*ShardBlockNode) Header

func (node *ShardBlockNode) Header() wire.BlockHeader

Header constructs a block ShardBlockHeader from the node and returns it.

This function is safe for concurrent access.

func (*ShardBlockNode) Height

func (node *ShardBlockNode) Height() int32

func (*ShardBlockNode) K

func (node *ShardBlockNode) K() uint32

func (*ShardBlockNode) NewHeader

func (node *ShardBlockNode) NewHeader() wire.BlockHeader

func (*ShardBlockNode) Parent

func (node *ShardBlockNode) Parent() IBlockNode

func (*ShardBlockNode) PowWeight added in v0.4.2

func (node *ShardBlockNode) PowWeight() *big.Int

func (*ShardBlockNode) PrevHash added in v0.4.2

func (node *ShardBlockNode) PrevHash() chainhash.Hash

func (*ShardBlockNode) PrevMMRRoot added in v0.4.2

func (node *ShardBlockNode) PrevMMRRoot() chainhash.Hash

func (*ShardBlockNode) RelativeAncestor

func (node *ShardBlockNode) RelativeAncestor(distance int32) IBlockNode

RelativeAncestor returns the ancestor block node a relative 'distance' blocks before this node. This is equivalent to calling Ancestor with the node's height minus provided distance.

This function is safe for concurrent access.

func (*ShardBlockNode) SerialID

func (node *ShardBlockNode) SerialID() int64

func (*ShardBlockNode) SetActualMMRRoot added in v0.4.2

func (node *ShardBlockNode) SetActualMMRRoot(mmrRoot chainhash.Hash)

func (*ShardBlockNode) SetStatus

func (node *ShardBlockNode) SetStatus(status BlockStatus)

func (*ShardBlockNode) Status

func (node *ShardBlockNode) Status() BlockStatus

func (*ShardBlockNode) Timestamp

func (node *ShardBlockNode) Timestamp() int64

func (*ShardBlockNode) Version

func (node *ShardBlockNode) Version() int32

func (*ShardBlockNode) VoteK

func (node *ShardBlockNode) VoteK() uint32

func (*ShardBlockNode) WorkSum

func (node *ShardBlockNode) WorkSum() *big.Int

Jump to

Keyboard shortcuts

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