notarization

package
v0.9.8 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2022 License: Apache-2.0, BSD-2-Clause Imports: 30 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// TestConflictAcceptanceStateTranslation translates a conflict's AW into a confirmation state.
	TestConflictAcceptanceStateTranslation acceptance.ConflictThresholdTranslation = func(_ utxo.TransactionID, aw float64) confirmation.State {
		if aw >= testingAcceptanceThreshold {
			return confirmation.Accepted
		}

		return confirmation.Pending
	}

	// TestBlockAcceptanceStateTranslation translates a block's AW into a confirmation state.
	TestBlockAcceptanceStateTranslation acceptance.BlockThresholdTranslation = func(aw float64) confirmation.State {
		if aw >= testingAcceptanceThreshold {
			return confirmation.Accepted
		}

		return confirmation.Pending
	}
)

Functions

This section is empty.

Types

type ActivityTreeUpdatedEvent added in v0.9.5

type ActivityTreeUpdatedEvent struct {
	// EI is the index of the epoch.
	EI epoch.Index
	// NodeID is the issuer nodeID.
	NodeID identity.ID
}

ActivityTreeUpdatedEvent is a container that acts as a dictionary for the ActivityTree inserted/removed event related parameters.

type BootstrappedEvent

type BootstrappedEvent struct {
	// EI is the index of the last commitable epoch
	EI epoch.Index
}

BootstrappedEvent is an event that gets triggered when a notarization manager has the last committable epoch relatively close to current epoch.

type CommitmentProof

type CommitmentProof struct {
	EI epoch.Index
	// contains filtered or unexported fields
}

CommitmentProof represents an inclusion proof for a specific epoch.

type CommitmentRoots

type CommitmentRoots struct {
	EI epoch.Index
	// contains filtered or unexported fields
}

CommitmentRoots contains roots of trees of an epoch.

type CommitmentTrees

type CommitmentTrees struct {
	EI epoch.Index
	// contains filtered or unexported fields
}

CommitmentTrees is a compressed form of all the information (blocks and confirmed value payloads) of an epoch.

type CompetingCommitmentDetectedEvent added in v0.9.5

type CompetingCommitmentDetectedEvent struct {
	// Block is the block that contains the competing commitment.
	Block *tangleold.Block
}

CompetingCommitmentDetectedEvent is a container that acts as a dictionary for the CompetingCommitmentDetectedEvent event related parameters.

type EpochCommitmentFactory

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

EpochCommitmentFactory manages epoch commitmentTrees.

func NewEpochCommitmentFactory

func NewEpochCommitmentFactory(store kvstore.KVStore, tangle *tangleold.Tangle, snapshotDepth int) *EpochCommitmentFactory

NewEpochCommitmentFactory returns a new commitment factory.

func (*EpochCommitmentFactory) ECRandRoots added in v0.9.5

func (f *EpochCommitmentFactory) ECRandRoots(ei epoch.Index) (ecr epoch.ECR, roots *epoch.CommitmentRoots, err error)

ECRandRoots retrieves the epoch commitment root.

func (*EpochCommitmentFactory) ManaRoot

func (f *EpochCommitmentFactory) ManaRoot() []byte

ManaRoot returns the root of the state sparse merkle tree at the latest committed epoch.

func (*EpochCommitmentFactory) ProofStateMutationRoot

func (f *EpochCommitmentFactory) ProofStateMutationRoot(ei epoch.Index, txID utxo.TransactionID) (*CommitmentProof, error)

ProofStateMutationRoot returns the merkle proof for the transactionID against the state mutation root.

func (*EpochCommitmentFactory) ProofStateRoot

func (f *EpochCommitmentFactory) ProofStateRoot(ei epoch.Index, outID utxo.OutputID) (*CommitmentProof, error)

ProofStateRoot returns the merkle proof for the outputID against the state root.

func (*EpochCommitmentFactory) ProofTangleRoot

func (f *EpochCommitmentFactory) ProofTangleRoot(ei epoch.Index, blockID tangleold.BlockID) (*CommitmentProof, error)

ProofTangleRoot returns the merkle proof for the blockID against the tangle root.

func (*EpochCommitmentFactory) StateRoot

func (f *EpochCommitmentFactory) StateRoot() []byte

StateRoot returns the root of the state sparse merkle tree at the latest committed epoch.

func (*EpochCommitmentFactory) VerifyStateMutationRoot

func (f *EpochCommitmentFactory) VerifyStateMutationRoot(proof CommitmentProof, transactionID utxo.TransactionID) bool

VerifyStateMutationRoot verify the provided merkle proof against the state mutation root.

func (*EpochCommitmentFactory) VerifyTangleRoot

