Skip to content

Commit

Permalink
executionPayloadHeader
Browse files Browse the repository at this point in the history
Signed-off-by: nidhi-singh02 <[email protected]>
  • Loading branch information
nidhi-singh02 committed Sep 20, 2024
1 parent dc4a4c5 commit 8329623
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 1 deletion.
10 changes: 10 additions & 0 deletions mod/cli/pkg/commands/genesis/payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package genesis

import (
"fmt"
"unsafe"

"github.com/berachain/beacon-kit/mod/cli/pkg/context"
Expand Down Expand Up @@ -58,6 +59,8 @@ func AddExecutionPayloadCmd(chainSpec common.ChainSpec) *cobra.Command {
}
genesisBlock := ethGenesis.ToBlock()

fmt.Printf("genesis Block nidz %v", genesisBlock.Time())

// Create the execution payload.
payload := gethprimitives.BlockToExecutableData(
genesisBlock,
Expand All @@ -74,6 +77,8 @@ func AddExecutionPayloadCmd(chainSpec common.ChainSpec) *cobra.Command {
return errors.Wrap(err, "failed to read genesis doc from file")
}

fmt.Printf("\n appGenesis %v \n ", appGenesis.GenesisTime)

// create the app state
appGenesisState, err := genutiltypes.GenesisStateFromAppGenesis(
appGenesis,
Expand All @@ -82,6 +87,8 @@ func AddExecutionPayloadCmd(chainSpec common.ChainSpec) *cobra.Command {
return err
}

fmt.Printf("appGenesisState %v \n ", appGenesisState)

genesisInfo := &types.Genesis[
*types.Deposit, *types.ExecutionPayloadHeader,
]{}
Expand All @@ -92,6 +99,9 @@ func AddExecutionPayloadCmd(chainSpec common.ChainSpec) *cobra.Command {
return errors.Wrap(err, "failed to unmarshal beacon state")
}

fmt.Printf("payload nidz %v \n ", payload.Timestamp)

fmt.Printf("genesisInfo nids %v \n ", genesisInfo)
// Inject the execution payload.
genesisInfo.ExecutionPayloadHeader = executableDataToExecutionPayloadHeader(
version.ToUint32(genesisInfo.ForkVersion),
Expand Down
19 changes: 19 additions & 0 deletions mod/node-api/backend/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package backend

import (
"fmt"
"github.com/berachain/beacon-kit/mod/primitives/pkg/common"
"github.com/berachain/beacon-kit/mod/primitives/pkg/math"
)
Expand Down Expand Up @@ -56,9 +57,27 @@ func (b Backend[
func (b Backend[
_, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _, _,
]) GetGenesisTime(slot math.Slot) (uint64, error) {

//state := b.sb.StateFromContext(ctx)
//if state == nil {
// fmt.Errorf("Failed to retrieve beacon state")
// return 0, errors.New("failed to retrieve beacon state")
//}
//
//genesisTime, err := state.GetGenesisTime()
//if err != nil {
// fmt.Errorf("Failed to get genesis time", err)
// return 0, err
//}
//
//fmt.Printf("Retrieved genesis time %v", genesisTime)
//return genesisTime, nil

st, _, err := b.stateFromSlot(slot)
if err != nil {
return 0, err
}

fmt.Printf("state nidzi %v", st)
return st.GetGenesisTime()
}
13 changes: 13 additions & 0 deletions mod/node-api/handlers/beacon/genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package beacon

import (
"encoding/hex"
"github.com/berachain/beacon-kit/mod/errors"
"strconv"

beacontypes "github.com/berachain/beacon-kit/mod/node-api/handlers/beacon/types"
Expand All @@ -48,6 +49,18 @@ func (h *Handler[_, ContextT, _, _]) GetGenesis(_ ContextT) (any, error) {
if err != nil {
return nil, err
}

if genesisTime == 0 {
h.Logger().Warn("Genesis time is 0, this may indicate an initialization issue")
// Optionally, you might want to return an error here instead of continuing
return nil, errors.New("genesis time not properly initialized")
}

h.Logger().Info("Retrieved genesis data",
"genesisTime", genesisTime,
"genesisValidatorsRoot", genesisRoot,
"genesisForkVersion", genesisForkVersionHex)

return types.Wrap(beacontypes.GenesisData{
GenesisTime: strconv.FormatUint(genesisTime, 10),
GenesisValidatorsRoot: genesisRoot,
Expand Down
10 changes: 9 additions & 1 deletion mod/state-transition/pkg/core/state_processor_genesis.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
package core

import (
"fmt"
"github.com/berachain/beacon-kit/mod/primitives/pkg/common"
"github.com/berachain/beacon-kit/mod/primitives/pkg/constants"
"github.com/berachain/beacon-kit/mod/primitives/pkg/encoding/hex"
Expand All @@ -47,6 +48,10 @@ func (sp *StateProcessor[
executionPayloadHeader ExecutionPayloadHeaderT,
genesisVersion common.Version,
) (transition.ValidatorUpdates, error) {

fmt.Printf("Execution Payload Header %v %v %v %v\n",
executionPayloadHeader.GetTimestamp(), executionPayloadHeader.GetBlockHash())

var (
blkHeader BeaconBlockHeaderT
blkBody BeaconBlockBodyT
Expand Down Expand Up @@ -152,7 +157,10 @@ func (sp *StateProcessor[
return nil, err
}

if err = st.SetGenesisTime(uint64(executionPayloadHeader.GetTimestamp())); err != nil {
genesisTime := uint64(executionPayloadHeader.GetTimestamp())
fmt.Printf("Setting genesis time %v", genesisTime)
if err = st.SetGenesisTime(genesisTime); err != nil {
fmt.Errorf("failed to set genesis time %v", err)
return nil, err
}

Expand Down

0 comments on commit 8329623

Please sign in to comment.