-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow nodes with and without payload in forkchoice (#14288)
* Allow nodes with and without payload in forkchoice This PR takes care of adding nodes to forkchoice that may or may not have a corresponding payload. The rationale is as follows - The node structure is kept almost the same as today. - A zero payload hash is considered as if the node was empty (except for the tree root) - When inserting a node we check what the right parent node would be depending on whether the parent had a payload or not. - For pre-epbs forks all nodes are full, no logic changes except a new steps to gather the parent hash that is needed for block insertion. This PR had to change some core consensus types and interfaces. - It removed the ROBlockEPBS interface and added the corresponding ePBS fields to the ReadOnlyBeaconBlockBody - It moved the setters and getters to epbs dedicated files. It also added a checker for `IsParentFull` on forkchoice that simply checks for the parent hash of the parent node. * review
- Loading branch information
Showing
13 changed files
with
231 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package doublylinkedtree | ||
|
||
func (n *Node) isParentFull() bool { | ||
// Finalized checkpoint is considered full | ||
if n.parent == nil || n.parent.parent == nil { | ||
return true | ||
} | ||
return n.parent.payloadHash != [32]byte{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package doublylinkedtree | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/prysmaticlabs/prysm/v5/testing/require" | ||
) | ||
|
||
func TestStore_Insert_PayloadContent(t *testing.T) { | ||
ctx := context.Background() | ||
f := setup(0, 0) | ||
s := f.store | ||
// The tree root is full | ||
fr := [32]byte{} | ||
n := s.nodeByRoot[fr] | ||
require.Equal(t, true, n.isParentFull()) | ||
|
||
// Insert a child with a payload | ||
cr := [32]byte{'a'} | ||
cp := [32]byte{'p'} | ||
n, err := s.insert(ctx, 1, cr, fr, cp, fr, 0, 0) | ||
require.NoError(t, err) | ||
require.Equal(t, true, n.isParentFull()) | ||
require.Equal(t, s.treeRootNode, n.parent) | ||
require.Equal(t, s.nodeByRoot[cr], n) | ||
|
||
// Insert a grandchild without a payload | ||
gr := [32]byte{'b'} | ||
gn, err := s.insert(ctx, 2, gr, cr, fr, cp, 0, 0) | ||
require.NoError(t, err) | ||
require.Equal(t, true, gn.isParentFull()) | ||
require.Equal(t, n, gn.parent) | ||
|
||
// Insert the payload of the same grandchild | ||
gp := [32]byte{'q'} | ||
gfn, err := s.insert(ctx, 2, gr, cr, gp, cp, 0, 0) | ||
require.NoError(t, err) | ||
require.Equal(t, true, gfn.isParentFull()) | ||
require.Equal(t, n, gfn.parent) | ||
|
||
// Insert an empty great grandchild based on empty | ||
ggr := [32]byte{'c'} | ||
ggn, err := s.insert(ctx, 3, ggr, gr, fr, cp, 0, 0) | ||
require.NoError(t, err) | ||
require.Equal(t, false, ggn.isParentFull()) | ||
require.Equal(t, gn, ggn.parent) | ||
|
||
// Insert an empty great grandchild based on full | ||
ggfr := [32]byte{'d'} | ||
ggfn, err := s.insert(ctx, 3, ggfr, gr, fr, gp, 0, 0) | ||
require.NoError(t, err) | ||
require.Equal(t, gfn, ggfn.parent) | ||
require.Equal(t, true, ggfn.isParentFull()) | ||
|
||
// Insert the payload for the great grandchild based on empty | ||
ggp := [32]byte{'r'} | ||
n, err = s.insert(ctx, 3, ggr, gr, ggp, cp, 0, 0) | ||
require.NoError(t, err) | ||
require.Equal(t, false, n.isParentFull()) | ||
require.Equal(t, gn, n.parent) | ||
|
||
// Insert the payload for the great grandchild based on full | ||
ggfp := [32]byte{'s'} | ||
n, err = s.insert(ctx, 3, ggfr, gr, ggfp, gp, 0, 0) | ||
require.NoError(t, err) | ||
require.Equal(t, true, n.isParentFull()) | ||
require.Equal(t, gfn, n.parent) | ||
|
||
// Reinsert an empty node | ||
ggfn2, err := s.insert(ctx, 3, ggfr, gr, fr, gp, 0, 0) | ||
require.NoError(t, err) | ||
require.Equal(t, ggfn, ggfn2) | ||
|
||
// Reinsert a full node | ||
n2, err := s.insert(ctx, 3, ggfr, gr, ggfp, gp, 0, 0) | ||
require.NoError(t, err) | ||
require.Equal(t, n, n2) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package blocks | ||
|
||
import ( | ||
consensus_types "github.com/prysmaticlabs/prysm/v5/consensus-types" | ||
enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1" | ||
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" | ||
"github.com/prysmaticlabs/prysm/v5/runtime/version" | ||
) | ||
|
||
// PayloadAttestations returns the payload attestations in the block. | ||
func (b *BeaconBlockBody) PayloadAttestations() ([]*ethpb.PayloadAttestation, error) { | ||
if b.version < version.EPBS { | ||
return nil, consensus_types.ErrNotSupported("PayloadAttestations", b.version) | ||
} | ||
return b.payloadAttestations, nil | ||
} | ||
|
||
// SignedExecutionPayloadHeader returns the signed execution payload header in the block. | ||
func (b *BeaconBlockBody) SignedExecutionPayloadHeader() (*enginev1.SignedExecutionPayloadHeader, error) { | ||
if b.version < version.EPBS { | ||
return nil, consensus_types.ErrNotSupported("SignedExecutionPayloadHeader", b.version) | ||
} | ||
return b.signedExecutionPayloadHeader, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package blocks | ||
|
||
import ( | ||
consensus_types "github.com/prysmaticlabs/prysm/v5/consensus-types" | ||
enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1" | ||
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" | ||
"github.com/prysmaticlabs/prysm/v5/runtime/version" | ||
) | ||
|
||
// SetPayloadAttestations sets the payload attestations in the block. | ||
func (b *SignedBeaconBlock) SetPayloadAttestations(p []*eth.PayloadAttestation) error { | ||
if b.version < version.EPBS { | ||
return consensus_types.ErrNotSupported("PayloadAttestations", b.version) | ||
} | ||
b.block.body.payloadAttestations = p | ||
return nil | ||
} | ||
|
||
// SetSignedExecutionPayloadHeader sets the signed execution payload header of the block body. | ||
func (b *SignedBeaconBlock) SetSignedExecutionPayloadHeader(h *enginev1.SignedExecutionPayloadHeader) error { | ||
if b.version < version.EPBS { | ||
return consensus_types.ErrNotSupported("SetSignedExecutionPayloadHeader", b.version) | ||
} | ||
b.block.body.signedExecutionPayloadHeader = h | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters