Skip to content

Commit

Permalink
Remove inclusion list from epbs (#14188)
Browse files Browse the repository at this point in the history
  • Loading branch information
terencechain authored and potuz committed Jul 5, 2024
1 parent 725ac66 commit ef2ac39
Show file tree
Hide file tree
Showing 39 changed files with 3,145 additions and 25,990 deletions.
7 changes: 0 additions & 7 deletions beacon-chain/state/interfaces_epbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import (
)

type ReadOnlyEpbsFields interface {
PreviousInclusionListSlot() primitives.Slot
PreviousInclusionListProposer() primitives.ValidatorIndex
LatestInclusionListSlot() primitives.Slot
LatestInclusionListProposer() primitives.ValidatorIndex
IsParentBlockFull() bool
ExecutionPayloadHeader() *enginev1.ExecutionPayloadHeaderEPBS
LatestBlockHash() []byte
Expand All @@ -19,9 +15,6 @@ type ReadOnlyEpbsFields interface {

type WriteOnlyEpbsFields interface {
SetExecutionPayloadHeader(val *enginev1.ExecutionPayloadHeaderEPBS)
UpdatePreviousInclusionListData()
SetLatestInclusionListSlot(val primitives.Slot)
SetLatestInclusionListProposer(val primitives.ValidatorIndex)
SetLatestBlockHash(val []byte)
SetLatestFullSlot(val primitives.Slot)
SetLastWithdrawalsRoot(val []byte)
Expand Down
12 changes: 4 additions & 8 deletions beacon-chain/state/state-native/beacon_state_mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,10 @@ type BeaconState struct {
nextWithdrawalIndex uint64
nextWithdrawalValidatorIndex primitives.ValidatorIndex
// ePBS fields
previousInclusionListProposer primitives.ValidatorIndex
previousInclusionListSlot primitives.Slot
latestInclusionListProposer primitives.ValidatorIndex
latestInclusionListSlot primitives.Slot
latestBlockHash [32]byte
latestFullSlot primitives.Slot
executionPayloadHeader *enginev1.ExecutionPayloadHeaderEPBS
lastWithdrawalsRoot [32]byte
latestBlockHash [32]byte
latestFullSlot primitives.Slot
executionPayloadHeader *enginev1.ExecutionPayloadHeaderEPBS
lastWithdrawalsRoot [32]byte

// Electra fields
depositRequestsStartIndex uint64
Expand Down
12 changes: 4 additions & 8 deletions beacon-chain/state/state-native/beacon_state_minimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,10 @@ type BeaconState struct {
nextWithdrawalIndex uint64
nextWithdrawalValidatorIndex primitives.ValidatorIndex
// ePBS fields
previousInclusionListProposer primitives.ValidatorIndex
previousInclusionListSlot primitives.Slot
latestInclusionListProposer primitives.ValidatorIndex
latestInclusionListSlot primitives.Slot
latestBlockHash [32]byte
latestFullSlot primitives.Slot
executionPayloadHeader *enginev1.ExecutionPayloadHeaderEPBS
lastWithdrawalsRoot [32]byte
latestBlockHash [32]byte
latestFullSlot primitives.Slot
executionPayloadHeader *enginev1.ExecutionPayloadHeaderEPBS
lastWithdrawalsRoot [32]byte

// Electra fields
depositRequestsStartIndex uint64
Expand Down
32 changes: 0 additions & 32 deletions beacon-chain/state/state-native/getters_epbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,6 @@ func (b *BeaconState) IsParentBlockFull() bool {
return headerBlockHash == b.latestBlockHash
}

// LatestInclusionListProposer returns the proposer index from the latest inclusion list.
func (b *BeaconState) LatestInclusionListProposer() primitives.ValidatorIndex {
b.lock.RLock()
defer b.lock.RUnlock()

return b.latestInclusionListProposer
}

// LatestInclusionListSlot returns the slot from the latest inclusion list.
func (b *BeaconState) LatestInclusionListSlot() primitives.Slot {
b.lock.RLock()
defer b.lock.RUnlock()

return b.latestInclusionListSlot
}

// PreviousInclusionListProposer returns the proposer index from the previous inclusion list.
func (b *BeaconState) PreviousInclusionListProposer() primitives.ValidatorIndex {
b.lock.RLock()
defer b.lock.RUnlock()

return b.previousInclusionListProposer
}

// PreviousInclusionListSlot returns the slot from the previous inclusion list.
func (b *BeaconState) PreviousInclusionListSlot() primitives.Slot {
b.lock.RLock()
defer b.lock.RUnlock()

return b.previousInclusionListSlot
}

// LatestBlockHash returns the latest block hash.
func (b *BeaconState) LatestBlockHash() []byte {
b.lock.RLock()
Expand Down
37 changes: 0 additions & 37 deletions beacon-chain/state/state-native/getters_setters_epbs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,43 +33,6 @@ func Test_SetExecutionPayloadHeader(t *testing.T) {
require.DeepEqual(t, got, header)
}

func Test_UpdatePreviousInclusionListData(t *testing.T) {
s := &BeaconState{version: version.EPBS, dirtyFields: make(map[types.FieldIndex]bool)}
p := s.PreviousInclusionListProposer()
require.Equal(t, primitives.ValidatorIndex(0), p)
ss := s.PreviousInclusionListSlot()
require.Equal(t, primitives.Slot(0), ss)

s.SetLatestInclusionListProposer(1)
s.SetLatestInclusionListSlot(2)
s.UpdatePreviousInclusionListData()
require.Equal(t, true, s.dirtyFields[types.PreviousInclusionListProposer])
require.Equal(t, true, s.dirtyFields[types.PreviousInclusionListSlot])

p = s.PreviousInclusionListProposer()
require.Equal(t, primitives.ValidatorIndex(1), p)
ss = s.PreviousInclusionListSlot()
require.Equal(t, primitives.Slot(2), ss)
}

func Test_SetLatestInclusionListProposer(t *testing.T) {
s := &BeaconState{version: version.EPBS, dirtyFields: make(map[types.FieldIndex]bool)}
s.SetLatestInclusionListProposer(1)
require.Equal(t, true, s.dirtyFields[types.LatestInclusionListProposer])

got := s.LatestInclusionListProposer()
require.Equal(t, primitives.ValidatorIndex(1), got)
}

func Test_SetLatestInclusionListSlot(t *testing.T) {
s := &BeaconState{version: version.EPBS, dirtyFields: make(map[types.FieldIndex]bool)}
s.SetLatestInclusionListSlot(2)
require.Equal(t, true, s.dirtyFields[types.LatestInclusionListSlot])

got := s.LatestInclusionListSlot()
require.Equal(t, primitives.Slot(2), got)
}

func Test_SetLatestBlockHash(t *testing.T) {
s := &BeaconState{version: version.EPBS, dirtyFields: make(map[types.FieldIndex]bool)}
b := make([]byte, fieldparams.RootLength)
Expand Down
12 changes: 2 additions & 10 deletions beacon-chain/state/state-native/getters_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,13 +250,9 @@ func (b *BeaconState) ToProtoUnsafe() interface{} {
PendingBalanceDeposits: b.pendingBalanceDeposits,
PendingPartialWithdrawals: b.pendingPartialWithdrawals,
PendingConsolidations: b.pendingConsolidations,
PreviousInclusionListProposer: b.previousInclusionListProposer,
PreviousInclusionListSlot: b.previousInclusionListSlot,
LatestInclusionListProposer: b.latestInclusionListProposer,
LatestInclusionListSlot: b.latestInclusionListSlot,
LatestBlockHash: b.latestBlockHash[:],
LatestFullSlot: b.latestFullSlot,
ExecutionPayloadHeader: b.executionPayloadHeader,
LatestExecutionPayloadHeader: b.executionPayloadHeader,
LastWithdrawalsRoot: b.lastWithdrawalsRoot[:],
}
default:
Expand Down Expand Up @@ -506,13 +502,9 @@ func (b *BeaconState) ToProto() interface{} {
PendingBalanceDeposits: b.pendingBalanceDepositsVal(),
PendingPartialWithdrawals: b.pendingPartialWithdrawalsVal(),
PendingConsolidations: b.pendingConsolidationsVal(),
PreviousInclusionListProposer: b.previousInclusionListProposer,
PreviousInclusionListSlot: b.previousInclusionListSlot,
LatestInclusionListProposer: b.latestInclusionListProposer,
LatestInclusionListSlot: b.latestInclusionListSlot,
LatestBlockHash: LatestBlockHashCopy[:],
LatestFullSlot: b.latestFullSlot,
ExecutionPayloadHeader: b.executionPayloadHeaderVal(),
LatestExecutionPayloadHeader: b.executionPayloadHeaderVal(),
LastWithdrawalsRoot: lastWithdrawalsRootCopy[:],
}
default:
Expand Down
16 changes: 0 additions & 16 deletions beacon-chain/state/state-native/hasher.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,22 +338,6 @@ func ComputeFieldRootsWithHasher(ctx context.Context, state *BeaconState) ([][]b
}

if state.version >= version.EPBS {
// Previous inclusion list proposer root.
prevInclusionListProposerRoot := ssz.Uint64Root(uint64(state.previousInclusionListProposer))
fieldRoots[types.PreviousInclusionListProposer.RealPosition()] = prevInclusionListProposerRoot[:]

// Previous inclusion list slot root.
prevInclusionListSlotRoot := ssz.Uint64Root(uint64(state.previousInclusionListSlot))
fieldRoots[types.PreviousInclusionListSlot.RealPosition()] = prevInclusionListSlotRoot[:]

// Latest inclusion list proposer root.
latestInclusionListProposerRoot := ssz.Uint64Root(uint64(state.latestInclusionListProposer))
fieldRoots[types.LatestInclusionListProposer.RealPosition()] = latestInclusionListProposerRoot[:]

// Latest inclusion list slot root.
latestInclusionListSlotRoot := ssz.Uint64Root(uint64(state.latestInclusionListSlot))
fieldRoots[types.LatestInclusionListSlot.RealPosition()] = latestInclusionListSlotRoot[:]

// Latest block hash root.
latestBlockHashRoot := state.latestBlockHash[:]
fieldRoots[types.LatestBlockHash.RealPosition()] = latestBlockHashRoot
Expand Down
29 changes: 0 additions & 29 deletions beacon-chain/state/state-native/setters_epbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,35 +16,6 @@ func (b *BeaconState) SetExecutionPayloadHeader(h *enginev1.ExecutionPayloadHead
b.markFieldAsDirty(types.ExecutionPayloadHeader)
}

// UpdatePreviousInclusionListData updates the data of previous inclusion list with latest values.
func (b *BeaconState) UpdatePreviousInclusionListData() {
b.lock.Lock()
defer b.lock.Unlock()

b.previousInclusionListProposer = b.latestInclusionListProposer
b.previousInclusionListSlot = b.latestInclusionListSlot
b.markFieldAsDirty(types.PreviousInclusionListProposer)
b.markFieldAsDirty(types.PreviousInclusionListSlot)
}

// SetLatestInclusionListProposer sets the latest inclusion list proposer for the beacon state.
func (b *BeaconState) SetLatestInclusionListProposer(i primitives.ValidatorIndex) {
b.lock.Lock()
defer b.lock.Unlock()

b.latestInclusionListProposer = i
b.markFieldAsDirty(types.LatestInclusionListProposer)
}

// SetLatestInclusionListSlot sets the latest inclusion list slot for the beacon state.
func (b *BeaconState) SetLatestInclusionListSlot(s primitives.Slot) {
b.lock.Lock()
defer b.lock.Unlock()

b.latestInclusionListSlot = s
b.markFieldAsDirty(types.LatestInclusionListSlot)
}

// SetLatestBlockHash sets the latest block hash for the beacon state.
func (b *BeaconState) SetLatestBlockHash(h []byte) {
b.lock.Lock()
Expand Down
18 changes: 1 addition & 17 deletions beacon-chain/state/state-native/state_trie.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,11 +126,7 @@ var epbsFields = append(
types.PendingBalanceDeposits,
types.PendingPartialWithdrawals,
types.PendingConsolidations,
types.PreviousInclusionListProposer, // ePBS fields start here
types.PreviousInclusionListSlot,
types.LatestInclusionListProposer,
types.LatestInclusionListSlot,
types.LatestBlockHash,
types.LatestBlockHash, // ePBS fields start here
types.LatestFullSlot,
types.ExecutionPayloadHeader,
types.LastWithdrawalsRoot,
Expand Down Expand Up @@ -902,10 +898,6 @@ func (b *BeaconState) Copy() state.BeaconState {
earliestExitEpoch: b.earliestExitEpoch,
consolidationBalanceToConsume: b.consolidationBalanceToConsume,
earliestConsolidationEpoch: b.earliestConsolidationEpoch,
previousInclusionListProposer: b.previousInclusionListProposer,
previousInclusionListSlot: b.previousInclusionListSlot,
latestInclusionListProposer: b.latestInclusionListProposer,
latestInclusionListSlot: b.latestInclusionListSlot,
latestBlockHash: b.latestBlockHash,
latestFullSlot: b.latestFullSlot,
lastWithdrawalsRoot: b.lastWithdrawalsRoot,
Expand Down Expand Up @@ -1352,14 +1344,6 @@ func (b *BeaconState) rootSelector(ctx context.Context, field types.FieldIndex)
return stateutil.PendingPartialWithdrawalsRoot(b.pendingPartialWithdrawals)
case types.PendingConsolidations:
return stateutil.PendingConsolidationsRoot(b.pendingConsolidations)
case types.PreviousInclusionListProposer:
return ssz.Uint64Root(uint64(b.previousInclusionListProposer)), nil
case types.PreviousInclusionListSlot:
return ssz.Uint64Root(uint64(b.previousInclusionListSlot)), nil
case types.LatestInclusionListProposer:
return ssz.Uint64Root(uint64(b.latestInclusionListProposer)), nil
case types.LatestInclusionListSlot:
return ssz.Uint64Root(uint64(b.latestInclusionListSlot)), nil
case types.LatestBlockHash:
return b.latestBlockHash, nil
case types.LatestFullSlot:
Expand Down
12 changes: 4 additions & 8 deletions beacon-chain/state/state-native/state_trie_epbs.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,14 +64,10 @@ func InitializeFromProtoUnsafeEpbs(st *ethpb.BeaconStateEPBS) (*BeaconState, err
pendingConsolidations: st.PendingConsolidations,

// ePBS fields
previousInclusionListProposer: st.PreviousInclusionListProposer,
previousInclusionListSlot: st.PreviousInclusionListSlot,
latestInclusionListProposer: st.LatestInclusionListProposer,
latestInclusionListSlot: st.LatestInclusionListSlot,
latestBlockHash: bytesutil.ToBytes32(st.LatestBlockHash),
latestFullSlot: st.LatestFullSlot,
executionPayloadHeader: st.ExecutionPayloadHeader,
lastWithdrawalsRoot: bytesutil.ToBytes32(st.LastWithdrawalsRoot),
latestBlockHash: bytesutil.ToBytes32(st.LatestBlockHash),
latestFullSlot: st.LatestFullSlot,
executionPayloadHeader: st.LatestExecutionPayloadHeader,
lastWithdrawalsRoot: bytesutil.ToBytes32(st.LastWithdrawalsRoot),

dirtyFields: make(map[types.FieldIndex]bool, fieldCount),
dirtyIndices: make(map[types.FieldIndex][]uint64, fieldCount),
Expand Down
14 changes: 1 addition & 13 deletions beacon-chain/state/state-native/state_trie_epbs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,15 @@ func Test_InitializeFromProtoEpbs(t *testing.T) {
st := random.BeaconState(t)

// Cache initial values to check against after initialization.
prevInclusionListProposer := st.PreviousInclusionListProposer
prevInclusionListSlot := st.PreviousInclusionListSlot
latestInclusionListProposer := st.LatestInclusionListProposer
latestInclusionListSlot := st.LatestInclusionListSlot
latestBlockHash := st.LatestBlockHash
latestFullSlot := st.LatestFullSlot
header := st.ExecutionPayloadHeader
header := st.LatestExecutionPayloadHeader
lastWithdrawalsRoot := st.LastWithdrawalsRoot

s, err := InitializeFromProtoEpbs(st)
require.NoError(t, err)

// Assert that initial values match those in the new state.
gotPrevInclusionListProposer := s.PreviousInclusionListProposer()
require.Equal(t, prevInclusionListProposer, gotPrevInclusionListProposer)
gotPrevInclusionListSlot := s.PreviousInclusionListSlot()
require.Equal(t, prevInclusionListSlot, gotPrevInclusionListSlot)
gotLatestInclusionListProposer := s.LatestInclusionListProposer()
require.Equal(t, latestInclusionListProposer, gotLatestInclusionListProposer)
gotLatestInclusionListSlot := s.LatestInclusionListSlot()
require.Equal(t, latestInclusionListSlot, gotLatestInclusionListSlot)
gotLatestBlockHash := s.LatestBlockHash()
require.DeepEqual(t, latestBlockHash, gotLatestBlockHash)
gotLatestFullSlot := s.LatestFullSlot()
Expand Down
28 changes: 4 additions & 24 deletions beacon-chain/state/state-native/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,7 @@ func (f FieldIndex) String() string {
return "pendingPartialWithdrawals"
case PendingConsolidations:
return "pendingConsolidations"
case PreviousInclusionListProposer: // ePBS fields start here
return "PreviousInclusionListProposer"
case PreviousInclusionListSlot:
return "PreviousInclusionListSlot"
case LatestInclusionListProposer:
return "LatestInclusionListProposer"
case LatestInclusionListSlot:
return "LatestInclusionListSlot"
case LatestBlockHash:
case LatestBlockHash: // ePBS fields start here
return "LatestBlockHash"
case LatestFullSlot:
return "LatestFullSlot"
Expand Down Expand Up @@ -214,15 +206,7 @@ func (f FieldIndex) RealPosition() int {
return 35
case PendingConsolidations:
return 36
case PreviousInclusionListProposer: // ePBS fields start here
return 37
case PreviousInclusionListSlot:
return 38
case LatestInclusionListProposer:
return 39
case LatestInclusionListSlot:
return 40
case LatestBlockHash:
case LatestBlockHash: // ePBS fields start here
return 41
case LatestFullSlot:
return 42
Expand Down Expand Up @@ -281,6 +265,7 @@ const (
LatestExecutionPayloadHeaderCapella
LatestExecutionPayloadHeaderDeneb
LatestExecutionPayloadHeaderElectra
ExecutionPayloadHeader
NextWithdrawalIndex
NextWithdrawalValidatorIndex
HistoricalSummaries
Expand All @@ -293,13 +278,8 @@ const (
PendingBalanceDeposits // Electra: EIP-7251
PendingPartialWithdrawals // Electra: EIP-7251
PendingConsolidations // Electra: EIP-7251
PreviousInclusionListProposer // ePBS fields start here
PreviousInclusionListSlot
LatestInclusionListProposer
LatestInclusionListSlot
LatestBlockHash
LatestBlockHash // ePBS fields start here
LatestFullSlot
ExecutionPayloadHeader
LastWithdrawalsRoot
)

Expand Down
1 change: 0 additions & 1 deletion config/fieldparams/mainnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const (
MaxBlobsPerBlock = 6 // MaxBlobsPerBlock defines the maximum number of blobs with respect to consensus rule can be included in a block.
MaxBlobCommitmentsPerBlock = 4096 // MaxBlobCommitmentsPerBlock defines the theoretical limit of blobs can be included in a block.
MaxPayloadAttestationsPerBlock = 4 // MAX_PAYLOAD_ATTESTATIONS [New in ePBS]
MaxTransactionsPerInclusionList = 1024 // MAX_TRANSACTIONS_PER_INCLUSION_LIST [New in ePBS]
LogMaxBlobCommitments = 12 // Log_2 of MaxBlobCommitmentsPerBlock
BlobLength = 131072 // BlobLength defines the byte length of a blob.
BlobSize = 131072 // defined to match blob.size in bazel ssz codegen
Expand Down
1 change: 0 additions & 1 deletion config/fieldparams/minimal.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const (
MaxBlobsPerBlock = 6 // MaxBlobsPerBlock defines the maximum number of blobs with respect to consensus rule can be included in a block.
MaxBlobCommitmentsPerBlock = 16 // MaxBlobCommitmentsPerBlock defines the theoretical limit of blobs can be included in a block.
MaxPayloadAttestationsPerBlock = 4 // MAX_PAYLOAD_ATTESTATIONS [New in ePBS]
MaxTransactionsPerInclusionList = 16 // MAX_TRANSACTIONS_PER_INCLUSION_LIST [New in ePBS]
LogMaxBlobCommitments = 4 // Log_2 of MaxBlobCommitmentsPerBlock
BlobLength = 131072 // BlobLength defines the byte length of a blob.
BlobSize = 131072 // defined to match blob.size in bazel ssz codegen
Expand Down
1 change: 1 addition & 0 deletions consensus-types/blocks/getters_epbs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func Test_EpbsBlock_Copy(t *testing.T) {
Slot: 2,
Value: 3,
BlobKzgCommitmentsRoot: bytesutil.PadTo([]byte("blobkzgcommitmentsroot"), fieldparams.RootLength),
GasLimit: 4,
},
Signature: bytesutil.PadTo([]byte("signature"), fieldparams.BLSSignatureLength),
}
Expand Down
Loading

0 comments on commit ef2ac39

Please sign in to comment.