Fixed size arrays in block interfaces and structs (#11375)

* Fixed size arrays in block fields

* test fix

* fmt

* fix fetcher test

* fix fuzz tests

Co-authored-by: prylabs-bulldozer[bot] <58059840+prylabs-bulldozer[bot]@users.noreply.github.com>
This commit is contained in:
Radosław Kapka
2022-09-06 16:30:16 +02:00
committed by GitHub
parent b98e9019ce
commit 4d90afe944
56 changed files with 432 additions and 383 deletions

View File

@@ -94,7 +94,7 @@ func (s *Service) notifyForkchoiceUpdate(ctx context.Context, arg *notifyForkcho
if len(lastValidHash) == 0 {
lastValidHash = defaultLatestValidHash
}
invalidRoots, err := s.ForkChoicer().SetOptimisticToInvalid(ctx, headRoot, bytesutil.ToBytes32(headBlk.ParentRoot()), bytesutil.ToBytes32(lastValidHash))
invalidRoots, err := s.ForkChoicer().SetOptimisticToInvalid(ctx, headRoot, headBlk.ParentRoot(), bytesutil.ToBytes32(lastValidHash))
if err != nil {
log.WithError(err).Error("Could not set head root to invalid")
return nil, nil
@@ -229,7 +229,7 @@ func (s *Service) notifyNewPayload(ctx context.Context, postStateVersion int,
if err != nil {
return false, err
}
invalidRoots, err := s.ForkChoicer().SetOptimisticToInvalid(ctx, root, bytesutil.ToBytes32(blk.Block().ParentRoot()), bytesutil.ToBytes32(lastValidHash))
invalidRoots, err := s.ForkChoicer().SetOptimisticToInvalid(ctx, root, blk.Block().ParentRoot(), bytesutil.ToBytes32(lastValidHash))
if err != nil {
return false, err
}
@@ -269,7 +269,7 @@ func (s *Service) optimisticCandidateBlock(ctx context.Context, blk interfaces.B
if blk.Slot()+params.BeaconConfig().SafeSlotsToImportOptimistically <= s.CurrentSlot() {
return nil
}
parent, err := s.getBlock(ctx, bytesutil.ToBytes32(blk.ParentRoot()))
parent, err := s.getBlock(ctx, blk.ParentRoot())
if err != nil {
return err
}

View File

@@ -100,7 +100,7 @@ func (s *Service) saveHead(ctx context.Context, newHeadRoot [32]byte, headBlock
newStateRoot := headBlock.Block().StateRoot()
// A chain re-org occurred, so we fire an event notifying the rest of the services.
if bytesutil.ToBytes32(headBlock.Block().ParentRoot()) != oldHeadRoot {
if headBlock.Block().ParentRoot() != oldHeadRoot {
commonRoot, forkSlot, err := s.ForkChoicer().CommonAncestor(ctx, oldHeadRoot, newHeadRoot)
if err != nil {
log.WithError(err).Error("Could not find common ancestor root")
@@ -126,8 +126,8 @@ func (s *Service) saveHead(ctx context.Context, newHeadRoot [32]byte, headBlock
Depth: math.Max(uint64(headSlot-forkSlot), uint64(newHeadSlot-forkSlot)),
OldHeadBlock: oldHeadRoot[:],
NewHeadBlock: newHeadRoot[:],
OldHeadState: oldStateRoot,
NewHeadState: newStateRoot,
OldHeadState: oldStateRoot[:],
NewHeadState: newStateRoot[:],
Epoch: slots.ToEpoch(newHeadSlot),
ExecutionOptimistic: isOptimistic,
},
@@ -152,7 +152,7 @@ func (s *Service) saveHead(ctx context.Context, newHeadRoot [32]byte, headBlock
// Forward an event capturing a new chain head over a common event feed
// done in a goroutine to avoid blocking the critical runtime main routine.
go func() {
if err := s.notifyNewHeadEvent(ctx, newHeadSlot, headState, newStateRoot, newHeadRoot[:]); err != nil {
if err := s.notifyNewHeadEvent(ctx, newHeadSlot, headState, newStateRoot[:], newHeadRoot[:]); err != nil {
log.WithError(err).Error("Could not notify event feed of new chain head")
}
}()
@@ -382,7 +382,8 @@ func (s *Service) saveOrphanedAtts(ctx context.Context, orphanedRoot [32]byte, n
}
saveOrphanedAttCount.Inc()
}
orphanedRoot = bytesutil.ToBytes32(orphanedBlk.Block().ParentRoot())
parentRoot := orphanedBlk.Block().ParentRoot()
orphanedRoot = bytesutil.ToBytes32(parentRoot[:])
}
return nil
}

View File

@@ -50,7 +50,7 @@ func TestSaveHead_Different(t *testing.T) {
require.NoError(t, err)
ojc := &ethpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
ofc := &ethpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
state, blkRoot, err := prepareForkchoiceState(ctx, oldBlock.Block().Slot(), oldRoot, bytesutil.ToBytes32(oldBlock.Block().ParentRoot()), [32]byte{}, ojc, ofc)
state, blkRoot, err := prepareForkchoiceState(ctx, oldBlock.Block().Slot(), oldRoot, oldBlock.Block().ParentRoot(), [32]byte{}, ojc, ofc)
require.NoError(t, err)
require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
service.head = &head{
@@ -66,11 +66,11 @@ func TestSaveHead_Different(t *testing.T) {
wsb := util.SaveBlock(t, context.Background(), service.cfg.BeaconDB, newHeadSignedBlock)
newRoot, err := newHeadBlock.HashTreeRoot()
require.NoError(t, err)
state, blkRoot, err = prepareForkchoiceState(ctx, wsb.Block().Slot()-1, bytesutil.ToBytes32(wsb.Block().ParentRoot()), service.cfg.ForkChoiceStore.CachedHeadRoot(), [32]byte{}, ojc, ofc)
state, blkRoot, err = prepareForkchoiceState(ctx, wsb.Block().Slot()-1, wsb.Block().ParentRoot(), service.cfg.ForkChoiceStore.CachedHeadRoot(), [32]byte{}, ojc, ofc)
require.NoError(t, err)
require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
state, blkRoot, err = prepareForkchoiceState(ctx, wsb.Block().Slot(), newRoot, bytesutil.ToBytes32(wsb.Block().ParentRoot()), [32]byte{}, ojc, ofc)
state, blkRoot, err = prepareForkchoiceState(ctx, wsb.Block().Slot(), newRoot, wsb.Block().ParentRoot(), [32]byte{}, ojc, ofc)
require.NoError(t, err)
require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
headState, err := util.NewBeaconState()
@@ -104,7 +104,7 @@ func TestSaveHead_Different_Reorg(t *testing.T) {
require.NoError(t, err)
ojc := &ethpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
ofc := &ethpb.Checkpoint{Root: params.BeaconConfig().ZeroHash[:]}
state, blkRoot, err := prepareForkchoiceState(ctx, oldBlock.Block().Slot(), oldRoot, bytesutil.ToBytes32(oldBlock.Block().ParentRoot()), [32]byte{}, ojc, ofc)
state, blkRoot, err := prepareForkchoiceState(ctx, oldBlock.Block().Slot(), oldRoot, oldBlock.Block().ParentRoot(), [32]byte{}, ojc, ofc)
require.NoError(t, err)
require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
service.head = &head{
@@ -114,7 +114,7 @@ func TestSaveHead_Different_Reorg(t *testing.T) {
}
reorgChainParent := [32]byte{'B'}
state, blkRoot, err = prepareForkchoiceState(ctx, 0, reorgChainParent, oldRoot, bytesutil.ToBytes32(oldBlock.Block().ParentRoot()), ojc, ofc)
state, blkRoot, err = prepareForkchoiceState(ctx, 0, reorgChainParent, oldRoot, oldBlock.Block().ParentRoot(), ojc, ofc)
require.NoError(t, err)
require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
@@ -126,7 +126,7 @@ func TestSaveHead_Different_Reorg(t *testing.T) {
wsb := util.SaveBlock(t, context.Background(), service.cfg.BeaconDB, newHeadSignedBlock)
newRoot, err := newHeadBlock.HashTreeRoot()
require.NoError(t, err)
state, blkRoot, err = prepareForkchoiceState(ctx, wsb.Block().Slot(), newRoot, bytesutil.ToBytes32(wsb.Block().ParentRoot()), [32]byte{}, ojc, ofc)
state, blkRoot, err = prepareForkchoiceState(ctx, wsb.Block().Slot(), newRoot, wsb.Block().ParentRoot(), [32]byte{}, ojc, ofc)
require.NoError(t, err)
require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, state, blkRoot))
headState, err := util.NewBeaconState()

View File

@@ -73,6 +73,7 @@ func logBlockSyncStatus(block interfaces.BeaconBlock, blockRoot [32]byte, justif
}
level := log.Logger.GetLevel()
if level >= logrus.DebugLevel {
parentRoot := block.ParentRoot()
log.WithFields(logrus.Fields{
"slot": block.Slot(),
"slotInEpoch": block.Slot() % params.BeaconConfig().SlotsPerEpoch,
@@ -82,7 +83,7 @@ func logBlockSyncStatus(block interfaces.BeaconBlock, blockRoot [32]byte, justif
"justifiedRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(justified.Root)[:8]),
"finalizedEpoch": finalized.Epoch,
"finalizedRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(finalized.Root)[:8]),
"parentRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(block.ParentRoot())[:8]),
"parentRoot": fmt.Sprintf("0x%s...", hex.EncodeToString(parentRoot[:])[:8]),
"version": version.String(block.Version()),
"sinceSlotStartTime": prysmTime.Now().Sub(startTime),
"chainServiceProcessedTime": prysmTime.Now().Sub(receivedTime),

View File

@@ -248,12 +248,13 @@ func (s *Service) onBlock(ctx context.Context, signed interfaces.SignedBeaconBlo
}
go func() {
// Send an event regarding the new finalized checkpoint over a common event feed.
stateRoot := signed.Block().StateRoot()
s.cfg.StateNotifier.StateFeed().Send(&feed.Event{
Type: statefeed.FinalizedCheckpoint,
Data: &ethpbv1.EventFinalizedCheckpoint{
Epoch: postState.FinalizedCheckpoint().Epoch,
Block: postState.FinalizedCheckpoint().Root,
State: signed.Block().StateRoot(),
State: stateRoot[:],
ExecutionOptimistic: isOptimistic,
},
})
@@ -317,7 +318,7 @@ func (s *Service) onBlockBatch(ctx context.Context, blks []interfaces.SignedBeac
if err := s.verifyBlkPreState(ctx, b); err != nil {
return err
}
preState, err := s.cfg.StateGen.StateByRootInitialSync(ctx, bytesutil.ToBytes32(b.ParentRoot()))
preState, err := s.cfg.StateGen.StateByRootInitialSync(ctx, b.ParentRoot())
if err != nil {
return err
}
@@ -516,7 +517,7 @@ func (s *Service) insertBlockToForkchoiceStore(ctx context.Context, blk interfac
ctx, span := trace.StartSpan(ctx, "blockChain.insertBlockToForkchoiceStore")
defer span.End()
if !s.cfg.ForkChoiceStore.HasNode(bytesutil.ToBytes32(blk.ParentRoot())) {
if !s.cfg.ForkChoiceStore.HasNode(blk.ParentRoot()) {
fCheckpoint := st.FinalizedCheckpoint()
jCheckpoint := st.CurrentJustifiedCheckpoint()
if err := s.fillInForkChoiceMissingBlocks(ctx, blk, fCheckpoint, jCheckpoint); err != nil {

View File

@@ -39,7 +39,7 @@ func (s *Service) getBlockPreState(ctx context.Context, b interfaces.BeaconBlock
return nil, err
}
preState, err := s.cfg.StateGen.StateByRoot(ctx, bytesutil.ToBytes32(b.ParentRoot()))
preState, err := s.cfg.StateGen.StateByRoot(ctx, b.ParentRoot())
if err != nil {
return nil, errors.Wrapf(err, "could not get pre state for slot %d", b.Slot())
}
@@ -65,7 +65,7 @@ func (s *Service) verifyBlkPreState(ctx context.Context, b interfaces.BeaconBloc
ctx, span := trace.StartSpan(ctx, "blockChain.verifyBlkPreState")
defer span.End()
parentRoot := bytesutil.ToBytes32(b.ParentRoot())
parentRoot := b.ParentRoot()
// Loosen the check to HasBlock because state summary gets saved in batches
// during initial syncing. There's no risk given a state summary object is just a
// a subset of the block object.
@@ -73,7 +73,7 @@ func (s *Service) verifyBlkPreState(ctx context.Context, b interfaces.BeaconBloc
return errors.New("could not reconstruct parent state")
}
if err := s.VerifyFinalizedBlkDescendant(ctx, bytesutil.ToBytes32(b.ParentRoot())); err != nil {
if err := s.VerifyFinalizedBlkDescendant(ctx, parentRoot); err != nil {
return err
}
@@ -241,7 +241,7 @@ func (s *Service) ancestorByDB(ctx context.Context, r [32]byte, slot types.Slot)
return r[:], nil
}
return s.ancestorByDB(ctx, bytesutil.ToBytes32(b.ParentRoot()), slot)
return s.ancestorByDB(ctx, b.ParentRoot(), slot)
}
// This retrieves missing blocks from DB (ie. the blocks that couldn't be received over sync) and inserts them to fork choice store.
@@ -259,7 +259,7 @@ func (s *Service) fillInForkChoiceMissingBlocks(ctx context.Context, blk interfa
pendingNodes = append(pendingNodes, &forkchoicetypes.BlockAndCheckpoints{Block: blk,
JustifiedCheckpoint: jCheckpoint, FinalizedCheckpoint: fCheckpoint})
// As long as parent node is not in fork choice store, and parent node is in DB.
root := bytesutil.ToBytes32(blk.ParentRoot())
root := blk.ParentRoot()
for !s.cfg.ForkChoiceStore.HasNode(root) && s.cfg.BeaconDB.HasBlock(ctx, root) {
b, err := s.getBlock(ctx, root)
if err != nil {
@@ -268,7 +268,7 @@ func (s *Service) fillInForkChoiceMissingBlocks(ctx context.Context, blk interfa
if b.Block().Slot() <= fSlot {
break
}
root = bytesutil.ToBytes32(b.Block().ParentRoot())
root = b.Block().ParentRoot()
args := &forkchoicetypes.BlockAndCheckpoints{Block: b.Block(),
JustifiedCheckpoint: jCheckpoint,
FinalizedCheckpoint: fCheckpoint}

View File

@@ -1756,7 +1756,7 @@ func TestOnBlock_ProcessBlocksParallel(t *testing.T) {
logHook := logTest.NewGlobal()
for i := 0; i < 10; i++ {
fc := &ethpb.Checkpoint{}
st, blkRoot, err := prepareForkchoiceState(ctx, 0, bytesutil.ToBytes32(wsb1.Block().ParentRoot()), [32]byte{}, [32]byte{}, fc, fc)
st, blkRoot, err := prepareForkchoiceState(ctx, 0, wsb1.Block().ParentRoot(), [32]byte{}, [32]byte{}, fc, fc)
require.NoError(t, err)
require.NoError(t, service.cfg.ForkChoiceStore.InsertNode(ctx, st, blkRoot))
var wg sync.WaitGroup

View File

@@ -174,7 +174,8 @@ func (s *ChainService) ReceiveBlockInitialSync(ctx context.Context, block interf
if s.State == nil {
return ErrNilState
}
if !bytes.Equal(s.Root, block.Block().ParentRoot()) {
parentRoot := block.Block().ParentRoot()
if !bytes.Equal(s.Root, parentRoot[:]) {
return errors.Errorf("wanted %#x but got %#x", s.Root, block.Block().ParentRoot())
}
if err := s.State.SetSlot(block.Block().Slot()); err != nil {
@@ -202,7 +203,8 @@ func (s *ChainService) ReceiveBlockBatch(ctx context.Context, blks []interfaces.
return ErrNilState
}
for _, b := range blks {
if !bytes.Equal(s.Root, b.Block().ParentRoot()) {
parentRoot := b.Block().ParentRoot()
if !bytes.Equal(s.Root, parentRoot[:]) {
return errors.Errorf("wanted %#x but got %#x", s.Root, b.Block().ParentRoot())
}
if err := s.State.SetSlot(b.Block().Slot()); err != nil {
@@ -233,7 +235,8 @@ func (s *ChainService) ReceiveBlock(ctx context.Context, block interfaces.Signed
if s.State == nil {
return ErrNilState
}
if !bytes.Equal(s.Root, block.Block().ParentRoot()) {
parentRoot := block.Block().ParentRoot()
if !bytes.Equal(s.Root, parentRoot[:]) {
return errors.Errorf("wanted %#x but got %#x", s.Root, block.Block().ParentRoot())
}
if err := s.State.SetSlot(block.Block().Slot()); err != nil {

View File

@@ -42,7 +42,7 @@ func TestFuzzProcessBlockHeader_10000(t *testing.T) {
s, err := v1.InitializeFromProtoUnsafe(state)
require.NoError(t, err)
if block.Block == nil || block.Block.Body == nil {
if block.Block == nil || block.Block.Body == nil || block.Block.Body.Eth1Data == nil {
continue
}
wsb, err := blocks.NewSignedBeaconBlock(block)

View File

@@ -51,13 +51,15 @@ func ProcessBlockHeader(
if err != nil {
return nil, err
}
beaconState, err = ProcessBlockHeaderNoVerify(ctx, beaconState, block.Block().Slot(), block.Block().ProposerIndex(), block.Block().ParentRoot(), bodyRoot[:])
parentRoot := block.Block().ParentRoot()
beaconState, err = ProcessBlockHeaderNoVerify(ctx, beaconState, block.Block().Slot(), block.Block().ProposerIndex(), parentRoot[:], bodyRoot[:])
if err != nil {
return nil, err
}
// Verify proposer signature.
if err := VerifyBlockSignature(beaconState, block.Block().ProposerIndex(), block.Signature(), block.Block().HashTreeRoot); err != nil {
sig := block.Signature()
if err := VerifyBlockSignature(beaconState, block.Block().ProposerIndex(), sig[:], block.Block().HashTreeRoot); err != nil {
return nil, err
}

View File

@@ -39,11 +39,13 @@ func ProcessRandao(
if err != nil {
return nil, err
}
if err := verifySignature(buf, proposerPub, body.RandaoReveal(), domain); err != nil {
randaoReveal := body.RandaoReveal()
if err := verifySignature(buf, proposerPub, randaoReveal[:], domain); err != nil {
return nil, errors.Wrap(err, "could not verify block randao")
}
beaconState, err = ProcessRandaoNoVerify(beaconState, body.RandaoReveal())
beaconState, err = ProcessRandaoNoVerify(beaconState, randaoReveal[:])
if err != nil {
return nil, errors.Wrap(err, "could not process randao")
}

View File

@@ -113,7 +113,8 @@ func VerifyBlockSignatureUsingCurrentFork(beaconState state.ReadOnlyBeaconState,
return err
}
proposerPubKey := proposer.PublicKey
return signing.VerifyBlockSigningRoot(proposerPubKey, blk.Signature(), domain, blk.Block().HashTreeRoot)
sig := blk.Signature()
return signing.VerifyBlockSigningRoot(proposerPubKey, sig[:], domain, blk.Block().HashTreeRoot)
}
// BlockSignatureBatch retrieves the block signature batch from the provided block and its corresponding state.

View File

@@ -184,7 +184,7 @@ func TestFuzzProcessBlockForStateRoot_1000(t *testing.T) {
for i := 0; i < 1000; i++ {
fuzzer.Fuzz(state)
fuzzer.Fuzz(sb)
if sb.Block == nil || sb.Block.Body == nil {
if sb.Block == nil || sb.Block.Body == nil || sb.Block.Body.Eth1Data == nil {
continue
}
wsb, err := blocks.NewSignedBeaconBlock(sb)

View File

@@ -59,7 +59,8 @@ func ExecuteStateTransitionNoVerifyAnySig(
interop.WriteBlockToDisk(signed, false /* Has the block failed */)
interop.WriteStateToDisk(st)
st, err = ProcessSlotsUsingNextSlotCache(ctx, st, signed.Block().ParentRoot(), signed.Block().Slot())
parentRoot := signed.Block().ParentRoot()
st, err = ProcessSlotsUsingNextSlotCache(ctx, st, parentRoot[:], signed.Block().Slot())
if err != nil {
return nil, nil, errors.Wrap(err, "could not process slots")
}
@@ -75,7 +76,8 @@ func ExecuteStateTransitionNoVerifyAnySig(
if err != nil {
return nil, nil, err
}
if !bytes.Equal(postStateRoot[:], signed.Block().StateRoot()) {
stateRoot := signed.Block().StateRoot()
if !bytes.Equal(postStateRoot[:], stateRoot[:]) {
return nil, nil, fmt.Errorf("could not validate state root, wanted: %#x, received: %#x",
postStateRoot[:], signed.Block().StateRoot())
}
@@ -127,7 +129,8 @@ func CalculateStateRoot(
// Execute per slots transition.
var err error
state, err = ProcessSlotsUsingNextSlotCache(ctx, state, signed.Block().ParentRoot(), signed.Block().Slot())
parentRoot := signed.Block().ParentRoot()
state, err = ProcessSlotsUsingNextSlotCache(ctx, state, parentRoot[:], signed.Block().Slot())
if err != nil {
return [32]byte{}, errors.Wrap(err, "could not process slots")
}
@@ -174,12 +177,14 @@ func ProcessBlockNoVerifyAnySig(
return nil, nil, err
}
bSet, err := b.BlockSignatureBatch(st, blk.ProposerIndex(), signed.Signature(), blk.HashTreeRoot)
sig := signed.Signature()
bSet, err := b.BlockSignatureBatch(st, blk.ProposerIndex(), sig[:], blk.HashTreeRoot)
if err != nil {
tracing.AnnotateError(span, err)
return nil, nil, errors.Wrap(err, "could not retrieve block signature set")
}
rSet, err := b.RandaoSignatureBatch(ctx, st, signed.Block().Body().RandaoReveal())
randaoReveal := signed.Block().Body().RandaoReveal()
rSet, err := b.RandaoSignatureBatch(ctx, st, randaoReveal[:])
if err != nil {
tracing.AnnotateError(span, err)
return nil, nil, errors.Wrap(err, "could not retrieve randao signature set")
@@ -279,7 +284,8 @@ func ProcessBlockForStateRoot(
if err != nil {
return nil, errors.Wrap(err, "could not hash tree root beacon block body")
}
state, err = b.ProcessBlockHeaderNoVerify(ctx, state, blk.Slot(), blk.ProposerIndex(), blk.ParentRoot(), bodyRoot[:])
parentRoot := blk.ParentRoot()
state, err = b.ProcessBlockHeaderNoVerify(ctx, state, blk.Slot(), blk.ProposerIndex(), parentRoot[:], bodyRoot[:])
if err != nil {
tracing.AnnotateError(span, err)
return nil, errors.Wrap(err, "could not process block header")
@@ -304,7 +310,8 @@ func ProcessBlockForStateRoot(
}
}
state, err = b.ProcessRandaoNoVerify(state, signed.Block().Body().RandaoReveal())
randaoReveal := signed.Block().Body().RandaoReveal()
state, err = b.ProcessRandaoNoVerify(state, randaoReveal[:])
if err != nil {
tracing.AnnotateError(span, err)
return nil, errors.Wrap(err, "could not verify and process randao")

View File

@@ -722,10 +722,10 @@ func createBlockIndicesFromBlock(ctx context.Context, block interfaces.BeaconBlo
indices := [][]byte{
bytesutil.SlotToBytesBigEndian(block.Slot()),
}
if block.ParentRoot() != nil && len(block.ParentRoot()) > 0 {
buckets = append(buckets, blockParentRootIndicesBucket)
indices = append(indices, block.ParentRoot())
}
buckets = append(buckets, blockParentRootIndicesBucket)
parentRoot := block.ParentRoot()
indices = append(indices, parentRoot[:])
for i := 0; i < len(buckets); i++ {
indicesByBucket[string(buckets[i])] = indices[i]
}

View File

@@ -90,8 +90,9 @@ func (s *Store) updateFinalizedBlockRoots(ctx context.Context, tx *bolt.Tx, chec
}
block := signedBlock.Block()
parentRoot := block.ParentRoot()
container := &ethpb.FinalizedBlockRootContainer{
ParentRoot: block.ParentRoot(),
ParentRoot: parentRoot[:],
ChildRoot: previousRoot,
}
@@ -112,7 +113,8 @@ func (s *Store) updateFinalizedBlockRoots(ctx context.Context, tx *bolt.Tx, chec
}
// Found parent, loop exit condition.
if parentBytes := bkt.Get(block.ParentRoot()); parentBytes != nil {
pr := block.ParentRoot()
if parentBytes := bkt.Get(pr[:]); parentBytes != nil {
parent := &ethpb.FinalizedBlockRootContainer{}
if err := decode(ctx, parentBytes, parent); err != nil {
tracing.AnnotateError(span, err)
@@ -124,14 +126,14 @@ func (s *Store) updateFinalizedBlockRoots(ctx context.Context, tx *bolt.Tx, chec
tracing.AnnotateError(span, err)
return err
}
if err := bkt.Put(block.ParentRoot(), enc); err != nil {
if err := bkt.Put(pr[:], enc); err != nil {
tracing.AnnotateError(span, err)
return err
}
break
}
previousRoot = root
root = block.ParentRoot()
root = pr[:]
}
// Upsert blocks from the current finalized epoch.

View File

@@ -552,8 +552,8 @@ func (f *ForkChoice) InsertOptimisticChain(ctx context.Context, chain []*forkcho
}
for i := len(chain) - 1; i > 0; i-- {
b := chain[i].Block
r := bytesutil.ToBytes32(chain[i-1].Block.ParentRoot())
parentRoot := bytesutil.ToBytes32(b.ParentRoot())
r := chain[i-1].Block.ParentRoot()
parentRoot := b.ParentRoot()
payloadHash, err := blocks.GetBlockPayloadHash(b)
if err != nil {
return err

View File

@@ -1003,8 +1003,8 @@ func (f *ForkChoice) InsertOptimisticChain(ctx context.Context, chain []*forkcho
}
for i := len(chain) - 1; i > 0; i-- {
b := chain[i].Block
r := bytesutil.ToBytes32(chain[i-1].Block.ParentRoot())
parentRoot := bytesutil.ToBytes32(b.ParentRoot())
r := chain[i-1].Block.ParentRoot()
parentRoot := b.ParentRoot()
payloadHash, err := blocks.GetBlockPayloadHash(b)
if err != nil {
return err

View File

@@ -88,11 +88,12 @@ func (s *Service) processProposedBlock(state state.BeaconState, root [32]byte, b
aggPerf.totalProposedCount++
s.aggregatedPerformance[blk.ProposerIndex()] = aggPerf
parentRoot := blk.ParentRoot()
log.WithFields(logrus.Fields{
"ProposerIndex": blk.ProposerIndex(),
"Slot": blk.Slot(),
"Version": blk.Version(),
"ParentRoot": fmt.Sprintf("%#x", bytesutil.Trunc(blk.ParentRoot())),
"ParentRoot": fmt.Sprintf("%#x", bytesutil.Trunc(parentRoot[:])),
"BlockRoot": fmt.Sprintf("%#x", bytesutil.Trunc(root[:])),
"NewBalance": balance,
"BalanceChange": balanceChg,

View File

@@ -78,7 +78,7 @@ func (bs *Server) GetWeakSubjectivity(ctx context.Context, _ *empty.Empty) (*eth
if err != nil {
return nil, status.Errorf(codes.Internal, fmt.Sprintf("block with root %#x from slot index %d not found in db", cbr, wsSlot))
}
stateRoot := bytesutil.ToBytes32(cb.Block().StateRoot())
stateRoot := cb.Block().StateRoot()
log.Printf("weak subjectivity checkpoint reported as epoch=%d, block root=%#x, state root=%#x", wsEpoch, cbr, stateRoot)
return &ethpbv1.WeakSubjectivityResponse{
Data: &ethpbv1.WeakSubjectivityData{
@@ -434,11 +434,12 @@ func (bs *Server) GetBlockV2(ctx context.Context, req *ethpbv2.BlockRequestV2) (
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not get signed beacon block: %v", err)
}
sig := blk.Signature()
return &ethpbv2.BlockResponseV2{
Version: ethpbv2.Version_ALTAIR,
Data: &ethpbv2.SignedBeaconBlockContainer{
Message: &ethpbv2.SignedBeaconBlockContainer_AltairBlock{AltairBlock: v2Blk},
Signature: blk.Signature(),
Signature: sig[:],
},
ExecutionOptimistic: false,
}, nil
@@ -465,11 +466,12 @@ func (bs *Server) GetBlockV2(ctx context.Context, req *ethpbv2.BlockRequestV2) (
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not check if block is optimistic: %v", err)
}
sig := blk.Signature()
return &ethpbv2.BlockResponseV2{
Version: ethpbv2.Version_BELLATRIX,
Data: &ethpbv2.SignedBeaconBlockContainer{
Message: &ethpbv2.SignedBeaconBlockContainer_BellatrixBlock{BellatrixBlock: v2Blk},
Signature: blk.Signature(),
Signature: sig[:],
},
ExecutionOptimistic: isOptimistic,
}, nil
@@ -499,11 +501,12 @@ func (bs *Server) GetBlockV2(ctx context.Context, req *ethpbv2.BlockRequestV2) (
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not check if block is optimistic: %v", err)
}
sig := blk.Signature()
return &ethpbv2.BlockResponseV2{
Version: ethpbv2.Version_BELLATRIX,
Data: &ethpbv2.SignedBeaconBlockContainer{
Message: &ethpbv2.SignedBeaconBlockContainer_BellatrixBlock{BellatrixBlock: v2Blk},
Signature: blk.Signature(),
Signature: sig[:],
},
ExecutionOptimistic: isOptimistic,
}, nil
@@ -553,9 +556,10 @@ func (bs *Server) GetBlockSSZV2(ctx context.Context, req *ethpbv2.BlockRequestV2
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not get signed beacon block: %v", err)
}
sig := blk.Signature()
data := &ethpbv2.SignedBeaconBlockAltair{
Message: v2Blk,
Signature: blk.Signature(),
Signature: sig[:],
}
sszData, err := data.MarshalSSZ()
if err != nil {
@@ -577,9 +581,10 @@ func (bs *Server) GetBlockSSZV2(ctx context.Context, req *ethpbv2.BlockRequestV2
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not get signed beacon block: %v", err)
}
sig := blk.Signature()
data := &ethpbv2.SignedBeaconBlockBellatrix{
Message: v2Blk,
Signature: blk.Signature(),
Signature: sig[:],
}
sszData, err := data.MarshalSSZ()
if err != nil {
@@ -605,9 +610,10 @@ func (bs *Server) GetBlockSSZV2(ctx context.Context, req *ethpbv2.BlockRequestV2
if err != nil {
return nil, status.Errorf(codes.Internal, "Could not get signed beacon block: %v", err)
}
sig := blk.Signature()
data := &ethpbv2.SignedBeaconBlockBellatrix{
Message: v2Blk,
Signature: blk.Signature(),
Signature: sig[:],
}
sszData, err := data.MarshalSSZ()
if err != nil {

View File

@@ -302,7 +302,8 @@ func (bs *Server) StreamBlocks(req *ethpb.StreamBlocksRequest, stream ethpb.Beac
continue
}
signed := data.SignedBlock
if err := blocks.VerifyBlockSignature(headState, signed.Block().ProposerIndex(), signed.Signature(), signed.Block().HashTreeRoot); err != nil {
sig := signed.Signature()
if err := blocks.VerifyBlockSignature(headState, signed.Block().ProposerIndex(), sig[:], signed.Block().HashTreeRoot); err != nil {
log.WithError(err).WithField("blockSlot", data.SignedBlock.Block().Slot()).Error("Could not verify block signature")
continue
}

View File

@@ -119,7 +119,8 @@ func (vs *Server) sendBlocks(stream ethpb.BeaconNodeValidator_StreamBlocksAltair
return nil
}
signed := data.SignedBlock
if err := blocks.VerifyBlockSignature(headState, signed.Block().ProposerIndex(), signed.Signature(), signed.Block().HashTreeRoot); err != nil {
sig := signed.Signature()
if err := blocks.VerifyBlockSignature(headState, signed.Block().ProposerIndex(), sig[:], signed.Block().HashTreeRoot); err != nil {
log.WithError(err).Error("Could not verify block signature")
return nil
}

View File

@@ -165,7 +165,7 @@ func (vs *Server) proposeGenericBeaconBlock(ctx context.Context, blk interfaces.
// computeStateRoot computes the state root after a block has been processed through a state transition and
// returns it to the validator client.
func (vs *Server) computeStateRoot(ctx context.Context, block interfaces.SignedBeaconBlock) ([]byte, error) {
beaconState, err := vs.StateGen.StateByRoot(ctx, bytesutil.ToBytes32(block.Block().ParentRoot()))
beaconState, err := vs.StateGen.StateByRoot(ctx, block.Block().ParentRoot())
if err != nil {
return nil, errors.Wrap(err, "could not retrieve beacon state")
}

View File

@@ -235,16 +235,21 @@ func (vs *Server) unblindBuilderBlock(ctx context.Context, b interfaces.SignedBe
if !ok {
return nil, errors.New("execution data must be execution payload header")
}
parentRoot := b.Block().ParentRoot()
stateRoot := b.Block().StateRoot()
randaoReveal := b.Block().Body().RandaoReveal()
graffiti := b.Block().Body().Graffiti()
sig := b.Signature()
sb := &ethpb.SignedBlindedBeaconBlockBellatrix{
Block: &ethpb.BlindedBeaconBlockBellatrix{
Slot: b.Block().Slot(),
ProposerIndex: b.Block().ProposerIndex(),
ParentRoot: b.Block().ParentRoot(),
StateRoot: b.Block().StateRoot(),
ParentRoot: parentRoot[:],
StateRoot: stateRoot[:],
Body: &ethpb.BlindedBeaconBlockBodyBellatrix{
RandaoReveal: b.Block().Body().RandaoReveal(),
RandaoReveal: randaoReveal[:],
Eth1Data: b.Block().Body().Eth1Data(),
Graffiti: b.Block().Body().Graffiti(),
Graffiti: graffiti[:],
ProposerSlashings: b.Block().Body().ProposerSlashings(),
AttesterSlashings: b.Block().Body().AttesterSlashings(),
Attestations: b.Block().Body().Attestations(),
@@ -254,7 +259,7 @@ func (vs *Server) unblindBuilderBlock(ctx context.Context, b interfaces.SignedBe
ExecutionPayloadHeader: header,
},
},
Signature: b.Signature(),
Signature: sig[:],
}
payload, err := vs.BlockBuilder.SubmitBlindedBlock(ctx, sb)

View File

@@ -223,7 +223,8 @@ func (p *StateProvider) headStateRoot(ctx context.Context) ([]byte, error) {
if err = blocks.BeaconBlockIsNil(b); err != nil {
return nil, err
}
return b.Block().StateRoot(), nil
stateRoot := b.Block().StateRoot()
return stateRoot[:], nil
}
func (p *StateProvider) genesisStateRoot(ctx context.Context) ([]byte, error) {
@@ -234,7 +235,8 @@ func (p *StateProvider) genesisStateRoot(ctx context.Context) ([]byte, error) {
if err := blocks.BeaconBlockIsNil(b); err != nil {
return nil, err
}
return b.Block().StateRoot(), nil
stateRoot := b.Block().StateRoot()
return stateRoot[:], nil
}
func (p *StateProvider) finalizedStateRoot(ctx context.Context) ([]byte, error) {
@@ -249,7 +251,8 @@ func (p *StateProvider) finalizedStateRoot(ctx context.Context) ([]byte, error)
if err := blocks.BeaconBlockIsNil(b); err != nil {
return nil, err
}
return b.Block().StateRoot(), nil
stateRoot := b.Block().StateRoot()
return stateRoot[:], nil
}
func (p *StateProvider) justifiedStateRoot(ctx context.Context) ([]byte, error) {
@@ -264,7 +267,8 @@ func (p *StateProvider) justifiedStateRoot(ctx context.Context) ([]byte, error)
if err := blocks.BeaconBlockIsNil(b); err != nil {
return nil, err
}
return b.Block().StateRoot(), nil
stateRoot := b.Block().StateRoot()
return stateRoot[:], nil
}
func (p *StateProvider) stateRootByRoot(ctx context.Context, stateRoot []byte) ([]byte, error) {
@@ -302,5 +306,6 @@ func (p *StateProvider) stateRootBySlot(ctx context.Context, slot types.Slot) ([
if blks[0] == nil || blks[0].Block() == nil {
return nil, errors.New("nil block")
}
return blks[0].Block().StateRoot(), nil
stateRoot := blks[0].Block().StateRoot()
return stateRoot[:], nil
}

View File

@@ -241,7 +241,8 @@ func TestGetStateRoot(t *testing.T) {
require.NoError(t, err)
genesisBlock, err := db.GenesisBlock(ctx)
require.NoError(t, err)
assert.DeepEqual(t, genesisBlock.Block().StateRoot(), s)
sr := genesisBlock.Block().StateRoot()
assert.DeepEqual(t, sr[:], s)
})
t.Run("finalized", func(t *testing.T) {

View File

@@ -237,7 +237,7 @@ func (s *State) latestAncestor(ctx context.Context, blockRoot [32]byte) (state.B
}
// Is the state the genesis state.
parentRoot := bytesutil.ToBytes32(b.Block().ParentRoot())
parentRoot := b.Block().ParentRoot()
if parentRoot == params.BeaconConfig().ZeroHash {
s, err := s.beaconDB.GenesisState(ctx)
return s, errors.Wrap(err, "could not get genesis state")

View File

@@ -11,7 +11,6 @@ import (
"github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
"go.opencensus.io/trace"
)
@@ -172,7 +171,7 @@ func (c *CanonicalHistory) ancestorChain(ctx context.Context, tail interfaces.Si
if err != nil && !errors.Is(err, db.ErrNotFoundState) {
return nil, nil, errors.Wrap(err, fmt.Sprintf("error querying database for state w/ block root = %#x", root))
}
parent, err := c.h.Block(ctx, bytesutil.ToBytes32(b.ParentRoot()))
parent, err := c.h.Block(ctx, b.ParentRoot())
if err != nil {
msg := fmt.Sprintf("db error when retrieving parent of block at slot=%d by root=%#x", b.Slot(), b.ParentRoot())
return nil, nil, errors.Wrap(err, msg)

View File

@@ -16,7 +16,6 @@ import (
blocktest "github.com/prysmaticlabs/prysm/v3/consensus-types/blocks/testing"
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v3/testing/require"
"github.com/prysmaticlabs/prysm/v3/testing/util"
)
@@ -65,7 +64,7 @@ func TestMockHistoryParentRoot(t *testing.T) {
endBlock, err := hist.Block(ctx, endRoot)
require.NoError(t, err)
// middle should be the parent of end, compare the middle root to endBlock's parent root
require.Equal(t, hist.slotMap[middle], bytesutil.ToBytes32(endBlock.Block().ParentRoot()))
require.Equal(t, hist.slotMap[middle], endBlock.Block().ParentRoot())
}
type mockHistorySpec struct {

View File

@@ -15,7 +15,6 @@ import (
"github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v3/monitoring/tracing"
"github.com/prysmaticlabs/prysm/v3/runtime/version"
"github.com/sirupsen/logrus"
@@ -124,7 +123,7 @@ func (s *State) loadBlocks(ctx context.Context, startSlot, endSlot types.Slot, e
return nil, ctx.Err()
}
b := filteredBlocks[len(filteredBlocks)-1]
if bytesutil.ToBytes32(b.Block().ParentRoot()) != blockRoots[i] {
if b.Block().ParentRoot() != blockRoots[i] {
continue
}
filteredBlocks = append(filteredBlocks, blocks[i])

View File

@@ -16,12 +16,14 @@ func headerFromBlock(b interfaces.SignedBeaconBlock) (*ethpb.BeaconBlockHeader,
if err != nil {
return nil, err
}
stateRoot := b.Block().StateRoot()
parentRoot := b.Block().ParentRoot()
return &ethpb.BeaconBlockHeader{
Slot: b.Block().Slot(),
StateRoot: b.Block().StateRoot(),
StateRoot: stateRoot[:],
ProposerIndex: b.Block().ProposerIndex(),
BodyRoot: bodyRoot[:],
ParentRoot: b.Block().ParentRoot(),
ParentRoot: parentRoot[:],
}, nil
}

View File

@@ -32,7 +32,6 @@ go_library(
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//crypto/rand:go_default_library",
"//encoding/bytesutil:go_default_library",
"//math:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//runtime:go_default_library",

View File

@@ -12,7 +12,6 @@ import (
"github.com/prysmaticlabs/prysm/v3/config/params"
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
p2ppb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v3/time/slots"
"github.com/sirupsen/logrus"
@@ -237,7 +236,7 @@ func (f *blocksFetcher) findForkWithPeer(ctx context.Context, pid peer.ID, slot
// Traverse blocks, and if we've got one that doesn't have parent in DB, backtrack on it.
for i, block := range blocks {
parentRoot := bytesutil.ToBytes32(block.Block().ParentRoot())
parentRoot := block.Block().ParentRoot()
if !f.chain.HasBlock(ctx, parentRoot) {
log.WithFields(logrus.Fields{
"peer": pid,
@@ -264,7 +263,7 @@ func (f *blocksFetcher) findForkWithPeer(ctx context.Context, pid peer.ID, slot
func (f *blocksFetcher) findAncestor(ctx context.Context, pid peer.ID, b interfaces.SignedBeaconBlock) (*forkData, error) {
outBlocks := []interfaces.SignedBeaconBlock{b}
for i := uint64(0); i < backtrackingMaxHops; i++ {
parentRoot := bytesutil.ToBytes32(outBlocks[len(outBlocks)-1].Block().ParentRoot())
parentRoot := outBlocks[len(outBlocks)-1].Block().ParentRoot()
if f.chain.HasBlock(ctx, parentRoot) {
// Common ancestor found, forward blocks back to processor.
sort.Slice(outBlocks, func(i, j int) bool {

View File

@@ -255,7 +255,7 @@ func TestBlocksQueue_Loop(t *testing.T) {
})
assert.NoError(t, queue.start())
processBlock := func(block interfaces.SignedBeaconBlock) error {
if !beaconDB.HasBlock(ctx, bytesutil.ToBytes32(block.Block().ParentRoot())) {
if !beaconDB.HasBlock(ctx, block.Block().ParentRoot()) {
return fmt.Errorf("%w: %#x", errParentDoesNotExist, block.Block().ParentRoot())
}
root, err := block.Block().HashTreeRoot()
@@ -1336,7 +1336,7 @@ func TestBlocksQueue_stuckWhenHeadIsSetToOrphanedBlock(t *testing.T) {
continue
}
parentRoot := bytesutil.ToBytes32(blk.Block().ParentRoot())
parentRoot := blk.Block().ParentRoot()
if !beaconDB.HasBlock(ctx, parentRoot) && !mc.HasBlock(ctx, parentRoot) {
log.Errorf("%v: %#x", errParentDoesNotExist, blk.Block().ParentRoot())
continue

View File

@@ -1,7 +1,6 @@
package initialsync
import (
"bytes"
"context"
"encoding/hex"
"errors"
@@ -13,7 +12,6 @@ import (
"github.com/prysmaticlabs/prysm/v3/beacon-chain/core/transition"
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v3/time/slots"
"github.com/sirupsen/logrus"
)
@@ -240,8 +238,7 @@ func (s *Service) processBlock(
}
s.logSyncStatus(genesis, blk.Block(), blkRoot)
parentRoot := bytesutil.ToBytes32(blk.Block().ParentRoot())
if !s.cfg.Chain.HasBlock(ctx, parentRoot) {
if !s.cfg.Chain.HasBlock(ctx, blk.Block().ParentRoot()) {
return fmt.Errorf("%w: (in processBlock, slot=%d) %#x", errParentDoesNotExist, blk.Block().Slot(), blk.Block().ParentRoot())
}
return blockReceiver(ctx, blk, blkRoot)
@@ -270,7 +267,7 @@ func (s *Service) processBatchedBlocks(ctx context.Context, genesis time.Time,
}
}
s.logBatchSyncStatus(genesis, blks, blkRoot)
parentRoot := bytesutil.ToBytes32(firstBlock.Block().ParentRoot())
parentRoot := firstBlock.Block().ParentRoot()
if !s.cfg.Chain.HasBlock(ctx, parentRoot) {
return fmt.Errorf("%w: %#x (in processBatchedBlocks, slot=%d)", errParentDoesNotExist, firstBlock.Block().ParentRoot(), firstBlock.Block().Slot())
}
@@ -278,7 +275,7 @@ func (s *Service) processBatchedBlocks(ctx context.Context, genesis time.Time,
blockRoots[0] = blkRoot
for i := 1; i < len(blks); i++ {
b := blks[i]
if !bytes.Equal(b.Block().ParentRoot(), blockRoots[i-1][:]) {
if b.Block().ParentRoot() != blockRoots[i-1] {
return fmt.Errorf("expected linear block list with parent root of %#x but received %#x",
blockRoots[i-1][:], b.Block().ParentRoot())
}

View File

@@ -114,7 +114,7 @@ func (s *Service) processPendingBlocks(ctx context.Context) error {
}
s.pendingQueueLock.RLock()
inPendingQueue := s.seenPendingBlocks[bytesutil.ToBytes32(b.Block().ParentRoot())]
inPendingQueue := s.seenPendingBlocks[b.Block().ParentRoot()]
s.pendingQueueLock.RUnlock()
keepProcessing, err := s.checkIfBlockIsBad(ctx, span, slot, b, blkRoot)
@@ -125,17 +125,18 @@ func (s *Service) processPendingBlocks(ctx context.Context) error {
continue
}
parentInDb := s.cfg.beaconDB.HasBlock(ctx, bytesutil.ToBytes32(b.Block().ParentRoot()))
parentInDb := s.cfg.beaconDB.HasBlock(ctx, b.Block().ParentRoot())
hasPeer := len(pids) != 0
// Only request for missing parent block if it's not in beaconDB, not in pending cache
// and has peer in the peer list.
parentRoot := b.Block().ParentRoot()
if !inPendingQueue && !parentInDb && hasPeer {
log.WithFields(logrus.Fields{
"currentSlot": b.Block().Slot(),
"parentRoot": hex.EncodeToString(bytesutil.Trunc(b.Block().ParentRoot())),
"parentRoot": hex.EncodeToString(bytesutil.Trunc(parentRoot[:])),
}).Debug("Requesting parent block")
parentRoots = append(parentRoots, bytesutil.ToBytes32(b.Block().ParentRoot()))
parentRoots = append(parentRoots, b.Block().ParentRoot())
span.End()
continue
@@ -213,7 +214,7 @@ func (s *Service) checkIfBlockIsBad(
b interfaces.SignedBeaconBlock,
blkRoot [32]byte,
) (keepProcessing bool, err error) {
parentIsBad := s.hasBadBlock(bytesutil.ToBytes32(b.Block().ParentRoot()))
parentIsBad := s.hasBadBlock(b.Block().ParentRoot())
blockIsBad := s.hasBadBlock(blkRoot)
// Check if parent is a bad block.
if parentIsBad || blockIsBad {
@@ -316,7 +317,7 @@ func (s *Service) validatePendingSlots() error {
for _, b := range blks {
epoch := slots.ToEpoch(slot)
// remove all descendant blocks of old blocks
if oldBlockRoots[bytesutil.ToBytes32(b.Block().ParentRoot())] {
if oldBlockRoots[b.Block().ParentRoot()] {
root, err := b.Block().HashTreeRoot()
if err != nil {
return err

View File

@@ -13,7 +13,6 @@ import (
"github.com/prysmaticlabs/prysm/v3/consensus-types/blocks"
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
"github.com/prysmaticlabs/prysm/v3/monitoring/tracing"
pb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"go.opencensus.io/trace"
@@ -247,7 +246,7 @@ func (s *Service) filterBlocks(ctx context.Context, blks []interfaces.SignedBeac
return nil, err
}
parentValid := *prevRoot != [32]byte{}
isLinear := *prevRoot == bytesutil.ToBytes32(b.Block().ParentRoot())
isLinear := *prevRoot == b.Block().ParentRoot()
isSingular := step == 1
slotDiff, err := b.Block().Slot().SafeSubSlot(startSlot)
if err != nil {

View File

@@ -104,7 +104,7 @@ func (s *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, ms
return pubsub.ValidationIgnore, nil
}
// Check if parent is a bad block and then reject the block.
if s.hasBadBlock(bytesutil.ToBytes32(blk.Block().ParentRoot())) {
if s.hasBadBlock(blk.Block().ParentRoot()) {
s.setBadBlock(ctx, blockRoot)
err := fmt.Errorf("received block with root %#x that has an invalid parent %#x", blockRoot, blk.Block().ParentRoot())
log.WithError(err).WithFields(getBlockFields(blk)).Debug("Received block with an invalid parent")
@@ -161,7 +161,7 @@ func (s *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, ms
}
// Handle block when the parent is unknown.
if !s.cfg.chain.HasBlock(ctx, bytesutil.ToBytes32(blk.Block().ParentRoot())) {
if !s.cfg.chain.HasBlock(ctx, blk.Block().ParentRoot()) {
s.pendingQueueLock.Lock()
if err := s.insertBlockToPendingQueue(blk.Block().Slot(), blk, blockRoot); err != nil {
s.pendingQueueLock.Unlock()
@@ -198,11 +198,12 @@ func (s *Service) validateBeaconBlockPubSub(ctx context.Context, pid peer.ID, ms
if err != nil {
return pubsub.ValidationIgnore, err
}
graffiti := blk.Block().Body().Graffiti()
log.WithFields(logrus.Fields{
"blockSlot": blk.Block().Slot(),
"sinceSlotStartTime": receivedTime.Sub(startTime),
"proposerIndex": blk.Block().ProposerIndex(),
"graffiti": string(blk.Block().Body().Graffiti()),
"graffiti": string(graffiti[:]),
}).Debug("Received block")
blockVerificationGossipSummary.Observe(float64(prysmTime.Since(receivedTime).Milliseconds()))
@@ -213,12 +214,12 @@ func (s *Service) validateBeaconBlock(ctx context.Context, blk interfaces.Signed
ctx, span := trace.StartSpan(ctx, "sync.validateBeaconBlock")
defer span.End()
if err := s.cfg.chain.VerifyFinalizedBlkDescendant(ctx, bytesutil.ToBytes32(blk.Block().ParentRoot())); err != nil {
if err := s.cfg.chain.VerifyFinalizedBlkDescendant(ctx, blk.Block().ParentRoot()); err != nil {
s.setBadBlock(ctx, blockRoot)
return err
}
parentState, err := s.cfg.stateGen.StateByRoot(ctx, bytesutil.ToBytes32(blk.Block().ParentRoot()))
parentState, err := s.cfg.stateGen.StateByRoot(ctx, blk.Block().ParentRoot())
if err != nil {
return err
}
@@ -229,7 +230,8 @@ func (s *Service) validateBeaconBlock(ctx context.Context, blk interfaces.Signed
}
// In the event the block is more than an epoch ahead from its
// parent state, we have to advance the state forward.
parentState, err = transition.ProcessSlotsUsingNextSlotCache(ctx, parentState, blk.Block().ParentRoot(), blk.Block().Slot())
parentRoot := blk.Block().ParentRoot()
parentState, err = transition.ProcessSlotsUsingNextSlotCache(ctx, parentState, parentRoot[:], blk.Block().Slot())
if err != nil {
return err
}
@@ -296,8 +298,7 @@ func (s *Service) validateBellatrixBeaconBlock(ctx context.Context, parentState
return errors.New("incorrect timestamp")
}
parentRoot := bytesutil.ToBytes32(blk.ParentRoot())
isParentOptimistic, err := s.cfg.chain.IsOptimisticForRoot(ctx, parentRoot)
isParentOptimistic, err := s.cfg.chain.IsOptimisticForRoot(ctx, blk.ParentRoot())
if err != nil {
return err
}
@@ -373,10 +374,11 @@ func getBlockFields(b interfaces.SignedBeaconBlock) logrus.Fields {
if consensusblocks.BeaconBlockIsNil(b) != nil {
return logrus.Fields{}
}
graffiti := b.Block().Body().Graffiti()
return logrus.Fields{
"slot": b.Block().Slot(),
"proposerIndex": b.Block().ProposerIndex(),
"graffiti": string(b.Block().Body().Graffiti()),
"graffiti": string(graffiti[:]),
"version": b.Block().Version(),
}
}

View File

@@ -182,16 +182,21 @@ func BuildSignedBeaconBlockFromExecutionPayload(
if err != nil {
return nil, errors.Wrap(err, "could not get sync aggregate from block body")
}
parentRoot := b.ParentRoot()
stateRoot := b.StateRoot()
randaoReveal := b.Body().RandaoReveal()
graffiti := b.Body().Graffiti()
sig := blk.Signature()
bellatrixFullBlock := &eth.SignedBeaconBlockBellatrix{
Block: &eth.BeaconBlockBellatrix{
Slot: b.Slot(),
ProposerIndex: b.ProposerIndex(),
ParentRoot: b.ParentRoot(),
StateRoot: b.StateRoot(),
ParentRoot: parentRoot[:],
StateRoot: stateRoot[:],
Body: &eth.BeaconBlockBodyBellatrix{
RandaoReveal: b.Body().RandaoReveal(),
RandaoReveal: randaoReveal[:],
Eth1Data: b.Body().Eth1Data(),
Graffiti: b.Body().Graffiti(),
Graffiti: graffiti[:],
ProposerSlashings: b.Body().ProposerSlashings(),
AttesterSlashings: b.Body().AttesterSlashings(),
Attestations: b.Body().Attestations(),
@@ -201,7 +206,7 @@ func BuildSignedBeaconBlockFromExecutionPayload(
ExecutionPayload: payload,
},
},
Signature: blk.Signature(),
Signature: sig[:],
}
return NewSignedBeaconBlock(bellatrixFullBlock)
}

View File

@@ -201,31 +201,31 @@ func Test_NewBeaconBlockBody(t *testing.T) {
}
func Test_BuildSignedBeaconBlock(t *testing.T) {
sig := []byte("signature")
sig := bytesutil.ToBytes96([]byte("signature"))
t.Run("Phase0", func(t *testing.T) {
b := &BeaconBlock{version: version.Phase0, body: &BeaconBlockBody{version: version.Phase0}}
sb, err := BuildSignedBeaconBlock(b, sig)
sb, err := BuildSignedBeaconBlock(b, sig[:])
require.NoError(t, err)
assert.DeepEqual(t, sig, sb.Signature())
assert.Equal(t, version.Phase0, sb.Version())
})
t.Run("Altair", func(t *testing.T) {
b := &BeaconBlock{version: version.Altair, body: &BeaconBlockBody{version: version.Altair}}
sb, err := BuildSignedBeaconBlock(b, sig)
sb, err := BuildSignedBeaconBlock(b, sig[:])
require.NoError(t, err)
assert.DeepEqual(t, sig, sb.Signature())
assert.Equal(t, version.Altair, sb.Version())
})
t.Run("Bellatrix", func(t *testing.T) {
b := &BeaconBlock{version: version.Bellatrix, body: &BeaconBlockBody{version: version.Bellatrix}}
sb, err := BuildSignedBeaconBlock(b, sig)
sb, err := BuildSignedBeaconBlock(b, sig[:])
require.NoError(t, err)
assert.DeepEqual(t, sig, sb.Signature())
assert.Equal(t, version.Bellatrix, sb.Version())
})
t.Run("BellatrixBlind", func(t *testing.T) {
b := &BeaconBlock{version: version.Bellatrix, body: &BeaconBlockBody{version: version.Bellatrix, isBlinded: true}}
sb, err := BuildSignedBeaconBlock(b, sig)
sb, err := BuildSignedBeaconBlock(b, sig[:])
require.NoError(t, err)
assert.DeepEqual(t, sig, sb.Signature())
assert.Equal(t, version.Bellatrix, sb.Version())

View File

@@ -3,6 +3,7 @@ package blocks
import (
"github.com/pkg/errors"
ssz "github.com/prysmaticlabs/fastssz"
field_params "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
@@ -21,7 +22,7 @@ func BeaconBlockIsNil(b interfaces.SignedBeaconBlock) error {
}
// Signature returns the respective block signature.
func (b *SignedBeaconBlock) Signature() []byte {
func (b *SignedBeaconBlock) Signature() [field_params.BLSSignatureLength]byte {
return b.signature
}
@@ -166,12 +167,12 @@ func (b *SignedBeaconBlock) ToBlinded() (interfaces.SignedBeaconBlock, error) {
Block: &eth.BlindedBeaconBlockBellatrix{
Slot: b.block.slot,
ProposerIndex: b.block.proposerIndex,
ParentRoot: b.block.parentRoot,
StateRoot: b.block.stateRoot,
ParentRoot: b.block.parentRoot[:],
StateRoot: b.block.stateRoot[:],
Body: &eth.BlindedBeaconBlockBodyBellatrix{
RandaoReveal: b.block.body.randaoReveal,
RandaoReveal: b.block.body.randaoReveal[:],
Eth1Data: b.block.body.eth1Data,
Graffiti: b.block.body.graffiti,
Graffiti: b.block.body.graffiti[:],
ProposerSlashings: b.block.body.proposerSlashings,
AttesterSlashings: b.block.body.attesterSlashings,
Attestations: b.block.body.attestations,
@@ -181,7 +182,7 @@ func (b *SignedBeaconBlock) ToBlinded() (interfaces.SignedBeaconBlock, error) {
ExecutionPayloadHeader: header,
},
},
Signature: b.signature,
Signature: b.signature[:],
})
}
@@ -208,11 +209,11 @@ func (b *SignedBeaconBlock) Header() (*eth.SignedBeaconBlockHeader, error) {
Header: &eth.BeaconBlockHeader{
Slot: b.block.slot,
ProposerIndex: b.block.proposerIndex,
ParentRoot: b.block.parentRoot,
StateRoot: b.block.stateRoot,
ParentRoot: b.block.parentRoot[:],
StateRoot: b.block.stateRoot[:],
BodyRoot: root[:],
},
Signature: b.signature,
Signature: b.signature[:],
}, nil
}
@@ -349,12 +350,12 @@ func (b *BeaconBlock) ProposerIndex() types.ValidatorIndex {
}
// ParentRoot returns the parent root of beacon block.
func (b *BeaconBlock) ParentRoot() []byte {
func (b *BeaconBlock) ParentRoot() [field_params.RootLength]byte {
return b.parentRoot
}
// StateRoot returns the state root of the beacon block.
func (b *BeaconBlock) StateRoot() []byte {
func (b *BeaconBlock) StateRoot() [field_params.RootLength]byte {
return b.stateRoot
}
@@ -379,10 +380,10 @@ func (b *BeaconBlock) Version() int {
}
// HashTreeRoot returns the ssz root of the block.
func (b *BeaconBlock) HashTreeRoot() ([32]byte, error) {
func (b *BeaconBlock) HashTreeRoot() ([field_params.RootLength]byte, error) {
pb, err := b.Proto()
if err != nil {
return [32]byte{}, err
return [field_params.RootLength]byte{}, err
}
switch b.version {
case version.Phase0:
@@ -395,7 +396,7 @@ func (b *BeaconBlock) HashTreeRoot() ([32]byte, error) {
}
return pb.(*eth.BeaconBlockBellatrix).HashTreeRoot()
default:
return [32]byte{}, errIncorrectBlockVersion
return [field_params.RootLength]byte{}, errIncorrectBlockVersion
}
}
@@ -570,7 +571,7 @@ func (b *BeaconBlockBody) IsNil() bool {
}
// RandaoReveal returns the randao reveal from the block body.
func (b *BeaconBlockBody) RandaoReveal() []byte {
func (b *BeaconBlockBody) RandaoReveal() [field_params.BLSSignatureLength]byte {
return b.randaoReveal
}
@@ -580,7 +581,7 @@ func (b *BeaconBlockBody) Eth1Data() *eth.Eth1Data {
}
// Graffiti returns the graffiti in the block.
func (b *BeaconBlockBody) Graffiti() []byte {
func (b *BeaconBlockBody) Graffiti() [field_params.RootLength]byte {
return b.graffiti
}
@@ -633,10 +634,10 @@ func (b *BeaconBlockBody) Execution() (interfaces.ExecutionData, error) {
}
// HashTreeRoot returns the ssz root of the block body.
func (b *BeaconBlockBody) HashTreeRoot() ([32]byte, error) {
func (b *BeaconBlockBody) HashTreeRoot() ([field_params.RootLength]byte, error) {
pb, err := b.Proto()
if err != nil {
return [32]byte{}, err
return [field_params.RootLength]byte{}, err
}
switch b.version {
case version.Phase0:
@@ -649,6 +650,6 @@ func (b *BeaconBlockBody) HashTreeRoot() ([32]byte, error) {
}
return pb.(*eth.BeaconBlockBodyBellatrix).HashTreeRoot()
default:
return [32]byte{}, errIncorrectBodyVersion
return [field_params.RootLength]byte{}, errIncorrectBodyVersion
}
}

View File

@@ -7,6 +7,7 @@ import (
fieldparams "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
validatorpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1/validator-client"
"github.com/prysmaticlabs/prysm/v3/runtime/version"
@@ -40,8 +41,8 @@ func Test_BeaconBlockIsNil(t *testing.T) {
}
func Test_SignedBeaconBlock_Signature(t *testing.T) {
sb := &SignedBeaconBlock{signature: []byte("signature")}
assert.DeepEqual(t, []byte("signature"), sb.Signature())
sb := &SignedBeaconBlock{signature: bytesutil.ToBytes96([]byte("signature"))}
assert.DeepEqual(t, bytesutil.ToBytes96([]byte("signature")), sb.Signature())
}
func Test_SignedBeaconBlock_Block(t *testing.T) {
@@ -88,12 +89,12 @@ func Test_SignedBeaconBlock_Version(t *testing.T) {
func Test_SignedBeaconBlock_Header(t *testing.T) {
bb := &BeaconBlockBody{
version: version.Phase0,
randaoReveal: make([]byte, 96),
randaoReveal: [96]byte{},
eth1Data: &eth.Eth1Data{
DepositRoot: make([]byte, 32),
BlockHash: make([]byte, 32),
},
graffiti: make([]byte, 32),
graffiti: [32]byte{},
}
sb := &SignedBeaconBlock{
version: version.Phase0,
@@ -101,19 +102,19 @@ func Test_SignedBeaconBlock_Header(t *testing.T) {
version: version.Phase0,
slot: 128,
proposerIndex: 128,
parentRoot: []byte("parentroot"),
stateRoot: []byte("stateroot"),
parentRoot: bytesutil.ToBytes32([]byte("parentroot")),
stateRoot: bytesutil.ToBytes32([]byte("stateroot")),
body: bb,
},
signature: []byte("signature"),
signature: bytesutil.ToBytes96([]byte("signature")),
}
h, err := sb.Header()
require.NoError(t, err)
assert.DeepEqual(t, sb.signature, h.Signature)
assert.DeepEqual(t, sb.signature[:], h.Signature)
assert.Equal(t, sb.block.slot, h.Header.Slot)
assert.Equal(t, sb.block.proposerIndex, h.Header.ProposerIndex)
assert.DeepEqual(t, sb.block.parentRoot, h.Header.ParentRoot)
assert.DeepEqual(t, sb.block.stateRoot, h.Header.StateRoot)
assert.DeepEqual(t, sb.block.parentRoot[:], h.Header.ParentRoot)
assert.DeepEqual(t, sb.block.stateRoot[:], h.Header.StateRoot)
expectedHTR, err := bb.HashTreeRoot()
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR[:], h.Header.BodyRoot)
@@ -147,13 +148,13 @@ func Test_BeaconBlock_ProposerIndex(t *testing.T) {
}
func Test_BeaconBlock_ParentRoot(t *testing.T) {
b := &BeaconBlock{parentRoot: []byte("parentroot")}
assert.DeepEqual(t, []byte("parentroot"), b.ParentRoot())
b := &BeaconBlock{parentRoot: bytesutil.ToBytes32([]byte("parentroot"))}
assert.DeepEqual(t, bytesutil.ToBytes32([]byte("parentroot")), b.ParentRoot())
}
func Test_BeaconBlock_StateRoot(t *testing.T) {
b := &BeaconBlock{stateRoot: []byte("stateroot")}
assert.DeepEqual(t, []byte("stateroot"), b.StateRoot())
b := &BeaconBlock{stateRoot: bytesutil.ToBytes32([]byte("stateroot"))}
assert.DeepEqual(t, bytesutil.ToBytes32([]byte("stateroot")), b.StateRoot())
}
func Test_BeaconBlock_Body(t *testing.T) {
@@ -255,8 +256,8 @@ func Test_BeaconBlockBody_IsNil(t *testing.T) {
}
func Test_BeaconBlockBody_RandaoReveal(t *testing.T) {
bb := &BeaconBlockBody{randaoReveal: []byte("randaoreveal")}
assert.DeepEqual(t, []byte("randaoreveal"), bb.RandaoReveal())
bb := &BeaconBlockBody{randaoReveal: bytesutil.ToBytes96([]byte("randaoreveal"))}
assert.DeepEqual(t, bytesutil.ToBytes96([]byte("randaoreveal")), bb.RandaoReveal())
}
func Test_BeaconBlockBody_Eth1Data(t *testing.T) {
@@ -266,8 +267,8 @@ func Test_BeaconBlockBody_Eth1Data(t *testing.T) {
}
func Test_BeaconBlockBody_Graffiti(t *testing.T) {
bb := &BeaconBlockBody{graffiti: []byte("graffiti")}
assert.DeepEqual(t, []byte("graffiti"), bb.Graffiti())
bb := &BeaconBlockBody{graffiti: bytesutil.ToBytes32([]byte("graffiti"))}
assert.DeepEqual(t, bytesutil.ToBytes32([]byte("graffiti")), bb.Graffiti())
}
func Test_BeaconBlockBody_ProposerSlashings(t *testing.T) {

View File

@@ -2,6 +2,7 @@ package blocks
import (
"github.com/pkg/errors"
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
"github.com/prysmaticlabs/prysm/v3/runtime/version"
"google.golang.org/protobuf/proto"
@@ -30,7 +31,7 @@ func (b *SignedBeaconBlock) Proto() (proto.Message, error) {
}
return &eth.SignedBeaconBlock{
Block: block,
Signature: b.signature,
Signature: b.signature[:],
}, nil
case version.Altair:
var block *eth.BeaconBlockAltair
@@ -43,7 +44,7 @@ func (b *SignedBeaconBlock) Proto() (proto.Message, error) {
}
return &eth.SignedBeaconBlockAltair{
Block: block,
Signature: b.signature,
Signature: b.signature[:],
}, nil
case version.Bellatrix:
if b.IsBlinded() {
@@ -57,7 +58,7 @@ func (b *SignedBeaconBlock) Proto() (proto.Message, error) {
}
return &eth.SignedBlindedBeaconBlockBellatrix{
Block: block,
Signature: b.signature,
Signature: b.signature[:],
}, nil
}
var block *eth.BeaconBlockBellatrix
@@ -70,7 +71,7 @@ func (b *SignedBeaconBlock) Proto() (proto.Message, error) {
}
return &eth.SignedBeaconBlockBellatrix{
Block: block,
Signature: b.signature,
Signature: b.signature[:],
}, nil
default:
return nil, errors.New("unsupported signed beacon block version")
@@ -101,8 +102,8 @@ func (b *BeaconBlock) Proto() (proto.Message, error) {
return &eth.BeaconBlock{
Slot: b.slot,
ProposerIndex: b.proposerIndex,
ParentRoot: b.parentRoot,
StateRoot: b.stateRoot,
ParentRoot: b.parentRoot[:],
StateRoot: b.stateRoot[:],
Body: body,
}, nil
case version.Altair:
@@ -117,8 +118,8 @@ func (b *BeaconBlock) Proto() (proto.Message, error) {
return &eth.BeaconBlockAltair{
Slot: b.slot,
ProposerIndex: b.proposerIndex,
ParentRoot: b.parentRoot,
StateRoot: b.stateRoot,
ParentRoot: b.parentRoot[:],
StateRoot: b.stateRoot[:],
Body: body,
}, nil
case version.Bellatrix:
@@ -134,8 +135,8 @@ func (b *BeaconBlock) Proto() (proto.Message, error) {
return &eth.BlindedBeaconBlockBellatrix{
Slot: b.slot,
ProposerIndex: b.proposerIndex,
ParentRoot: b.parentRoot,
StateRoot: b.stateRoot,
ParentRoot: b.parentRoot[:],
StateRoot: b.stateRoot[:],
Body: body,
}, nil
}
@@ -150,8 +151,8 @@ func (b *BeaconBlock) Proto() (proto.Message, error) {
return &eth.BeaconBlockBellatrix{
Slot: b.slot,
ProposerIndex: b.proposerIndex,
ParentRoot: b.parentRoot,
StateRoot: b.stateRoot,
ParentRoot: b.parentRoot[:],
StateRoot: b.stateRoot[:],
Body: body,
}, nil
default:
@@ -168,9 +169,9 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) {
switch b.version {
case version.Phase0:
return &eth.BeaconBlockBody{
RandaoReveal: b.randaoReveal,
RandaoReveal: b.randaoReveal[:],
Eth1Data: b.eth1Data,
Graffiti: b.graffiti,
Graffiti: b.graffiti[:],
ProposerSlashings: b.proposerSlashings,
AttesterSlashings: b.attesterSlashings,
Attestations: b.attestations,
@@ -179,9 +180,9 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) {
}, nil
case version.Altair:
return &eth.BeaconBlockBodyAltair{
RandaoReveal: b.randaoReveal,
RandaoReveal: b.randaoReveal[:],
Eth1Data: b.eth1Data,
Graffiti: b.graffiti,
Graffiti: b.graffiti[:],
ProposerSlashings: b.proposerSlashings,
AttesterSlashings: b.attesterSlashings,
Attestations: b.attestations,
@@ -192,9 +193,9 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) {
case version.Bellatrix:
if b.isBlinded {
return &eth.BlindedBeaconBlockBodyBellatrix{
RandaoReveal: b.randaoReveal,
RandaoReveal: b.randaoReveal[:],
Eth1Data: b.eth1Data,
Graffiti: b.graffiti,
Graffiti: b.graffiti[:],
ProposerSlashings: b.proposerSlashings,
AttesterSlashings: b.attesterSlashings,
Attestations: b.attestations,
@@ -205,9 +206,9 @@ func (b *BeaconBlockBody) Proto() (proto.Message, error) {
}, nil
}
return &eth.BeaconBlockBodyBellatrix{
RandaoReveal: b.randaoReveal,
RandaoReveal: b.randaoReveal[:],
Eth1Data: b.eth1Data,
Graffiti: b.graffiti,
Graffiti: b.graffiti[:],
ProposerSlashings: b.proposerSlashings,
AttesterSlashings: b.attesterSlashings,
Attestations: b.attestations,
@@ -233,7 +234,7 @@ func initSignedBlockFromProtoPhase0(pb *eth.SignedBeaconBlock) (*SignedBeaconBlo
b := &SignedBeaconBlock{
version: version.Phase0,
block: block,
signature: pb.Signature,
signature: bytesutil.ToBytes96(pb.Signature),
}
return b, nil
}
@@ -250,7 +251,7 @@ func initSignedBlockFromProtoAltair(pb *eth.SignedBeaconBlockAltair) (*SignedBea
b := &SignedBeaconBlock{
version: version.Altair,
block: block,
signature: pb.Signature,
signature: bytesutil.ToBytes96(pb.Signature),
}
return b, nil
}
@@ -267,7 +268,7 @@ func initSignedBlockFromProtoBellatrix(pb *eth.SignedBeaconBlockBellatrix) (*Sig
b := &SignedBeaconBlock{
version: version.Bellatrix,
block: block,
signature: pb.Signature,
signature: bytesutil.ToBytes96(pb.Signature),
}
return b, nil
}
@@ -284,7 +285,7 @@ func initBlindedSignedBlockFromProtoBellatrix(pb *eth.SignedBlindedBeaconBlockBe
b := &SignedBeaconBlock{
version: version.Bellatrix,
block: block,
signature: pb.Signature,
signature: bytesutil.ToBytes96(pb.Signature),
}
return b, nil
}
@@ -302,8 +303,8 @@ func initBlockFromProtoPhase0(pb *eth.BeaconBlock) (*BeaconBlock, error) {
version: version.Phase0,
slot: pb.Slot,
proposerIndex: pb.ProposerIndex,
parentRoot: pb.ParentRoot,
stateRoot: pb.StateRoot,
parentRoot: bytesutil.ToBytes32(pb.ParentRoot),
stateRoot: bytesutil.ToBytes32(pb.StateRoot),
body: body,
}
return b, nil
@@ -322,8 +323,8 @@ func initBlockFromProtoAltair(pb *eth.BeaconBlockAltair) (*BeaconBlock, error) {
version: version.Altair,
slot: pb.Slot,
proposerIndex: pb.ProposerIndex,
parentRoot: pb.ParentRoot,
stateRoot: pb.StateRoot,
parentRoot: bytesutil.ToBytes32(pb.ParentRoot),
stateRoot: bytesutil.ToBytes32(pb.StateRoot),
body: body,
}
return b, nil
@@ -342,8 +343,8 @@ func initBlockFromProtoBellatrix(pb *eth.BeaconBlockBellatrix) (*BeaconBlock, er
version: version.Bellatrix,
slot: pb.Slot,
proposerIndex: pb.ProposerIndex,
parentRoot: pb.ParentRoot,
stateRoot: pb.StateRoot,
parentRoot: bytesutil.ToBytes32(pb.ParentRoot),
stateRoot: bytesutil.ToBytes32(pb.StateRoot),
body: body,
}
return b, nil
@@ -362,8 +363,8 @@ func initBlindedBlockFromProtoBellatrix(pb *eth.BlindedBeaconBlockBellatrix) (*B
version: version.Bellatrix,
slot: pb.Slot,
proposerIndex: pb.ProposerIndex,
parentRoot: pb.ParentRoot,
stateRoot: pb.StateRoot,
parentRoot: bytesutil.ToBytes32(pb.ParentRoot),
stateRoot: bytesutil.ToBytes32(pb.StateRoot),
body: body,
}
return b, nil
@@ -377,9 +378,9 @@ func initBlockBodyFromProtoPhase0(pb *eth.BeaconBlockBody) (*BeaconBlockBody, er
b := &BeaconBlockBody{
version: version.Phase0,
isBlinded: false,
randaoReveal: pb.RandaoReveal,
randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal),
eth1Data: pb.Eth1Data,
graffiti: pb.Graffiti,
graffiti: bytesutil.ToBytes32(pb.Graffiti),
proposerSlashings: pb.ProposerSlashings,
attesterSlashings: pb.AttesterSlashings,
attestations: pb.Attestations,
@@ -397,9 +398,9 @@ func initBlockBodyFromProtoAltair(pb *eth.BeaconBlockBodyAltair) (*BeaconBlockBo
b := &BeaconBlockBody{
version: version.Altair,
isBlinded: false,
randaoReveal: pb.RandaoReveal,
randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal),
eth1Data: pb.Eth1Data,
graffiti: pb.Graffiti,
graffiti: bytesutil.ToBytes32(pb.Graffiti),
proposerSlashings: pb.ProposerSlashings,
attesterSlashings: pb.AttesterSlashings,
attestations: pb.Attestations,
@@ -418,9 +419,9 @@ func initBlockBodyFromProtoBellatrix(pb *eth.BeaconBlockBodyBellatrix) (*BeaconB
b := &BeaconBlockBody{
version: version.Bellatrix,
isBlinded: false,
randaoReveal: pb.RandaoReveal,
randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal),
eth1Data: pb.Eth1Data,
graffiti: pb.Graffiti,
graffiti: bytesutil.ToBytes32(pb.Graffiti),
proposerSlashings: pb.ProposerSlashings,
attesterSlashings: pb.AttesterSlashings,
attestations: pb.Attestations,
@@ -440,9 +441,9 @@ func initBlindedBlockBodyFromProtoBellatrix(pb *eth.BlindedBeaconBlockBodyBellat
b := &BeaconBlockBody{
version: version.Bellatrix,
isBlinded: true,
randaoReveal: pb.RandaoReveal,
randaoReveal: bytesutil.ToBytes96(pb.RandaoReveal),
eth1Data: pb.Eth1Data,
graffiti: pb.Graffiti,
graffiti: bytesutil.ToBytes32(pb.Graffiti),
proposerSlashings: pb.ProposerSlashings,
attesterSlashings: pb.AttesterSlashings,
attestations: pb.Attestations,

View File

@@ -12,11 +12,8 @@ import (
)
type fields struct {
b20 []byte
b32 []byte
b48 []byte
b96 []byte
b256 []byte
root [32]byte
sig [96]byte
deposits []*eth.Deposit
atts []*eth.Attestation
proposerSlashings []*eth.ProposerSlashing
@@ -35,11 +32,11 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) {
Block: &eth.BeaconBlock{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbPhase0(),
},
Signature: f.b96,
Signature: f.sig[:],
}
block := &SignedBeaconBlock{
version: version.Phase0,
@@ -47,11 +44,11 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) {
version: version.Phase0,
slot: 128,
proposerIndex: 128,
parentRoot: f.b32,
stateRoot: f.b32,
parentRoot: f.root,
stateRoot: f.root,
body: bodyPhase0(),
},
signature: f.b96,
signature: f.sig,
}
result, err := block.Proto()
@@ -69,11 +66,11 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) {
Block: &eth.BeaconBlockAltair{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbAltair(),
},
Signature: f.b96,
Signature: f.sig[:],
}
block := &SignedBeaconBlock{
version: version.Altair,
@@ -81,11 +78,11 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) {
version: version.Altair,
slot: 128,
proposerIndex: 128,
parentRoot: f.b32,
stateRoot: f.b32,
parentRoot: f.root,
stateRoot: f.root,
body: bodyAltair(),
},
signature: f.b96,
signature: f.sig,
}
result, err := block.Proto()
@@ -103,11 +100,11 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) {
Block: &eth.BeaconBlockBellatrix{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbBellatrix(),
},
Signature: f.b96,
Signature: f.sig[:],
}
block := &SignedBeaconBlock{
version: version.Bellatrix,
@@ -115,11 +112,11 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) {
version: version.Bellatrix,
slot: 128,
proposerIndex: 128,
parentRoot: f.b32,
stateRoot: f.b32,
parentRoot: f.root,
stateRoot: f.root,
body: bodyBellatrix(),
},
signature: f.b96,
signature: f.sig,
}
result, err := block.Proto()
@@ -137,11 +134,11 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) {
Block: &eth.BlindedBeaconBlockBellatrix{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbBlindedBellatrix(),
},
Signature: f.b96,
Signature: f.sig[:],
}
block := &SignedBeaconBlock{
version: version.Bellatrix,
@@ -149,11 +146,11 @@ func Test_SignedBeaconBlock_Proto(t *testing.T) {
version: version.Bellatrix,
slot: 128,
proposerIndex: 128,
parentRoot: f.b32,
stateRoot: f.b32,
parentRoot: f.root,
stateRoot: f.root,
body: bodyBlindedBellatrix(),
},
signature: f.b96,
signature: f.sig,
}
result, err := block.Proto()
@@ -175,16 +172,16 @@ func Test_BeaconBlock_Proto(t *testing.T) {
expectedBlock := &eth.BeaconBlock{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbPhase0(),
}
block := &BeaconBlock{
version: version.Phase0,
slot: 128,
proposerIndex: 128,
parentRoot: f.b32,
stateRoot: f.b32,
parentRoot: f.root,
stateRoot: f.root,
body: bodyPhase0(),
}
@@ -202,16 +199,16 @@ func Test_BeaconBlock_Proto(t *testing.T) {
expectedBlock := &eth.BeaconBlockAltair{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbAltair(),
}
block := &BeaconBlock{
version: version.Altair,
slot: 128,
proposerIndex: 128,
parentRoot: f.b32,
stateRoot: f.b32,
parentRoot: f.root,
stateRoot: f.root,
body: bodyAltair(),
}
@@ -229,16 +226,16 @@ func Test_BeaconBlock_Proto(t *testing.T) {
expectedBlock := &eth.BeaconBlockBellatrix{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbBellatrix(),
}
block := &BeaconBlock{
version: version.Bellatrix,
slot: 128,
proposerIndex: 128,
parentRoot: f.b32,
stateRoot: f.b32,
parentRoot: f.root,
stateRoot: f.root,
body: bodyBellatrix(),
}
@@ -256,16 +253,16 @@ func Test_BeaconBlock_Proto(t *testing.T) {
expectedBlock := &eth.BlindedBeaconBlockBellatrix{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbBlindedBellatrix(),
}
block := &BeaconBlock{
version: version.Bellatrix,
slot: 128,
proposerIndex: 128,
parentRoot: f.b32,
stateRoot: f.b32,
parentRoot: f.root,
stateRoot: f.root,
body: bodyBlindedBellatrix(),
}
@@ -343,11 +340,11 @@ func Test_initSignedBlockFromProtoPhase0(t *testing.T) {
Block: &eth.BeaconBlock{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbPhase0(),
},
Signature: f.b96,
Signature: f.sig[:],
}
resultBlock, err := initSignedBlockFromProtoPhase0(expectedBlock)
require.NoError(t, err)
@@ -356,7 +353,7 @@ func Test_initSignedBlockFromProtoPhase0(t *testing.T) {
expectedHTR, err := expectedBlock.Block.HashTreeRoot()
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR, resultHTR)
assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature)
assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature[:])
}
func Test_initSignedBlockFromProtoAltair(t *testing.T) {
@@ -365,11 +362,11 @@ func Test_initSignedBlockFromProtoAltair(t *testing.T) {
Block: &eth.BeaconBlockAltair{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbAltair(),
},
Signature: f.b96,
Signature: f.sig[:],
}
resultBlock, err := initSignedBlockFromProtoAltair(expectedBlock)
require.NoError(t, err)
@@ -378,7 +375,7 @@ func Test_initSignedBlockFromProtoAltair(t *testing.T) {
expectedHTR, err := expectedBlock.Block.HashTreeRoot()
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR, resultHTR)
assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature)
assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature[:])
}
func Test_initSignedBlockFromProtoBellatrix(t *testing.T) {
@@ -387,11 +384,11 @@ func Test_initSignedBlockFromProtoBellatrix(t *testing.T) {
Block: &eth.BeaconBlockBellatrix{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbBellatrix(),
},
Signature: f.b96,
Signature: f.sig[:],
}
resultBlock, err := initSignedBlockFromProtoBellatrix(expectedBlock)
require.NoError(t, err)
@@ -400,7 +397,7 @@ func Test_initSignedBlockFromProtoBellatrix(t *testing.T) {
expectedHTR, err := expectedBlock.Block.HashTreeRoot()
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR, resultHTR)
assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature)
assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature[:])
}
func Test_initBlindedSignedBlockFromProtoBellatrix(t *testing.T) {
@@ -409,11 +406,11 @@ func Test_initBlindedSignedBlockFromProtoBellatrix(t *testing.T) {
Block: &eth.BlindedBeaconBlockBellatrix{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbBlindedBellatrix(),
},
Signature: f.b96,
Signature: f.sig[:],
}
resultBlock, err := initBlindedSignedBlockFromProtoBellatrix(expectedBlock)
require.NoError(t, err)
@@ -422,7 +419,7 @@ func Test_initBlindedSignedBlockFromProtoBellatrix(t *testing.T) {
expectedHTR, err := expectedBlock.Block.HashTreeRoot()
require.NoError(t, err)
assert.DeepEqual(t, expectedHTR, resultHTR)
assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature)
assert.DeepEqual(t, expectedBlock.Signature, resultBlock.signature[:])
}
func Test_initBlockFromProtoPhase0(t *testing.T) {
@@ -430,8 +427,8 @@ func Test_initBlockFromProtoPhase0(t *testing.T) {
expectedBlock := &eth.BeaconBlock{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbPhase0(),
}
resultBlock, err := initBlockFromProtoPhase0(expectedBlock)
@@ -448,8 +445,8 @@ func Test_initBlockFromProtoAltair(t *testing.T) {
expectedBlock := &eth.BeaconBlockAltair{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbAltair(),
}
resultBlock, err := initBlockFromProtoAltair(expectedBlock)
@@ -466,8 +463,8 @@ func Test_initBlockFromProtoBellatrix(t *testing.T) {
expectedBlock := &eth.BeaconBlockBellatrix{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbBellatrix(),
}
resultBlock, err := initBlockFromProtoBellatrix(expectedBlock)
@@ -484,8 +481,8 @@ func Test_initBlockFromProtoBlindedBellatrix(t *testing.T) {
expectedBlock := &eth.BlindedBeaconBlockBellatrix{
Slot: 128,
ProposerIndex: 128,
ParentRoot: f.b32,
StateRoot: f.b32,
ParentRoot: f.root[:],
StateRoot: f.root[:],
Body: bodyPbBlindedBellatrix(),
}
resultBlock, err := initBlindedBlockFromProtoBellatrix(expectedBlock)
@@ -544,13 +541,13 @@ func Test_initBlockBodyFromProtoBlindedBellatrix(t *testing.T) {
func bodyPbPhase0() *eth.BeaconBlockBody {
f := getFields()
return &eth.BeaconBlockBody{
RandaoReveal: f.b96,
RandaoReveal: f.sig[:],
Eth1Data: &eth.Eth1Data{
DepositRoot: f.b32,
DepositRoot: f.root[:],
DepositCount: 128,
BlockHash: f.b32,
BlockHash: f.root[:],
},
Graffiti: f.b32,
Graffiti: f.root[:],
ProposerSlashings: f.proposerSlashings,
AttesterSlashings: f.attesterSlashings,
Attestations: f.atts,
@@ -562,13 +559,13 @@ func bodyPbPhase0() *eth.BeaconBlockBody {
func bodyPbAltair() *eth.BeaconBlockBodyAltair {
f := getFields()
return &eth.BeaconBlockBodyAltair{
RandaoReveal: f.b96,
RandaoReveal: f.sig[:],
Eth1Data: &eth.Eth1Data{
DepositRoot: f.b32,
DepositRoot: f.root[:],
DepositCount: 128,
BlockHash: f.b32,
BlockHash: f.root[:],
},
Graffiti: f.b32,
Graffiti: f.root[:],
ProposerSlashings: f.proposerSlashings,
AttesterSlashings: f.attesterSlashings,
Attestations: f.atts,
@@ -581,13 +578,13 @@ func bodyPbAltair() *eth.BeaconBlockBodyAltair {
func bodyPbBellatrix() *eth.BeaconBlockBodyBellatrix {
f := getFields()
return &eth.BeaconBlockBodyBellatrix{
RandaoReveal: f.b96,
RandaoReveal: f.sig[:],
Eth1Data: &eth.Eth1Data{
DepositRoot: f.b32,
DepositRoot: f.root[:],
DepositCount: 128,
BlockHash: f.b32,
BlockHash: f.root[:],
},
Graffiti: f.b32,
Graffiti: f.root[:],
ProposerSlashings: f.proposerSlashings,
AttesterSlashings: f.attesterSlashings,
Attestations: f.atts,
@@ -601,13 +598,13 @@ func bodyPbBellatrix() *eth.BeaconBlockBodyBellatrix {
func bodyPbBlindedBellatrix() *eth.BlindedBeaconBlockBodyBellatrix {
f := getFields()
return &eth.BlindedBeaconBlockBodyBellatrix{
RandaoReveal: f.b96,
RandaoReveal: f.sig[:],
Eth1Data: &eth.Eth1Data{
DepositRoot: f.b32,
DepositRoot: f.root[:],
DepositCount: 128,
BlockHash: f.b32,
BlockHash: f.root[:],
},
Graffiti: f.b32,
Graffiti: f.root[:],
ProposerSlashings: f.proposerSlashings,
AttesterSlashings: f.attesterSlashings,
Attestations: f.atts,
@@ -622,13 +619,13 @@ func bodyPhase0() *BeaconBlockBody {
f := getFields()
return &BeaconBlockBody{
version: version.Phase0,
randaoReveal: f.b96,
randaoReveal: f.sig,
eth1Data: &eth.Eth1Data{
DepositRoot: f.b32,
DepositRoot: f.root[:],
DepositCount: 128,
BlockHash: f.b32,
BlockHash: f.root[:],
},
graffiti: f.b32,
graffiti: f.root,
proposerSlashings: f.proposerSlashings,
attesterSlashings: f.attesterSlashings,
attestations: f.atts,
@@ -641,13 +638,13 @@ func bodyAltair() *BeaconBlockBody {
f := getFields()
return &BeaconBlockBody{
version: version.Altair,
randaoReveal: f.b96,
randaoReveal: f.sig,
eth1Data: &eth.Eth1Data{
DepositRoot: f.b32,
DepositRoot: f.root[:],
DepositCount: 128,
BlockHash: f.b32,
BlockHash: f.root[:],
},
graffiti: f.b32,
graffiti: f.root,
proposerSlashings: f.proposerSlashings,
attesterSlashings: f.attesterSlashings,
attestations: f.atts,
@@ -661,13 +658,13 @@ func bodyBellatrix() *BeaconBlockBody {
f := getFields()
return &BeaconBlockBody{
version: version.Bellatrix,
randaoReveal: f.b96,
randaoReveal: f.sig,
eth1Data: &eth.Eth1Data{
DepositRoot: f.b32,
DepositRoot: f.root[:],
DepositCount: 128,
BlockHash: f.b32,
BlockHash: f.root[:],
},
graffiti: f.b32,
graffiti: f.root,
proposerSlashings: f.proposerSlashings,
attesterSlashings: f.attesterSlashings,
attestations: f.atts,
@@ -683,13 +680,13 @@ func bodyBlindedBellatrix() *BeaconBlockBody {
return &BeaconBlockBody{
version: version.Bellatrix,
isBlinded: true,
randaoReveal: f.b96,
randaoReveal: f.sig,
eth1Data: &eth.Eth1Data{
DepositRoot: f.b32,
DepositRoot: f.root[:],
DepositCount: 128,
BlockHash: f.b32,
BlockHash: f.root[:],
},
graffiti: f.b32,
graffiti: f.root,
proposerSlashings: f.proposerSlashings,
attesterSlashings: f.attesterSlashings,
attestations: f.atts,
@@ -702,45 +699,45 @@ func bodyBlindedBellatrix() *BeaconBlockBody {
func getFields() fields {
b20 := make([]byte, 20)
b32 := make([]byte, 32)
b48 := make([]byte, 48)
b96 := make([]byte, 96)
b256 := make([]byte, 256)
var root [32]byte
var sig [96]byte
b20[0], b20[5], b20[10] = 'q', 'u', 'x'
b32[0], b32[5], b32[10] = 'f', 'o', 'o'
b48[0], b48[5], b48[10] = 'b', 'a', 'r'
b96[0], b96[5], b96[10] = 'b', 'a', 'z'
b256[0], b256[5], b256[10] = 'x', 'y', 'z'
root[0], root[5], root[10] = 'a', 'b', 'c'
sig[0], sig[5], sig[10] = 'd', 'e', 'f'
deposits := make([]*eth.Deposit, 16)
for i := range deposits {
deposits[i] = &eth.Deposit{}
deposits[i].Proof = make([][]byte, 33)
for j := range deposits[i].Proof {
deposits[i].Proof[j] = b32
deposits[i].Proof[j] = root[:]
}
deposits[i].Data = &eth.Deposit_Data{
PublicKey: b48,
WithdrawalCredentials: b32,
WithdrawalCredentials: root[:],
Amount: 128,
Signature: b96,
Signature: sig[:],
}
}
atts := make([]*eth.Attestation, 128)
for i := range atts {
atts[i] = &eth.Attestation{}
atts[i].Signature = b96
atts[i].Signature = sig[:]
atts[i].AggregationBits = bitfield.NewBitlist(1)
atts[i].Data = &eth.AttestationData{
Slot: 128,
CommitteeIndex: 128,
BeaconBlockRoot: b32,
BeaconBlockRoot: root[:],
Source: &eth.Checkpoint{
Epoch: 128,
Root: b32,
Root: root[:],
},
Target: &eth.Checkpoint{
Epoch: 128,
Root: b32,
Root: root[:],
},
}
}
@@ -749,21 +746,21 @@ func getFields() fields {
Header: &eth.BeaconBlockHeader{
Slot: 128,
ProposerIndex: 128,
ParentRoot: b32,
StateRoot: b32,
BodyRoot: b32,
ParentRoot: root[:],
StateRoot: root[:],
BodyRoot: root[:],
},
Signature: b96,
Signature: sig[:],
},
Header_2: &eth.SignedBeaconBlockHeader{
Header: &eth.BeaconBlockHeader{
Slot: 128,
ProposerIndex: 128,
ParentRoot: b32,
StateRoot: b32,
BodyRoot: b32,
ParentRoot: root[:],
StateRoot: root[:],
BodyRoot: root[:],
},
Signature: b96,
Signature: sig[:],
},
}
attesterSlashing := &eth.AttesterSlashing{
@@ -772,34 +769,34 @@ func getFields() fields {
Data: &eth.AttestationData{
Slot: 128,
CommitteeIndex: 128,
BeaconBlockRoot: b32,
BeaconBlockRoot: root[:],
Source: &eth.Checkpoint{
Epoch: 128,
Root: b32,
Root: root[:],
},
Target: &eth.Checkpoint{
Epoch: 128,
Root: b32,
Root: root[:],
},
},
Signature: b96,
Signature: sig[:],
},
Attestation_2: &eth.IndexedAttestation{
AttestingIndices: []uint64{1, 2, 8},
Data: &eth.AttestationData{
Slot: 128,
CommitteeIndex: 128,
BeaconBlockRoot: b32,
BeaconBlockRoot: root[:],
Source: &eth.Checkpoint{
Epoch: 128,
Root: b32,
Root: root[:],
},
Target: &eth.Checkpoint{
Epoch: 128,
Root: b32,
Root: root[:],
},
},
Signature: b96,
Signature: sig[:],
},
}
voluntaryExit := &eth.SignedVoluntaryExit{
@@ -807,7 +804,7 @@ func getFields() fields {
Epoch: 128,
ValidatorIndex: 128,
},
Signature: b96,
Signature: sig[:],
}
syncCommitteeBits := bitfield.NewBitvector512()
syncCommitteeBits.SetBitAt(1, true)
@@ -815,22 +812,22 @@ func getFields() fields {
syncCommitteeBits.SetBitAt(8, true)
syncAggregate := &eth.SyncAggregate{
SyncCommitteeBits: syncCommitteeBits,
SyncCommitteeSignature: b96,
SyncCommitteeSignature: sig[:],
}
execPayload := &enginev1.ExecutionPayload{
ParentHash: b32,
ParentHash: root[:],
FeeRecipient: b20,
StateRoot: b32,
ReceiptsRoot: b32,
StateRoot: root[:],
ReceiptsRoot: root[:],
LogsBloom: b256,
PrevRandao: b32,
PrevRandao: root[:],
BlockNumber: 128,
GasLimit: 128,
GasUsed: 128,
Timestamp: 128,
ExtraData: b32,
BaseFeePerGas: b32,
BlockHash: b32,
ExtraData: root[:],
BaseFeePerGas: root[:],
BlockHash: root[:],
Transactions: [][]byte{
[]byte("transaction1"),
[]byte("transaction2"),
@@ -838,28 +835,25 @@ func getFields() fields {
},
}
execPayloadHeader := &enginev1.ExecutionPayloadHeader{
ParentHash: b32,
ParentHash: root[:],
FeeRecipient: b20,
StateRoot: b32,
ReceiptsRoot: b32,
StateRoot: root[:],
ReceiptsRoot: root[:],
LogsBloom: b256,
PrevRandao: b32,
PrevRandao: root[:],
BlockNumber: 128,
GasLimit: 128,
GasUsed: 128,
Timestamp: 128,
ExtraData: b32,
BaseFeePerGas: b32,
BlockHash: b32,
TransactionsRoot: b32,
ExtraData: root[:],
BaseFeePerGas: root[:],
BlockHash: root[:],
TransactionsRoot: root[:],
}
return fields{
b20: b20,
b32: b32,
b48: b48,
b96: b96,
b256: b256,
root: root,
sig: sig,
deposits: deposits,
atts: atts,
proposerSlashings: []*eth.ProposerSlashing{proposerSlashing},

View File

@@ -4,6 +4,7 @@ import (
"fmt"
"github.com/pkg/errors"
field_params "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
engine "github.com/prysmaticlabs/prysm/v3/proto/engine/v1"
@@ -39,9 +40,9 @@ var (
type BeaconBlockBody struct {
version int
isBlinded bool
randaoReveal []byte
randaoReveal [field_params.BLSSignatureLength]byte
eth1Data *eth.Eth1Data
graffiti []byte
graffiti [field_params.RootLength]byte
proposerSlashings []*eth.ProposerSlashing
attesterSlashings []*eth.AttesterSlashing
attestations []*eth.Attestation
@@ -57,8 +58,8 @@ type BeaconBlock struct {
version int
slot types.Slot
proposerIndex types.ValidatorIndex
parentRoot []byte
stateRoot []byte
parentRoot [field_params.RootLength]byte
stateRoot [field_params.RootLength]byte
body *BeaconBlockBody
}
@@ -66,7 +67,7 @@ type BeaconBlock struct {
type SignedBeaconBlock struct {
version int
block *BeaconBlock
signature []byte
signature [field_params.BLSSignatureLength]byte
}
func errNotSupported(funcName string, ver int) error {

View File

@@ -9,6 +9,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces",
visibility = ["//visibility:public"],
deps = [
"//config/fieldparams:go_default_library",
"//consensus-types/primitives:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",
"//proto/prysm/v1alpha1/validator-client:go_default_library",

View File

@@ -2,6 +2,7 @@ package interfaces
import (
ssz "github.com/prysmaticlabs/fastssz"
field_params "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
ethpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
validatorpb "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1/validator-client"
@@ -12,7 +13,7 @@ import (
// a signed beacon block.
type SignedBeaconBlock interface {
Block() BeaconBlock
Signature() []byte
Signature() [field_params.BLSSignatureLength]byte
IsNil() bool
Copy() (SignedBeaconBlock, error)
Proto() (proto.Message, error)
@@ -34,12 +35,12 @@ type SignedBeaconBlock interface {
type BeaconBlock interface {
Slot() types.Slot
ProposerIndex() types.ValidatorIndex
ParentRoot() []byte
StateRoot() []byte
ParentRoot() [field_params.RootLength]byte
StateRoot() [field_params.RootLength]byte
Body() BeaconBlockBody
IsNil() bool
IsBlinded() bool
HashTreeRoot() ([32]byte, error)
HashTreeRoot() ([field_params.RootLength]byte, error)
Proto() (proto.Message, error)
ssz.Marshaler
ssz.Unmarshaler
@@ -51,9 +52,9 @@ type BeaconBlock interface {
// BeaconBlockBody describes the method set employed by an object
// that is a beacon block body.
type BeaconBlockBody interface {
RandaoReveal() []byte
RandaoReveal() [field_params.BLSSignatureLength]byte
Eth1Data() *ethpb.Eth1Data
Graffiti() []byte
Graffiti() [field_params.RootLength]byte
ProposerSlashings() []*ethpb.ProposerSlashing
AttesterSlashings() []*ethpb.AttesterSlashing
Attestations() []*ethpb.Attestation
@@ -61,7 +62,7 @@ type BeaconBlockBody interface {
VoluntaryExits() []*ethpb.SignedVoluntaryExit
SyncAggregate() (*ethpb.SyncAggregate, error)
IsNil() bool
HashTreeRoot() ([32]byte, error)
HashTreeRoot() ([field_params.RootLength]byte, error)
Proto() (proto.Message, error)
Execution() (ExecutionData, error)
}

View File

@@ -38,9 +38,10 @@ func SignedBeaconBlockHeaderFromBlockInterface(sb SignedBeaconBlock) (*ethpb.Sig
if err != nil {
return nil, errors.Wrap(err, "failed to get block header of block")
}
sig := sb.Signature()
return &ethpb.SignedBeaconBlockHeader{
Header: h,
Signature: sb.Signature(),
Signature: sig[:],
}, nil
}
@@ -73,11 +74,13 @@ func BeaconBlockHeaderFromBlockInterface(block BeaconBlock) (*ethpb.BeaconBlockH
if err != nil {
return nil, errors.Wrap(err, "failed to get body root of block")
}
parentRoot := block.ParentRoot()
stateRoot := block.StateRoot()
return &ethpb.BeaconBlockHeader{
Slot: block.Slot(),
ProposerIndex: block.ProposerIndex(),
ParentRoot: block.ParentRoot(),
StateRoot: block.StateRoot(),
ParentRoot: parentRoot[:],
StateRoot: stateRoot[:],
BodyRoot: bodyRoot[:],
}, nil
}

View File

@@ -6,6 +6,7 @@ go_library(
importpath = "github.com/prysmaticlabs/prysm/v3/consensus-types/mock",
visibility = ["//visibility:public"],
deps = [
"//config/fieldparams:go_default_library",
"//consensus-types/interfaces:go_default_library",
"//consensus-types/primitives:go_default_library",
"//proto/prysm/v1alpha1:go_default_library",

View File

@@ -2,6 +2,7 @@ package mock
import (
ssz "github.com/prysmaticlabs/fastssz"
field_params "github.com/prysmaticlabs/prysm/v3/config/fieldparams"
"github.com/prysmaticlabs/prysm/v3/consensus-types/interfaces"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
eth "github.com/prysmaticlabs/prysm/v3/proto/prysm/v1alpha1"
@@ -21,7 +22,7 @@ func (m SignedBeaconBlock) Block() interfaces.BeaconBlock {
return m.BeaconBlock
}
func (SignedBeaconBlock) Signature() []byte {
func (SignedBeaconBlock) Signature() [field_params.BLSSignatureLength]byte {
panic("implement me")
}
@@ -86,7 +87,7 @@ func (SignedBeaconBlock) Header() (*eth.SignedBeaconBlockHeader, error) {
}
type BeaconBlock struct {
Htr [32]byte
Htr [field_params.RootLength]byte
HtrErr error
BeaconBlockBody interfaces.BeaconBlockBody
BlockSlot types.Slot
@@ -96,7 +97,7 @@ func (BeaconBlock) AsSignRequestObject() (validatorpb.SignRequestObject, error)
panic("implement me")
}
func (m BeaconBlock) HashTreeRoot() ([32]byte, error) {
func (m BeaconBlock) HashTreeRoot() ([field_params.RootLength]byte, error) {
return m.Htr, m.HtrErr
}
@@ -108,11 +109,11 @@ func (BeaconBlock) ProposerIndex() types.ValidatorIndex {
panic("implement me")
}
func (BeaconBlock) ParentRoot() []byte {
func (BeaconBlock) ParentRoot() [field_params.RootLength]byte {
panic("implement me")
}
func (BeaconBlock) StateRoot() []byte {
func (BeaconBlock) StateRoot() [field_params.RootLength]byte {
panic("implement me")
}
@@ -158,7 +159,7 @@ func (BeaconBlock) Version() int {
type BeaconBlockBody struct{}
func (BeaconBlockBody) RandaoReveal() []byte {
func (BeaconBlockBody) RandaoReveal() [field_params.BLSSignatureLength]byte {
panic("implement me")
}
@@ -166,7 +167,7 @@ func (BeaconBlockBody) Eth1Data() *eth.Eth1Data {
panic("implement me")
}
func (BeaconBlockBody) Graffiti() []byte {
func (BeaconBlockBody) Graffiti() [field_params.RootLength]byte {
panic("implement me")
}
@@ -198,7 +199,7 @@ func (BeaconBlockBody) IsNil() bool {
return false
}
func (BeaconBlockBody) HashTreeRoot() ([32]byte, error) {
func (BeaconBlockBody) HashTreeRoot() ([field_params.RootLength]byte, error) {
panic("implement me")
}

View File

@@ -16,15 +16,18 @@ func BlockIfaceToV1BlockHeader(block interfaces.SignedBeaconBlock) (*ethpbv1.Sig
if err != nil {
return nil, errors.Wrap(err, "failed to get body root of block")
}
parentRoot := block.Block().ParentRoot()
stateRoot := block.Block().StateRoot()
sig := block.Signature()
return &ethpbv1.SignedBeaconBlockHeader{
Message: &ethpbv1.BeaconBlockHeader{
Slot: block.Block().Slot(),
ProposerIndex: block.Block().ProposerIndex(),
ParentRoot: block.Block().ParentRoot(),
StateRoot: block.Block().StateRoot(),
ParentRoot: parentRoot[:],
StateRoot: stateRoot[:],
BodyRoot: bodyRoot[:],
},
Signature: block.Signature(),
Signature: sig[:],
}, nil
}

View File

@@ -159,7 +159,7 @@ func verifyGraffitiInBlocks(conns ...*grpc.ClientConn) error {
slot := blk.Block().Slot()
graffitiInBlock := blk.Block().Body().Graffiti()
for _, graffiti := range helpers.Graffiti {
if bytes.Equal(bytesutil.PadTo([]byte(graffiti), 32), graffitiInBlock) {
if bytes.Equal(bytesutil.PadTo([]byte(graffiti), 32), graffitiInBlock[:]) {
e = true
break
}

View File

@@ -10,7 +10,6 @@ go_library(
"//beacon-chain/db:go_default_library",
"//beacon-chain/db/filters:go_default_library",
"//consensus-types/primitives:go_default_library",
"//encoding/bytesutil:go_default_library",
"@com_github_emicklei_dot//:go_default_library",
],
)

View File

@@ -19,7 +19,6 @@ import (
"github.com/prysmaticlabs/prysm/v3/beacon-chain/db"
"github.com/prysmaticlabs/prysm/v3/beacon-chain/db/filters"
types "github.com/prysmaticlabs/prysm/v3/consensus-types/primitives"
"github.com/prysmaticlabs/prysm/v3/encoding/bytesutil"
)
var (
@@ -86,7 +85,7 @@ func main() {
dotN := graph.Node(rStr).Box().Attr("label", label)
n := &node{
parentRoot: bytesutil.ToBytes32(b.Block().ParentRoot()),
parentRoot: b.Block().ParentRoot(),
dothNode: &dotN,
}
m[r] = n

View File

@@ -169,12 +169,13 @@ func (v *validator) ProposeBlock(ctx context.Context, slot types.Slot, pubKey [f
}
blkRoot := fmt.Sprintf("%#x", bytesutil.Trunc(blkResp.BlockRoot))
graffiti := blk.Block().Body().Graffiti()
log.WithFields(logrus.Fields{
"slot": blk.Block().Slot(),
"blockRoot": blkRoot,
"numAttestations": len(blk.Block().Body().Attestations()),
"numDeposits": len(blk.Block().Body().Deposits()),
"graffiti": string(blk.Block().Body().Graffiti()),
"graffiti": string(graffiti[:]),
"fork": version.String(blk.Block().Version()),
}).Info("Submitted new block")

View File

@@ -606,7 +606,8 @@ func testProposeBlock(t *testing.T, graffiti []byte) {
})
validator.ProposeBlock(context.Background(), 1, pubKey)
assert.Equal(t, string(validator.graffiti), string(sentBlock.Block().Body().Graffiti()))
g := sentBlock.Block().Body().Graffiti()
assert.Equal(t, string(validator.graffiti), string(g[:]))
require.LogsContain(t, hook, "Submitted new block")
})
}