From 958c22e67299e9594dda5ff3ffce802de89fc8a5 Mon Sep 17 00:00:00 2001 From: kira Date: Tue, 27 Aug 2024 04:31:48 -0700 Subject: [PATCH] [ePBS] implement `UpdateVotesOnPayloadAttestation` (#14308) * Add protos for ePBS except state * Add ePBS beacon state proto * ePBS configuration constants * Helper for Payload Attestation Signing (#13901) * Add ePBS stuff to consensus-types: block * Add testing utility methods to return randomly populated ePBS objects * Add ePBS to state (#13926) * Implement get_ptc This implements a helper to get the ptc committee from a state. It uses the cached beacon committees if possible It also implements a helper to compute the largest power of two of a uint64 and a helper to test for nil payload attestation messages * Add EPBS slashing params * Add ePBS to db (#13971) * Add ePBS to db * Fix GetPayloadTimelinessCommittee to return correct PTC size (#14012) * Change gwei math to primitives package for ePBS state * use Keymanager() in validator client * Add PTC assignment support for Duty endpoint (#14032) * Enable validator client to submit payload attestation message (#14064) * Remove inclusion list from epbs (#14188) * Modify `get_ptc` function to follow the Python spec (#14256) * Modify `get_ptc` function to follow the Python spec * Assign PTC members from the beginning of beacon committee array * Add `remove_flag` and its unit test (#14260) * Add `remove_flag` and its unit test * Add a test case trying to remove a flag that is not set * Ensure epbs state getters & setters check versions (#14276) * Ensure EPBS state getters and setters check versions * Rename to LatestExecutionPayloadHeaderEPBS * Add minimal beacon state * Use slot for latest message in forkchoice (#14279) * Add payload attestation helper functions (#14258) * Add `IndexedPayloadAttestation` container * Add `GetPayloadAttestingIndices` and its unit test * Add `GetIndexedPayloadAttestation` and its unit test * Add `is_valid_indexed_payload_attestation` and its unit test * Create a smaller set of validators for faster unit test * Pass context to `GetPayloadTimelinessCommittee` * Iterate `ValidatorsReadOnly` instead of copying all validators * Use BeaconCommittees helper to get the ptc (#14286) * 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 * Read only payload attestation message with Verifier (#14222) * Read only payload attestation message with verifier * Payload attestation tests (#14242) * Payload attestation in verification package * Feedback #1 --------- Co-authored-by: Md Amaan <114795592+Redidacove@users.noreply.github.com> * Broadcast signed execution payload header to peer (#14300) * Add `execution_payload` and `payload_attestation_message` topics (#14304) * Add `execution_payload` and `payload_attestation_message` topics * Set `SourcePubkey` to 48 bytes long * Add randomly populated `PayloadAttestationMessage` object * Add tests for `execution_payload` and `payload_attestation_message` topics * Indexed paylaod attestation test (#14299) * test-added * nil check fix * randomized inputs * hardcoded inputs * suggestions applied * minor-typo fixed * deleted * Process Execution Payload Envelope in Chain Service (#14295) Adds the processing of execution payload envelope Corrects the protos for attestations and slashings in Electra versions Adds generators of full blocks for Electra * Implement OnPayloadAttestationMessage; add setters and required fields * Update ptcVote from byte to primitives; update functions * Update fields in struct * fix lint error: unnecessary conversion * fix lint error: unnecessary conversion * organize code; move ptcVote to node from store * add check to avoid computation if the payload boost is already applied * cleanup * update code to loop over bitfield * fix deepsource errors * use preset value instead of .len() * Payload Attestation Sync package changes (#13989) * Payload Attestation Sync package changes * With verifier * change idx back to uint64 * subscribe to topic * add back error --------- Co-authored-by: terence tsao * change the name of the function; Add comprehensive comments * Add comprehensive unit tests for updateVotes function * fix unused var * fix nits * only updateBoosts onDemand * handle potential equivocation * Add protos for ePBS except state * Add ePBS beacon state proto * ePBS configuration constants * Helper for Payload Attestation Signing (#13901) * Add ePBS stuff to consensus-types: block * Add testing utility methods to return randomly populated ePBS objects * Add ePBS to state (#13926) * Implement get_ptc This implements a helper to get the ptc committee from a state. It uses the cached beacon committees if possible It also implements a helper to compute the largest power of two of a uint64 and a helper to test for nil payload attestation messages * Add EPBS slashing params * Add ePBS to db (#13971) * Add ePBS to db * Fix GetPayloadTimelinessCommittee to return correct PTC size (#14012) * Change gwei math to primitives package for ePBS state * use Keymanager() in validator client * Add PTC assignment support for Duty endpoint (#14032) * Enable validator client to submit payload attestation message (#14064) * Remove inclusion list from epbs (#14188) * Modify `get_ptc` function to follow the Python spec (#14256) * Modify `get_ptc` function to follow the Python spec * Assign PTC members from the beginning of beacon committee array * Add `remove_flag` and its unit test (#14260) * Add `remove_flag` and its unit test * Add a test case trying to remove a flag that is not set * Ensure epbs state getters & setters check versions (#14276) * Ensure EPBS state getters and setters check versions * Rename to LatestExecutionPayloadHeaderEPBS * Add minimal beacon state * Use slot for latest message in forkchoice (#14279) * Add payload attestation helper functions (#14258) * Add `IndexedPayloadAttestation` container * Add `GetPayloadAttestingIndices` and its unit test * Add `GetIndexedPayloadAttestation` and its unit test * Add `is_valid_indexed_payload_attestation` and its unit test * Create a smaller set of validators for faster unit test * Pass context to `GetPayloadTimelinessCommittee` * Iterate `ValidatorsReadOnly` instead of copying all validators * Use BeaconCommittees helper to get the ptc (#14286) * 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 * Read only payload attestation message with Verifier (#14222) * Read only payload attestation message with verifier * Payload attestation tests (#14242) * Payload attestation in verification package * Feedback #1 --------- Co-authored-by: Md Amaan <114795592+Redidacove@users.noreply.github.com> * Broadcast signed execution payload header to peer (#14300) * Add `execution_payload` and `payload_attestation_message` topics (#14304) * Add `execution_payload` and `payload_attestation_message` topics * Set `SourcePubkey` to 48 bytes long * Add randomly populated `PayloadAttestationMessage` object * Add tests for `execution_payload` and `payload_attestation_message` topics * Indexed paylaod attestation test (#14299) * test-added * nil check fix * randomized inputs * hardcoded inputs * suggestions applied * minor-typo fixed * deleted * Process Execution Payload Envelope in Chain Service (#14295) Adds the processing of execution payload envelope Corrects the protos for attestations and slashings in Electra versions Adds generators of full blocks for Electra * Payload Attestation Sync package changes (#13989) * Payload Attestation Sync package changes * With verifier * change idx back to uint64 * subscribe to topic * add back error --------- Co-authored-by: terence tsao * Add getter for payload attestation cache (#14328) * Add getter for payload attestation cache * Check against status * Feedback #1 * Initialize payload att message verfier in sync (#14323) * Enable validator client to sign execution header (#14333) * Enable validator client to sign execution header * Update proto/prysm/v1alpha1/validator-client/keymanager.proto --------- Co-authored-by: Potuz * Process withdrawal (#14297) * process_withdrawal_fn and isParentfull test * suggestions applied * minor change * removed * lint * lint fix * removed Latestheader * test added with nil error * tests passing * IsParentNode Test added * lint * fix test * updated godoc * fix in godoc * comment removed * fixed braces * removed var * removed var * Update beacon-chain/core/blocks/withdrawals.go * Update beacon-chain/core/blocks/withdrawals_test.go * gazelle * test added and removed previous changes in Testprocesswithdrawal * added check for nil state * decrease chromatic complexity --------- Co-authored-by: Potuz Co-authored-by: Potuz * Update tests * undo changes * UpdateVote independent of timing; updatePayloadboosts if the block is early * fix deep source * remove timinng checks; move to onDemand payloadBoosts; update testCases for the changes * update errors and returns; update test cases for the changes * fix deep source errors * reduce cyclomatic complexity * gazelle fix * remove a comment Co-authored-by: Potuz * fix duplication in beacon-chain config * fix config tests * fix number of config params --------- Co-authored-by: Potuz Co-authored-by: terence Co-authored-by: JihoonSong Co-authored-by: Md Amaan <114795592+Redidacove@users.noreply.github.com> Co-authored-by: Potuz --- .../forkchoice/doubly-linked-tree/BUILD.bazel | 2 + .../doubly-linked-tree/forkchoice.go | 59 +++++ .../doubly-linked-tree/forkchoice_test.go | 235 ++++++++++++++++++ .../forkchoice/doubly-linked-tree/types.go | 4 + beacon-chain/rpc/eth/config/handlers_test.go | 12 +- config/fieldparams/mainnet.go | 1 + config/params/config.go | 5 + config/params/mainnet_config.go | 7 +- 8 files changed, 323 insertions(+), 2 deletions(-) diff --git a/beacon-chain/forkchoice/doubly-linked-tree/BUILD.bazel b/beacon-chain/forkchoice/doubly-linked-tree/BUILD.bazel index ac58d534dada..15a6c60fcfe7 100644 --- a/beacon-chain/forkchoice/doubly-linked-tree/BUILD.bazel +++ b/beacon-chain/forkchoice/doubly-linked-tree/BUILD.bazel @@ -68,6 +68,7 @@ go_test( "//beacon-chain/forkchoice/types:go_default_library", "//beacon-chain/state:go_default_library", "//beacon-chain/state/state-native:go_default_library", + "//config/fieldparams:go_default_library", "//config/params:go_default_library", "//consensus-types/blocks:go_default_library", "//consensus-types/forkchoice:go_default_library", @@ -80,5 +81,6 @@ go_test( "//testing/require:go_default_library", "//testing/util:go_default_library", "//time/slots:go_default_library", + "@com_github_prysmaticlabs_go_bitfield//:go_default_library", ], ) diff --git a/beacon-chain/forkchoice/doubly-linked-tree/forkchoice.go b/beacon-chain/forkchoice/doubly-linked-tree/forkchoice.go index be96e7aff224..3481ca1e7c0c 100644 --- a/beacon-chain/forkchoice/doubly-linked-tree/forkchoice.go +++ b/beacon-chain/forkchoice/doubly-linked-tree/forkchoice.go @@ -721,3 +721,62 @@ func (f *ForkChoice) ParentRoot(root [32]byte) ([32]byte, error) { } return n.parent.root, nil } + +// UpdateVotesOnPayloadAttestation processes a new aggregated +// payload attestation message and updates +// the Payload Timeliness Committee (PTC) votes for the corresponding block. +func (s *Store) updateVotesOnPayloadAttestation( + payloadAttestation *ethpb.PayloadAttestation) error { + // Extract the attestation data and convert the beacon block root to a 32-byte array + data := payloadAttestation.Data + blockRoot := bytesutil.ToBytes32(data.BeaconBlockRoot) + + // Check if the block exists in the store + node, ok := s.nodeByRoot[blockRoot] + if !ok || node == nil { + return ErrNilNode + } + + // Update the PTC votes based on the attestation + // We only set the vote if it hasn't been set before + // to handle potential equivocations + for i := uint64(0); i < fieldparams.PTCSize; i++ { + if payloadAttestation.AggregationBits.BitAt(i) && node.ptcVote[i] == primitives.PAYLOAD_ABSENT { + node.ptcVote[i] = data.PayloadStatus + } + } + + return nil +} + +// updatePayloadBoosts checks the PTC votes for a given node and updates +// the payload reveal and withhold boost roots if the necessary thresholds are met. +func (s *Store) updatePayloadBoosts(node *Node) { + presentCount := 0 + withheldCount := 0 + + // Count the number of PRESENT and WITHHELD votes + for _, vote := range node.ptcVote { + if vote == primitives.PAYLOAD_PRESENT { + presentCount++ + } else if vote == primitives.PAYLOAD_WITHHELD { + withheldCount++ + } + } + + // If the number of PRESENT votes exceeds the threshold, + // update the payload reveal boost root + if presentCount > int(params.BeaconConfig().PayloadTimelyThreshold) { + s.payloadRevealBoostRoot = node.root + return + } + // If the number of WITHHELD votes exceeds the threshold, + // update the payload reveal boost root + if withheldCount > int(params.BeaconConfig().PayloadTimelyThreshold) { + if node.parent != nil { + s.payloadWithholdBoostRoot = node.parent.root + // A node is considered "full" if it has a non-zero payload hash + s.payloadWithholdBoostFull = node.parent.payloadHash != [32]byte{} + } + } +} diff --git a/beacon-chain/forkchoice/doubly-linked-tree/forkchoice_test.go b/beacon-chain/forkchoice/doubly-linked-tree/forkchoice_test.go index 2dc695f6fb81..1b08d95bedfe 100644 --- a/beacon-chain/forkchoice/doubly-linked-tree/forkchoice_test.go +++ b/beacon-chain/forkchoice/doubly-linked-tree/forkchoice_test.go @@ -6,14 +6,17 @@ import ( "testing" "time" + "github.com/prysmaticlabs/go-bitfield" "github.com/prysmaticlabs/prysm/v5/beacon-chain/forkchoice" forkchoicetypes "github.com/prysmaticlabs/prysm/v5/beacon-chain/forkchoice/types" "github.com/prysmaticlabs/prysm/v5/beacon-chain/state" state_native "github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native" + fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" "github.com/prysmaticlabs/prysm/v5/config/params" "github.com/prysmaticlabs/prysm/v5/consensus-types/blocks" "github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" "github.com/prysmaticlabs/prysm/v5/crypto/hash" + "github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1" ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" "github.com/prysmaticlabs/prysm/v5/testing/assert" @@ -62,6 +65,14 @@ func prepareForkchoiceState( return st, blockRoot, err } +// Helper function to set all bits in a Bitvector512 +func setAllBits(bv bitfield.Bitvector512) bitfield.Bitvector512 { + for i := 0; i < len(bv); i++ { + bv[i] = 0xFF + } + return bv +} + func TestForkChoice_UpdateBalancesPositiveChange(t *testing.T) { f := setup(0, 0) ctx := context.Background() @@ -888,3 +899,227 @@ func TestForkchoiceParentRoot(t *testing.T) { require.NoError(t, err) require.Equal(t, zeroHash, root) } + +func TestStore_UpdateVotesOnPayloadAttestation(t *testing.T) { + tests := []struct { + name string + setupStore func(*Store) + payloadAttestation *ethpb.PayloadAttestation + wantErr bool + expectedPTCVotes []primitives.PTCStatus + expectedBoosts func(*Store) bool + }{ + { + name: "Unknown block root", + setupStore: func(_ *Store) {}, + payloadAttestation: ðpb.PayloadAttestation{ + Data: ðpb.PayloadAttestationData{ + BeaconBlockRoot: []byte{1, 2, 3}, + }, + }, + wantErr: true, + }, + { + name: "Update PTC votes - all present", + setupStore: func(s *Store) { + root := [32]byte{1, 2, 3} + s.nodeByRoot[root] = &Node{root: root, ptcVote: make([]primitives.PTCStatus, fieldparams.PTCSize)} + }, + payloadAttestation: ðpb.PayloadAttestation{ + Data: ðpb.PayloadAttestationData{ + BeaconBlockRoot: []byte{1, 2, 3}, + PayloadStatus: primitives.PAYLOAD_PRESENT, + }, + AggregationBits: setAllBits(bitfield.NewBitvector512()), + }, + expectedPTCVotes: func() []primitives.PTCStatus { + return makeVotes(fieldparams.PTCSize, primitives.PAYLOAD_PRESENT) + }(), + expectedBoosts: noBoosts, + }, + { + name: "Update PTC votes - all withheld", + setupStore: func(s *Store) { + root := [32]byte{4, 5, 6} + s.nodeByRoot[root] = &Node{root: root, ptcVote: make([]primitives.PTCStatus, fieldparams.PTCSize)} + }, + payloadAttestation: ðpb.PayloadAttestation{ + Data: ðpb.PayloadAttestationData{ + BeaconBlockRoot: []byte{4, 5, 6}, + PayloadStatus: primitives.PAYLOAD_WITHHELD, + }, + AggregationBits: setAllBits(bitfield.NewBitvector512()), + }, + expectedPTCVotes: func() []primitives.PTCStatus { + return makeVotes(fieldparams.PTCSize, primitives.PAYLOAD_WITHHELD) + }(), + expectedBoosts: noBoosts, + }, + { + name: "Update PTC votes - partial attestation", + setupStore: func(s *Store) { + root := [32]byte{7, 8, 9} + s.nodeByRoot[root] = &Node{root: root, ptcVote: make([]primitives.PTCStatus, fieldparams.PTCSize)} + }, + payloadAttestation: ðpb.PayloadAttestation{ + Data: ðpb.PayloadAttestationData{ + BeaconBlockRoot: []byte{7, 8, 9}, + PayloadStatus: primitives.PAYLOAD_PRESENT, + }, + AggregationBits: func() bitfield.Bitvector512 { + bits := bitfield.NewBitvector512() + for i := 0; i < fieldparams.PTCSize/2; i++ { + bits.SetBitAt(uint64(i), true) + } + return bits + }(), + }, + expectedPTCVotes: func() []primitives.PTCStatus { + votes := make([]primitives.PTCStatus, fieldparams.PTCSize) + for i := 0; i < fieldparams.PTCSize/2; i++ { + votes[i] = primitives.PAYLOAD_PRESENT + } + return votes + }(), + expectedBoosts: noBoosts, + }, + { + name: "Update PTC votes - no change for already set votes", + setupStore: func(s *Store) { + root := [32]byte{10, 11, 12} + votes := make([]primitives.PTCStatus, fieldparams.PTCSize) + for i := range votes { + if i%2 == 0 { + votes[i] = primitives.PAYLOAD_PRESENT + } + } + s.nodeByRoot[root] = &Node{root: root, ptcVote: votes} + }, + payloadAttestation: ðpb.PayloadAttestation{ + Data: ðpb.PayloadAttestationData{ + BeaconBlockRoot: []byte{10, 11, 12}, + PayloadStatus: primitives.PAYLOAD_WITHHELD, + }, + AggregationBits: setAllBits(bitfield.NewBitvector512()), + }, + expectedPTCVotes: func() []primitives.PTCStatus { + votes := make([]primitives.PTCStatus, fieldparams.PTCSize) + for i := range votes { + if i%2 == 0 { + votes[i] = primitives.PAYLOAD_PRESENT + } else { + votes[i] = primitives.PAYLOAD_WITHHELD + } + } + return votes + }(), + expectedBoosts: noBoosts, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + s := &Store{ + nodeByRoot: make(map[[32]byte]*Node), + } + tt.setupStore(s) + + err := s.updateVotesOnPayloadAttestation(tt.payloadAttestation) + + if tt.wantErr { + require.ErrorIs(t, err, ErrNilNode, "Expected ErrNilNode") + } else { + require.NoError(t, err) + node := s.nodeByRoot[bytesutil.ToBytes32(tt.payloadAttestation.Data.BeaconBlockRoot)] + assert.DeepEqual(t, tt.expectedPTCVotes, node.ptcVote, "Unexpected PTC votes") + assert.Equal(t, tt.expectedBoosts(s), true, "Unexpected boost values") + } + }) + } +} + +func makeVotes(count int, status primitives.PTCStatus) []primitives.PTCStatus { + votes := make([]primitives.PTCStatus, fieldparams.PTCSize) + for i := 0; i < count; i++ { + votes[i] = status + } + return votes +} + +func noBoosts(s *Store) bool { + return s.payloadRevealBoostRoot == [32]byte{} && + s.payloadWithholdBoostRoot == [32]byte{} && + !s.payloadWithholdBoostFull +} + +func TestStore_UpdatePayloadBoosts(t *testing.T) { + tests := []struct { + name string + setupNode func(*Node) + expectedRevealBoost [32]byte + expectedWithholdBoost [32]byte + expectedWithholdFull bool + }{ + { + name: "No boost", + setupNode: func(n *Node) { + n.ptcVote = make([]primitives.PTCStatus, fieldparams.PTCSize) + }, + }, + { + name: "Reveal boost", + setupNode: func(n *Node) { + n.root = [32]byte{1, 2, 3} + n.ptcVote = make([]primitives.PTCStatus, fieldparams.PTCSize) + for i := 0; i < int(params.BeaconConfig().PayloadTimelyThreshold)+1; i++ { + n.ptcVote[i] = primitives.PAYLOAD_PRESENT + } + }, + expectedRevealBoost: [32]byte{1, 2, 3}, + }, + { + name: "Withhold boost", + setupNode: func(n *Node) { + n.ptcVote = make([]primitives.PTCStatus, fieldparams.PTCSize) + for i := 0; i < int(params.BeaconConfig().PayloadTimelyThreshold)+1; i++ { + n.ptcVote[i] = primitives.PAYLOAD_WITHHELD + } + n.parent = &Node{root: [32]byte{4, 5, 6}, payloadHash: [32]byte{7, 8, 9}} + }, + expectedWithholdBoost: [32]byte{4, 5, 6}, + expectedWithholdFull: true, + }, + { + name: "Reveal boost with early return", + setupNode: func(n *Node) { + n.root = [32]byte{1, 2, 3} + n.ptcVote = make([]primitives.PTCStatus, fieldparams.PTCSize) + for i := 0; i < int(params.BeaconConfig().PayloadTimelyThreshold)+1; i++ { + n.ptcVote[i] = primitives.PAYLOAD_PRESENT + } + // Set up conditions for withhold boost, which should not be applied due to early return + n.parent = &Node{root: [32]byte{4, 5, 6}, payloadHash: [32]byte{7, 8, 9}} + for i := int(params.BeaconConfig().PayloadTimelyThreshold) + 1; i < fieldparams.PTCSize; i++ { + n.ptcVote[i] = primitives.PAYLOAD_WITHHELD + } + }, + expectedRevealBoost: [32]byte{1, 2, 3}, + expectedWithholdBoost: [32]byte{}, // Should remain zero due to early return + expectedWithholdFull: false, // Should remain false due to early return + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + s := &Store{} + n := &Node{} + tt.setupNode(n) + + s.updatePayloadBoosts(n) + + assert.Equal(t, tt.expectedRevealBoost, s.payloadRevealBoostRoot, "Unexpected reveal boost root") + assert.Equal(t, tt.expectedWithholdBoost, s.payloadWithholdBoostRoot, "Unexpected withhold boost root") + assert.Equal(t, tt.expectedWithholdFull, s.payloadWithholdBoostFull, "Unexpected withhold full status") + }) + } +} diff --git a/beacon-chain/forkchoice/doubly-linked-tree/types.go b/beacon-chain/forkchoice/doubly-linked-tree/types.go index a8877834a60f..0039496810c7 100644 --- a/beacon-chain/forkchoice/doubly-linked-tree/types.go +++ b/beacon-chain/forkchoice/doubly-linked-tree/types.go @@ -41,6 +41,9 @@ type Store struct { highestReceivedNode *Node // The highest slot node. receivedBlocksLastEpoch [fieldparams.SlotsPerEpoch]primitives.Slot // Using `highestReceivedSlot`. The slot of blocks received in the last epoch. allTipsAreInvalid bool // tracks if all tips are not viable for head + payloadWithholdBoostRoot [fieldparams.RootLength]byte // the root of the block that receives the withhold boost + payloadWithholdBoostFull bool // Indicator of whether the block receiving the withhold boost is full or empty + payloadRevealBoostRoot [fieldparams.RootLength]byte // the root of the block that receives the reveal boost } // Node defines the individual block which includes its block parent, ancestor and how much weight accounted for it. @@ -61,6 +64,7 @@ type Node struct { bestDescendant *Node // bestDescendant node of this node. optimistic bool // whether the block has been fully validated or not timestamp uint64 // The timestamp when the node was inserted. + ptcVote []primitives.PTCStatus // tracks the Payload Timeliness Committee (PTC) votes for the node } // Vote defines an individual validator's vote. diff --git a/beacon-chain/rpc/eth/config/handlers_test.go b/beacon-chain/rpc/eth/config/handlers_test.go index b8d8a5319ef7..5862b2a66b48 100644 --- a/beacon-chain/rpc/eth/config/handlers_test.go +++ b/beacon-chain/rpc/eth/config/handlers_test.go @@ -196,7 +196,7 @@ func TestGetSpec(t *testing.T) { data, ok := resp.Data.(map[string]interface{}) require.Equal(t, true, ok) - assert.Equal(t, 158, len(data)) + assert.Equal(t, 163, len(data)) for k, v := range data { t.Run(k, func(t *testing.T) { switch k { @@ -533,6 +533,16 @@ func TestGetSpec(t *testing.T) { assert.Equal(t, "92", v) case "MAX_DEPOSIT_REQUESTS_PER_PAYLOAD": assert.Equal(t, "93", v) + case "PROPOSER_SCORE_BOOST_EPBS": + assert.Equal(t, "20", v) + case "PAYLOAD_REVEAL_BOOST": + assert.Equal(t, "40", v) + case "PAYLOAD_WITHHOLD_BOOST": + assert.Equal(t, "40", v) + case "PAYLOAD_TIMELY_THRESHOLD": + assert.Equal(t, "256", v) + case "INTERVALS_PER_SLOT_EPBS": + assert.Equal(t, "4", v) case "MIN_BUILDER_BALANCE": assert.Equal(t, "0", v) default: diff --git a/config/fieldparams/mainnet.go b/config/fieldparams/mainnet.go index a72ecdad0b64..2530e84cea13 100644 --- a/config/fieldparams/mainnet.go +++ b/config/fieldparams/mainnet.go @@ -15,6 +15,7 @@ const ( SlashingsLength = 8192 // EPOCHS_PER_SLASHINGS_VECTOR SyncCommitteeLength = 512 // SYNC_COMMITTEE_SIZE PTCSize = 512 // PTC_SIZE [New in ePBS] + PayloadTimelyThreshold = 256 // PTC_SIZE / 2 [New in ePBS] RootLength = 32 // RootLength defines the byte length of a Merkle root. BLSSignatureLength = 96 // BLSSignatureLength defines the byte length of a BLSSignature. BLSPubkeyLength = 48 // BLSPubkeyLength defines the byte length of a BLSSignature. diff --git a/config/params/config.go b/config/params/config.go index 1526614535cb..4e5ccccb0dce 100644 --- a/config/params/config.go +++ b/config/params/config.go @@ -70,10 +70,15 @@ type BeaconChainConfig struct { // Fork choice algorithm constants. ProposerScoreBoost uint64 `yaml:"PROPOSER_SCORE_BOOST" spec:"true"` // ProposerScoreBoost defines a value that is a % of the committee weight for fork-choice boosting. + ProposerScoreBoostEPBS uint64 `yaml:"PROPOSER_SCORE_BOOST_EPBS" spec:"true"` // ProposerScoreBoostEPBS defines a value that is a % of the committee weight for fork-choice boosting. ReorgWeightThreshold uint64 `yaml:"REORG_WEIGHT_THRESHOLD" spec:"true"` // ReorgWeightThreshold defines a value that is a % of the committee weight to consider a block weak and subject to being orphaned. ReorgParentWeightThreshold uint64 `yaml:"REORG_PARENT_WEIGHT_THRESHOLD" spec:"true"` // ReorgParentWeightThreshold defines a value that is a % of the committee weight to consider a parent block strong and subject its child to being orphaned. ReorgMaxEpochsSinceFinalization primitives.Epoch `yaml:"REORG_MAX_EPOCHS_SINCE_FINALIZATION" spec:"true"` // This defines a limit to consider safe to orphan a block if the network is finalizing IntervalsPerSlot uint64 `yaml:"INTERVALS_PER_SLOT" spec:"true"` // IntervalsPerSlot defines the number of fork choice intervals in a slot defined in the fork choice spec. + IntervalsPerSlotEPBS uint64 `yaml:"INTERVALS_PER_SLOT_EPBS" spec:"true"` // IntervalsPerSlotEPBS defines the number of fork choice intervals in a slot defined in the fork choice spec from EIP-7732. + PayloadWithholdBoost uint64 `yaml:"PAYLOAD_WITHHOLD_BOOST" spec:"true"` // PayloadWithholdBoost define a value that is the score boost given when a payload is withheld by the builder + PayloadRevealBoost uint64 `yaml:"PAYLOAD_REVEAL_BOOST" spec:"true"` // PayloadRevealBoost a value that is the score boost given when a payload is revealed by the builder + PayloadTimelyThreshold uint64 `yaml:"PAYLOAD_TIMELY_THRESHOLD" spec:"true"` // PayloadTimelyThreshold is the threshold for considering a payload timely. // Ethereum PoW parameters. DepositChainID uint64 `yaml:"DEPOSIT_CHAIN_ID" spec:"true"` // DepositChainID of the eth1 network. This used for replay protection. diff --git a/config/params/mainnet_config.go b/config/params/mainnet_config.go index 78954dd85eef..4644ac5693db 100644 --- a/config/params/mainnet_config.go +++ b/config/params/mainnet_config.go @@ -111,10 +111,15 @@ var mainnetBeaconConfig = &BeaconChainConfig{ // Fork choice algorithm constants. ProposerScoreBoost: 40, + ProposerScoreBoostEPBS: 20, ReorgWeightThreshold: 20, ReorgParentWeightThreshold: 160, ReorgMaxEpochsSinceFinalization: 2, IntervalsPerSlot: 3, + IntervalsPerSlotEPBS: 4, + PayloadWithholdBoost: 40, + PayloadRevealBoost: 40, + PayloadTimelyThreshold: 256, // PTC_SIZE / 2. // Ethereum PoW parameters. DepositChainID: 1, // Chain ID of eth1 mainnet. @@ -247,7 +252,7 @@ var mainnetBeaconConfig = &BeaconChainConfig{ EpochsPerSyncCommitteePeriod: 256, // Updated penalty values. - InactivityPenaltyQuotientAltair: 3 * 1 << 24, //50331648 + InactivityPenaltyQuotientAltair: 3 * 1 << 24, // 50331648 MinSlashingPenaltyQuotientAltair: 64, ProportionalSlashingMultiplierAltair: 2, MinSlashingPenaltyQuotientBellatrix: 32,