tangle

package
v2.0.0-beta.3 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2022 License: Apache-2.0 Imports: 31 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SolidifierTriggerSignal = iotago.MilestoneIndex(0)
)

Variables

View Source
var (
	ErrBlockAttacherInvalidBlock         = errors.New("invalid block")
	ErrBlockAttacherAttachingNotPossible = errors.New("attaching not possible")
	ErrBlockAttacherPoWNotAvailable      = errors.New("proof of work is not available on this node")
)
View Source
var (
	ErrLatestMilestoneOlderThanSnapshotIndex = errors.New("latest milestone in the database is older than the snapshot index")
	ErrSnapshotIndexWrong                    = errors.New("snapshot index does not fit the snapshot ledger index")
)
View Source
var (
	ErrParentsNotGiven = errors.New("no parents given")
	ErrParentsNotSolid = errors.New("parents not solid")
)
View Source
var (
	ErrDivisionByZero = errors.New("division by zero")
)

Functions

func AddBlockToStorage

func AddBlockToStorage(dbStorage *storage.Storage, milestoneManager *milestonemanager.MilestoneManager, block *storage.Block, latestMilestoneIndex iotago.MilestoneIndex, requested bool, forceRelease bool) (cachedBlock *storage.CachedBlock, alreadyAdded bool)

AddBlockToStorage adds a new block to the cache/persistence layer, including all additional information like metadata, children, unreferenced blocks and milestone entries. block +1

func BPSMetricsCaller

func BPSMetricsCaller(handler interface{}, params ...interface{})

func ConfirmationMetricsCaller

func ConfirmationMetricsCaller(handler interface{}, params ...interface{})

ConfirmationMetricsCaller is used to signal updated confirmation metrics.

func LedgerUpdatedCaller

func LedgerUpdatedCaller(handler interface{}, params ...interface{})

func ReceiptCaller

func ReceiptCaller(handler interface{}, params ...interface{})

func ReferencedBlocksCountUpdatedCaller

func ReferencedBlocksCountUpdatedCaller(handler interface{}, params ...interface{})

func TreasuryMutationCaller

func TreasuryMutationCaller(handler interface{}, params ...interface{})

Types

type BPSMetrics

type BPSMetrics struct {
	Incoming uint32 `json:"incoming"`
	New      uint32 `json:"new"`
	Outgoing uint32 `json:"outgoing"`
}

type BlockAttacher

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

func (*BlockAttacher) AttachBlock

func (a *BlockAttacher) AttachBlock(ctx context.Context, iotaBlock *iotago.Block) (iotago.BlockID, error)

type BlockAttacherOption

type BlockAttacherOption func(opts *BlockAttacherOptions)

func WithPoW

func WithPoW(handler *pow.Handler, workerCount int) BlockAttacherOption

func WithPoWMetrics

func WithPoWMetrics(powMetrics metrics.PoWMetrics) BlockAttacherOption

func WithTimeout

func WithTimeout(blockProcessedTimeout time.Duration) BlockAttacherOption

func WithTipSel

func WithTipSel(tipsFunc pow.RefreshTipsFunc) BlockAttacherOption

type BlockAttacherOptions

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

type ConfirmedMilestoneMetric

type ConfirmedMilestoneMetric struct {
	MilestoneIndex         iotago.MilestoneIndex `json:"ms_index"`
	BPS                    float64               `json:"bps"`
	RBPS                   float64               `json:"rbps"`
	ReferencedRate         float64               `json:"referenced_rate"`
	TimeSinceLastMilestone float64               `json:"time_since_last_ms"`
}

type Events

type Events struct {
	// block events
	ReceivedNewBlock          *events.Event
	BlockSolid                *events.Event
	ReceivedNewMilestoneBlock *events.Event // remove with dashboard removal PR

	// milestone events
	LatestMilestoneChanged        *events.Event
	LatestMilestoneIndexChanged   *events.Event
	MilestoneSolidificationFailed *events.Event
	MilestoneTimeout              *events.Event

	// metrics
	BPSMetricsUpdated *events.Event

	// Hint: Ledger is write locked
	ConfirmedMilestoneIndexChanged *events.Event
	// Hint: Ledger is not locked
	ConfirmationMetricsUpdated *events.Event // used for prometheus metrics
	// Hint: Ledger is not locked
	ConfirmedMilestoneChanged *events.Event
	// Hint: Ledger is not locked
	BlockReferenced *events.Event
	// Hint: Ledger is not locked
	ReferencedBlocksCountUpdated *events.Event
	// Hint: Ledger is not locked
	LedgerUpdated *events.Event
	// Hint: Ledger is not locked
	TreasuryMutated *events.Event
	// Hint: Ledger is not locked
	NewReceipt *events.Event
}

