trie

package
v1.4.10 Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2023 License: GPL-3.0 Imports: 34 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidLengthNode        = fmt.Errorf("proto: negative length found during unmarshaling")
	ErrIntOverflowNode          = fmt.Errorf("proto: integer overflow")
	ErrUnexpectedEndOfGroupNode = fmt.Errorf("proto: unexpected end of group")
)
View Source
var ErrChildPosOutOfRange = errors.New("the position of the child is out of range")

ErrChildPosOutOfRange is raised when the position of a child in a branch node is less than 0 or greater than 16

View Source
var ErrEmptyBranchNode = errors.New("the branch node is empty")

ErrEmptyBranchNode is raised when we reach an empty branch node (a node with no children)

View Source
var ErrEmptyExtensionNode = errors.New("the extension node is empty")

ErrEmptyExtensionNode is raised when we reach an empty extension node (a node with no child)

View Source
var ErrEmptyLeafNode = errors.New("the leaf node is empty")

ErrEmptyLeafNode is raised when we reach an empty leaf node (a node with no value)

View Source
var ErrInvalidEncoding = errors.New("cannot decode this invalid encoding")

ErrInvalidEncoding is raised when the encoded information cannot be decoded

View Source
var ErrInvalidLevelValue = errors.New("invalid trie level in memory value")

ErrInvalidLevelValue signals that the given value for maxTrieLevelInMemory is invalid

View Source
var ErrInvalidMaxHardCapForMissingNodes = errors.New("invalid max hardcap for missing nodes")

ErrInvalidMaxHardCapForMissingNodes signals that the maximum hardcap value for missing nodes is invalid

View Source
var ErrInvalidNode = errors.New("invalid node")

ErrInvalidNode is raised when we reach an invalid node

View Source
var ErrInvalidTrieSyncerVersion = errors.New("invalid trie syncer version")

ErrInvalidTrieSyncerVersion signals that an invalid trie syncer version was provided

View Source
var ErrInvalidTrieTopic = errors.New("invalid trie topic")

ErrInvalidTrieTopic signals that invalid trie topic has been provided

View Source
var ErrKeyNotFound = errors.New("key not found")

ErrKeyNotFound is raised when a key is not found

View Source
var ErrNilBranchNode = errors.New("the branch node is nil")

ErrNilBranchNode is raised when we reach a nil branch node

View Source
var ErrNilCheckpointHashesHolder = errors.New("nil checkpoint hashes holder")

ErrNilCheckpointHashesHolder signals that a nil checkpoint hashes holder was provided

View Source
var ErrNilContext = errors.New("nil context")

ErrNilContext signals that nil context has been provided

View Source
var ErrNilDatabase = errors.New("no database provided")

ErrNilDatabase is raised when a database operation is called, but no database is provided

View Source
var ErrNilExtensionNode = errors.New("the extension node is nil")

ErrNilExtensionNode is raised when we reach a nil extension node

View Source
var ErrNilHasher = errors.New("no hasher provided")

ErrNilHasher is raised when the NewTrie() function is called, but a hasher isn't provided

View Source
var ErrNilIdleNodeProvider = errors.New("nil idle node provider")

ErrNilIdleNodeProvider signals that a nil idle node provider was provided

View Source
var ErrNilLeafNode = errors.New("the leaf node is nil")

ErrNilLeafNode is raised when we reach a nil leaf node

View Source
var ErrNilMarshalizer = errors.New("no marshalizer provided")

ErrNilMarshalizer is raised when the NewTrie() function is called, but a marshalizer isn't provided

View Source
var ErrNilNode = errors.New("the node is nil")

ErrNilNode is raised when we reach a nil node

View Source
var ErrNilPathManager = errors.New("nil path manager")

ErrNilPathManager signals that a nil path manager has been provided

View Source
var ErrNilRequestHandler = errors.New("the request handler is nil")

ErrNilRequestHandler is raised when the given request handler is nil

View Source
var ErrNilRootHashHolder = errors.New("nil root hash holder provided")

ErrNilRootHashHolder signals that a nil root hash holder was provided

View Source
var ErrNilStorer = errors.New("nil storer")

ErrNilStorer is raised when a nil storer has been provided

View Source
var ErrNilTimeoutHandler = errors.New("nil timeout handler")

ErrNilTimeoutHandler signals that a nil timeout handler has been provided

View Source
var ErrNilTrie = errors.New("the trie is nil")

