node

package
v0.22.119 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2022 License: ISC Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ComputeMerkleRoot

func ComputeMerkleRoot(hashes []*chainhash.Hash) *chainhash.Hash

func DisableLog

func DisableLog()

DisableLog disables all library log output. Logging output is disabled by default until either UseLogger or SetLogWriter are called.

func GetLogger

func GetLogger() btclog.Logger

func HashMerkleBranches

func HashMerkleBranches(left *chainhash.Hash, right *chainhash.Hash) *chainhash.Hash

func Log

func Log(s string)

func LogOnce

func LogOnce(s string)

func NewOutPointFromString

func NewOutPointFromString(str string) *wire.OutPoint

func OutPointLess

func OutPointLess(a, b wire.OutPoint) bool

func UseLogger

func UseLogger(logger btclog.Logger)

UseLogger uses a specified Logger to output package logging info. This should be used in preference to SetLogWriter if the caller is also using btclog.

func Warn

func Warn(s string)

Types

type BaseManager

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

func NewBaseManager

func NewBaseManager(repo Repo) (*BaseManager, error)

func (*BaseManager) AppendChange

func (nm *BaseManager) AppendChange(chg change.Change)

func (*BaseManager) ClearCache

func (nm *BaseManager) ClearCache()

func (*BaseManager) Close

func (nm *BaseManager) Close() error

func (*BaseManager) DecrementHeightTo

func (nm *BaseManager) DecrementHeightTo(affectedNames [][]byte, height int32) ([][]byte, error)

func (*BaseManager) Flush

func (nm *BaseManager) Flush() error

func (*BaseManager) Hash

func (nm *BaseManager) Hash(name []byte) (*chainhash.Hash, int32)

func (*BaseManager) Height

func (nm *BaseManager) Height() int32

func (*BaseManager) IncrementHeightTo

func (nm *BaseManager) IncrementHeightTo(height int32, temporary bool) ([][]byte, error)

func (*BaseManager) IterateNames

func (nm *BaseManager) IterateNames(predicate func(name []byte) bool)

func (*BaseManager) NodeAt

func (nm *BaseManager) NodeAt(height int32, name []byte) (*Node, error)

type Cache

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

func NewCache

func NewCache(limit int) *Cache

type Claim

type Claim struct {
	OutPoint wire.OutPoint
	ClaimID  change.ClaimID
	Amount   int64
	// CreatedAt  int32 // the very first block, unused at present
	AcceptedAt int32 // the latest update height
	ActiveAt   int32 // AcceptedAt + actual delay
	VisibleAt  int32

	Status   Status `msgpack:",omitempty"`
	Sequence int32  `msgpack:",omitempty"`
}

Claim defines a structure of stake, which could be a Claim or Support.

func (*Claim) SetAmt

func (c *Claim) SetAmt(amt int64) *Claim

type ClaimList

type ClaimList []*Claim

type HashV2Manager

type HashV2Manager struct {
	Manager
}

func (*HashV2Manager) Hash

func (nm *HashV2Manager) Hash(name []byte) (*chainhash.Hash, int32)

type Manager

type Manager interface {
	AppendChange(chg change.Change)
	IncrementHeightTo(height int32, temporary bool) ([][]byte, error)
	DecrementHeightTo(affectedNames [][]byte, height int32) ([][]byte, error)
	Height() int32
	Close() error
	NodeAt(height int32, name []byte) (*Node, error)
	IterateNames(predicate func(name []byte) bool)
	Hash(name []byte) (*chainhash.Hash, int32)
	Flush() error
	ClearCache()
}

func NewNormalizingManager

func NewNormalizingManager(baseManager Manager) Manager

type Node

type Node struct {
	BestClaim   *Claim    // The claim that has most effective amount at the current height.
	TakenOverAt int32     // The height at when the current BestClaim took over.
	Claims      ClaimList // List of all Claims.
	Supports    ClaimList // List of all Supports, including orphaned ones.
	SupportSums map[string]int64
}

func New

func New() *Node

New returns a new node.

func (*Node) AdjustTo

func (n *Node) AdjustTo(height, maxHeight int32, name []byte)

AdjustTo activates claims and computes takeovers until it reaches the specified height.

func (*Node) ApplyChange

func (n *Node) ApplyChange(chg change.Change, delay int32) error

func (*Node) Clone

func (n *Node) Clone() *Node

func (*Node) HasActiveBestClaim

func (n *Node) HasActiveBestClaim() bool

func (Node) NextUpdate

func (n Node) NextUpdate() int32

NextUpdate returns the nearest height in the future that the node should be refreshed due to changes of claims or supports.

func (*Node) SortClaimsByBid

func (n *Node) SortClaimsByBid()

type NormalizingManager

type NormalizingManager struct {
	Manager
	// contains filtered or unexported fields
}

func (*NormalizingManager) AppendChange

func (nm *NormalizingManager) AppendChange(chg change.Change)

func (*NormalizingManager) DecrementHeightTo

func (nm *NormalizingManager) DecrementHeightTo(affectedNames [][]byte, height int32) ([][]byte, error)

func (*NormalizingManager) IncrementHeightTo

func (nm *NormalizingManager) IncrementHeightTo(height int32, temporary bool) ([][]byte, error)

type Repo

type Repo interface {
	// AppendChanges saves changes into the repo.
	// The changes can belong to different nodes, but the chronological
	// order must be preserved for the same node.
	AppendChanges(changes []change.Change) error

	// LoadChanges loads changes of a node up to (includes) the specified height.
	// If no changes found, both returned slice and error will be nil.
	LoadChanges(name []byte) ([]change.Change, error)

	DropChanges(name []byte, finalHeight int32) error

	// Close closes the repo.
	Close() error

	// IterateChildren returns change sets for each of name.+
	// Return false on f to stop the iteration.
	IterateChildren(name []byte, f func(changes []change.Change) bool) error

	// IterateAll iterates keys until the predicate function returns false
	IterateAll(predicate func(name []byte) bool)

	Flush() error
}

Repo defines APIs for Node to access persistence layer.

type Status

type Status int
const (
	Accepted Status = iota
	Activated
	Deactivated
)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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