type FutureConeSolidifier

type FutureConeSolidifier struct {
	syncutils.Mutex
	// contains filtered or unexported fields
}

FutureConeSolidifier traverses the future cone of blocks and updates their solidity. It holds a reference to a traverser and a memcache, so that these can be reused for "gossip solidifcation".

func NewFutureConeSolidifier

func NewFutureConeSolidifier(dbStorage *storage.Storage, markBlockAsSolidFunc MarkBlockAsSolidFunc) *FutureConeSolidifier

NewFutureConeSolidifier creates a new FutureConeSolidifier instance.

func (*FutureConeSolidifier) Cleanup

func (s *FutureConeSolidifier) Cleanup(forceRelease bool)

Cleanup releases all the currently cached objects that have been traversed. This SHOULD be called periodically to free the caches (e.g. with every change of the latest known milestone index).

func (*FutureConeSolidifier) SolidifyBlockAndFutureCone

func (s *FutureConeSolidifier) SolidifyBlockAndFutureCone(ctx context.Context, cachedBlockMeta *storage.CachedMetadata) error

SolidifyBlockAndFutureCone updates the solidity of the block and its future cone (blocks approving the given block). We keep on walking the future cone, if a block became newly solid during the walk.

func (*FutureConeSolidifier) SolidifyFutureConesWithMetadataMemcache

func (s *FutureConeSolidifier) SolidifyFutureConesWithMetadataMemcache(ctx context.Context, memcachedTraverserStorage dag.TraverserStorage, blockIDs iotago.BlockIDs) error

SolidifyFutureConesWithMetadataMemcache updates the solidity of the given blocks and their future cones (blocks approving the given blocks). This function doesn't use the same memcache nor traverser like the FutureConeSolidifier, but it holds the lock, so no other solidifications are done in parallel.

type MarkBlockAsSolidFunc

type MarkBlockAsSolidFunc func(*storage.CachedMetadata)

type Tangle

type Tangle struct {
	// the logger used to log events.
	*logger.WrappedLogger

	Events *Events
	// contains filtered or unexported fields
}

func New

func New(
	log *logger.Logger,
	daemon daemon.Daemon,
	shutdownCtx context.Context,
	dbStorage *storage.Storage,
	syncManager *syncmanager.SyncManager,
	milestoneManager *milestonemanager.MilestoneManager,
	requestQueue gossip.RequestQueue,
	gossipService *gossip.Service,
	messageProcessor *gossip.MessageProcessor,
	serverMetrics *metrics.ServerMetrics,
	requester *gossip.Requester,
	receiptService *migrator.ReceiptService,
	protocolManager *protocol.Manager,
	milestoneTimeout time.Duration,
	whiteFlagParentsSolidTimeout time.Duration,
	updateSyncedAtStartup bool) *Tangle

func (*Tangle) AbortMilestoneSolidification

func (t *Tangle) AbortMilestoneSolidification()

func (*Tangle) BlockAttacher

func (t *Tangle) BlockAttacher(opts ...BlockAttacherOption) *BlockAttacher

func (*Tangle) CheckSolidityAndComputeWhiteFlagMutations

func (t *Tangle) CheckSolidityAndComputeWhiteFlagMutations(ctx context.Context, index iotago.MilestoneIndex, timestamp uint32, parents iotago.BlockIDs, previousMilestoneID iotago.MilestoneID) (*whiteflag.WhiteFlagMutations, error)

CheckSolidityAndComputeWhiteFlagMutations waits until all given parents are solid, an then calculates the white flag mutations with given milestone index, timestamp and previousMilestoneID. Attention: this call puts missing parents of the cone as undiscardable requests into the request queue. Therefore the caller needs to be trustful (e.g. coordinator plugin).

func (*Tangle) ConfigureTangleProcessor

func (t *Tangle) ConfigureTangleProcessor()

func (*Tangle) DeregisterBlockProcessedEvent

func (t *Tangle) DeregisterBlockProcessedEvent(blockID iotago.BlockID)

DeregisterBlockProcessedEvent removes a registered event to free the memory if not used.

func (*Tangle) DeregisterBlockSolidEvent

func (t *Tangle) DeregisterBlockSolidEvent(blockID iotago.BlockID)

DeregisterBlockSolidEvent removes a registered event to free the memory if not used.

func (*Tangle) IsNodeHealthy

func (t *Tangle) IsNodeHealthy() bool

IsNodeHealthy returns whether the node is synced, has active peers and its latest milestone is not too old.

