Skip to content

Commit

Permalink
engineapi: Update interface and Rpc conversion for EIP-7685 Requests (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
somnathb1 authored Jul 30, 2024
1 parent c4d1675 commit 402467a
Show file tree
Hide file tree
Showing 8 changed files with 397 additions and 183 deletions.
11 changes: 6 additions & 5 deletions core/types/consolidation_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,19 @@ func (d *ConsolidationRequest) UnmarshalJSON(input []byte) error {
return err
}
if len(sourceKey) != BLSPubKeyLen {
return errors.New("Unmarshalled pubkey not equal to BLSPubkeyLen")
return errors.New("ConsolidationRequest SourcePubKey not equal to BLSPubkeyLen after UnmarshalJSON")

}
targetKey, err := hexutil.Decode(tt.TargetPubKey)
if err != nil {
return err
}
if len(targetKey) != BLSSigLen {
return errors.New("Unmarshalled TargetPubKey len not equal to BLSSiglen")
if len(targetKey) != BLSPubKeyLen {
return errors.New("ConsolidationRequest TargetPubKey len not equal to BLSSiglen after UnmarshalJSON")
}
d.SourceAddress = tt.SourceAddress
d.SourcePubKey = [48]byte(sourceKey)
d.TargetPubKey = [48]byte(targetKey)
d.SourcePubKey = [BLSPubKeyLen]byte(sourceKey)
d.TargetPubKey = [BLSPubKeyLen]byte(targetKey)
return nil
}

Expand Down
8 changes: 4 additions & 4 deletions core/types/deposit_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,18 +145,18 @@ func (d *DepositRequest) UnmarshalJSON(input []byte) error {
return err
}
if len(pubkey) != BLSPubKeyLen {
return errors.New("Unmarshalled pubkey len not equal to BLSPubkeyLen")
return errors.New("DepositRequest Pubkey len not equal to BLSPubkeyLen after UnmarshalJSON")
}
sig, err := hexutil.Decode(tt.Signature)
if err != nil {
return err
}
if len(sig) != BLSSigLen {
return errors.New("Unmarshalled Signature len not equal to BLSSiglen")
return errors.New("DepositRequest Signature len not equal to BLSSiglen after UnmarshalJSON")
}

d.Pubkey = [48]byte(pubkey)
d.Signature = [96]byte(sig)
d.Pubkey = [BLSPubKeyLen]byte(pubkey)
d.Signature = [BLSSigLen]byte(sig)
d.WithdrawalCredentials = tt.WithdrawalCredentials
d.Amount = tt.Amount.Uint64()
d.Index = tt.Index.Uint64()
Expand Down
7 changes: 3 additions & 4 deletions core/types/withdrawal_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
"bytes"
"encoding/json"
"errors"
// "fmt"
"io"

libcommon "github.com/erigontech/erigon-lib/common"
Expand Down Expand Up @@ -111,11 +110,11 @@ func (w *WithdrawalRequest) UnmarshalJSON(input []byte) error {
if err != nil {
return err
}
if len(validatorKey) != 48 {
return errors.New("decoded validatorKey len after UnmarshalJSON doesn't match BLSKeyLen")
if len(validatorKey) != BLSPubKeyLen {
return errors.New("WithdrawalRequest ValidatorPubkey len after UnmarshalJSON doesn't match BLSKeyLen")
}

w.ValidatorPubkey = [48]byte(validatorKey)
w.ValidatorPubkey = [BLSPubKeyLen]byte(validatorKey)
w.Amount = tt.Amount.Uint64()
w.SourceAddress = tt.SourceAddress
return nil
Expand Down
2 changes: 1 addition & 1 deletion erigon-lib/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.21.5

require (
github.com/erigontech/erigon-snapshot v1.3.1-0.20240727090507-df8adef084d0
github.com/erigontech/interfaces v0.0.0-20240720173141-ef1ae67f39ce
github.com/erigontech/interfaces v0.0.0-20240723225543-c6b574058f8c
github.com/erigontech/mdbx-go v0.38.4
github.com/erigontech/secp256k1 v1.1.0
github.com/rs/dnscache v0.0.0-20211102005908-e0241e321417
Expand Down
4 changes: 2 additions & 2 deletions erigon-lib/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,8 @@ github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1m
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/erigontech/erigon-snapshot v1.3.1-0.20240727090507-df8adef084d0 h1:c9eK0xYibI7hWFvKi2zcrE+mXcJfensX0p7alxQZxBY=
github.com/erigontech/erigon-snapshot v1.3.1-0.20240727090507-df8adef084d0/go.mod h1:ooHlCl+eEYzebiPu+FP6Q6SpPUeMADn8Jxabv3IKb9M=
github.com/erigontech/interfaces v0.0.0-20240720173141-ef1ae67f39ce h1:qkXlUmdi5nx/wXdEyqzj/I4NDn9CDh5efiZxe/hbre0=
github.com/erigontech/interfaces v0.0.0-20240720173141-ef1ae67f39ce/go.mod h1:N7OUkhkcagp9+7yb4ycHsG2VWCOmuJ1ONBecJshxtLE=
github.com/erigontech/interfaces v0.0.0-20240723225543-c6b574058f8c h1:KbcMdRKYRL+A4bJGK+fNOITk95wJzh9rUXFJ17wCyUY=
github.com/erigontech/interfaces v0.0.0-20240723225543-c6b574058f8c/go.mod h1:N7OUkhkcagp9+7yb4ycHsG2VWCOmuJ1ONBecJshxtLE=
github.com/erigontech/mdbx-go v0.38.4 h1:S9T7mTe9KPcFe4dOoOtVdI6gPzht9y7wMnYfUBgrQLo=
github.com/erigontech/mdbx-go v0.38.4/go.mod h1:IcOLQDPw3VM/asP6T5JVPPN4FHHgJtY16XfYjzWKVNI=
github.com/erigontech/secp256k1 v1.1.0 h1:mO3YJMUSoASE15Ya//SoHiisptUhdXExuMUN1M0X9qY=
Expand Down
435 changes: 268 additions & 167 deletions erigon-lib/gointerfaces/typesproto/types.pb.go

Large diffs are not rendered by default.

105 changes: 105 additions & 0 deletions turbo/engineapi/engine_types/jsonrpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,12 @@ func ConvertRpcBlockToExecutionPayload(payload *execution.Block) *ExecutionPaylo
excessBlobGas := *header.ExcessBlobGas
res.ExcessBlobGas = (*hexutil.Uint64)(&excessBlobGas)
}
if header.RequestsRoot != nil {
reqs, _ := types.UnmarshalRequestsFromBinary(body.Requests)
res.DepositRequests = reqs.Deposits()
res.WithdrawalRequests = reqs.Withdrawals()
res.ConsolidationRequests = reqs.Consolidations()
}
return res
}

Expand Down Expand Up @@ -209,6 +215,11 @@ func ConvertPayloadFromRpc(payload *types2.ExecutionPayload) *ExecutionPayload {
excessBlobGas := *payload.ExcessBlobGas
res.ExcessBlobGas = (*hexutil.Uint64)(&excessBlobGas)
}
if payload.Version >= 4 {
res.DepositRequests = ConvertDepositRequestsFromRpc(payload.DepositRequests)
res.WithdrawalRequests = ConvertWithdrawalRequestsFromRpc(payload.WithdrawalRequests)
res.ConsolidationRequests = ConvertConsolidationRequestsFromRpc(payload.ConsolidationRequests)
}
return res
}

Expand Down Expand Up @@ -265,6 +276,100 @@ func ConvertWithdrawalsFromRpc(in []*types2.Withdrawal) []*types.Withdrawal {
return out
}

func ConvertDepositRequestsToRpc(in []*types.DepositRequest) []*types2.DepositRequest {
if in == nil {
return nil
}
out := make([]*types2.DepositRequest, 0, len(in))
for _, w := range in {
out = append(out, &types2.DepositRequest{
Pubkey: w.Pubkey[:],
WithdrawalCredentials: gointerfaces.ConvertHashToH256(w.WithdrawalCredentials),
Amount: w.Amount,
Signature: w.Signature[:],
Index: w.Index,
})
}
return out
}

func ConvertDepositRequestsFromRpc(in []*types2.DepositRequest) []*types.DepositRequest {
if in == nil {
return nil
}
out := make([]*types.DepositRequest, 0, len(in))
for _, w := range in {
out = append(out, &types.DepositRequest{
Pubkey: [48]byte(w.Pubkey),
WithdrawalCredentials: gointerfaces.ConvertH256ToHash(w.WithdrawalCredentials),
Amount: w.Amount,
Signature: [96]byte(w.Signature),
Index: w.Index,
})
}
return out
}

func ConvertWithdrawalRequestsToRpc(in []*types.WithdrawalRequest) []*types2.WithdrawalRequest {
if in == nil {
return nil
}
out := make([]*types2.WithdrawalRequest, 0, len(in))
for _, w := range in {
out = append(out, &types2.WithdrawalRequest{
SourceAddress: gointerfaces.ConvertAddressToH160(w.SourceAddress),
ValidatorPubkey: w.ValidatorPubkey[:],
Amount: w.Amount,
})
}
return out
}

func ConvertWithdrawalRequestsFromRpc(in []*types2.WithdrawalRequest) []*types.WithdrawalRequest {
if in == nil {
return nil
}
out := make([]*types.WithdrawalRequest, 0, len(in))
for _, w := range in {
out = append(out, &types.WithdrawalRequest{
SourceAddress: gointerfaces.ConvertH160toAddress(w.SourceAddress),
ValidatorPubkey: [48]byte(w.ValidatorPubkey),
Amount: w.Amount,
})
}
return out
}

func ConvertConsolidationRequestsToRpc(in []*types.ConsolidationRequest) []*types2.ConsolidationRequest {
if in == nil {
return nil
}
out := make([]*types2.ConsolidationRequest, 0, len(in))
for _, w := range in {
out = append(out, &types2.ConsolidationRequest{
SourceAddress: gointerfaces.ConvertAddressToH160(w.SourceAddress),
SourcePubkey: w.SourcePubKey[:],
TargetPubkey: w.TargetPubKey[:],
})
}
return out
}

func ConvertConsolidationRequestsFromRpc(in []*types2.ConsolidationRequest) []*types.ConsolidationRequest {
if in == nil {
return nil
}
out := make([]*types.ConsolidationRequest, 0, len(in))
for _, c := range in {
out = append(out, &types.ConsolidationRequest{
SourceAddress: gointerfaces.ConvertH160toAddress(c.SourceAddress),
SourcePubKey: [48]byte(c.SourcePubkey),
TargetPubKey: [48]byte(c.TargetPubkey),
})
}
return out
}

func ConvertPayloadId(payloadId uint64) *hexutility.Bytes {
encodedPayloadId := make([]byte, 8)
binary.BigEndian.PutUint64(encodedPayloadId, payloadId)
Expand Down
8 changes: 8 additions & 0 deletions turbo/execution/eth1/block_building.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import (
"github.com/erigontech/erigon/rpc"
"github.com/erigontech/erigon/turbo/builder"
"github.com/erigontech/erigon/turbo/engineapi/engine_helpers"
"github.com/erigontech/erigon/turbo/engineapi/engine_types"
"github.com/erigontech/erigon/turbo/execution/eth1/eth1_utils"
)

Expand Down Expand Up @@ -182,6 +183,13 @@ func (e *EthereumExecutionModule) GetAssembledBlock(ctx context.Context, req *ex
payload.BlobGasUsed = header.BlobGasUsed
payload.ExcessBlobGas = header.ExcessBlobGas
}
reqs := block.Requests()
if reqs != nil {
payload.Version = 4
payload.DepositRequests = engine_types.ConvertDepositRequestsToRpc(reqs.Deposits())
payload.WithdrawalRequests = engine_types.ConvertWithdrawalRequestsToRpc(reqs.Withdrawals())
payload.ConsolidationRequests = engine_types.ConvertConsolidationRequestsToRpc(reqs.Consolidations())
}

blockValue := blockValue(blockWithReceipts, baseFee)

Expand Down

0 comments on commit 402467a

Please sign in to comment.