Documentation ¶
Overview ¶
Package depositsnapshot implements the EIP-4881 standard for minimal sparse Merkle tree. The format proposed by the EIP allows for the pruning of deposits that are no longer needed to participate fully in consensus. Full EIP-4881 specification can be found here: https://eips.ethereum.org/EIPS/eip-4881
Index ¶
- Constants
- Variables
- type Cache
- func (c *Cache) AllDepositContainers(ctx context.Context) []*ethpb.DepositContainer
- func (c *Cache) AllDeposits(ctx context.Context, untilBlk *big.Int) []*ethpb.Deposit
- func (c *Cache) DepositByPubkey(ctx context.Context, pubKey []byte) (*ethpb.Deposit, *big.Int)
- func (c *Cache) DepositsNumberAndRootAtHeight(ctx context.Context, blockHeight *big.Int) (uint64, [32]byte)
- func (c *Cache) FinalizedDeposits(ctx context.Context) (cache.FinalizedDeposits, error)
- func (c *Cache) InsertDeposit(ctx context.Context, d *ethpb.Deposit, blockNum uint64, index int64, ...) error
- func (c *Cache) InsertDepositContainers(ctx context.Context, ctrs []*ethpb.DepositContainer)
- func (c *Cache) InsertFinalizedDeposits(ctx context.Context, eth1DepositIndex int64, executionHash common.Hash, ...) error
- func (c *Cache) InsertPendingDeposit(ctx context.Context, d *ethpb.Deposit, blockNum uint64, index int64, ...)
- func (c *Cache) NonFinalizedDeposits(ctx context.Context, lastFinalizedIndex int64, untilBlk *big.Int) []*ethpb.Deposit
- func (c *Cache) PendingContainers(ctx context.Context, untilBlk *big.Int) []*ethpb.DepositContainer
- func (c *Cache) PendingDeposits(ctx context.Context, untilBlk *big.Int) []*ethpb.Deposit
- func (c *Cache) PrunePendingDeposits(ctx context.Context, merkleTreeIndex int64)
- func (c *Cache) PruneProofs(ctx context.Context, untilDepositIndex int64) error
- type DepositTree
- func (d *DepositTree) Copy() (*DepositTree, error)
- func (d *DepositTree) Finalize(eth1DepositIndex int64, executionHash common.Hash, executionNumber uint64) error
- func (d *DepositTree) GetSnapshot() (DepositTreeSnapshot, error)
- func (d *DepositTree) HashTreeRoot() ([32]byte, error)
- func (d *DepositTree) Insert(item []byte, _ int) error
- func (d *DepositTree) MerkleProof(index int) ([][]byte, error)
- func (d *DepositTree) NumOfItems() int
- func (d *DepositTree) ToProto() (*protodb.DepositSnapshot, error)
- type DepositTreeSnapshot
- type FinalizedNode
- func (f *FinalizedNode) Finalize(depositsToFinalize uint64, depth uint64) (MerkleTreeNode, error)
- func (f *FinalizedNode) GetFinalized(result [][32]byte) (uint64, [][32]byte)
- func (f *FinalizedNode) GetRoot() [32]byte
- func (_ *FinalizedNode) IsFull() bool
- func (_ *FinalizedNode) Left() MerkleTreeNode
- func (_ *FinalizedNode) PushLeaf(_ [32]byte, _ uint64) (MerkleTreeNode, error)
- func (_ *FinalizedNode) Right() MerkleTreeNode
- type InnerNode
- func (n *InnerNode) Finalize(depositsToFinalize uint64, depth uint64) (MerkleTreeNode, error)
- func (n *InnerNode) GetFinalized(result [][32]byte) (uint64, [][32]byte)
- func (n *InnerNode) GetRoot() [32]byte
- func (n *InnerNode) IsFull() bool
- func (n *InnerNode) Left() MerkleTreeNode
- func (n *InnerNode) PushLeaf(leaf [32]byte, depth uint64) (MerkleTreeNode, error)
- func (n *InnerNode) Right() MerkleTreeNode
- type LeafNode
- func (l *LeafNode) Finalize(depositsToFinalize uint64, depth uint64) (MerkleTreeNode, error)
- func (_ *LeafNode) GetFinalized(result [][32]byte) (uint64, [][32]byte)
- func (l *LeafNode) GetRoot() [32]byte
- func (_ *LeafNode) IsFull() bool
- func (_ *LeafNode) Left() MerkleTreeNode
- func (_ *LeafNode) PushLeaf(_ [32]byte, _ uint64) (MerkleTreeNode, error)
- func (_ *LeafNode) Right() MerkleTreeNode
- type MerkleTreeNode
- type PendingDepositsFetcher
- type ZeroNode
- func (_ *ZeroNode) Finalize(depositsToFinalize uint64, depth uint64) (MerkleTreeNode, error)
- func (_ *ZeroNode) GetFinalized(result [][32]byte) (uint64, [][32]byte)
- func (z *ZeroNode) GetRoot() [32]byte
- func (_ *ZeroNode) IsFull() bool
- func (_ *ZeroNode) Left() MerkleTreeNode
- func (_ *ZeroNode) PushLeaf(leaf [32]byte, depth uint64) (MerkleTreeNode, error)
- func (_ *ZeroNode) Right() MerkleTreeNode
Constants ¶
const (
// DepositContractDepth is the maximum tree depth as defined by EIP-4881.
DepositContractDepth = 32
)
Variables ¶
var ( // ErrInvalidSnapshotRoot occurs when the snapshot root does not match the calculated root. ErrInvalidSnapshotRoot = errors.New("snapshot root is invalid") // ErrInvalidDepositCount occurs when the value for mix in length is 0. ErrInvalidDepositCount = errors.New("deposit count should be greater than 0") // ErrInvalidIndex occurs when the index is less than the number of finalized deposits. ErrInvalidIndex = errors.New("index should be greater than finalizedDeposits - 1") // ErrTooManyDeposits occurs when the number of deposits exceeds the capacity of the tree. ErrTooManyDeposits = errors.New("number of deposits should not be greater than the capacity of the tree") )
var ( // ErrFinalizedNodeCannotPushLeaf may occur when attempting to push a leaf to a finalized node. When a node is finalized, it cannot be modified or changed. ErrFinalizedNodeCannotPushLeaf = errors.New("can't push a leaf to a finalized node") // ErrLeafNodeCannotPushLeaf may occur when attempting to push a leaf to a leaf node. ErrLeafNodeCannotPushLeaf = errors.New("can't push a leaf to a leaf node") // ErrZeroLevel occurs when the value of level is 0. ErrZeroLevel = errors.New("level should be greater than 0") // ErrZeroDepth occurs when the value of depth is 0. ErrZeroDepth = errors.New("depth should be greater than 0") )
Functions ¶
This section is empty.
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache stores all in-memory deposit objects. This stores all the deposit related data that is required by the beacon-node.
func (*Cache) AllDepositContainers ¶
func (c *Cache) AllDepositContainers(ctx context.Context) []*ethpb.DepositContainer
AllDepositContainers returns all historical deposit containers.
func (*Cache) AllDeposits ¶
AllDeposits returns a list of historical deposits until the given block number (inclusive). If no block is specified then this method returns all historical deposits.
func (*Cache) DepositByPubkey ¶
DepositByPubkey looks through historical deposits and finds one which contains a certain public key within its deposit data.
func (*Cache) DepositsNumberAndRootAtHeight ¶
func (c *Cache) DepositsNumberAndRootAtHeight(ctx context.Context, blockHeight *big.Int) (uint64, [32]byte)
DepositsNumberAndRootAtHeight returns number of deposits made up to blockheight and the root that corresponds to the latest deposit at that blockheight.
func (*Cache) FinalizedDeposits ¶
FinalizedDeposits returns the finalized deposits trie.
func (*Cache) InsertDeposit ¶
func (c *Cache) InsertDeposit(ctx context.Context, d *ethpb.Deposit, blockNum uint64, index int64, depositRoot [32]byte) error
InsertDeposit into the database. If deposit or block number are nil then this method does nothing.
func (*Cache) InsertDepositContainers ¶
func (c *Cache) InsertDepositContainers(ctx context.Context, ctrs []*ethpb.DepositContainer)
InsertDepositContainers inserts a set of deposit containers into our deposit cache.
func (*Cache) InsertFinalizedDeposits ¶
func (c *Cache) InsertFinalizedDeposits(ctx context.Context, eth1DepositIndex int64, executionHash common.Hash, executionNumber uint64) error
InsertFinalizedDeposits inserts deposits up to eth1DepositIndex (inclusive) into the finalized deposits cache.
func (*Cache) InsertPendingDeposit ¶
func (c *Cache) InsertPendingDeposit(ctx context.Context, d *ethpb.Deposit, blockNum uint64, index int64, depositRoot [32]byte)
InsertPendingDeposit into the database. If deposit or block number are nil then this method does nothing.
func (*Cache) NonFinalizedDeposits ¶
func (c *Cache) NonFinalizedDeposits(ctx context.Context, lastFinalizedIndex int64, untilBlk *big.Int) []*ethpb.Deposit
NonFinalizedDeposits returns the list of non-finalized deposits until the given block number (inclusive). If no block is specified then this method returns all non-finalized deposits.
func (*Cache) PendingContainers ¶
PendingContainers returns a list of deposit containers until the given block number (inclusive).
func (*Cache) PendingDeposits ¶
PendingDeposits returns a list of deposits until the given block number (inclusive). If no block is specified then this method returns all pending deposits.
func (*Cache) PrunePendingDeposits ¶
PrunePendingDeposits removes any deposit which is older than the given deposit merkle tree index.
type DepositTree ¶
type DepositTree struct {
// contains filtered or unexported fields
}
DepositTree is the Merkle tree representation of deposits.
func DepositTreeFromSnapshotProto ¶
func DepositTreeFromSnapshotProto(snapshotProto *protodb.DepositSnapshot) (*DepositTree, error)
DepositTreeFromSnapshotProto generates a deposit tree object from a provided snapshot.
func NewDepositTree ¶
func NewDepositTree() *DepositTree
NewDepositTree creates an empty deposit tree.
func (*DepositTree) Copy ¶
func (d *DepositTree) Copy() (*DepositTree, error)
Copy performs a deep copy of the tree.
func (*DepositTree) Finalize ¶
func (d *DepositTree) Finalize(eth1DepositIndex int64, executionHash common.Hash, executionNumber uint64) error
Finalize marks a deposit as finalized.
func (*DepositTree) GetSnapshot ¶
func (d *DepositTree) GetSnapshot() (DepositTreeSnapshot, error)
GetSnapshot returns a deposit tree snapshot.
func (*DepositTree) HashTreeRoot ¶
func (d *DepositTree) HashTreeRoot() ([32]byte, error)
HashTreeRoot is defined as part of MerkleTree interface and calculates the hash tree root.
func (*DepositTree) Insert ¶
func (d *DepositTree) Insert(item []byte, _ int) error
Insert is defined as part of MerkleTree interface and adds a new leaf to the tree.
func (*DepositTree) MerkleProof ¶
func (d *DepositTree) MerkleProof(index int) ([][]byte, error)
MerkleProof is defined as part of MerkleTree interface and generates a merkle proof.
func (*DepositTree) NumOfItems ¶
func (d *DepositTree) NumOfItems() int
NumOfItems is defined as part of MerkleTree interface and returns the number of deposits in the tree.
func (*DepositTree) ToProto ¶
func (d *DepositTree) ToProto() (*protodb.DepositSnapshot, error)
ToProto returns a proto object of the deposit snapshot of the tree.
type DepositTreeSnapshot ¶
type DepositTreeSnapshot struct {
// contains filtered or unexported fields
}
DepositTreeSnapshot represents the data used to create a deposit tree given a snapshot.
func (*DepositTreeSnapshot) CalculateRoot ¶
func (ds *DepositTreeSnapshot) CalculateRoot() ([32]byte, error)
CalculateRoot returns the root of a deposit tree snapshot.
func (*DepositTreeSnapshot) ToProto ¶
func (ds *DepositTreeSnapshot) ToProto() *protodb.DepositSnapshot
ToProto converts the underlying trie into its corresponding proto object.
type FinalizedNode ¶
type FinalizedNode struct {
// contains filtered or unexported fields
}
FinalizedNode represents a finalized node and satisfies the MerkleTreeNode interface.
func (*FinalizedNode) Finalize ¶
func (f *FinalizedNode) Finalize(depositsToFinalize uint64, depth uint64) (MerkleTreeNode, error)
Finalize marks deposits of the Merkle tree as finalized.
func (*FinalizedNode) GetFinalized ¶
func (f *FinalizedNode) GetFinalized(result [][32]byte) (uint64, [][32]byte)
GetFinalized returns a list of hashes of all the finalized nodes and the number of deposits.
func (*FinalizedNode) GetRoot ¶
func (f *FinalizedNode) GetRoot() [32]byte
GetRoot returns the root of the Merkle tree.
func (*FinalizedNode) IsFull ¶
func (_ *FinalizedNode) IsFull() bool
IsFull returns whether there is space left for deposits. A FinalizedNode will always return true as by definition it is full and deposits can't be added to it.
func (*FinalizedNode) Left ¶
func (_ *FinalizedNode) Left() MerkleTreeNode
Left returns nil as a finalized node can't have any children.
func (*FinalizedNode) PushLeaf ¶
func (_ *FinalizedNode) PushLeaf(_ [32]byte, _ uint64) (MerkleTreeNode, error)
PushLeaf adds a new leaf node at the next available zero node.
func (*FinalizedNode) Right ¶
func (_ *FinalizedNode) Right() MerkleTreeNode
Right returns nil as a finalized node can't have any children.
type InnerNode ¶
type InnerNode struct {
// contains filtered or unexported fields
}
InnerNode represents an inner node with two children and satisfies the MerkleTreeNode interface.
func (*InnerNode) Finalize ¶
func (n *InnerNode) Finalize(depositsToFinalize uint64, depth uint64) (MerkleTreeNode, error)
Finalize marks deposits of the Merkle tree as finalized.
func (*InnerNode) GetFinalized ¶
GetFinalized returns a list of hashes of all the finalized nodes and the number of deposits.
func (*InnerNode) Left ¶
func (n *InnerNode) Left() MerkleTreeNode
Left returns the child node on the left.
func (*InnerNode) PushLeaf ¶
func (n *InnerNode) PushLeaf(leaf [32]byte, depth uint64) (MerkleTreeNode, error)
PushLeaf adds a new leaf node at the next available zero node.
func (*InnerNode) Right ¶
func (n *InnerNode) Right() MerkleTreeNode
Right returns the child node on the right.
type LeafNode ¶
type LeafNode struct {
// contains filtered or unexported fields
}
LeafNode represents a leaf node holding a deposit and satisfies the MerkleTreeNode interface.
func (*LeafNode) Finalize ¶
func (l *LeafNode) Finalize(depositsToFinalize uint64, depth uint64) (MerkleTreeNode, error)
Finalize marks deposits of the Merkle tree as finalized.
func (*LeafNode) GetFinalized ¶
GetFinalized returns a list of hashes of all the finalized nodes and the number of deposits.
func (*LeafNode) IsFull ¶
IsFull returns whether there is space left for deposits. A LeafNode will always return true as it is the last node in the tree and therefore can't have any deposits added to it.
func (*LeafNode) Left ¶
func (_ *LeafNode) Left() MerkleTreeNode
Left returns nil as a leaf node is the last node and can't have any children.
func (*LeafNode) PushLeaf ¶
func (_ *LeafNode) PushLeaf(_ [32]byte, _ uint64) (MerkleTreeNode, error)
PushLeaf adds a new leaf node at the next available zero node.
func (*LeafNode) Right ¶
func (_ *LeafNode) Right() MerkleTreeNode
Right returns nil as a leaf node is the last node and can't have any children.
type MerkleTreeNode ¶
type MerkleTreeNode interface { // GetRoot returns the root of the Merkle tree. GetRoot() [32]byte // IsFull returns whether there is space left for deposits. IsFull() bool // Finalize marks deposits of the Merkle tree as finalized. Finalize(depositsToFinalize uint64, depth uint64) (MerkleTreeNode, error) // GetFinalized returns the number of deposits and a list of hashes of all the finalized nodes. GetFinalized(result [][32]byte) (uint64, [][32]byte) // PushLeaf adds a new leaf node at the next available Zero node. PushLeaf(leaf [32]byte, depth uint64) (MerkleTreeNode, error) // Right represents the right child of a node. Right() MerkleTreeNode // Left represents the left child of a node. Left() MerkleTreeNode }
MerkleTreeNode is the interface for a Merkle tree.
type PendingDepositsFetcher ¶ added in v5.0.4
type PendingDepositsFetcher interface {
PendingContainers(ctx context.Context, untilBlk *big.Int) []*ethpb.DepositContainer
}
PendingDepositsFetcher specifically outlines a struct that can retrieve deposits which have not yet been included in the chain.
type ZeroNode ¶
type ZeroNode struct {
// contains filtered or unexported fields
}
ZeroNode represents an empty node without a deposit and satisfies the MerkleTreeNode interface.
func (*ZeroNode) Finalize ¶
func (_ *ZeroNode) Finalize(depositsToFinalize uint64, depth uint64) (MerkleTreeNode, error)
Finalize marks deposits of the Merkle tree as finalized.
func (*ZeroNode) GetFinalized ¶
GetFinalized returns a list of hashes of all the finalized nodes and the number of deposits.
func (*ZeroNode) IsFull ¶
IsFull returns wh ether there is space left for deposits. A ZeroNode will always return false as a ZeroNode is an empty node that gets replaced by a deposit.
func (*ZeroNode) Left ¶
func (_ *ZeroNode) Left() MerkleTreeNode
Left returns nil as a zero node can't have any children.
func (*ZeroNode) PushLeaf ¶
func (_ *ZeroNode) PushLeaf(leaf [32]byte, depth uint64) (MerkleTreeNode, error)
PushLeaf adds a new leaf node at the next available zero node.
func (*ZeroNode) Right ¶
func (_ *ZeroNode) Right() MerkleTreeNode
Right returns nil as a zero node can't have any children.