func (*Tangle) IsReceiveTxWorkerPoolBusy

func (t *Tangle) IsReceiveTxWorkerPoolBusy() bool

func (*Tangle) LastConfirmedMilestoneMetric

func (t *Tangle) LastConfirmedMilestoneMetric() *ConfirmedMilestoneMetric

func (*Tangle) PrintStatus

func (t *Tangle) PrintStatus()

func (*Tangle) RegisterBlockProcessedEvent

func (t *Tangle) RegisterBlockProcessedEvent(blockID iotago.BlockID) chan struct{}

RegisterBlockProcessedEvent returns a channel that gets closed when the block is processed.

func (*Tangle) RegisterBlockSolidEvent

func (t *Tangle) RegisterBlockSolidEvent(blockID iotago.BlockID) chan struct{}

RegisterBlockSolidEvent returns a channel that gets closed when the block is marked as solid.

func (*Tangle) ResetMilestoneTimeoutTicker

func (t *Tangle) ResetMilestoneTimeoutTicker()

ResetMilestoneTimeoutTicker stops a running milestone timeout ticker and starts a new one. MilestoneTimeout event is fired periodically if ResetMilestoneTimeoutTicker is not called within milestoneTimeout.

func (*Tangle) RevalidateDatabase

func (t *Tangle) RevalidateDatabase(snapshotImporter *snapshot.Importer, pruneReceipts bool) error

RevalidateDatabase tries to revalidate a corrupted database (after an unclean node shutdown/crash)

HORNET uses caches for almost all tangle related data. If the node crashes, it is not guaranteed that all data in the cache was already persisted to the disk. Thats why we flag the database as corrupted.

This function tries to restore a clean database state by deleting all existing blocks since last local snapshot, deleting all ledger states and changes, and loading a valid snapshot ledger state.

This way HORNET should be able to re-solidify the existing tangle in the database.

Object Storages:

  • Milestone => will be removed and added again if missing by receiving the block
  • Block => will be removed and added again by requesting the block at solidification
  • BlockMetadata => will be removed and added again if missing by receiving the block
  • Children => will be removed and added again if missing by receiving the block
  • Indexation => will be removed and added again if missing by receiving the block
  • UnreferencedBlock => will be removed at pruning anyway

Database:

  • LedgerState
  • Unspent => will be removed and loaded again from last snapshot
  • Spent => will be removed and loaded again from last snapshot
  • Balances => will be removed and loaded again from last snapshot
  • Diffs => will be removed and loaded again from last snapshot
  • Treasury => will be removed and loaded again from last snapshot
  • Receipts => will be removed and loaded again from last snapshot (if pruneReceipts is enabled)

func (*Tangle) RunTangleProcessor

func (t *Tangle) RunTangleProcessor()

func (*Tangle) SetUpdateSyncedAtStartup

func (t *Tangle) SetUpdateSyncedAtStartup(updateSyncedAtStartup bool)

SetUpdateSyncedAtStartup sets the flag if the isNodeSynced status should be updated at startup

func (*Tangle) SolidQueueCheck

func (t *Tangle) SolidQueueCheck(
	ctx context.Context,
	memcachedTraverserStorage dag.TraverserStorage,
	milestoneIndex iotago.MilestoneIndex,
	parents iotago.BlockIDs) (solid bool, aborted bool)

SolidQueueCheck traverses a milestone and checks if it is solid. Missing blocks are requested. Can be aborted if the given context is canceled.

func (*Tangle) StopMilestoneTimeoutTicker

func (t *Tangle) StopMilestoneTimeoutTicker()

StopMilestoneTimeoutTicker stops the milestone timeout ticker.

func (*Tangle) TriggerSolidifier

func (t *Tangle) TriggerSolidifier()

TriggerSolidifier can be used to manually trigger the solidifier from other plugins.

func (*Tangle) WaitForTangleProcessorStartup

func (t *Tangle) WaitForTangleProcessorStartup()

WaitForTangleProcessorStartup waits until all background workers of the tangle processor are started.

type TipScore

type TipScore int
const (
	TipScoreNotFound TipScore = iota
	TipScoreBelowMaxDepth
	TipScoreYCRIThresholdReached
	TipScoreOCRIThresholdReached
	TipScoreHealthy
)

type TipScoreCalculator

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

func NewTipScoreCalculator

func NewTipScoreCalculator(storage *storage.Storage, maxDeltaBlockYoungestConeRootIndexToCMI int, maxDeltaBlockOldestConeRootIndexToCMI int, belowMaxDepth int) *TipScoreCalculator

func (*TipScoreCalculator) TipScore

Jump to

Keyboard shortcuts

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