mirror of
https://gitlab.com/pulsechaincom/prysm-pulse.git
synced 2025-01-09 19:21:19 +00:00
d58d3f2c57
* rewrite/refactor deposit testing code keep track of sent deposits so that they can be compared in detail with the validator set retreived from the API. * fix bugs in evaluator and retry * lint + deepsource appeasement * typo s/Sprintf/Printf/ * gosec, more like nosec * fix gosec number - 204->304 * type switch to get signed block from container * improve comments * centralizing constants and adding comments * lock around Depositor to avoid future races Co-authored-by: Kasey Kirkham <kasey@users.noreply.github.com>
67 lines
2.0 KiB
Go
67 lines
2.0 KiB
Go
package eth1
|
|
|
|
import (
|
|
"context"
|
|
"math/big"
|
|
"time"
|
|
|
|
"github.com/ethereum/go-ethereum/accounts/keystore"
|
|
"github.com/ethereum/go-ethereum/core/types"
|
|
"github.com/ethereum/go-ethereum/ethclient"
|
|
"github.com/prysmaticlabs/prysm/v3/testing/endtoend/params"
|
|
e2etypes "github.com/prysmaticlabs/prysm/v3/testing/endtoend/types"
|
|
)
|
|
|
|
// NetworkId is the ID of the ETH1 chain.
|
|
const NetworkId = 1337
|
|
|
|
// KeystorePassword is the password used to decrypt ETH1 keystores.
|
|
const KeystorePassword = "password"
|
|
|
|
const minerPasswordFile = "password.txt"
|
|
const minerFile = "UTC--2021-12-22T19-14-08.590377700Z--878705ba3f8bc32fcf7f4caa1a35e72af65cf766"
|
|
const timeGapPerTX = 100 * time.Millisecond
|
|
const timeGapPerMiningTX = 250 * time.Millisecond
|
|
|
|
var _ e2etypes.ComponentRunner = (*NodeSet)(nil)
|
|
var _ e2etypes.MultipleComponentRunners = (*NodeSet)(nil)
|
|
var _ e2etypes.MultipleComponentRunners = (*ProxySet)(nil)
|
|
var _ e2etypes.ComponentRunner = (*Miner)(nil)
|
|
var _ e2etypes.ComponentRunner = (*Node)(nil)
|
|
var _ e2etypes.EngineProxy = (*Proxy)(nil)
|
|
|
|
// WaitForBlocks waits for a certain amount of blocks to be mined by the ETH1 chain before returning.
|
|
func WaitForBlocks(web3 *ethclient.Client, key *keystore.Key, blocksToWait uint64) error {
|
|
nonce, err := web3.PendingNonceAt(context.Background(), key.Address)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
chainID, err := web3.NetworkID(context.Background())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
block, err := web3.BlockByNumber(context.Background(), nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
finishBlock := block.NumberU64() + blocksToWait
|
|
|
|
for block.NumberU64() <= finishBlock {
|
|
spamTX := types.NewTransaction(nonce, key.Address, big.NewInt(0), params.SpamTxGasLimit, big.NewInt(1e6), []byte{})
|
|
signed, err := types.SignTx(spamTX, types.NewEIP155Signer(chainID), key.PrivateKey)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if err = web3.SendTransaction(context.Background(), signed); err != nil {
|
|
return err
|
|
}
|
|
nonce++
|
|
time.Sleep(timeGapPerMiningTX)
|
|
block, err = web3.BlockByNumber(context.Background(), nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
}
|
|
return nil
|
|
}
|