ErrNilTrie is raised when the trie is nil

View Source
var ErrNilTrieIteratorChannels = errors.New("nil trie iterator channels")

ErrNilTrieIteratorChannels signals that nil trie iterator channels has been provided

View Source
var ErrNilTrieIteratorErrChannel = errors.New("nil trie iterator error channel")

ErrNilTrieIteratorErrChannel signals that a nil trie iterator error channel has been provided

View Source
var ErrNilTrieIteratorLeavesChannel = errors.New("nil trie iterator leaves channel")

ErrNilTrieIteratorLeavesChannel signals that a nil trie iterator leaves channel has been provided

View Source
var ErrNilTrieStorage = errors.New("nil trie storage provided")

ErrNilTrieStorage is raised when a nil trie storage is provided

View Source
var ErrNilTrieSyncStatistics = errors.New("nil trie sync statistics handler")

ErrNilTrieSyncStatistics signals that a nil trie sync statistics handler was provided

View Source
var ErrNodeNotFound = errors.New("the node is not present in the trie")

ErrNodeNotFound is raised when we try to get a node that is not present in the trie

View Source
var ErrTimeIsOut = errors.New("time is out")

ErrTimeIsOut signals that time is out

View Source
var ErrTrieSyncTimeout = errors.New("trie sync timeout")

ErrTrieSyncTimeout signals that a timeout occurred while syncing the trie

View Source
var ErrValueTooShort = errors.New("cannot remove bytes from value because value is too short")

ErrValueTooShort is raised when we try to remove something from a value, and the value is too short

View Source
var ErrWrongTypeAssertion = errors.New("wrong type assertion")

ErrWrongTypeAssertion signals that wrong type was provided

Functions

func CheckTrieSyncerVersion

func CheckTrieSyncerVersion(trieSyncerVersion int) error

CheckTrieSyncerVersion can check if the syncer version has a correct value

func CreateTrieStorageManager

func CreateTrieStorageManager(
	args NewTrieStorageManagerArgs,
	options StorageManagerOptions,
) (common.StorageManager, error)

CreateTrieStorageManager creates a new trie storage manager based on the given type

func NewDepthFirstTrieSyncer

func NewDepthFirstTrieSyncer(arg ArgTrieSyncer) (*depthFirstTrieSyncer, error)

NewDepthFirstTrieSyncer creates a new instance of trieSyncer that uses the depth-first algorithm

func NewDoubleListTrieSyncer

func NewDoubleListTrieSyncer(arg ArgTrieSyncer) (*doubleListTrieSyncer, error)

NewDoubleListTrieSyncer creates a new instance of trieSyncer that uses 2 list for keeping the "margin" nodes. One is used for keeping track of the loaded nodes (their children will need to be checked) and the other one that holds missing nodes

func NewIterator

func NewIterator(trie common.Trie) (*iterator, error)

NewIterator creates a new instance of trie iterator

func NewMerkleProofVerifier

func NewMerkleProofVerifier(marshalizer marshal.Marshalizer, hasher hashing.Hasher) (*merkleProofVerifier, error)

NewMerkleProofVerifier creates a new instance of merkleProofVerifier

func NewSyncTrieStorageManager

func NewSyncTrieStorageManager(tsm common.StorageManager) (*syncTrieStorageManager, error)

NewSyncTrieStorageManager creates a new instance of syncTrieStorageManager

func NewTrie

func NewTrie(
	trieStorage common.StorageManager,
	msh marshal.Marshalizer,
	hsh hashing.Hasher,
	maxTrieLevelInMemory uint,
) (*patriciaMerkleTrie, error)

NewTrie creates a new Patricia Merkle Trie

func NewTrieStorageManager

func NewTrieStorageManager(args NewTrieStorageManagerArgs) (*trieStorageManager, error)

NewTrieStorageManager creates a new instance of trieStorageManager

func NewTrieStorageManagerWithoutCheckpoints

func NewTrieStorageManagerWithoutCheckpoints(tsm common.StorageManager) (*trieStorageManagerWithoutCheckpoints, error)

NewTrieStorageManagerWithoutCheckpoints creates a new instance of trieStorageManagerWithoutCheckpoints

func NewTrieStorageManagerWithoutPruning

func NewTrieStorageManagerWithoutPruning(sm common.StorageManager) (*trieStorageManagerWithoutPruning, error)