func (f *EpochCommitmentFactory) VerifyTangleRoot(proof CommitmentProof, blockID tangleold.BlockID) bool

VerifyTangleRoot verify the provided merkle proof against the tangle root.

type EpochCommitmentStorage

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

EpochCommitmentStorage is a Ledger component that bundles the storage related API.

func (*EpochCommitmentStorage) CachedECRecord

func (s *EpochCommitmentStorage) CachedECRecord(ei epoch.Index, computeIfAbsentCallback ...func(ei epoch.Index) *epoch.ECRecord) (cachedEpochDiff *objectstorage.CachedObject[*epoch.ECRecord])

CachedECRecord retrieves cached ECRecord of the given EI. (Make sure to Release or Consume the return object.)

type EpochCommittableEvent

type EpochCommittableEvent struct {
	// EI is the index of committable epoch.
	EI epoch.Index
	// ECRecord is the ec root of committable epoch.
	ECRecord *epoch.ECRecord
}

EpochCommittableEvent is a container that acts as a dictionary for the EpochCommittable event related parameters.

type EpochConfirmedEvent added in v0.9.5

type EpochConfirmedEvent struct {
	// EI is the index of committable epoch.
	EI epoch.Index
}

EpochConfirmedEvent is a container that acts as a dictionary for the EpochConfirmed event related parameters.

type EventMock

type EventMock struct {
	mock.Mock
	// contains filtered or unexported fields
}

EventMock acts as a container for event mocks.

func NewEventMock

func NewEventMock(t *testing.T, notarizationManager *Manager) *EventMock

NewEventMock creates a new EventMock.

func (*EventMock) AssertExpectations

func (e *EventMock) AssertExpectations(t mock.TestingT) bool

AssertExpectations asserts expectations.

func (*EventMock) DetachAll

func (e *EventMock) DetachAll()

DetachAll detaches all event handlers.

func (*EventMock) EpochCommittable

func (e *EventMock) EpochCommittable(event *EpochCommittableEvent)

EpochCommittable is the mocked EpochCommittable event.

func (*EventMock) Expect

func (e *EventMock) Expect(eventName string, arguments ...interface{})

Expect is a proxy for Mock.On() but keeping track of num of calls.

func (*EventMock) ManaVectorUpdate

func (e *EventMock) ManaVectorUpdate(event *mana.ManaVectorUpdateEvent)

ManaVectorUpdate is the mocked ManaVectorUpdate event.

type Events

type Events struct {
	// EpochCommittable is an event that gets triggered whenever an epoch commitment is committable.
	EpochCommittable *event.Event[*EpochCommittableEvent]
	// EpochConfirmed is an event that gets triggered whenever an epoch is confirmed.
	EpochConfirmed *event.Event[*EpochConfirmedEvent]
	// CompetingCommitmentDetected is an event that gets triggered whenever a competing epoch commitment is detected.
	CompetingCommitmentDetected *event.Event[*CompetingCommitmentDetectedEvent]
	// ManaVectorUpdate is an event that gets triggered whenever the consensus mana vector needs to be updated.
	ManaVectorUpdate *event.Event[*mana.ManaVectorUpdateEvent]
	// TangleTreeInserted is an event that gets triggered when a Block is inserted into the Tangle smt.
	TangleTreeInserted *event.Event[*TangleTreeUpdatedEvent]
	// TangleTreeRemoved is an event that gets triggered when a Block is removed from Tangle smt.
	TangleTreeRemoved *event.Event[*TangleTreeUpdatedEvent]
	// StateMutationTreeInserted is an event that gets triggered when a transaction is inserted into the state mutation smt.
	StateMutationTreeInserted *event.Event[*StateMutationTreeUpdatedEvent]
	// StateMutationTreeRemoved is an event that gets triggered when a transaction is removed from state mutation smt.
	StateMutationTreeRemoved *event.Event[*StateMutationTreeUpdatedEvent]
	// UTXOTreeInserted is an event that gets triggered when UTXOs are stored into the UTXO smt.
	UTXOTreeInserted *event.Event[*UTXOUpdatedEvent]
	// UTXOTreeRemoved is an event that gets triggered when UTXOs are removed from the UTXO smt.
	UTXOTreeRemoved *event.Event[*UTXOUpdatedEvent]
	// Bootstrapped is an event that gets triggered when a notarization manager has the last committable epoch relatively close to current epoch.
	Bootstrapped *event.Event[*BootstrappedEvent]
	// SyncRange is an event that gets triggered when an entire range of epochs needs to be requested, validated and solidified
	SyncRange *event.Event[*SyncRangeEvent]
	// ActivityTreeInserted is an event that gets triggered when nodeID is added to the activity tree.
	ActivityTreeInserted *event.Event[*ActivityTreeUpdatedEvent]
	// ActivityTreeRemoved is an event that gets triggered when nodeID is removed from activity tree.
	ActivityTreeRemoved *event.Event[*ActivityTreeUpdatedEvent]
}

