Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support DENEB #235

Merged
merged 2 commits into from
Oct 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions pkg/cannon/deriver/beacon/eth/v2/attester_slashing.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,12 @@ func (a *AttesterSlashingDeriver) processSlot(ctx context.Context, slot phase0.S

events := []*xatu.DecoratedEvent{}

for _, slashing := range a.getAttesterSlashings(ctx, block) {
slashings, err := a.getAttesterSlashings(ctx, block)
if err != nil {
return nil, errors.Wrapf(err, "failed to get attester slashings for slot %d", slot)
}

for _, slashing := range slashings {
event, err := a.createEvent(ctx, slashing, blockIdentifier)
if err != nil {
a.log.WithError(err).Error("Failed to create event")
Expand All @@ -244,12 +249,12 @@ func (a *AttesterSlashingDeriver) processSlot(ctx context.Context, slot phase0.S
return events, nil
}

func (a *AttesterSlashingDeriver) getAttesterSlashings(ctx context.Context, block *spec.VersionedSignedBeaconBlock) []*xatuethv1.AttesterSlashingV2 {
func (a *AttesterSlashingDeriver) getAttesterSlashings(ctx context.Context, block *spec.VersionedSignedBeaconBlock) ([]*xatuethv1.AttesterSlashingV2, error) {
slashings := []*xatuethv1.AttesterSlashingV2{}

attesterSlashings, err := block.AttesterSlashings()
if err != nil {
a.log.WithError(err).Error("Failed to obtain attester slashings")
return nil, errors.Wrap(err, "failed to obtain attester slashings")
}

for _, slashing := range attesterSlashings {
Expand All @@ -259,7 +264,7 @@ func (a *AttesterSlashingDeriver) getAttesterSlashings(ctx context.Context, bloc
})
}

return slashings
return slashings, nil
}

func convertIndexedAttestation(attestation *phase0.IndexedAttestation) *xatuethv1.IndexedAttestationV2 {
Expand Down
7 changes: 7 additions & 0 deletions pkg/cannon/deriver/beacon/eth/v2/beacon_block.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,13 @@ func (b *BeaconBlockDeriver) getAdditionalData(_ context.Context, block *spec.Ve
}

addTxData(capellaTxs)
case spec.DataVersionDeneb:
denebTxs := make([][]byte, len(block.Deneb.Message.Body.ExecutionPayload.Transactions))
for i, tx := range block.Deneb.Message.Body.ExecutionPayload.Transactions {
denebTxs[i] = tx
}

addTxData(denebTxs)
}

compressedTransactions := snappy.Encode(nil, transactionsBytes)
Expand Down
34 changes: 14 additions & 20 deletions pkg/cannon/deriver/beacon/eth/v2/bls_to_execution_change.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,26 +253,20 @@ func (b *BLSToExecutionChangeDeriver) processSlot(ctx context.Context, slot phas
func (b *BLSToExecutionChangeDeriver) getBLSToExecutionChanges(ctx context.Context, block *spec.VersionedSignedBeaconBlock) ([]*xatuethv2.SignedBLSToExecutionChangeV2, error) {
changes := []*xatuethv2.SignedBLSToExecutionChangeV2{}

switch block.Version {
case spec.DataVersionPhase0:
return changes, nil
case spec.DataVersionAltair:
return changes, nil
case spec.DataVersionBellatrix:
return changes, nil
case spec.DataVersionCapella:
for _, change := range block.Capella.Message.Body.BLSToExecutionChanges {
changes = append(changes, &xatuethv2.SignedBLSToExecutionChangeV2{
Message: &xatuethv2.BLSToExecutionChangeV2{
ValidatorIndex: wrapperspb.UInt64(uint64(change.Message.ValidatorIndex)),
FromBlsPubkey: change.Message.FromBLSPubkey.String(),
ToExecutionAddress: change.Message.ToExecutionAddress.String(),
},
Signature: change.Signature.String(),
})
}
default:
return nil, fmt.Errorf("unsupported block version: %s", block.Version.String())
chs, err := block.BLSToExecutionChanges()
if err != nil {
return nil, errors.Wrap(err, "failed to obtain BLS to execution changes")
}

for _, change := range chs {
changes = append(changes, &xatuethv2.SignedBLSToExecutionChangeV2{
Message: &xatuethv2.BLSToExecutionChangeV2{
ValidatorIndex: wrapperspb.UInt64(uint64(change.Message.ValidatorIndex)),
FromBlsPubkey: change.Message.FromBLSPubkey.String(),
ToExecutionAddress: change.Message.ToExecutionAddress.String(),
},
Signature: change.Signature.String(),
})
}

return changes, nil
Expand Down
26 changes: 8 additions & 18 deletions pkg/cannon/deriver/beacon/eth/v2/deposit.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,30 +249,20 @@ func (b *DepositDeriver) processSlot(ctx context.Context, slot phase0.Slot) ([]*
}

func (b *DepositDeriver) getDeposits(ctx context.Context, block *spec.VersionedSignedBeaconBlock) ([]*xatuethv1.DepositV2, error) {
exits := []*xatuethv1.DepositV2{}

var deposits []*phase0.Deposit

switch block.Version {
case spec.DataVersionPhase0:
deposits = block.Phase0.Message.Body.Deposits
case spec.DataVersionAltair:
deposits = block.Altair.Message.Body.Deposits
case spec.DataVersionBellatrix:
deposits = block.Bellatrix.Message.Body.Deposits
case spec.DataVersionCapella:
deposits = block.Capella.Message.Body.Deposits
default:
return nil, fmt.Errorf("unsupported block version: %s", block.Version.String())
deposits := []*xatuethv1.DepositV2{}

dps, err := block.Deposits()
if err != nil {
return nil, errors.Wrap(err, "failed to obtain deposits")
}

for _, deposit := range deposits {
for _, deposit := range dps {
proof := []string{}
for _, p := range deposit.Proof {
proof = append(proof, fmt.Sprintf("0x%x", p))
}

exits = append(exits, &xatuethv1.DepositV2{
deposits = append(deposits, &xatuethv1.DepositV2{
Proof: proof,
Data: &xatuethv1.DepositV2_Data{
Pubkey: deposit.Data.PublicKey.String(),
Expand All @@ -283,7 +273,7 @@ func (b *DepositDeriver) getDeposits(ctx context.Context, block *spec.VersionedS
})
}

return exits, nil
return deposits, nil
}

func (b *DepositDeriver) createEvent(ctx context.Context, deposit *xatuethv1.DepositV2, identifier *xatu.BlockIdentifier) (*xatu.DecoratedEvent, error) {
Expand Down
31 changes: 8 additions & 23 deletions pkg/cannon/deriver/beacon/eth/v2/execution_transaction.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,31 +289,16 @@ func (b *ExecutionTransactionDeriver) processSlot(ctx context.Context, slot phas
func (b *ExecutionTransactionDeriver) getExecutionTransactions(ctx context.Context, block *spec.VersionedSignedBeaconBlock) ([]*types.Transaction, error) {
transactions := []*types.Transaction{}

switch block.Version {
case spec.DataVersionPhase0:
return transactions, nil
case spec.DataVersionAltair:
return transactions, nil
case spec.DataVersionBellatrix:
for _, transaction := range block.Bellatrix.Message.Body.ExecutionPayload.Transactions {
ethTransaction := new(types.Transaction)
if err := ethTransaction.UnmarshalBinary(transaction); err != nil {
return nil, fmt.Errorf("failed to unmarshal transaction: %v", err)
}

transactions = append(transactions, ethTransaction)
}
case spec.DataVersionCapella:
for _, transaction := range block.Capella.Message.Body.ExecutionPayload.Transactions {
ethTransaction := new(types.Transaction)
if err := ethTransaction.UnmarshalBinary(transaction); err != nil {
return nil, fmt.Errorf("failed to unmarshal transaction: %v", err)
}
txs, err := block.ExecutionTransactions()
if err != nil {
return nil, fmt.Errorf("failed to get execution transactions: %v", err)
}

transactions = append(transactions, ethTransaction)
for _, transaction := range txs {
ethTransaction := new(types.Transaction)
if err := ethTransaction.UnmarshalBinary(transaction); err != nil {
return nil, fmt.Errorf("failed to unmarshal transaction: %v", err)
}
default:
return nil, fmt.Errorf("unsupported block version: %s", block.Version.String())
}

return transactions, nil
Expand Down
16 changes: 3 additions & 13 deletions pkg/cannon/deriver/beacon/eth/v2/voluntary_exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,19 +251,9 @@ func (b *VoluntaryExitDeriver) processSlot(ctx context.Context, slot phase0.Slot
func (b *VoluntaryExitDeriver) getVoluntaryExits(ctx context.Context, block *spec.VersionedSignedBeaconBlock) ([]*xatuethv1.SignedVoluntaryExitV2, error) {
exits := []*xatuethv1.SignedVoluntaryExitV2{}

var voluntaryExits []*phase0.SignedVoluntaryExit

switch block.Version {
case spec.DataVersionPhase0:
voluntaryExits = block.Phase0.Message.Body.VoluntaryExits
case spec.DataVersionAltair:
voluntaryExits = block.Altair.Message.Body.VoluntaryExits
case spec.DataVersionBellatrix:
voluntaryExits = block.Bellatrix.Message.Body.VoluntaryExits
case spec.DataVersionCapella:
voluntaryExits = block.Capella.Message.Body.VoluntaryExits
default:
return nil, fmt.Errorf("unsupported block version: %s", block.Version.String())
voluntaryExits, err := block.VoluntaryExits()
if err != nil {
return nil, errors.Wrap(err, "failed to obtain voluntary exits")
}

for _, exit := range voluntaryExits {
Expand Down
8 changes: 4 additions & 4 deletions pkg/cannon/deriver/beacon/eth/v2/withdrawal.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ func (b *WithdrawalDeriver) lookAheadAtLocation(ctx context.Context, locations [
func (b *WithdrawalDeriver) getWithdrawals(ctx context.Context, block *spec.VersionedSignedBeaconBlock) ([]*xatuethv1.WithdrawalV2, error) {
withdrawals := []*xatuethv1.WithdrawalV2{}

switch block.Version {
case spec.DataVersionPhase0, spec.DataVersionAltair, spec.DataVersionBellatrix:
return withdrawals, nil
withd, err := block.Withdrawals()
if err != nil {
return nil, errors.Wrap(err, "failed to obtain withdrawals")
}

for _, withdrawal := range block.Capella.Message.Body.ExecutionPayload.Withdrawals {
for _, withdrawal := range withd {
withdrawals = append(withdrawals, &xatuethv1.WithdrawalV2{
Index: &wrapperspb.UInt64Value{Value: uint64(withdrawal.Index)},
ValidatorIndex: &wrapperspb.UInt64Value{Value: uint64(withdrawal.ValidatorIndex)},
Expand Down
62 changes: 62 additions & 0 deletions pkg/proto/eth/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ func NewEventBlockV2FromVersionSignedBeaconBlock(block *spec.VersionedSignedBeac
data = NewEventBlockFromBellatrix(block)
case spec.DataVersionCapella:
data = NewEventBlockFromCapella(block)
case spec.DataVersionDeneb:
data = NewEventBlockFromDeneb(block)
default:
return nil, fmt.Errorf("unsupported block version: %v", block.Version)
}
Expand Down Expand Up @@ -200,3 +202,63 @@ func NewEventBlockFromCapella(block *spec.VersionedSignedBeaconBlock) *v2.EventB
Signature: block.Capella.Signature.String(),
}
}

func NewEventBlockFromDeneb(block *spec.VersionedSignedBeaconBlock) *v2.EventBlockV2 {
kzgCommitments := []string{}

for _, commitment := range block.Deneb.Message.Body.BlobKzgCommitments {
kzgCommitments = append(kzgCommitments, commitment.String())
}

return &v2.EventBlockV2{
Version: v2.BlockVersion_DENEB,
Message: &v2.EventBlockV2_DenebBlock{
DenebBlock: &v2.BeaconBlockDeneb{
Slot: &wrapperspb.UInt64Value{Value: uint64(block.Deneb.Message.Slot)},
ProposerIndex: &wrapperspb.UInt64Value{Value: uint64(block.Deneb.Message.ProposerIndex)},
ParentRoot: block.Deneb.Message.ParentRoot.String(),
StateRoot: block.Deneb.Message.StateRoot.String(),
Body: &v2.BeaconBlockBodyDeneb{
RandaoReveal: block.Deneb.Message.Body.RANDAOReveal.String(),
Eth1Data: &v1.Eth1Data{
DepositRoot: block.Deneb.Message.Body.ETH1Data.DepositRoot.String(),
DepositCount: block.Deneb.Message.Body.ETH1Data.DepositCount,
BlockHash: fmt.Sprintf("0x%x", block.Deneb.Message.Body.ETH1Data.BlockHash),
},
Graffiti: fmt.Sprintf("0x%x", block.Deneb.Message.Body.Graffiti[:]),
ProposerSlashings: v1.NewProposerSlashingsFromPhase0(block.Deneb.Message.Body.ProposerSlashings),
AttesterSlashings: v1.NewAttesterSlashingsFromPhase0(block.Deneb.Message.Body.AttesterSlashings),
Attestations: v1.NewAttestationsFromPhase0(block.Deneb.Message.Body.Attestations),
Deposits: v1.NewDepositsFromPhase0(block.Deneb.Message.Body.Deposits),
VoluntaryExits: v1.NewSignedVoluntaryExitsFromPhase0(block.Deneb.Message.Body.VoluntaryExits),
SyncAggregate: &v1.SyncAggregate{
SyncCommitteeBits: fmt.Sprintf("0x%x", block.Deneb.Message.Body.SyncAggregate.SyncCommitteeBits),
SyncCommitteeSignature: block.Deneb.Message.Body.SyncAggregate.SyncCommitteeSignature.String(),
},
ExecutionPayload: &v1.ExecutionPayloadDeneb{
ParentHash: block.Deneb.Message.Body.ExecutionPayload.ParentHash.String(),
FeeRecipient: block.Deneb.Message.Body.ExecutionPayload.FeeRecipient.String(),
StateRoot: fmt.Sprintf("0x%x", block.Deneb.Message.Body.ExecutionPayload.StateRoot[:]),
ReceiptsRoot: fmt.Sprintf("0x%x", block.Deneb.Message.Body.ExecutionPayload.ReceiptsRoot[:]),
LogsBloom: fmt.Sprintf("0x%x", block.Deneb.Message.Body.ExecutionPayload.LogsBloom[:]),
PrevRandao: fmt.Sprintf("0x%x", block.Deneb.Message.Body.ExecutionPayload.PrevRandao[:]),
BlockNumber: &wrapperspb.UInt64Value{Value: block.Deneb.Message.Body.ExecutionPayload.BlockNumber},
GasLimit: &wrapperspb.UInt64Value{Value: block.Deneb.Message.Body.ExecutionPayload.GasLimit},
GasUsed: &wrapperspb.UInt64Value{Value: block.Deneb.Message.Body.ExecutionPayload.GasUsed},
Timestamp: &wrapperspb.UInt64Value{Value: block.Deneb.Message.Body.ExecutionPayload.Timestamp},
ExtraData: fmt.Sprintf("0x%x", block.Deneb.Message.Body.ExecutionPayload.ExtraData),
BaseFeePerGas: fmt.Sprintf("0x%x", block.Deneb.Message.Body.ExecutionPayload.BaseFeePerGas[:]),
BlockHash: block.Deneb.Message.Body.ExecutionPayload.BlockHash.String(),
Transactions: getTransactions(block.Deneb.Message.Body.ExecutionPayload.Transactions),
Withdrawals: v1.NewWithdrawalsFromCapella(block.Deneb.Message.Body.ExecutionPayload.Withdrawals),
BlobGasUsed: &wrapperspb.UInt64Value{Value: block.Deneb.Message.Body.ExecutionPayload.BlobGasUsed},
ExcessBlobGas: &wrapperspb.UInt64Value{Value: block.Deneb.Message.Body.ExecutionPayload.ExcessBlobGas},
},
BlsToExecutionChanges: v2.NewBLSToExecutionChangesFromCapella(block.Deneb.Message.Body.BLSToExecutionChanges),
BlobKzgCommitments: kzgCommitments,
},
},
},
Signature: block.Deneb.Signature.String(),
}
}
Loading
Loading