Skip to content

Commit

Permalink
Add Partial Deposits in E2E (#7801)
Browse files Browse the repository at this point in the history
* Partial Deposits in E2E

* Undo changes made to evaluator

Co-authored-by: Raul Jordan <raul@prysmaticlabs.com>
  • Loading branch information
0xKiwi and rauljordan committed Nov 13, 2020
1 parent 16bccf0 commit da835af
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 13 deletions.
1 change: 1 addition & 0 deletions endtoend/components/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ go_library(
"//endtoend/helpers:go_default_library",
"//endtoend/params:go_default_library",
"//endtoend/types:go_default_library",
"//shared/bytesutil:go_default_library",
"//shared/featureconfig:go_default_library",
"//shared/params:go_default_library",
"//shared/testutil:go_default_library",
Expand Down
39 changes: 28 additions & 11 deletions endtoend/components/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/prysmaticlabs/prysm/endtoend/helpers"
e2e "github.com/prysmaticlabs/prysm/endtoend/params"
"github.com/prysmaticlabs/prysm/endtoend/types"
"github.com/prysmaticlabs/prysm/shared/bytesutil"
"github.com/prysmaticlabs/prysm/shared/featureconfig"
"github.com/prysmaticlabs/prysm/shared/params"
"github.com/prysmaticlabs/prysm/shared/testutil"
Expand Down Expand Up @@ -83,7 +84,7 @@ func StartNewValidatorClient(t *testing.T, config *types.E2EConfig, validatorNum
}

// SendAndMineDeposits sends the requested amount of deposits and mines the chain after to ensure the deposits are seen.
func SendAndMineDeposits(t *testing.T, keystorePath string, validatorNum, offset int) {
func SendAndMineDeposits(t *testing.T, keystorePath string, validatorNum, offset int, partial bool) {
client, err := rpc.DialHTTP(fmt.Sprintf("http://127.0.0.1:%d", e2e.TestParams.Eth1RPCPort))
if err != nil {
t.Fatal(err)
Expand All @@ -95,7 +96,7 @@ func SendAndMineDeposits(t *testing.T, keystorePath string, validatorNum, offset
if err != nil {
t.Fatal(err)
}
if err = sendDeposits(web3, keystoreBytes, validatorNum, offset); err != nil {
if err = sendDeposits(web3, keystoreBytes, validatorNum, offset, partial); err != nil {
t.Fatal(err)
}
mineKey, err := keystore.DecryptKey(keystoreBytes, "" /*password*/)
Expand All @@ -108,13 +109,11 @@ func SendAndMineDeposits(t *testing.T, keystorePath string, validatorNum, offset
}

// sendDeposits uses the passed in web3 and keystore bytes to send the requested deposits.
func sendDeposits(web3 *ethclient.Client, keystoreBytes []byte, num, offset int) error {
func sendDeposits(web3 *ethclient.Client, keystoreBytes []byte, num int, offset int, partial bool) error {
txOps, err := bind.NewTransactor(bytes.NewReader(keystoreBytes), "" /*password*/)
if err != nil {
return err
}
depositInGwei := big.NewInt(int64(params.BeaconConfig().MaxEffectiveBalance))
txOps.Value = depositInGwei.Mul(depositInGwei, big.NewInt(int64(params.BeaconConfig().GweiPerEth)))
txOps.GasLimit = depositGasLimit
nonce, err := web3.PendingNonceAt(context.Background(), txOps.From)
if err != nil {
Expand All @@ -127,19 +126,37 @@ func sendDeposits(web3 *ethclient.Client, keystoreBytes []byte, num, offset int)
return err
}

deposits, _, err := testutil.DeterministicDepositsAndKeys(uint64(num + offset))
if err != nil {
return err
balances := make([]uint64, num+offset)
for i := 0; i < len(balances); i++ {
if i < len(balances)/2 && partial {
balances[i] = params.BeaconConfig().MaxEffectiveBalance / 2
} else {
balances[i] = params.BeaconConfig().MaxEffectiveBalance
}
}
_, roots, err := testutil.DeterministicDepositTrie(len(deposits))
deposits, trie, err := testutil.DepositsWithBalance(balances)
if err != nil {
return err
}
for index, dd := range deposits {
allDeposits := deposits
allRoots := trie.Items()
allBalances := balances
if partial {
deposits2, trie2, err := testutil.DepositsWithBalance(balances)
if err != nil {
return err
}
allDeposits = append(deposits, deposits2[:len(balances)/2]...)
allRoots = append(trie.Items(), trie2.Items()[:len(balances)/2]...)
allBalances = append(balances, balances[:len(balances)/2]...)
}
for index, dd := range allDeposits {
if index < offset {
continue
}
_, err = contract.Deposit(txOps, dd.Data.PublicKey, dd.Data.WithdrawalCredentials, dd.Data.Signature, roots[index])
depositInGwei := big.NewInt(int64(allBalances[index]))
txOps.Value = depositInGwei.Mul(depositInGwei, big.NewInt(int64(params.BeaconConfig().GweiPerEth)))
_, err = contract.Deposit(txOps, dd.Data.PublicKey, dd.Data.WithdrawalCredentials, dd.Data.Signature, bytesutil.ToBytes32(allRoots[index]))
if err != nil {
return errors.Wrap(err, "unable to send transaction to contract")
}
Expand Down
4 changes: 2 additions & 2 deletions endtoend/endtoend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ func runEndToEndTest(t *testing.T, config *types.E2EConfig) {
minGenesisActiveCount := int(params.BeaconConfig().MinGenesisActiveValidatorCount)

keystorePath := components.StartEth1Node(t)
go components.SendAndMineDeposits(t, keystorePath, minGenesisActiveCount, 0)
go components.SendAndMineDeposits(t, keystorePath, minGenesisActiveCount, 0, true /* partial */)
bootnodeENR := components.StartBootnode(t)
components.StartBeaconNodes(t, config, bootnodeENR)
components.StartValidatorClients(t, config)
Expand Down Expand Up @@ -71,7 +71,7 @@ func runEndToEndTest(t *testing.T, config *types.E2EConfig) {
}
if config.TestDeposits {
go components.StartNewValidatorClient(t, config, int(e2e.DepositCount), e2e.TestParams.BeaconNodeCount, minGenesisActiveCount)
go components.SendAndMineDeposits(t, keystorePath, int(e2e.DepositCount), minGenesisActiveCount)
go components.SendAndMineDeposits(t, keystorePath, int(e2e.DepositCount), minGenesisActiveCount, false /* partial */)
}

conns := make([]*grpc.ClientConn, e2e.TestParams.BeaconNodeCount)
Expand Down

0 comments on commit da835af

Please sign in to comment.