NewTrieStorageManagerWithoutPruning creates a new instance of trieStorageManagerWithoutPruning

func NewTrieStorageManagerWithoutSnapshot

func NewTrieStorageManagerWithoutSnapshot(tsm common.StorageManager) (*trieStorageManagerWithoutSnapshot, error)

NewTrieStorageManagerWithoutSnapshot creates a new trieStorageManagerWithoutSnapshot

func NewTrieSyncer

func NewTrieSyncer(arg ArgTrieSyncer) (*trieSyncer, error)

NewTrieSyncer creates a new instance of trieSyncer

Types

type ArgTrieSyncer

type ArgTrieSyncer struct {
	Marshalizer               marshal.Marshalizer
	Hasher                    hashing.Hasher
	DB                        common.StorageManager
	RequestHandler            RequestHandler
	InterceptedNodes          storage.Cacher
	ShardId                   uint32
	Topic                     string
	TrieSyncStatistics        common.SizeSyncStatisticsHandler
	MaxHardCapForMissingNodes int
	CheckNodesOnDisk          bool
	TimeoutHandler            TimeoutHandler
}

ArgTrieSyncer is the argument for the trie syncer

type CheckpointHashesHolder

type CheckpointHashesHolder interface {
	Put(rootHash []byte, hashes common.ModifiedHashes) bool
	RemoveCommitted(lastCommittedRootHash []byte)
	Remove(hash []byte)
	ShouldCommit(hash []byte) bool
	IsInterfaceNil() bool
}

CheckpointHashesHolder is used to hold the hashes that need to be committed in the future state checkpoint

type CollapsedBn

type CollapsedBn struct {
	EncodedChildren [][]byte `protobuf:"bytes,1,rep,name=EncodedChildren,proto3" json:"EncodedChildren,omitempty"`
}

func (*CollapsedBn) Descriptor

func (*CollapsedBn) Descriptor() ([]byte, []int)

func (*CollapsedBn) Equal

func (this *CollapsedBn) Equal(that interface{}) bool

func (*CollapsedBn) GetEncodedChildren

func (m *CollapsedBn) GetEncodedChildren() [][]byte

func (*CollapsedBn) GoString

func (this *CollapsedBn) GoString() string

func (*CollapsedBn) Marshal

func (m *CollapsedBn) Marshal() (dAtA []byte, err error)

func (*CollapsedBn) MarshalTo

func (m *CollapsedBn) MarshalTo(dAtA []byte) (int, error)

func (*CollapsedBn) MarshalToSizedBuffer

func (m *CollapsedBn) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*CollapsedBn) ProtoMessage

func (*CollapsedBn) ProtoMessage()

func (*CollapsedBn) Reset

func (m *CollapsedBn) Reset()

func (*CollapsedBn) Size

func (m *CollapsedBn) Size() (n int)

func (*CollapsedBn) String

func (this *CollapsedBn) String() string

func (*CollapsedBn) Unmarshal

func (m *CollapsedBn) Unmarshal(dAtA []byte) error

func (*CollapsedBn) XXX_DiscardUnknown

func (m *CollapsedBn) XXX_DiscardUnknown()

func (*CollapsedBn) XXX_Marshal

func (m *CollapsedBn) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*CollapsedBn) XXX_Merge

func (m *CollapsedBn) XXX_Merge(src proto.Message)

func (*CollapsedBn) XXX_Size

func (m *CollapsedBn) XXX_Size() int

func (*CollapsedBn) XXX_Unmarshal

func (m *CollapsedBn) XXX_Unmarshal(b []byte) error

type CollapsedEn

type CollapsedEn struct {
	Key          []byte `protobuf:"bytes,1,opt,name=Key,proto3" json:"Key,omitempty"`
	EncodedChild []byte `protobuf:"bytes,2,opt,name=EncodedChild,proto3" json:"EncodedChild,omitempty"`
}

func (*CollapsedEn) Descriptor

func (*CollapsedEn) Descriptor() ([]byte, []int)

func (*CollapsedEn) Equal

func (this *CollapsedEn) Equal(that interface{}) bool

func (*CollapsedEn) GetEncodedChild

func (m *CollapsedEn) GetEncodedChild() []byte

func (*CollapsedEn) GetKey

func (m *CollapsedEn) GetKey() []byte

func (*CollapsedEn) GoString

func (this *CollapsedEn) GoString() string

func (*CollapsedEn) Marshal