Events is a container that acts as a dictionary for the existing events of a notarization manager.

type Manager

type Manager struct {
	Events *Events
	// contains filtered or unexported fields
}

Manager is the notarization manager.

func NewManager

func NewManager(epochCommitmentFactory *EpochCommitmentFactory, t *tangleold.Tangle, opts ...ManagerOption) (new *Manager)

NewManager creates and returns a new notarization manager.

func (*Manager) Bootstrapped

func (m *Manager) Bootstrapped() bool

Bootstrapped returns the current value of pendingConflictsCount per epoch.

func (*Manager) EndSnapshot added in v0.9.5

func (m *Manager) EndSnapshot()

EndSnapshot unlocks the commitment factory when the snapshotting completes.

func (*Manager) GetBlockInclusionProof

func (m *Manager) GetBlockInclusionProof(blockID tangleold.BlockID) (*CommitmentProof, error)

GetBlockInclusionProof gets the proof of the inclusion (acceptance) of a block.

func (*Manager) GetLatestEC

func (m *Manager) GetLatestEC() (ecRecord *epoch.ECRecord, err error)

GetLatestEC returns the latest commitment that a new block should commit to.

func (*Manager) GetTransactionInclusionProof

func (m *Manager) GetTransactionInclusionProof(transactionID utxo.TransactionID) (*CommitmentProof, error)

GetTransactionInclusionProof gets the proof of the inclusion (acceptance) of a transaction.

func (*Manager) LatestConfirmedEpochIndex

func (m *Manager) LatestConfirmedEpochIndex() (epoch.Index, error)

LatestConfirmedEpochIndex returns the latest epoch index that has been confirmed.

func (*Manager) LoadActivityLogs added in v0.9.5

func (m *Manager) LoadActivityLogs(epochActivity epoch.SnapshotEpochActivity)

LoadActivityLogs loads activity logs from the snapshot and updates the activity tree.

func (*Manager) LoadECandEIs

func (m *Manager) LoadECandEIs(header *ledger.SnapshotHeader)

LoadECandEIs initiates the ECRecord, latest committable EI, last confirmed EI and acceptance EI from a given snapshot.

func (*Manager) LoadEpochDiff added in v0.9.5

func (m *Manager) LoadEpochDiff(epochDiff *ledger.EpochDiff)

LoadEpochDiff loads an epoch diff.

func (*Manager) LoadOutputsWithMetadata

func (m *Manager) LoadOutputsWithMetadata(outputsWithMetadatas []*ledger.OutputWithMetadata)

LoadOutputsWithMetadata initiates the state and mana trees from a given snapshot.

func (*Manager) OnAcceptanceTimeUpdated

func (m *Manager) OnAcceptanceTimeUpdated(newTime time.Time)

OnAcceptanceTimeUpdated is the handler for time updated event and triggers the events.

func (*Manager) OnBlockAccepted

func (m *Manager) OnBlockAccepted(block *tangleold.Block)

OnBlockAccepted is the handler for block confirmed event.

func (*Manager) OnBlockOrphaned

func (m *Manager) OnBlockOrphaned(block *tangleold.Block)

OnBlockOrphaned is the handler for block orphaned event.

func (*Manager) OnBlockStored added in v0.9.5

func (m *Manager) OnBlockStored(block *tangleold.Block)

OnBlockStored is a handler fo Block stored event that updates the activity log and triggers warpsyncing.

func (*Manager) OnConflictAccepted

func (m *Manager) OnConflictAccepted(conflictID utxo.TransactionID)

OnConflictAccepted is the handler for conflict confirmed event.

func (*Manager) OnConflictCreated

func (m *Manager) OnConflictCreated(conflictID utxo.TransactionID)

OnConflictCreated is the handler for conflict created event.

func (*Manager) OnConflictRejected

func (m *Manager) OnConflictRejected(conflictID utxo.TransactionID)

OnConflictRejected is the handler for conflict created event.

func (*Manager) OnTransactionAccepted

func (m *Manager) OnTransactionAccepted(event *ledger.TransactionAcceptedEvent)

OnTransactionAccepted is the handler for transaction accepted event.

func (*Manager) OnTransactionInclusionUpdated

func (m *Manager) OnTransactionInclusionUpdated(event *ledger.TransactionInclusionUpdatedEvent)

