-
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
9895c89
commit 3772f13
Showing
30 changed files
with
1,058 additions
and
64 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 ReadOnlyEpbs interface { | ||
PreviousInclusionListSlot() (primitives.Slot, error) | ||
PreviousInclusionListProposer() (primitives.ValidatorIndex, error) | ||
LatestInclusionListSlot() (primitives.Slot, error) | ||
LatestInclusionListProposer() (primitives.ValidatorIndex, error) | ||
IsParentBlockFull() (bool, error) | ||
ExecutionPayloadHeader() (*enginev1.ExecutionPayloadHeaderEPBS, error) | ||
LatestBlockHash() ([]byte, error) | ||
LatestFullSlot() (primitives.Slot, error) | ||
LastWithdrawalsRoot() ([]byte, error) | ||
} | ||
|
||
type WriteOnlyEpbs interface { | ||
SetExecutionPayloadHeader(val *enginev1.ExecutionPayloadHeaderEPBS) error | ||
UpdatePreviousInclusionListData() error | ||
SetLatestInclusionListSlot(val primitives.Slot) error | ||
SetLatestInclusionListProposer(val primitives.ValidatorIndex) error | ||
SetLatestBlockHash(val []byte) error | ||
SetLatestFullSlot(val primitives.Slot) error | ||
SetLastWithdrawalsRoot(val []byte) error | ||
} |
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,122 @@ | ||
package state_native | ||
|
||
import ( | ||
"github.com/pkg/errors" | ||
consensus_types "github.com/prysmaticlabs/prysm/v5/consensus-types" | ||
"github.com/prysmaticlabs/prysm/v5/consensus-types/primitives" | ||
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" | ||
enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1" | ||
"github.com/prysmaticlabs/prysm/v5/runtime/version" | ||
) | ||
|
||
// 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, error) { | ||
if b.version < version.EPBS { | ||
return nil, errors.Wrapf(consensus_types.ErrUnsupportedField, "ExecutionPayloadHeader not supported for version: %d", b.version) | ||
} | ||
|
||
b.lock.RLock() | ||
defer b.lock.RUnlock() | ||
|
||
return b.executionPayloadHeaderVal(), nil | ||
} | ||
|
||
// 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, error) { | ||
if b.version < version.EPBS { | ||
return false, errors.Wrapf(consensus_types.ErrUnsupportedField, "IsParentBlockFull not supported for version: %d", b.version) | ||
} | ||
|
||
b.lock.RLock() | ||
defer b.lock.RUnlock() | ||
|
||
headerBlockHash := bytesutil.ToBytes32(b.executionPayloadHeader.BlockHash) | ||
return headerBlockHash == b.latestBlockHash, nil | ||
} | ||
|
||
// LatestInclusionListProposer returns the proposer index from the latest inclusion list. | ||
func (b *BeaconState) LatestInclusionListProposer() (primitives.ValidatorIndex, error) { | ||
if b.version < version.EPBS { | ||
return 0, errors.Wrapf(consensus_types.ErrUnsupportedField, "LatestInclusionListProposer not supported for version: %d", b.version) | ||
} | ||
|
||
b.lock.RLock() | ||
defer b.lock.RUnlock() | ||
|
||
return b.latestInclusionListProposer, nil | ||
} | ||
|
||
// LatestInclusionListSlot returns the slot from the latest inclusion list. | ||
func (b *BeaconState) LatestInclusionListSlot() (primitives.Slot, error) { | ||
if b.version < version.EPBS { | ||
return 0, errors.Wrapf(consensus_types.ErrUnsupportedField, "LatestInclusionListSlot not supported for version: %d", b.version) | ||
} | ||
|
||
b.lock.RLock() | ||
defer b.lock.RUnlock() | ||
|
||
return b.latestInclusionListSlot, nil | ||
} | ||
|
||
// PreviousInclusionListProposer returns the proposer index from the previous inclusion list. | ||
func (b *BeaconState) PreviousInclusionListProposer() (primitives.ValidatorIndex, error) { | ||
if b.version < version.EPBS { | ||
return 0, errors.Wrapf(consensus_types.ErrUnsupportedField, "PreviousInclusionListProposer not supported for version: %d", b.version) | ||
} | ||
|
||
b.lock.RLock() | ||
defer b.lock.RUnlock() | ||
|
||
return b.previousInclusionListProposer, nil | ||
} | ||
|
||
// PreviousInclusionListSlot returns the slot from the previous inclusion list. | ||
func (b *BeaconState) PreviousInclusionListSlot() (primitives.Slot, error) { | ||
if b.version < version.EPBS { | ||
return 0, errors.Wrapf(consensus_types.ErrUnsupportedField, "PreviousInclusionListSlot not supported for version: %d", b.version) | ||
} | ||
|
||
b.lock.RLock() | ||
defer b.lock.RUnlock() | ||
|
||
return b.previousInclusionListSlot, nil | ||
} | ||
|
||
// LatestBlockHash returns the latest block hash. | ||
func (b *BeaconState) LatestBlockHash() ([]byte, error) { | ||
if b.version < version.EPBS { | ||
return nil, errors.Wrapf(consensus_types.ErrUnsupportedField, "LatestBlockHash not supported for version: %d", b.version) | ||
} | ||
|
||
b.lock.RLock() | ||
defer b.lock.RUnlock() | ||
|
||
return b.latestBlockHash[:], nil | ||
} | ||
|
||
// LatestFullSlot returns the slot of the latest full block. | ||
func (b *BeaconState) LatestFullSlot() (primitives.Slot, error) { | ||
if b.version < version.EPBS { | ||
return 0, errors.Wrapf(consensus_types.ErrUnsupportedField, "LatestFullSlot not supported for version: %d", b.version) | ||
} | ||
|
||
b.lock.RLock() | ||
defer b.lock.RUnlock() | ||
|
||
return b.latestFullSlot, nil | ||
} | ||
|
||
// LastWithdrawalsRoot returns the latest withdrawal root. | ||
func (b *BeaconState) LastWithdrawalsRoot() ([]byte, error) { | ||
if b.version < version.EPBS { | ||
return nil, errors.Wrapf(consensus_types.ErrUnsupportedField, "LastWithdrawalsRoot not supported for version: %d", b.version) | ||
} | ||
|
||
b.lock.RLock() | ||
defer b.lock.RUnlock() | ||
|
||
return b.lastWithdrawalsRoot[:], 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
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) | ||
} |
Oops, something went wrong.