-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ePBS to db #13971
Add ePBS to db #13971
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package kv | ||
|
||
import ( | ||
"context" | ||
|
||
ethpb "github.com/prysmaticlabs/prysm/v5/proto/prysm/v1alpha1" | ||
bolt "go.etcd.io/bbolt" | ||
"go.opencensus.io/trace" | ||
) | ||
|
||
// SaveSignedExecutionPayloadEnvelopeBlind saves a signed execution payload envelope blind in the database. | ||
func (s *Store) SaveSignedExecutionPayloadEnvelopeBlind(ctx context.Context, env *ethpb.SignedExecutionPayloadEnvelopeBlind) error { | ||
ctx, span := trace.StartSpan(ctx, "BeaconDB.SaveSignedExecutionPayloadEnvelopeBlind") | ||
defer span.End() | ||
|
||
enc, err := encode(ctx, env) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
r := env.Message.BeaconBlockRoot | ||
err = s.db.Update(func(tx *bolt.Tx) error { | ||
bucket := tx.Bucket(executionPayloadEnvelopeBucket) | ||
return bucket.Put(r, enc) | ||
}) | ||
|
||
return err | ||
} | ||
|
||
// SignedExecutionPayloadEnvelopeBlind retrieves a signed execution payload envelope blind from the database. | ||
func (s *Store) SignedExecutionPayloadEnvelopeBlind(ctx context.Context, blockRoot []byte) (*ethpb.SignedExecutionPayloadEnvelopeBlind, error) { | ||
ctx, span := trace.StartSpan(ctx, "BeaconDB.SignedExecutionPayloadEnvelopeBlind") | ||
defer span.End() | ||
|
||
env := ðpb.SignedExecutionPayloadEnvelopeBlind{} | ||
err := s.db.View(func(tx *bolt.Tx) error { | ||
bkt := tx.Bucket(executionPayloadEnvelopeBucket) | ||
enc := bkt.Get(blockRoot) | ||
if enc == nil { | ||
return ErrNotFound | ||
} | ||
return decode(ctx, enc, env) | ||
}) | ||
return env, err | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package kv | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/prysmaticlabs/prysm/v5/testing/require" | ||
"github.com/prysmaticlabs/prysm/v5/testing/util/random" | ||
) | ||
|
||
func TestStore_SignedExecutionPayloadEnvelopeBlind(t *testing.T) { | ||
db := setupDB(t) | ||
ctx := context.Background() | ||
_, err := db.SignedExecutionPayloadEnvelopeBlind(ctx, []byte("test")) | ||
require.ErrorIs(t, err, ErrNotFound) | ||
|
||
env := random.SignedExecutionPayloadEnvelopeBlind(t) | ||
err = db.SaveSignedExecutionPayloadEnvelopeBlind(ctx, env) | ||
require.NoError(t, err) | ||
got, err := db.SignedExecutionPayloadEnvelopeBlind(ctx, env.Message.BeaconBlockRoot) | ||
require.NoError(t, err) | ||
require.DeepEqual(t, got, env) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -303,7 +303,7 @@ func prepareBlockBatch(blks []blocks.ROBlock, shouldBlind bool) ([]blockBatchEnt | |
if !errors.Is(err, blocks.ErrUnsupportedVersion) { | ||
return nil, errors.Wrapf(err, "could not convert block to blinded format for root %#x", batch[i].root) | ||
} | ||
// Pre-deneb blocks give ErrUnsupportedVersion; use the full block already in the batch entry. | ||
// Pre-bellatrix and ePBS blocks give ErrUnsupportedVersion; use the full block already in the batch entry. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment change is confusing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll revert this change. There's nothing we have to do here anyway |
||
} else { | ||
batch[i].block = blinded | ||
} | ||
|
@@ -823,6 +823,11 @@ func unmarshalBlock(_ context.Context, enc []byte) (interfaces.ReadOnlySignedBea | |
if err := rawBlock.UnmarshalSSZ(enc[len(electraBlindKey):]); err != nil { | ||
return nil, errors.Wrap(err, "could not unmarshal blinded Electra block") | ||
} | ||
case hasEpbsKey(enc): | ||
rawBlock = ðpb.SignedBeaconBlockEpbs{} | ||
if err := rawBlock.UnmarshalSSZ(enc[len(epbsKey):]); err != nil { | ||
return nil, errors.Wrap(err, "could not unmarshal EPBS block") | ||
} | ||
default: | ||
// Marshal block bytes to phase 0 beacon block. | ||
rawBlock = ðpb.SignedBeaconBlock{} | ||
|
@@ -852,6 +857,8 @@ func encodeBlock(blk interfaces.ReadOnlySignedBeaconBlock) ([]byte, error) { | |
|
||
func keyForBlock(blk interfaces.ReadOnlySignedBeaconBlock) ([]byte, error) { | ||
switch blk.Version() { | ||
case version.EPBS: | ||
return epbsKey, nil | ||
case version.Electra: | ||
if blk.IsBlinded() { | ||
return electraBlindKey, nil | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import ( | |
"github.com/prysmaticlabs/prysm/v5/testing/assert" | ||
"github.com/prysmaticlabs/prysm/v5/testing/require" | ||
"github.com/prysmaticlabs/prysm/v5/testing/util" | ||
"github.com/prysmaticlabs/prysm/v5/testing/util/random" | ||
"google.golang.org/protobuf/proto" | ||
) | ||
|
||
|
@@ -166,6 +167,17 @@ var blockTests = []struct { | |
} | ||
return blocks.NewSignedBeaconBlock(b) | ||
}}, | ||
{ | ||
name: "epbs", | ||
newBlock: func(slot primitives.Slot, root []byte) (interfaces.ReadOnlySignedBeaconBlock, error) { | ||
b := random.SignedBeaconBlock(&testing.T{}) | ||
b.Block.Slot = slot | ||
if root != nil { | ||
b.Block.ParentRoot = root | ||
} | ||
return blocks.NewSignedBeaconBlock(b) | ||
}, | ||
}, | ||
} | ||
|
||
func TestStore_SaveBlock_NoDuplicates(t *testing.T) { | ||
|
@@ -222,7 +234,7 @@ func TestStore_BlocksCRUD(t *testing.T) { | |
retrievedBlock, err = db.Block(ctx, blockRoot) | ||
require.NoError(t, err) | ||
wanted := retrievedBlock | ||
if retrievedBlock.Version() >= version.Bellatrix { | ||
if retrievedBlock.Version() >= version.Bellatrix && retrievedBlock.Version() < version.EPBS { | ||
wanted, err = retrievedBlock.ToBlinded() | ||
require.NoError(t, err) | ||
} | ||
|
@@ -410,7 +422,7 @@ func TestStore_BlocksCRUD_NoCache(t *testing.T) { | |
require.NoError(t, err) | ||
|
||
wanted := blk | ||
if blk.Version() >= version.Bellatrix { | ||
if blk.Version() >= version.Bellatrix && blk.Version() < version.EPBS { | ||
wanted, err = blk.ToBlinded() | ||
require.NoError(t, err) | ||
} | ||
|
@@ -629,7 +641,7 @@ func TestStore_SaveBlock_CanGetHighestAt(t *testing.T) { | |
b, err := db.Block(ctx, root) | ||
require.NoError(t, err) | ||
wanted := block1 | ||
if block1.Version() >= version.Bellatrix { | ||
if block1.Version() >= version.Bellatrix && block1.Version() < version.EPBS { | ||
wanted, err = wanted.ToBlinded() | ||
require.NoError(t, err) | ||
} | ||
|
@@ -647,7 +659,7 @@ func TestStore_SaveBlock_CanGetHighestAt(t *testing.T) { | |
b, err = db.Block(ctx, root) | ||
require.NoError(t, err) | ||
wanted2 := block2 | ||
if block2.Version() >= version.Bellatrix { | ||
if block2.Version() >= version.Bellatrix && block2.Version() < version.EPBS { | ||
wanted2, err = block2.ToBlinded() | ||
require.NoError(t, err) | ||
} | ||
|
@@ -665,7 +677,7 @@ func TestStore_SaveBlock_CanGetHighestAt(t *testing.T) { | |
b, err = db.Block(ctx, root) | ||
require.NoError(t, err) | ||
wanted = block3 | ||
if block3.Version() >= version.Bellatrix { | ||
if block3.Version() >= version.Bellatrix && block3.Version() < version.EPBS { | ||
wanted, err = wanted.ToBlinded() | ||
require.NoError(t, err) | ||
} | ||
|
@@ -701,7 +713,7 @@ func TestStore_GenesisBlock_CanGetHighestAt(t *testing.T) { | |
b, err := db.Block(ctx, root) | ||
require.NoError(t, err) | ||
wanted := block1 | ||
if block1.Version() >= version.Bellatrix { | ||
if block1.Version() >= version.Bellatrix && block1.Version() < version.EPBS { | ||
wanted, err = block1.ToBlinded() | ||
require.NoError(t, err) | ||
} | ||
|
@@ -718,7 +730,7 @@ func TestStore_GenesisBlock_CanGetHighestAt(t *testing.T) { | |
b, err = db.Block(ctx, root) | ||
require.NoError(t, err) | ||
wanted = genesisBlock | ||
if genesisBlock.Version() >= version.Bellatrix { | ||
if genesisBlock.Version() >= version.Bellatrix && genesisBlock.Version() < version.EPBS { | ||
wanted, err = genesisBlock.ToBlinded() | ||
require.NoError(t, err) | ||
} | ||
|
@@ -735,7 +747,7 @@ func TestStore_GenesisBlock_CanGetHighestAt(t *testing.T) { | |
b, err = db.Block(ctx, root) | ||
require.NoError(t, err) | ||
wanted = genesisBlock | ||
if genesisBlock.Version() >= version.Bellatrix { | ||
if genesisBlock.Version() >= version.Bellatrix && genesisBlock.Version() < version.EPBS { | ||
wanted, err = genesisBlock.ToBlinded() | ||
require.NoError(t, err) | ||
} | ||
|
@@ -831,7 +843,7 @@ func TestStore_BlocksBySlot_BlockRootsBySlot(t *testing.T) { | |
require.NoError(t, err) | ||
|
||
wanted := b1 | ||
if b1.Version() >= version.Bellatrix { | ||
if b1.Version() >= version.Bellatrix && b1.Version() < version.EPBS { | ||
wanted, err = b1.ToBlinded() | ||
require.NoError(t, err) | ||
} | ||
|
@@ -847,7 +859,7 @@ func TestStore_BlocksBySlot_BlockRootsBySlot(t *testing.T) { | |
t.Fatalf("Expected 2 blocks, received %d blocks", len(retrievedBlocks)) | ||
} | ||
wanted = b2 | ||
if b2.Version() >= version.Bellatrix { | ||
if b2.Version() >= version.Bellatrix && b2.Version() < version.EPBS { | ||
wanted, err = b2.ToBlinded() | ||
require.NoError(t, err) | ||
} | ||
|
@@ -857,7 +869,7 @@ func TestStore_BlocksBySlot_BlockRootsBySlot(t *testing.T) { | |
require.NoError(t, err) | ||
assert.Equal(t, true, proto.Equal(wantedPb, retrieved0Pb), "Wanted: %v, received: %v", retrievedBlocks[0], wanted) | ||
wanted = b3 | ||
if b3.Version() >= version.Bellatrix { | ||
if b3.Version() >= version.Bellatrix && b3.Version() < version.EPBS { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't we need to add then a test for epbs? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm unclear what you meant. We have an EPBS test in |
||
wanted, err = b3.ToBlinded() | ||
require.NoError(t, err) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need the Blind here? and even such a long name? any problem in calling this
SavePayloadEnvelope
?