func (m *CollapsedEn) Marshal() (dAtA []byte, err error)

func (*CollapsedEn) MarshalTo

func (m *CollapsedEn) MarshalTo(dAtA []byte) (int, error)

func (*CollapsedEn) MarshalToSizedBuffer

func (m *CollapsedEn) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*CollapsedEn) ProtoMessage

func (*CollapsedEn) ProtoMessage()

func (*CollapsedEn) Reset

func (m *CollapsedEn) Reset()

func (*CollapsedEn) Size

func (m *CollapsedEn) Size() (n int)

func (*CollapsedEn) String

func (this *CollapsedEn) String() string

func (*CollapsedEn) Unmarshal

func (m *CollapsedEn) Unmarshal(dAtA []byte) error

func (*CollapsedEn) XXX_DiscardUnknown

func (m *CollapsedEn) XXX_DiscardUnknown()

func (*CollapsedEn) XXX_Marshal

func (m *CollapsedEn) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*CollapsedEn) XXX_Merge

func (m *CollapsedEn) XXX_Merge(src proto.Message)

func (*CollapsedEn) XXX_Size

func (m *CollapsedEn) XXX_Size() int

func (*CollapsedEn) XXX_Unmarshal

func (m *CollapsedEn) XXX_Unmarshal(b []byte) error

type CollapsedLn

type CollapsedLn struct {
	Key   []byte `protobuf:"bytes,1,opt,name=Key,proto3" json:"Key,omitempty"`
	Value []byte `protobuf:"bytes,2,opt,name=Value,proto3" json:"Value,omitempty"`
}

func (*CollapsedLn) Descriptor

func (*CollapsedLn) Descriptor() ([]byte, []int)

func (*CollapsedLn) Equal

func (this *CollapsedLn) Equal(that interface{}) bool

func (*CollapsedLn) GetKey

func (m *CollapsedLn) GetKey() []byte

func (*CollapsedLn) GetValue

func (m *CollapsedLn) GetValue() []byte

func (*CollapsedLn) GoString

func (this *CollapsedLn) GoString() string

func (*CollapsedLn) Marshal

func (m *CollapsedLn) Marshal() (dAtA []byte, err error)

func (*CollapsedLn) MarshalTo

func (m *CollapsedLn) MarshalTo(dAtA []byte) (int, error)

func (*CollapsedLn) MarshalToSizedBuffer

func (m *CollapsedLn) MarshalToSizedBuffer(dAtA []byte) (int, error)

func (*CollapsedLn) ProtoMessage

func (*CollapsedLn) ProtoMessage()

func (*CollapsedLn) Reset

func (m *CollapsedLn) Reset()

func (*CollapsedLn) Size

func (m *CollapsedLn) Size() (n int)

func (*CollapsedLn) String

func (this *CollapsedLn) String() string

func (*CollapsedLn) Unmarshal

func (m *CollapsedLn) Unmarshal(dAtA []byte) error

func (*CollapsedLn) XXX_DiscardUnknown

func (m *CollapsedLn) XXX_DiscardUnknown()

func (*CollapsedLn) XXX_Marshal

func (m *CollapsedLn) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)

func (*CollapsedLn) XXX_Merge

func (m *CollapsedLn) XXX_Merge(src proto.Message)

func (*CollapsedLn) XXX_Size

func (m *CollapsedLn) XXX_Size() int

func (*CollapsedLn) XXX_Unmarshal

func (m *CollapsedLn) XXX_Unmarshal(b []byte) error

type EpochNotifier

type EpochNotifier interface {
	RegisterNotifyHandler(handler vmcommon.EpochSubscriberHandler)
	IsInterfaceNil() bool
}

EpochNotifier can notify upon an epoch change and provide the current epoch

type IdleNodeProvider

type IdleNodeProvider interface {
	IsIdle() bool
	IsInterfaceNil() bool
}

IdleNodeProvider can determine if the node is idle or not

type InterceptedTrieNode

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

InterceptedTrieNode implements intercepted data interface and is used when trie nodes are intercepted

func NewInterceptedTrieNode

func NewInterceptedTrieNode(
	buff []byte,
	hasher hashing.Hasher,
) (*InterceptedTrieNode, error)

NewInterceptedTrieNode creates a new instance of InterceptedTrieNode

func (*InterceptedTrieNode) CheckValidity

func (inTn *InterceptedTrieNode) CheckValidity() error

