-
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.
- Loading branch information
1 parent
4cac646
commit 58a1b2f
Showing
25 changed files
with
1,073 additions
and
95 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,28 @@ | ||
package state | ||
|
||
import ( | ||
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" | ||
enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1" | ||
) | ||
|
||
type ReadOnlyEpbsFields interface { | ||
PreviousInclusionListSlot() primitives.Slot | ||
PreviousInclusionListProposer() primitives.ValidatorIndex | ||
LatestInclusionListSlot() primitives.Slot | ||
LatestInclusionListProposer() primitives.ValidatorIndex | ||
IsParentBlockFull() bool | ||
ExecutionPayloadHeader() *enginev1.ExecutionPayloadHeaderEPBS | ||
LatestBlockHash() []byte | ||
LatestFullSlot() primitives.Slot | ||
LastWithdrawalsRoot() []byte | ||
} | ||
|
||
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) | ||
} |
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,83 @@ | ||
package state_native | ||
|
||
import ( | ||
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" | ||
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" | ||
enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1" | ||
) | ||
|
||
// ExecutionPayloadHeader retrieves a copy of the execution payload header. | ||
// It returns an error if the operation is not supported for the beacon state's version. | ||
func (b *BeaconState) ExecutionPayloadHeader() *enginev1.ExecutionPayloadHeaderEPBS { | ||
b.lock.RLock() | ||
defer b.lock.RUnlock() | ||
|
||
return b.executionPayloadHeaderVal() | ||
} | ||
|
||
// IsParentBlockFull checks if the last committed payload header was fulfilled. | ||
// Returns true if both the beacon block and payload were present. | ||
// Call this function on a beacon state before processing the execution payload header. | ||
func (b *BeaconState) IsParentBlockFull() bool { | ||
b.lock.RLock() | ||
defer b.lock.RUnlock() | ||
|
||
headerBlockHash := bytesutil.ToBytes32(b.executionPayloadHeader.BlockHash) | ||
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() | ||
defer b.lock.RUnlock() | ||
|
||
return b.latestBlockHash[:] | ||
} | ||
|
||
// LatestFullSlot returns the slot of the latest full block. | ||
func (b *BeaconState) LatestFullSlot() primitives.Slot { | ||
b.lock.RLock() | ||
defer b.lock.RUnlock() | ||
|
||
return b.latestFullSlot | ||
} | ||
|
||
// LastWithdrawalsRoot returns the latest withdrawal root. | ||
func (b *BeaconState) LastWithdrawalsRoot() []byte { | ||
b.lock.RLock() | ||
defer b.lock.RUnlock() | ||
|
||
return b.lastWithdrawalsRoot[:] | ||
} |
10 changes: 10 additions & 0 deletions
10
beacon-chain/state/state-native/getters_payload_header_epbs.go
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,10 @@ | ||
package state_native | ||
|
||
import ( | ||
enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1" | ||
eth "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" | ||
) | ||
|
||
func (b *BeaconState) executionPayloadHeaderVal() *enginev1.ExecutionPayloadHeaderEPBS { | ||
return eth.CopyExecutionPayloadHeaderEPBS(b.executionPayloadHeader) | ||
} |
104 changes: 104 additions & 0 deletions
104
beacon-chain/state/state-native/getters_setters_epbs_test.go
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,104 @@ | ||
package state_native | ||
|
||
import ( | ||
"crypto/rand" | ||
"testing" | ||
|
||
"github.com/prysmaticlabs/prysm/v5/beacon-chain/state/state-native/types" | ||
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" | ||
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" | ||
"github.com/prysmaticlabs/prysm/v5/runtime/version" | ||
"github.com/prysmaticlabs/prysm/v5/testing/require" | ||
"github.com/prysmaticlabs/prysm/v5/testing/util/random" | ||
) | ||
|
||
func Test_LatestExecutionPayloadHeader(t *testing.T) { | ||
s := &BeaconState{version: version.EPBS} | ||
_, err := s.LatestExecutionPayloadHeader() | ||
require.ErrorContains(t, "unsupported version (epbs) for latest execution payload header", err) | ||
} | ||
|
||
func Test_SetLatestExecutionPayloadHeader(t *testing.T) { | ||
s := &BeaconState{version: version.EPBS} | ||
require.ErrorContains(t, "SetLatestExecutionPayloadHeader is not supported for epbs", s.SetLatestExecutionPayloadHeader(nil)) | ||
} | ||
|
||
func Test_SetExecutionPayloadHeader(t *testing.T) { | ||
s := &BeaconState{version: version.EPBS, dirtyFields: make(map[types.FieldIndex]bool)} | ||
header := random.ExecutionPayloadHeader(t) | ||
s.SetExecutionPayloadHeader(header) | ||
require.Equal(t, true, s.dirtyFields[types.ExecutionPayloadHeader]) | ||
|
||
got := s.ExecutionPayloadHeader() | ||
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) | ||
_, err := rand.Read(b) | ||
require.NoError(t, err) | ||
s.SetLatestBlockHash(b) | ||
require.Equal(t, true, s.dirtyFields[types.LatestBlockHash]) | ||
|
||
got := s.LatestBlockHash() | ||
require.DeepEqual(t, got, b) | ||
} | ||
|
||
func Test_SetLatestFullSlot(t *testing.T) { | ||
s := &BeaconState{version: version.EPBS, dirtyFields: make(map[types.FieldIndex]bool)} | ||
s.SetLatestFullSlot(3) | ||
require.Equal(t, true, s.dirtyFields[types.LatestFullSlot]) | ||
|
||
got := s.LatestFullSlot() | ||
require.Equal(t, primitives.Slot(3), got) | ||
} | ||
|
||
func Test_SetLastWithdrawalsRoot(t *testing.T) { | ||
s := &BeaconState{version: version.EPBS, dirtyFields: make(map[types.FieldIndex]bool)} | ||
b := make([]byte, fieldparams.RootLength) | ||
_, err := rand.Read(b) | ||
require.NoError(t, err) | ||
s.SetLastWithdrawalsRoot(b) | ||
require.Equal(t, true, s.dirtyFields[types.LastWithdrawalsRoot]) | ||
|
||
got := s.LastWithdrawalsRoot() | ||
require.DeepEqual(t, got, b) | ||
} |
Oops, something went wrong.