-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
147af2a
commit aa1b263
Showing
14 changed files
with
222 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package execution | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ethereum/go-ethereum/common" | ||
fieldparams "github.com/prysmaticlabs/prysm/v5/config/fieldparams" | ||
"github.com/prysmaticlabs/prysm/v5/encoding/bytesutil" | ||
pb "github.com/prysmaticlabs/prysm/v5/proto/engine/v1" | ||
) | ||
|
||
func (s *Service) ReconstructPayloadEnvelope(ctx context.Context, e *pb.SignedBlindPayloadEnvelope) (*pb.SignedExecutionPayloadEnvelope, error) { | ||
b, err := s.ExecutionBlockByHash(ctx, common.Hash(e.Message.BlockHash), true) | ||
if err != nil { | ||
return nil, err | ||
} | ||
txs := make([][]byte, len(b.Transactions)) | ||
for i, t := range b.Transactions { | ||
txs[i], err = t.MarshalBinary() | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
return &pb.SignedExecutionPayloadEnvelope{ | ||
Message: &pb.ExecutionPayloadEnvelope{ | ||
Payload: &pb.ExecutionPayloadDeneb{ | ||
ParentHash: b.ParentHash.Bytes(), | ||
FeeRecipient: b.Coinbase.Bytes(), | ||
StateRoot: b.Root.Bytes(), | ||
ReceiptsRoot: b.ReceiptHash.Bytes(), | ||
LogsBloom: b.Bloom.Bytes(), | ||
PrevRandao: b.MixDigest.Bytes(), | ||
BlockNumber: b.Number.Uint64(), | ||
GasLimit: b.GasLimit, | ||
GasUsed: b.GasUsed, | ||
Timestamp: b.Time, | ||
ExtraData: b.Extra, | ||
BaseFeePerGas: bytesutil.PadTo(bytesutil.ReverseByteOrder(b.BaseFee.Bytes()), fieldparams.RootLength), | ||
BlockHash: b.Hash.Bytes(), | ||
Transactions: txs, | ||
Withdrawals: b.Withdrawals, | ||
BlobGasUsed: *b.BlobGasUsed, | ||
ExcessBlobGas: *b.ExcessBlobGas, | ||
}, | ||
ExecutionRequests: e.Message.ExecutionRequests, | ||
BuilderIndex: e.Message.BuilderIndex, | ||
BeaconBlockRoot: e.Message.BeaconBlockRoot, | ||
Slot: e.Message.Slot, | ||
BlobKzgCommitments: e.Message.BlobKzgCommitments, | ||
StateRoot: e.Message.StateRoot, | ||
}, | ||
Signature: e.Signature, | ||
}, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package sync | ||
|
||
import ( | ||
"context" | ||
|
||
libp2pcore "github.com/libp2p/go-libp2p/core" | ||
"github.com/pkg/errors" | ||
"github.com/prysmaticlabs/prysm/v5/beacon-chain/blockchain" | ||
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/encoder" | ||
"github.com/prysmaticlabs/prysm/v5/beacon-chain/p2p/types" | ||
"github.com/prysmaticlabs/prysm/v5/network/forks" | ||
enginev1 "github.com/prysmaticlabs/prysm/v5/proto/engine/v1" | ||
"github.com/prysmaticlabs/prysm/v5/time/slots" | ||
) | ||
|
||
func (s *Service) executionPayloadByRootRPCHandler(ctx context.Context, msg interface{}, stream libp2pcore.Stream) error { | ||
SetRPCStreamDeadlines(stream) | ||
|
||
r, ok := msg.(*types.BeaconBlockByRootsReq) | ||
if !ok { | ||
return errors.New("message is not type BlobSidecarsByRootReq") | ||
} | ||
blockRoots := *r | ||
if err := s.rateLimiter.validateRequest(stream, uint64(len(blockRoots))); err != nil { | ||
return err | ||
} | ||
if len(blockRoots) == 0 { | ||
s.rateLimiter.add(stream, 1) | ||
s.writeErrorResponseToStream(responseCodeInvalidRequest, "no block roots provided in request", stream) | ||
return errors.New("no block roots provided") | ||
} | ||
for _, root := range blockRoots { | ||
blindPayload, err := s.cfg.beaconDB.SignedBlindPayloadEnvelope(ctx, root[:]) | ||
if err != nil { | ||
log.WithError(err).WithField("root", root).Error("Failed to get payload envelope") | ||
s.writeErrorResponseToStream(responseCodeServerError, types.ErrGeneric.Error(), stream) | ||
return err | ||
} | ||
if blindPayload == nil { | ||
s.writeErrorResponseToStream(responseCodeServerError, types.ErrGeneric.Error(), stream) | ||
return errors.New("payload is nil") | ||
} | ||
SetStreamWriteDeadline(stream, defaultWriteDuration) | ||
|
||
constructedPayload, err := s.cfg.executionReconstructor.ReconstructPayloadEnvelope(ctx, blindPayload) | ||
if err != nil { | ||
log.WithError(err).WithField("root", root).Error("Failed to reconstruct payload envelope") | ||
s.writeErrorResponseToStream(responseCodeServerError, types.ErrGeneric.Error(), stream) | ||
return err | ||
} | ||
|
||
if chunkErr := writePayloadChunk(stream, s.cfg.chain, s.cfg.p2p.Encoding(), constructedPayload); chunkErr != nil { | ||
log.WithError(chunkErr).Debug("Could not send a chunked response") | ||
s.writeErrorResponseToStream(responseCodeServerError, types.ErrGeneric.Error(), stream) | ||
return chunkErr | ||
} | ||
} | ||
closeStream(stream, log) | ||
return nil | ||
} | ||
|
||
func writePayloadChunk(stream libp2pcore.Stream, tor blockchain.TemporalOracle, encoding encoder.NetworkEncoding, payload *enginev1.SignedExecutionPayloadEnvelope) error { | ||
if _, err := stream.Write([]byte{responseCodeSuccess}); err != nil { | ||
return err | ||
} | ||
valRoot := tor.GenesisValidatorsRoot() | ||
ctxBytes, err := forks.ForkDigestFromEpoch(slots.ToEpoch(payload.Message.Slot), valRoot[:]) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if err := writeContextToStream(ctxBytes[:], stream); err != nil { | ||
return err | ||
} | ||
_, err = encoding.EncodeWithMaxLength(stream, payload) | ||
return err | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.