Skip to content

Commit

Permalink
chore(state-transition): you know what this is (berachain#1676)
Browse files Browse the repository at this point in the history
  • Loading branch information
ocnc authored Jul 3, 2024
1 parent 556618d commit 9415dd6
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 78 deletions.
1 change: 0 additions & 1 deletion mod/node-core/pkg/components/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func ProvideStateProcessor(
*BeaconBlockBody,
*BeaconBlockHeader,
BeaconState,
*BlobSidecars,
*transition.Context,
*Deposit,
*types.Eth1Data,
Expand Down
26 changes: 12 additions & 14 deletions mod/state-transition/pkg/core/state_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ type StateProcessor[
ExecutionPayloadHeaderT, ForkT,
ValidatorT, WithdrawalT,
],
BlobSidecarsT BlobSidecars,
ContextT Context,
DepositT Deposit[ForkDataT, WithdrawalCredentialsT],
Eth1DataT interface {
Expand Down Expand Up @@ -97,7 +96,6 @@ func NewStateProcessor[
BeaconBlockHeaderT, Eth1DataT, ExecutionPayloadHeaderT, ForkT,
ValidatorT, WithdrawalT,
],
BlobSidecarsT BlobSidecars,
ContextT Context,
DepositT Deposit[ForkDataT, WithdrawalCredentialsT],
Eth1DataT interface {
Expand All @@ -123,13 +121,13 @@ func NewStateProcessor[
signer crypto.BLSSigner,
) *StateProcessor[
BeaconBlockT, BeaconBlockBodyT, BeaconBlockHeaderT,
BeaconStateT, BlobSidecarsT, ContextT,
BeaconStateT, ContextT,
DepositT, Eth1DataT, ExecutionPayloadT, ExecutionPayloadHeaderT,
ForkT, ForkDataT, ValidatorT, WithdrawalT, WithdrawalCredentialsT,
] {
return &StateProcessor[
BeaconBlockT, BeaconBlockBodyT, BeaconBlockHeaderT,
BeaconStateT, BlobSidecarsT, ContextT,
BeaconStateT, ContextT,
DepositT, Eth1DataT, ExecutionPayloadT, ExecutionPayloadHeaderT,
ForkT, ForkDataT, ValidatorT, WithdrawalT,
WithdrawalCredentialsT,
Expand All @@ -144,9 +142,9 @@ func NewStateProcessor[
// Transition is the main function for processing a state transition.
func (sp *StateProcessor[
BeaconBlockT, BeaconBlockBodyT, BeaconBlockHeaderT,
BeaconStateT, BlobSidecarsT, ContextT,
DepositT, Eth1DataT, ExecutionPayloadT, ExecutionPayloadHeaderT,
ForkT, ForkDataT, ValidatorT, WithdrawalT, WithdrawalCredentialsT,
BeaconStateT, ContextT, DepositT, Eth1DataT,
ExecutionPayloadT, ExecutionPayloadHeaderT, ForkT,
ForkDataT, ValidatorT, WithdrawalT, WithdrawalCredentialsT,
]) Transition(
ctx ContextT,
st BeaconStateT,
Expand Down Expand Up @@ -174,7 +172,7 @@ func (sp *StateProcessor[
}

func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _,
]) ProcessSlots(
st BeaconStateT, slot math.U64,
) (transition.ValidatorUpdates, error) {
Expand Down Expand Up @@ -219,7 +217,7 @@ func (sp *StateProcessor[

// processSlot is run when a slot is missed.
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _,
]) processSlot(
st BeaconStateT,
) error {
Expand Down Expand Up @@ -276,7 +274,7 @@ func (sp *StateProcessor[
// ProcessBlock processes the block, it optionally verifies the
// state root.
func (sp *StateProcessor[
BeaconBlockT, _, _, BeaconStateT, _, ContextT, _, _, _, _, _, _, _, _, _,
BeaconBlockT, _, _, BeaconStateT, ContextT, _, _, _, _, _, _, _, _, _,
]) ProcessBlock(
ctx ContextT,
st BeaconStateT,
Expand Down Expand Up @@ -344,7 +342,7 @@ func (sp *StateProcessor[

// processEpoch processes the epoch and ensures it matches the local state.
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _,
]) processEpoch(
st BeaconStateT,
) (transition.ValidatorUpdates, error) {
Expand All @@ -362,7 +360,7 @@ func (sp *StateProcessor[
// state.
func (sp *StateProcessor[
BeaconBlockT, _, BeaconBlockHeaderT, BeaconStateT,
_, _, _, _, _, _, _, _, ValidatorT, _, _,
_, _, _, _, _, _, _, ValidatorT, _, _,
]) processBlockHeader(
st BeaconStateT,
blk BeaconBlockT,
Expand Down Expand Up @@ -448,7 +446,7 @@ func (sp *StateProcessor[
//
//nolint:lll
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _,
]) getAttestationDeltas(
st BeaconStateT,
) ([]math.Gwei, []math.Gwei, error) {
Expand All @@ -466,7 +464,7 @@ func (sp *StateProcessor[
//
//nolint:lll
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _,
]) processRewardsAndPenalties(
st BeaconStateT,
) error {
Expand Down
2 changes: 1 addition & 1 deletion mod/state-transition/pkg/core/state_processor_committee.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

// processSyncCommitteeUpdates processes the sync committee updates.
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, ValidatorT, _, _,
_, _, _, BeaconStateT, _, _, _, _, _, _, _, ValidatorT, _, _,
]) processSyncCommitteeUpdates(
st BeaconStateT,
) (transition.ValidatorUpdates, error) {
Expand Down
2 changes: 1 addition & 1 deletion mod/state-transition/pkg/core/state_processor_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
//
//nolint:gocognit,funlen // todo fix.
func (sp *StateProcessor[
_, BeaconBlockBodyT, BeaconBlockHeaderT, BeaconStateT, _, _, DepositT,
_, BeaconBlockBodyT, BeaconBlockHeaderT, BeaconStateT, _, DepositT,
Eth1DataT, _, ExecutionPayloadHeaderT, ForkT, _, ValidatorT, _, _,
]) InitializePreminedBeaconStateFromEth1(
st BeaconStateT,
Expand Down
4 changes: 2 additions & 2 deletions mod/state-transition/pkg/core/state_processor_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
// processExecutionPayload processes the execution payload and ensures it
// matches the local state.
func (sp *StateProcessor[
BeaconBlockT, _, _, BeaconStateT, _, ContextT,
BeaconBlockT, _, _, BeaconStateT, ContextT,
_, _, _, ExecutionPayloadHeaderT, _, _, _, _, _,
]) processExecutionPayload(
ctx ContextT,
Expand Down Expand Up @@ -76,7 +76,7 @@ func (sp *StateProcessor[
// and the execution engine.
func (sp *StateProcessor[
BeaconBlockT, _, _, BeaconStateT,
_, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _,
]) validateExecutionPayload(
ctx context.Context,
st BeaconStateT,
Expand Down
6 changes: 3 additions & 3 deletions mod/state-transition/pkg/core/state_processor_randao.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import (
// ensures it matches the local state.
func (sp *StateProcessor[
BeaconBlockT, _, _, BeaconStateT,
_, _, _, _, _, _, _, ForkDataT, _, _, _,
_, _, _, _, _, _, ForkDataT, _, _, _,
]) processRandaoReveal(
st BeaconStateT,
blk BeaconBlockT,
Expand Down Expand Up @@ -105,7 +105,7 @@ func (sp *StateProcessor[
//
//nolint:lll
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _,
]) processRandaoMixesReset(
st BeaconStateT,
) error {
Expand All @@ -129,7 +129,7 @@ func (sp *StateProcessor[

// buildRandaoMix as defined in the Ethereum 2.0 specification.
func (sp *StateProcessor[
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, _, _, _, _, _, _, _, _, _, _, _,
]) buildRandaoMix(
mix common.Bytes32,
reveal crypto.BLSSignature,
Expand Down
10 changes: 5 additions & 5 deletions mod/state-transition/pkg/core/state_processor_slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
//
//nolint:lll
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _,
]) processSlashingsReset(
st BeaconStateT,
) error {
Expand All @@ -48,7 +48,7 @@ func (sp *StateProcessor[
//
//nolint:lll,unused // will be used later
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _,
]) processProposerSlashing(
_ BeaconStateT,
// ps ProposerSlashing,
Expand All @@ -61,7 +61,7 @@ func (sp *StateProcessor[
//
//nolint:lll,unused // will be used later
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _,
]) processAttesterSlashing(
_ BeaconStateT,
// as AttesterSlashing,
Expand All @@ -77,7 +77,7 @@ func (sp *StateProcessor[
//
//nolint:lll,unused // will be used later
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _,
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _,
]) processSlashings(
st BeaconStateT,
) error {
Expand Down Expand Up @@ -130,7 +130,7 @@ func (sp *StateProcessor[
//
//nolint:unused // will be used later
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, _, _, _, _, _, _, ValidatorT, _, _,
_, _, _, BeaconStateT, _, _, _, _, _, _, _, ValidatorT, _, _,
]) processSlash(
st BeaconStateT,
val ValidatorT,
Expand Down
14 changes: 7 additions & 7 deletions mod/state-transition/pkg/core/state_processor_staking.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
// processOperations processes the operations and ensures they match the
// local state.
func (sp *StateProcessor[
BeaconBlockT, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _,
BeaconBlockT, _, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _,
]) processOperations(
st BeaconStateT,
blk BeaconBlockT,
Expand Down Expand Up @@ -62,7 +62,7 @@ func (sp *StateProcessor[
// processDeposits processes the deposits and ensures they match the
// local state.
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, DepositT, _, _, _, _, _, _, _, _,
_, _, _, BeaconStateT, _, DepositT, _, _, _, _, _, _, _, _,
]) processDeposits(
st BeaconStateT,
deposits []DepositT,
Expand All @@ -78,7 +78,7 @@ func (sp *StateProcessor[

// processDeposit processes the deposit and ensures it matches the local state.
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, DepositT, _, _, _, _, _, _, _, _,
_, _, _, BeaconStateT, _, DepositT, _, _, _, _, _, _, _, _,
]) processDeposit(
st BeaconStateT,
dep DepositT,
Expand Down Expand Up @@ -110,7 +110,7 @@ func (sp *StateProcessor[

// applyDeposit processes the deposit and ensures it matches the local state.
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, DepositT, _, _, _, _, _, ValidatorT, _, _,
_, _, _, BeaconStateT, _, DepositT, _, _, _, _, _, ValidatorT, _, _,
]) applyDeposit(
st BeaconStateT,
dep DepositT,
Expand All @@ -137,7 +137,7 @@ func (sp *StateProcessor[

// createValidator creates a validator if the deposit is valid.
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, DepositT, _, _, _, _, ForkDataT, _, _, _,
_, _, _, BeaconStateT, _, DepositT, _, _, _, _, ForkDataT, _, _, _,
]) createValidator(
st BeaconStateT,
dep DepositT,
Expand Down Expand Up @@ -188,7 +188,7 @@ func (sp *StateProcessor[

// addValidatorToRegistry adds a validator to the registry.
func (sp *StateProcessor[
_, _, _, BeaconStateT, _, _, DepositT, _, _, _, _, _, ValidatorT, _, _,
_, _, _, BeaconStateT, _, DepositT, _, _, _, _, _, ValidatorT, _, _,
]) addValidatorToRegistry(
st BeaconStateT,
dep DepositT,
Expand Down Expand Up @@ -219,7 +219,7 @@ func (sp *StateProcessor[
//
//nolint:lll
func (sp *StateProcessor[
_, BeaconBlockBodyT, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _, _,
_, BeaconBlockBodyT, _, BeaconStateT, _, _, _, _, _, _, _, _, _, _,
]) processWithdrawals(
st BeaconStateT,
body BeaconBlockBodyT,
Expand Down
45 changes: 1 addition & 44 deletions mod/state-transition/pkg/core/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,6 @@ import (
"github.com/berachain/beacon-kit/mod/primitives/pkg/ssz/merkleizer"
)

// The AvailabilityStore interface is responsible for validating and storing
// sidecars for specific blocks, as well as verifying sidecars that have already
// been stored.
type AvailabilityStore[BeaconBlockBodyT any, BlobSidecarsT any] interface {
// IsDataAvailable ensures that all blobs referenced in the block are
// securely stored before it returns without an error.
IsDataAvailable(
context.Context, math.Slot, BeaconBlockBodyT,
) bool

// Persist makes sure that the sidecar remains accessible for data
// availability checks throughout the beacon node's operation.
Persist(math.Slot, BlobSidecarsT) error
}

// BeaconBlock represents a generic interface for a beacon block.
type BeaconBlock[
DepositT any,
Expand Down Expand Up @@ -82,9 +67,7 @@ type BeaconBlockBody[
ExecutionPayloadT ExecutionPayload[
ExecutionPayloadT, ExecutionPayloadHeaderT, WithdrawalT,
],
ExecutionPayloadHeaderT interface {
GetBlockHash() gethprimitives.ExecutionHash
},
ExecutionPayloadHeaderT ExecutionPayloadHeader,
WithdrawalT any,
] interface {
constraints.EmptyWithVersion[BeaconBlockBodyT]
Expand All @@ -100,11 +83,6 @@ type BeaconBlockBody[
GetBlobKzgCommitments() eip4844.KZGCommitments[gethprimitives.ExecutionHash]
}

// BlobSidecars is the interface for blobs sidecars.
type BlobSidecars interface {
Len() int
}

// Context defines an interface for managing state transition context.
type Context interface {
context.Context
Expand All @@ -122,9 +100,6 @@ type Context interface {
// GetSkipValidateResult returns whether to validate the result of the state
// transition.
GetSkipValidateResult() bool

// Unwrap returns the underlying golang standard library context.
Unwrap() context.Context
}

// Deposit is the interface for a deposit.
Expand All @@ -134,12 +109,8 @@ type Deposit[
] interface {
// GetAmount returns the amount of the deposit.
GetAmount() math.Gwei
// GetIndex returns the index of the deposit.
GetIndex() uint64
// GetPubkey returns the public key of the validator.
GetPubkey() crypto.BLSPubkey
// GetSignature returns the signature of the deposit.
GetSignature() crypto.BLSSignature
// GetWithdrawalCredentials returns the withdrawal credentials.
GetWithdrawalCredentials() WithdrawlCredentialsT
// VerifySignature verifies the deposit and creates a validator.
Expand Down Expand Up @@ -181,21 +152,7 @@ type ExecutionPayload[
}

type ExecutionPayloadHeader interface {
GetParentHash() gethprimitives.ExecutionHash
GetBlockHash() gethprimitives.ExecutionHash
GetPrevRandao() common.Bytes32
GetFeeRecipient() gethprimitives.ExecutionAddress
GetStateRoot() common.Bytes32
GetReceiptsRoot() common.Root
GetLogsBloom() []byte
GetNumber() math.U64
GetGasLimit() math.U64
GetTimestamp() math.U64
GetGasUsed() math.U64
GetExtraData() []byte
GetBaseFeePerGas() math.U256L
GetBlobGasUsed() math.U64
GetExcessBlobGas() math.U64
}

// ExecutionEngine is the interface for the execution engine.
Expand Down

0 comments on commit 9415dd6

Please sign in to comment.