mirror of
https://gitlab.com/pulsechaincom/erigon-pulse.git
synced 2024-12-22 03:30:37 +00:00
Withdrawal amount in GWei (#6578)
See https://github.com/ethereum/execution-apis/pull/354 & https://github.com/ethereum/EIPs/pull/6325. Prerequisite: https://github.com/ledgerwatch/erigon-lib/pull/832.
This commit is contained in:
parent
9e452fe8c4
commit
f151a52c0e
@ -85,7 +85,7 @@ func (e *Eth1Execution) InsertBodies(ctx context.Context, req *execution.InsertB
|
||||
Index: withdrawal.Index,
|
||||
Validator: withdrawal.ValidatorIndex,
|
||||
Address: gointerfaces.ConvertH160toAddress(withdrawal.Address),
|
||||
Amount: *gointerfaces.ConvertH256ToUint256Int(withdrawal.Amount),
|
||||
Amount: withdrawal.Amount,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"github.com/holiman/uint256"
|
||||
"github.com/ledgerwatch/erigon-lib/chain"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
|
||||
@ -136,7 +137,8 @@ func (s *Serenity) Finalize(config *chain.Config, header *types.Header, state *s
|
||||
}
|
||||
}
|
||||
for _, w := range withdrawals {
|
||||
state.AddBalance(w.Address, &w.Amount)
|
||||
amountInWei := new(uint256.Int).Mul(uint256.NewInt(w.Amount), uint256.NewInt(params.GWei))
|
||||
state.AddBalance(w.Address, amountInWei)
|
||||
}
|
||||
return txs, r, nil
|
||||
}
|
||||
|
@ -24,7 +24,6 @@ import (
|
||||
"math/big"
|
||||
"testing"
|
||||
|
||||
"github.com/holiman/uint256"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/kv/memdb"
|
||||
"github.com/stretchr/testify/require"
|
||||
@ -446,14 +445,14 @@ func TestBlockWithdrawalsStorage(t *testing.T) {
|
||||
Index: uint64(15),
|
||||
Validator: uint64(5500),
|
||||
Address: libcommon.Address{0: 0xff},
|
||||
Amount: *uint256.NewInt(1000),
|
||||
Amount: 1000,
|
||||
}
|
||||
|
||||
w2 := types.Withdrawal{
|
||||
Index: uint64(16),
|
||||
Validator: uint64(5501),
|
||||
Address: libcommon.Address{0: 0xff},
|
||||
Amount: *uint256.NewInt(1001),
|
||||
Amount: 1001,
|
||||
}
|
||||
|
||||
withdrawals := make([]*types.Withdrawal, 0)
|
||||
@ -523,13 +522,13 @@ func TestBlockWithdrawalsStorage(t *testing.T) {
|
||||
require.Equal(uint64(15), rw.Index)
|
||||
require.Equal(uint64(5500), rw.Validator)
|
||||
require.Equal(libcommon.Address{0: 0xff}, rw.Address)
|
||||
require.Equal(*uint256.NewInt(1000), rw.Amount)
|
||||
require.Equal(uint64(1000), rw.Amount)
|
||||
|
||||
require.NotNil(rw2)
|
||||
require.Equal(uint64(16), rw2.Index)
|
||||
require.Equal(uint64(5501), rw2.Validator)
|
||||
require.Equal(libcommon.Address{0: 0xff}, rw2.Address)
|
||||
require.Equal(*uint256.NewInt(1001), rw2.Amount)
|
||||
require.Equal(uint64(1001), rw2.Amount)
|
||||
|
||||
// Delete the block and verify the execution
|
||||
if err := TruncateBlocks(context.Background(), tx, block.NumberU64()); err != nil {
|
||||
|
@ -408,13 +408,13 @@ func TestWithdrawalsEncoding(t *testing.T) {
|
||||
Index: 44555666,
|
||||
Validator: 89,
|
||||
Address: libcommon.HexToAddress("0x690b9a9e9aa1c9db991c7721a92d351db4fac990"),
|
||||
Amount: *uint256.NewInt(2 * params.Ether),
|
||||
Amount: 2,
|
||||
}
|
||||
withdrawals[1] = &Withdrawal{
|
||||
Index: 44555667,
|
||||
Validator: 37,
|
||||
Address: libcommon.HexToAddress("0x95222290dd7278aa3ddd389cc1e1d165cc4bafe5"),
|
||||
Amount: *uint256.NewInt(5 * params.Ether),
|
||||
Amount: 5_000_000_000,
|
||||
}
|
||||
|
||||
block := NewBlock(&header, nil, nil, nil, withdrawals)
|
||||
|
@ -5,7 +5,6 @@ package types
|
||||
import (
|
||||
"encoding/json"
|
||||
|
||||
"github.com/holiman/uint256"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
|
||||
"github.com/ledgerwatch/erigon/common/hexutil"
|
||||
@ -16,26 +15,26 @@ var _ = (*withdrawalMarshaling)(nil)
|
||||
// MarshalJSON marshals as JSON.
|
||||
func (w Withdrawal) MarshalJSON() ([]byte, error) {
|
||||
type Withdrawal struct {
|
||||
Index hexutil.Uint64 `json:"index"`
|
||||
Validator hexutil.Uint64 `json:"validatorIndex"`
|
||||
Index hexutil.Uint64 `json:"index"`
|
||||
Validator hexutil.Uint64 `json:"validatorIndex"`
|
||||
Address libcommon.Address `json:"address"`
|
||||
Amount uint256.Int `json:"amount"`
|
||||
Amount hexutil.Uint64 `json:"amount"`
|
||||
}
|
||||
var enc Withdrawal
|
||||
enc.Index = hexutil.Uint64(w.Index)
|
||||
enc.Validator = hexutil.Uint64(w.Validator)
|
||||
enc.Address = w.Address
|
||||
enc.Amount = w.Amount
|
||||
enc.Amount = hexutil.Uint64(w.Amount)
|
||||
return json.Marshal(&enc)
|
||||
}
|
||||
|
||||
// UnmarshalJSON unmarshals from JSON.
|
||||
func (w *Withdrawal) UnmarshalJSON(input []byte) error {
|
||||
type Withdrawal struct {
|
||||
Index *hexutil.Uint64 `json:"index"`
|
||||
Validator *hexutil.Uint64 `json:"validatorIndex"`
|
||||
Index *hexutil.Uint64 `json:"index"`
|
||||
Validator *hexutil.Uint64 `json:"validatorIndex"`
|
||||
Address *libcommon.Address `json:"address"`
|
||||
Amount *uint256.Int `json:"amount"`
|
||||
Amount *hexutil.Uint64 `json:"amount"`
|
||||
}
|
||||
var dec Withdrawal
|
||||
if err := json.Unmarshal(input, &dec); err != nil {
|
||||
@ -51,7 +50,7 @@ func (w *Withdrawal) UnmarshalJSON(input []byte) error {
|
||||
w.Address = *dec.Address
|
||||
}
|
||||
if dec.Amount != nil {
|
||||
w.Amount = *dec.Amount
|
||||
w.Amount = uint64(*dec.Amount)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -21,7 +21,6 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/holiman/uint256"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/ledgerwatch/erigon-lib/common/length"
|
||||
|
||||
@ -39,7 +38,7 @@ type Withdrawal struct {
|
||||
Index uint64 `json:"index"` // monotonically increasing identifier issued by consensus layer
|
||||
Validator uint64 `json:"validatorIndex"` // index of validator associated with withdrawal
|
||||
Address libcommon.Address `json:"address"` // target address for withdrawn ether
|
||||
Amount uint256.Int `json:"amount"` // value of withdrawal in wei
|
||||
Amount uint64 `json:"amount"` // value of withdrawal in GWei
|
||||
}
|
||||
|
||||
func (obj *Withdrawal) EncodingSize() int {
|
||||
@ -49,7 +48,7 @@ func (obj *Withdrawal) EncodingSize() int {
|
||||
encodingSize++
|
||||
encodingSize += rlp.IntLenExcludingHead(obj.Validator)
|
||||
encodingSize++
|
||||
encodingSize += rlp.Uint256LenExcludingHead(&obj.Amount)
|
||||
encodingSize += rlp.IntLenExcludingHead(obj.Amount)
|
||||
return encodingSize
|
||||
}
|
||||
|
||||
@ -76,7 +75,7 @@ func (obj *Withdrawal) EncodeRLP(w io.Writer) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return obj.Amount.EncodeRLP(w)
|
||||
return rlp.EncodeInt(obj.Amount, w, b[:])
|
||||
}
|
||||
|
||||
func (obj *Withdrawal) EncodeSSZ() []byte {
|
||||
@ -84,8 +83,7 @@ func (obj *Withdrawal) EncodeSSZ() []byte {
|
||||
ssz_utils.MarshalUint64SSZ(buf, obj.Index)
|
||||
ssz_utils.MarshalUint64SSZ(buf[8:], obj.Validator)
|
||||
copy(buf[16:], obj.Address[:])
|
||||
// Supports only GWEI format.
|
||||
ssz_utils.MarshalUint64SSZ(buf[36:], obj.Amount.Uint64())
|
||||
ssz_utils.MarshalUint64SSZ(buf[36:], obj.Amount)
|
||||
return buf
|
||||
}
|
||||
|
||||
@ -96,7 +94,7 @@ func (obj *Withdrawal) DecodeSSZ(buf []byte) error {
|
||||
obj.Index = ssz_utils.UnmarshalUint64SSZ(buf)
|
||||
obj.Validator = ssz_utils.UnmarshalUint64SSZ(buf[8:])
|
||||
copy(obj.Address[:], buf[16:])
|
||||
obj.Amount = *uint256.NewInt(ssz_utils.UnmarshalUint64SSZ(buf[36:]))
|
||||
obj.Amount = ssz_utils.UnmarshalUint64SSZ(buf[36:])
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -112,7 +110,7 @@ func (obj *Withdrawal) HashSSZ() ([32]byte, error) { // the [32]byte is temporar
|
||||
merkle_tree.Uint64Root(obj.Index),
|
||||
merkle_tree.Uint64Root(obj.Validator),
|
||||
addressLeaf,
|
||||
merkle_tree.Uint64Root(obj.Amount.Uint64()),
|
||||
merkle_tree.Uint64Root(obj.Amount),
|
||||
}, 4)
|
||||
}
|
||||
|
||||
@ -138,10 +136,9 @@ func (obj *Withdrawal) DecodeRLP(s *rlp.Stream) error {
|
||||
}
|
||||
copy(obj.Address[:], b)
|
||||
|
||||
if b, err = s.Uint256Bytes(); err != nil {
|
||||
if obj.Amount, err = s.Uint(); err != nil {
|
||||
return fmt.Errorf("read Amount: %w", err)
|
||||
}
|
||||
obj.Amount.SetBytes(b)
|
||||
|
||||
return s.ListEnd()
|
||||
}
|
||||
@ -150,7 +147,7 @@ func (obj *Withdrawal) DecodeRLP(s *rlp.Stream) error {
|
||||
type withdrawalMarshaling struct {
|
||||
Index hexutil.Uint64
|
||||
Validator hexutil.Uint64
|
||||
Amount *hexutil.Big
|
||||
Amount hexutil.Uint64
|
||||
}
|
||||
|
||||
// Withdrawals implements DerivableList for withdrawals.
|
||||
|
@ -3,13 +3,11 @@ package types
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/holiman/uint256"
|
||||
libcommon "github.com/ledgerwatch/erigon-lib/common"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
|
||||
"github.com/ledgerwatch/erigon/common"
|
||||
"github.com/ledgerwatch/erigon/common/u256"
|
||||
)
|
||||
|
||||
func TestWithdrawalsHash(t *testing.T) {
|
||||
@ -17,7 +15,7 @@ func TestWithdrawalsHash(t *testing.T) {
|
||||
Index: 0,
|
||||
Validator: 0,
|
||||
Address: libcommon.HexToAddress("0x6295ee1b4f6dd65047762f924ecd367c17eabf8f"),
|
||||
Amount: *u256.Num1,
|
||||
Amount: 1,
|
||||
}
|
||||
withdrawals := Withdrawals([]*Withdrawal{w})
|
||||
hash := DeriveSha(withdrawals)
|
||||
@ -33,7 +31,7 @@ var testWithdrawal = &Withdrawal{
|
||||
Index: 9170781944418253065,
|
||||
Validator: 16033042974434771745,
|
||||
Address: libcommon.HexToAddress("0xdbbcbcbeee17b2395d5d3f839fc1ba3559d1a73e"),
|
||||
Amount: *uint256.NewInt(15157676145812061173),
|
||||
Amount: 15157676145812061173,
|
||||
}
|
||||
|
||||
func TestWithdrawalSSZ(t *testing.T) {
|
||||
|
@ -724,7 +724,7 @@ func ConvertWithdrawalsFromRpc(in []*types2.Withdrawal) []*types.Withdrawal {
|
||||
Index: w.Index,
|
||||
Validator: w.ValidatorIndex,
|
||||
Address: gointerfaces.ConvertH160toAddress(w.Address),
|
||||
Amount: *gointerfaces.ConvertH256ToUint256Int(w.Amount),
|
||||
Amount: w.Amount,
|
||||
})
|
||||
}
|
||||
return out
|
||||
@ -737,7 +737,7 @@ func ConvertWithdrawalsToRpc(in []*types.Withdrawal) []*types2.Withdrawal {
|
||||
Index: w.Index,
|
||||
ValidatorIndex: w.Validator,
|
||||
Address: gointerfaces.ConvertAddressToH160(w.Address),
|
||||
Amount: gointerfaces.ConvertUint256IntToH256(&w.Amount),
|
||||
Amount: w.Amount,
|
||||
})
|
||||
}
|
||||
return out
|
||||
|
2
go.mod
2
go.mod
@ -3,7 +3,7 @@ module github.com/ledgerwatch/erigon
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
github.com/ledgerwatch/erigon-lib v0.0.0-20230117064926-4d298d0017b0
|
||||
github.com/ledgerwatch/erigon-lib v0.0.0-20230117095843-fc3dd4fd2789
|
||||
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230117072003-4cc5ebded386
|
||||
github.com/ledgerwatch/log/v3 v3.7.0
|
||||
github.com/ledgerwatch/secp256k1 v1.0.0
|
||||
|
4
go.sum
4
go.sum
@ -565,8 +565,8 @@ github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
|
||||
github.com/kylelemons/godebug v0.0.0-20170224010052-a616ab194758 h1:0D5M2HQSGD3PYPwICLl+/9oulQauOuETfgFvhBDffs0=
|
||||
github.com/leanovate/gopter v0.2.9 h1:fQjYxZaynp97ozCzfOyOuAGOU4aU/z37zf/tOujFk7c=
|
||||
github.com/leanovate/gopter v0.2.9/go.mod h1:U2L/78B+KVFIx2VmW6onHJQzXtFb+p5y3y2Sh+Jxxv8=
|
||||
github.com/ledgerwatch/erigon-lib v0.0.0-20230117064926-4d298d0017b0 h1:eNvCZ1rQO//pQRoNW7VqwEO3YiP3TW8mcam7k4fTQfo=
|
||||
github.com/ledgerwatch/erigon-lib v0.0.0-20230117064926-4d298d0017b0/go.mod h1:tsfqxwRd5LYjXQyrC085+61iHp6Vwi1nOhxjro3w0Wo=
|
||||
github.com/ledgerwatch/erigon-lib v0.0.0-20230117095843-fc3dd4fd2789 h1:y/XlIJal2I99Eu/zQj6aM3oynxmK0Xc89nUG/WCMVsY=
|
||||
github.com/ledgerwatch/erigon-lib v0.0.0-20230117095843-fc3dd4fd2789/go.mod h1:1UHFnZQCpr37W397IJf68OxYv3iQmBTU9D7t3LUHbPo=
|
||||
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230117072003-4cc5ebded386 h1:dpTtuW3uRhwbS81yWRX1arSLDyCDFfe8MWGhXx5lGas=
|
||||
github.com/ledgerwatch/erigon-snapshot v1.1.1-0.20230117072003-4cc5ebded386/go.mod h1:3AuPxZc85jkehh/HA9h8gabv5MSi3kb/ddtzBsTVJFo=
|
||||
github.com/ledgerwatch/log/v3 v3.7.0 h1:aFPEZdwZx4jzA3+/Pf8wNDN5tCI0cIolq/kfvgcM+og=
|
||||
|
@ -38,6 +38,10 @@ func TestBlockchain(t *testing.T) {
|
||||
// For speedier CI-runs those are skipped.
|
||||
bt.skipLoad(`^GeneralStateTests/`)
|
||||
|
||||
// TODO(yperbasis): re-enable after the tests are updated to GWei
|
||||
bt.skipLoad(`^EIPTests/bc4895-withdrawals/`)
|
||||
bt.skipLoad(`^TransitionTests/bcMergeToShanghai/`)
|
||||
|
||||
// Currently it fails because SpawnStageHeaders doesn't accept any PoW blocks after PoS transition
|
||||
// TODO(yperbasis): make it work
|
||||
bt.skipLoad(`^TransitionTests/bcArrowGlacierToMerge/powToPosBlockRejection\.json`)
|
||||
|
@ -15,8 +15,8 @@ func TestExecutionSpec(t *testing.T) {
|
||||
|
||||
dir := filepath.Join(".", "execution-spec-tests")
|
||||
|
||||
// Failing because the fixture was filled by geth w/o EIP-3860
|
||||
bt.skipLoad(`^withdrawals/withdrawals/withdrawals_newly_created_contract.json`)
|
||||
// TODO(yperbasis): re-fill and re-enable after Wei -> Gwei in geth
|
||||
bt.skipLoad(`^withdrawals/withdrawals`)
|
||||
|
||||
bt.walk(t, dir, func(t *testing.T, name string, test *BlockTest) {
|
||||
// import pre accounts & construct test genesis block & state root
|
||||
|
Loading…
Reference in New Issue
Block a user