CheckValidity checks if the intercepted data is valid

func (*InterceptedTrieNode) Fee

func (inTn *InterceptedTrieNode) Fee() *big.Int

Fee returns big.NewInt(0)

func (*InterceptedTrieNode) GetSerialized

func (inTn *InterceptedTrieNode) GetSerialized() []byte

GetSerialized returns the intercepted encoded node

func (*InterceptedTrieNode) Hash

func (inTn *InterceptedTrieNode) Hash() []byte

Hash returns the hash of the intercepted node

func (*InterceptedTrieNode) Identifiers

func (inTn *InterceptedTrieNode) Identifiers() [][]byte

Identifiers returns the identifiers used in requests

func (*InterceptedTrieNode) IsForCurrentShard

func (inTn *InterceptedTrieNode) IsForCurrentShard() bool

IsForCurrentShard checks if the intercepted data is for the current shard

func (*InterceptedTrieNode) IsInterfaceNil

func (inTn *InterceptedTrieNode) IsInterfaceNil() bool

IsInterfaceNil returns true if there is no value under the interface

func (*InterceptedTrieNode) Nonce

func (inTn *InterceptedTrieNode) Nonce() uint64

Nonce return 0

func (*InterceptedTrieNode) ReceiverShardId

func (inTn *InterceptedTrieNode) ReceiverShardId() uint32

ReceiverShardId returns 0

func (*InterceptedTrieNode) SenderAddress

func (inTn *InterceptedTrieNode) SenderAddress() []byte

SenderAddress returns nil

func (*InterceptedTrieNode) SenderShardId

func (inTn *InterceptedTrieNode) SenderShardId() uint32

SenderShardId returns 0

func (*InterceptedTrieNode) SetSerialized

func (inTn *InterceptedTrieNode) SetSerialized(serializedNode []byte)

SetSerialized sets the given bytes as the SerializedNode

func (*InterceptedTrieNode) SizeInBytes

func (inTn *InterceptedTrieNode) SizeInBytes() int

SizeInBytes returns the size in bytes held by this instance plus the inner node's instance size

func (*InterceptedTrieNode) String

func (inTn *InterceptedTrieNode) String() string

String returns the trie node's most important fields as string

func (*InterceptedTrieNode) Type

func (inTn *InterceptedTrieNode) Type() string

Type returns the type of this intercepted data

type NewTrieStorageManagerArgs

type NewTrieStorageManagerArgs struct {
	MainStorer             common.DBWriteCacher
	CheckpointsStorer      common.DBWriteCacher
	Marshalizer            marshal.Marshalizer
	Hasher                 hashing.Hasher
	GeneralConfig          config.TrieStorageManagerConfig
	CheckpointHashesHolder CheckpointHashesHolder
	IdleProvider           IdleNodeProvider
}

NewTrieStorageManagerArgs holds the arguments needed for creating a new trieStorageManager

type RequestHandler

type RequestHandler interface {
	RequestTrieNodes(destShardID uint32, hashes [][]byte, topic string)
	RequestInterval() time.Duration
	IsInterfaceNil() bool
}

RequestHandler defines the methods through which request to data can be made

type StorageManagerOptions

type StorageManagerOptions struct {
	PruningEnabled     bool
	SnapshotsEnabled   bool
	CheckpointsEnabled bool
}

StorageManagerOptions specify the options that a trie storage manager can have

type StorageMarker

type StorageMarker interface {
	MarkStorerAsSyncedAndActive(storer common.StorageManager)
}

StorageMarker is used to mark the given storer as synced and active

type TimeoutHandler

type TimeoutHandler interface {
	ResetWatchdog()
	IsTimeout() bool
	IsInterfaceNil() bool
}

TimeoutHandler is able to tell if a timeout has occurred

type TrieSyncer

type TrieSyncer interface {
	StartSyncing(rootHash []byte, ctx context.Context) error
	NumLeaves() uint64
	NumBytes() uint64
	NumTrieNodes() uint64
	Duration() time.Duration
	IsInterfaceNil() bool
}

TrieSyncer synchronizes the trie, asking on the network for the missing nodes

func CreateTrieSyncer

func CreateTrieSyncer(arg ArgTrieSyncer, trieSyncerVersion int) (TrieSyncer, error)

CreateTrieSyncer is the method factory to create the correct trie syncer implementation TODO try to split this package (syncers should go in sync package, this file in the factory package)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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