Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions beacon-chain/blockchain/execution_engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package blockchain

import (
"context"
"crypto/sha256"
"fmt"

"github.com/pkg/errors"
Expand Down Expand Up @@ -213,12 +214,16 @@ func (s *Service) notifyNewPayload(ctx context.Context, preStateVersion int,

var lastValidHash []byte
if blk.Version() >= version.Deneb {
_, err = blk.Block().Body().BlobKzgCommitments()
var kzgs [][]byte
kzgs, err = blk.Block().Body().BlobKzgCommitments()
if err != nil {
return false, errors.Wrap(invalidBlock{error: err}, "could not get blob kzg commitments")
}
// TODO: Convert kzg commitment to version hashes and feed to below
lastValidHash, err = s.cfg.ExecutionEngineCaller.NewPayload(ctx, payload, [][32]byte{})
versionedHashes := make([][32]byte, len(kzgs))
for i := range versionedHashes {
versionedHashes[i] = kzgToVersionedHash(kzgs[i])
}
lastValidHash, err = s.cfg.ExecutionEngineCaller.NewPayload(ctx, payload, versionedHashes)
} else {
lastValidHash, err = s.cfg.ExecutionEngineCaller.NewPayload(ctx, payload, [][32]byte{} /*empty version hashes before Deneb*/)
}
Expand Down Expand Up @@ -371,3 +376,14 @@ func (s *Service) removeInvalidBlockAndState(ctx context.Context, blkRoots [][32
}
return nil
}

const (
blobCommitmentVersionKZG uint8 = 0x01
)

// kzgToVersionedHash implements kzg_to_versioned_hash from EIP-4844
func kzgToVersionedHash(kzg []byte) (h [32]byte) {
h = sha256.Sum256(kzg)
h[0] = blobCommitmentVersionKZG
return
}
6 changes: 0 additions & 6 deletions beacon-chain/db/kv/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ func (s *Store) SaveBlobSidecar(ctx context.Context, scs []*ethpb.BlobSidecar) e
return err
}

slot := scs[0].Slot
return s.db.Update(func(tx *bolt.Tx) error {
encodedBlobSidecar, err := encode(ctx, &ethpb.BlobSidecars{Sidecars: scs})
if err != nil {
Expand All @@ -47,11 +46,6 @@ func (s *Store) SaveBlobSidecar(ctx context.Context, scs []*ethpb.BlobSidecar) e
for k, _ := c.Seek(rotatingBufferPrefix); bytes.HasPrefix(k, rotatingBufferPrefix); k, _ = c.Next() {
if len(k) != 0 {
replacingKey = k
oldSlotBytes := replacingKey[8:16]
oldSlot := bytesutil.BytesToSlotBigEndian(oldSlotBytes)
if oldSlot >= slot {
return fmt.Errorf("attempted to save blob with slot %d but already have older blob with slot %d", slot, oldSlot)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know this was a workaround for devnet, but is this behavior we want in prod? Presumably we protect this invariant as part of our circular buffer design, cc @rauljordan

break
}
}
Expand Down
10 changes: 0 additions & 10 deletions beacon-chain/db/kv/blob_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,16 +157,6 @@ func TestStore_BlobSidecars(t *testing.T) {
require.ErrorIs(t, ErrNotFound, err)
require.Equal(t, 0, len(got))
})
t.Run("saving a blob with older slot", func(t *testing.T) {
db := setupDB(t)
scs := generateBlobSidecars(t, fieldparams.MaxBlobsPerBlock)
require.NoError(t, db.SaveBlobSidecar(ctx, scs))
require.Equal(t, int(fieldparams.MaxBlobsPerBlock), len(scs))
got, err := db.BlobSidecarsByRoot(ctx, bytesutil.ToBytes32(scs[0].BlockRoot))
require.NoError(t, err)
require.NoError(t, equalBlobSlices(scs, got))
require.ErrorContains(t, "but already have older blob with slot", db.SaveBlobSidecar(ctx, scs))
})
t.Run("saving a new blob for rotation", func(t *testing.T) {
db := setupDB(t)
scs := generateBlobSidecars(t, fieldparams.MaxBlobsPerBlock)
Expand Down
5 changes: 5 additions & 0 deletions beacon-chain/execution/engine_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,10 @@ func fullPayloadFromExecutionBlock(
if err != nil {
return nil, errors.Wrap(err, "unable to extract ExcessDataGas attribute from excution payload header")
}
dgu, err := header.DataGasUsed()
if err != nil {
return nil, errors.Wrap(err, "unable to extract DataGasUsed attribute from excution payload header")
}
return blocks.WrappedExecutionPayloadDeneb(
&pb.ExecutionPayloadDeneb{
ParentHash: header.ParentHash(),
Expand All @@ -773,6 +777,7 @@ func fullPayloadFromExecutionBlock(
Transactions: txs,
Withdrawals: block.Withdrawals,
ExcessDataGas: edg,
DataGasUsed: dgu,
}, 0) // We can't get the block value and don't care about the block value for this instance
default:
return nil, fmt.Errorf("unknown execution block version %d", block.Version)
Expand Down
3 changes: 2 additions & 1 deletion beacon-chain/p2p/fork_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ func (s *Service) forkWatcher() {
currEpoch := slots.ToEpoch(currSlot)
if currEpoch == params.BeaconConfig().AltairForkEpoch ||
currEpoch == params.BeaconConfig().BellatrixForkEpoch ||
currEpoch == params.BeaconConfig().CapellaForkEpoch {
currEpoch == params.BeaconConfig().CapellaForkEpoch ||
currEpoch == params.BeaconConfig().DenebForkEpoch {
// If we are in the fork epoch, we update our enr with
// the updated fork digest. These repeatedly does
// this over the epoch, which might be slightly wasteful
Expand Down
3 changes: 3 additions & 0 deletions beacon-chain/p2p/gossip_topic_mappings.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ var gossipTopicMappings = map[string]proto.Message{
// versioned by epoch.
func GossipTopicMappings(topic string, epoch primitives.Epoch) proto.Message {
if topic == BlockSubnetTopicFormat {
if epoch >= params.BeaconConfig().DenebForkEpoch {
return &ethpb.SignedBeaconBlockDeneb{}
}
if epoch >= params.BeaconConfig().CapellaForkEpoch {
return &ethpb.SignedBeaconBlockCapella{}
}
Expand Down
8 changes: 8 additions & 0 deletions beacon-chain/p2p/types/object_mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ func InitializeDataMaps() {
&ethpb.SignedBeaconBlockCapella{Block: &ethpb.BeaconBlockCapella{Body: &ethpb.BeaconBlockBodyCapella{}}},
)
},
bytesutil.ToBytes4(params.BeaconConfig().DenebForkVersion): func() (interfaces.ReadOnlySignedBeaconBlock, error) {
return blocks.NewSignedBeaconBlock(
&ethpb.SignedBeaconBlockDeneb{Block: &ethpb.BeaconBlockDeneb{Body: &ethpb.BeaconBlockBodyDeneb{}}},
)
},
}

// Reset our metadata map.
Expand All @@ -69,5 +74,8 @@ func InitializeDataMaps() {
bytesutil.ToBytes4(params.BeaconConfig().CapellaForkVersion): func() metadata.Metadata {
return wrapper.WrappedMetadataV1(&ethpb.MetaDataV1{})
},
bytesutil.ToBytes4(params.BeaconConfig().DenebForkVersion): func() metadata.Metadata {
return wrapper.WrappedMetadataV1(&ethpb.MetaDataV1{})
},
}
}
7 changes: 5 additions & 2 deletions beacon-chain/sync/rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,13 @@ func (s *Service) registerRPC(baseTopic string, handle rpcHandler) {
s.cfg.p2p.SetStreamHandler(topic, func(stream network.Stream) {
defer func() {
if r := recover(); r != nil {
log.WithField("error", r).Error("Panic occurred")
log.Errorf("%s", debug.Stack())
log.WithField("error", r).
WithField("recovered_at", "registerRPC").
WithField("stack", string(debug.Stack())).
Error("Panic occurred")
}
}()

ctx, cancel := context.WithTimeout(s.ctx, ttfbTimeout)
defer cancel()

Expand Down
6 changes: 6 additions & 0 deletions beacon-chain/sync/rpc_chunked_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ func WriteBlockChunk(stream libp2pcore.Stream, tor blockchain.TemporalOracle, en
return err
}
obtainedCtx = digest[:]
case version.Deneb:
digest, err := forks.ForkDigestFromEpoch(params.BeaconConfig().DenebForkEpoch, valRoot[:])
if err != nil {
return err
}
obtainedCtx = digest[:]
default:
return errors.Wrapf(ErrUnrecognizedVersion, "block version %d is not recognized", blk.Version())
}
Expand Down
6 changes: 4 additions & 2 deletions beacon-chain/sync/subscriber.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,10 @@ func (s *Service) subscribeWithBase(topic string, validator wrappedVal, handle s
defer func() {
if r := recover(); r != nil {
tracing.AnnotateError(span, fmt.Errorf("panic occurred: %v", r))
log.WithField("error", r).Error("Panic occurred")
debug.PrintStack()
log.WithField("error", r).
WithField("recovered_at", "subscribeWithBase").
WithField("stack", string(debug.Stack())).
Error("Panic occurred")
}
}()

Expand Down
8 changes: 6 additions & 2 deletions config/params/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,13 @@ func assertEqualConfigs(t *testing.T, name string, fields []string, expected, ac
assert.Equal(t, expected.AltairForkEpoch, actual.AltairForkEpoch, "%s: AltairForkEpoch", name)
assert.Equal(t, expected.BellatrixForkEpoch, actual.BellatrixForkEpoch, "%s: BellatrixForkEpoch", name)
assert.Equal(t, expected.CapellaForkEpoch, actual.CapellaForkEpoch, "%s: CapellaForkEpoch", name)
assert.Equal(t, expected.DenebForkEpoch, actual.DenebForkEpoch, "%s: DenebForkEpoch", name)
assert.Equal(t, expected.SqrRootSlotsPerEpoch, actual.SqrRootSlotsPerEpoch, "%s: SqrRootSlotsPerEpoch", name)
assert.DeepEqual(t, expected.GenesisForkVersion, actual.GenesisForkVersion, "%s: GenesisForkVersion", name)
assert.DeepEqual(t, expected.AltairForkVersion, actual.AltairForkVersion, "%s: AltairForkVersion", name)
assert.DeepEqual(t, expected.BellatrixForkVersion, actual.BellatrixForkVersion, "%s: BellatrixForkVersion", name)
assert.DeepEqual(t, expected.CapellaForkVersion, actual.CapellaForkVersion, "%s: CapellaForkVersion", name)
assert.DeepEqual(t, expected.DenebForkVersion, actual.DenebForkVersion, "%s: DenebForkVersion", name)

assertYamlFieldsMatch(t, name, fields, expected, actual)
}
Expand All @@ -127,8 +129,10 @@ func TestModifiedE2E(t *testing.T) {
c := params.E2ETestConfig().Copy()
c.DepositContractAddress = "0x4242424242424242424242424242424242424242"
c.TerminalTotalDifficulty = "0"
c.AltairForkEpoch = 0
c.BellatrixForkEpoch = 0
c.AltairForkEpoch = 112
c.BellatrixForkEpoch = 123
c.CapellaForkEpoch = 235
c.DenebForkEpoch = 358
y := params.ConfigToYaml(c)
cfg, err := params.UnmarshalConfig(y, nil)
require.NoError(t, err)
Expand Down
3 changes: 3 additions & 0 deletions config/params/testdata/e2e_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ BELLATRIX_FORK_EPOCH: 8
# Capella
CAPELLA_FORK_VERSION: 0x030000fd
CAPELLA_FORK_EPOCH: 10
# Deneb
DENEB_FORK_VERSION: 0x040000fd
DENEB_FORK_EPOCH: 12


# Time parameters
Expand Down
3 changes: 3 additions & 0 deletions config/params/testnet_e2e_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const (
AltairE2EForkEpoch = 6
BellatrixE2EForkEpoch = 8
CapellaE2EForkEpoch = 10
DenebE2EForkEpoch = 12
)

// E2ETestConfig retrieves the configurations made specifically for E2E testing.
Expand Down Expand Up @@ -38,6 +39,7 @@ func E2ETestConfig() *BeaconChainConfig {
e2eConfig.AltairForkEpoch = AltairE2EForkEpoch
e2eConfig.BellatrixForkEpoch = BellatrixE2EForkEpoch
e2eConfig.CapellaForkEpoch = CapellaE2EForkEpoch
e2eConfig.DenebForkEpoch = DenebE2EForkEpoch

// Terminal Total Difficulty.
e2eConfig.TerminalTotalDifficulty = "480"
Expand Down Expand Up @@ -79,6 +81,7 @@ func E2EMainnetTestConfig() *BeaconChainConfig {
e2eConfig.AltairForkEpoch = AltairE2EForkEpoch
e2eConfig.BellatrixForkEpoch = BellatrixE2EForkEpoch
e2eConfig.CapellaForkEpoch = CapellaE2EForkEpoch
e2eConfig.DenebForkEpoch = DenebE2EForkEpoch

// Terminal Total Difficulty.
e2eConfig.TerminalTotalDifficulty = "480"
Expand Down
4 changes: 4 additions & 0 deletions consensus-types/blocks/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,10 @@ func BuildSignedBeaconBlockFromExecutionPayload(
// This is particularly useful for using the values from API calls.
func BeaconBlockContainerToSignedBeaconBlock(obj *eth.BeaconBlockContainer) (interfaces.ReadOnlySignedBeaconBlock, error) {
switch obj.Block.(type) {
case *eth.BeaconBlockContainer_BlindedDenebBlock:
return NewSignedBeaconBlock(obj.GetBlindedDenebBlock())
case *eth.BeaconBlockContainer_DenebBlock:
return NewSignedBeaconBlock(obj.GetDenebBlock())
case *eth.BeaconBlockContainer_BlindedCapellaBlock:
return NewSignedBeaconBlock(obj.GetBlindedCapellaBlock())
case *eth.BeaconBlockContainer_CapellaBlock:
Expand Down
2 changes: 1 addition & 1 deletion consensus-types/payload-attribute/getters.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (a *data) PbV2() (*enginev1.PayloadAttributesV2, error) {
if a == nil {
return nil, errNilPayloadAttribute
}
if a.version != version.Capella {
if a.version < version.Capella {
return nil, consensus_types.ErrNotSupported("PayloadAttributePbV2", a.version)
}
if a.timeStamp == 0 && len(a.prevRandao) == 0 {
Expand Down
Loading