From 83c5dfcec495c77523584e12da83bc1c00956875 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Thu, 12 Jan 2023 11:08:03 -0800 Subject: [PATCH 1/2] Change withdrawal amount unmarshal to uint64 (gwei) --- proto/engine/v1/json_marshal_unmarshal.go | 21 +++++++------------ .../engine/v1/json_marshal_unmarshal_test.go | 12 ++++++----- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/proto/engine/v1/json_marshal_unmarshal.go b/proto/engine/v1/json_marshal_unmarshal.go index 823319ad160b..7c974b8a00a2 100644 --- a/proto/engine/v1/json_marshal_unmarshal.go +++ b/proto/engine/v1/json_marshal_unmarshal.go @@ -144,7 +144,7 @@ type withdrawalJSON struct { Index *hexutil.Uint64 `json:"index"` Validator *hexutil.Uint64 `json:"validatorIndex"` Address *common.Address `json:"address"` - Amount string `json:"amount"` + Amount *hexutil.Uint64 `json:"amount"` } func (j *withdrawalJSON) ToWithdrawal() (*Withdrawal, error) { @@ -162,14 +162,13 @@ func (j *withdrawalJSON) ToWithdrawal() (*Withdrawal, error) { func (w *Withdrawal) MarshalJSON() ([]byte, error) { index := hexutil.Uint64(w.Index) validatorIndex := hexutil.Uint64(w.ValidatorIndex) + gwei := hexutil.Uint64(w.Amount) address := common.BytesToAddress(w.Address) - wei := new(big.Int).SetUint64(1000000000) - amountWei := new(big.Int).Mul(new(big.Int).SetUint64(w.Amount), wei) return json.Marshal(withdrawalJSON{ Index: &index, Validator: &validatorIndex, Address: &address, - Amount: hexutil.EncodeBig(amountWei), + Amount: &gwei, }) } @@ -184,23 +183,17 @@ func (w *Withdrawal) UnmarshalJSON(enc []byte) error { if dec.Validator == nil { return errors.New("missing validator index") } + if dec.Amount == nil { + return errors.New("missing withdrawal amount") + } if dec.Address == nil { return errors.New("missing execution address") } *w = Withdrawal{} w.Index = uint64(*dec.Index) w.ValidatorIndex = types.ValidatorIndex(*dec.Validator) + w.Amount = uint64(*dec.Amount) w.Address = dec.Address.Bytes() - wei := new(big.Int).SetUint64(1000000000) - amountWei, err := hexutil.DecodeBig(dec.Amount) - if err != nil { - return err - } - amount := new(big.Int).Div(amountWei, wei) - if !amount.IsUint64() { - return errors.New("withdrawal amount overflow") - } - w.Amount = amount.Uint64() return nil } diff --git a/proto/engine/v1/json_marshal_unmarshal_test.go b/proto/engine/v1/json_marshal_unmarshal_test.go index 8ed09ee27e35..f222b8560ba1 100644 --- a/proto/engine/v1/json_marshal_unmarshal_test.go +++ b/proto/engine/v1/json_marshal_unmarshal_test.go @@ -21,7 +21,7 @@ type withdrawalJSON struct { Index *hexutil.Uint64 `json:"index"` Validator *hexutil.Uint64 `json:"validatorIndex"` Address *common.Address `json:"address"` - Amount string `json:"amount"` + Amount *hexutil.Uint64 `json:"amount"` } func TestJsonMarshalUnmarshal(t *testing.T) { @@ -353,6 +353,8 @@ func TestJsonMarshalUnmarshal(t *testing.T) { withdrawalIndex1 := hexutil.Uint64(1) withdrawalIndex2 := hexutil.Uint64(2) + withdrawalAmount1 := hexutil.Uint64(100) + withdrawalAmount2 := hexutil.Uint64(200) withdrawalValidator1 := hexutil.Uint64(1) withdrawalValidator2 := hexutil.Uint64(2) address1 := common.Address(bytesutil.ToBytes20([]byte("address1"))) @@ -362,13 +364,13 @@ func TestJsonMarshalUnmarshal(t *testing.T) { Index: &withdrawalIndex1, Validator: &withdrawalValidator1, Address: &address1, - Amount: "0x3b9aca00", + Amount: &withdrawalAmount1, }, { Index: &withdrawalIndex2, Validator: &withdrawalValidator2, Address: &address2, - Amount: "0x77359400", + Amount: &withdrawalAmount2, }, } @@ -400,11 +402,11 @@ func TestJsonMarshalUnmarshal(t *testing.T) { require.Equal(t, uint64(1), payloadPb.Withdrawals[0].Index) require.Equal(t, types.ValidatorIndex(1), payloadPb.Withdrawals[0].ValidatorIndex) require.DeepEqual(t, bytesutil.PadTo([]byte("address1"), 20), payloadPb.Withdrawals[0].Address) - require.Equal(t, uint64(1), payloadPb.Withdrawals[0].Amount) + require.Equal(t, uint64(100), payloadPb.Withdrawals[0].Amount) require.Equal(t, uint64(2), payloadPb.Withdrawals[1].Index) require.Equal(t, types.ValidatorIndex(2), payloadPb.Withdrawals[1].ValidatorIndex) require.DeepEqual(t, bytesutil.PadTo([]byte("address2"), 20), payloadPb.Withdrawals[1].Address) - require.Equal(t, uint64(2), payloadPb.Withdrawals[1].Amount) + require.Equal(t, uint64(200), payloadPb.Withdrawals[1].Amount) }) } From f892c1a88f9d0d6633416559dcc8a354e356e5b8 Mon Sep 17 00:00:00 2001 From: terence tsao Date: Mon, 16 Jan 2023 08:16:31 -0800 Subject: [PATCH 2/2] Init server --- beacon-chain/rpc/service.go | 1 + 1 file changed, 1 insertion(+) diff --git a/beacon-chain/rpc/service.go b/beacon-chain/rpc/service.go index 7bacb36575e5..bf25fb3a8010 100644 --- a/beacon-chain/rpc/service.go +++ b/beacon-chain/rpc/service.go @@ -223,6 +223,7 @@ func (s *Service) Start() { BeaconDB: s.cfg.BeaconDB, ProposerSlotIndexCache: s.cfg.ProposerIdsCache, BlockBuilder: s.cfg.BlockBuilder, + BLSChangesPool: s.cfg.BLSChangesPool, } validatorServerV1 := &validator.Server{ HeadFetcher: s.cfg.HeadFetcher,