Documentation ¶
Index ¶
- Constants
- Variables
- func PruningMetricsCaller(handler interface{}, params ...interface{})
- func SnapshotMetricsCaller(handler interface{}, params ...interface{})
- func StreamSnapshotDataFrom(reader io.Reader, headerConsumer HeaderConsumerFunc, ...) error
- type DownloadTarget
- type Events
- type FileHeader
- type HeaderConsumerFunc
- type MergeInfo
- type MilestoneDiff
- type MilestoneDiffConsumerFunc
- type MilestoneDiffProducerFunc
- type MilestoneRetrieverFunc
- type MsDiffDirection
- type Output
- type OutputConsumerFunc
- type OutputProducerFunc
- type PruningMetrics
- type ReadFileHeader
- type SEPConsumerFunc
- type SEPProducerFunc
- type Snapshot
- func (s *Snapshot) CheckCurrentSnapshot(snapshotInfo *storage.SnapshotInfo) error
- func (s *Snapshot) CreateDeltaSnapshot(targetIndex milestone.Index, filePath string, writeToDatabase bool, ...) error
- func (s *Snapshot) CreateFullSnapshot(targetIndex milestone.Index, filePath string, writeToDatabase bool, ...) error
- func (s *Snapshot) DownloadSnapshotFiles(wantedNetworkID uint64, fullPath string, deltaPath string, ...) error
- func (s *Snapshot) GetSnapshotsFilesLedgerIndex() (milestone.Index, error)
- func (s *Snapshot) HandleNewConfirmedMilestoneEvent(confirmedMilestoneIndex milestone.Index, shutdownSignal <-chan struct{})
- func (s *Snapshot) ImportSnapshots() error
- func (s *Snapshot) IsSnapshottingOrPruning() bool
- func (s *Snapshot) LoadSnapshotFromFile(snapshotType Type, networkID uint64, filePath string) error
- func (s *Snapshot) PruneDatabaseByDepth(depth milestone.Index) (milestone.Index, error)
- func (s *Snapshot) PruneDatabaseBySize(targetSizeBytes int64) (milestone.Index, error)
- func (s *Snapshot) PruneDatabaseByTargetIndex(targetIndex milestone.Index) (milestone.Index, error)
- type SnapshotMetrics
- type Spent
- type Type
- type UnspentTreasuryOutputConsumerFunc
- type WriteCounter
Constants ¶
const ( // The supported snapshot file version. SupportedFormatVersion byte = 1 // The length of a solid entry point hash. SolidEntryPointHashLength = iotago.MessageIDLength )
Variables ¶
var ( // Returned when a critical error stops the execution of a task. ErrCritical = errors.New("critical error") // Returned when unsupported snapshot data is read. ErrUnsupportedSnapshot = errors.New("unsupported snapshot data") // Returned when a child message wasn't found. ErrChildMsgNotFound = errors.New("child message not found") // Returned when the milestone diff that should be applied is not the current or next milestone. ErrWrongMilestoneDiffIndex = errors.New("wrong milestone diff index") // Returned when the final milestone after loading the snapshot is not equal to the solid entry point index. ErrFinalLedgerIndexDoesNotMatchSEPIndex = errors.New("final ledger index does not match solid entry point index") // Returned when a delta snapshot is available, but no full snapshot is found. ErrInvalidSnapshotAvailabilityState = errors.New("invalid snapshot files availability") ErrNoSnapshotSpecified = errors.New("no snapshot file was specified in the config") ErrNoSnapshotDownloadURL = errors.New("no download URL specified for snapshot files in config") ErrSnapshotDownloadWasAborted = errors.New("snapshot download was aborted") ErrSnapshotDownloadNoValidSource = errors.New("no valid source found, snapshot download not possible") ErrSnapshotCreationWasAborted = errors.New("operation was aborted") ErrSnapshotCreationFailed = errors.New("creating snapshot failed") ErrTargetIndexTooNew = errors.New("snapshot target is too new") ErrTargetIndexTooOld = errors.New("snapshot target is too old") ErrNotEnoughHistory = errors.New("not enough history") ErrNoPruningNeeded = errors.New("no pruning needed") ErrPruningAborted = errors.New("pruning was aborted") ErrDatabaseCompactionNotSupported = errors.New("database compaction not supported") ErrDatabaseCompactionRunning = errors.New("database compaction is running") ErrExistingDeltaSnapshotWrongLedgerIndex = errors.New("existing delta ledger snapshot has wrong ledger index") )
var ( // Returned when an output producer has not been provided. ErrOutputProducerNotProvided = errors.New("output producer is not provided") // Returned when an output consumer has not been provided. ErrOutputConsumerNotProvided = errors.New("output consumer is not provided") // Returned when the treasury output for a full snapshot has not been provided. ErrTreasuryOutputNotProvided = errors.New("treasury output is not provided") // Returned when a treasury output consumer has not been provided. ErrTreasuryOutputConsumerNotProvided = errors.New("treasury output consumer is not provided") // Returned if specified snapshots are not mergeable. ErrSnapshotsNotMergeable = errors.New("snapshot files not mergeable") )
Functions ¶
func PruningMetricsCaller ¶
func PruningMetricsCaller(handler interface{}, params ...interface{})
PruningMetricsCaller is used to signal updated pruning metrics.
func SnapshotMetricsCaller ¶
func SnapshotMetricsCaller(handler interface{}, params ...interface{})
SnapshotMetricsCaller is used to signal updated snapshot metrics.
func StreamSnapshotDataFrom ¶
func StreamSnapshotDataFrom(reader io.Reader, headerConsumer HeaderConsumerFunc, sepConsumer SEPConsumerFunc, outputConsumer OutputConsumerFunc, unspentTreasuryOutputConsumer UnspentTreasuryOutputConsumerFunc, msDiffConsumer MilestoneDiffConsumerFunc) error
StreamSnapshotDataFrom consumes a snapshot from the given reader. OutputConsumerFunc must not be nil if the snapshot is not a delta snapshot.
Types ¶
type DownloadTarget ¶
type DownloadTarget struct { // URL of the full snapshot file. Full string `json:"full"` // URL of the delta snapshot file. Delta string `json:"delta"` }
DownloadTarget holds URLs to a full and delta snapshot.
type FileHeader ¶
type FileHeader struct { // Version denotes the version of this snapshot. Version byte // Type denotes the type of this snapshot. Type Type // The ID of the network for which this snapshot is compatible with. NetworkID uint64 // The milestone index of the SEPs for which this snapshot was taken. SEPMilestoneIndex milestone.Index // The milestone index of the ledger data within the snapshot. LedgerMilestoneIndex milestone.Index // The treasury output existing for the given ledger milestone index. // This field must be populated if a Full snapshot is created/read. TreasuryOutput *utxo.TreasuryOutput }
FileHeader is the file header of a snapshot file.
type HeaderConsumerFunc ¶
type HeaderConsumerFunc func(*ReadFileHeader) error
HeaderConsumerFunc consumes the snapshot file header. A returned error signals to cancel further reading.
type MergeInfo ¶
type MergeInfo struct { // The header of the full snapshot. FullSnapshotHeader *ReadFileHeader // The header of the delta snapshot. DeltaSnapshotHeader *ReadFileHeader // The header of the merged snapshot. MergedSnapshotHeader *FileHeader // The total output count of the ledger. UnspentOutputsCount uint64 // The total count of solid entry points. SEPsCount int }
MergeInfo holds information about a merge of a full and delta snapshot.
func MergeSnapshotsFiles ¶
func MergeSnapshotsFiles(tempDBPath string, fullPath string, deltaPath string, targetFileName string) (*MergeInfo, error)
MergeSnapshotsFiles merges the given full and delta snapshots to create an updated full snapshot. The result is a full snapshot file containing the ledger outputs corresponding to the snapshot index of the specified delta snapshot. The target file does not include any milestone diffs and the ledger and snapshot index are equal. This function consumes disk space over memory by importing the full snapshot into a temporary database, applying the delta diffs onto it and then writing out the merged state.
type MilestoneDiff ¶
type MilestoneDiff struct { // The milestone payload itself. Milestone *iotago.Milestone `json:"milestone"` // The created outputs with this milestone. Created []*Output `json:"created"` // The consumed spents with this milestone. Consumed []*Spent `json:"consumed"` // The consumed treasury output with this milestone. SpentTreasuryOutput *utxo.TreasuryOutput }
MilestoneDiff represents the outputs which were created and consumed for the given milestone and the message itself which contains the milestone.
func (*MilestoneDiff) MarshalBinary ¶
func (md *MilestoneDiff) MarshalBinary() ([]byte, error)
func (*MilestoneDiff) TreasuryOutput ¶
func (md *MilestoneDiff) TreasuryOutput() *utxo.TreasuryOutput
TreasuryOutput extracts the new treasury output from within the milestone receipt. Might return nil if there is no receipt within the milestone.
type MilestoneDiffConsumerFunc ¶
type MilestoneDiffConsumerFunc func(milestoneDiff *MilestoneDiff) error
MilestoneDiffConsumerFunc consumes the given MilestoneDiff. A returned error signals to cancel further reading.
type MilestoneDiffProducerFunc ¶
type MilestoneDiffProducerFunc func() (*MilestoneDiff, error)
MilestoneDiffProducerFunc yields a milestone diff to be written to a snapshot or nil if no more is available.
type MilestoneRetrieverFunc ¶
MilestoneRetrieverFunc is a function which returns the milestone for the given index.
func MilestoneRetrieverFromStorage ¶
func MilestoneRetrieverFromStorage(storage *storage.Storage) MilestoneRetrieverFunc
MilestoneRetrieverFromStorage creates a MilestoneRetrieverFunc which access the storage. If it can not retrieve a wanted milestone it panics.
type MsDiffDirection ¶
type MsDiffDirection byte
MsDiffDirection determines the milestone diff direction.
const ( // MsDiffDirectionBackwards defines to produce milestone diffs in backwards direction. MsDiffDirectionBackwards MsDiffDirection = iota // MsDiffDirectionOnwards defines to produce milestone diffs in onwards direction. MsDiffDirectionOnwards )
type Output ¶
type Output struct { // The message ID of the message that contained the transaction where this output was created. MessageID [iotago.MessageIDLength]byte `json:"message_id"` // The transaction ID and the index of the output. OutputID [iotago.TransactionIDLength + 2]byte `json:"output_id"` // The type of the output. OutputType iotago.OutputType `json:"output_type"` // The underlying address to which this output deposits to. Address iotago.Serializable `json:"address"` // The amount of the deposit. Amount uint64 `json:"amount"` }
Output defines an output within a snapshot.
func (*Output) MarshalBinary ¶
type OutputConsumerFunc ¶
OutputConsumerFunc consumes the given output. A returned error signals to cancel further reading.
type OutputProducerFunc ¶
OutputProducerFunc yields an output to be written to a snapshot or nil if no more is available.
type PruningMetrics ¶
type PruningMetrics struct { DurationPruneUnreferencedMessages time.Duration DurationTraverseMilestoneCone time.Duration DurationPruneMilestone time.Duration DurationPruneMessages time.Duration DurationSetSnapshotInfo time.Duration DurationPruningMilestoneIndexChanged time.Duration DurationTotal time.Duration }
PruningMetrics holds metrics about a database pruning run.
type ReadFileHeader ¶
type ReadFileHeader struct { FileHeader // The time at which the snapshot was taken. Timestamp uint64 // The count of solid entry points. SEPCount uint64 // The count of outputs. This count is zero if a delta snapshot has been read. OutputCount uint64 // The count of milestone diffs. MilestoneDiffCount uint64 }
ReadFileHeader is a FileHeader but with additional content read from the snapshot.
func ReadSnapshotHeader ¶
func ReadSnapshotHeader(reader io.Reader) (*ReadFileHeader, error)
ReadSnapshotHeader reads the snapshot header from the given reader.
func ReadSnapshotHeaderFromFile ¶ added in v1.0.2
func ReadSnapshotHeaderFromFile(filePath string) (*ReadFileHeader, error)
ReadSnapshotHeaderFromFile reads the header of the given snapshot file.
type SEPConsumerFunc ¶
SEPConsumerFunc consumes the given solid entry point. A returned error signals to cancel further reading.
type SEPProducerFunc ¶
SEPProducerFunc yields a solid entry point to be written to a snapshot or nil if no more is available.
type Snapshot ¶
type Snapshot struct { Events *Events // contains filtered or unexported fields }
Snapshot handles reading and writing snapshot data.
func New ¶
func New(shutdownCtx context.Context, log *logger.Logger, database *database.Database, storage *storage.Storage, utxo *utxo.Manager, networkID uint64, networkIDSource string, snapshotFullPath string, snapshotDeltaPath string, deltaSnapshotSizeThresholdPercentage float64, downloadTargets []*DownloadTarget, solidEntryPointCheckThresholdPast milestone.Index, solidEntryPointCheckThresholdFuture milestone.Index, additionalPruningThreshold milestone.Index, snapshotDepth milestone.Index, snapshotInterval milestone.Index, pruningMilestonesEnabled bool, pruningMilestonesMaxMilestonesToKeep milestone.Index, pruningSizeEnabled bool, pruningSizeTargetSizeBytes int64, pruningSizeThresholdPercentage float64, pruningSizeCooldownTime time.Duration, pruneReceipts bool) *Snapshot
New creates a new snapshot instance.
func (*Snapshot) CheckCurrentSnapshot ¶
func (s *Snapshot) CheckCurrentSnapshot(snapshotInfo *storage.SnapshotInfo) error
checks that the current snapshot info is valid regarding its network ID and the ledger state.
func (*Snapshot) CreateDeltaSnapshot ¶
func (s *Snapshot) CreateDeltaSnapshot(targetIndex milestone.Index, filePath string, writeToDatabase bool, abortSignal <-chan struct{}, snapshotFullPath ...string) error
CreateDeltaSnapshot creates a delta snapshot for the given target milestone index.
func (*Snapshot) CreateFullSnapshot ¶
func (s *Snapshot) CreateFullSnapshot(targetIndex milestone.Index, filePath string, writeToDatabase bool, abortSignal <-chan struct{}) error
CreateFullSnapshot creates a full snapshot for the given target milestone index.
func (*Snapshot) DownloadSnapshotFiles ¶
func (s *Snapshot) DownloadSnapshotFiles(wantedNetworkID uint64, fullPath string, deltaPath string, targets []*DownloadTarget) error
DownloadSnapshotFiles tries to download snapshots files from the given targets.
func (*Snapshot) GetSnapshotsFilesLedgerIndex ¶ added in v1.0.2
GetSnapshotsFilesLedgerIndex returns the final ledger index if the snapshots from the configured file paths would be applied.
func (*Snapshot) HandleNewConfirmedMilestoneEvent ¶
func (s *Snapshot) HandleNewConfirmedMilestoneEvent(confirmedMilestoneIndex milestone.Index, shutdownSignal <-chan struct{})
HandleNewConfirmedMilestoneEvent handles new confirmed milestone events which may trigger a delta snapshot creation and pruning.
func (*Snapshot) ImportSnapshots ¶
ImportSnapshots imports snapshot data from the configured file paths. automatically downloads snapshot data if no files are available.
func (*Snapshot) IsSnapshottingOrPruning ¶
func (*Snapshot) LoadSnapshotFromFile ¶
LoadSnapshotFromFile loads a snapshot file from the given file path into the storage.
func (*Snapshot) PruneDatabaseByDepth ¶
func (*Snapshot) PruneDatabaseBySize ¶ added in v1.0.2
type SnapshotMetrics ¶
type SnapshotMetrics struct { DurationReadLockLedger time.Duration DurationInit time.Duration DurationSetSnapshotInfo time.Duration DurationSnapshotMilestoneIndexChanged time.Duration DurationHeader time.Duration DurationSolidEntryPoints time.Duration DurationOutputs time.Duration DurationMilestoneDiffs time.Duration DurationTotal time.Duration }
SnapshotMetrics holds metrics about a snapshot creation run.
func StreamSnapshotDataTo ¶
func StreamSnapshotDataTo(writeSeeker io.WriteSeeker, timestamp uint64, header *FileHeader, sepProd SEPProducerFunc, outputProd OutputProducerFunc, msDiffProd MilestoneDiffProducerFunc) (error, *SnapshotMetrics)
StreamSnapshotDataTo streams a snapshot data into the given io.WriteSeeker. FileHeader.Type is used to determine whether to write a full or delta snapshot. If the type of the snapshot is Full, then OutputProducerFunc must be provided.
type Spent ¶
type Spent struct { Output // The transaction ID the funds were spent with. TargetTransactionID [iotago.TransactionIDLength]byte `json:"target_transaction_id"` }
Spent defines a spent within a snapshot.
func (*Spent) MarshalBinary ¶
type Type ¶
type Type byte
Type defines the type of the snapshot.
const ( // Full is a snapshot which contains the full ledger entry for a given milestone // plus the milestone diffs which subtracted to the ledger milestone reduce to the snapshot milestone ledger. Full Type = iota // Delta is a snapshot which contains solely diffs of milestones newer than a certain ledger milestone // instead of the complete ledger state of a given milestone. Delta )
type UnspentTreasuryOutputConsumerFunc ¶
type UnspentTreasuryOutputConsumerFunc func(output *utxo.TreasuryOutput) error
UnspentTreasuryOutputConsumerFunc consumes the given treasury output. A returned error signals to cancel further reading.
type WriteCounter ¶
type WriteCounter struct { Expected uint64 // contains filtered or unexported fields }
WriteCounter counts the number of bytes written to it. It implements to the io.Writer interface and we can pass this into io.TeeReader() which will report progress on each write cycle.
func NewWriteCounter ¶
func NewWriteCounter(shutdownCtx context.Context, expected uint64) *WriteCounter
NewWriteCounter creates a new WriteCounter.
func (*WriteCounter) PrintProgress ¶
func (wc *WriteCounter) PrintProgress()
PrintProgress prints the current progress.