mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-31 08:08:18 -05:00
Compare commits
19 Commits
process-at
...
e2e-debugg
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35720e3f71 | ||
|
|
6effcf5d53 | ||
|
|
bd778dad3a | ||
|
|
ceadf6e5c9 | ||
|
|
22769ed486 | ||
|
|
b960e54e00 | ||
|
|
1c65c8866a | ||
|
|
14a4b97d57 | ||
|
|
0e537694c3 | ||
|
|
1b190e966e | ||
|
|
2cbb743606 | ||
|
|
ce9c968dcc | ||
|
|
60e5c29b92 | ||
|
|
e27445bae2 | ||
|
|
42e5417a7b | ||
|
|
c8012b41f9 | ||
|
|
f35074a78f | ||
|
|
520733ba55 | ||
|
|
bcf060619b |
@@ -503,3 +503,77 @@ func (s *SignedBlindedBeaconBlockFulu) MessageRawJson() ([]byte, error) {
|
|||||||
func (s *SignedBlindedBeaconBlockFulu) SigString() string {
|
func (s *SignedBlindedBeaconBlockFulu) SigString() string {
|
||||||
return s.Signature
|
return s.Signature
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// Gloas
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
type ExecutionPayloadBid struct {
|
||||||
|
ParentBlockHash string `json:"parent_block_hash"`
|
||||||
|
ParentBlockRoot string `json:"parent_block_root"`
|
||||||
|
BlockHash string `json:"block_hash"`
|
||||||
|
PrevRandao string `json:"prev_randao"`
|
||||||
|
FeeRecipient string `json:"fee_recipient"`
|
||||||
|
GasLimit string `json:"gas_limit"`
|
||||||
|
BuilderIndex string `json:"builder_index"`
|
||||||
|
Slot string `json:"slot"`
|
||||||
|
Value string `json:"value"`
|
||||||
|
ExecutionPayment string `json:"execution_payment"`
|
||||||
|
BlobKzgCommitmentsRoot string `json:"blob_kzg_commitments_root"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SignedExecutionPayloadBid struct {
|
||||||
|
Message *ExecutionPayloadBid `json:"message"`
|
||||||
|
Signature string `json:"signature"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PayloadAttestationData struct {
|
||||||
|
BeaconBlockRoot string `json:"beacon_block_root"`
|
||||||
|
Slot string `json:"slot"`
|
||||||
|
PayloadPresent bool `json:"payload_present"`
|
||||||
|
BlobDataAvailable bool `json:"blob_data_available"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PayloadAttestation struct {
|
||||||
|
AggregationBits string `json:"aggregation_bits"`
|
||||||
|
Data *PayloadAttestationData `json:"data"`
|
||||||
|
Signature string `json:"signature"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type BeaconBlockBodyGloas struct {
|
||||||
|
RandaoReveal string `json:"randao_reveal"`
|
||||||
|
Eth1Data *Eth1Data `json:"eth1_data"`
|
||||||
|
Graffiti string `json:"graffiti"`
|
||||||
|
ProposerSlashings []*ProposerSlashing `json:"proposer_slashings"`
|
||||||
|
AttesterSlashings []*AttesterSlashingElectra `json:"attester_slashings"`
|
||||||
|
Attestations []*AttestationElectra `json:"attestations"`
|
||||||
|
Deposits []*Deposit `json:"deposits"`
|
||||||
|
VoluntaryExits []*SignedVoluntaryExit `json:"voluntary_exits"`
|
||||||
|
SyncAggregate *SyncAggregate `json:"sync_aggregate"`
|
||||||
|
BLSToExecutionChanges []*SignedBLSToExecutionChange `json:"bls_to_execution_changes"`
|
||||||
|
SignedExecutionPayloadBid *SignedExecutionPayloadBid `json:"signed_execution_payload_bid"`
|
||||||
|
PayloadAttestations []*PayloadAttestation `json:"payload_attestations"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type BeaconBlockGloas struct {
|
||||||
|
Slot string `json:"slot"`
|
||||||
|
ProposerIndex string `json:"proposer_index"`
|
||||||
|
ParentRoot string `json:"parent_root"`
|
||||||
|
StateRoot string `json:"state_root"`
|
||||||
|
Body *BeaconBlockBodyGloas `json:"body"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type SignedBeaconBlockGloas struct {
|
||||||
|
Message *BeaconBlockGloas `json:"message"`
|
||||||
|
Signature string `json:"signature"`
|
||||||
|
}
|
||||||
|
|
||||||
|
var _ SignedMessageJsoner = &SignedBeaconBlockGloas{}
|
||||||
|
|
||||||
|
func (s *SignedBeaconBlockGloas) MessageRawJson() ([]byte, error) {
|
||||||
|
return json.Marshal(s.Message)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SignedBeaconBlockGloas) SigString() string {
|
||||||
|
return s.Signature
|
||||||
|
}
|
||||||
|
|||||||
@@ -268,6 +268,8 @@ func SignedBeaconBlockMessageJsoner(block interfaces.ReadOnlySignedBeaconBlock)
|
|||||||
return SignedBlindedBeaconBlockFuluFromConsensus(pbStruct)
|
return SignedBlindedBeaconBlockFuluFromConsensus(pbStruct)
|
||||||
case *eth.SignedBeaconBlockFulu:
|
case *eth.SignedBeaconBlockFulu:
|
||||||
return SignedBeaconBlockFuluFromConsensus(pbStruct)
|
return SignedBeaconBlockFuluFromConsensus(pbStruct)
|
||||||
|
case *eth.SignedBeaconBlockGloas:
|
||||||
|
return SignedBeaconBlockGloasFromConsensus(pbStruct)
|
||||||
default:
|
default:
|
||||||
return nil, ErrUnsupportedConversion
|
return nil, ErrUnsupportedConversion
|
||||||
}
|
}
|
||||||
@@ -2885,3 +2887,379 @@ func SignedBeaconBlockFuluFromConsensus(b *eth.SignedBeaconBlockFulu) (*SignedBe
|
|||||||
Signature: hexutil.Encode(b.Signature),
|
Signature: hexutil.Encode(b.Signature),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
// Gloas
|
||||||
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
func SignedBeaconBlockGloasFromConsensus(b *eth.SignedBeaconBlockGloas) (*SignedBeaconBlockGloas, error) {
|
||||||
|
block, err := BeaconBlockGloasFromConsensus(b.Block)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return &SignedBeaconBlockGloas{
|
||||||
|
Message: block,
|
||||||
|
Signature: hexutil.Encode(b.Signature),
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func BeaconBlockGloasFromConsensus(b *eth.BeaconBlockGloas) (*BeaconBlockGloas, error) {
|
||||||
|
payloadAttestations := make([]*PayloadAttestation, len(b.Body.PayloadAttestations))
|
||||||
|
for i, pa := range b.Body.PayloadAttestations {
|
||||||
|
payloadAttestations[i] = PayloadAttestationFromConsensus(pa)
|
||||||
|
}
|
||||||
|
|
||||||
|
return &BeaconBlockGloas{
|
||||||
|
Slot: fmt.Sprintf("%d", b.Slot),
|
||||||
|
ProposerIndex: fmt.Sprintf("%d", b.ProposerIndex),
|
||||||
|
ParentRoot: hexutil.Encode(b.ParentRoot),
|
||||||
|
StateRoot: hexutil.Encode(b.StateRoot),
|
||||||
|
Body: &BeaconBlockBodyGloas{
|
||||||
|
RandaoReveal: hexutil.Encode(b.Body.RandaoReveal),
|
||||||
|
Eth1Data: Eth1DataFromConsensus(b.Body.Eth1Data),
|
||||||
|
Graffiti: hexutil.Encode(b.Body.Graffiti),
|
||||||
|
ProposerSlashings: ProposerSlashingsFromConsensus(b.Body.ProposerSlashings),
|
||||||
|
AttesterSlashings: AttesterSlashingsElectraFromConsensus(b.Body.AttesterSlashings),
|
||||||
|
Attestations: AttsElectraFromConsensus(b.Body.Attestations),
|
||||||
|
Deposits: DepositsFromConsensus(b.Body.Deposits),
|
||||||
|
VoluntaryExits: SignedExitsFromConsensus(b.Body.VoluntaryExits),
|
||||||
|
SyncAggregate: SyncAggregateFromConsensus(b.Body.SyncAggregate),
|
||||||
|
BLSToExecutionChanges: SignedBLSChangesFromConsensus(b.Body.BlsToExecutionChanges),
|
||||||
|
SignedExecutionPayloadBid: SignedExecutionPayloadBidFromConsensus(b.Body.SignedExecutionPayloadBid),
|
||||||
|
PayloadAttestations: payloadAttestations,
|
||||||
|
},
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func SignedExecutionPayloadBidFromConsensus(b *eth.SignedExecutionPayloadBid) *SignedExecutionPayloadBid {
|
||||||
|
return &SignedExecutionPayloadBid{
|
||||||
|
Message: ExecutionPayloadBidFromConsensus(b.Message),
|
||||||
|
Signature: hexutil.Encode(b.Signature),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ExecutionPayloadBidFromConsensus(b *eth.ExecutionPayloadBid) *ExecutionPayloadBid {
|
||||||
|
return &ExecutionPayloadBid{
|
||||||
|
ParentBlockHash: hexutil.Encode(b.ParentBlockHash),
|
||||||
|
ParentBlockRoot: hexutil.Encode(b.ParentBlockRoot),
|
||||||
|
BlockHash: hexutil.Encode(b.BlockHash),
|
||||||
|
PrevRandao: hexutil.Encode(b.PrevRandao),
|
||||||
|
FeeRecipient: hexutil.Encode(b.FeeRecipient),
|
||||||
|
GasLimit: fmt.Sprintf("%d", b.GasLimit),
|
||||||
|
BuilderIndex: fmt.Sprintf("%d", b.BuilderIndex),
|
||||||
|
Slot: fmt.Sprintf("%d", b.Slot),
|
||||||
|
Value: fmt.Sprintf("%d", b.Value),
|
||||||
|
ExecutionPayment: fmt.Sprintf("%d", b.ExecutionPayment),
|
||||||
|
BlobKzgCommitmentsRoot: hexutil.Encode(b.BlobKzgCommitmentsRoot),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func PayloadAttestationFromConsensus(pa *eth.PayloadAttestation) *PayloadAttestation {
|
||||||
|
return &PayloadAttestation{
|
||||||
|
AggregationBits: hexutil.Encode(pa.AggregationBits),
|
||||||
|
Data: PayloadAttestationDataFromConsensus(pa.Data),
|
||||||
|
Signature: hexutil.Encode(pa.Signature),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func PayloadAttestationDataFromConsensus(d *eth.PayloadAttestationData) *PayloadAttestationData {
|
||||||
|
return &PayloadAttestationData{
|
||||||
|
BeaconBlockRoot: hexutil.Encode(d.BeaconBlockRoot),
|
||||||
|
Slot: fmt.Sprintf("%d", d.Slot),
|
||||||
|
PayloadPresent: d.PayloadPresent,
|
||||||
|
BlobDataAvailable: d.BlobDataAvailable,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *SignedBeaconBlockGloas) ToConsensus() (*eth.SignedBeaconBlockGloas, error) {
|
||||||
|
if b == nil {
|
||||||
|
return nil, errNilValue
|
||||||
|
}
|
||||||
|
|
||||||
|
sig, err := bytesutil.DecodeHexWithLength(b.Signature, fieldparams.BLSSignatureLength)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "Signature")
|
||||||
|
}
|
||||||
|
block, err := b.Message.ToConsensus()
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "Message")
|
||||||
|
}
|
||||||
|
return ð.SignedBeaconBlockGloas{
|
||||||
|
Block: block,
|
||||||
|
Signature: sig,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BeaconBlockGloas) ToConsensus() (*eth.BeaconBlockGloas, error) {
|
||||||
|
if b == nil {
|
||||||
|
return nil, errNilValue
|
||||||
|
}
|
||||||
|
if b.Body == nil {
|
||||||
|
return nil, server.NewDecodeError(errNilValue, "Body")
|
||||||
|
}
|
||||||
|
if b.Body.Eth1Data == nil {
|
||||||
|
return nil, server.NewDecodeError(errNilValue, "Body.Eth1Data")
|
||||||
|
}
|
||||||
|
if b.Body.SyncAggregate == nil {
|
||||||
|
return nil, server.NewDecodeError(errNilValue, "Body.SyncAggregate")
|
||||||
|
}
|
||||||
|
if b.Body.SignedExecutionPayloadBid == nil {
|
||||||
|
return nil, server.NewDecodeError(errNilValue, "Body.SignedExecutionPayloadBid")
|
||||||
|
}
|
||||||
|
|
||||||
|
slot, err := strconv.ParseUint(b.Slot, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "Slot")
|
||||||
|
}
|
||||||
|
proposerIndex, err := strconv.ParseUint(b.ProposerIndex, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "ProposerIndex")
|
||||||
|
}
|
||||||
|
parentRoot, err := bytesutil.DecodeHexWithLength(b.ParentRoot, fieldparams.RootLength)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "ParentRoot")
|
||||||
|
}
|
||||||
|
stateRoot, err := bytesutil.DecodeHexWithLength(b.StateRoot, fieldparams.RootLength)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "StateRoot")
|
||||||
|
}
|
||||||
|
body, err := b.Body.ToConsensus()
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "Body")
|
||||||
|
}
|
||||||
|
return ð.BeaconBlockGloas{
|
||||||
|
Slot: primitives.Slot(slot),
|
||||||
|
ProposerIndex: primitives.ValidatorIndex(proposerIndex),
|
||||||
|
ParentRoot: parentRoot,
|
||||||
|
StateRoot: stateRoot,
|
||||||
|
Body: body,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BeaconBlockBodyGloas) ToConsensus() (*eth.BeaconBlockBodyGloas, error) {
|
||||||
|
if b == nil {
|
||||||
|
return nil, errNilValue
|
||||||
|
}
|
||||||
|
|
||||||
|
randaoReveal, err := bytesutil.DecodeHexWithLength(b.RandaoReveal, fieldparams.BLSSignatureLength)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "RandaoReveal")
|
||||||
|
}
|
||||||
|
depositRoot, err := bytesutil.DecodeHexWithLength(b.Eth1Data.DepositRoot, fieldparams.RootLength)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "Eth1Data.DepositRoot")
|
||||||
|
}
|
||||||
|
depositCount, err := strconv.ParseUint(b.Eth1Data.DepositCount, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "Eth1Data.DepositCount")
|
||||||
|
}
|
||||||
|
blockHash, err := bytesutil.DecodeHexWithLength(b.Eth1Data.BlockHash, fieldparams.RootLength)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "Eth1Data.BlockHash")
|
||||||
|
}
|
||||||
|
graffiti, err := bytesutil.DecodeHexWithLength(b.Graffiti, fieldparams.RootLength)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "Graffiti")
|
||||||
|
}
|
||||||
|
proposerSlashings, err := ProposerSlashingsToConsensus(b.ProposerSlashings)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "ProposerSlashings")
|
||||||
|
}
|
||||||
|
attesterSlashings, err := AttesterSlashingsElectraToConsensus(b.AttesterSlashings)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "AttesterSlashings")
|
||||||
|
}
|
||||||
|
atts, err := AttsElectraToConsensus(b.Attestations)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "Attestations")
|
||||||
|
}
|
||||||
|
deposits, err := DepositsToConsensus(b.Deposits)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "Deposits")
|
||||||
|
}
|
||||||
|
exits, err := SignedExitsToConsensus(b.VoluntaryExits)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "VoluntaryExits")
|
||||||
|
}
|
||||||
|
syncCommitteeBits, err := bytesutil.DecodeHexWithLength(b.SyncAggregate.SyncCommitteeBits, fieldparams.SyncAggregateSyncCommitteeBytesLength)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "SyncAggregate.SyncCommitteeBits")
|
||||||
|
}
|
||||||
|
syncCommitteeSig, err := bytesutil.DecodeHexWithLength(b.SyncAggregate.SyncCommitteeSignature, fieldparams.BLSSignatureLength)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "SyncAggregate.SyncCommitteeSignature")
|
||||||
|
}
|
||||||
|
blsChanges, err := SignedBLSChangesToConsensus(b.BLSToExecutionChanges)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "BLSToExecutionChanges")
|
||||||
|
}
|
||||||
|
signedBid, err := b.SignedExecutionPayloadBid.ToConsensus()
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "SignedExecutionPayloadBid")
|
||||||
|
}
|
||||||
|
payloadAttestations, err := PayloadAttestationsToConsensus(b.PayloadAttestations)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "PayloadAttestations")
|
||||||
|
}
|
||||||
|
|
||||||
|
return ð.BeaconBlockBodyGloas{
|
||||||
|
RandaoReveal: randaoReveal,
|
||||||
|
Eth1Data: ð.Eth1Data{
|
||||||
|
DepositRoot: depositRoot,
|
||||||
|
DepositCount: depositCount,
|
||||||
|
BlockHash: blockHash,
|
||||||
|
},
|
||||||
|
Graffiti: graffiti,
|
||||||
|
ProposerSlashings: proposerSlashings,
|
||||||
|
AttesterSlashings: attesterSlashings,
|
||||||
|
Attestations: atts,
|
||||||
|
Deposits: deposits,
|
||||||
|
VoluntaryExits: exits,
|
||||||
|
SyncAggregate: ð.SyncAggregate{
|
||||||
|
SyncCommitteeBits: syncCommitteeBits,
|
||||||
|
SyncCommitteeSignature: syncCommitteeSig,
|
||||||
|
},
|
||||||
|
BlsToExecutionChanges: blsChanges,
|
||||||
|
SignedExecutionPayloadBid: signedBid,
|
||||||
|
PayloadAttestations: payloadAttestations,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *SignedExecutionPayloadBid) ToConsensus() (*eth.SignedExecutionPayloadBid, error) {
|
||||||
|
if b == nil {
|
||||||
|
return nil, errNilValue
|
||||||
|
}
|
||||||
|
sig, err := bytesutil.DecodeHexWithLength(b.Signature, fieldparams.BLSSignatureLength)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "Signature")
|
||||||
|
}
|
||||||
|
message, err := b.Message.ToConsensus()
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "Message")
|
||||||
|
}
|
||||||
|
return ð.SignedExecutionPayloadBid{
|
||||||
|
Message: message,
|
||||||
|
Signature: sig,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *ExecutionPayloadBid) ToConsensus() (*eth.ExecutionPayloadBid, error) {
|
||||||
|
if b == nil {
|
||||||
|
return nil, errNilValue
|
||||||
|
}
|
||||||
|
parentBlockHash, err := bytesutil.DecodeHexWithLength(b.ParentBlockHash, fieldparams.RootLength)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "ParentBlockHash")
|
||||||
|
}
|
||||||
|
parentBlockRoot, err := bytesutil.DecodeHexWithLength(b.ParentBlockRoot, fieldparams.RootLength)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "ParentBlockRoot")
|
||||||
|
}
|
||||||
|
blockHash, err := bytesutil.DecodeHexWithLength(b.BlockHash, fieldparams.RootLength)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "BlockHash")
|
||||||
|
}
|
||||||
|
prevRandao, err := bytesutil.DecodeHexWithLength(b.PrevRandao, fieldparams.RootLength)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "PrevRandao")
|
||||||
|
}
|
||||||
|
feeRecipient, err := bytesutil.DecodeHexWithLength(b.FeeRecipient, fieldparams.FeeRecipientLength)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "FeeRecipient")
|
||||||
|
}
|
||||||
|
gasLimit, err := strconv.ParseUint(b.GasLimit, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "GasLimit")
|
||||||
|
}
|
||||||
|
builderIndex, err := strconv.ParseUint(b.BuilderIndex, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "BuilderIndex")
|
||||||
|
}
|
||||||
|
slot, err := strconv.ParseUint(b.Slot, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "Slot")
|
||||||
|
}
|
||||||
|
value, err := strconv.ParseUint(b.Value, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "Value")
|
||||||
|
}
|
||||||
|
executionPayment, err := strconv.ParseUint(b.ExecutionPayment, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "ExecutionPayment")
|
||||||
|
}
|
||||||
|
blobKzgCommitmentsRoot, err := bytesutil.DecodeHexWithLength(b.BlobKzgCommitmentsRoot, fieldparams.RootLength)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "BlobKzgCommitmentsRoot")
|
||||||
|
}
|
||||||
|
return ð.ExecutionPayloadBid{
|
||||||
|
ParentBlockHash: parentBlockHash,
|
||||||
|
ParentBlockRoot: parentBlockRoot,
|
||||||
|
BlockHash: blockHash,
|
||||||
|
PrevRandao: prevRandao,
|
||||||
|
FeeRecipient: feeRecipient,
|
||||||
|
GasLimit: gasLimit,
|
||||||
|
BuilderIndex: primitives.BuilderIndex(builderIndex),
|
||||||
|
Slot: primitives.Slot(slot),
|
||||||
|
Value: primitives.Gwei(value),
|
||||||
|
ExecutionPayment: primitives.Gwei(executionPayment),
|
||||||
|
BlobKzgCommitmentsRoot: blobKzgCommitmentsRoot,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func PayloadAttestationsToConsensus(pa []*PayloadAttestation) ([]*eth.PayloadAttestation, error) {
|
||||||
|
if pa == nil {
|
||||||
|
return nil, errNilValue
|
||||||
|
}
|
||||||
|
result := make([]*eth.PayloadAttestation, len(pa))
|
||||||
|
for i, p := range pa {
|
||||||
|
converted, err := p.ToConsensus()
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, fmt.Sprintf("[%d]", i))
|
||||||
|
}
|
||||||
|
result[i] = converted
|
||||||
|
}
|
||||||
|
return result, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *PayloadAttestation) ToConsensus() (*eth.PayloadAttestation, error) {
|
||||||
|
if p == nil {
|
||||||
|
return nil, errNilValue
|
||||||
|
}
|
||||||
|
aggregationBits, err := hexutil.Decode(p.AggregationBits)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "AggregationBits")
|
||||||
|
}
|
||||||
|
data, err := p.Data.ToConsensus()
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "Data")
|
||||||
|
}
|
||||||
|
sig, err := bytesutil.DecodeHexWithLength(p.Signature, fieldparams.BLSSignatureLength)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "Signature")
|
||||||
|
}
|
||||||
|
return ð.PayloadAttestation{
|
||||||
|
AggregationBits: aggregationBits,
|
||||||
|
Data: data,
|
||||||
|
Signature: sig,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (d *PayloadAttestationData) ToConsensus() (*eth.PayloadAttestationData, error) {
|
||||||
|
if d == nil {
|
||||||
|
return nil, errNilValue
|
||||||
|
}
|
||||||
|
beaconBlockRoot, err := bytesutil.DecodeHexWithLength(d.BeaconBlockRoot, fieldparams.RootLength)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "BeaconBlockRoot")
|
||||||
|
}
|
||||||
|
slot, err := strconv.ParseUint(d.Slot, 10, 64)
|
||||||
|
if err != nil {
|
||||||
|
return nil, server.NewDecodeError(err, "Slot")
|
||||||
|
}
|
||||||
|
return ð.PayloadAttestationData{
|
||||||
|
BeaconBlockRoot: beaconBlockRoot,
|
||||||
|
Slot: primitives.Slot(slot),
|
||||||
|
PayloadPresent: d.PayloadPresent,
|
||||||
|
BlobDataAvailable: d.BlobDataAvailable,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ go_library(
|
|||||||
"//beacon-chain/core/blocks:go_default_library",
|
"//beacon-chain/core/blocks:go_default_library",
|
||||||
"//beacon-chain/core/epoch:go_default_library",
|
"//beacon-chain/core/epoch:go_default_library",
|
||||||
"//beacon-chain/core/epoch/precompute:go_default_library",
|
"//beacon-chain/core/epoch/precompute:go_default_library",
|
||||||
"//beacon-chain/core/gloas:go_default_library",
|
|
||||||
"//beacon-chain/core/helpers:go_default_library",
|
"//beacon-chain/core/helpers:go_default_library",
|
||||||
"//beacon-chain/core/signing:go_default_library",
|
"//beacon-chain/core/signing:go_default_library",
|
||||||
"//beacon-chain/core/time:go_default_library",
|
"//beacon-chain/core/time:go_default_library",
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/blocks"
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/blocks"
|
||||||
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/gloas"
|
|
||||||
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/helpers"
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/helpers"
|
||||||
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/time"
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/time"
|
||||||
"github.com/OffchainLabs/prysm/v7/beacon-chain/state"
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/state"
|
||||||
@@ -76,11 +75,7 @@ func ProcessAttestationNoVerifySignature(
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := beaconState.UpdatePendingPaymentWeight(att, indices, participatedFlags); err != nil {
|
return SetParticipationAndRewardProposer(ctx, beaconState, att.GetData().Target.Epoch, indices, participatedFlags, totalBalance)
|
||||||
return nil, errors.Wrap(err, "failed to update pending payment weight")
|
|
||||||
}
|
|
||||||
|
|
||||||
return SetParticipationAndRewardProposer(ctx, beaconState, att.GetData().Target.Epoch, indices, participatedFlags, totalBalance, att)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetParticipationAndRewardProposer retrieves and sets the epoch participation bits in state. Based on the epoch participation, it rewards
|
// SetParticipationAndRewardProposer retrieves and sets the epoch participation bits in state. Based on the epoch participation, it rewards
|
||||||
@@ -110,9 +105,7 @@ func SetParticipationAndRewardProposer(
|
|||||||
beaconState state.BeaconState,
|
beaconState state.BeaconState,
|
||||||
targetEpoch primitives.Epoch,
|
targetEpoch primitives.Epoch,
|
||||||
indices []uint64,
|
indices []uint64,
|
||||||
participatedFlags map[uint8]bool,
|
participatedFlags map[uint8]bool, totalBalance uint64) (state.BeaconState, error) {
|
||||||
totalBalance uint64,
|
|
||||||
att ethpb.Att) (state.BeaconState, error) {
|
|
||||||
var proposerRewardNumerator uint64
|
var proposerRewardNumerator uint64
|
||||||
currentEpoch := time.CurrentEpoch(beaconState)
|
currentEpoch := time.CurrentEpoch(beaconState)
|
||||||
var stateErr error
|
var stateErr error
|
||||||
@@ -306,19 +299,6 @@ func AttestationParticipationFlagIndices(beaconState state.ReadOnlyBeaconState,
|
|||||||
participatedFlags[targetFlagIndex] = true
|
participatedFlags[targetFlagIndex] = true
|
||||||
}
|
}
|
||||||
matchedSrcTgtHead := matchedHead && matchedSrcTgt
|
matchedSrcTgtHead := matchedHead && matchedSrcTgt
|
||||||
|
|
||||||
var beaconBlockRoot [32]byte
|
|
||||||
copy(beaconBlockRoot[:], data.BeaconBlockRoot)
|
|
||||||
matchingPayload, err := gloas.MatchingPayload(
|
|
||||||
beaconState,
|
|
||||||
beaconBlockRoot,
|
|
||||||
data.Slot,
|
|
||||||
uint64(data.CommitteeIndex),
|
|
||||||
)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
matchedSrcTgtHead = matchedSrcTgtHead && matchingPayload
|
|
||||||
if matchedSrcTgtHead && delay == cfg.MinAttestationInclusionDelay {
|
if matchedSrcTgtHead && delay == cfg.MinAttestationInclusionDelay {
|
||||||
participatedFlags[headFlagIndex] = true
|
participatedFlags[headFlagIndex] = true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package altair_test
|
package altair_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/OffchainLabs/go-bitfield"
|
"github.com/OffchainLabs/go-bitfield"
|
||||||
@@ -558,7 +556,7 @@ func TestSetParticipationAndRewardProposer(t *testing.T) {
|
|||||||
|
|
||||||
b, err := helpers.TotalActiveBalance(beaconState)
|
b, err := helpers.TotalActiveBalance(beaconState)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
st, err := altair.SetParticipationAndRewardProposer(t.Context(), beaconState, test.epoch, test.indices, test.participatedFlags, b, ðpb.Attestation{})
|
st, err := altair.SetParticipationAndRewardProposer(t.Context(), beaconState, test.epoch, test.indices, test.participatedFlags, b)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|
||||||
i, err := helpers.BeaconProposerIndex(t.Context(), st)
|
i, err := helpers.BeaconProposerIndex(t.Context(), st)
|
||||||
@@ -777,67 +775,11 @@ func TestAttestationParticipationFlagIndices(t *testing.T) {
|
|||||||
headFlagIndex: true,
|
headFlagIndex: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
name: "gloas same-slot committee index non-zero errors",
|
|
||||||
inputState: func() state.BeaconState {
|
|
||||||
stateSlot := primitives.Slot(5)
|
|
||||||
slot := primitives.Slot(3)
|
|
||||||
targetRoot := bytes.Repeat([]byte{0xAA}, 32)
|
|
||||||
headRoot := bytes.Repeat([]byte{0xBB}, 32)
|
|
||||||
prevRoot := bytes.Repeat([]byte{0xCC}, 32)
|
|
||||||
return buildGloasStateForFlags(t, stateSlot, slot, targetRoot, headRoot, prevRoot, 0, 0)
|
|
||||||
}(),
|
|
||||||
inputData: ðpb.AttestationData{
|
|
||||||
Slot: 3,
|
|
||||||
CommitteeIndex: 1, // invalid for same-slot
|
|
||||||
BeaconBlockRoot: bytes.Repeat([]byte{0xBB}, 32),
|
|
||||||
Source: ðpb.Checkpoint{Root: bytes.Repeat([]byte{0xDD}, 32)},
|
|
||||||
Target: ðpb.Checkpoint{
|
|
||||||
Epoch: 0,
|
|
||||||
Root: bytes.Repeat([]byte{0xAA}, 32),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
inputDelay: 1,
|
|
||||||
participationIndices: nil,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "gloas payload availability matches committee index",
|
|
||||||
inputState: func() state.BeaconState {
|
|
||||||
stateSlot := primitives.Slot(5)
|
|
||||||
slot := primitives.Slot(3)
|
|
||||||
targetRoot := bytes.Repeat([]byte{0xAA}, 32)
|
|
||||||
headRoot := bytes.Repeat([]byte{0xBB}, 32)
|
|
||||||
// Same prev root to make SameSlotAttestation false and use payload availability.
|
|
||||||
return buildGloasStateForFlags(t, stateSlot, slot, targetRoot, headRoot, headRoot, 1, slot)
|
|
||||||
}(),
|
|
||||||
inputData: ðpb.AttestationData{
|
|
||||||
Slot: 3,
|
|
||||||
CommitteeIndex: 1,
|
|
||||||
BeaconBlockRoot: bytes.Repeat([]byte{0xBB}, 32),
|
|
||||||
Source: ðpb.Checkpoint{Root: bytes.Repeat([]byte{0xDD}, 32)},
|
|
||||||
Target: ðpb.Checkpoint{
|
|
||||||
Epoch: 0,
|
|
||||||
Root: bytes.Repeat([]byte{0xAA}, 32),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
inputDelay: 1,
|
|
||||||
participationIndices: map[uint8]bool{
|
|
||||||
sourceFlagIndex: true,
|
|
||||||
targetFlagIndex: true,
|
|
||||||
headFlagIndex: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
for _, test := range tests {
|
for _, test := range tests {
|
||||||
flagIndices, err := altair.AttestationParticipationFlagIndices(test.inputState, test.inputData, test.inputDelay)
|
flagIndices, err := altair.AttestationParticipationFlagIndices(test.inputState, test.inputData, test.inputDelay)
|
||||||
if test.participationIndices == nil {
|
|
||||||
require.ErrorContains(t, "committee index", err)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
if !reflect.DeepEqual(test.participationIndices, flagIndices) {
|
require.DeepEqual(t, test.participationIndices, flagIndices)
|
||||||
t.Fatalf("unexpected participation indices: got %v want %v", flagIndices, test.participationIndices)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -916,61 +858,3 @@ func TestMatchingStatus(t *testing.T) {
|
|||||||
require.Equal(t, test.matchedHead, head)
|
require.Equal(t, test.matchedHead, head)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildGloasStateForFlags(t *testing.T, stateSlot, slot primitives.Slot, targetRoot, headRoot, prevRoot []byte, availabilityBit uint8, availabilitySlot primitives.Slot) state.BeaconState {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
cfg := params.BeaconConfig()
|
|
||||||
blockRoots := make([][]byte, cfg.SlotsPerHistoricalRoot)
|
|
||||||
blockRoots[0] = targetRoot
|
|
||||||
blockRoots[slot%cfg.SlotsPerHistoricalRoot] = headRoot
|
|
||||||
blockRoots[(slot-1)%cfg.SlotsPerHistoricalRoot] = prevRoot
|
|
||||||
|
|
||||||
stateRoots := make([][]byte, cfg.SlotsPerHistoricalRoot)
|
|
||||||
for i := range stateRoots {
|
|
||||||
stateRoots[i] = make([]byte, fieldparams.RootLength)
|
|
||||||
}
|
|
||||||
randaoMixes := make([][]byte, cfg.EpochsPerHistoricalVector)
|
|
||||||
for i := range randaoMixes {
|
|
||||||
randaoMixes[i] = make([]byte, fieldparams.RootLength)
|
|
||||||
}
|
|
||||||
|
|
||||||
execPayloadAvailability := make([]byte, cfg.SlotsPerHistoricalRoot/8)
|
|
||||||
idx := availabilitySlot % cfg.SlotsPerHistoricalRoot
|
|
||||||
byteIndex := idx / 8
|
|
||||||
bitIndex := idx % 8
|
|
||||||
if availabilityBit == 1 {
|
|
||||||
execPayloadAvailability[byteIndex] |= 1 << bitIndex
|
|
||||||
}
|
|
||||||
|
|
||||||
checkpointRoot := bytes.Repeat([]byte{0xDD}, fieldparams.RootLength)
|
|
||||||
justified := ðpb.Checkpoint{Root: checkpointRoot}
|
|
||||||
|
|
||||||
stProto := ðpb.BeaconStateGloas{
|
|
||||||
Slot: stateSlot,
|
|
||||||
GenesisValidatorsRoot: bytes.Repeat([]byte{0x11}, fieldparams.RootLength),
|
|
||||||
BlockRoots: blockRoots,
|
|
||||||
StateRoots: stateRoots,
|
|
||||||
RandaoMixes: randaoMixes,
|
|
||||||
ExecutionPayloadAvailability: execPayloadAvailability,
|
|
||||||
CurrentJustifiedCheckpoint: justified,
|
|
||||||
PreviousJustifiedCheckpoint: justified,
|
|
||||||
Validators: []*ethpb.Validator{
|
|
||||||
{
|
|
||||||
EffectiveBalance: cfg.MinActivationBalance,
|
|
||||||
WithdrawalCredentials: append([]byte{cfg.ETH1AddressWithdrawalPrefixByte}, bytes.Repeat([]byte{0x01}, 31)...),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Balances: []uint64{cfg.MinActivationBalance},
|
|
||||||
BuilderPendingPayments: make([]*ethpb.BuilderPendingPayment, cfg.SlotsPerEpoch*2),
|
|
||||||
Fork: ðpb.Fork{
|
|
||||||
CurrentVersion: bytes.Repeat([]byte{0x01}, 4),
|
|
||||||
PreviousVersion: bytes.Repeat([]byte{0x01}, 4),
|
|
||||||
Epoch: 0,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
beaconState, err := state_native.InitializeFromProtoGloas(stProto)
|
|
||||||
require.NoError(t, err)
|
|
||||||
return beaconState
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -111,21 +111,10 @@ func VerifyAttestationNoVerifySignature(
|
|||||||
var indexedAtt ethpb.IndexedAtt
|
var indexedAtt ethpb.IndexedAtt
|
||||||
|
|
||||||
if att.Version() >= version.Electra {
|
if att.Version() >= version.Electra {
|
||||||
ci := att.GetData().CommitteeIndex
|
if att.GetData().CommitteeIndex != 0 {
|
||||||
// Spec v1.7.0-alpha pseudocode:
|
return errors.New("committee index must be 0 post-Electra")
|
||||||
//
|
|
||||||
// # [Modified in Gloas:EIP7732]
|
|
||||||
// assert data.index < 2
|
|
||||||
//
|
|
||||||
if beaconState.Version() >= version.Gloas {
|
|
||||||
if ci >= 2 {
|
|
||||||
return fmt.Errorf("incorrect committee index %d", ci)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if ci != 0 {
|
|
||||||
return errors.New("committee index must be 0 between Electra and Gloas forks")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
aggBits := att.GetAggregationBits()
|
aggBits := att.GetAggregationBits()
|
||||||
committeeIndices := att.CommitteeBitsVal().BitIndices()
|
committeeIndices := att.CommitteeBitsVal().BitIndices()
|
||||||
committees := make([][]primitives.ValidatorIndex, len(committeeIndices))
|
committees := make([][]primitives.ValidatorIndex, len(committeeIndices))
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package blocks_test
|
package blocks_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"context"
|
"context"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@@ -263,7 +262,7 @@ func TestVerifyAttestationNoVerifySignature_Electra(t *testing.T) {
|
|||||||
CommitteeBits: bitfield.NewBitvector64(),
|
CommitteeBits: bitfield.NewBitvector64(),
|
||||||
}
|
}
|
||||||
err = blocks.VerifyAttestationNoVerifySignature(context.TODO(), beaconState, att)
|
err = blocks.VerifyAttestationNoVerifySignature(context.TODO(), beaconState, att)
|
||||||
assert.ErrorContains(t, "committee index must be 0", err)
|
assert.ErrorContains(t, "committee index must be 0 post-Electra", err)
|
||||||
})
|
})
|
||||||
t.Run("index of committee too big", func(t *testing.T) {
|
t.Run("index of committee too big", func(t *testing.T) {
|
||||||
aggBits := bitfield.NewBitlist(3)
|
aggBits := bitfield.NewBitlist(3)
|
||||||
@@ -315,75 +314,6 @@ func TestVerifyAttestationNoVerifySignature_Electra(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestVerifyAttestationNoVerifySignature_GloasCommitteeIndexLimit(t *testing.T) {
|
|
||||||
cfg := params.BeaconConfig()
|
|
||||||
stateSlot := cfg.MinAttestationInclusionDelay + 1
|
|
||||||
|
|
||||||
blockRoots := make([][]byte, cfg.SlotsPerHistoricalRoot)
|
|
||||||
for i := range blockRoots {
|
|
||||||
blockRoots[i] = make([]byte, fieldparams.RootLength)
|
|
||||||
}
|
|
||||||
stateRoots := make([][]byte, cfg.SlotsPerHistoricalRoot)
|
|
||||||
for i := range stateRoots {
|
|
||||||
stateRoots[i] = make([]byte, fieldparams.RootLength)
|
|
||||||
}
|
|
||||||
randaoMixes := make([][]byte, cfg.EpochsPerHistoricalVector)
|
|
||||||
for i := range randaoMixes {
|
|
||||||
randaoMixes[i] = make([]byte, fieldparams.RootLength)
|
|
||||||
}
|
|
||||||
|
|
||||||
checkpointRoot := bytes.Repeat([]byte{0xAA}, fieldparams.RootLength)
|
|
||||||
justified := ðpb.Checkpoint{Epoch: 0, Root: checkpointRoot}
|
|
||||||
|
|
||||||
gloasStateProto := ðpb.BeaconStateGloas{
|
|
||||||
Slot: stateSlot,
|
|
||||||
GenesisValidatorsRoot: bytes.Repeat([]byte{0x11}, fieldparams.RootLength),
|
|
||||||
BlockRoots: blockRoots,
|
|
||||||
StateRoots: stateRoots,
|
|
||||||
RandaoMixes: randaoMixes,
|
|
||||||
ExecutionPayloadAvailability: make([]byte, cfg.SlotsPerHistoricalRoot/8),
|
|
||||||
CurrentJustifiedCheckpoint: justified,
|
|
||||||
PreviousJustifiedCheckpoint: justified,
|
|
||||||
Validators: []*ethpb.Validator{
|
|
||||||
{
|
|
||||||
EffectiveBalance: cfg.MinActivationBalance,
|
|
||||||
WithdrawalCredentials: append([]byte{cfg.ETH1AddressWithdrawalPrefixByte}, bytes.Repeat([]byte{0x01}, 31)...),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
Balances: []uint64{cfg.MinActivationBalance},
|
|
||||||
BuilderPendingPayments: make([]*ethpb.BuilderPendingPayment, cfg.SlotsPerEpoch*2),
|
|
||||||
Fork: ðpb.Fork{
|
|
||||||
CurrentVersion: bytes.Repeat([]byte{0x01}, 4),
|
|
||||||
PreviousVersion: bytes.Repeat([]byte{0x01}, 4),
|
|
||||||
Epoch: 0,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
beaconState, err := state_native.InitializeFromProtoGloas(gloasStateProto)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
committeeBits := bitfield.NewBitvector64()
|
|
||||||
committeeBits.SetBitAt(0, true)
|
|
||||||
aggBits := bitfield.NewBitlist(1)
|
|
||||||
aggBits.SetBitAt(0, true)
|
|
||||||
|
|
||||||
att := ðpb.AttestationElectra{
|
|
||||||
Data: ðpb.AttestationData{
|
|
||||||
Slot: 0,
|
|
||||||
CommitteeIndex: 2, // invalid for Gloas (must be <2)
|
|
||||||
BeaconBlockRoot: blockRoots[0],
|
|
||||||
Source: justified,
|
|
||||||
Target: justified,
|
|
||||||
},
|
|
||||||
AggregationBits: aggBits,
|
|
||||||
CommitteeBits: committeeBits,
|
|
||||||
Signature: bytes.Repeat([]byte{0x00}, fieldparams.BLSSignatureLength),
|
|
||||||
}
|
|
||||||
|
|
||||||
err = blocks.VerifyAttestationNoVerifySignature(context.TODO(), beaconState, att)
|
|
||||||
assert.ErrorContains(t, "incorrect committee index 2", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestConvertToIndexed_OK(t *testing.T) {
|
func TestConvertToIndexed_OK(t *testing.T) {
|
||||||
helpers.ClearCache()
|
helpers.ClearCache()
|
||||||
validators := make([]*ethpb.Validator, 2*params.BeaconConfig().SlotsPerEpoch)
|
validators := make([]*ethpb.Validator, 2*params.BeaconConfig().SlotsPerEpoch)
|
||||||
@@ -653,7 +583,6 @@ func TestVerifyAttestations_HandlesPlannedFork(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestRetrieveAttestationSignatureSet_VerifiesMultipleAttestations(t *testing.T) {
|
func TestRetrieveAttestationSignatureSet_VerifiesMultipleAttestations(t *testing.T) {
|
||||||
helpers.ClearCache()
|
|
||||||
ctx := t.Context()
|
ctx := t.Context()
|
||||||
numOfValidators := uint64(params.BeaconConfig().SlotsPerEpoch.Mul(4))
|
numOfValidators := uint64(params.BeaconConfig().SlotsPerEpoch.Mul(4))
|
||||||
validators := make([]*ethpb.Validator, numOfValidators)
|
validators := make([]*ethpb.Validator, numOfValidators)
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ go_library(
|
|||||||
"transition.go",
|
"transition.go",
|
||||||
"upgrade.go",
|
"upgrade.go",
|
||||||
"validator.go",
|
"validator.go",
|
||||||
"withdrawals.go",
|
|
||||||
],
|
],
|
||||||
importpath = "github.com/OffchainLabs/prysm/v7/beacon-chain/core/electra",
|
importpath = "github.com/OffchainLabs/prysm/v7/beacon-chain/core/electra",
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
@@ -42,8 +41,6 @@ go_library(
|
|||||||
"//proto/prysm/v1alpha1/attestation:go_default_library",
|
"//proto/prysm/v1alpha1/attestation:go_default_library",
|
||||||
"//runtime/version:go_default_library",
|
"//runtime/version:go_default_library",
|
||||||
"//time/slots:go_default_library",
|
"//time/slots:go_default_library",
|
||||||
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
|
|
||||||
"@com_github_ethereum_go_ethereum//common/math:go_default_library",
|
|
||||||
"@com_github_pkg_errors//:go_default_library",
|
"@com_github_pkg_errors//:go_default_library",
|
||||||
"@com_github_sirupsen_logrus//:go_default_library",
|
"@com_github_sirupsen_logrus//:go_default_library",
|
||||||
],
|
],
|
||||||
@@ -63,13 +60,11 @@ go_test(
|
|||||||
"transition_test.go",
|
"transition_test.go",
|
||||||
"upgrade_test.go",
|
"upgrade_test.go",
|
||||||
"validator_test.go",
|
"validator_test.go",
|
||||||
"withdrawals_test.go",
|
|
||||||
],
|
],
|
||||||
data = glob(["testdata/**"]),
|
data = glob(["testdata/**"]),
|
||||||
embed = [":go_default_library"],
|
embed = [":go_default_library"],
|
||||||
deps = [
|
deps = [
|
||||||
"//beacon-chain/core/helpers:go_default_library",
|
"//beacon-chain/core/helpers:go_default_library",
|
||||||
"//beacon-chain/core/signing:go_default_library",
|
|
||||||
"//beacon-chain/core/time:go_default_library",
|
"//beacon-chain/core/time:go_default_library",
|
||||||
"//beacon-chain/state:go_default_library",
|
"//beacon-chain/state:go_default_library",
|
||||||
"//beacon-chain/state/state-native:go_default_library",
|
"//beacon-chain/state/state-native:go_default_library",
|
||||||
@@ -82,16 +77,12 @@ go_test(
|
|||||||
"//encoding/bytesutil:go_default_library",
|
"//encoding/bytesutil:go_default_library",
|
||||||
"//proto/engine/v1:go_default_library",
|
"//proto/engine/v1:go_default_library",
|
||||||
"//proto/prysm/v1alpha1:go_default_library",
|
"//proto/prysm/v1alpha1:go_default_library",
|
||||||
"//testing/assert:go_default_library",
|
|
||||||
"//testing/fuzz:go_default_library",
|
"//testing/fuzz:go_default_library",
|
||||||
"//testing/require:go_default_library",
|
"//testing/require:go_default_library",
|
||||||
"//testing/util:go_default_library",
|
"//testing/util:go_default_library",
|
||||||
"//time/slots:go_default_library",
|
"//time/slots:go_default_library",
|
||||||
"@com_github_ethereum_go_ethereum//common:go_default_library",
|
"@com_github_ethereum_go_ethereum//common:go_default_library",
|
||||||
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
|
|
||||||
"@com_github_google_gofuzz//:go_default_library",
|
"@com_github_google_gofuzz//:go_default_library",
|
||||||
"@com_github_pkg_errors//:go_default_library",
|
"@com_github_pkg_errors//:go_default_library",
|
||||||
"@com_github_sirupsen_logrus//:go_default_library",
|
|
||||||
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
|
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,19 +3,14 @@ package electra
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/helpers"
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/helpers"
|
||||||
"github.com/OffchainLabs/prysm/v7/beacon-chain/state"
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/state"
|
||||||
state_native "github.com/OffchainLabs/prysm/v7/beacon-chain/state/state-native"
|
|
||||||
"github.com/OffchainLabs/prysm/v7/config/params"
|
"github.com/OffchainLabs/prysm/v7/config/params"
|
||||||
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
|
||||||
"github.com/OffchainLabs/prysm/v7/encoding/bytesutil"
|
"github.com/OffchainLabs/prysm/v7/encoding/bytesutil"
|
||||||
"github.com/OffchainLabs/prysm/v7/monitoring/tracing/trace"
|
"github.com/OffchainLabs/prysm/v7/monitoring/tracing/trace"
|
||||||
enginev1 "github.com/OffchainLabs/prysm/v7/proto/engine/v1"
|
enginev1 "github.com/OffchainLabs/prysm/v7/proto/engine/v1"
|
||||||
eth "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
|
||||||
"github.com/OffchainLabs/prysm/v7/time/slots"
|
"github.com/OffchainLabs/prysm/v7/time/slots"
|
||||||
"github.com/ethereum/go-ethereum/common/math"
|
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -95,217 +90,6 @@ func ProcessPendingConsolidations(ctx context.Context, st state.BeaconState) err
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProcessConsolidationRequests implements the spec definition below. This method makes mutating
|
|
||||||
// calls to the beacon state.
|
|
||||||
//
|
|
||||||
// def process_consolidation_request(
|
|
||||||
// state: BeaconState,
|
|
||||||
// consolidation_request: ConsolidationRequest
|
|
||||||
// ) -> None:
|
|
||||||
// if is_valid_switch_to_compounding_request(state, consolidation_request):
|
|
||||||
// validator_pubkeys = [v.pubkey for v in state.validators]
|
|
||||||
// request_source_pubkey = consolidation_request.source_pubkey
|
|
||||||
// source_index = ValidatorIndex(validator_pubkeys.index(request_source_pubkey))
|
|
||||||
// switch_to_compounding_validator(state, source_index)
|
|
||||||
// return
|
|
||||||
//
|
|
||||||
// # Verify that source != target, so a consolidation cannot be used as an exit.
|
|
||||||
// if consolidation_request.source_pubkey == consolidation_request.target_pubkey:
|
|
||||||
// return
|
|
||||||
// # If the pending consolidations queue is full, consolidation requests are ignored
|
|
||||||
// if len(state.pending_consolidations) == PENDING_CONSOLIDATIONS_LIMIT:
|
|
||||||
// return
|
|
||||||
// # If there is too little available consolidation churn limit, consolidation requests are ignored
|
|
||||||
// if get_consolidation_churn_limit(state) <= MIN_ACTIVATION_BALANCE:
|
|
||||||
// return
|
|
||||||
//
|
|
||||||
// validator_pubkeys = [v.pubkey for v in state.validators]
|
|
||||||
// # Verify pubkeys exists
|
|
||||||
// request_source_pubkey = consolidation_request.source_pubkey
|
|
||||||
// request_target_pubkey = consolidation_request.target_pubkey
|
|
||||||
// if request_source_pubkey not in validator_pubkeys:
|
|
||||||
// return
|
|
||||||
// if request_target_pubkey not in validator_pubkeys:
|
|
||||||
// return
|
|
||||||
// source_index = ValidatorIndex(validator_pubkeys.index(request_source_pubkey))
|
|
||||||
// target_index = ValidatorIndex(validator_pubkeys.index(request_target_pubkey))
|
|
||||||
// source_validator = state.validators[source_index]
|
|
||||||
// target_validator = state.validators[target_index]
|
|
||||||
//
|
|
||||||
// # Verify source withdrawal credentials
|
|
||||||
// has_correct_credential = has_execution_withdrawal_credential(source_validator)
|
|
||||||
// is_correct_source_address = (
|
|
||||||
// source_validator.withdrawal_credentials[12:] == consolidation_request.source_address
|
|
||||||
// )
|
|
||||||
// if not (has_correct_credential and is_correct_source_address):
|
|
||||||
// return
|
|
||||||
//
|
|
||||||
// # Verify that target has compounding withdrawal credentials
|
|
||||||
// if not has_compounding_withdrawal_credential(target_validator):
|
|
||||||
// return
|
|
||||||
//
|
|
||||||
// # Verify the source and the target are active
|
|
||||||
// current_epoch = get_current_epoch(state)
|
|
||||||
// if not is_active_validator(source_validator, current_epoch):
|
|
||||||
// return
|
|
||||||
// if not is_active_validator(target_validator, current_epoch):
|
|
||||||
// return
|
|
||||||
// # Verify exits for source and target have not been initiated
|
|
||||||
// if source_validator.exit_epoch != FAR_FUTURE_EPOCH:
|
|
||||||
// return
|
|
||||||
// if target_validator.exit_epoch != FAR_FUTURE_EPOCH:
|
|
||||||
// return
|
|
||||||
//
|
|
||||||
// # Verify the source has been active long enough
|
|
||||||
// if current_epoch < source_validator.activation_epoch + SHARD_COMMITTEE_PERIOD:
|
|
||||||
// return
|
|
||||||
//
|
|
||||||
// # Verify the source has no pending withdrawals in the queue
|
|
||||||
// if get_pending_balance_to_withdraw(state, source_index) > 0:
|
|
||||||
// return
|
|
||||||
// # Initiate source validator exit and append pending consolidation
|
|
||||||
// source_validator.exit_epoch = compute_consolidation_epoch_and_update_churn(
|
|
||||||
// state, source_validator.effective_balance
|
|
||||||
// )
|
|
||||||
// source_validator.withdrawable_epoch = Epoch(
|
|
||||||
// source_validator.exit_epoch + MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
|
||||||
// )
|
|
||||||
// state.pending_consolidations.append(PendingConsolidation(
|
|
||||||
// source_index=source_index,
|
|
||||||
// target_index=target_index
|
|
||||||
// ))
|
|
||||||
func ProcessConsolidationRequests(ctx context.Context, st state.BeaconState, reqs []*enginev1.ConsolidationRequest) error {
|
|
||||||
if len(reqs) == 0 || st == nil {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
curEpoch := slots.ToEpoch(st.Slot())
|
|
||||||
ffe := params.BeaconConfig().FarFutureEpoch
|
|
||||||
minValWithdrawDelay := params.BeaconConfig().MinValidatorWithdrawabilityDelay
|
|
||||||
pcLimit := params.BeaconConfig().PendingConsolidationsLimit
|
|
||||||
|
|
||||||
for _, cr := range reqs {
|
|
||||||
if cr == nil {
|
|
||||||
return errors.New("nil consolidation request")
|
|
||||||
}
|
|
||||||
if ctx.Err() != nil {
|
|
||||||
return fmt.Errorf("cannot process consolidation requests: %w", ctx.Err())
|
|
||||||
}
|
|
||||||
if IsValidSwitchToCompoundingRequest(st, cr) {
|
|
||||||
srcIdx, ok := st.ValidatorIndexByPubkey(bytesutil.ToBytes48(cr.SourcePubkey))
|
|
||||||
if !ok {
|
|
||||||
log.Error("Failed to find source validator index")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if err := SwitchToCompoundingValidator(st, srcIdx); err != nil {
|
|
||||||
log.WithError(err).Error("Failed to switch to compounding validator")
|
|
||||||
}
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
sourcePubkey := bytesutil.ToBytes48(cr.SourcePubkey)
|
|
||||||
targetPubkey := bytesutil.ToBytes48(cr.TargetPubkey)
|
|
||||||
if sourcePubkey == targetPubkey {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
if npc, err := st.NumPendingConsolidations(); err != nil {
|
|
||||||
return fmt.Errorf("failed to fetch number of pending consolidations: %w", err) // This should never happen.
|
|
||||||
} else if npc >= pcLimit {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
activeBal, err := helpers.TotalActiveBalance(st)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
churnLimit := helpers.ConsolidationChurnLimit(primitives.Gwei(activeBal))
|
|
||||||
if churnLimit <= primitives.Gwei(params.BeaconConfig().MinActivationBalance) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
srcIdx, ok := st.ValidatorIndexByPubkey(sourcePubkey)
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
tgtIdx, ok := st.ValidatorIndexByPubkey(targetPubkey)
|
|
||||||
if !ok {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
srcV, err := st.ValidatorAtIndex(srcIdx)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to fetch source validator: %w", err) // This should never happen.
|
|
||||||
}
|
|
||||||
|
|
||||||
roSrcV, err := state_native.NewValidator(srcV)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
tgtV, err := st.ValidatorAtIndexReadOnly(tgtIdx)
|
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to fetch target validator: %w", err) // This should never happen.
|
|
||||||
}
|
|
||||||
|
|
||||||
// Verify source withdrawal credentials
|
|
||||||
if !roSrcV.HasExecutionWithdrawalCredentials() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Confirm source_validator.withdrawal_credentials[12:] == consolidation_request.source_address
|
|
||||||
if len(srcV.WithdrawalCredentials) != 32 || len(cr.SourceAddress) != 20 || !bytes.HasSuffix(srcV.WithdrawalCredentials, cr.SourceAddress) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Target validator must have their withdrawal credentials set appropriately.
|
|
||||||
if !tgtV.HasCompoundingWithdrawalCredentials() {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Both validators must be active.
|
|
||||||
if !helpers.IsActiveValidator(srcV, curEpoch) || !helpers.IsActiveValidatorUsingTrie(tgtV, curEpoch) {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
// Neither validator is exiting.
|
|
||||||
if srcV.ExitEpoch != ffe || tgtV.ExitEpoch() != ffe {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
e, overflow := math.SafeAdd(uint64(srcV.ActivationEpoch), uint64(params.BeaconConfig().ShardCommitteePeriod))
|
|
||||||
if overflow {
|
|
||||||
log.Error("Overflow when adding activation epoch and shard committee period")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if uint64(curEpoch) < e {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
hasBal, err := st.HasPendingBalanceToWithdraw(srcIdx)
|
|
||||||
if err != nil {
|
|
||||||
log.WithError(err).Error("Failed to fetch pending balance to withdraw")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if hasBal {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initiate the exit of the source validator.
|
|
||||||
exitEpoch, err := ComputeConsolidationEpochAndUpdateChurn(ctx, st, primitives.Gwei(srcV.EffectiveBalance))
|
|
||||||
if err != nil {
|
|
||||||
log.WithError(err).Error("Failed to compute consolidation epoch")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
srcV.ExitEpoch = exitEpoch
|
|
||||||
srcV.WithdrawableEpoch = exitEpoch + minValWithdrawDelay
|
|
||||||
if err := st.UpdateValidatorAtIndex(srcIdx, srcV); err != nil {
|
|
||||||
return fmt.Errorf("failed to update validator: %w", err) // This should never happen.
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := st.AppendPendingConsolidation(ð.PendingConsolidation{SourceIndex: srcIdx, TargetIndex: tgtIdx}); err != nil {
|
|
||||||
return fmt.Errorf("failed to append pending consolidation: %w", err) // This should never happen.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// IsValidSwitchToCompoundingRequest returns true if the given consolidation request is valid for switching to compounding.
|
// IsValidSwitchToCompoundingRequest returns true if the given consolidation request is valid for switching to compounding.
|
||||||
//
|
//
|
||||||
// Spec code:
|
// Spec code:
|
||||||
|
|||||||
@@ -8,8 +8,6 @@ import (
|
|||||||
"github.com/OffchainLabs/prysm/v7/beacon-chain/state"
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/state"
|
||||||
state_native "github.com/OffchainLabs/prysm/v7/beacon-chain/state/state-native"
|
state_native "github.com/OffchainLabs/prysm/v7/beacon-chain/state/state-native"
|
||||||
"github.com/OffchainLabs/prysm/v7/config/params"
|
"github.com/OffchainLabs/prysm/v7/config/params"
|
||||||
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
|
||||||
"github.com/OffchainLabs/prysm/v7/encoding/bytesutil"
|
|
||||||
enginev1 "github.com/OffchainLabs/prysm/v7/proto/engine/v1"
|
enginev1 "github.com/OffchainLabs/prysm/v7/proto/engine/v1"
|
||||||
eth "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
eth "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
||||||
"github.com/OffchainLabs/prysm/v7/testing/require"
|
"github.com/OffchainLabs/prysm/v7/testing/require"
|
||||||
@@ -203,275 +201,6 @@ func TestProcessPendingConsolidations(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestProcessConsolidationRequests(t *testing.T) {
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
state state.BeaconState
|
|
||||||
reqs []*enginev1.ConsolidationRequest
|
|
||||||
validate func(*testing.T, state.BeaconState)
|
|
||||||
wantErr bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "nil request",
|
|
||||||
state: func() state.BeaconState {
|
|
||||||
st := ð.BeaconStateElectra{}
|
|
||||||
s, err := state_native.InitializeFromProtoElectra(st)
|
|
||||||
require.NoError(t, err)
|
|
||||||
return s
|
|
||||||
}(),
|
|
||||||
reqs: []*enginev1.ConsolidationRequest{nil},
|
|
||||||
validate: func(t *testing.T, st state.BeaconState) {
|
|
||||||
require.DeepEqual(t, st, st)
|
|
||||||
},
|
|
||||||
wantErr: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "one valid request",
|
|
||||||
state: func() state.BeaconState {
|
|
||||||
st := ð.BeaconStateElectra{
|
|
||||||
Slot: params.BeaconConfig().SlotsPerEpoch.Mul(uint64(params.BeaconConfig().ShardCommitteePeriod)),
|
|
||||||
Validators: createValidatorsWithTotalActiveBalance(32000000000000000), // 32M ETH
|
|
||||||
}
|
|
||||||
// Validator scenario setup. See comments in reqs section.
|
|
||||||
st.Validators[3].WithdrawalCredentials = bytesutil.Bytes32(0)
|
|
||||||
st.Validators[8].WithdrawalCredentials = bytesutil.Bytes32(1)
|
|
||||||
st.Validators[9].ActivationEpoch = params.BeaconConfig().FarFutureEpoch
|
|
||||||
st.Validators[12].ActivationEpoch = params.BeaconConfig().FarFutureEpoch
|
|
||||||
st.Validators[13].ExitEpoch = 10
|
|
||||||
st.Validators[16].ExitEpoch = 10
|
|
||||||
st.PendingPartialWithdrawals = []*eth.PendingPartialWithdrawal{
|
|
||||||
{
|
|
||||||
Index: 17,
|
|
||||||
Amount: 100,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
s, err := state_native.InitializeFromProtoElectra(st)
|
|
||||||
require.NoError(t, err)
|
|
||||||
return s
|
|
||||||
}(),
|
|
||||||
reqs: []*enginev1.ConsolidationRequest{
|
|
||||||
// Source doesn't have withdrawal credentials.
|
|
||||||
{
|
|
||||||
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(1)),
|
|
||||||
SourcePubkey: []byte("val_3"),
|
|
||||||
TargetPubkey: []byte("val_4"),
|
|
||||||
},
|
|
||||||
// Source withdrawal credentials don't match the consolidation address.
|
|
||||||
{
|
|
||||||
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(0)), // Should be 5
|
|
||||||
SourcePubkey: []byte("val_5"),
|
|
||||||
TargetPubkey: []byte("val_6"),
|
|
||||||
},
|
|
||||||
// Target does not have their withdrawal credentials set appropriately. (Using eth1 address prefix)
|
|
||||||
{
|
|
||||||
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(7)),
|
|
||||||
SourcePubkey: []byte("val_7"),
|
|
||||||
TargetPubkey: []byte("val_8"),
|
|
||||||
},
|
|
||||||
// Source is inactive.
|
|
||||||
{
|
|
||||||
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(9)),
|
|
||||||
SourcePubkey: []byte("val_9"),
|
|
||||||
TargetPubkey: []byte("val_10"),
|
|
||||||
},
|
|
||||||
// Target is inactive.
|
|
||||||
{
|
|
||||||
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(11)),
|
|
||||||
SourcePubkey: []byte("val_11"),
|
|
||||||
TargetPubkey: []byte("val_12"),
|
|
||||||
},
|
|
||||||
// Source is exiting.
|
|
||||||
{
|
|
||||||
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(13)),
|
|
||||||
SourcePubkey: []byte("val_13"),
|
|
||||||
TargetPubkey: []byte("val_14"),
|
|
||||||
},
|
|
||||||
// Target is exiting.
|
|
||||||
{
|
|
||||||
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(15)),
|
|
||||||
SourcePubkey: []byte("val_15"),
|
|
||||||
TargetPubkey: []byte("val_16"),
|
|
||||||
},
|
|
||||||
// Source doesn't exist
|
|
||||||
{
|
|
||||||
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(0)),
|
|
||||||
SourcePubkey: []byte("INVALID"),
|
|
||||||
TargetPubkey: []byte("val_0"),
|
|
||||||
},
|
|
||||||
// Target doesn't exist
|
|
||||||
{
|
|
||||||
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(0)),
|
|
||||||
SourcePubkey: []byte("val_0"),
|
|
||||||
TargetPubkey: []byte("INVALID"),
|
|
||||||
},
|
|
||||||
// Source == target
|
|
||||||
{
|
|
||||||
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(0)),
|
|
||||||
SourcePubkey: []byte("val_0"),
|
|
||||||
TargetPubkey: []byte("val_0"),
|
|
||||||
},
|
|
||||||
// Has pending partial withdrawal
|
|
||||||
{
|
|
||||||
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(0)),
|
|
||||||
SourcePubkey: []byte("val_17"),
|
|
||||||
TargetPubkey: []byte("val_1"),
|
|
||||||
},
|
|
||||||
// Valid consolidation request. This should be last to ensure invalid requests do
|
|
||||||
// not end the processing early.
|
|
||||||
{
|
|
||||||
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(1)),
|
|
||||||
SourcePubkey: []byte("val_1"),
|
|
||||||
TargetPubkey: []byte("val_2"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
validate: func(t *testing.T, st state.BeaconState) {
|
|
||||||
// Verify a pending consolidation is created.
|
|
||||||
numPC, err := st.NumPendingConsolidations()
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, uint64(1), numPC)
|
|
||||||
pcs, err := st.PendingConsolidations()
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, primitives.ValidatorIndex(1), pcs[0].SourceIndex)
|
|
||||||
require.Equal(t, primitives.ValidatorIndex(2), pcs[0].TargetIndex)
|
|
||||||
|
|
||||||
// Verify the source validator is exiting.
|
|
||||||
src, err := st.ValidatorAtIndex(1)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.NotEqual(t, params.BeaconConfig().FarFutureEpoch, src.ExitEpoch, "source validator exit epoch not updated")
|
|
||||||
require.Equal(t, params.BeaconConfig().MinValidatorWithdrawabilityDelay, src.WithdrawableEpoch-src.ExitEpoch, "source validator withdrawable epoch not set correctly")
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "pending consolidations limit reached",
|
|
||||||
state: func() state.BeaconState {
|
|
||||||
st := ð.BeaconStateElectra{
|
|
||||||
Validators: createValidatorsWithTotalActiveBalance(32000000000000000), // 32M ETH
|
|
||||||
PendingConsolidations: make([]*eth.PendingConsolidation, params.BeaconConfig().PendingConsolidationsLimit),
|
|
||||||
}
|
|
||||||
s, err := state_native.InitializeFromProtoElectra(st)
|
|
||||||
require.NoError(t, err)
|
|
||||||
return s
|
|
||||||
}(),
|
|
||||||
reqs: []*enginev1.ConsolidationRequest{
|
|
||||||
{
|
|
||||||
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(1)),
|
|
||||||
SourcePubkey: []byte("val_1"),
|
|
||||||
TargetPubkey: []byte("val_2"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
validate: func(t *testing.T, st state.BeaconState) {
|
|
||||||
// Verify no pending consolidation is created.
|
|
||||||
numPC, err := st.NumPendingConsolidations()
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, params.BeaconConfig().PendingConsolidationsLimit, numPC)
|
|
||||||
|
|
||||||
// Verify the source validator is not exiting.
|
|
||||||
src, err := st.ValidatorAtIndex(1)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, params.BeaconConfig().FarFutureEpoch, src.ExitEpoch, "source validator exit epoch should not be updated")
|
|
||||||
require.Equal(t, params.BeaconConfig().FarFutureEpoch, src.WithdrawableEpoch, "source validator withdrawable epoch should not be updated")
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "pending consolidations limit reached during processing",
|
|
||||||
state: func() state.BeaconState {
|
|
||||||
st := ð.BeaconStateElectra{
|
|
||||||
Slot: params.BeaconConfig().SlotsPerEpoch.Mul(uint64(params.BeaconConfig().ShardCommitteePeriod)),
|
|
||||||
Validators: createValidatorsWithTotalActiveBalance(32000000000000000), // 32M ETH
|
|
||||||
PendingConsolidations: make([]*eth.PendingConsolidation, params.BeaconConfig().PendingConsolidationsLimit-1),
|
|
||||||
}
|
|
||||||
s, err := state_native.InitializeFromProtoElectra(st)
|
|
||||||
require.NoError(t, err)
|
|
||||||
return s
|
|
||||||
}(),
|
|
||||||
reqs: []*enginev1.ConsolidationRequest{
|
|
||||||
{
|
|
||||||
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(1)),
|
|
||||||
SourcePubkey: []byte("val_1"),
|
|
||||||
TargetPubkey: []byte("val_2"),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(3)),
|
|
||||||
SourcePubkey: []byte("val_3"),
|
|
||||||
TargetPubkey: []byte("val_4"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
validate: func(t *testing.T, st state.BeaconState) {
|
|
||||||
// Verify a pending consolidation is created.
|
|
||||||
numPC, err := st.NumPendingConsolidations()
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, params.BeaconConfig().PendingConsolidationsLimit, numPC)
|
|
||||||
|
|
||||||
// The first consolidation was appended.
|
|
||||||
pcs, err := st.PendingConsolidations()
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, primitives.ValidatorIndex(1), pcs[params.BeaconConfig().PendingConsolidationsLimit-1].SourceIndex)
|
|
||||||
require.Equal(t, primitives.ValidatorIndex(2), pcs[params.BeaconConfig().PendingConsolidationsLimit-1].TargetIndex)
|
|
||||||
|
|
||||||
// Verify the second source validator is not exiting.
|
|
||||||
src, err := st.ValidatorAtIndex(3)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, params.BeaconConfig().FarFutureEpoch, src.ExitEpoch, "source validator exit epoch should not be updated")
|
|
||||||
require.Equal(t, params.BeaconConfig().FarFutureEpoch, src.WithdrawableEpoch, "source validator withdrawable epoch should not be updated")
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "pending consolidations limit reached and compounded consolidation after",
|
|
||||||
state: func() state.BeaconState {
|
|
||||||
st := ð.BeaconStateElectra{
|
|
||||||
Slot: params.BeaconConfig().SlotsPerEpoch.Mul(uint64(params.BeaconConfig().ShardCommitteePeriod)),
|
|
||||||
Validators: createValidatorsWithTotalActiveBalance(32000000000000000), // 32M ETH
|
|
||||||
PendingConsolidations: make([]*eth.PendingConsolidation, params.BeaconConfig().PendingConsolidationsLimit),
|
|
||||||
}
|
|
||||||
// To allow compounding consolidation requests.
|
|
||||||
st.Validators[3].WithdrawalCredentials[0] = params.BeaconConfig().ETH1AddressWithdrawalPrefixByte
|
|
||||||
s, err := state_native.InitializeFromProtoElectra(st)
|
|
||||||
require.NoError(t, err)
|
|
||||||
return s
|
|
||||||
}(),
|
|
||||||
reqs: []*enginev1.ConsolidationRequest{
|
|
||||||
{
|
|
||||||
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(1)),
|
|
||||||
SourcePubkey: []byte("val_1"),
|
|
||||||
TargetPubkey: []byte("val_2"),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(3)),
|
|
||||||
SourcePubkey: []byte("val_3"),
|
|
||||||
TargetPubkey: []byte("val_3"),
|
|
||||||
},
|
|
||||||
},
|
|
||||||
validate: func(t *testing.T, st state.BeaconState) {
|
|
||||||
// Verify a pending consolidation is created.
|
|
||||||
numPC, err := st.NumPendingConsolidations()
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, params.BeaconConfig().PendingConsolidationsLimit, numPC)
|
|
||||||
|
|
||||||
// Verify that the last consolidation was included
|
|
||||||
src, err := st.ValidatorAtIndex(3)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, params.BeaconConfig().CompoundingWithdrawalPrefixByte, src.WithdrawalCredentials[0], "source validator was not compounded")
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
err := electra.ProcessConsolidationRequests(context.TODO(), tt.state, tt.reqs)
|
|
||||||
if (err != nil) != tt.wantErr {
|
|
||||||
t.Errorf("ProcessWithdrawalRequests() error = %v, wantErr %v", err, tt.wantErr)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if !tt.wantErr {
|
|
||||||
require.NoError(t, err)
|
|
||||||
}
|
|
||||||
if tt.validate != nil {
|
|
||||||
tt.validate(t, tt.state)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestIsValidSwitchToCompoundingRequest(t *testing.T) {
|
func TestIsValidSwitchToCompoundingRequest(t *testing.T) {
|
||||||
st, _ := util.DeterministicGenesisStateElectra(t, 1)
|
st, _ := util.DeterministicGenesisStateElectra(t, 1)
|
||||||
t.Run("nil source pubkey", func(t *testing.T) {
|
t.Run("nil source pubkey", func(t *testing.T) {
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ import (
|
|||||||
"github.com/OffchainLabs/prysm/v7/contracts/deposit"
|
"github.com/OffchainLabs/prysm/v7/contracts/deposit"
|
||||||
"github.com/OffchainLabs/prysm/v7/encoding/bytesutil"
|
"github.com/OffchainLabs/prysm/v7/encoding/bytesutil"
|
||||||
"github.com/OffchainLabs/prysm/v7/monitoring/tracing/trace"
|
"github.com/OffchainLabs/prysm/v7/monitoring/tracing/trace"
|
||||||
enginev1 "github.com/OffchainLabs/prysm/v7/proto/engine/v1"
|
|
||||||
ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
||||||
"github.com/OffchainLabs/prysm/v7/runtime/version"
|
"github.com/OffchainLabs/prysm/v7/runtime/version"
|
||||||
"github.com/OffchainLabs/prysm/v7/time/slots"
|
"github.com/OffchainLabs/prysm/v7/time/slots"
|
||||||
@@ -536,62 +535,3 @@ func GetValidatorFromDeposit(pubKey []byte, withdrawalCredentials []byte, amount
|
|||||||
validator.EffectiveBalance = min(amount-(amount%params.BeaconConfig().EffectiveBalanceIncrement), maxEffectiveBalance)
|
validator.EffectiveBalance = min(amount-(amount%params.BeaconConfig().EffectiveBalanceIncrement), maxEffectiveBalance)
|
||||||
return validator, nil
|
return validator, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProcessDepositRequests is a function as part of electra to process execution layer deposits
|
|
||||||
func ProcessDepositRequests(ctx context.Context, beaconState state.BeaconState, requests []*enginev1.DepositRequest) (state.BeaconState, error) {
|
|
||||||
_, span := trace.StartSpan(ctx, "electra.ProcessDepositRequests")
|
|
||||||
defer span.End()
|
|
||||||
|
|
||||||
if len(requests) == 0 {
|
|
||||||
return beaconState, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var err error
|
|
||||||
for _, receipt := range requests {
|
|
||||||
beaconState, err = processDepositRequest(beaconState, receipt)
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not apply deposit request")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return beaconState, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// processDepositRequest processes the specific deposit request
|
|
||||||
// def process_deposit_request(state: BeaconState, deposit_request: DepositRequest) -> None:
|
|
||||||
//
|
|
||||||
// # Set deposit request start index
|
|
||||||
// if state.deposit_requests_start_index == UNSET_DEPOSIT_REQUESTS_START_INDEX:
|
|
||||||
// state.deposit_requests_start_index = deposit_request.index
|
|
||||||
//
|
|
||||||
// # Create pending deposit
|
|
||||||
// state.pending_deposits.append(PendingDeposit(
|
|
||||||
// pubkey=deposit_request.pubkey,
|
|
||||||
// withdrawal_credentials=deposit_request.withdrawal_credentials,
|
|
||||||
// amount=deposit_request.amount,
|
|
||||||
// signature=deposit_request.signature,
|
|
||||||
// slot=state.slot,
|
|
||||||
// ))
|
|
||||||
func processDepositRequest(beaconState state.BeaconState, request *enginev1.DepositRequest) (state.BeaconState, error) {
|
|
||||||
requestsStartIndex, err := beaconState.DepositRequestsStartIndex()
|
|
||||||
if err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not get deposit requests start index")
|
|
||||||
}
|
|
||||||
if request == nil {
|
|
||||||
return nil, errors.New("nil deposit request")
|
|
||||||
}
|
|
||||||
if requestsStartIndex == params.BeaconConfig().UnsetDepositRequestsStartIndex {
|
|
||||||
if err := beaconState.SetDepositRequestsStartIndex(request.Index); err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not set deposit requests start index")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if err := beaconState.AppendPendingDeposit(ðpb.PendingDeposit{
|
|
||||||
PublicKey: bytesutil.SafeCopyBytes(request.Pubkey),
|
|
||||||
WithdrawalCredentials: bytesutil.SafeCopyBytes(request.WithdrawalCredentials),
|
|
||||||
Amount: request.Amount,
|
|
||||||
Signature: bytesutil.SafeCopyBytes(request.Signature),
|
|
||||||
Slot: beaconState.Slot(),
|
|
||||||
}); err != nil {
|
|
||||||
return nil, errors.Wrap(err, "could not append deposit request")
|
|
||||||
}
|
|
||||||
return beaconState, nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
|
|
||||||
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/electra"
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/electra"
|
||||||
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/helpers"
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/helpers"
|
||||||
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/signing"
|
|
||||||
"github.com/OffchainLabs/prysm/v7/beacon-chain/state"
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/state"
|
||||||
state_native "github.com/OffchainLabs/prysm/v7/beacon-chain/state/state-native"
|
state_native "github.com/OffchainLabs/prysm/v7/beacon-chain/state/state-native"
|
||||||
stateTesting "github.com/OffchainLabs/prysm/v7/beacon-chain/state/testing"
|
stateTesting "github.com/OffchainLabs/prysm/v7/beacon-chain/state/testing"
|
||||||
@@ -15,7 +14,6 @@ import (
|
|||||||
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
||||||
"github.com/OffchainLabs/prysm/v7/crypto/bls"
|
"github.com/OffchainLabs/prysm/v7/crypto/bls"
|
||||||
"github.com/OffchainLabs/prysm/v7/encoding/bytesutil"
|
"github.com/OffchainLabs/prysm/v7/encoding/bytesutil"
|
||||||
enginev1 "github.com/OffchainLabs/prysm/v7/proto/engine/v1"
|
|
||||||
eth "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
eth "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
||||||
"github.com/OffchainLabs/prysm/v7/testing/require"
|
"github.com/OffchainLabs/prysm/v7/testing/require"
|
||||||
"github.com/OffchainLabs/prysm/v7/testing/util"
|
"github.com/OffchainLabs/prysm/v7/testing/util"
|
||||||
@@ -361,60 +359,6 @@ func TestBatchProcessNewPendingDeposits(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestProcessDepositRequests(t *testing.T) {
|
|
||||||
st, _ := util.DeterministicGenesisStateElectra(t, 1)
|
|
||||||
sk, err := bls.RandKey()
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.NoError(t, st.SetDepositRequestsStartIndex(1))
|
|
||||||
|
|
||||||
t.Run("empty requests continues", func(t *testing.T) {
|
|
||||||
newSt, err := electra.ProcessDepositRequests(t.Context(), st, []*enginev1.DepositRequest{})
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.DeepEqual(t, newSt, st)
|
|
||||||
})
|
|
||||||
t.Run("nil request errors", func(t *testing.T) {
|
|
||||||
_, err = electra.ProcessDepositRequests(t.Context(), st, []*enginev1.DepositRequest{nil})
|
|
||||||
require.ErrorContains(t, "nil deposit request", err)
|
|
||||||
})
|
|
||||||
|
|
||||||
vals := st.Validators()
|
|
||||||
vals[0].PublicKey = sk.PublicKey().Marshal()
|
|
||||||
vals[0].WithdrawalCredentials[0] = params.BeaconConfig().ETH1AddressWithdrawalPrefixByte
|
|
||||||
require.NoError(t, st.SetValidators(vals))
|
|
||||||
bals := st.Balances()
|
|
||||||
bals[0] = params.BeaconConfig().MinActivationBalance + 2000
|
|
||||||
require.NoError(t, st.SetBalances(bals))
|
|
||||||
require.NoError(t, st.SetPendingDeposits(make([]*eth.PendingDeposit, 0))) // reset pbd as the determinitstic state populates this already
|
|
||||||
withdrawalCred := make([]byte, 32)
|
|
||||||
withdrawalCred[0] = params.BeaconConfig().CompoundingWithdrawalPrefixByte
|
|
||||||
depositMessage := ð.DepositMessage{
|
|
||||||
PublicKey: sk.PublicKey().Marshal(),
|
|
||||||
Amount: 1000,
|
|
||||||
WithdrawalCredentials: withdrawalCred,
|
|
||||||
}
|
|
||||||
domain, err := signing.ComputeDomain(params.BeaconConfig().DomainDeposit, nil, nil)
|
|
||||||
require.NoError(t, err)
|
|
||||||
sr, err := signing.ComputeSigningRoot(depositMessage, domain)
|
|
||||||
require.NoError(t, err)
|
|
||||||
sig := sk.Sign(sr[:])
|
|
||||||
requests := []*enginev1.DepositRequest{
|
|
||||||
{
|
|
||||||
Pubkey: depositMessage.PublicKey,
|
|
||||||
Index: 0,
|
|
||||||
WithdrawalCredentials: depositMessage.WithdrawalCredentials,
|
|
||||||
Amount: depositMessage.Amount,
|
|
||||||
Signature: sig.Marshal(),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
st, err = electra.ProcessDepositRequests(t.Context(), st, requests)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
pbd, err := st.PendingDeposits()
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, 1, len(pbd))
|
|
||||||
require.Equal(t, uint64(1000), pbd[0].Amount)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestProcessDeposit_Electra_Simple(t *testing.T) {
|
func TestProcessDeposit_Electra_Simple(t *testing.T) {
|
||||||
deps, _, err := util.DeterministicDepositsAndKeysSameValidator(3)
|
deps, _, err := util.DeterministicDepositsAndKeysSameValidator(3)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test")
|
|||||||
go_library(
|
go_library(
|
||||||
name = "go_default_library",
|
name = "go_default_library",
|
||||||
srcs = [
|
srcs = [
|
||||||
"attestation.go",
|
|
||||||
"bid.go",
|
"bid.go",
|
||||||
|
"payload_attestation.go",
|
||||||
"pending_payment.go",
|
"pending_payment.go",
|
||||||
"proposer_slashing.go",
|
"proposer_slashing.go",
|
||||||
],
|
],
|
||||||
@@ -15,14 +15,17 @@ go_library(
|
|||||||
"//beacon-chain/core/signing:go_default_library",
|
"//beacon-chain/core/signing:go_default_library",
|
||||||
"//beacon-chain/core/time:go_default_library",
|
"//beacon-chain/core/time:go_default_library",
|
||||||
"//beacon-chain/state:go_default_library",
|
"//beacon-chain/state:go_default_library",
|
||||||
|
"//config/fieldparams:go_default_library",
|
||||||
"//config/params:go_default_library",
|
"//config/params:go_default_library",
|
||||||
|
"//consensus-types:go_default_library",
|
||||||
"//consensus-types/blocks:go_default_library",
|
"//consensus-types/blocks:go_default_library",
|
||||||
"//consensus-types/interfaces:go_default_library",
|
"//consensus-types/interfaces:go_default_library",
|
||||||
"//consensus-types/primitives:go_default_library",
|
"//consensus-types/primitives:go_default_library",
|
||||||
"//crypto/bls:go_default_library",
|
"//crypto/bls:go_default_library",
|
||||||
"//crypto/bls/common:go_default_library",
|
"//crypto/bls/common:go_default_library",
|
||||||
|
"//crypto/hash:go_default_library",
|
||||||
|
"//encoding/bytesutil:go_default_library",
|
||||||
"//proto/prysm/v1alpha1:go_default_library",
|
"//proto/prysm/v1alpha1:go_default_library",
|
||||||
"//runtime/version:go_default_library",
|
|
||||||
"//time/slots:go_default_library",
|
"//time/slots:go_default_library",
|
||||||
"@com_github_pkg_errors//:go_default_library",
|
"@com_github_pkg_errors//:go_default_library",
|
||||||
],
|
],
|
||||||
@@ -31,8 +34,8 @@ go_library(
|
|||||||
go_test(
|
go_test(
|
||||||
name = "go_default_test",
|
name = "go_default_test",
|
||||||
srcs = [
|
srcs = [
|
||||||
"attestation_test.go",
|
|
||||||
"bid_test.go",
|
"bid_test.go",
|
||||||
|
"payload_attestation_test.go",
|
||||||
"pending_payment_test.go",
|
"pending_payment_test.go",
|
||||||
"proposer_slashing_test.go",
|
"proposer_slashing_test.go",
|
||||||
],
|
],
|
||||||
@@ -43,6 +46,7 @@ go_test(
|
|||||||
"//beacon-chain/state:go_default_library",
|
"//beacon-chain/state:go_default_library",
|
||||||
"//beacon-chain/state/state-native:go_default_library",
|
"//beacon-chain/state/state-native:go_default_library",
|
||||||
"//config/params:go_default_library",
|
"//config/params:go_default_library",
|
||||||
|
"//consensus-types/blocks:go_default_library",
|
||||||
"//consensus-types/interfaces:go_default_library",
|
"//consensus-types/interfaces:go_default_library",
|
||||||
"//consensus-types/primitives:go_default_library",
|
"//consensus-types/primitives:go_default_library",
|
||||||
"//crypto/bls:go_default_library",
|
"//crypto/bls:go_default_library",
|
||||||
@@ -53,8 +57,10 @@ go_test(
|
|||||||
"//proto/prysm/v1alpha1/validator-client:go_default_library",
|
"//proto/prysm/v1alpha1/validator-client:go_default_library",
|
||||||
"//runtime/version:go_default_library",
|
"//runtime/version:go_default_library",
|
||||||
"//testing/require:go_default_library",
|
"//testing/require:go_default_library",
|
||||||
|
"//testing/util:go_default_library",
|
||||||
"//time/slots:go_default_library",
|
"//time/slots:go_default_library",
|
||||||
"@com_github_prysmaticlabs_fastssz//:go_default_library",
|
"@com_github_prysmaticlabs_fastssz//:go_default_library",
|
||||||
|
"@com_github_prysmaticlabs_go_bitfield//:go_default_library",
|
||||||
"@org_golang_google_protobuf//proto:go_default_library",
|
"@org_golang_google_protobuf//proto:go_default_library",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
package gloas
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/OffchainLabs/prysm/v7/beacon-chain/state"
|
|
||||||
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
|
||||||
"github.com/OffchainLabs/prysm/v7/runtime/version"
|
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
|
||||||
|
|
||||||
// MatchingPayload returns true if the attestation's committee index matches the expected payload index.
|
|
||||||
//
|
|
||||||
// For pre-Gloas forks, this always returns true.
|
|
||||||
//
|
|
||||||
// Spec v1.7.0-alpha (pseudocode):
|
|
||||||
//
|
|
||||||
// # [New in Gloas:EIP7732]
|
|
||||||
// if is_attestation_same_slot(state, data):
|
|
||||||
// assert data.index == 0
|
|
||||||
// payload_matches = True
|
|
||||||
// else:
|
|
||||||
// slot_index = data.slot % SLOTS_PER_HISTORICAL_ROOT
|
|
||||||
// payload_index = state.execution_payload_availability[slot_index]
|
|
||||||
// payload_matches = data.index == payload_index
|
|
||||||
func MatchingPayload(
|
|
||||||
beaconState state.ReadOnlyBeaconState,
|
|
||||||
beaconBlockRoot [32]byte,
|
|
||||||
slot primitives.Slot,
|
|
||||||
committeeIndex uint64,
|
|
||||||
) (bool, error) {
|
|
||||||
if beaconState.Version() < version.Gloas {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
sameSlot, err := beaconState.IsAttestationSameSlot(beaconBlockRoot, slot)
|
|
||||||
if err != nil {
|
|
||||||
return false, errors.Wrap(err, "failed to get same slot attestation status")
|
|
||||||
}
|
|
||||||
if sameSlot {
|
|
||||||
if committeeIndex != 0 {
|
|
||||||
return false, fmt.Errorf("committee index %d for same slot attestation must be 0", committeeIndex)
|
|
||||||
}
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
executionPayloadAvail, err := beaconState.ExecutionPayloadAvailability(slot)
|
|
||||||
if err != nil {
|
|
||||||
return false, errors.Wrap(err, "failed to get execution payload availability status")
|
|
||||||
}
|
|
||||||
return executionPayloadAvail == committeeIndex, nil
|
|
||||||
}
|
|
||||||
@@ -1,110 +0,0 @@
|
|||||||
package gloas
|
|
||||||
|
|
||||||
import (
|
|
||||||
"bytes"
|
|
||||||
"testing"
|
|
||||||
|
|
||||||
state_native "github.com/OffchainLabs/prysm/v7/beacon-chain/state/state-native"
|
|
||||||
"github.com/OffchainLabs/prysm/v7/config/params"
|
|
||||||
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
|
||||||
ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
|
||||||
"github.com/OffchainLabs/prysm/v7/runtime/version"
|
|
||||||
"github.com/OffchainLabs/prysm/v7/testing/require"
|
|
||||||
)
|
|
||||||
|
|
||||||
func buildStateWithBlockRoots(t *testing.T, stateSlot primitives.Slot, roots map[primitives.Slot][]byte) *state_native.BeaconState {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
cfg := params.BeaconConfig()
|
|
||||||
blockRoots := make([][]byte, cfg.SlotsPerHistoricalRoot)
|
|
||||||
for slot, root := range roots {
|
|
||||||
blockRoots[slot%cfg.SlotsPerHistoricalRoot] = root
|
|
||||||
}
|
|
||||||
|
|
||||||
stProto := ðpb.BeaconStateGloas{
|
|
||||||
Slot: stateSlot,
|
|
||||||
BlockRoots: blockRoots,
|
|
||||||
}
|
|
||||||
|
|
||||||
state, err := state_native.InitializeFromProtoGloas(stProto)
|
|
||||||
require.NoError(t, err)
|
|
||||||
return state.(*state_native.BeaconState)
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestMatchingPayload(t *testing.T) {
|
|
||||||
t.Run("pre-gloas always true", func(t *testing.T) {
|
|
||||||
stIface, err := state_native.InitializeFromProtoElectra(ðpb.BeaconStateElectra{})
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
ok, err := MatchingPayload(stIface, [32]byte{}, 0, 123)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, true, ok)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("same slot requires committee index 0", func(t *testing.T) {
|
|
||||||
root := bytes.Repeat([]byte{0xAA}, 32)
|
|
||||||
state := buildStateWithBlockRoots(t, 6, map[primitives.Slot][]byte{
|
|
||||||
4: root,
|
|
||||||
3: bytes.Repeat([]byte{0xBB}, 32),
|
|
||||||
})
|
|
||||||
|
|
||||||
var rootArr [32]byte
|
|
||||||
copy(rootArr[:], root)
|
|
||||||
|
|
||||||
ok, err := MatchingPayload(state, rootArr, 4, 1)
|
|
||||||
require.ErrorContains(t, "committee index", err)
|
|
||||||
require.Equal(t, false, ok)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("same slot matches when committee index is 0", func(t *testing.T) {
|
|
||||||
root := bytes.Repeat([]byte{0xAA}, 32)
|
|
||||||
state := buildStateWithBlockRoots(t, 6, map[primitives.Slot][]byte{
|
|
||||||
4: root,
|
|
||||||
3: bytes.Repeat([]byte{0xBB}, 32),
|
|
||||||
})
|
|
||||||
|
|
||||||
var rootArr [32]byte
|
|
||||||
copy(rootArr[:], root)
|
|
||||||
|
|
||||||
ok, err := MatchingPayload(state, rootArr, 4, 0)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, true, ok)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("non same slot checks payload availability", func(t *testing.T) {
|
|
||||||
cfg := params.BeaconConfig()
|
|
||||||
root := bytes.Repeat([]byte{0xAA}, 32)
|
|
||||||
blockRoots := make([][]byte, cfg.SlotsPerHistoricalRoot)
|
|
||||||
blockRoots[4%cfg.SlotsPerHistoricalRoot] = bytes.Repeat([]byte{0xCC}, 32)
|
|
||||||
blockRoots[3%cfg.SlotsPerHistoricalRoot] = bytes.Repeat([]byte{0xBB}, 32)
|
|
||||||
|
|
||||||
availability := make([]byte, cfg.SlotsPerHistoricalRoot/8)
|
|
||||||
slotIndex := uint64(4)
|
|
||||||
availability[slotIndex/8] = byte(1 << (slotIndex % 8))
|
|
||||||
|
|
||||||
stIface, err := state_native.InitializeFromProtoGloas(ðpb.BeaconStateGloas{
|
|
||||||
Slot: 6,
|
|
||||||
BlockRoots: blockRoots,
|
|
||||||
ExecutionPayloadAvailability: availability,
|
|
||||||
Fork: ðpb.Fork{
|
|
||||||
CurrentVersion: bytes.Repeat([]byte{0x66}, 4),
|
|
||||||
PreviousVersion: bytes.Repeat([]byte{0x66}, 4),
|
|
||||||
Epoch: 0,
|
|
||||||
},
|
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
|
||||||
state := stIface.(*state_native.BeaconState)
|
|
||||||
require.Equal(t, version.Gloas, state.Version())
|
|
||||||
|
|
||||||
var rootArr [32]byte
|
|
||||||
copy(rootArr[:], root)
|
|
||||||
|
|
||||||
ok, err := MatchingPayload(state, rootArr, 4, 1)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, true, ok)
|
|
||||||
|
|
||||||
ok, err = MatchingPayload(state, rootArr, 4, 0)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, false, ok)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
253
beacon-chain/core/gloas/payload_attestation.go
Normal file
253
beacon-chain/core/gloas/payload_attestation.go
Normal file
@@ -0,0 +1,253 @@
|
|||||||
|
package gloas
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"encoding/binary"
|
||||||
|
"fmt"
|
||||||
|
"slices"
|
||||||
|
|
||||||
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/helpers"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/signing"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/state"
|
||||||
|
fieldparams "github.com/OffchainLabs/prysm/v7/config/fieldparams"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/config/params"
|
||||||
|
consensus_types "github.com/OffchainLabs/prysm/v7/consensus-types"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/consensus-types/interfaces"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/crypto/bls"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/crypto/hash"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/encoding/bytesutil"
|
||||||
|
eth "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/time/slots"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ProcessPayloadAttestations validates payload attestations in a block body.
|
||||||
|
// Spec v1.7.0-alpha.0 (pseudocode):
|
||||||
|
// process_payload_attestation(state: BeaconState, payload_attestation: PayloadAttestation):
|
||||||
|
//
|
||||||
|
// data = payload_attestation.data
|
||||||
|
// assert data.beacon_block_root == state.latest_block_header.parent_root
|
||||||
|
// assert data.slot + 1 == state.slot
|
||||||
|
// indexed = get_indexed_payload_attestation(state, data.slot, payload_attestation)
|
||||||
|
// assert is_valid_indexed_payload_attestation(state, indexed)
|
||||||
|
func ProcessPayloadAttestations(ctx context.Context, st state.BeaconState, body interfaces.ReadOnlyBeaconBlockBody) error {
|
||||||
|
atts, err := body.PayloadAttestations()
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "failed to get payload attestations from block body")
|
||||||
|
}
|
||||||
|
if len(atts) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
header := st.LatestBlockHeader()
|
||||||
|
|
||||||
|
for i, att := range atts {
|
||||||
|
data := att.Data
|
||||||
|
if !bytes.Equal(data.BeaconBlockRoot, header.ParentRoot) {
|
||||||
|
return fmt.Errorf("payload attestation %d has wrong parent: got %x want %x", i, data.BeaconBlockRoot, header.ParentRoot)
|
||||||
|
}
|
||||||
|
|
||||||
|
dataSlot, err := data.Slot.SafeAdd(1)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "payload attestation %d has invalid slot addition", i)
|
||||||
|
}
|
||||||
|
if dataSlot != st.Slot() {
|
||||||
|
return fmt.Errorf("payload attestation %d has wrong slot: got %d want %d", i, data.Slot+1, st.Slot())
|
||||||
|
}
|
||||||
|
|
||||||
|
indexed, err := indexedPayloadAttestation(ctx, st, att)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "payload attestation %d failed to convert to indexed form", i)
|
||||||
|
}
|
||||||
|
if err := validIndexedPayloadAttestation(st, indexed); err != nil {
|
||||||
|
return errors.Wrapf(err, "payload attestation %d failed to verify indexed form", i)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// indexedPayloadAttestation converts a payload attestation into its indexed form.
|
||||||
|
func indexedPayloadAttestation(ctx context.Context, st state.ReadOnlyBeaconState, att *eth.PayloadAttestation) (*consensus_types.IndexedPayloadAttestation, error) {
|
||||||
|
committee, err := payloadCommittee(ctx, st, att.Data.Slot)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
indices := make([]primitives.ValidatorIndex, 0, len(committee))
|
||||||
|
for i, idx := range committee {
|
||||||
|
if att.AggregationBits.BitAt(uint64(i)) {
|
||||||
|
indices = append(indices, idx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
slices.Sort(indices)
|
||||||
|
|
||||||
|
return &consensus_types.IndexedPayloadAttestation{
|
||||||
|
AttestingIndices: indices,
|
||||||
|
Data: att.Data,
|
||||||
|
Signature: att.Signature,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// payloadCommittee returns the payload timeliness committee for a given slot for the state.
|
||||||
|
// Spec v1.7.0-alpha.0 (pseudocode):
|
||||||
|
// get_ptc(state: BeaconState, slot: Slot) -> Vector[ValidatorIndex, PTC_SIZE]:
|
||||||
|
//
|
||||||
|
// epoch = compute_epoch_at_slot(slot)
|
||||||
|
// seed = hash(get_seed(state, epoch, DOMAIN_PTC_ATTESTER) + uint_to_bytes(slot))
|
||||||
|
// indices = []
|
||||||
|
// committees_per_slot = get_committee_count_per_slot(state, epoch)
|
||||||
|
// for i in range(committees_per_slot):
|
||||||
|
// committee = get_beacon_committee(state, slot, CommitteeIndex(i))
|
||||||
|
// indices.extend(committee)
|
||||||
|
// return compute_balance_weighted_selection(state, indices, seed, size=PTC_SIZE, shuffle_indices=False)
|
||||||
|
func payloadCommittee(ctx context.Context, st state.ReadOnlyBeaconState, slot primitives.Slot) ([]primitives.ValidatorIndex, error) {
|
||||||
|
epoch := slots.ToEpoch(slot)
|
||||||
|
seed, err := ptcSeed(st, epoch, slot)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
activeCount, err := helpers.ActiveValidatorCount(ctx, st, epoch)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
committeesPerSlot := helpers.SlotCommitteeCount(activeCount)
|
||||||
|
out := make([]primitives.ValidatorIndex, 0, activeCount/uint64(params.BeaconConfig().SlotsPerEpoch))
|
||||||
|
|
||||||
|
for i := primitives.CommitteeIndex(0); i < primitives.CommitteeIndex(committeesPerSlot); i++ {
|
||||||
|
committee, err := helpers.BeaconCommitteeFromState(ctx, st, slot, i)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "failed to get beacon committee %d", i)
|
||||||
|
}
|
||||||
|
out = append(out, committee...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return selectByBalance(ctx, st, out, seed, fieldparams.PTCSize)
|
||||||
|
}
|
||||||
|
|
||||||
|
// ptcSeed computes the seed for the payload timeliness committee.
|
||||||
|
func ptcSeed(st state.ReadOnlyBeaconState, epoch primitives.Epoch, slot primitives.Slot) ([32]byte, error) {
|
||||||
|
seed, err := helpers.Seed(st, epoch, params.BeaconConfig().DomainPTCAttester)
|
||||||
|
if err != nil {
|
||||||
|
return [32]byte{}, err
|
||||||
|
}
|
||||||
|
return hash.Hash(append(seed[:], bytesutil.Bytes8(uint64(slot))...)), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// selectByBalance selects a balance-weighted subset of input candidates.
|
||||||
|
// Spec v1.7.0-alpha.0 (pseudocode):
|
||||||
|
// compute_balance_weighted_selection(state, indices, seed, size, shuffle_indices):
|
||||||
|
// Note: shuffle_indices is false for PTC.
|
||||||
|
//
|
||||||
|
// total = len(indices); selected = []; i = 0
|
||||||
|
// while len(selected) < size:
|
||||||
|
// next = i % total
|
||||||
|
// if shuffle_indices: next = compute_shuffled_index(next, total, seed)
|
||||||
|
// if compute_balance_weighted_acceptance(state, indices[next], seed, i):
|
||||||
|
// selected.append(indices[next])
|
||||||
|
// i += 1
|
||||||
|
func selectByBalance(ctx context.Context, st state.ReadOnlyBeaconState, candidates []primitives.ValidatorIndex, seed [32]byte, count uint64) ([]primitives.ValidatorIndex, error) {
|
||||||
|
if len(candidates) == 0 {
|
||||||
|
return nil, errors.New("no candidates for balance weighted selection")
|
||||||
|
}
|
||||||
|
|
||||||
|
hashFunc := hash.CustomSHA256Hasher()
|
||||||
|
// Pre-allocate buffer for hash input: seed (32 bytes) + round counter (8 bytes).
|
||||||
|
var buf [40]byte
|
||||||
|
copy(buf[:], seed[:])
|
||||||
|
maxBalance := params.BeaconConfig().MaxEffectiveBalanceElectra
|
||||||
|
|
||||||
|
selected := make([]primitives.ValidatorIndex, 0, count)
|
||||||
|
total := uint64(len(candidates))
|
||||||
|
for i := uint64(0); uint64(len(selected)) < count; i++ {
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
return nil, ctx.Err()
|
||||||
|
}
|
||||||
|
idx := candidates[i%total]
|
||||||
|
ok, err := acceptByBalance(st, idx, buf[:], hashFunc, maxBalance, i)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if ok {
|
||||||
|
selected = append(selected, idx)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return selected, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// acceptByBalance determines if a validator is accepted based on its effective balance.
|
||||||
|
// Spec v1.7.0-alpha.0 (pseudocode):
|
||||||
|
// compute_balance_weighted_acceptance(state, index, seed, i):
|
||||||
|
//
|
||||||
|
// MAX_RANDOM_VALUE = 2**16 - 1
|
||||||
|
// random_bytes = hash(seed + uint_to_bytes(i // 16))
|
||||||
|
// offset = i % 16 * 2
|
||||||
|
// random_value = bytes_to_uint64(random_bytes[offset:offset+2])
|
||||||
|
// effective_balance = state.validators[index].effective_balance
|
||||||
|
// return effective_balance * MAX_RANDOM_VALUE >= MAX_EFFECTIVE_BALANCE_ELECTRA * random_value
|
||||||
|
func acceptByBalance(st state.ReadOnlyBeaconState, idx primitives.ValidatorIndex, seedBuf []byte, hashFunc func([]byte) [32]byte, maxBalance uint64, round uint64) (bool, error) {
|
||||||
|
// Reuse the seed buffer by overwriting the last 8 bytes with the round counter.
|
||||||
|
binary.LittleEndian.PutUint64(seedBuf[len(seedBuf)-8:], round/16)
|
||||||
|
random := hashFunc(seedBuf)
|
||||||
|
offset := (round % 16) * 2
|
||||||
|
randomValue := uint64(binary.LittleEndian.Uint16(random[offset : offset+2])) // 16-bit draw per spec
|
||||||
|
|
||||||
|
val, err := st.ValidatorAtIndex(idx)
|
||||||
|
if err != nil {
|
||||||
|
return false, errors.Wrapf(err, "validator %d", idx)
|
||||||
|
}
|
||||||
|
|
||||||
|
return val.EffectiveBalance*fieldparams.MaxRandomValueElectra >= maxBalance*randomValue, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// validIndexedPayloadAttestation verifies the signature of an indexed payload attestation.
|
||||||
|
// Spec v1.7.0-alpha.0 (pseudocode):
|
||||||
|
// is_valid_indexed_payload_attestation(state: BeaconState, indexed_payload_attestation: IndexedPayloadAttestation) -> bool:
|
||||||
|
//
|
||||||
|
// indices = indexed_payload_attestation.attesting_indices
|
||||||
|
// return len(indices) > 0 and indices == sorted(indices) and
|
||||||
|
// bls.FastAggregateVerify(
|
||||||
|
// [state.validators[i].pubkey for i in indices],
|
||||||
|
// compute_signing_root(indexed_payload_attestation.data, get_domain(state, DOMAIN_PTC_ATTESTER, compute_epoch_at_slot(attestation.data.slot)),
|
||||||
|
// indexed_payload_attestation.signature,
|
||||||
|
// )
|
||||||
|
func validIndexedPayloadAttestation(st state.ReadOnlyBeaconState, att *consensus_types.IndexedPayloadAttestation) error {
|
||||||
|
indices := att.AttestingIndices
|
||||||
|
if len(indices) == 0 || !slices.IsSorted(indices) {
|
||||||
|
return errors.New("attesting indices empty or unsorted")
|
||||||
|
}
|
||||||
|
|
||||||
|
pubkeys := make([]bls.PublicKey, len(indices))
|
||||||
|
for i, idx := range indices {
|
||||||
|
val, err := st.ValidatorAtIndexReadOnly(idx)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "validator %d", idx)
|
||||||
|
}
|
||||||
|
keyBytes := val.PublicKey()
|
||||||
|
key, err := bls.PublicKeyFromBytes(keyBytes[:])
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrapf(err, "pubkey %d", idx)
|
||||||
|
}
|
||||||
|
pubkeys[i] = key
|
||||||
|
}
|
||||||
|
|
||||||
|
domain, err := signing.Domain(st.Fork(), slots.ToEpoch(att.Data.Slot), params.BeaconConfig().DomainPTCAttester, st.GenesisValidatorsRoot())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
root, err := signing.ComputeSigningRoot(att.Data, domain)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
sig, err := bls.SignatureFromBytes(att.Signature)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if !sig.FastAggregateVerify(pubkeys, root) {
|
||||||
|
return errors.New("invalid signature")
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
305
beacon-chain/core/gloas/payload_attestation_test.go
Normal file
305
beacon-chain/core/gloas/payload_attestation_test.go
Normal file
@@ -0,0 +1,305 @@
|
|||||||
|
package gloas_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/OffchainLabs/go-bitfield"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/gloas"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/helpers"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/signing"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/state"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/config/params"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/consensus-types/blocks"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/consensus-types/interfaces"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/crypto/bls"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/crypto/bls/common"
|
||||||
|
eth "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/testing/require"
|
||||||
|
testutil "github.com/OffchainLabs/prysm/v7/testing/util"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/time/slots"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestProcessPayloadAttestations_WrongParent(t *testing.T) {
|
||||||
|
setupTestConfig(t)
|
||||||
|
|
||||||
|
_, pk := newKey(t)
|
||||||
|
st := newTestState(t, []*eth.Validator{activeValidator(pk)}, 1)
|
||||||
|
require.NoError(t, st.SetSlot(2))
|
||||||
|
parentRoot := bytes.Repeat([]byte{0xaa}, 32)
|
||||||
|
require.NoError(t, st.SetLatestBlockHeader(ð.BeaconBlockHeader{ParentRoot: parentRoot}))
|
||||||
|
|
||||||
|
att := ð.PayloadAttestation{
|
||||||
|
Data: ð.PayloadAttestationData{
|
||||||
|
BeaconBlockRoot: bytes.Repeat([]byte{0xbb}, 32),
|
||||||
|
Slot: 1,
|
||||||
|
},
|
||||||
|
AggregationBits: bitfield.NewBitvector512(),
|
||||||
|
Signature: make([]byte, 96),
|
||||||
|
}
|
||||||
|
body := buildBody(t, att)
|
||||||
|
|
||||||
|
err := gloas.ProcessPayloadAttestations(t.Context(), st, body)
|
||||||
|
require.ErrorContains(t, "wrong parent", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestProcessPayloadAttestations_WrongSlot(t *testing.T) {
|
||||||
|
setupTestConfig(t)
|
||||||
|
|
||||||
|
_, pk := newKey(t)
|
||||||
|
st := newTestState(t, []*eth.Validator{activeValidator(pk)}, 1)
|
||||||
|
require.NoError(t, st.SetSlot(3))
|
||||||
|
parentRoot := bytes.Repeat([]byte{0xaa}, 32)
|
||||||
|
require.NoError(t, st.SetLatestBlockHeader(ð.BeaconBlockHeader{ParentRoot: parentRoot}))
|
||||||
|
|
||||||
|
att := ð.PayloadAttestation{
|
||||||
|
Data: ð.PayloadAttestationData{
|
||||||
|
BeaconBlockRoot: parentRoot,
|
||||||
|
Slot: 1,
|
||||||
|
},
|
||||||
|
AggregationBits: bitfield.NewBitvector512(),
|
||||||
|
Signature: make([]byte, 96),
|
||||||
|
}
|
||||||
|
body := buildBody(t, att)
|
||||||
|
|
||||||
|
err := gloas.ProcessPayloadAttestations(t.Context(), st, body)
|
||||||
|
require.ErrorContains(t, "wrong slot", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestProcessPayloadAttestations_InvalidSignature(t *testing.T) {
|
||||||
|
setupTestConfig(t)
|
||||||
|
|
||||||
|
_, pk1 := newKey(t)
|
||||||
|
sk2, pk2 := newKey(t)
|
||||||
|
vals := []*eth.Validator{activeValidator(pk1), activeValidator(pk2)}
|
||||||
|
st := newTestState(t, vals, 2)
|
||||||
|
parentRoot := bytes.Repeat([]byte{0xaa}, 32)
|
||||||
|
require.NoError(t, st.SetLatestBlockHeader(ð.BeaconBlockHeader{ParentRoot: parentRoot}))
|
||||||
|
|
||||||
|
attData := ð.PayloadAttestationData{
|
||||||
|
BeaconBlockRoot: parentRoot,
|
||||||
|
Slot: 1,
|
||||||
|
}
|
||||||
|
att := ð.PayloadAttestation{
|
||||||
|
Data: attData,
|
||||||
|
AggregationBits: setBits(bitfield.NewBitvector512(), 0),
|
||||||
|
Signature: signAttestation(t, st, attData, []common.SecretKey{sk2}),
|
||||||
|
}
|
||||||
|
body := buildBody(t, att)
|
||||||
|
|
||||||
|
err := gloas.ProcessPayloadAttestations(t.Context(), st, body)
|
||||||
|
require.ErrorContains(t, "failed to verify indexed form", err)
|
||||||
|
require.ErrorContains(t, "invalid signature", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestProcessPayloadAttestations_EmptyAggregationBits(t *testing.T) {
|
||||||
|
setupTestConfig(t)
|
||||||
|
|
||||||
|
_, pk := newKey(t)
|
||||||
|
st := newTestState(t, []*eth.Validator{activeValidator(pk)}, 1)
|
||||||
|
require.NoError(t, st.SetSlot(2))
|
||||||
|
parentRoot := bytes.Repeat([]byte{0xaa}, 32)
|
||||||
|
require.NoError(t, st.SetLatestBlockHeader(ð.BeaconBlockHeader{ParentRoot: parentRoot}))
|
||||||
|
|
||||||
|
attData := ð.PayloadAttestationData{
|
||||||
|
BeaconBlockRoot: parentRoot,
|
||||||
|
Slot: 1,
|
||||||
|
}
|
||||||
|
att := ð.PayloadAttestation{
|
||||||
|
Data: attData,
|
||||||
|
AggregationBits: bitfield.NewBitvector512(),
|
||||||
|
Signature: make([]byte, 96),
|
||||||
|
}
|
||||||
|
body := buildBody(t, att)
|
||||||
|
|
||||||
|
err := gloas.ProcessPayloadAttestations(t.Context(), st, body)
|
||||||
|
require.ErrorContains(t, "failed to verify indexed form", err)
|
||||||
|
require.ErrorContains(t, "attesting indices empty or unsorted", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestProcessPayloadAttestations_HappyPath(t *testing.T) {
|
||||||
|
helpers.ClearCache()
|
||||||
|
setupTestConfig(t)
|
||||||
|
|
||||||
|
sk1, pk1 := newKey(t)
|
||||||
|
sk2, pk2 := newKey(t)
|
||||||
|
vals := []*eth.Validator{activeValidator(pk1), activeValidator(pk2)}
|
||||||
|
|
||||||
|
st := newTestState(t, vals, 2)
|
||||||
|
parentRoot := bytes.Repeat([]byte{0xaa}, 32)
|
||||||
|
require.NoError(t, st.SetLatestBlockHeader(ð.BeaconBlockHeader{ParentRoot: parentRoot}))
|
||||||
|
|
||||||
|
attData := ð.PayloadAttestationData{
|
||||||
|
BeaconBlockRoot: parentRoot,
|
||||||
|
Slot: 1,
|
||||||
|
}
|
||||||
|
aggBits := bitfield.NewBitvector512()
|
||||||
|
aggBits.SetBitAt(0, true)
|
||||||
|
aggBits.SetBitAt(1, true)
|
||||||
|
|
||||||
|
att := ð.PayloadAttestation{
|
||||||
|
Data: attData,
|
||||||
|
AggregationBits: aggBits,
|
||||||
|
Signature: signAttestation(t, st, attData, []common.SecretKey{sk1, sk2}),
|
||||||
|
}
|
||||||
|
body := buildBody(t, att)
|
||||||
|
|
||||||
|
err := gloas.ProcessPayloadAttestations(t.Context(), st, body)
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestProcessPayloadAttestations_MultipleAttestations(t *testing.T) {
|
||||||
|
helpers.ClearCache()
|
||||||
|
setupTestConfig(t)
|
||||||
|
|
||||||
|
sk1, pk1 := newKey(t)
|
||||||
|
sk2, pk2 := newKey(t)
|
||||||
|
vals := []*eth.Validator{activeValidator(pk1), activeValidator(pk2)}
|
||||||
|
|
||||||
|
st := newTestState(t, vals, 2)
|
||||||
|
parentRoot := bytes.Repeat([]byte{0xaa}, 32)
|
||||||
|
require.NoError(t, st.SetLatestBlockHeader(ð.BeaconBlockHeader{ParentRoot: parentRoot}))
|
||||||
|
|
||||||
|
attData1 := ð.PayloadAttestationData{
|
||||||
|
BeaconBlockRoot: parentRoot,
|
||||||
|
Slot: 1,
|
||||||
|
}
|
||||||
|
attData2 := ð.PayloadAttestationData{
|
||||||
|
BeaconBlockRoot: parentRoot,
|
||||||
|
Slot: 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
att1 := ð.PayloadAttestation{
|
||||||
|
Data: attData1,
|
||||||
|
AggregationBits: setBits(bitfield.NewBitvector512(), 0),
|
||||||
|
Signature: signAttestation(t, st, attData1, []common.SecretKey{sk1}),
|
||||||
|
}
|
||||||
|
att2 := ð.PayloadAttestation{
|
||||||
|
Data: attData2,
|
||||||
|
AggregationBits: setBits(bitfield.NewBitvector512(), 1),
|
||||||
|
Signature: signAttestation(t, st, attData2, []common.SecretKey{sk2}),
|
||||||
|
}
|
||||||
|
|
||||||
|
body := buildBody(t, att1, att2)
|
||||||
|
|
||||||
|
err := gloas.ProcessPayloadAttestations(t.Context(), st, body)
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestProcessPayloadAttestations_IndexedVerificationError(t *testing.T) {
|
||||||
|
setupTestConfig(t)
|
||||||
|
|
||||||
|
_, pk := newKey(t)
|
||||||
|
st := newTestState(t, []*eth.Validator{activeValidator(pk)}, 1)
|
||||||
|
parentRoot := bytes.Repeat([]byte{0xaa}, 32)
|
||||||
|
require.NoError(t, st.SetLatestBlockHeader(ð.BeaconBlockHeader{ParentRoot: parentRoot}))
|
||||||
|
|
||||||
|
attData := ð.PayloadAttestationData{
|
||||||
|
BeaconBlockRoot: parentRoot,
|
||||||
|
Slot: 0,
|
||||||
|
}
|
||||||
|
att := ð.PayloadAttestation{
|
||||||
|
Data: attData,
|
||||||
|
AggregationBits: setBits(bitfield.NewBitvector512(), 0),
|
||||||
|
Signature: make([]byte, 96),
|
||||||
|
}
|
||||||
|
body := buildBody(t, att)
|
||||||
|
|
||||||
|
errState := &validatorLookupErrState{
|
||||||
|
BeaconState: st,
|
||||||
|
errIndex: 0,
|
||||||
|
}
|
||||||
|
err := gloas.ProcessPayloadAttestations(t.Context(), errState, body)
|
||||||
|
require.ErrorContains(t, "failed to verify indexed form", err)
|
||||||
|
require.ErrorContains(t, "validator 0", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
func newTestState(t *testing.T, vals []*eth.Validator, slot primitives.Slot) state.BeaconState {
|
||||||
|
st, err := testutil.NewBeaconState()
|
||||||
|
require.NoError(t, err)
|
||||||
|
for _, v := range vals {
|
||||||
|
require.NoError(t, st.AppendValidator(v))
|
||||||
|
require.NoError(t, st.AppendBalance(v.EffectiveBalance))
|
||||||
|
}
|
||||||
|
require.NoError(t, st.SetSlot(slot))
|
||||||
|
require.NoError(t, helpers.UpdateCommitteeCache(t.Context(), st, slots.ToEpoch(slot)))
|
||||||
|
return st
|
||||||
|
}
|
||||||
|
|
||||||
|
func setupTestConfig(t *testing.T) {
|
||||||
|
params.SetupTestConfigCleanup(t)
|
||||||
|
cfg := params.BeaconConfig().Copy()
|
||||||
|
cfg.SlotsPerEpoch = 1
|
||||||
|
cfg.MaxEffectiveBalanceElectra = cfg.MaxEffectiveBalance
|
||||||
|
params.OverrideBeaconConfig(cfg)
|
||||||
|
}
|
||||||
|
|
||||||
|
func buildBody(t *testing.T, atts ...*eth.PayloadAttestation) interfaces.ReadOnlyBeaconBlockBody {
|
||||||
|
body := ð.BeaconBlockBodyGloas{
|
||||||
|
PayloadAttestations: atts,
|
||||||
|
RandaoReveal: make([]byte, 96),
|
||||||
|
Eth1Data: ð.Eth1Data{},
|
||||||
|
Graffiti: make([]byte, 32),
|
||||||
|
ProposerSlashings: []*eth.ProposerSlashing{},
|
||||||
|
AttesterSlashings: []*eth.AttesterSlashingElectra{},
|
||||||
|
Attestations: []*eth.AttestationElectra{},
|
||||||
|
Deposits: []*eth.Deposit{},
|
||||||
|
VoluntaryExits: []*eth.SignedVoluntaryExit{},
|
||||||
|
SyncAggregate: ð.SyncAggregate{},
|
||||||
|
BlsToExecutionChanges: []*eth.SignedBLSToExecutionChange{},
|
||||||
|
}
|
||||||
|
wrapped, err := blocks.NewBeaconBlockBody(body)
|
||||||
|
require.NoError(t, err)
|
||||||
|
return wrapped
|
||||||
|
}
|
||||||
|
|
||||||
|
func setBits(bits bitfield.Bitvector512, idx uint64) bitfield.Bitvector512 {
|
||||||
|
bits.SetBitAt(idx, true)
|
||||||
|
return bits
|
||||||
|
}
|
||||||
|
|
||||||
|
func activeValidator(pub []byte) *eth.Validator {
|
||||||
|
return ð.Validator{
|
||||||
|
PublicKey: pub,
|
||||||
|
EffectiveBalance: params.BeaconConfig().MaxEffectiveBalance,
|
||||||
|
WithdrawalCredentials: make([]byte, 32),
|
||||||
|
ActivationEligibilityEpoch: 0,
|
||||||
|
ActivationEpoch: 0,
|
||||||
|
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||||
|
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func newKey(t *testing.T) (common.SecretKey, []byte) {
|
||||||
|
sk, err := bls.RandKey()
|
||||||
|
require.NoError(t, err)
|
||||||
|
return sk, sk.PublicKey().Marshal()
|
||||||
|
}
|
||||||
|
|
||||||
|
func signAttestation(t *testing.T, st state.ReadOnlyBeaconState, data *eth.PayloadAttestationData, sks []common.SecretKey) []byte {
|
||||||
|
domain, err := signing.Domain(st.Fork(), slots.ToEpoch(data.Slot), params.BeaconConfig().DomainPTCAttester, st.GenesisValidatorsRoot())
|
||||||
|
require.NoError(t, err)
|
||||||
|
root, err := signing.ComputeSigningRoot(data, domain)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
sigs := make([]common.Signature, len(sks))
|
||||||
|
for i, sk := range sks {
|
||||||
|
sigs[i] = sk.Sign(root[:])
|
||||||
|
}
|
||||||
|
agg := bls.AggregateSignatures(sigs)
|
||||||
|
return agg.Marshal()
|
||||||
|
}
|
||||||
|
|
||||||
|
type validatorLookupErrState struct {
|
||||||
|
state.BeaconState
|
||||||
|
errIndex primitives.ValidatorIndex
|
||||||
|
}
|
||||||
|
|
||||||
|
// ValidatorAtIndexReadOnly is overridden to simulate a missing validator lookup.
|
||||||
|
func (s *validatorLookupErrState) ValidatorAtIndexReadOnly(idx primitives.ValidatorIndex) (state.ReadOnlyValidator, error) {
|
||||||
|
if idx == s.errIndex {
|
||||||
|
return nil, state.ErrNilValidatorsInState
|
||||||
|
}
|
||||||
|
return s.BeaconState.ValidatorAtIndexReadOnly(idx)
|
||||||
|
}
|
||||||
60
beacon-chain/core/requests/BUILD.bazel
Normal file
60
beacon-chain/core/requests/BUILD.bazel
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
load("@prysm//tools/go:def.bzl", "go_library", "go_test")
|
||||||
|
|
||||||
|
go_library(
|
||||||
|
name = "go_default_library",
|
||||||
|
srcs = [
|
||||||
|
"consolidations.go",
|
||||||
|
"deposits.go",
|
||||||
|
"log.go",
|
||||||
|
"withdrawals.go",
|
||||||
|
],
|
||||||
|
importpath = "github.com/OffchainLabs/prysm/v7/beacon-chain/core/requests",
|
||||||
|
visibility = ["//visibility:public"],
|
||||||
|
deps = [
|
||||||
|
"//beacon-chain/core/helpers:go_default_library",
|
||||||
|
"//beacon-chain/core/validators:go_default_library",
|
||||||
|
"//beacon-chain/state:go_default_library",
|
||||||
|
"//beacon-chain/state/state-native:go_default_library",
|
||||||
|
"//config/params:go_default_library",
|
||||||
|
"//consensus-types/primitives:go_default_library",
|
||||||
|
"//crypto/bls/common:go_default_library",
|
||||||
|
"//encoding/bytesutil:go_default_library",
|
||||||
|
"//math:go_default_library",
|
||||||
|
"//monitoring/tracing/trace:go_default_library",
|
||||||
|
"//proto/engine/v1:go_default_library",
|
||||||
|
"//proto/prysm/v1alpha1:go_default_library",
|
||||||
|
"//runtime/version:go_default_library",
|
||||||
|
"//time/slots:go_default_library",
|
||||||
|
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
|
||||||
|
"@com_github_ethereum_go_ethereum//common/math:go_default_library",
|
||||||
|
"@com_github_pkg_errors//:go_default_library",
|
||||||
|
"@com_github_sirupsen_logrus//:go_default_library",
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
go_test(
|
||||||
|
name = "go_default_test",
|
||||||
|
srcs = [
|
||||||
|
"consolidations_test.go",
|
||||||
|
"deposits_test.go",
|
||||||
|
"withdrawals_test.go",
|
||||||
|
],
|
||||||
|
deps = [
|
||||||
|
":go_default_library",
|
||||||
|
"//beacon-chain/core/signing:go_default_library",
|
||||||
|
"//beacon-chain/state:go_default_library",
|
||||||
|
"//beacon-chain/state/state-native:go_default_library",
|
||||||
|
"//config/params:go_default_library",
|
||||||
|
"//consensus-types/primitives:go_default_library",
|
||||||
|
"//crypto/bls:go_default_library",
|
||||||
|
"//encoding/bytesutil:go_default_library",
|
||||||
|
"//proto/engine/v1:go_default_library",
|
||||||
|
"//proto/prysm/v1alpha1:go_default_library",
|
||||||
|
"//testing/assert:go_default_library",
|
||||||
|
"//testing/require:go_default_library",
|
||||||
|
"//testing/util:go_default_library",
|
||||||
|
"@com_github_ethereum_go_ethereum//common/hexutil:go_default_library",
|
||||||
|
"@com_github_sirupsen_logrus//:go_default_library",
|
||||||
|
"@com_github_sirupsen_logrus//hooks/test:go_default_library",
|
||||||
|
],
|
||||||
|
)
|
||||||
365
beacon-chain/core/requests/consolidations.go
Normal file
365
beacon-chain/core/requests/consolidations.go
Normal file
@@ -0,0 +1,365 @@
|
|||||||
|
package requests
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bytes"
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/helpers"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/state"
|
||||||
|
state_native "github.com/OffchainLabs/prysm/v7/beacon-chain/state/state-native"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/config/params"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/crypto/bls/common"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/encoding/bytesutil"
|
||||||
|
prysmMath "github.com/OffchainLabs/prysm/v7/math"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/monitoring/tracing/trace"
|
||||||
|
enginev1 "github.com/OffchainLabs/prysm/v7/proto/engine/v1"
|
||||||
|
eth "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/time/slots"
|
||||||
|
"github.com/ethereum/go-ethereum/common/math"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ProcessConsolidationRequests implements the spec definition below. This method makes mutating
|
||||||
|
// calls to the beacon state.
|
||||||
|
//
|
||||||
|
// def process_consolidation_request(
|
||||||
|
// state: BeaconState,
|
||||||
|
// consolidation_request: ConsolidationRequest
|
||||||
|
// ) -> None:
|
||||||
|
// if is_valid_switch_to_compounding_request(state, consolidation_request):
|
||||||
|
// validator_pubkeys = [v.pubkey for v in state.validators]
|
||||||
|
// request_source_pubkey = consolidation_request.source_pubkey
|
||||||
|
// source_index = ValidatorIndex(validator_pubkeys.index(request_source_pubkey))
|
||||||
|
// switch_to_compounding_validator(state, source_index)
|
||||||
|
// return
|
||||||
|
//
|
||||||
|
// # Verify that source != target, so a consolidation cannot be used as an exit.
|
||||||
|
// if consolidation_request.source_pubkey == consolidation_request.target_pubkey:
|
||||||
|
// return
|
||||||
|
// # If the pending consolidations queue is full, consolidation requests are ignored
|
||||||
|
// if len(state.pending_consolidations) == PENDING_CONSOLIDATIONS_LIMIT:
|
||||||
|
// return
|
||||||
|
// # If there is too little available consolidation churn limit, consolidation requests are ignored
|
||||||
|
// if get_consolidation_churn_limit(state) <= MIN_ACTIVATION_BALANCE:
|
||||||
|
// return
|
||||||
|
//
|
||||||
|
// validator_pubkeys = [v.pubkey for v in state.validators]
|
||||||
|
// # Verify pubkeys exists
|
||||||
|
// request_source_pubkey = consolidation_request.source_pubkey
|
||||||
|
// request_target_pubkey = consolidation_request.target_pubkey
|
||||||
|
// if request_source_pubkey not in validator_pubkeys:
|
||||||
|
// return
|
||||||
|
// if request_target_pubkey not in validator_pubkeys:
|
||||||
|
// return
|
||||||
|
// source_index = ValidatorIndex(validator_pubkeys.index(request_source_pubkey))
|
||||||
|
// target_index = ValidatorIndex(validator_pubkeys.index(request_target_pubkey))
|
||||||
|
// source_validator = state.validators[source_index]
|
||||||
|
// target_validator = state.validators[target_index]
|
||||||
|
//
|
||||||
|
// # Verify source withdrawal credentials
|
||||||
|
// has_correct_credential = has_execution_withdrawal_credential(source_validator)
|
||||||
|
// is_correct_source_address = (
|
||||||
|
// source_validator.withdrawal_credentials[12:] == consolidation_request.source_address
|
||||||
|
// )
|
||||||
|
// if not (has_correct_credential and is_correct_source_address):
|
||||||
|
// return
|
||||||
|
//
|
||||||
|
// # Verify that target has compounding withdrawal credentials
|
||||||
|
// if not has_compounding_withdrawal_credential(target_validator):
|
||||||
|
// return
|
||||||
|
//
|
||||||
|
// # Verify the source and the target are active
|
||||||
|
// current_epoch = get_current_epoch(state)
|
||||||
|
// if not is_active_validator(source_validator, current_epoch):
|
||||||
|
// return
|
||||||
|
// if not is_active_validator(target_validator, current_epoch):
|
||||||
|
// return
|
||||||
|
// # Verify exits for source and target have not been initiated
|
||||||
|
// if source_validator.exit_epoch != FAR_FUTURE_EPOCH:
|
||||||
|
// return
|
||||||
|
// if target_validator.exit_epoch != FAR_FUTURE_EPOCH:
|
||||||
|
// return
|
||||||
|
//
|
||||||
|
// # Verify the source has been active long enough
|
||||||
|
// if current_epoch < source_validator.activation_epoch + SHARD_COMMITTEE_PERIOD:
|
||||||
|
// return
|
||||||
|
//
|
||||||
|
// # Verify the source has no pending withdrawals in the queue
|
||||||
|
// if get_pending_balance_to_withdraw(state, source_index) > 0:
|
||||||
|
// return
|
||||||
|
// # Initiate source validator exit and append pending consolidation
|
||||||
|
// source_validator.exit_epoch = compute_consolidation_epoch_and_update_churn(
|
||||||
|
// state, source_validator.effective_balance
|
||||||
|
// )
|
||||||
|
// source_validator.withdrawable_epoch = Epoch(
|
||||||
|
// source_validator.exit_epoch + MIN_VALIDATOR_WITHDRAWABILITY_DELAY
|
||||||
|
// )
|
||||||
|
// state.pending_consolidations.append(PendingConsolidation(
|
||||||
|
// source_index=source_index,
|
||||||
|
// target_index=target_index
|
||||||
|
// ))
|
||||||
|
func ProcessConsolidationRequests(ctx context.Context, st state.BeaconState, reqs []*enginev1.ConsolidationRequest) error {
|
||||||
|
ctx, span := trace.StartSpan(ctx, "requests.ProcessConsolidationRequests")
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
|
if len(reqs) == 0 || st == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
curEpoch := slots.ToEpoch(st.Slot())
|
||||||
|
ffe := params.BeaconConfig().FarFutureEpoch
|
||||||
|
minValWithdrawDelay := params.BeaconConfig().MinValidatorWithdrawabilityDelay
|
||||||
|
pcLimit := params.BeaconConfig().PendingConsolidationsLimit
|
||||||
|
|
||||||
|
for _, cr := range reqs {
|
||||||
|
if cr == nil {
|
||||||
|
return errors.New("nil consolidation request")
|
||||||
|
}
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
return fmt.Errorf("cannot process consolidation requests: %w", ctx.Err())
|
||||||
|
}
|
||||||
|
|
||||||
|
if isValidSwitchToCompoundingRequest(st, cr) {
|
||||||
|
srcIdx, ok := st.ValidatorIndexByPubkey(bytesutil.ToBytes48(cr.SourcePubkey))
|
||||||
|
if !ok {
|
||||||
|
log.Error("Failed to find source validator index")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if err := switchToCompoundingValidator(st, srcIdx); err != nil {
|
||||||
|
log.WithError(err).Error("Failed to switch to compounding validator")
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
sourcePubkey := bytesutil.ToBytes48(cr.SourcePubkey)
|
||||||
|
targetPubkey := bytesutil.ToBytes48(cr.TargetPubkey)
|
||||||
|
if sourcePubkey == targetPubkey {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
if npc, err := st.NumPendingConsolidations(); err != nil {
|
||||||
|
return fmt.Errorf("failed to fetch number of pending consolidations: %w", err) // This should never happen.
|
||||||
|
} else if npc >= pcLimit {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
activeBal, err := helpers.TotalActiveBalance(st)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
churnLimit := helpers.ConsolidationChurnLimit(primitives.Gwei(activeBal))
|
||||||
|
if churnLimit <= primitives.Gwei(params.BeaconConfig().MinActivationBalance) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
srcIdx, ok := st.ValidatorIndexByPubkey(sourcePubkey)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
tgtIdx, ok := st.ValidatorIndexByPubkey(targetPubkey)
|
||||||
|
if !ok {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
srcV, err := st.ValidatorAtIndex(srcIdx)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to fetch source validator: %w", err) // This should never happen.
|
||||||
|
}
|
||||||
|
|
||||||
|
roSrcV, err := state_native.NewValidator(srcV)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
tgtV, err := st.ValidatorAtIndexReadOnly(tgtIdx)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to fetch target validator: %w", err) // This should never happen.
|
||||||
|
}
|
||||||
|
|
||||||
|
// Verify source withdrawal credentials.
|
||||||
|
if !roSrcV.HasExecutionWithdrawalCredentials() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Confirm source_validator.withdrawal_credentials[12:] == consolidation_request.source_address.
|
||||||
|
if len(srcV.WithdrawalCredentials) != 32 || len(cr.SourceAddress) != 20 || !bytes.HasSuffix(srcV.WithdrawalCredentials, cr.SourceAddress) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Target validator must have their withdrawal credentials set appropriately.
|
||||||
|
if !tgtV.HasCompoundingWithdrawalCredentials() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Both validators must be active.
|
||||||
|
if !helpers.IsActiveValidator(srcV, curEpoch) || !helpers.IsActiveValidatorUsingTrie(tgtV, curEpoch) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Neither validator is exiting.
|
||||||
|
if srcV.ExitEpoch != ffe || tgtV.ExitEpoch() != ffe {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
e, overflow := math.SafeAdd(uint64(srcV.ActivationEpoch), uint64(params.BeaconConfig().ShardCommitteePeriod))
|
||||||
|
if overflow {
|
||||||
|
log.Error("Overflow when adding activation epoch and shard committee period")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if uint64(curEpoch) < e {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
hasBal, err := st.HasPendingBalanceToWithdraw(srcIdx)
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err).Error("Failed to fetch pending balance to withdraw")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if hasBal {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
exitEpoch, err := computeConsolidationEpochAndUpdateChurn(st, primitives.Gwei(srcV.EffectiveBalance))
|
||||||
|
if err != nil {
|
||||||
|
log.WithError(err).Error("Failed to compute consolidation epoch")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
srcV.ExitEpoch = exitEpoch
|
||||||
|
srcV.WithdrawableEpoch = exitEpoch + minValWithdrawDelay
|
||||||
|
if err := st.UpdateValidatorAtIndex(srcIdx, srcV); err != nil {
|
||||||
|
return fmt.Errorf("failed to update validator: %w", err) // This should never happen.
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := st.AppendPendingConsolidation(ð.PendingConsolidation{SourceIndex: srcIdx, TargetIndex: tgtIdx}); err != nil {
|
||||||
|
return fmt.Errorf("failed to append pending consolidation: %w", err) // This should never happen.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func isValidSwitchToCompoundingRequest(st state.BeaconState, req *enginev1.ConsolidationRequest) bool {
|
||||||
|
if req.SourcePubkey == nil || req.TargetPubkey == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if !bytes.Equal(req.SourcePubkey, req.TargetPubkey) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
srcIdx, ok := st.ValidatorIndexByPubkey(bytesutil.ToBytes48(req.SourcePubkey))
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
srcV, err := st.ValidatorAtIndexReadOnly(srcIdx)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
sourceAddress := req.SourceAddress
|
||||||
|
withdrawalCreds := srcV.GetWithdrawalCredentials()
|
||||||
|
if len(withdrawalCreds) != 32 || len(sourceAddress) != 20 || !bytes.HasSuffix(withdrawalCreds, sourceAddress) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if !srcV.HasETH1WithdrawalCredentials() {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
curEpoch := slots.ToEpoch(st.Slot())
|
||||||
|
if !helpers.IsActiveValidatorUsingTrie(srcV, curEpoch) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if srcV.ExitEpoch() != params.BeaconConfig().FarFutureEpoch {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
func switchToCompoundingValidator(st state.BeaconState, idx primitives.ValidatorIndex) error {
|
||||||
|
v, err := st.ValidatorAtIndex(idx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if len(v.WithdrawalCredentials) == 0 {
|
||||||
|
return errors.New("validator has no withdrawal credentials")
|
||||||
|
}
|
||||||
|
|
||||||
|
v.WithdrawalCredentials[0] = params.BeaconConfig().CompoundingWithdrawalPrefixByte
|
||||||
|
if err := st.UpdateValidatorAtIndex(idx, v); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return queueExcessActiveBalance(st, idx)
|
||||||
|
}
|
||||||
|
|
||||||
|
func queueExcessActiveBalance(st state.BeaconState, idx primitives.ValidatorIndex) error {
|
||||||
|
bal, err := st.BalanceAtIndex(idx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
if bal > params.BeaconConfig().MinActivationBalance {
|
||||||
|
if err := st.UpdateBalancesAtIndex(idx, params.BeaconConfig().MinActivationBalance); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
excessBalance := bal - params.BeaconConfig().MinActivationBalance
|
||||||
|
val, err := st.ValidatorAtIndexReadOnly(idx)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
pk := val.PublicKey()
|
||||||
|
return st.AppendPendingDeposit(ð.PendingDeposit{
|
||||||
|
PublicKey: pk[:],
|
||||||
|
WithdrawalCredentials: val.GetWithdrawalCredentials(),
|
||||||
|
Amount: excessBalance,
|
||||||
|
Signature: common.InfiniteSignature[:],
|
||||||
|
Slot: params.BeaconConfig().GenesisSlot,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func computeConsolidationEpochAndUpdateChurn(st state.BeaconState, consolidationBalance primitives.Gwei) (primitives.Epoch, error) {
|
||||||
|
earliestEpoch, err := st.EarliestConsolidationEpoch()
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
earliestConsolidationEpoch := max(earliestEpoch, helpers.ActivationExitEpoch(slots.ToEpoch(st.Slot())))
|
||||||
|
|
||||||
|
activeBal, err := helpers.TotalActiveBalance(st)
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
perEpochConsolidationChurn := helpers.ConsolidationChurnLimit(primitives.Gwei(activeBal))
|
||||||
|
|
||||||
|
var consolidationBalanceToConsume primitives.Gwei
|
||||||
|
if earliestEpoch < earliestConsolidationEpoch {
|
||||||
|
consolidationBalanceToConsume = perEpochConsolidationChurn
|
||||||
|
} else {
|
||||||
|
consolidationBalanceToConsume, err = st.ConsolidationBalanceToConsume()
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if consolidationBalance > consolidationBalanceToConsume {
|
||||||
|
balanceToProcess := consolidationBalance - consolidationBalanceToConsume
|
||||||
|
additionalEpochs, err := prysmMath.Div64(uint64(balanceToProcess-1), uint64(perEpochConsolidationChurn))
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
additionalEpochs++
|
||||||
|
earliestConsolidationEpoch += primitives.Epoch(additionalEpochs)
|
||||||
|
consolidationBalanceToConsume += primitives.Gwei(additionalEpochs) * perEpochConsolidationChurn
|
||||||
|
}
|
||||||
|
|
||||||
|
if err := st.SetConsolidationBalanceToConsume(consolidationBalanceToConsume - consolidationBalance); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
if err := st.SetEarliestConsolidationEpoch(earliestConsolidationEpoch); err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return earliestConsolidationEpoch, nil
|
||||||
|
}
|
||||||
316
beacon-chain/core/requests/consolidations_test.go
Normal file
316
beacon-chain/core/requests/consolidations_test.go
Normal file
@@ -0,0 +1,316 @@
|
|||||||
|
package requests_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/requests"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/state"
|
||||||
|
state_native "github.com/OffchainLabs/prysm/v7/beacon-chain/state/state-native"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/config/params"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/encoding/bytesutil"
|
||||||
|
enginev1 "github.com/OffchainLabs/prysm/v7/proto/engine/v1"
|
||||||
|
eth "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/testing/require"
|
||||||
|
)
|
||||||
|
|
||||||
|
func createValidatorsWithTotalActiveBalance(totalBal primitives.Gwei) []*eth.Validator {
|
||||||
|
num := totalBal / primitives.Gwei(params.BeaconConfig().MinActivationBalance)
|
||||||
|
vals := make([]*eth.Validator, num)
|
||||||
|
for i := range vals {
|
||||||
|
wd := make([]byte, 32)
|
||||||
|
wd[0] = params.BeaconConfig().CompoundingWithdrawalPrefixByte
|
||||||
|
wd[31] = byte(i)
|
||||||
|
|
||||||
|
vals[i] = ð.Validator{
|
||||||
|
ActivationEpoch: primitives.Epoch(0),
|
||||||
|
EffectiveBalance: params.BeaconConfig().MinActivationBalance,
|
||||||
|
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||||
|
PublicKey: fmt.Appendf(nil, "val_%d", i),
|
||||||
|
WithdrawableEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||||
|
WithdrawalCredentials: wd,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if totalBal%primitives.Gwei(params.BeaconConfig().MinActivationBalance) != 0 {
|
||||||
|
vals = append(vals, ð.Validator{
|
||||||
|
ActivationEpoch: primitives.Epoch(0),
|
||||||
|
ExitEpoch: params.BeaconConfig().FarFutureEpoch,
|
||||||
|
EffectiveBalance: uint64(totalBal) % params.BeaconConfig().MinActivationBalance,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
return vals
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestProcessConsolidationRequests(t *testing.T) {
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
state state.BeaconState
|
||||||
|
reqs []*enginev1.ConsolidationRequest
|
||||||
|
validate func(*testing.T, state.BeaconState)
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "nil request",
|
||||||
|
state: func() state.BeaconState {
|
||||||
|
st := ð.BeaconStateElectra{}
|
||||||
|
s, err := state_native.InitializeFromProtoElectra(st)
|
||||||
|
require.NoError(t, err)
|
||||||
|
return s
|
||||||
|
}(),
|
||||||
|
reqs: []*enginev1.ConsolidationRequest{nil},
|
||||||
|
validate: func(t *testing.T, st state.BeaconState) {
|
||||||
|
require.DeepEqual(t, st, st)
|
||||||
|
},
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "one valid request",
|
||||||
|
state: func() state.BeaconState {
|
||||||
|
st := ð.BeaconStateElectra{
|
||||||
|
Slot: params.BeaconConfig().SlotsPerEpoch.Mul(uint64(params.BeaconConfig().ShardCommitteePeriod)),
|
||||||
|
Validators: createValidatorsWithTotalActiveBalance(32000000000000000), // 32M ETH
|
||||||
|
}
|
||||||
|
// Validator scenario setup. See comments in reqs section.
|
||||||
|
st.Validators[3].WithdrawalCredentials = bytesutil.Bytes32(0)
|
||||||
|
st.Validators[8].WithdrawalCredentials = bytesutil.Bytes32(1)
|
||||||
|
st.Validators[9].ActivationEpoch = params.BeaconConfig().FarFutureEpoch
|
||||||
|
st.Validators[12].ActivationEpoch = params.BeaconConfig().FarFutureEpoch
|
||||||
|
st.Validators[13].ExitEpoch = 10
|
||||||
|
st.Validators[16].ExitEpoch = 10
|
||||||
|
st.PendingPartialWithdrawals = []*eth.PendingPartialWithdrawal{
|
||||||
|
{
|
||||||
|
Index: 17,
|
||||||
|
Amount: 100,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
s, err := state_native.InitializeFromProtoElectra(st)
|
||||||
|
require.NoError(t, err)
|
||||||
|
return s
|
||||||
|
}(),
|
||||||
|
reqs: []*enginev1.ConsolidationRequest{
|
||||||
|
// Source doesn't have withdrawal credentials.
|
||||||
|
{
|
||||||
|
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(1)),
|
||||||
|
SourcePubkey: []byte("val_3"),
|
||||||
|
TargetPubkey: []byte("val_4"),
|
||||||
|
},
|
||||||
|
// Source withdrawal credentials don't match the consolidation address.
|
||||||
|
{
|
||||||
|
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(0)), // Should be 5
|
||||||
|
SourcePubkey: []byte("val_5"),
|
||||||
|
TargetPubkey: []byte("val_6"),
|
||||||
|
},
|
||||||
|
// Target does not have their withdrawal credentials set appropriately. (Using eth1 address prefix)
|
||||||
|
{
|
||||||
|
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(7)),
|
||||||
|
SourcePubkey: []byte("val_7"),
|
||||||
|
TargetPubkey: []byte("val_8"),
|
||||||
|
},
|
||||||
|
// Source is inactive.
|
||||||
|
{
|
||||||
|
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(9)),
|
||||||
|
SourcePubkey: []byte("val_9"),
|
||||||
|
TargetPubkey: []byte("val_10"),
|
||||||
|
},
|
||||||
|
// Target is inactive.
|
||||||
|
{
|
||||||
|
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(11)),
|
||||||
|
SourcePubkey: []byte("val_11"),
|
||||||
|
TargetPubkey: []byte("val_12"),
|
||||||
|
},
|
||||||
|
// Source is exiting.
|
||||||
|
{
|
||||||
|
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(13)),
|
||||||
|
SourcePubkey: []byte("val_13"),
|
||||||
|
TargetPubkey: []byte("val_14"),
|
||||||
|
},
|
||||||
|
// Target is exiting.
|
||||||
|
{
|
||||||
|
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(15)),
|
||||||
|
SourcePubkey: []byte("val_15"),
|
||||||
|
TargetPubkey: []byte("val_16"),
|
||||||
|
},
|
||||||
|
// Source doesn't exist
|
||||||
|
{
|
||||||
|
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(0)),
|
||||||
|
SourcePubkey: []byte("INVALID"),
|
||||||
|
TargetPubkey: []byte("val_0"),
|
||||||
|
},
|
||||||
|
// Target doesn't exist
|
||||||
|
{
|
||||||
|
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(0)),
|
||||||
|
SourcePubkey: []byte("val_0"),
|
||||||
|
TargetPubkey: []byte("INVALID"),
|
||||||
|
},
|
||||||
|
// Source == target
|
||||||
|
{
|
||||||
|
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(0)),
|
||||||
|
SourcePubkey: []byte("val_0"),
|
||||||
|
TargetPubkey: []byte("val_0"),
|
||||||
|
},
|
||||||
|
// Has pending partial withdrawal
|
||||||
|
{
|
||||||
|
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(0)),
|
||||||
|
SourcePubkey: []byte("val_17"),
|
||||||
|
TargetPubkey: []byte("val_1"),
|
||||||
|
},
|
||||||
|
// Valid consolidation request. This should be last to ensure invalid requests do
|
||||||
|
// not end the processing early.
|
||||||
|
{
|
||||||
|
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(1)),
|
||||||
|
SourcePubkey: []byte("val_1"),
|
||||||
|
TargetPubkey: []byte("val_2"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
validate: func(t *testing.T, st state.BeaconState) {
|
||||||
|
// Verify a pending consolidation is created.
|
||||||
|
numPC, err := st.NumPendingConsolidations()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, uint64(1), numPC)
|
||||||
|
pcs, err := st.PendingConsolidations()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, primitives.ValidatorIndex(1), pcs[0].SourceIndex)
|
||||||
|
require.Equal(t, primitives.ValidatorIndex(2), pcs[0].TargetIndex)
|
||||||
|
|
||||||
|
// Verify the source validator is exiting.
|
||||||
|
src, err := st.ValidatorAtIndex(1)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NotEqual(t, params.BeaconConfig().FarFutureEpoch, src.ExitEpoch, "source validator exit epoch not updated")
|
||||||
|
require.Equal(t, params.BeaconConfig().MinValidatorWithdrawabilityDelay, src.WithdrawableEpoch-src.ExitEpoch, "source validator withdrawable epoch not set correctly")
|
||||||
|
},
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "pending consolidations limit reached",
|
||||||
|
state: func() state.BeaconState {
|
||||||
|
st := ð.BeaconStateElectra{
|
||||||
|
Validators: createValidatorsWithTotalActiveBalance(32000000000000000), // 32M ETH
|
||||||
|
PendingConsolidations: make([]*eth.PendingConsolidation, params.BeaconConfig().PendingConsolidationsLimit),
|
||||||
|
}
|
||||||
|
s, err := state_native.InitializeFromProtoElectra(st)
|
||||||
|
require.NoError(t, err)
|
||||||
|
return s
|
||||||
|
}(),
|
||||||
|
reqs: []*enginev1.ConsolidationRequest{
|
||||||
|
{
|
||||||
|
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(1)),
|
||||||
|
SourcePubkey: []byte("val_1"),
|
||||||
|
TargetPubkey: []byte("val_2"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
validate: func(t *testing.T, st state.BeaconState) {
|
||||||
|
// Verify no pending consolidation is created.
|
||||||
|
numPC, err := st.NumPendingConsolidations()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, params.BeaconConfig().PendingConsolidationsLimit, numPC)
|
||||||
|
|
||||||
|
// Verify the source validator is not exiting.
|
||||||
|
src, err := st.ValidatorAtIndex(1)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, params.BeaconConfig().FarFutureEpoch, src.ExitEpoch, "source validator exit epoch should not be updated")
|
||||||
|
require.Equal(t, params.BeaconConfig().FarFutureEpoch, src.WithdrawableEpoch, "source validator withdrawable epoch should not be updated")
|
||||||
|
},
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "pending consolidations limit reached during processing",
|
||||||
|
state: func() state.BeaconState {
|
||||||
|
st := ð.BeaconStateElectra{
|
||||||
|
Slot: params.BeaconConfig().SlotsPerEpoch.Mul(uint64(params.BeaconConfig().ShardCommitteePeriod)),
|
||||||
|
Validators: createValidatorsWithTotalActiveBalance(32000000000000000), // 32M ETH
|
||||||
|
PendingConsolidations: make([]*eth.PendingConsolidation, params.BeaconConfig().PendingConsolidationsLimit-1),
|
||||||
|
}
|
||||||
|
s, err := state_native.InitializeFromProtoElectra(st)
|
||||||
|
require.NoError(t, err)
|
||||||
|
return s
|
||||||
|
}(),
|
||||||
|
reqs: []*enginev1.ConsolidationRequest{
|
||||||
|
{
|
||||||
|
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(1)),
|
||||||
|
SourcePubkey: []byte("val_1"),
|
||||||
|
TargetPubkey: []byte("val_2"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(3)),
|
||||||
|
SourcePubkey: []byte("val_3"),
|
||||||
|
TargetPubkey: []byte("val_4"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
validate: func(t *testing.T, st state.BeaconState) {
|
||||||
|
// Verify a pending consolidation is created.
|
||||||
|
numPC, err := st.NumPendingConsolidations()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, params.BeaconConfig().PendingConsolidationsLimit, numPC)
|
||||||
|
|
||||||
|
// The first consolidation was appended.
|
||||||
|
pcs, err := st.PendingConsolidations()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, primitives.ValidatorIndex(1), pcs[params.BeaconConfig().PendingConsolidationsLimit-1].SourceIndex)
|
||||||
|
require.Equal(t, primitives.ValidatorIndex(2), pcs[params.BeaconConfig().PendingConsolidationsLimit-1].TargetIndex)
|
||||||
|
|
||||||
|
// Verify the second source validator is not exiting.
|
||||||
|
src, err := st.ValidatorAtIndex(3)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, params.BeaconConfig().FarFutureEpoch, src.ExitEpoch, "source validator exit epoch should not be updated")
|
||||||
|
require.Equal(t, params.BeaconConfig().FarFutureEpoch, src.WithdrawableEpoch, "source validator withdrawable epoch should not be updated")
|
||||||
|
},
|
||||||
|
wantErr: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "pending consolidations limit reached and compounded consolidation after",
|
||||||
|
state: func() state.BeaconState {
|
||||||
|
st := ð.BeaconStateElectra{
|
||||||
|
Slot: params.BeaconConfig().SlotsPerEpoch.Mul(uint64(params.BeaconConfig().ShardCommitteePeriod)),
|
||||||
|
Validators: createValidatorsWithTotalActiveBalance(32000000000000000), // 32M ETH
|
||||||
|
PendingConsolidations: make([]*eth.PendingConsolidation, params.BeaconConfig().PendingConsolidationsLimit),
|
||||||
|
}
|
||||||
|
// To allow compounding consolidation requests.
|
||||||
|
st.Validators[3].WithdrawalCredentials[0] = params.BeaconConfig().ETH1AddressWithdrawalPrefixByte
|
||||||
|
s, err := state_native.InitializeFromProtoElectra(st)
|
||||||
|
require.NoError(t, err)
|
||||||
|
return s
|
||||||
|
}(),
|
||||||
|
reqs: []*enginev1.ConsolidationRequest{
|
||||||
|
{
|
||||||
|
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(1)),
|
||||||
|
SourcePubkey: []byte("val_1"),
|
||||||
|
TargetPubkey: []byte("val_2"),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
SourceAddress: append(bytesutil.PadTo(nil, 19), byte(3)),
|
||||||
|
SourcePubkey: []byte("val_3"),
|
||||||
|
TargetPubkey: []byte("val_3"),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
validate: func(t *testing.T, st state.BeaconState) {
|
||||||
|
// Verify a pending consolidation is created.
|
||||||
|
numPC, err := st.NumPendingConsolidations()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, params.BeaconConfig().PendingConsolidationsLimit, numPC)
|
||||||
|
|
||||||
|
// Verify that the last consolidation was included
|
||||||
|
src, err := st.ValidatorAtIndex(3)
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, params.BeaconConfig().CompoundingWithdrawalPrefixByte, src.WithdrawalCredentials[0], "source validator was not compounded")
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
err := requests.ProcessConsolidationRequests(context.TODO(), tt.state, tt.reqs)
|
||||||
|
if (err != nil) != tt.wantErr {
|
||||||
|
t.Errorf("ProcessWithdrawalRequests() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if !tt.wantErr {
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
if tt.validate != nil {
|
||||||
|
tt.validate(t, tt.state)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
73
beacon-chain/core/requests/deposits.go
Normal file
73
beacon-chain/core/requests/deposits.go
Normal file
@@ -0,0 +1,73 @@
|
|||||||
|
package requests
|
||||||
|
|
||||||
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/state"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/config/params"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/encoding/bytesutil"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/monitoring/tracing/trace"
|
||||||
|
enginev1 "github.com/OffchainLabs/prysm/v7/proto/engine/v1"
|
||||||
|
ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ProcessDepositRequests processes execution layer deposits requests.
|
||||||
|
func ProcessDepositRequests(ctx context.Context, beaconState state.BeaconState, reqs []*enginev1.DepositRequest) (state.BeaconState, error) {
|
||||||
|
_, span := trace.StartSpan(ctx, "requests.ProcessDepositRequests")
|
||||||
|
defer span.End()
|
||||||
|
|
||||||
|
if len(reqs) == 0 {
|
||||||
|
return beaconState, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var err error
|
||||||
|
for _, req := range reqs {
|
||||||
|
beaconState, err = processDepositRequest(beaconState, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "could not apply deposit request")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return beaconState, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// processDepositRequest processes the specific deposit request
|
||||||
|
//
|
||||||
|
// def process_deposit_request(state: BeaconState, deposit_request: DepositRequest) -> None:
|
||||||
|
//
|
||||||
|
// # Set deposit request start index
|
||||||
|
// if state.deposit_requests_start_index == UNSET_DEPOSIT_REQUESTS_START_INDEX:
|
||||||
|
// state.deposit_requests_start_index = deposit_request.index
|
||||||
|
//
|
||||||
|
// # Create pending deposit
|
||||||
|
// state.pending_deposits.append(PendingDeposit(
|
||||||
|
// pubkey=deposit_request.pubkey,
|
||||||
|
// withdrawal_credentials=deposit_request.withdrawal_credentials,
|
||||||
|
// amount=deposit_request.amount,
|
||||||
|
// signature=deposit_request.signature,
|
||||||
|
// slot=state.slot,
|
||||||
|
// ))
|
||||||
|
func processDepositRequest(beaconState state.BeaconState, req *enginev1.DepositRequest) (state.BeaconState, error) {
|
||||||
|
requestsStartIndex, err := beaconState.DepositRequestsStartIndex()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrap(err, "could not get deposit requests start index")
|
||||||
|
}
|
||||||
|
if req == nil {
|
||||||
|
return nil, errors.New("nil deposit request")
|
||||||
|
}
|
||||||
|
if requestsStartIndex == params.BeaconConfig().UnsetDepositRequestsStartIndex {
|
||||||
|
if err := beaconState.SetDepositRequestsStartIndex(req.Index); err != nil {
|
||||||
|
return nil, errors.Wrap(err, "could not set deposit requests start index")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := beaconState.AppendPendingDeposit(ðpb.PendingDeposit{
|
||||||
|
PublicKey: bytesutil.SafeCopyBytes(req.Pubkey),
|
||||||
|
WithdrawalCredentials: bytesutil.SafeCopyBytes(req.WithdrawalCredentials),
|
||||||
|
Amount: req.Amount,
|
||||||
|
Signature: bytesutil.SafeCopyBytes(req.Signature),
|
||||||
|
Slot: beaconState.Slot(),
|
||||||
|
}); err != nil {
|
||||||
|
return nil, errors.Wrap(err, "could not append deposit request")
|
||||||
|
}
|
||||||
|
return beaconState, nil
|
||||||
|
}
|
||||||
70
beacon-chain/core/requests/deposits_test.go
Normal file
70
beacon-chain/core/requests/deposits_test.go
Normal file
@@ -0,0 +1,70 @@
|
|||||||
|
package requests_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/requests"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/signing"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/config/params"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/crypto/bls"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/encoding/bytesutil"
|
||||||
|
enginev1 "github.com/OffchainLabs/prysm/v7/proto/engine/v1"
|
||||||
|
eth "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/testing/require"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/testing/util"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestProcessDepositRequests(t *testing.T) {
|
||||||
|
st, _ := util.DeterministicGenesisStateElectra(t, 1)
|
||||||
|
sk, err := bls.RandKey()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.NoError(t, st.SetDepositRequestsStartIndex(1))
|
||||||
|
|
||||||
|
t.Run("empty requests continues", func(t *testing.T) {
|
||||||
|
newSt, err := requests.ProcessDepositRequests(t.Context(), st, []*enginev1.DepositRequest{})
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.DeepEqual(t, newSt, st)
|
||||||
|
})
|
||||||
|
t.Run("nil request errors", func(t *testing.T) {
|
||||||
|
_, err = requests.ProcessDepositRequests(t.Context(), st, []*enginev1.DepositRequest{nil})
|
||||||
|
require.ErrorContains(t, "nil deposit request", err)
|
||||||
|
})
|
||||||
|
|
||||||
|
vals := st.Validators()
|
||||||
|
vals[0].PublicKey = sk.PublicKey().Marshal()
|
||||||
|
vals[0].WithdrawalCredentials[0] = params.BeaconConfig().ETH1AddressWithdrawalPrefixByte
|
||||||
|
require.NoError(t, st.SetValidators(vals))
|
||||||
|
bals := st.Balances()
|
||||||
|
bals[0] = params.BeaconConfig().MinActivationBalance + 2000
|
||||||
|
require.NoError(t, st.SetBalances(bals))
|
||||||
|
require.NoError(t, st.SetPendingDeposits(make([]*eth.PendingDeposit, 0))) // reset pbd as the deterministic state populates this already
|
||||||
|
withdrawalCred := make([]byte, 32)
|
||||||
|
withdrawalCred[0] = params.BeaconConfig().CompoundingWithdrawalPrefixByte
|
||||||
|
depositMessage := ð.DepositMessage{
|
||||||
|
PublicKey: sk.PublicKey().Marshal(),
|
||||||
|
Amount: 1000,
|
||||||
|
WithdrawalCredentials: withdrawalCred,
|
||||||
|
}
|
||||||
|
domain, err := signing.ComputeDomain(params.BeaconConfig().DomainDeposit, nil, nil)
|
||||||
|
require.NoError(t, err)
|
||||||
|
sr, err := signing.ComputeSigningRoot(depositMessage, domain)
|
||||||
|
require.NoError(t, err)
|
||||||
|
sig := sk.Sign(sr[:])
|
||||||
|
reqs := []*enginev1.DepositRequest{
|
||||||
|
{
|
||||||
|
Pubkey: depositMessage.PublicKey,
|
||||||
|
Index: 0,
|
||||||
|
WithdrawalCredentials: depositMessage.WithdrawalCredentials,
|
||||||
|
Amount: depositMessage.Amount,
|
||||||
|
Signature: sig.Marshal(),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
st, err = requests.ProcessDepositRequests(t.Context(), st, reqs)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
pbd, err := st.PendingDeposits()
|
||||||
|
require.NoError(t, err)
|
||||||
|
require.Equal(t, 1, len(pbd))
|
||||||
|
require.Equal(t, uint64(1000), pbd[0].Amount)
|
||||||
|
require.DeepEqual(t, bytesutil.SafeCopyBytes(reqs[0].Pubkey), pbd[0].PublicKey)
|
||||||
|
}
|
||||||
9
beacon-chain/core/requests/log.go
Normal file
9
beacon-chain/core/requests/log.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
// Code generated by hack/gen-logs.sh; DO NOT EDIT.
|
||||||
|
// This file is created and regenerated automatically. Anything added here might get removed.
|
||||||
|
package requests
|
||||||
|
|
||||||
|
import "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
// The prefix for logs from this package will be the text after the last slash in the package path.
|
||||||
|
// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file.
|
||||||
|
var log = logrus.WithField("package", "beacon-chain/core/requests")
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package electra
|
package requests
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@@ -88,7 +88,7 @@ import (
|
|||||||
// withdrawable_epoch=withdrawable_epoch,
|
// withdrawable_epoch=withdrawable_epoch,
|
||||||
// ))
|
// ))
|
||||||
func ProcessWithdrawalRequests(ctx context.Context, st state.BeaconState, wrs []*enginev1.WithdrawalRequest) (state.BeaconState, error) {
|
func ProcessWithdrawalRequests(ctx context.Context, st state.BeaconState, wrs []*enginev1.WithdrawalRequest) (state.BeaconState, error) {
|
||||||
ctx, span := trace.StartSpan(ctx, "electra.ProcessWithdrawalRequests")
|
ctx, span := trace.StartSpan(ctx, "requests.ProcessWithdrawalRequests")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
currentEpoch := slots.ToEpoch(st.Slot())
|
currentEpoch := slots.ToEpoch(st.Slot())
|
||||||
if len(wrs) == 0 {
|
if len(wrs) == 0 {
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package electra_test
|
package requests_test
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/electra"
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/requests"
|
||||||
"github.com/OffchainLabs/prysm/v7/beacon-chain/state"
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/state"
|
||||||
"github.com/OffchainLabs/prysm/v7/config/params"
|
"github.com/OffchainLabs/prysm/v7/config/params"
|
||||||
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
||||||
@@ -289,7 +289,7 @@ func TestProcessWithdrawRequests(t *testing.T) {
|
|||||||
for _, tt := range tests {
|
for _, tt := range tests {
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
|
||||||
got, err := electra.ProcessWithdrawalRequests(t.Context(), tt.args.st, tt.args.wrs)
|
got, err := requests.ProcessWithdrawalRequests(t.Context(), tt.args.st, tt.args.wrs)
|
||||||
if (err != nil) != tt.wantErr {
|
if (err != nil) != tt.wantErr {
|
||||||
t.Errorf("ProcessWithdrawalRequests() error = %v, wantErr %v", err, tt.wantErr)
|
t.Errorf("ProcessWithdrawalRequests() error = %v, wantErr %v", err, tt.wantErr)
|
||||||
return
|
return
|
||||||
@@ -27,6 +27,7 @@ go_library(
|
|||||||
"//beacon-chain/core/execution:go_default_library",
|
"//beacon-chain/core/execution:go_default_library",
|
||||||
"//beacon-chain/core/fulu:go_default_library",
|
"//beacon-chain/core/fulu:go_default_library",
|
||||||
"//beacon-chain/core/helpers:go_default_library",
|
"//beacon-chain/core/helpers:go_default_library",
|
||||||
|
"//beacon-chain/core/requests:go_default_library",
|
||||||
"//beacon-chain/core/time:go_default_library",
|
"//beacon-chain/core/time:go_default_library",
|
||||||
"//beacon-chain/core/transition/interop:go_default_library",
|
"//beacon-chain/core/transition/interop:go_default_library",
|
||||||
"//beacon-chain/core/validators:go_default_library",
|
"//beacon-chain/core/validators:go_default_library",
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/blocks"
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/blocks"
|
||||||
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/electra"
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/electra"
|
||||||
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/helpers"
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/helpers"
|
||||||
|
coreRequests "github.com/OffchainLabs/prysm/v7/beacon-chain/core/requests"
|
||||||
v "github.com/OffchainLabs/prysm/v7/beacon-chain/core/validators"
|
v "github.com/OffchainLabs/prysm/v7/beacon-chain/core/validators"
|
||||||
"github.com/OffchainLabs/prysm/v7/beacon-chain/state"
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/state"
|
||||||
"github.com/OffchainLabs/prysm/v7/consensus-types/interfaces"
|
"github.com/OffchainLabs/prysm/v7/consensus-types/interfaces"
|
||||||
@@ -97,7 +98,7 @@ func electraOperations(ctx context.Context, st state.BeaconState, block interfac
|
|||||||
return nil, electra.NewExecReqError("nil deposit request")
|
return nil, electra.NewExecReqError("nil deposit request")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
st, err = electra.ProcessDepositRequests(ctx, st, requests.Deposits)
|
st, err = coreRequests.ProcessDepositRequests(ctx, st, requests.Deposits)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, electra.NewExecReqError(errors.Wrap(err, "could not process deposit requests").Error())
|
return nil, electra.NewExecReqError(errors.Wrap(err, "could not process deposit requests").Error())
|
||||||
}
|
}
|
||||||
@@ -107,7 +108,7 @@ func electraOperations(ctx context.Context, st state.BeaconState, block interfac
|
|||||||
return nil, electra.NewExecReqError("nil withdrawal request")
|
return nil, electra.NewExecReqError("nil withdrawal request")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
st, err = electra.ProcessWithdrawalRequests(ctx, st, requests.Withdrawals)
|
st, err = coreRequests.ProcessWithdrawalRequests(ctx, st, requests.Withdrawals)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, electra.NewExecReqError(errors.Wrap(err, "could not process withdrawal requests").Error())
|
return nil, electra.NewExecReqError(errors.Wrap(err, "could not process withdrawal requests").Error())
|
||||||
}
|
}
|
||||||
@@ -116,7 +117,7 @@ func electraOperations(ctx context.Context, st state.BeaconState, block interfac
|
|||||||
return nil, electra.NewExecReqError("nil consolidation request")
|
return nil, electra.NewExecReqError("nil consolidation request")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if err := electra.ProcessConsolidationRequests(ctx, st, requests.Consolidations); err != nil {
|
if err := coreRequests.ProcessConsolidationRequests(ctx, st, requests.Consolidations); err != nil {
|
||||||
return nil, electra.NewExecReqError(errors.Wrap(err, "could not process consolidation requests").Error())
|
return nil, electra.NewExecReqError(errors.Wrap(err, "could not process consolidation requests").Error())
|
||||||
}
|
}
|
||||||
return st, nil
|
return st, nil
|
||||||
|
|||||||
@@ -67,7 +67,6 @@ func getSubscriptionStatusFromDB(t *testing.T, db *Store) bool {
|
|||||||
return subscribed
|
return subscribed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
func TestUpdateCustodyInfo(t *testing.T) {
|
func TestUpdateCustodyInfo(t *testing.T) {
|
||||||
ctx := t.Context()
|
ctx := t.Context()
|
||||||
|
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ var ErrNotFoundFeeRecipient = errors.Wrap(ErrNotFound, "fee recipient")
|
|||||||
// ErrNotFoundMetadataSeqNum is a not found error specifically for the metadata sequence number getter
|
// ErrNotFoundMetadataSeqNum is a not found error specifically for the metadata sequence number getter
|
||||||
var ErrNotFoundMetadataSeqNum = errors.Wrap(ErrNotFound, "metadata sequence number")
|
var ErrNotFoundMetadataSeqNum = errors.Wrap(ErrNotFound, "metadata sequence number")
|
||||||
|
|
||||||
|
// ErrStateDiffIncompatible is returned when state-diff feature is enabled
|
||||||
|
// but the database was created without state-diff support.
|
||||||
|
var ErrStateDiffIncompatible = errors.New("state-diff feature enabled but database was created without state-diff support")
|
||||||
|
|
||||||
var errEmptyBlockSlice = errors.New("[]blocks.ROBlock is empty")
|
var errEmptyBlockSlice = errors.New("[]blocks.ROBlock is empty")
|
||||||
var errIncorrectBlockParent = errors.New("unexpected missing or forked blocks in a []ROBlock")
|
var errIncorrectBlockParent = errors.New("unexpected missing or forked blocks in a []ROBlock")
|
||||||
var errFinalizedChildNotFound = errors.New("unable to find finalized root descending from backfill batch")
|
var errFinalizedChildNotFound = errors.New("unable to find finalized root descending from backfill batch")
|
||||||
|
|||||||
@@ -42,6 +42,10 @@ func (s *Store) SaveGenesisData(ctx context.Context, genesisState state.BeaconSt
|
|||||||
if err := s.SaveGenesisBlockRoot(ctx, genesisBlkRoot); err != nil {
|
if err := s.SaveGenesisBlockRoot(ctx, genesisBlkRoot); err != nil {
|
||||||
return errors.Wrap(err, "could not save genesis block root")
|
return errors.Wrap(err, "could not save genesis block root")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if err := s.initializeStateDiff(0, genesisState); err != nil {
|
||||||
|
return errors.Wrap(err, "failed to initialize state diff for genesis")
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -203,15 +203,45 @@ func NewKVStore(ctx context.Context, dirPath string, opts ...KVStoreOption) (*St
|
|||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
if features.Get().EnableStateDiff {
|
if err := kv.startStateDiff(ctx); err != nil {
|
||||||
sdCache, err := newStateDiffCache(kv)
|
if errors.Is(err, ErrStateDiffIncompatible) {
|
||||||
if err != nil {
|
return kv, err
|
||||||
return nil, err
|
|
||||||
}
|
}
|
||||||
kv.stateDiffCache = sdCache
|
return nil, err
|
||||||
|
}
|
||||||
|
return kv, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (kv *Store) startStateDiff(ctx context.Context) error {
|
||||||
|
if !features.Get().EnableStateDiff {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
// Check if offset already exists (existing state-diff database).
|
||||||
|
hasOffset, err := kv.hasStateDiffOffset()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return kv, nil
|
if hasOffset {
|
||||||
|
// Existing state-diff database - restarts not yet supported.
|
||||||
|
return errors.New("restarting with existing state-diff database not yet supported")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if this is a new database (no head block).
|
||||||
|
headBlock, err := kv.HeadBlock(ctx)
|
||||||
|
if err != nil {
|
||||||
|
return errors.Wrap(err, "could not get head block")
|
||||||
|
}
|
||||||
|
|
||||||
|
if headBlock == nil {
|
||||||
|
// New database - will be initialized later during checkpoint/genesis sync.
|
||||||
|
// stateDiffCache stays nil until SaveOrigin or SaveGenesisData initializes it.
|
||||||
|
log.Info("State-diff enabled: will be initialized during checkpoint or genesis sync")
|
||||||
|
} else {
|
||||||
|
// Existing database without state-diff - return store with error for caller to handle.
|
||||||
|
return ErrStateDiffIncompatible
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ClearDB removes the previously stored database in the data directory.
|
// ClearDB removes the previously stored database in the data directory.
|
||||||
|
|||||||
@@ -9,11 +9,13 @@ import (
|
|||||||
"github.com/OffchainLabs/prysm/v7/beacon-chain/state"
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/state"
|
||||||
statenative "github.com/OffchainLabs/prysm/v7/beacon-chain/state/state-native"
|
statenative "github.com/OffchainLabs/prysm/v7/beacon-chain/state/state-native"
|
||||||
"github.com/OffchainLabs/prysm/v7/cmd/beacon-chain/flags"
|
"github.com/OffchainLabs/prysm/v7/cmd/beacon-chain/flags"
|
||||||
|
"github.com/OffchainLabs/prysm/v7/config/features"
|
||||||
"github.com/OffchainLabs/prysm/v7/consensus-types/hdiff"
|
"github.com/OffchainLabs/prysm/v7/consensus-types/hdiff"
|
||||||
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
||||||
"github.com/OffchainLabs/prysm/v7/math"
|
"github.com/OffchainLabs/prysm/v7/math"
|
||||||
ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
||||||
"github.com/OffchainLabs/prysm/v7/runtime/version"
|
"github.com/OffchainLabs/prysm/v7/runtime/version"
|
||||||
|
pkgerrors "github.com/pkg/errors"
|
||||||
"go.etcd.io/bbolt"
|
"go.etcd.io/bbolt"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -122,6 +124,66 @@ func (s *Store) getOffset() uint64 {
|
|||||||
return s.stateDiffCache.getOffset()
|
return s.stateDiffCache.getOffset()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// hasStateDiffOffset checks if the state-diff offset has been set in the database.
|
||||||
|
// This is used to detect if an existing database has state-diff enabled.
|
||||||
|
func (s *Store) hasStateDiffOffset() (bool, error) {
|
||||||
|
var hasOffset bool
|
||||||
|
err := s.db.View(func(tx *bbolt.Tx) error {
|
||||||
|
bucket := tx.Bucket(stateDiffBucket)
|
||||||
|
if bucket == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
hasOffset = bucket.Get(offsetKey) != nil
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
return hasOffset, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// initializeStateDiff sets up the state-diff schema for a new database.
|
||||||
|
// This should be called during checkpoint sync or genesis sync.
|
||||||
|
func (s *Store) initializeStateDiff(slot primitives.Slot, initialState state.ReadOnlyBeaconState) error {
|
||||||
|
// Return early if the feature is not set
|
||||||
|
if !features.Get().EnableStateDiff {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
// Only reinitialize if the offset is different
|
||||||
|
if s.stateDiffCache != nil {
|
||||||
|
if s.stateDiffCache.getOffset() == uint64(slot) {
|
||||||
|
log.WithField("offset", slot).Warning("Ignoring state diff cache reinitialization")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Write offset directly to the database (without using cache which doesn't exist yet).
|
||||||
|
err := s.db.Update(func(tx *bbolt.Tx) error {
|
||||||
|
bucket := tx.Bucket(stateDiffBucket)
|
||||||
|
if bucket == nil {
|
||||||
|
return bbolt.ErrBucketNotFound
|
||||||
|
}
|
||||||
|
|
||||||
|
offsetBytes := make([]byte, 8)
|
||||||
|
binary.LittleEndian.PutUint64(offsetBytes, uint64(slot))
|
||||||
|
return bucket.Put(offsetKey, offsetBytes)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
return pkgerrors.Wrap(err, "failed to set offset")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create the state diff cache (this will read the offset from the database).
|
||||||
|
sdCache, err := newStateDiffCache(s)
|
||||||
|
if err != nil {
|
||||||
|
return pkgerrors.Wrap(err, "failed to create state diff cache")
|
||||||
|
}
|
||||||
|
s.stateDiffCache = sdCache
|
||||||
|
|
||||||
|
// Save the initial state as a full snapshot.
|
||||||
|
if err := s.saveFullSnapshot(initialState); err != nil {
|
||||||
|
return pkgerrors.Wrap(err, "failed to save initial snapshot")
|
||||||
|
}
|
||||||
|
|
||||||
|
log.WithField("offset", slot).Info("Initialized state-diff cache")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func keyForSnapshot(v int) ([]byte, error) {
|
func keyForSnapshot(v int) ([]byte, error) {
|
||||||
switch v {
|
switch v {
|
||||||
case version.Fulu:
|
case version.Fulu:
|
||||||
|
|||||||
@@ -110,6 +110,8 @@ func (s *Store) SaveOrigin(ctx context.Context, serState, serBlock []byte) error
|
|||||||
if err = s.SaveFinalizedCheckpoint(ctx, chkpt); err != nil {
|
if err = s.SaveFinalizedCheckpoint(ctx, chkpt); err != nil {
|
||||||
return errors.Wrap(err, "save finalized checkpoint")
|
return errors.Wrap(err, "save finalized checkpoint")
|
||||||
}
|
}
|
||||||
|
if err := s.initializeStateDiff(state.Slot(), state); err != nil {
|
||||||
|
return errors.Wrap(err, "failed to initialize state diff")
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ go_library(
|
|||||||
"//monitoring/tracing:go_default_library",
|
"//monitoring/tracing:go_default_library",
|
||||||
"//runtime:go_default_library",
|
"//runtime:go_default_library",
|
||||||
"//runtime/prereqs:go_default_library",
|
"//runtime/prereqs:go_default_library",
|
||||||
"//runtime/version:go_default_library",
|
|
||||||
"@com_github_ethereum_go_ethereum//common:go_default_library",
|
"@com_github_ethereum_go_ethereum//common:go_default_library",
|
||||||
"@com_github_pkg_errors//:go_default_library",
|
"@com_github_pkg_errors//:go_default_library",
|
||||||
"@com_github_prometheus_client_golang//prometheus:go_default_library",
|
"@com_github_prometheus_client_golang//prometheus:go_default_library",
|
||||||
|
|||||||
@@ -66,7 +66,6 @@ import (
|
|||||||
"github.com/OffchainLabs/prysm/v7/monitoring/prometheus"
|
"github.com/OffchainLabs/prysm/v7/monitoring/prometheus"
|
||||||
"github.com/OffchainLabs/prysm/v7/runtime"
|
"github.com/OffchainLabs/prysm/v7/runtime"
|
||||||
"github.com/OffchainLabs/prysm/v7/runtime/prereqs"
|
"github.com/OffchainLabs/prysm/v7/runtime/prereqs"
|
||||||
"github.com/OffchainLabs/prysm/v7/runtime/version"
|
|
||||||
"github.com/ethereum/go-ethereum/common"
|
"github.com/ethereum/go-ethereum/common"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
@@ -469,10 +468,6 @@ func (b *BeaconNode) OperationFeed() event.SubscriberSender {
|
|||||||
func (b *BeaconNode) Start() {
|
func (b *BeaconNode) Start() {
|
||||||
b.lock.Lock()
|
b.lock.Lock()
|
||||||
|
|
||||||
log.WithFields(logrus.Fields{
|
|
||||||
"version": version.Version(),
|
|
||||||
}).Info("Starting beacon node")
|
|
||||||
|
|
||||||
b.services.StartAll()
|
b.services.StartAll()
|
||||||
|
|
||||||
stop := b.stop
|
stop := b.stop
|
||||||
@@ -540,7 +535,12 @@ func openDB(ctx context.Context, dbPath string, clearer *dbClearer) (*kv.Store,
|
|||||||
log.WithField("databasePath", dbPath).Info("Checking DB")
|
log.WithField("databasePath", dbPath).Info("Checking DB")
|
||||||
|
|
||||||
d, err := kv.NewKVStore(ctx, dbPath)
|
d, err := kv.NewKVStore(ctx, dbPath)
|
||||||
if err != nil {
|
if errors.Is(err, kv.ErrStateDiffIncompatible) {
|
||||||
|
log.WithError(err).Warn("Disabling state-diff feature")
|
||||||
|
cfg := features.Get()
|
||||||
|
cfg.EnableStateDiff = false
|
||||||
|
features.Init(cfg)
|
||||||
|
} else if err != nil {
|
||||||
return nil, errors.Wrapf(err, "could not create database at %s", dbPath)
|
return nil, errors.Wrapf(err, "could not create database at %s", dbPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ func TestNodeClose_OK(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNodeStart_Ok(t *testing.T) {
|
func TestNodeStart_Ok(t *testing.T) {
|
||||||
hook := logTest.NewGlobal()
|
|
||||||
app := cli.App{}
|
app := cli.App{}
|
||||||
tmp := fmt.Sprintf("%s/datadirtest2", t.TempDir())
|
tmp := fmt.Sprintf("%s/datadirtest2", t.TempDir())
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
@@ -97,11 +96,9 @@ func TestNodeStart_Ok(t *testing.T) {
|
|||||||
}()
|
}()
|
||||||
time.Sleep(3 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
node.Close()
|
node.Close()
|
||||||
require.LogsContain(t, hook, "Starting beacon node")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNodeStart_SyncChecker(t *testing.T) {
|
func TestNodeStart_SyncChecker(t *testing.T) {
|
||||||
hook := logTest.NewGlobal()
|
|
||||||
app := cli.App{}
|
app := cli.App{}
|
||||||
tmp := fmt.Sprintf("%s/datadirtest2", t.TempDir())
|
tmp := fmt.Sprintf("%s/datadirtest2", t.TempDir())
|
||||||
set := flag.NewFlagSet("test", 0)
|
set := flag.NewFlagSet("test", 0)
|
||||||
@@ -127,7 +124,6 @@ func TestNodeStart_SyncChecker(t *testing.T) {
|
|||||||
time.Sleep(3 * time.Second)
|
time.Sleep(3 * time.Second)
|
||||||
assert.NotNil(t, node.syncChecker.Svc)
|
assert.NotNil(t, node.syncChecker.Svc)
|
||||||
node.Close()
|
node.Close()
|
||||||
require.LogsContain(t, hook, "Starting beacon node")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TestClearDB tests clearing the database
|
// TestClearDB tests clearing the database
|
||||||
|
|||||||
@@ -575,7 +575,7 @@ func (s *Service) beaconEndpoints(
|
|||||||
name: namespace + ".PublishBlockV2",
|
name: namespace + ".PublishBlockV2",
|
||||||
middleware: []middleware.Middleware{
|
middleware: []middleware.Middleware{
|
||||||
middleware.ContentTypeHandler([]string{api.JsonMediaType, api.OctetStreamMediaType}),
|
middleware.ContentTypeHandler([]string{api.JsonMediaType, api.OctetStreamMediaType}),
|
||||||
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
|
middleware.AcceptHeaderHandler([]string{api.JsonMediaType, api.OctetStreamMediaType}),
|
||||||
middleware.AcceptEncodingHeaderHandler(),
|
middleware.AcceptEncodingHeaderHandler(),
|
||||||
},
|
},
|
||||||
handler: server.PublishBlockV2,
|
handler: server.PublishBlockV2,
|
||||||
@@ -586,7 +586,7 @@ func (s *Service) beaconEndpoints(
|
|||||||
name: namespace + ".PublishBlindedBlockV2",
|
name: namespace + ".PublishBlindedBlockV2",
|
||||||
middleware: []middleware.Middleware{
|
middleware: []middleware.Middleware{
|
||||||
middleware.ContentTypeHandler([]string{api.JsonMediaType, api.OctetStreamMediaType}),
|
middleware.ContentTypeHandler([]string{api.JsonMediaType, api.OctetStreamMediaType}),
|
||||||
middleware.AcceptHeaderHandler([]string{api.JsonMediaType}),
|
middleware.AcceptHeaderHandler([]string{api.JsonMediaType, api.OctetStreamMediaType}),
|
||||||
middleware.AcceptEncodingHeaderHandler(),
|
middleware.AcceptEncodingHeaderHandler(),
|
||||||
},
|
},
|
||||||
handler: server.PublishBlindedBlockV2,
|
handler: server.PublishBlindedBlockV2,
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/OffchainLabs/prysm/v7/api"
|
"github.com/OffchainLabs/prysm/v7/api"
|
||||||
@@ -26,7 +25,6 @@ import (
|
|||||||
"github.com/OffchainLabs/prysm/v7/consensus-types/blocks"
|
"github.com/OffchainLabs/prysm/v7/consensus-types/blocks"
|
||||||
"github.com/OffchainLabs/prysm/v7/consensus-types/interfaces"
|
"github.com/OffchainLabs/prysm/v7/consensus-types/interfaces"
|
||||||
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
||||||
"github.com/OffchainLabs/prysm/v7/encoding/bytesutil"
|
|
||||||
"github.com/OffchainLabs/prysm/v7/monitoring/tracing/trace"
|
"github.com/OffchainLabs/prysm/v7/monitoring/tracing/trace"
|
||||||
"github.com/OffchainLabs/prysm/v7/network/httputil"
|
"github.com/OffchainLabs/prysm/v7/network/httputil"
|
||||||
eth "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
eth "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
||||||
@@ -1044,112 +1042,27 @@ func (s *Server) GetBlockRoot(w http.ResponseWriter, r *http.Request) {
|
|||||||
ctx, span := trace.StartSpan(r.Context(), "beacon.GetBlockRoot")
|
ctx, span := trace.StartSpan(r.Context(), "beacon.GetBlockRoot")
|
||||||
defer span.End()
|
defer span.End()
|
||||||
|
|
||||||
var err error
|
|
||||||
var root []byte
|
|
||||||
blockID := r.PathValue("block_id")
|
blockID := r.PathValue("block_id")
|
||||||
if blockID == "" {
|
if blockID == "" {
|
||||||
httputil.HandleError(w, "block_id is required in URL params", http.StatusBadRequest)
|
httputil.HandleError(w, "block_id is required in URL params", http.StatusBadRequest)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
switch blockID {
|
root, err := s.Blocker.BlockRoot(ctx, []byte(blockID))
|
||||||
case "head":
|
if !shared.WriteBlockRootFetchError(w, err) {
|
||||||
root, err = s.ChainInfoFetcher.HeadRoot(ctx)
|
return
|
||||||
if err != nil {
|
|
||||||
httputil.HandleError(w, "Could not retrieve head root: "+err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if root == nil {
|
|
||||||
httputil.HandleError(w, "No head root was found", http.StatusNotFound)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
case "finalized":
|
|
||||||
finalized := s.ChainInfoFetcher.FinalizedCheckpt()
|
|
||||||
root = finalized.Root
|
|
||||||
case "genesis":
|
|
||||||
blk, err := s.BeaconDB.GenesisBlock(ctx)
|
|
||||||
if err != nil {
|
|
||||||
httputil.HandleError(w, "Could not retrieve genesis block: "+err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err := blocks.BeaconBlockIsNil(blk); err != nil {
|
|
||||||
httputil.HandleError(w, "Could not find genesis block: "+err.Error(), http.StatusNotFound)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
blkRoot, err := blk.Block().HashTreeRoot()
|
|
||||||
if err != nil {
|
|
||||||
httputil.HandleError(w, "Could not hash genesis block: "+err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
root = blkRoot[:]
|
|
||||||
default:
|
|
||||||
isHex := strings.HasPrefix(blockID, "0x")
|
|
||||||
if isHex {
|
|
||||||
blockIDBytes, err := hexutil.Decode(blockID)
|
|
||||||
if err != nil {
|
|
||||||
httputil.HandleError(w, "Could not decode block ID into bytes: "+err.Error(), http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if len(blockIDBytes) != fieldparams.RootLength {
|
|
||||||
httputil.HandleError(w, fmt.Sprintf("Block ID has length %d instead of %d", len(blockIDBytes), fieldparams.RootLength), http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
blockID32 := bytesutil.ToBytes32(blockIDBytes)
|
|
||||||
blk, err := s.BeaconDB.Block(ctx, blockID32)
|
|
||||||
if err != nil {
|
|
||||||
httputil.HandleError(w, fmt.Sprintf("Could not retrieve block for block root %#x: %v", blockID, err), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if err := blocks.BeaconBlockIsNil(blk); err != nil {
|
|
||||||
httputil.HandleError(w, "Could not find block: "+err.Error(), http.StatusNotFound)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
root = blockIDBytes
|
|
||||||
} else {
|
|
||||||
slot, err := strconv.ParseUint(blockID, 10, 64)
|
|
||||||
if err != nil {
|
|
||||||
httputil.HandleError(w, "Could not parse block ID: "+err.Error(), http.StatusBadRequest)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
hasRoots, roots, err := s.BeaconDB.BlockRootsBySlot(ctx, primitives.Slot(slot))
|
|
||||||
if err != nil {
|
|
||||||
httputil.HandleError(w, fmt.Sprintf("Could not retrieve blocks for slot %d: %v", slot, err), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
if !hasRoots {
|
|
||||||
httputil.HandleError(w, "Could not find any blocks with given slot", http.StatusNotFound)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
root = roots[0][:]
|
|
||||||
if len(roots) == 1 {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
for _, blockRoot := range roots {
|
|
||||||
canonical, err := s.ChainInfoFetcher.IsCanonical(ctx, blockRoot)
|
|
||||||
if err != nil {
|
|
||||||
httputil.HandleError(w, "Could not determine if block root is canonical: "+err.Error(), http.StatusInternalServerError)
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if canonical {
|
|
||||||
root = blockRoot[:]
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
b32Root := bytesutil.ToBytes32(root)
|
isOptimistic, err := s.OptimisticModeFetcher.IsOptimisticForRoot(ctx, root)
|
||||||
isOptimistic, err := s.OptimisticModeFetcher.IsOptimisticForRoot(ctx, b32Root)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
httputil.HandleError(w, "Could not check if block is optimistic: "+err.Error(), http.StatusInternalServerError)
|
httputil.HandleError(w, "Could not check if block is optimistic: "+err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
response := &structs.BlockRootResponse{
|
response := &structs.BlockRootResponse{
|
||||||
Data: &structs.BlockRoot{
|
Data: &structs.BlockRoot{
|
||||||
Root: hexutil.Encode(root),
|
Root: hexutil.Encode(root[:]),
|
||||||
},
|
},
|
||||||
ExecutionOptimistic: isOptimistic,
|
ExecutionOptimistic: isOptimistic,
|
||||||
Finalized: s.FinalizationFetcher.IsFinalized(ctx, b32Root),
|
Finalized: s.FinalizationFetcher.IsFinalized(ctx, root),
|
||||||
}
|
}
|
||||||
httputil.WriteJson(w, response)
|
httputil.WriteJson(w, response)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,8 +26,8 @@ import (
|
|||||||
"github.com/OffchainLabs/prysm/v7/beacon-chain/operations/voluntaryexits/mock"
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/operations/voluntaryexits/mock"
|
||||||
p2pMock "github.com/OffchainLabs/prysm/v7/beacon-chain/p2p/testing"
|
p2pMock "github.com/OffchainLabs/prysm/v7/beacon-chain/p2p/testing"
|
||||||
"github.com/OffchainLabs/prysm/v7/beacon-chain/rpc/core"
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/rpc/core"
|
||||||
mockSync "github.com/OffchainLabs/prysm/v7/beacon-chain/sync/initial-sync/testing"
|
|
||||||
state_native "github.com/OffchainLabs/prysm/v7/beacon-chain/state/state-native"
|
state_native "github.com/OffchainLabs/prysm/v7/beacon-chain/state/state-native"
|
||||||
|
mockSync "github.com/OffchainLabs/prysm/v7/beacon-chain/sync/initial-sync/testing"
|
||||||
"github.com/OffchainLabs/prysm/v7/config/params"
|
"github.com/OffchainLabs/prysm/v7/config/params"
|
||||||
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
||||||
"github.com/OffchainLabs/prysm/v7/crypto/bls"
|
"github.com/OffchainLabs/prysm/v7/crypto/bls"
|
||||||
|
|||||||
@@ -50,6 +50,14 @@ import (
|
|||||||
"go.uber.org/mock/gomock"
|
"go.uber.org/mock/gomock"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// fillGloasBlockTestData populates a Gloas block with non-zero test values for the
|
||||||
|
// Gloas-specific fields: SignedExecutionPayloadBid and PayloadAttestations.
|
||||||
|
func fillGloasBlockTestData(b *eth.SignedBeaconBlockGloas, numPayloadAttestations int) {
|
||||||
|
slot := b.Block.Slot
|
||||||
|
b.Block.Body.SignedExecutionPayloadBid = util.GenerateTestSignedExecutionPayloadBid(slot)
|
||||||
|
b.Block.Body.PayloadAttestations = util.GenerateTestPayloadAttestations(numPayloadAttestations, slot)
|
||||||
|
}
|
||||||
|
|
||||||
func fillDBTestBlocks(ctx context.Context, t *testing.T, beaconDB db.Database) (*eth.SignedBeaconBlock, []*eth.BeaconBlockContainer) {
|
func fillDBTestBlocks(ctx context.Context, t *testing.T, beaconDB db.Database) (*eth.SignedBeaconBlock, []*eth.BeaconBlockContainer) {
|
||||||
parentRoot := [32]byte{1, 2, 3}
|
parentRoot := [32]byte{1, 2, 3}
|
||||||
genBlk := util.NewBeaconBlock()
|
genBlk := util.NewBeaconBlock()
|
||||||
@@ -335,6 +343,50 @@ func TestGetBlockV2(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.DeepEqual(t, blk, b)
|
assert.DeepEqual(t, blk, b)
|
||||||
})
|
})
|
||||||
|
t.Run("gloas", func(t *testing.T) {
|
||||||
|
b := util.NewBeaconBlockGloas()
|
||||||
|
b.Block.Slot = 123
|
||||||
|
fillGloasBlockTestData(b, 2)
|
||||||
|
sb, err := blocks.NewSignedBeaconBlock(b)
|
||||||
|
require.NoError(t, err)
|
||||||
|
mockBlockFetcher := &testutil.MockBlocker{BlockToReturn: sb}
|
||||||
|
mockChainService := &chainMock.ChainService{
|
||||||
|
FinalizedRoots: map[[32]byte]bool{},
|
||||||
|
}
|
||||||
|
s := &Server{
|
||||||
|
OptimisticModeFetcher: mockChainService,
|
||||||
|
FinalizationFetcher: mockChainService,
|
||||||
|
Blocker: mockBlockFetcher,
|
||||||
|
}
|
||||||
|
|
||||||
|
request := httptest.NewRequest(http.MethodGet, "http://foo.example/eth/v2/beacon/blocks/{block_id}", nil)
|
||||||
|
request.SetPathValue("block_id", "head")
|
||||||
|
writer := httptest.NewRecorder()
|
||||||
|
writer.Body = &bytes.Buffer{}
|
||||||
|
|
||||||
|
s.GetBlockV2(writer, request)
|
||||||
|
require.Equal(t, http.StatusOK, writer.Code)
|
||||||
|
resp := &structs.GetBlockV2Response{}
|
||||||
|
require.NoError(t, json.Unmarshal(writer.Body.Bytes(), resp))
|
||||||
|
assert.Equal(t, version.String(version.Gloas), resp.Version)
|
||||||
|
sbb := &structs.SignedBeaconBlockGloas{Message: &structs.BeaconBlockGloas{}}
|
||||||
|
require.NoError(t, json.Unmarshal(resp.Data.Message, sbb.Message))
|
||||||
|
sbb.Signature = resp.Data.Signature
|
||||||
|
blk, err := sbb.ToConsensus()
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.DeepEqual(t, blk, b)
|
||||||
|
|
||||||
|
// Verify Gloas-specific fields are correctly serialized/deserialized
|
||||||
|
require.NotNil(t, blk.Block.Body.SignedExecutionPayloadBid)
|
||||||
|
assert.Equal(t, primitives.Slot(123), blk.Block.Body.SignedExecutionPayloadBid.Message.Slot)
|
||||||
|
assert.Equal(t, primitives.BuilderIndex(1), blk.Block.Body.SignedExecutionPayloadBid.Message.BuilderIndex)
|
||||||
|
require.Equal(t, 2, len(blk.Block.Body.PayloadAttestations))
|
||||||
|
for _, att := range blk.Block.Body.PayloadAttestations {
|
||||||
|
assert.Equal(t, primitives.Slot(123), att.Data.Slot)
|
||||||
|
assert.Equal(t, true, att.Data.PayloadPresent)
|
||||||
|
assert.Equal(t, true, att.Data.BlobDataAvailable)
|
||||||
|
}
|
||||||
|
})
|
||||||
t.Run("execution optimistic", func(t *testing.T) {
|
t.Run("execution optimistic", func(t *testing.T) {
|
||||||
b := util.NewBeaconBlockBellatrix()
|
b := util.NewBeaconBlockBellatrix()
|
||||||
sb, err := blocks.NewSignedBeaconBlock(b)
|
sb, err := blocks.NewSignedBeaconBlock(b)
|
||||||
@@ -574,6 +626,37 @@ func TestGetBlockSSZV2(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.DeepEqual(t, sszExpected, writer.Body.Bytes())
|
assert.DeepEqual(t, sszExpected, writer.Body.Bytes())
|
||||||
})
|
})
|
||||||
|
t.Run("gloas", func(t *testing.T) {
|
||||||
|
b := util.NewBeaconBlockGloas()
|
||||||
|
b.Block.Slot = 123
|
||||||
|
fillGloasBlockTestData(b, 2)
|
||||||
|
sb, err := blocks.NewSignedBeaconBlock(b)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
s := &Server{
|
||||||
|
Blocker: &testutil.MockBlocker{BlockToReturn: sb},
|
||||||
|
}
|
||||||
|
|
||||||
|
request := httptest.NewRequest(http.MethodGet, "http://foo.example/eth/v2/beacon/blocks/{block_id}", nil)
|
||||||
|
request.SetPathValue("block_id", "head")
|
||||||
|
request.Header.Set("Accept", api.OctetStreamMediaType)
|
||||||
|
writer := httptest.NewRecorder()
|
||||||
|
writer.Body = &bytes.Buffer{}
|
||||||
|
|
||||||
|
s.GetBlockV2(writer, request)
|
||||||
|
require.Equal(t, http.StatusOK, writer.Code)
|
||||||
|
assert.Equal(t, version.String(version.Gloas), writer.Header().Get(api.VersionHeader))
|
||||||
|
sszExpected, err := b.MarshalSSZ()
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.DeepEqual(t, sszExpected, writer.Body.Bytes())
|
||||||
|
|
||||||
|
// Verify SSZ round-trip preserves Gloas-specific fields
|
||||||
|
decoded := ð.SignedBeaconBlockGloas{}
|
||||||
|
require.NoError(t, decoded.UnmarshalSSZ(writer.Body.Bytes()))
|
||||||
|
require.NotNil(t, decoded.Block.Body.SignedExecutionPayloadBid)
|
||||||
|
assert.Equal(t, primitives.Slot(123), decoded.Block.Body.SignedExecutionPayloadBid.Message.Slot)
|
||||||
|
require.Equal(t, 2, len(decoded.Block.Body.PayloadAttestations))
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestGetBlockAttestationsV2(t *testing.T) {
|
func TestGetBlockAttestationsV2(t *testing.T) {
|
||||||
@@ -2509,6 +2592,10 @@ func TestServer_GetBlockRoot(t *testing.T) {
|
|||||||
HeadFetcher: mockChainFetcher,
|
HeadFetcher: mockChainFetcher,
|
||||||
OptimisticModeFetcher: mockChainFetcher,
|
OptimisticModeFetcher: mockChainFetcher,
|
||||||
FinalizationFetcher: mockChainFetcher,
|
FinalizationFetcher: mockChainFetcher,
|
||||||
|
Blocker: &lookup.BeaconDbBlocker{
|
||||||
|
BeaconDB: beaconDB,
|
||||||
|
ChainInfoFetcher: mockChainFetcher,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
root, err := genBlk.Block.HashTreeRoot()
|
root, err := genBlk.Block.HashTreeRoot()
|
||||||
@@ -2524,7 +2611,7 @@ func TestServer_GetBlockRoot(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "bad formatting",
|
name: "bad formatting",
|
||||||
blockID: map[string]string{"block_id": "3bad0"},
|
blockID: map[string]string{"block_id": "3bad0"},
|
||||||
wantErr: "Could not parse block ID",
|
wantErr: "Invalid block ID",
|
||||||
wantCode: http.StatusBadRequest,
|
wantCode: http.StatusBadRequest,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -2572,7 +2659,7 @@ func TestServer_GetBlockRoot(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "non-existent root",
|
name: "non-existent root",
|
||||||
blockID: map[string]string{"block_id": hexutil.Encode(bytesutil.PadTo([]byte("hi there"), 32))},
|
blockID: map[string]string{"block_id": hexutil.Encode(bytesutil.PadTo([]byte("hi there"), 32))},
|
||||||
wantErr: "Could not find block",
|
wantErr: "Block not found",
|
||||||
wantCode: http.StatusNotFound,
|
wantCode: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -2585,7 +2672,7 @@ func TestServer_GetBlockRoot(t *testing.T) {
|
|||||||
{
|
{
|
||||||
name: "no block",
|
name: "no block",
|
||||||
blockID: map[string]string{"block_id": "105"},
|
blockID: map[string]string{"block_id": "105"},
|
||||||
wantErr: "Could not find any blocks with given slot",
|
wantErr: "Block not found",
|
||||||
wantCode: http.StatusNotFound,
|
wantCode: http.StatusNotFound,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -2633,6 +2720,10 @@ func TestServer_GetBlockRoot(t *testing.T) {
|
|||||||
HeadFetcher: mockChainFetcher,
|
HeadFetcher: mockChainFetcher,
|
||||||
OptimisticModeFetcher: mockChainFetcher,
|
OptimisticModeFetcher: mockChainFetcher,
|
||||||
FinalizationFetcher: mockChainFetcher,
|
FinalizationFetcher: mockChainFetcher,
|
||||||
|
Blocker: &lookup.BeaconDbBlocker{
|
||||||
|
BeaconDB: beaconDB,
|
||||||
|
ChainInfoFetcher: mockChainFetcher,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
request := httptest.NewRequest(http.MethodGet, url, nil)
|
request := httptest.NewRequest(http.MethodGet, url, nil)
|
||||||
@@ -2668,6 +2759,10 @@ func TestServer_GetBlockRoot(t *testing.T) {
|
|||||||
HeadFetcher: mockChainFetcher,
|
HeadFetcher: mockChainFetcher,
|
||||||
OptimisticModeFetcher: mockChainFetcher,
|
OptimisticModeFetcher: mockChainFetcher,
|
||||||
FinalizationFetcher: mockChainFetcher,
|
FinalizationFetcher: mockChainFetcher,
|
||||||
|
Blocker: &lookup.BeaconDbBlocker{
|
||||||
|
BeaconDB: beaconDB,
|
||||||
|
ChainInfoFetcher: mockChainFetcher,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
t.Run("true", func(t *testing.T) {
|
t.Run("true", func(t *testing.T) {
|
||||||
request := httptest.NewRequest(http.MethodGet, url, nil)
|
request := httptest.NewRequest(http.MethodGet, url, nil)
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ func TestGetSpec(t *testing.T) {
|
|||||||
config.ElectraForkEpoch = 107
|
config.ElectraForkEpoch = 107
|
||||||
config.FuluForkVersion = []byte("FuluForkVersion")
|
config.FuluForkVersion = []byte("FuluForkVersion")
|
||||||
config.FuluForkEpoch = 109
|
config.FuluForkEpoch = 109
|
||||||
|
config.GloasForkEpoch = 110
|
||||||
config.BLSWithdrawalPrefixByte = byte('b')
|
config.BLSWithdrawalPrefixByte = byte('b')
|
||||||
config.ETH1AddressWithdrawalPrefixByte = byte('c')
|
config.ETH1AddressWithdrawalPrefixByte = byte('c')
|
||||||
config.GenesisDelay = 24
|
config.GenesisDelay = 24
|
||||||
@@ -134,6 +135,10 @@ func TestGetSpec(t *testing.T) {
|
|||||||
config.AttestationDueBPS = primitives.BP(122)
|
config.AttestationDueBPS = primitives.BP(122)
|
||||||
config.AggregateDueBPS = primitives.BP(123)
|
config.AggregateDueBPS = primitives.BP(123)
|
||||||
config.ContributionDueBPS = primitives.BP(124)
|
config.ContributionDueBPS = primitives.BP(124)
|
||||||
|
config.AttestationDueBPSGloas = primitives.BP(126)
|
||||||
|
config.AggregateDueBPSGloas = primitives.BP(127)
|
||||||
|
config.SyncMessageDueBPSGloas = primitives.BP(128)
|
||||||
|
config.ContributionDueBPSGloas = primitives.BP(129)
|
||||||
config.TerminalBlockHash = common.HexToHash("TerminalBlockHash")
|
config.TerminalBlockHash = common.HexToHash("TerminalBlockHash")
|
||||||
config.TerminalBlockHashActivationEpoch = 72
|
config.TerminalBlockHashActivationEpoch = 72
|
||||||
config.TerminalTotalDifficulty = "73"
|
config.TerminalTotalDifficulty = "73"
|
||||||
@@ -197,6 +202,9 @@ func TestGetSpec(t *testing.T) {
|
|||||||
var dbb [4]byte
|
var dbb [4]byte
|
||||||
copy(dbb[:], []byte{'0', '0', '0', '8'})
|
copy(dbb[:], []byte{'0', '0', '0', '8'})
|
||||||
config.DomainBeaconBuilder = dbb
|
config.DomainBeaconBuilder = dbb
|
||||||
|
var dptc [4]byte
|
||||||
|
copy(dptc[:], []byte{'0', '0', '0', '8'})
|
||||||
|
config.DomainPTCAttester = dptc
|
||||||
var dam [4]byte
|
var dam [4]byte
|
||||||
copy(dam[:], []byte{'1', '0', '0', '0'})
|
copy(dam[:], []byte{'1', '0', '0', '0'})
|
||||||
config.DomainApplicationMask = dam
|
config.DomainApplicationMask = dam
|
||||||
@@ -212,7 +220,7 @@ func TestGetSpec(t *testing.T) {
|
|||||||
require.NoError(t, json.Unmarshal(writer.Body.Bytes(), &resp))
|
require.NoError(t, json.Unmarshal(writer.Body.Bytes(), &resp))
|
||||||
data, ok := resp.Data.(map[string]any)
|
data, ok := resp.Data.(map[string]any)
|
||||||
require.Equal(t, true, ok)
|
require.Equal(t, true, ok)
|
||||||
assert.Equal(t, 186, len(data))
|
assert.Equal(t, 192, len(data))
|
||||||
for k, v := range data {
|
for k, v := range data {
|
||||||
t.Run(k, func(t *testing.T) {
|
t.Run(k, func(t *testing.T) {
|
||||||
switch k {
|
switch k {
|
||||||
@@ -292,6 +300,8 @@ func TestGetSpec(t *testing.T) {
|
|||||||
assert.Equal(t, "0x"+hex.EncodeToString([]byte("FuluForkVersion")), v)
|
assert.Equal(t, "0x"+hex.EncodeToString([]byte("FuluForkVersion")), v)
|
||||||
case "FULU_FORK_EPOCH":
|
case "FULU_FORK_EPOCH":
|
||||||
assert.Equal(t, "109", v)
|
assert.Equal(t, "109", v)
|
||||||
|
case "GLOAS_FORK_EPOCH":
|
||||||
|
assert.Equal(t, "110", v)
|
||||||
case "MIN_ANCHOR_POW_BLOCK_DIFFICULTY":
|
case "MIN_ANCHOR_POW_BLOCK_DIFFICULTY":
|
||||||
assert.Equal(t, "1000", v)
|
assert.Equal(t, "1000", v)
|
||||||
case "BLS_WITHDRAWAL_PREFIX":
|
case "BLS_WITHDRAWAL_PREFIX":
|
||||||
@@ -414,6 +424,8 @@ func TestGetSpec(t *testing.T) {
|
|||||||
assert.Equal(t, "0x30303036", v)
|
assert.Equal(t, "0x30303036", v)
|
||||||
case "DOMAIN_AGGREGATE_AND_PROOF":
|
case "DOMAIN_AGGREGATE_AND_PROOF":
|
||||||
assert.Equal(t, "0x30303037", v)
|
assert.Equal(t, "0x30303037", v)
|
||||||
|
case "DOMAIN_PTC_ATTESTER":
|
||||||
|
assert.Equal(t, "0x30303038", v)
|
||||||
case "DOMAIN_APPLICATION_MASK":
|
case "DOMAIN_APPLICATION_MASK":
|
||||||
assert.Equal(t, "0x31303030", v)
|
assert.Equal(t, "0x31303030", v)
|
||||||
case "DOMAIN_SYNC_COMMITTEE":
|
case "DOMAIN_SYNC_COMMITTEE":
|
||||||
@@ -474,6 +486,14 @@ func TestGetSpec(t *testing.T) {
|
|||||||
assert.Equal(t, "123", v)
|
assert.Equal(t, "123", v)
|
||||||
case "CONTRIBUTION_DUE_BPS":
|
case "CONTRIBUTION_DUE_BPS":
|
||||||
assert.Equal(t, "124", v)
|
assert.Equal(t, "124", v)
|
||||||
|
case "ATTESTATION_DUE_BPS_GLOAS":
|
||||||
|
assert.Equal(t, "126", v)
|
||||||
|
case "AGGREGATE_DUE_BPS_GLOAS":
|
||||||
|
assert.Equal(t, "127", v)
|
||||||
|
case "SYNC_MESSAGE_DUE_BPS_GLOAS":
|
||||||
|
assert.Equal(t, "128", v)
|
||||||
|
case "CONTRIBUTION_DUE_BPS_GLOAS":
|
||||||
|
assert.Equal(t, "129", v)
|
||||||
case "MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT":
|
case "MAX_PER_EPOCH_ACTIVATION_CHURN_LIMIT":
|
||||||
assert.Equal(t, "8", v)
|
assert.Equal(t, "8", v)
|
||||||
case "MAX_REQUEST_LIGHT_CLIENT_UPDATES":
|
case "MAX_REQUEST_LIGHT_CLIENT_UPDATES":
|
||||||
|
|||||||
@@ -26,21 +26,30 @@ func WriteStateFetchError(w http.ResponseWriter, err error) {
|
|||||||
httputil.HandleError(w, "Could not get state: "+err.Error(), http.StatusInternalServerError)
|
httputil.HandleError(w, "Could not get state: "+err.Error(), http.StatusInternalServerError)
|
||||||
}
|
}
|
||||||
|
|
||||||
// WriteBlockFetchError writes an appropriate error based on the supplied argument.
|
// writeBlockIdError handles common block ID lookup errors.
|
||||||
// The argument error should be a result of fetching block.
|
// Returns true if an error was handled and written to the response, false if no error.
|
||||||
func WriteBlockFetchError(w http.ResponseWriter, blk interfaces.ReadOnlySignedBeaconBlock, err error) bool {
|
func writeBlockIdError(w http.ResponseWriter, err error, fallbackMsg string) bool {
|
||||||
|
if err == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
var blockNotFoundErr *lookup.BlockNotFoundError
|
var blockNotFoundErr *lookup.BlockNotFoundError
|
||||||
if errors.As(err, &blockNotFoundErr) {
|
if errors.As(err, &blockNotFoundErr) {
|
||||||
httputil.HandleError(w, "Block not found: "+blockNotFoundErr.Error(), http.StatusNotFound)
|
httputil.HandleError(w, "Block not found: "+blockNotFoundErr.Error(), http.StatusNotFound)
|
||||||
return false
|
return true
|
||||||
}
|
}
|
||||||
var invalidBlockIdErr *lookup.BlockIdParseError
|
var invalidBlockIdErr *lookup.BlockIdParseError
|
||||||
if errors.As(err, &invalidBlockIdErr) {
|
if errors.As(err, &invalidBlockIdErr) {
|
||||||
httputil.HandleError(w, "Invalid block ID: "+invalidBlockIdErr.Error(), http.StatusBadRequest)
|
httputil.HandleError(w, "Invalid block ID: "+invalidBlockIdErr.Error(), http.StatusBadRequest)
|
||||||
return false
|
return true
|
||||||
}
|
}
|
||||||
if err != nil {
|
httputil.HandleError(w, fallbackMsg+": "+err.Error(), http.StatusInternalServerError)
|
||||||
httputil.HandleError(w, "Could not get block from block ID: "+err.Error(), http.StatusInternalServerError)
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteBlockFetchError writes an appropriate error based on the supplied argument.
|
||||||
|
// The argument error should be a result of fetching block.
|
||||||
|
func WriteBlockFetchError(w http.ResponseWriter, blk interfaces.ReadOnlySignedBeaconBlock, err error) bool {
|
||||||
|
if writeBlockIdError(w, err, "Could not get block from block ID") {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if err = blocks.BeaconBlockIsNil(blk); err != nil {
|
if err = blocks.BeaconBlockIsNil(blk); err != nil {
|
||||||
@@ -49,3 +58,10 @@ func WriteBlockFetchError(w http.ResponseWriter, blk interfaces.ReadOnlySignedBe
|
|||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WriteBlockRootFetchError writes an appropriate error based on the supplied argument.
|
||||||
|
// The argument error should be a result of fetching block root.
|
||||||
|
// Returns true if no error occurred, false otherwise.
|
||||||
|
func WriteBlockRootFetchError(w http.ResponseWriter, err error) bool {
|
||||||
|
return !writeBlockIdError(w, err, "Could not get block root from block ID")
|
||||||
|
}
|
||||||
|
|||||||
@@ -105,3 +105,59 @@ func TestWriteBlockFetchError(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestWriteBlockRootFetchError tests the WriteBlockRootFetchError function
|
||||||
|
// to ensure that the correct error message and code are written to the response
|
||||||
|
// and that the function returns the correct boolean value.
|
||||||
|
func TestWriteBlockRootFetchError(t *testing.T) {
|
||||||
|
cases := []struct {
|
||||||
|
name string
|
||||||
|
err error
|
||||||
|
expectedMessage string
|
||||||
|
expectedCode int
|
||||||
|
expectedReturn bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Nil error should return true",
|
||||||
|
err: nil,
|
||||||
|
expectedReturn: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "BlockNotFoundError should return 404",
|
||||||
|
err: lookup.NewBlockNotFoundError("block not found at slot 123"),
|
||||||
|
expectedMessage: "Block not found",
|
||||||
|
expectedCode: http.StatusNotFound,
|
||||||
|
expectedReturn: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "BlockIdParseError should return 400",
|
||||||
|
err: &lookup.BlockIdParseError{},
|
||||||
|
expectedMessage: "Invalid block ID",
|
||||||
|
expectedCode: http.StatusBadRequest,
|
||||||
|
expectedReturn: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Generic error should return 500",
|
||||||
|
err: errors.New("database connection failed"),
|
||||||
|
expectedMessage: "Could not get block root from block ID",
|
||||||
|
expectedCode: http.StatusInternalServerError,
|
||||||
|
expectedReturn: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, c := range cases {
|
||||||
|
t.Run(c.name, func(t *testing.T) {
|
||||||
|
writer := httptest.NewRecorder()
|
||||||
|
result := WriteBlockRootFetchError(writer, c.err)
|
||||||
|
|
||||||
|
assert.Equal(t, c.expectedReturn, result, "incorrect return value")
|
||||||
|
if !c.expectedReturn {
|
||||||
|
assert.Equal(t, c.expectedCode, writer.Code, "incorrect status code")
|
||||||
|
assert.StringContains(t, c.expectedMessage, writer.Body.String(), "incorrect error message")
|
||||||
|
|
||||||
|
e := &httputil.DefaultJsonError{}
|
||||||
|
assert.NoError(t, json.Unmarshal(writer.Body.Bytes(), e), "failed to unmarshal response")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ func (e BlockIdParseError) Error() string {
|
|||||||
// Blocker is responsible for retrieving blocks.
|
// Blocker is responsible for retrieving blocks.
|
||||||
type Blocker interface {
|
type Blocker interface {
|
||||||
Block(ctx context.Context, id []byte) (interfaces.ReadOnlySignedBeaconBlock, error)
|
Block(ctx context.Context, id []byte) (interfaces.ReadOnlySignedBeaconBlock, error)
|
||||||
|
BlockRoot(ctx context.Context, id []byte) ([fieldparams.RootLength]byte, error)
|
||||||
BlobSidecars(ctx context.Context, id string, opts ...options.BlobsOption) ([]*blocks.VerifiedROBlob, *core.RpcError)
|
BlobSidecars(ctx context.Context, id string, opts ...options.BlobsOption) ([]*blocks.VerifiedROBlob, *core.RpcError)
|
||||||
Blobs(ctx context.Context, id string, opts ...options.BlobsOption) ([][]byte, *core.RpcError)
|
Blobs(ctx context.Context, id string, opts ...options.BlobsOption) ([][]byte, *core.RpcError)
|
||||||
DataColumns(ctx context.Context, id string, indices []int) ([]blocks.VerifiedRODataColumn, *core.RpcError)
|
DataColumns(ctx context.Context, id string, indices []int) ([]blocks.VerifiedRODataColumn, *core.RpcError)
|
||||||
@@ -225,6 +226,18 @@ func (p *BeaconDbBlocker) Block(ctx context.Context, id []byte) (interfaces.Read
|
|||||||
return blk, nil
|
return blk, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BlockRoot returns the block root for a given identifier. The identifier can be one of:
|
||||||
|
// - "head" (canonical head in node's view)
|
||||||
|
// - "genesis"
|
||||||
|
// - "finalized"
|
||||||
|
// - "justified"
|
||||||
|
// - <slot>
|
||||||
|
// - <hex encoded block root with '0x' prefix>
|
||||||
|
func (p *BeaconDbBlocker) BlockRoot(ctx context.Context, id []byte) ([fieldparams.RootLength]byte, error) {
|
||||||
|
root, _, err := p.resolveBlockID(ctx, string(id))
|
||||||
|
return root, err
|
||||||
|
}
|
||||||
|
|
||||||
// blobsContext holds common information needed for blob retrieval
|
// blobsContext holds common information needed for blob retrieval
|
||||||
type blobsContext struct {
|
type blobsContext struct {
|
||||||
root [fieldparams.RootLength]byte
|
root [fieldparams.RootLength]byte
|
||||||
|
|||||||
@@ -168,6 +168,111 @@ func TestGetBlock(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestBlockRoot(t *testing.T) {
|
||||||
|
beaconDB := testDB.SetupDB(t)
|
||||||
|
ctx := t.Context()
|
||||||
|
|
||||||
|
genBlk, blkContainers := testutil.FillDBWithBlocks(ctx, t, beaconDB)
|
||||||
|
canonicalRoots := make(map[[32]byte]bool)
|
||||||
|
|
||||||
|
for _, bContr := range blkContainers {
|
||||||
|
canonicalRoots[bytesutil.ToBytes32(bContr.BlockRoot)] = true
|
||||||
|
}
|
||||||
|
headBlock := blkContainers[len(blkContainers)-1]
|
||||||
|
|
||||||
|
wsb, err := blocks.NewSignedBeaconBlock(headBlock.Block.(*ethpb.BeaconBlockContainer_Phase0Block).Phase0Block)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
fetcher := &BeaconDbBlocker{
|
||||||
|
BeaconDB: beaconDB,
|
||||||
|
ChainInfoFetcher: &mockChain.ChainService{
|
||||||
|
DB: beaconDB,
|
||||||
|
Block: wsb,
|
||||||
|
Root: headBlock.BlockRoot,
|
||||||
|
FinalizedCheckPoint: ðpb.Checkpoint{Root: blkContainers[64].BlockRoot},
|
||||||
|
CurrentJustifiedCheckPoint: ðpb.Checkpoint{Root: blkContainers[32].BlockRoot},
|
||||||
|
CanonicalRoots: canonicalRoots,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
genesisRoot, err := genBlk.Block.HashTreeRoot()
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
blockID []byte
|
||||||
|
want [32]byte
|
||||||
|
wantErr bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "slot",
|
||||||
|
blockID: []byte("30"),
|
||||||
|
want: bytesutil.ToBytes32(blkContainers[30].BlockRoot),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "bad formatting",
|
||||||
|
blockID: []byte("3bad0"),
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "head",
|
||||||
|
blockID: []byte("head"),
|
||||||
|
want: bytesutil.ToBytes32(headBlock.BlockRoot),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "finalized",
|
||||||
|
blockID: []byte("finalized"),
|
||||||
|
want: bytesutil.ToBytes32(blkContainers[64].BlockRoot),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "justified",
|
||||||
|
blockID: []byte("justified"),
|
||||||
|
want: bytesutil.ToBytes32(blkContainers[32].BlockRoot),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "genesis",
|
||||||
|
blockID: []byte("genesis"),
|
||||||
|
want: genesisRoot,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "genesis root",
|
||||||
|
blockID: genesisRoot[:],
|
||||||
|
want: genesisRoot,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "root",
|
||||||
|
blockID: blkContainers[20].BlockRoot,
|
||||||
|
want: bytesutil.ToBytes32(blkContainers[20].BlockRoot),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "hex root",
|
||||||
|
blockID: []byte(hexutil.Encode(blkContainers[20].BlockRoot)),
|
||||||
|
want: bytesutil.ToBytes32(blkContainers[20].BlockRoot),
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "non-existent root",
|
||||||
|
blockID: bytesutil.PadTo([]byte("hi there"), 32),
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "no block at slot",
|
||||||
|
blockID: []byte("105"),
|
||||||
|
wantErr: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
result, err := fetcher.BlockRoot(ctx, tt.blockID)
|
||||||
|
if tt.wantErr {
|
||||||
|
assert.NotEqual(t, err, nil, "no error has been returned")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
require.NoError(t, err)
|
||||||
|
assert.DeepEqual(t, tt.want, result)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestBlobsErrorHandling(t *testing.T) {
|
func TestBlobsErrorHandling(t *testing.T) {
|
||||||
params.SetupTestConfigCleanup(t)
|
params.SetupTestConfigCleanup(t)
|
||||||
cfg := params.BeaconConfig().Copy()
|
cfg := params.BeaconConfig().Copy()
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import (
|
|||||||
// MockBlocker is a fake implementation of lookup.Blocker.
|
// MockBlocker is a fake implementation of lookup.Blocker.
|
||||||
type MockBlocker struct {
|
type MockBlocker struct {
|
||||||
BlockToReturn interfaces.ReadOnlySignedBeaconBlock
|
BlockToReturn interfaces.ReadOnlySignedBeaconBlock
|
||||||
|
RootToReturn [32]byte
|
||||||
ErrorToReturn error
|
ErrorToReturn error
|
||||||
SlotBlockMap map[primitives.Slot]interfaces.ReadOnlySignedBeaconBlock
|
SlotBlockMap map[primitives.Slot]interfaces.ReadOnlySignedBeaconBlock
|
||||||
RootBlockMap map[[32]byte]interfaces.ReadOnlySignedBeaconBlock
|
RootBlockMap map[[32]byte]interfaces.ReadOnlySignedBeaconBlock
|
||||||
@@ -39,6 +40,14 @@ func (m *MockBlocker) Block(_ context.Context, b []byte) (interfaces.ReadOnlySig
|
|||||||
return m.SlotBlockMap[primitives.Slot(slotNumber)], nil
|
return m.SlotBlockMap[primitives.Slot(slotNumber)], nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// BlockRoot --
|
||||||
|
func (m *MockBlocker) BlockRoot(_ context.Context, _ []byte) ([32]byte, error) {
|
||||||
|
if m.ErrorToReturn != nil {
|
||||||
|
return [32]byte{}, m.ErrorToReturn
|
||||||
|
}
|
||||||
|
return m.RootToReturn, nil
|
||||||
|
}
|
||||||
|
|
||||||
// BlobSidecars --
|
// BlobSidecars --
|
||||||
func (*MockBlocker) BlobSidecars(_ context.Context, _ string, _ ...options.BlobsOption) ([]*blocks.VerifiedROBlob, *core.RpcError) {
|
func (*MockBlocker) BlobSidecars(_ context.Context, _ string, _ ...options.BlobsOption) ([]*blocks.VerifiedROBlob, *core.RpcError) {
|
||||||
return nil, &core.RpcError{}
|
return nil, &core.RpcError{}
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ type writeOnlyGloasFields interface {
|
|||||||
RotateBuilderPendingPayments() error
|
RotateBuilderPendingPayments() error
|
||||||
AppendBuilderPendingWithdrawals([]*ethpb.BuilderPendingWithdrawal) error
|
AppendBuilderPendingWithdrawals([]*ethpb.BuilderPendingWithdrawal) error
|
||||||
UpdateExecutionPayloadAvailabilityAtIndex(idx uint64, val byte) error
|
UpdateExecutionPayloadAvailabilityAtIndex(idx uint64, val byte) error
|
||||||
UpdatePendingPaymentWeight(att ethpb.Att, indices []uint64, participatedFlags map[uint8]bool) error
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type readOnlyGloasFields interface {
|
type readOnlyGloasFields interface {
|
||||||
@@ -21,8 +20,5 @@ type readOnlyGloasFields interface {
|
|||||||
IsActiveBuilder(primitives.BuilderIndex) (bool, error)
|
IsActiveBuilder(primitives.BuilderIndex) (bool, error)
|
||||||
CanBuilderCoverBid(primitives.BuilderIndex, primitives.Gwei) (bool, error)
|
CanBuilderCoverBid(primitives.BuilderIndex, primitives.Gwei) (bool, error)
|
||||||
LatestBlockHash() ([32]byte, error)
|
LatestBlockHash() ([32]byte, error)
|
||||||
IsAttestationSameSlot(blockRoot [32]byte, slot primitives.Slot) (bool, error)
|
|
||||||
BuilderPendingPayment(index uint64) (*ethpb.BuilderPendingPayment, error)
|
|
||||||
BuilderPendingPayments() ([]*ethpb.BuilderPendingPayment, error)
|
BuilderPendingPayments() ([]*ethpb.BuilderPendingPayment, error)
|
||||||
ExecutionPayloadAvailability(slot primitives.Slot) (uint64, error)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,16 +1,13 @@
|
|||||||
package state_native
|
package state_native
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
"github.com/OffchainLabs/prysm/v7/beacon-chain/core/helpers"
|
|
||||||
fieldparams "github.com/OffchainLabs/prysm/v7/config/fieldparams"
|
fieldparams "github.com/OffchainLabs/prysm/v7/config/fieldparams"
|
||||||
"github.com/OffchainLabs/prysm/v7/config/params"
|
"github.com/OffchainLabs/prysm/v7/config/params"
|
||||||
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
||||||
ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
||||||
"github.com/OffchainLabs/prysm/v7/runtime/version"
|
"github.com/OffchainLabs/prysm/v7/runtime/version"
|
||||||
"github.com/pkg/errors"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// LatestBlockHash returns the hash of the latest execution block.
|
// LatestBlockHash returns the hash of the latest execution block.
|
||||||
@@ -29,45 +26,6 @@ func (b *BeaconState) LatestBlockHash() ([32]byte, error) {
|
|||||||
return [32]byte(b.latestBlockHash), nil
|
return [32]byte(b.latestBlockHash), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsAttestationSameSlot checks if the attestation is for the same slot as the block root in the state.
|
|
||||||
// Spec v1.7.0-alpha pseudocode:
|
|
||||||
//
|
|
||||||
// is_attestation_same_slot(state, data):
|
|
||||||
// if data.slot == 0:
|
|
||||||
// return True
|
|
||||||
//
|
|
||||||
// blockroot = data.beacon_block_root
|
|
||||||
// slot_blockroot = get_block_root_at_slot(state, data.slot)
|
|
||||||
// prev_blockroot = get_block_root_at_slot(state, Slot(data.slot - 1))
|
|
||||||
//
|
|
||||||
// return blockroot == slot_blockroot and blockroot != prev_blockroot
|
|
||||||
func (b *BeaconState) IsAttestationSameSlot(blockRoot [32]byte, slot primitives.Slot) (bool, error) {
|
|
||||||
if b.version < version.Gloas {
|
|
||||||
return false, errNotSupported("IsAttestationSameSlot", b.version)
|
|
||||||
}
|
|
||||||
|
|
||||||
b.lock.RLock()
|
|
||||||
defer b.lock.RUnlock()
|
|
||||||
|
|
||||||
if slot == 0 {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
blockRootAtSlot, err := helpers.BlockRootAtSlot(b, slot)
|
|
||||||
if err != nil {
|
|
||||||
return false, errors.Wrapf(err, "block root at slot %d", slot)
|
|
||||||
}
|
|
||||||
matchingBlockRoot := bytes.Equal(blockRoot[:], blockRootAtSlot)
|
|
||||||
|
|
||||||
blockRootAtPrevSlot, err := helpers.BlockRootAtSlot(b, slot-1)
|
|
||||||
if err != nil {
|
|
||||||
return false, errors.Wrapf(err, "block root at slot %d", slot-1)
|
|
||||||
}
|
|
||||||
matchingPrevBlockRoot := bytes.Equal(blockRoot[:], blockRootAtPrevSlot)
|
|
||||||
|
|
||||||
return matchingBlockRoot && !matchingPrevBlockRoot, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// BuilderPubkey returns the builder pubkey at the provided index.
|
// BuilderPubkey returns the builder pubkey at the provided index.
|
||||||
func (b *BeaconState) BuilderPubkey(builderIndex primitives.BuilderIndex) ([fieldparams.BLSPubkeyLength]byte, error) {
|
func (b *BeaconState) BuilderPubkey(builderIndex primitives.BuilderIndex) ([fieldparams.BLSPubkeyLength]byte, error) {
|
||||||
if b.version < version.Gloas {
|
if b.version < version.Gloas {
|
||||||
@@ -189,36 +147,3 @@ func (b *BeaconState) BuilderPendingPayments() ([]*ethpb.BuilderPendingPayment,
|
|||||||
|
|
||||||
return b.builderPendingPaymentsVal(), nil
|
return b.builderPendingPaymentsVal(), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// BuilderPendingPayment returns the builder pending payment for the given index.
|
|
||||||
func (b *BeaconState) BuilderPendingPayment(index uint64) (*ethpb.BuilderPendingPayment, error) {
|
|
||||||
if b.version < version.Gloas {
|
|
||||||
return nil, errNotSupported("BuilderPendingPayment", b.version)
|
|
||||||
}
|
|
||||||
|
|
||||||
b.lock.RLock()
|
|
||||||
defer b.lock.RUnlock()
|
|
||||||
|
|
||||||
if index >= uint64(len(b.builderPendingPayments)) {
|
|
||||||
return nil, fmt.Errorf("builder pending payment index %d out of range (len=%d)", index, len(b.builderPendingPayments))
|
|
||||||
}
|
|
||||||
return ethpb.CopyBuilderPendingPayment(b.builderPendingPayments[index]), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// ExecutionPayloadAvailability returns the execution payload availability bit for the given slot.
|
|
||||||
func (b *BeaconState) ExecutionPayloadAvailability(slot primitives.Slot) (uint64, error) {
|
|
||||||
if b.version < version.Gloas {
|
|
||||||
return 0, errNotSupported("ExecutionPayloadAvailability", b.version)
|
|
||||||
}
|
|
||||||
|
|
||||||
b.lock.RLock()
|
|
||||||
defer b.lock.RUnlock()
|
|
||||||
|
|
||||||
slotIndex := slot % params.BeaconConfig().SlotsPerHistoricalRoot
|
|
||||||
byteIndex := slotIndex / 8
|
|
||||||
bitIndex := slotIndex % 8
|
|
||||||
|
|
||||||
bit := (b.executionPayloadAvailability[byteIndex] >> bitIndex) & 1
|
|
||||||
|
|
||||||
return uint64(bit), nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -44,92 +44,6 @@ func TestLatestBlockHash(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIsAttestationSameSlot(t *testing.T) {
|
|
||||||
buildStateWithBlockRoots := func(t *testing.T, stateSlot primitives.Slot, roots map[primitives.Slot][]byte) *state_native.BeaconState {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
cfg := params.BeaconConfig()
|
|
||||||
blockRoots := make([][]byte, cfg.SlotsPerHistoricalRoot)
|
|
||||||
for slot, root := range roots {
|
|
||||||
blockRoots[slot%cfg.SlotsPerHistoricalRoot] = root
|
|
||||||
}
|
|
||||||
|
|
||||||
stIface, err := state_native.InitializeFromProtoGloas(ðpb.BeaconStateGloas{
|
|
||||||
Slot: stateSlot,
|
|
||||||
BlockRoots: blockRoots,
|
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
|
||||||
return stIface.(*state_native.BeaconState)
|
|
||||||
}
|
|
||||||
|
|
||||||
rootA := bytes.Repeat([]byte{0xAA}, 32)
|
|
||||||
rootB := bytes.Repeat([]byte{0xBB}, 32)
|
|
||||||
rootC := bytes.Repeat([]byte{0xCC}, 32)
|
|
||||||
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
stateSlot primitives.Slot
|
|
||||||
slot primitives.Slot
|
|
||||||
blockRoot []byte
|
|
||||||
roots map[primitives.Slot][]byte
|
|
||||||
want bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "slot zero always true",
|
|
||||||
stateSlot: 1,
|
|
||||||
slot: 0,
|
|
||||||
blockRoot: rootA,
|
|
||||||
roots: map[primitives.Slot][]byte{},
|
|
||||||
want: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "matching current different previous",
|
|
||||||
stateSlot: 6,
|
|
||||||
slot: 4,
|
|
||||||
blockRoot: rootA,
|
|
||||||
roots: map[primitives.Slot][]byte{
|
|
||||||
4: rootA,
|
|
||||||
3: rootB,
|
|
||||||
},
|
|
||||||
want: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "matching current same previous",
|
|
||||||
stateSlot: 6,
|
|
||||||
slot: 4,
|
|
||||||
blockRoot: rootA,
|
|
||||||
roots: map[primitives.Slot][]byte{
|
|
||||||
4: rootA,
|
|
||||||
3: rootA,
|
|
||||||
},
|
|
||||||
want: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "non matching current",
|
|
||||||
stateSlot: 6,
|
|
||||||
slot: 4,
|
|
||||||
blockRoot: rootC,
|
|
||||||
roots: map[primitives.Slot][]byte{
|
|
||||||
4: rootA,
|
|
||||||
3: rootB,
|
|
||||||
},
|
|
||||||
want: false,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
st := buildStateWithBlockRoots(t, tt.stateSlot, tt.roots)
|
|
||||||
var rootArr [32]byte
|
|
||||||
copy(rootArr[:], tt.blockRoot)
|
|
||||||
|
|
||||||
got, err := st.IsAttestationSameSlot(rootArr, tt.slot)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, tt.want, got)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestBuilderPubkey(t *testing.T) {
|
func TestBuilderPubkey(t *testing.T) {
|
||||||
t.Run("returns error before gloas", func(t *testing.T) {
|
t.Run("returns error before gloas", func(t *testing.T) {
|
||||||
stIface, _ := util.DeterministicGenesisState(t, 1)
|
stIface, _ := util.DeterministicGenesisState(t, 1)
|
||||||
@@ -252,79 +166,3 @@ func TestBuilderPendingPayments_UnsupportedVersion(t *testing.T) {
|
|||||||
_, err = st.BuilderPendingPayments()
|
_, err = st.BuilderPendingPayments()
|
||||||
require.ErrorContains(t, "BuilderPendingPayments", err)
|
require.ErrorContains(t, "BuilderPendingPayments", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestBuilderPendingPayment(t *testing.T) {
|
|
||||||
t.Run("returns copy", func(t *testing.T) {
|
|
||||||
slotsPerEpoch := params.BeaconConfig().SlotsPerEpoch
|
|
||||||
payments := make([]*ethpb.BuilderPendingPayment, 2*slotsPerEpoch)
|
|
||||||
target := uint64(slotsPerEpoch + 1)
|
|
||||||
payments[target] = ðpb.BuilderPendingPayment{Weight: 10}
|
|
||||||
|
|
||||||
st, err := state_native.InitializeFromProtoUnsafeGloas(ðpb.BeaconStateGloas{
|
|
||||||
BuilderPendingPayments: payments,
|
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
payment, err := st.BuilderPendingPayment(target)
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
// mutate returned copy
|
|
||||||
payment.Weight = 99
|
|
||||||
|
|
||||||
original, err := st.BuilderPendingPayment(target)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, uint64(10), uint64(original.Weight))
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("unsupported version", func(t *testing.T) {
|
|
||||||
stIface, err := state_native.InitializeFromProtoElectra(ðpb.BeaconStateElectra{})
|
|
||||||
require.NoError(t, err)
|
|
||||||
st := stIface.(*state_native.BeaconState)
|
|
||||||
|
|
||||||
_, err = st.BuilderPendingPayment(0)
|
|
||||||
require.ErrorContains(t, "BuilderPendingPayment", err)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("out of range", func(t *testing.T) {
|
|
||||||
stIface, err := state_native.InitializeFromProtoUnsafeGloas(ðpb.BeaconStateGloas{
|
|
||||||
BuilderPendingPayments: []*ethpb.BuilderPendingPayment{},
|
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
_, err = stIface.BuilderPendingPayment(0)
|
|
||||||
require.ErrorContains(t, "out of range", err)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestExecutionPayloadAvailability(t *testing.T) {
|
|
||||||
t.Run("unsupported version", func(t *testing.T) {
|
|
||||||
stIface, err := state_native.InitializeFromProtoElectra(ðpb.BeaconStateElectra{})
|
|
||||||
require.NoError(t, err)
|
|
||||||
st := stIface.(*state_native.BeaconState)
|
|
||||||
|
|
||||||
_, err = st.ExecutionPayloadAvailability(0)
|
|
||||||
require.ErrorContains(t, "ExecutionPayloadAvailability", err)
|
|
||||||
})
|
|
||||||
|
|
||||||
t.Run("reads expected bit", func(t *testing.T) {
|
|
||||||
// Ensure the backing slice is large enough.
|
|
||||||
availability := make([]byte, params.BeaconConfig().SlotsPerHistoricalRoot/8)
|
|
||||||
|
|
||||||
// Pick a slot and set its corresponding bit.
|
|
||||||
slot := primitives.Slot(9) // byteIndex=1, bitIndex=1
|
|
||||||
availability[1] = 0b00000010
|
|
||||||
|
|
||||||
stIface, err := state_native.InitializeFromProtoUnsafeGloas(ðpb.BeaconStateGloas{
|
|
||||||
ExecutionPayloadAvailability: availability,
|
|
||||||
})
|
|
||||||
require.NoError(t, err)
|
|
||||||
|
|
||||||
bit, err := stIface.ExecutionPayloadAvailability(slot)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, uint64(1), bit)
|
|
||||||
|
|
||||||
otherBit, err := stIface.ExecutionPayloadAvailability(8)
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, uint64(0), otherBit)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -113,77 +113,100 @@ func (b *BeaconState) ExpectedWithdrawals() ([]*enginev1.Withdrawal, uint64, err
|
|||||||
defer b.lock.RUnlock()
|
defer b.lock.RUnlock()
|
||||||
|
|
||||||
withdrawals := make([]*enginev1.Withdrawal, 0, params.BeaconConfig().MaxWithdrawalsPerPayload)
|
withdrawals := make([]*enginev1.Withdrawal, 0, params.BeaconConfig().MaxWithdrawalsPerPayload)
|
||||||
validatorIndex := b.nextWithdrawalValidatorIndex
|
|
||||||
withdrawalIndex := b.nextWithdrawalIndex
|
withdrawalIndex := b.nextWithdrawalIndex
|
||||||
epoch := slots.ToEpoch(b.slot)
|
|
||||||
|
|
||||||
// Electra partial withdrawals functionality.
|
withdrawalIndex, processedPartialWithdrawalsCount, err := b.appendPendingPartialWithdrawals(withdrawalIndex, &withdrawals)
|
||||||
var processedPartialWithdrawalsCount uint64
|
if err != nil {
|
||||||
if b.version >= version.Electra {
|
return nil, 0, err
|
||||||
for _, w := range b.pendingPartialWithdrawals {
|
|
||||||
if w.WithdrawableEpoch > epoch || len(withdrawals) >= int(params.BeaconConfig().MaxPendingPartialsPerWithdrawalsSweep) {
|
|
||||||
break
|
|
||||||
}
|
|
||||||
|
|
||||||
v, err := b.validatorAtIndexReadOnly(w.Index)
|
|
||||||
if err != nil {
|
|
||||||
return nil, 0, fmt.Errorf("failed to determine withdrawals at index %d: %w", w.Index, err)
|
|
||||||
}
|
|
||||||
vBal, err := b.balanceAtIndex(w.Index)
|
|
||||||
if err != nil {
|
|
||||||
return nil, 0, fmt.Errorf("could not retrieve balance at index %d: %w", w.Index, err)
|
|
||||||
}
|
|
||||||
hasSufficientEffectiveBalance := v.EffectiveBalance() >= params.BeaconConfig().MinActivationBalance
|
|
||||||
var totalWithdrawn uint64
|
|
||||||
for _, wi := range withdrawals {
|
|
||||||
if wi.ValidatorIndex == w.Index {
|
|
||||||
totalWithdrawn += wi.Amount
|
|
||||||
}
|
|
||||||
}
|
|
||||||
balance, err := mathutil.Sub64(vBal, totalWithdrawn)
|
|
||||||
if err != nil {
|
|
||||||
return nil, 0, errors.Wrapf(err, "failed to subtract balance %d with total withdrawn %d", vBal, totalWithdrawn)
|
|
||||||
}
|
|
||||||
hasExcessBalance := balance > params.BeaconConfig().MinActivationBalance
|
|
||||||
if v.ExitEpoch() == params.BeaconConfig().FarFutureEpoch && hasSufficientEffectiveBalance && hasExcessBalance {
|
|
||||||
amount := min(balance-params.BeaconConfig().MinActivationBalance, w.Amount)
|
|
||||||
withdrawals = append(withdrawals, &enginev1.Withdrawal{
|
|
||||||
Index: withdrawalIndex,
|
|
||||||
ValidatorIndex: w.Index,
|
|
||||||
Address: v.GetWithdrawalCredentials()[12:],
|
|
||||||
Amount: amount,
|
|
||||||
})
|
|
||||||
withdrawalIndex++
|
|
||||||
}
|
|
||||||
processedPartialWithdrawalsCount++
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
err = b.appendValidatorsSweepWithdrawals(withdrawalIndex, &withdrawals)
|
||||||
|
if err != nil {
|
||||||
|
return nil, 0, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return withdrawals, processedPartialWithdrawalsCount, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BeaconState) appendPendingPartialWithdrawals(withdrawalIndex uint64, withdrawals *[]*enginev1.Withdrawal) (uint64, uint64, error) {
|
||||||
|
if b.version < version.Electra {
|
||||||
|
return withdrawalIndex, 0, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
ws := *withdrawals
|
||||||
|
epoch := slots.ToEpoch(b.slot)
|
||||||
|
var processedPartialWithdrawalsCount uint64
|
||||||
|
for _, w := range b.pendingPartialWithdrawals {
|
||||||
|
if w.WithdrawableEpoch > epoch || len(ws) >= int(params.BeaconConfig().MaxPendingPartialsPerWithdrawalsSweep) {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
v, err := b.validatorAtIndexReadOnly(w.Index)
|
||||||
|
if err != nil {
|
||||||
|
return withdrawalIndex, 0, fmt.Errorf("failed to determine withdrawals at index %d: %w", w.Index, err)
|
||||||
|
}
|
||||||
|
vBal, err := b.balanceAtIndex(w.Index)
|
||||||
|
if err != nil {
|
||||||
|
return withdrawalIndex, 0, fmt.Errorf("could not retrieve balance at index %d: %w", w.Index, err)
|
||||||
|
}
|
||||||
|
hasSufficientEffectiveBalance := v.EffectiveBalance() >= params.BeaconConfig().MinActivationBalance
|
||||||
|
var totalWithdrawn uint64
|
||||||
|
for _, wi := range ws {
|
||||||
|
if wi.ValidatorIndex == w.Index {
|
||||||
|
totalWithdrawn += wi.Amount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
balance, err := mathutil.Sub64(vBal, totalWithdrawn)
|
||||||
|
if err != nil {
|
||||||
|
return withdrawalIndex, 0, errors.Wrapf(err, "failed to subtract balance %d with total withdrawn %d", vBal, totalWithdrawn)
|
||||||
|
}
|
||||||
|
hasExcessBalance := balance > params.BeaconConfig().MinActivationBalance
|
||||||
|
if v.ExitEpoch() == params.BeaconConfig().FarFutureEpoch && hasSufficientEffectiveBalance && hasExcessBalance {
|
||||||
|
amount := min(balance-params.BeaconConfig().MinActivationBalance, w.Amount)
|
||||||
|
ws = append(ws, &enginev1.Withdrawal{
|
||||||
|
Index: withdrawalIndex,
|
||||||
|
ValidatorIndex: w.Index,
|
||||||
|
Address: v.GetWithdrawalCredentials()[12:],
|
||||||
|
Amount: amount,
|
||||||
|
})
|
||||||
|
withdrawalIndex++
|
||||||
|
}
|
||||||
|
processedPartialWithdrawalsCount++
|
||||||
|
}
|
||||||
|
|
||||||
|
*withdrawals = ws
|
||||||
|
return withdrawalIndex, processedPartialWithdrawalsCount, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (b *BeaconState) appendValidatorsSweepWithdrawals(withdrawalIndex uint64, withdrawals *[]*enginev1.Withdrawal) error {
|
||||||
|
ws := *withdrawals
|
||||||
|
validatorIndex := b.nextWithdrawalValidatorIndex
|
||||||
validatorsLen := b.validatorsLen()
|
validatorsLen := b.validatorsLen()
|
||||||
|
epoch := slots.ToEpoch(b.slot)
|
||||||
bound := min(uint64(validatorsLen), params.BeaconConfig().MaxValidatorsPerWithdrawalsSweep)
|
bound := min(uint64(validatorsLen), params.BeaconConfig().MaxValidatorsPerWithdrawalsSweep)
|
||||||
for range bound {
|
for range bound {
|
||||||
val, err := b.validatorAtIndexReadOnly(validatorIndex)
|
val, err := b.validatorAtIndexReadOnly(validatorIndex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, errors.Wrapf(err, "could not retrieve validator at index %d", validatorIndex)
|
return errors.Wrapf(err, "could not retrieve validator at index %d", validatorIndex)
|
||||||
}
|
}
|
||||||
balance, err := b.balanceAtIndex(validatorIndex)
|
balance, err := b.balanceAtIndex(validatorIndex)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, errors.Wrapf(err, "could not retrieve balance at index %d", validatorIndex)
|
return errors.Wrapf(err, "could not retrieve balance at index %d", validatorIndex)
|
||||||
}
|
}
|
||||||
if b.version >= version.Electra {
|
if b.version >= version.Electra {
|
||||||
var partiallyWithdrawnBalance uint64
|
var partiallyWithdrawnBalance uint64
|
||||||
for _, w := range withdrawals {
|
for _, w := range ws {
|
||||||
if w.ValidatorIndex == validatorIndex {
|
if w.ValidatorIndex == validatorIndex {
|
||||||
partiallyWithdrawnBalance += w.Amount
|
partiallyWithdrawnBalance += w.Amount
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
balance, err = mathutil.Sub64(balance, partiallyWithdrawnBalance)
|
balance, err = mathutil.Sub64(balance, partiallyWithdrawnBalance)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, 0, errors.Wrapf(err, "could not subtract balance %d with partial withdrawn balance %d", balance, partiallyWithdrawnBalance)
|
return errors.Wrapf(err, "could not subtract balance %d with partial withdrawn balance %d", balance, partiallyWithdrawnBalance)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if helpers.IsFullyWithdrawableValidator(val, balance, epoch, b.version) {
|
if helpers.IsFullyWithdrawableValidator(val, balance, epoch, b.version) {
|
||||||
withdrawals = append(withdrawals, &enginev1.Withdrawal{
|
ws = append(ws, &enginev1.Withdrawal{
|
||||||
Index: withdrawalIndex,
|
Index: withdrawalIndex,
|
||||||
ValidatorIndex: validatorIndex,
|
ValidatorIndex: validatorIndex,
|
||||||
Address: bytesutil.SafeCopyBytes(val.GetWithdrawalCredentials()[ETH1AddressOffset:]),
|
Address: bytesutil.SafeCopyBytes(val.GetWithdrawalCredentials()[ETH1AddressOffset:]),
|
||||||
@@ -191,7 +214,7 @@ func (b *BeaconState) ExpectedWithdrawals() ([]*enginev1.Withdrawal, uint64, err
|
|||||||
})
|
})
|
||||||
withdrawalIndex++
|
withdrawalIndex++
|
||||||
} else if helpers.IsPartiallyWithdrawableValidator(val, balance, epoch, b.version) {
|
} else if helpers.IsPartiallyWithdrawableValidator(val, balance, epoch, b.version) {
|
||||||
withdrawals = append(withdrawals, &enginev1.Withdrawal{
|
ws = append(ws, &enginev1.Withdrawal{
|
||||||
Index: withdrawalIndex,
|
Index: withdrawalIndex,
|
||||||
ValidatorIndex: validatorIndex,
|
ValidatorIndex: validatorIndex,
|
||||||
Address: bytesutil.SafeCopyBytes(val.GetWithdrawalCredentials()[ETH1AddressOffset:]),
|
Address: bytesutil.SafeCopyBytes(val.GetWithdrawalCredentials()[ETH1AddressOffset:]),
|
||||||
@@ -199,7 +222,7 @@ func (b *BeaconState) ExpectedWithdrawals() ([]*enginev1.Withdrawal, uint64, err
|
|||||||
})
|
})
|
||||||
withdrawalIndex++
|
withdrawalIndex++
|
||||||
}
|
}
|
||||||
if uint64(len(withdrawals)) == params.BeaconConfig().MaxWithdrawalsPerPayload {
|
if uint64(len(ws)) == params.BeaconConfig().MaxWithdrawalsPerPayload {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
validatorIndex += 1
|
validatorIndex += 1
|
||||||
@@ -208,7 +231,8 @@ func (b *BeaconState) ExpectedWithdrawals() ([]*enginev1.Withdrawal, uint64, err
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return withdrawals, processedPartialWithdrawalsCount, nil
|
*withdrawals = ws
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (b *BeaconState) PendingPartialWithdrawals() ([]*ethpb.PendingPartialWithdrawal, error) {
|
func (b *BeaconState) PendingPartialWithdrawals() ([]*ethpb.PendingPartialWithdrawal, error) {
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import (
|
|||||||
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
||||||
ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
||||||
"github.com/OffchainLabs/prysm/v7/runtime/version"
|
"github.com/OffchainLabs/prysm/v7/runtime/version"
|
||||||
"github.com/OffchainLabs/prysm/v7/time/slots"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// RotateBuilderPendingPayments rotates the queue by dropping slots per epoch payments from the
|
// RotateBuilderPendingPayments rotates the queue by dropping slots per epoch payments from the
|
||||||
@@ -162,123 +161,3 @@ func (b *BeaconState) UpdateExecutionPayloadAvailabilityAtIndex(idx uint64, val
|
|||||||
b.markFieldAsDirty(types.ExecutionPayloadAvailability)
|
b.markFieldAsDirty(types.ExecutionPayloadAvailability)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdatePendingPaymentWeight updates the builder pending payment weight based on attestation participation.
|
|
||||||
//
|
|
||||||
// This is a no-op for pre-Gloas forks.
|
|
||||||
//
|
|
||||||
// Spec v1.7.0-alpha pseudocode:
|
|
||||||
//
|
|
||||||
// if data.target.epoch == get_current_epoch(state):
|
|
||||||
// current_epoch_target = True
|
|
||||||
// epoch_participation = state.current_epoch_participation
|
|
||||||
// payment = state.builder_pending_payments[SLOTS_PER_EPOCH + data.slot % SLOTS_PER_EPOCH]
|
|
||||||
// else:
|
|
||||||
// current_epoch_target = False
|
|
||||||
// epoch_participation = state.previous_epoch_participation
|
|
||||||
// payment = state.builder_pending_payments[data.slot % SLOTS_PER_EPOCH]
|
|
||||||
//
|
|
||||||
// proposer_reward_numerator = 0
|
|
||||||
// for index in get_attesting_indices(state, attestation):
|
|
||||||
// will_set_new_flag = False
|
|
||||||
// for flag_index, weight in enumerate(PARTICIPATION_FLAG_WEIGHTS):
|
|
||||||
// if flag_index in participation_flag_indices and not has_flag(epoch_participation[index], flag_index):
|
|
||||||
// epoch_participation[index] = add_flag(epoch_participation[index], flag_index)
|
|
||||||
// proposer_reward_numerator += get_base_reward(state, index) * weight
|
|
||||||
// # [New in Gloas:EIP7732]
|
|
||||||
// will_set_new_flag = True
|
|
||||||
// if (
|
|
||||||
// will_set_new_flag
|
|
||||||
// and is_attestation_same_slot(state, data)
|
|
||||||
// and payment.withdrawal.amount > 0
|
|
||||||
// ):
|
|
||||||
// payment.weight += state.validators[index].effective_balance
|
|
||||||
// if current_epoch_target:
|
|
||||||
// state.builder_pending_payments[SLOTS_PER_EPOCH + data.slot % SLOTS_PER_EPOCH] = payment
|
|
||||||
// else:
|
|
||||||
// state.builder_pending_payments[data.slot % SLOTS_PER_EPOCH] = payment
|
|
||||||
func (b *BeaconState) UpdatePendingPaymentWeight(att ethpb.Att, indices []uint64, participatedFlags map[uint8]bool) error {
|
|
||||||
var (
|
|
||||||
paymentSlot primitives.Slot
|
|
||||||
currentPayment *ethpb.BuilderPendingPayment
|
|
||||||
weight primitives.Gwei
|
|
||||||
)
|
|
||||||
|
|
||||||
early, err := func() (bool, error) {
|
|
||||||
b.lock.RLock()
|
|
||||||
defer b.lock.RUnlock()
|
|
||||||
|
|
||||||
if b.version < version.Gloas {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
data := att.GetData()
|
|
||||||
var beaconBlockRoot [32]byte
|
|
||||||
copy(beaconBlockRoot[:], data.BeaconBlockRoot)
|
|
||||||
sameSlot, err := b.IsAttestationSameSlot(beaconBlockRoot, data.Slot)
|
|
||||||
if err != nil {
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
if !sameSlot {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
slotsPerEpoch := params.BeaconConfig().SlotsPerEpoch
|
|
||||||
var epochParticipation []byte
|
|
||||||
|
|
||||||
if data.Target != nil && data.Target.Epoch == slots.ToEpoch(b.slot) {
|
|
||||||
paymentSlot = slotsPerEpoch + (data.Slot % slotsPerEpoch)
|
|
||||||
epochParticipation = b.currentEpochParticipation
|
|
||||||
} else {
|
|
||||||
paymentSlot = data.Slot % slotsPerEpoch
|
|
||||||
epochParticipation = b.previousEpochParticipation
|
|
||||||
}
|
|
||||||
|
|
||||||
if uint64(paymentSlot) >= uint64(len(b.builderPendingPayments)) {
|
|
||||||
return false, fmt.Errorf("builder pending payments index %d out of range (len=%d)", paymentSlot, len(b.builderPendingPayments))
|
|
||||||
}
|
|
||||||
currentPayment = b.builderPendingPayments[paymentSlot]
|
|
||||||
if currentPayment.Withdrawal.Amount == 0 {
|
|
||||||
return true, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
cfg := params.BeaconConfig()
|
|
||||||
flagIndices := []uint8{cfg.TimelySourceFlagIndex, cfg.TimelyTargetFlagIndex, cfg.TimelyHeadFlagIndex}
|
|
||||||
for _, idx := range indices {
|
|
||||||
if idx >= uint64(len(epochParticipation)) {
|
|
||||||
return false, fmt.Errorf("index %d exceeds participation length %d", idx, len(epochParticipation))
|
|
||||||
}
|
|
||||||
participation := epochParticipation[idx]
|
|
||||||
for _, f := range flagIndices {
|
|
||||||
if !participatedFlags[f] {
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if participation&(1<<f) == 0 {
|
|
||||||
v, err := b.validatorAtIndexReadOnly(primitives.ValidatorIndex(idx))
|
|
||||||
if err != nil {
|
|
||||||
return false, fmt.Errorf("validator at index %d: %w", idx, err)
|
|
||||||
}
|
|
||||||
weight += primitives.Gwei(v.EffectiveBalance())
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false, nil
|
|
||||||
}()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
if early || weight == 0 {
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
b.lock.Lock()
|
|
||||||
defer b.lock.Unlock()
|
|
||||||
|
|
||||||
newPayment := ethpb.CopyBuilderPendingPayment(currentPayment)
|
|
||||||
newPayment.Weight += weight
|
|
||||||
b.builderPendingPayments[paymentSlot] = newPayment
|
|
||||||
b.markFieldAsDirty(types.BuilderPendingPayments)
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import (
|
|||||||
ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
ethpb "github.com/OffchainLabs/prysm/v7/proto/prysm/v1alpha1"
|
||||||
"github.com/OffchainLabs/prysm/v7/runtime/version"
|
"github.com/OffchainLabs/prysm/v7/runtime/version"
|
||||||
"github.com/OffchainLabs/prysm/v7/testing/require"
|
"github.com/OffchainLabs/prysm/v7/testing/require"
|
||||||
"github.com/OffchainLabs/prysm/v7/time/slots"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type testExecutionPayloadBid struct {
|
type testExecutionPayloadBid struct {
|
||||||
@@ -182,99 +181,6 @@ func TestClearBuilderPendingPayment(t *testing.T) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestUpdatePendingPaymentWeight(t *testing.T) {
|
|
||||||
cfg := params.BeaconConfig()
|
|
||||||
slotsPerEpoch := cfg.SlotsPerEpoch
|
|
||||||
slot := primitives.Slot(4)
|
|
||||||
stateSlot := slot + 1
|
|
||||||
stateEpoch := slots.ToEpoch(stateSlot)
|
|
||||||
|
|
||||||
rootA := bytes.Repeat([]byte{0xAA}, 32)
|
|
||||||
rootB := bytes.Repeat([]byte{0xBB}, 32)
|
|
||||||
|
|
||||||
tests := []struct {
|
|
||||||
name string
|
|
||||||
targetEpoch primitives.Epoch
|
|
||||||
blockRoot []byte
|
|
||||||
initialAmount primitives.Gwei
|
|
||||||
initialWeight primitives.Gwei
|
|
||||||
wantWeight primitives.Gwei
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
name: "same slot current epoch adds weight",
|
|
||||||
targetEpoch: stateEpoch,
|
|
||||||
blockRoot: rootA,
|
|
||||||
initialAmount: 1,
|
|
||||||
initialWeight: 0,
|
|
||||||
wantWeight: primitives.Gwei(cfg.MinActivationBalance),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "same slot zero amount no weight change",
|
|
||||||
targetEpoch: stateEpoch,
|
|
||||||
blockRoot: rootA,
|
|
||||||
initialAmount: 0,
|
|
||||||
initialWeight: 5,
|
|
||||||
wantWeight: 5,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "non matching block root no change",
|
|
||||||
targetEpoch: stateEpoch,
|
|
||||||
blockRoot: rootB,
|
|
||||||
initialAmount: 1,
|
|
||||||
initialWeight: 7,
|
|
||||||
wantWeight: 7,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "previous epoch target uses earlier slot",
|
|
||||||
targetEpoch: stateEpoch - 1,
|
|
||||||
blockRoot: rootA,
|
|
||||||
initialAmount: 1,
|
|
||||||
initialWeight: 0,
|
|
||||||
wantWeight: primitives.Gwei(cfg.MinActivationBalance),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
for _, tt := range tests {
|
|
||||||
t.Run(tt.name, func(t *testing.T) {
|
|
||||||
var paymentIdx int
|
|
||||||
if tt.targetEpoch == stateEpoch {
|
|
||||||
paymentIdx = int(slotsPerEpoch + (slot % slotsPerEpoch))
|
|
||||||
} else {
|
|
||||||
paymentIdx = int(slot % slotsPerEpoch)
|
|
||||||
}
|
|
||||||
state := buildGloasStateForPaymentWeightTest(t, stateSlot, paymentIdx, tt.initialAmount, tt.initialWeight, map[primitives.Slot][]byte{
|
|
||||||
slot: tt.blockRoot,
|
|
||||||
slot - 1: rootB,
|
|
||||||
})
|
|
||||||
|
|
||||||
att := ðpb.Attestation{
|
|
||||||
Data: ðpb.AttestationData{
|
|
||||||
Slot: slot,
|
|
||||||
CommitteeIndex: 0,
|
|
||||||
BeaconBlockRoot: tt.blockRoot,
|
|
||||||
Source: ðpb.Checkpoint{},
|
|
||||||
Target: ðpb.Checkpoint{
|
|
||||||
Epoch: tt.targetEpoch,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
participatedFlags := map[uint8]bool{
|
|
||||||
cfg.TimelySourceFlagIndex: true,
|
|
||||||
cfg.TimelyTargetFlagIndex: true,
|
|
||||||
cfg.TimelyHeadFlagIndex: true,
|
|
||||||
}
|
|
||||||
indices := []uint64{0}
|
|
||||||
|
|
||||||
require.NoError(t, state.UpdatePendingPaymentWeight(att, indices, participatedFlags))
|
|
||||||
|
|
||||||
payment, err := state.BuilderPendingPayment(uint64(paymentIdx))
|
|
||||||
require.NoError(t, err)
|
|
||||||
require.Equal(t, tt.wantWeight, payment.Weight)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestRotateBuilderPendingPayments(t *testing.T) {
|
func TestRotateBuilderPendingPayments(t *testing.T) {
|
||||||
totalPayments := 2 * params.BeaconConfig().SlotsPerEpoch
|
totalPayments := 2 * params.BeaconConfig().SlotsPerEpoch
|
||||||
payments := make([]*ethpb.BuilderPendingPayment, totalPayments)
|
payments := make([]*ethpb.BuilderPendingPayment, totalPayments)
|
||||||
@@ -412,79 +318,6 @@ func TestUpdateExecutionPayloadAvailabilityAtIndex_OutOfRange(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildGloasStateForPaymentWeightTest(
|
|
||||||
t *testing.T,
|
|
||||||
stateSlot primitives.Slot,
|
|
||||||
paymentIdx int,
|
|
||||||
amount primitives.Gwei,
|
|
||||||
weight primitives.Gwei,
|
|
||||||
roots map[primitives.Slot][]byte,
|
|
||||||
) *BeaconState {
|
|
||||||
t.Helper()
|
|
||||||
|
|
||||||
cfg := params.BeaconConfig()
|
|
||||||
blockRoots := make([][]byte, cfg.SlotsPerHistoricalRoot)
|
|
||||||
for slot, root := range roots {
|
|
||||||
blockRoots[slot%cfg.SlotsPerHistoricalRoot] = root
|
|
||||||
}
|
|
||||||
|
|
||||||
stateRoots := make([][]byte, cfg.SlotsPerHistoricalRoot)
|
|
||||||
for i := range stateRoots {
|
|
||||||
stateRoots[i] = bytes.Repeat([]byte{0x44}, 32)
|
|
||||||
}
|
|
||||||
randaoMixes := make([][]byte, cfg.EpochsPerHistoricalVector)
|
|
||||||
for i := range randaoMixes {
|
|
||||||
randaoMixes[i] = bytes.Repeat([]byte{0x55}, 32)
|
|
||||||
}
|
|
||||||
|
|
||||||
validator := ðpb.Validator{
|
|
||||||
PublicKey: bytes.Repeat([]byte{0x01}, 48),
|
|
||||||
WithdrawalCredentials: append([]byte{cfg.ETH1AddressWithdrawalPrefixByte}, bytes.Repeat([]byte{0x02}, 31)...),
|
|
||||||
EffectiveBalance: cfg.MinActivationBalance,
|
|
||||||
}
|
|
||||||
|
|
||||||
payments := make([]*ethpb.BuilderPendingPayment, cfg.SlotsPerEpoch*2)
|
|
||||||
for i := range payments {
|
|
||||||
payments[i] = ðpb.BuilderPendingPayment{
|
|
||||||
Withdrawal: ðpb.BuilderPendingWithdrawal{
|
|
||||||
FeeRecipient: make([]byte, 20),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
payments[paymentIdx] = ðpb.BuilderPendingPayment{
|
|
||||||
Weight: weight,
|
|
||||||
Withdrawal: ðpb.BuilderPendingWithdrawal{
|
|
||||||
FeeRecipient: make([]byte, 20),
|
|
||||||
Amount: amount,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
execPayloadAvailability := make([]byte, cfg.SlotsPerHistoricalRoot/8)
|
|
||||||
|
|
||||||
stProto := ðpb.BeaconStateGloas{
|
|
||||||
Slot: stateSlot,
|
|
||||||
GenesisValidatorsRoot: bytes.Repeat([]byte{0x33}, 32),
|
|
||||||
BlockRoots: blockRoots,
|
|
||||||
StateRoots: stateRoots,
|
|
||||||
RandaoMixes: randaoMixes,
|
|
||||||
ExecutionPayloadAvailability: execPayloadAvailability,
|
|
||||||
Validators: []*ethpb.Validator{validator},
|
|
||||||
Balances: []uint64{cfg.MinActivationBalance},
|
|
||||||
CurrentEpochParticipation: []byte{0},
|
|
||||||
PreviousEpochParticipation: []byte{0},
|
|
||||||
BuilderPendingPayments: payments,
|
|
||||||
Fork: ðpb.Fork{
|
|
||||||
CurrentVersion: bytes.Repeat([]byte{0x66}, 4),
|
|
||||||
PreviousVersion: bytes.Repeat([]byte{0x66}, 4),
|
|
||||||
Epoch: 0,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
statePb, err := InitializeFromProtoGloas(stProto)
|
|
||||||
require.NoError(t, err)
|
|
||||||
return statePb.(*BeaconState)
|
|
||||||
}
|
|
||||||
|
|
||||||
func newGloasStateWithAvailability(t *testing.T, availability []byte) *BeaconState {
|
func newGloasStateWithAvailability(t *testing.T, availability []byte) *BeaconState {
|
||||||
t.Helper()
|
t.Helper()
|
||||||
|
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ func (s *State) migrateToColdHdiff(ctx context.Context, fRoot [32]byte) error {
|
|||||||
if ctx.Err() != nil {
|
if ctx.Err() != nil {
|
||||||
return ctx.Err()
|
return ctx.Err()
|
||||||
}
|
}
|
||||||
_, lvl, err := s.beaconDB.SlotInDiffTree(slot)
|
offset, lvl, err := s.beaconDB.SlotInDiffTree(slot)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.WithError(err).Errorf("could not determine if slot %d is in diff tree", slot)
|
log.WithError(err).Errorf("could not determine if slot %d is in diff tree", slot)
|
||||||
continue
|
continue
|
||||||
@@ -145,6 +145,9 @@ func (s *State) migrateToColdHdiff(ctx context.Context, fRoot [32]byte) error {
|
|||||||
if lvl == -1 {
|
if lvl == -1 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
if uint64(slot) == offset {
|
||||||
|
continue
|
||||||
|
}
|
||||||
// The state needs to be saved.
|
// The state needs to be saved.
|
||||||
// Try the epoch boundary cache first.
|
// Try the epoch boundary cache first.
|
||||||
cached, exists, err := s.epochBoundaryStateCache.getBySlot(slot)
|
cached, exists, err := s.epochBoundaryStateCache.getBySlot(slot)
|
||||||
|
|||||||
@@ -1027,10 +1027,10 @@ func TestGetVerifyingStateEdgeCases(t *testing.T) {
|
|||||||
sc: signatureCache,
|
sc: signatureCache,
|
||||||
sr: &mockStateByRooter{sbr: sbrErrorIfCalled(t)}, // Should not be called
|
sr: &mockStateByRooter{sbr: sbrErrorIfCalled(t)}, // Should not be called
|
||||||
hsp: &mockHeadStateProvider{
|
hsp: &mockHeadStateProvider{
|
||||||
headRoot: parentRoot[:], // Same as parent
|
headRoot: parentRoot[:], // Same as parent
|
||||||
headSlot: 32, // Epoch 1
|
headSlot: 32, // Epoch 1
|
||||||
headState: fuluState.Copy(), // HeadState (not ReadOnly) for ProcessSlots
|
headState: fuluState.Copy(), // HeadState (not ReadOnly) for ProcessSlots
|
||||||
headStateReadOnly: nil, // Should not use ReadOnly path
|
headStateReadOnly: nil, // Should not use ReadOnly path
|
||||||
},
|
},
|
||||||
fc: &mockForkchoicer{
|
fc: &mockForkchoicer{
|
||||||
// Return same root for both to simulate same chain
|
// Return same root for both to simulate same chain
|
||||||
@@ -1045,8 +1045,8 @@ func TestGetVerifyingStateEdgeCases(t *testing.T) {
|
|||||||
// Wrap to detect HeadState call
|
// Wrap to detect HeadState call
|
||||||
originalHsp := initializer.shared.hsp.(*mockHeadStateProvider)
|
originalHsp := initializer.shared.hsp.(*mockHeadStateProvider)
|
||||||
wrappedHsp := &mockHeadStateProvider{
|
wrappedHsp := &mockHeadStateProvider{
|
||||||
headRoot: originalHsp.headRoot,
|
headRoot: originalHsp.headRoot,
|
||||||
headSlot: originalHsp.headSlot,
|
headSlot: originalHsp.headSlot,
|
||||||
headState: originalHsp.headState,
|
headState: originalHsp.headState,
|
||||||
}
|
}
|
||||||
initializer.shared.hsp = &headStateCallTracker{
|
initializer.shared.hsp = &headStateCallTracker{
|
||||||
|
|||||||
3
changelog/bastin_add-cmd-to-gen-log.md
Normal file
3
changelog/bastin_add-cmd-to-gen-log.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
### Ignored
|
||||||
|
|
||||||
|
- add `cmd` and all it's subcategories to the log.go generation process.
|
||||||
3
changelog/bastin_add-version-log-at-startup.md
Normal file
3
changelog/bastin_add-version-log-at-startup.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
### Added
|
||||||
|
|
||||||
|
- Added a version log at startup to display the version of the build.
|
||||||
3
changelog/bastin_fix-check-logs-bug.md
Normal file
3
changelog/bastin_fix-check-logs-bug.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed a bug in `hack/check-logs.sh` where untracked files were ignored.
|
||||||
3
changelog/bastin_path-ephemeral-log.md
Normal file
3
changelog/bastin_path-ephemeral-log.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
### Ignored
|
||||||
|
|
||||||
|
- Added a field `path` for the ephemeral log file initialization log.
|
||||||
3
changelog/farazdagi_fix-hashtree-darwin-amd64.md
Normal file
3
changelog/farazdagi_fix-hashtree-darwin-amd64.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fix Bazel build failure on macOS x86_64 (darwin_amd64) (adds missing assembly stub to hashtree patch).
|
||||||
3
changelog/james-prysm_blocker-for-block-root.md
Normal file
3
changelog/james-prysm_blocker-for-block-root.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
### Ignored
|
||||||
|
|
||||||
|
- optimizing /eth/v1/beacon/blocks/{block_id}/root endpoint by reusing blocker lookup instead of duplicated logic.
|
||||||
3
changelog/james-prysm_gloas-getblockv2-rest.md
Normal file
3
changelog/james-prysm_gloas-getblockv2-rest.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
### Added
|
||||||
|
|
||||||
|
- gloas block return support for /eth/v2/beacon/blocks/{block_id} and /eth/v1/beacon/blocks/{block_id}/root endpoints.
|
||||||
2
changelog/potuz_hashtree_builds.md
Normal file
2
changelog/potuz_hashtree_builds.md
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
### Fixed
|
||||||
|
- Fix hashtree release builds.
|
||||||
3
changelog/potuz_hdiff_start_db.md
Normal file
3
changelog/potuz_hdiff_start_db.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
### Added
|
||||||
|
|
||||||
|
- Initialize db with state-diff feature flag.
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
### Added
|
|
||||||
|
|
||||||
- Added process attestation for gloas
|
|
||||||
2
changelog/terencechain_core-requests.md
Normal file
2
changelog/terencechain_core-requests.md
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
### Ignored
|
||||||
|
- Move withdrawal/consolidation request processing into `beacon-chain/core/requests` to avoid fork/package dependency cycles.
|
||||||
2
changelog/terencechain_gloas-duty-timings.md
Normal file
2
changelog/terencechain_gloas-duty-timings.md
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
### Added
|
||||||
|
- Gloas-specific timing intervals for validator attestation, aggregation, and sync duties.
|
||||||
2
changelog/terencechain_refactor-expected-withdrawals.md
Normal file
2
changelog/terencechain_refactor-expected-withdrawals.md
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
### Ignored
|
||||||
|
- Refactor expected withdrawals into reusable helpers for future forks.
|
||||||
3
changelog/ttsao_add-gloas-process-payload-att.md
Normal file
3
changelog/ttsao_add-gloas-process-payload-att.md
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
### Added
|
||||||
|
|
||||||
|
- Add Gloas process payload attestation
|
||||||
@@ -9,6 +9,7 @@ go_library(
|
|||||||
"defaults.go",
|
"defaults.go",
|
||||||
"flags.go",
|
"flags.go",
|
||||||
"helpers.go",
|
"helpers.go",
|
||||||
|
"log.go",
|
||||||
"password_reader.go",
|
"password_reader.go",
|
||||||
"wrap_flags.go",
|
"wrap_flags.go",
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ load("@prysm//tools/go:def.bzl", "go_library")
|
|||||||
|
|
||||||
go_library(
|
go_library(
|
||||||
name = "go_default_library",
|
name = "go_default_library",
|
||||||
srcs = ["db.go"],
|
srcs = [
|
||||||
|
"db.go",
|
||||||
|
"log.go",
|
||||||
|
],
|
||||||
importpath = "github.com/OffchainLabs/prysm/v7/cmd/beacon-chain/db",
|
importpath = "github.com/OffchainLabs/prysm/v7/cmd/beacon-chain/db",
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
deps = [
|
deps = [
|
||||||
|
|||||||
@@ -4,12 +4,9 @@ import (
|
|||||||
beacondb "github.com/OffchainLabs/prysm/v7/beacon-chain/db"
|
beacondb "github.com/OffchainLabs/prysm/v7/beacon-chain/db"
|
||||||
"github.com/OffchainLabs/prysm/v7/cmd"
|
"github.com/OffchainLabs/prysm/v7/cmd"
|
||||||
"github.com/OffchainLabs/prysm/v7/runtime/tos"
|
"github.com/OffchainLabs/prysm/v7/runtime/tos"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var log = logrus.WithField("prefix", "db")
|
|
||||||
|
|
||||||
// Commands for interacting with a beacon chain database.
|
// Commands for interacting with a beacon chain database.
|
||||||
var Commands = &cli.Command{
|
var Commands = &cli.Command{
|
||||||
Name: "db",
|
Name: "db",
|
||||||
|
|||||||
9
cmd/beacon-chain/db/log.go
Normal file
9
cmd/beacon-chain/db/log.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
// Code generated by hack/gen-logs.sh; DO NOT EDIT.
|
||||||
|
// This file is created and regenerated automatically. Anything added here might get removed.
|
||||||
|
package db
|
||||||
|
|
||||||
|
import "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
// The prefix for logs from this package will be the text after the last slash in the package path.
|
||||||
|
// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file.
|
||||||
|
var log = logrus.WithField("package", "cmd/beacon-chain/db")
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
|
// Code generated by hack/gen-logs.sh; DO NOT EDIT.
|
||||||
|
// This file is created and regenerated automatically. Anything added here might get removed.
|
||||||
package flags
|
package flags
|
||||||
|
|
||||||
import "github.com/sirupsen/logrus"
|
import "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
var log = logrus.WithField("prefix", "flags")
|
// The prefix for logs from this package will be the text after the last slash in the package path.
|
||||||
|
// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file.
|
||||||
|
var log = logrus.WithField("package", "cmd/beacon-chain/flags")
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
|
// Code generated by hack/gen-logs.sh; DO NOT EDIT.
|
||||||
|
// This file is created and regenerated automatically. Anything added here might get removed.
|
||||||
package genesis
|
package genesis
|
||||||
|
|
||||||
import "github.com/sirupsen/logrus"
|
import "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
var log = logrus.WithField("prefix", "genesis")
|
// The prefix for logs from this package will be the text after the last slash in the package path.
|
||||||
|
// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file.
|
||||||
|
var log = logrus.WithField("package", "cmd/beacon-chain/genesis")
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test")
|
|||||||
|
|
||||||
go_library(
|
go_library(
|
||||||
name = "go_default_library",
|
name = "go_default_library",
|
||||||
srcs = ["jwt.go"],
|
srcs = [
|
||||||
|
"jwt.go",
|
||||||
|
"log.go",
|
||||||
|
],
|
||||||
importpath = "github.com/OffchainLabs/prysm/v7/cmd/beacon-chain/jwt",
|
importpath = "github.com/OffchainLabs/prysm/v7/cmd/beacon-chain/jwt",
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
deps = [
|
deps = [
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"github.com/OffchainLabs/prysm/v7/api"
|
"github.com/OffchainLabs/prysm/v7/api"
|
||||||
"github.com/OffchainLabs/prysm/v7/cmd"
|
"github.com/OffchainLabs/prysm/v7/cmd"
|
||||||
"github.com/OffchainLabs/prysm/v7/io/file"
|
"github.com/OffchainLabs/prysm/v7/io/file"
|
||||||
"github.com/sirupsen/logrus"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -23,7 +22,7 @@ var Commands = &cli.Command{
|
|||||||
}),
|
}),
|
||||||
Action: func(cliCtx *cli.Context) error {
|
Action: func(cliCtx *cli.Context) error {
|
||||||
if err := generateAuthSecretInFile(cliCtx); err != nil {
|
if err := generateAuthSecretInFile(cliCtx); err != nil {
|
||||||
logrus.WithError(err).Fatal("Could not generate jwt")
|
log.WithError(err).Fatal("Could not generate jwt")
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
},
|
},
|
||||||
@@ -57,6 +56,6 @@ func generateAuthSecretInFile(c *cli.Context) error {
|
|||||||
if err := file.WriteFile(fileName, []byte(secret)); err != nil {
|
if err := file.WriteFile(fileName, []byte(secret)); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
logrus.Infof("Successfully wrote JSON-RPC authentication secret to file %s", fileName)
|
log.Infof("Successfully wrote JSON-RPC authentication secret to file %s", fileName)
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
9
cmd/beacon-chain/jwt/log.go
Normal file
9
cmd/beacon-chain/jwt/log.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
// Code generated by hack/gen-logs.sh; DO NOT EDIT.
|
||||||
|
// This file is created and regenerated automatically. Anything added here might get removed.
|
||||||
|
package jwt
|
||||||
|
|
||||||
|
import "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
// The prefix for logs from this package will be the text after the last slash in the package path.
|
||||||
|
// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file.
|
||||||
|
var log = logrus.WithField("package", "cmd/beacon-chain/jwt")
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
|
// Code generated by hack/gen-logs.sh; DO NOT EDIT.
|
||||||
|
// This file is created and regenerated automatically. Anything added here might get removed.
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/sirupsen/logrus"
|
import "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
var log = logrus.WithField("prefix", "main")
|
// The prefix for logs from this package will be the text after the last slash in the package path.
|
||||||
|
// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file.
|
||||||
|
var log = logrus.WithField("package", "cmd/beacon-chain")
|
||||||
|
|||||||
@@ -160,6 +160,7 @@ var appFlags = []cli.Flag{
|
|||||||
dasFlags.BackfillOldestSlot,
|
dasFlags.BackfillOldestSlot,
|
||||||
dasFlags.BlobRetentionEpochFlag,
|
dasFlags.BlobRetentionEpochFlag,
|
||||||
flags.BatchVerifierLimit,
|
flags.BatchVerifierLimit,
|
||||||
|
flags.StateDiffExponents,
|
||||||
flags.DisableEphemeralLogFile,
|
flags.DisableEphemeralLogFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -243,6 +244,11 @@ func before(ctx *cli.Context) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Log Prysm version on startup. After initializing log-file and ephemeral log-file.
|
||||||
|
log.WithFields(logrus.Fields{
|
||||||
|
"version": version.Version(),
|
||||||
|
}).Info("Prysm Beacon Chain started")
|
||||||
|
|
||||||
if err := cmd.ExpandSingleEndpointIfFile(ctx, flags.ExecutionEngineEndpoint); err != nil {
|
if err := cmd.ExpandSingleEndpointIfFile(ctx, flags.ExecutionEngineEndpoint); err != nil {
|
||||||
return errors.Wrap(err, "failed to expand single endpoint")
|
return errors.Wrap(err, "failed to expand single endpoint")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,10 @@ load("@prysm//tools/go:def.bzl", "go_library", "go_test")
|
|||||||
|
|
||||||
go_library(
|
go_library(
|
||||||
name = "go_default_library",
|
name = "go_default_library",
|
||||||
srcs = ["options.go"],
|
srcs = [
|
||||||
|
"log.go",
|
||||||
|
"options.go",
|
||||||
|
],
|
||||||
importpath = "github.com/OffchainLabs/prysm/v7/cmd/beacon-chain/storage",
|
importpath = "github.com/OffchainLabs/prysm/v7/cmd/beacon-chain/storage",
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
deps = [
|
deps = [
|
||||||
|
|||||||
9
cmd/beacon-chain/storage/log.go
Normal file
9
cmd/beacon-chain/storage/log.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
// Code generated by hack/gen-logs.sh; DO NOT EDIT.
|
||||||
|
// This file is created and regenerated automatically. Anything added here might get removed.
|
||||||
|
package storage
|
||||||
|
|
||||||
|
import "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
// The prefix for logs from this package will be the text after the last slash in the package path.
|
||||||
|
// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file.
|
||||||
|
var log = logrus.WithField("package", "cmd/beacon-chain/storage")
|
||||||
@@ -15,7 +15,6 @@ import (
|
|||||||
"github.com/OffchainLabs/prysm/v7/config/params"
|
"github.com/OffchainLabs/prysm/v7/config/params"
|
||||||
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
"github.com/OffchainLabs/prysm/v7/consensus-types/primitives"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -74,6 +74,7 @@ var appHelpFlagGroups = []flagGroup{
|
|||||||
flags.RPCHost,
|
flags.RPCHost,
|
||||||
flags.RPCPort,
|
flags.RPCPort,
|
||||||
flags.BatchVerifierLimit,
|
flags.BatchVerifierLimit,
|
||||||
|
flags.StateDiffExponents,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
|
// Code generated by hack/gen-logs.sh; DO NOT EDIT.
|
||||||
|
// This file is created and regenerated automatically. Anything added here might get removed.
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import "github.com/sirupsen/logrus"
|
import "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
var log = logrus.WithField("prefix", "main")
|
// The prefix for logs from this package will be the text after the last slash in the package path.
|
||||||
|
// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file.
|
||||||
|
var log = logrus.WithField("package", "cmd/client-stats")
|
||||||
|
|||||||
@@ -14,8 +14,6 @@ import (
|
|||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
var log = logrus.WithField("prefix", "node")
|
|
||||||
|
|
||||||
// ConfirmAction uses the passed in actionText as the confirmation text displayed in the terminal.
|
// ConfirmAction uses the passed in actionText as the confirmation text displayed in the terminal.
|
||||||
// The user must enter Y or N to indicate whether they confirm the action detailed in the warning text.
|
// The user must enter Y or N to indicate whether they confirm the action detailed in the warning text.
|
||||||
// Returns a boolean representing the user's answer.
|
// Returns a boolean representing the user's answer.
|
||||||
|
|||||||
9
cmd/log.go
Normal file
9
cmd/log.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
// Code generated by hack/gen-logs.sh; DO NOT EDIT.
|
||||||
|
// This file is created and regenerated automatically. Anything added here might get removed.
|
||||||
|
package cmd
|
||||||
|
|
||||||
|
import "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
// The prefix for logs from this package will be the text after the last slash in the package path.
|
||||||
|
// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file.
|
||||||
|
var log = logrus.WithField("package", "cmd")
|
||||||
@@ -4,7 +4,10 @@ load("//tools:prysm_image.bzl", "prysm_image_upload")
|
|||||||
|
|
||||||
go_library(
|
go_library(
|
||||||
name = "go_default_library",
|
name = "go_default_library",
|
||||||
srcs = ["main.go"],
|
srcs = [
|
||||||
|
"log.go",
|
||||||
|
"main.go",
|
||||||
|
],
|
||||||
importpath = "github.com/OffchainLabs/prysm/v7/cmd/prysmctl",
|
importpath = "github.com/OffchainLabs/prysm/v7/cmd/prysmctl",
|
||||||
visibility = ["//visibility:private"],
|
visibility = ["//visibility:private"],
|
||||||
deps = [
|
deps = [
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ go_library(
|
|||||||
srcs = [
|
srcs = [
|
||||||
"cmd.go",
|
"cmd.go",
|
||||||
"download.go",
|
"download.go",
|
||||||
|
"log.go",
|
||||||
],
|
],
|
||||||
importpath = "github.com/OffchainLabs/prysm/v7/cmd/prysmctl/checkpointsync",
|
importpath = "github.com/OffchainLabs/prysm/v7/cmd/prysmctl/checkpointsync",
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/OffchainLabs/prysm/v7/api/client"
|
"github.com/OffchainLabs/prysm/v7/api/client"
|
||||||
"github.com/OffchainLabs/prysm/v7/api/client/beacon"
|
"github.com/OffchainLabs/prysm/v7/api/client/beacon"
|
||||||
"github.com/OffchainLabs/prysm/v7/beacon-chain/sync/checkpoint"
|
"github.com/OffchainLabs/prysm/v7/beacon-chain/sync/checkpoint"
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
9
cmd/prysmctl/checkpointsync/log.go
Normal file
9
cmd/prysmctl/checkpointsync/log.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
// Code generated by hack/gen-logs.sh; DO NOT EDIT.
|
||||||
|
// This file is created and regenerated automatically. Anything added here might get removed.
|
||||||
|
package checkpointsync
|
||||||
|
|
||||||
|
import "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
// The prefix for logs from this package will be the text after the last slash in the package path.
|
||||||
|
// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file.
|
||||||
|
var log = logrus.WithField("package", "cmd/prysmctl/checkpointsync")
|
||||||
@@ -5,6 +5,7 @@ go_library(
|
|||||||
srcs = [
|
srcs = [
|
||||||
"buckets.go",
|
"buckets.go",
|
||||||
"cmd.go",
|
"cmd.go",
|
||||||
|
"log.go",
|
||||||
"query.go",
|
"query.go",
|
||||||
"span.go",
|
"span.go",
|
||||||
],
|
],
|
||||||
|
|||||||
9
cmd/prysmctl/db/log.go
Normal file
9
cmd/prysmctl/db/log.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
// Code generated by hack/gen-logs.sh; DO NOT EDIT.
|
||||||
|
// This file is created and regenerated automatically. Anything added here might get removed.
|
||||||
|
package db
|
||||||
|
|
||||||
|
import "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
// The prefix for logs from this package will be the text after the last slash in the package path.
|
||||||
|
// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file.
|
||||||
|
var log = logrus.WithField("package", "cmd/prysmctl/db")
|
||||||
@@ -8,7 +8,6 @@ import (
|
|||||||
"github.com/OffchainLabs/prysm/v7/config/params"
|
"github.com/OffchainLabs/prysm/v7/config/params"
|
||||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
bolt "go.etcd.io/bbolt"
|
bolt "go.etcd.io/bbolt"
|
||||||
)
|
)
|
||||||
|
|||||||
9
cmd/prysmctl/log.go
Normal file
9
cmd/prysmctl/log.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
// Code generated by hack/gen-logs.sh; DO NOT EDIT.
|
||||||
|
// This file is created and regenerated automatically. Anything added here might get removed.
|
||||||
|
package main
|
||||||
|
|
||||||
|
import "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
// The prefix for logs from this package will be the text after the last slash in the package path.
|
||||||
|
// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file.
|
||||||
|
var log = logrus.WithField("package", "cmd/prysmctl")
|
||||||
@@ -9,7 +9,6 @@ import (
|
|||||||
"github.com/OffchainLabs/prysm/v7/cmd/prysmctl/testnet"
|
"github.com/OffchainLabs/prysm/v7/cmd/prysmctl/testnet"
|
||||||
"github.com/OffchainLabs/prysm/v7/cmd/prysmctl/validator"
|
"github.com/OffchainLabs/prysm/v7/cmd/prysmctl/validator"
|
||||||
"github.com/OffchainLabs/prysm/v7/cmd/prysmctl/weaksubjectivity"
|
"github.com/OffchainLabs/prysm/v7/cmd/prysmctl/weaksubjectivity"
|
||||||
log "github.com/sirupsen/logrus"
|
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
|
// Code generated by hack/gen-logs.sh; DO NOT EDIT.
|
||||||
|
// This file is created and regenerated automatically. Anything added here might get removed.
|
||||||
package p2p
|
package p2p
|
||||||
|
|
||||||
import "github.com/sirupsen/logrus"
|
import "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
var log = logrus.WithField("prefix", "prysmctl-p2p")
|
// The prefix for logs from this package will be the text after the last slash in the package path.
|
||||||
|
// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file.
|
||||||
|
var log = logrus.WithField("package", "cmd/prysmctl/p2p")
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ go_library(
|
|||||||
name = "go_default_library",
|
name = "go_default_library",
|
||||||
srcs = [
|
srcs = [
|
||||||
"generate_genesis.go",
|
"generate_genesis.go",
|
||||||
|
"log.go",
|
||||||
"testnet.go",
|
"testnet.go",
|
||||||
],
|
],
|
||||||
importpath = "github.com/OffchainLabs/prysm/v7/cmd/prysmctl/testnet",
|
importpath = "github.com/OffchainLabs/prysm/v7/cmd/prysmctl/testnet",
|
||||||
|
|||||||
@@ -43,7 +43,6 @@ var (
|
|||||||
GethGenesisJsonIn string
|
GethGenesisJsonIn string
|
||||||
GethGenesisJsonOut string
|
GethGenesisJsonOut string
|
||||||
}{}
|
}{}
|
||||||
log = logrus.WithField("prefix", "genesis")
|
|
||||||
outputSSZFlag = &cli.StringFlag{
|
outputSSZFlag = &cli.StringFlag{
|
||||||
Name: "output-ssz",
|
Name: "output-ssz",
|
||||||
Destination: &generateGenesisStateFlags.OutputSSZ,
|
Destination: &generateGenesisStateFlags.OutputSSZ,
|
||||||
|
|||||||
9
cmd/prysmctl/testnet/log.go
Normal file
9
cmd/prysmctl/testnet/log.go
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
// Code generated by hack/gen-logs.sh; DO NOT EDIT.
|
||||||
|
// This file is created and regenerated automatically. Anything added here might get removed.
|
||||||
|
package testnet
|
||||||
|
|
||||||
|
import "github.com/sirupsen/logrus"
|
||||||
|
|
||||||
|
// The prefix for logs from this package will be the text after the last slash in the package path.
|
||||||
|
// If you wish to change this, you should add your desired name in the runtime/logging/logrus-prefixed-formatter/prefix-replacement.go file.
|
||||||
|
var log = logrus.WithField("package", "cmd/prysmctl/testnet")
|
||||||
@@ -5,6 +5,7 @@ go_library(
|
|||||||
srcs = [
|
srcs = [
|
||||||
"cmd.go",
|
"cmd.go",
|
||||||
"error.go",
|
"error.go",
|
||||||
|
"log.go",
|
||||||
"proposer_settings.go",
|
"proposer_settings.go",
|
||||||
"withdraw.go",
|
"withdraw.go",
|
||||||
],
|
],
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user