OnTransactionInclusionUpdated is the handler for transaction inclusion updated event.

func (*Manager) PendingConflictsCountAll

func (m *Manager) PendingConflictsCountAll() (pendingConflicts map[epoch.Index]uint64)

PendingConflictsCountAll returns the current value of pendingConflictsCount per epoch.

func (*Manager) Shutdown

func (m *Manager) Shutdown()

Shutdown shuts down the manager's permanent storagee.

func (*Manager) SnapshotEpochActivity added in v0.9.5

func (m *Manager) SnapshotEpochActivity(epochDiffIndex epoch.Index) (epochActivity epoch.SnapshotEpochActivity, err error)

SnapshotEpochActivity snapshots accepted block counts from activity tree and updates provided SnapshotEpochActivity.

func (*Manager) SnapshotEpochDiffs

func (m *Manager) SnapshotEpochDiffs(fullEpochIndex, latestCommitableEpoch epoch.Index, prodChan chan *ledger.EpochDiff, stopChan chan struct{})

SnapshotEpochDiffs returns the EpochDiffs when a snapshot is created.

func (*Manager) SnapshotLedgerState

func (m *Manager) SnapshotLedgerState(prodChan chan *ledger.OutputWithMetadata, stopChan chan struct{})

SnapshotLedgerState returns the all confirmed OutputsWithMetadata when a snapshot is created.

func (*Manager) StartSnapshot added in v0.9.5

func (m *Manager) StartSnapshot() (fullEpochIndex epoch.Index, ecRecord *epoch.ECRecord, err error)

StartSnapshot locks the commitment factory and returns the latest ecRecord and last confirmed epoch index.

type ManagerOption

type ManagerOption func(options *ManagerOptions)

ManagerOption represents the return type of the optional config parameters of the notarization manager.

func BootstrapWindow

func BootstrapWindow(d time.Duration) ManagerOption

BootstrapWindow specifies when the notarization manager is considered to be bootstrapped.

func Log

func Log(log *logger.Logger) ManagerOption

Log provides the logger.

func ManaEpochDelay added in v0.9.6

func ManaEpochDelay(manaEpochDelay uint) ManagerOption

ManaEpochDelay specifies how many epochs the consensus mana booking is delayed with respect to the latest committable epoch.

func MinCommittableEpochAge

func MinCommittableEpochAge(d time.Duration) ManagerOption

MinCommittableEpochAge specifies how old an epoch has to be for it to be committable.

type ManagerOptions

type ManagerOptions struct {
	MinCommittableEpochAge time.Duration
	BootstrapWindow        time.Duration
	Log                    *logger.Logger
	ManaEpochDelay         uint
}

ManagerOptions is a container of all the config parameters of the notarization manager.

type Option

type Option func(*options)

Option represents the return type of optional parameters that can be handed into the constructor of the EpochStateDiffStorage to configure its behavior.

func WithStore

func WithStore(store kvstore.KVStore) (option Option)

WithStore is an Option for the Ledger that allows to configure which KVStore is supposed to be used to persist data (the default option is to use a MapDB).

type StateMutationTreeUpdatedEvent

type StateMutationTreeUpdatedEvent struct {
	// EI is the index of the transaction.
	EI epoch.Index
	// TransactionID is the transaction ID that inserted/removed to/from the state mutation smt.
	TransactionID utxo.TransactionID
}

StateMutationTreeUpdatedEvent is a container that acts as a dictionary for the State mutation tree inserted/removed event related parameters.

type SyncRangeEvent added in v0.9.5

type SyncRangeEvent struct {
	StartEI   epoch.Index
	EndEI     epoch.Index
	StartEC   epoch.EC
	EndPrevEC epoch.EC
}

SyncRangeEvent is a container that acts as a dictionary for the SyncRange event related parameters.

type TangleTreeUpdatedEvent

type TangleTreeUpdatedEvent struct {
	// EI is the index of the block.
	EI epoch.Index
	// BlockID is the blockID that inserted/removed to/from the tangle smt.
	BlockID tangleold.BlockID
}

TangleTreeUpdatedEvent is a container that acts as a dictionary for the TangleTree inserted/removed event related parameters.

type UTXOUpdatedEvent

type UTXOUpdatedEvent struct {
	// EI is the index of updated UTXO.
	EI epoch.Index
	// Spent are outputs that is spent in a transaction.
	Spent []*ledger.OutputWithMetadata
	// Created are the outputs created in a transaction.
	Created []*ledger.OutputWithMetadata
}

UTXOUpdatedEvent is a container that acts as a dictionary for the UTXO update event related parameters.

Jump to

Keyboard shortcuts

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