Update References to Deposit Contract, Update Flags (#1576)

* update readme

* rename k8 file
This commit is contained in:
Raul Jordan
2019-02-13 13:08:28 -06:00
committed by GitHub
parent b1f1dff8e5
commit fb9d60c377
15 changed files with 76 additions and 101 deletions

View File

@@ -63,8 +63,7 @@ VERSION:
app.Flags = []cli.Flag{
utils.DemoConfigFlag,
utils.VrcContractFlag,
utils.PubKeyFlag,
utils.DepositContractFlag,
utils.Web3ProviderFlag,
utils.RPCPort,
utils.CertFlag,

View File

@@ -233,7 +233,7 @@ func (b *BeaconNode) registerPOWChainService(ctx *cli.Context) error {
web3Service, err := powchain.NewWeb3Service(context.TODO(), &powchain.Web3ServiceConfig{
Endpoint: b.ctx.GlobalString(utils.Web3ProviderFlag.Name),
DepositContract: common.HexToAddress(b.ctx.GlobalString(utils.VrcContractFlag.Name)),
DepositContract: common.HexToAddress(b.ctx.GlobalString(utils.DepositContractFlag.Name)),
Client: powClient,
Reader: powClient,
Logger: powClient,

View File

@@ -212,24 +212,24 @@ func (w *Web3Service) HasChainStartLogOccurred() (bool, uint64, error) {
// ProcessLog is the main method which handles the processing of all
// logs from the deposit contract on the ETH1.0 chain.
func (w *Web3Service) ProcessLog(VRClog gethTypes.Log) {
func (w *Web3Service) ProcessLog(depositLog gethTypes.Log) {
// Process logs according to their event signature.
if VRClog.Topics[0] == hashutil.Hash(depositEventSignature) {
w.ProcessDepositLog(VRClog)
if depositLog.Topics[0] == hashutil.Hash(depositEventSignature) {
w.ProcessDepositLog(depositLog)
return
}
if VRClog.Topics[0] == hashutil.Hash(chainStartEventSignature) && !w.chainStarted {
w.ProcessChainStartLog(VRClog)
if depositLog.Topics[0] == hashutil.Hash(chainStartEventSignature) && !w.chainStarted {
w.ProcessChainStartLog(depositLog)
return
}
log.Debugf("Log is not of a valid event signature %#x", VRClog.Topics[0])
log.Debugf("Log is not of a valid event signature %#x", depositLog.Topics[0])
}
// ProcessDepositLog processes the log which had been received from
// the ETH1.0 chain by trying to ascertain which participant deposited
// in the contract.
func (w *Web3Service) ProcessDepositLog(VRClog gethTypes.Log) {
merkleRoot, depositData, merkleTreeIndex, _, err := contracts.UnpackDepositLogData(VRClog.Data)
func (w *Web3Service) ProcessDepositLog(depositLog gethTypes.Log) {
merkleRoot, depositData, merkleTreeIndex, _, err := contracts.UnpackDepositLogData(depositLog.Data)
if err != nil {
log.Errorf("Could not unpack log %v", err)
return
@@ -259,7 +259,7 @@ func (w *Web3Service) ProcessDepositLog(VRClog gethTypes.Log) {
if !w.chainStarted {
w.chainStartDeposits = append(w.chainStartDeposits, deposit)
} else {
w.beaconDB.InsertPendingDeposit(w.ctx, deposit, big.NewInt(int64(VRClog.BlockNumber)))
w.beaconDB.InsertPendingDeposit(w.ctx, deposit, big.NewInt(int64(depositLog.BlockNumber)))
}
log.WithFields(logrus.Fields{
"publicKey": fmt.Sprintf("%#x", depositInput.Pubkey),
@@ -270,9 +270,9 @@ func (w *Web3Service) ProcessDepositLog(VRClog gethTypes.Log) {
// ProcessChainStartLog processes the log which had been received from
// the ETH1.0 chain by trying to determine when to start the beacon chain.
func (w *Web3Service) ProcessChainStartLog(VRClog gethTypes.Log) {
func (w *Web3Service) ProcessChainStartLog(depositLog gethTypes.Log) {
chainStartCount.Inc()
receiptRoot, timestampData, err := contracts.UnpackChainStartLogData(VRClog.Data)
receiptRoot, timestampData, err := contracts.UnpackChainStartLogData(depositLog.Data)
if err != nil {
log.Errorf("Unable to unpack ChainStart log data %v", err)
return
@@ -320,7 +320,7 @@ func (w *Web3Service) run(done <-chan struct{}) {
}
logSub, err := w.logger.SubscribeFilterLogs(w.ctx, query, w.logChan)
if err != nil {
log.Errorf("Unable to query logs from VRC: %v", err)
log.Errorf("Unable to query logs from deposit contract: %v", err)
return
}
if err := w.processPastLogs(query); err != nil {
@@ -349,9 +349,9 @@ func (w *Web3Service) run(done <-chan struct{}) {
"blockNumber": w.blockNumber,
"blockHash": w.blockHash.Hex(),
}).Debug("Latest web3 chain event")
case VRClog := <-w.logChan:
case depositLog := <-w.logChan:
log.Info("Received deposit contract log")
w.ProcessLog(VRClog)
w.ProcessLog(depositLog)
}
}

View File

@@ -229,7 +229,7 @@ func TestStop(t *testing.T) {
hook.Reset()
}
func TestInitDataFromVRC(t *testing.T) {
func TestInitDataFromContract(t *testing.T) {
endpoint := "ws://127.0.0.1"
testAcc, err := setup()
if err != nil {
@@ -260,12 +260,12 @@ func TestInitDataFromVRC(t *testing.T) {
testAcc.txOpts.Value = amount32Eth
if _, err := testAcc.contract.Deposit(testAcc.txOpts, []byte{'a'}); err != nil {
t.Fatalf("Could not deposit to VRC %v", err)
t.Fatalf("Could not deposit to deposit contract %v", err)
}
testAcc.backend.Commit()
if err := web3Service.initDataFromContract(); err != nil {
t.Fatalf("Could not init from vrc: %v", err)
t.Fatalf("Could not init from deposit contract: %v", err)
}
if bytes.Equal(web3Service.depositRoot, []byte{}) {
@@ -399,7 +399,7 @@ func TestBadLogger(t *testing.T) {
web3Service.run(web3Service.ctx.Done())
msg := hook.LastEntry().Message
want := "Unable to query logs from VRC: subscription has failed"
want := "Unable to query logs from deposit contract: subscription has failed"
if msg != want {
t.Errorf("incorrect log, expected %s, got %s", want, msg)
}
@@ -444,7 +444,7 @@ func TestProcessDepositLog(t *testing.T) {
testAcc.txOpts.Value = amount32Eth
if _, err := testAcc.contract.Deposit(testAcc.txOpts, serializedData.Bytes()); err != nil {
t.Fatalf("Could not deposit to VRC %v", err)
t.Fatalf("Could not deposit to deposit contract %v", err)
}
testAcc.backend.Commit()
@@ -508,7 +508,7 @@ func TestProcessDepositLog_InsertsPendingDeposit(t *testing.T) {
testAcc.txOpts.Value = amount32Eth
if _, err := testAcc.contract.Deposit(testAcc.txOpts, serializedData.Bytes()); err != nil {
t.Fatalf("Could not deposit to VRC %v", err)
t.Fatalf("Could not deposit to deposit contract %v", err)
}
testAcc.backend.Commit()
@@ -571,7 +571,7 @@ func TestProcessDepositLog_SkipDuplicateLog(t *testing.T) {
testAcc.txOpts.Value = amount32Eth
if _, err := testAcc.contract.Deposit(testAcc.txOpts, serializedData.Bytes()); err != nil {
t.Fatalf("Could not deposit to VRC %v", err)
t.Fatalf("Could not deposit to deposit contract %v", err)
}
testAcc.backend.Commit()
@@ -643,7 +643,7 @@ func TestUnpackDepositLogs(t *testing.T) {
testAcc.txOpts.Value = amount32Eth
if _, err := testAcc.contract.Deposit(testAcc.txOpts, serializedData.Bytes()); err != nil {
t.Fatalf("Could not deposit to VRC %v", err)
t.Fatalf("Could not deposit to deposit contract %v", err)
}
testAcc.backend.Commit()
@@ -726,12 +726,12 @@ func TestProcessChainStartLog(t *testing.T) {
blocks.EncodeDepositData(data, amount32Eth.Uint64(), time.Now().Unix())
// 8 Validators are used as size required for beacon-chain to start. This number
// is defined in the VRC as the number required for the testnet. The actual number
// is defined in the deposit contract as the number required for the testnet. The actual number
// is 2**14
for i := 0; i < depositsReqForChainStart; i++ {
testAcc.txOpts.Value = amount32Eth
if _, err := testAcc.contract.Deposit(testAcc.txOpts, serializedData.Bytes()); err != nil {
t.Fatalf("Could not deposit to VRC %v", err)
t.Fatalf("Could not deposit to deposit contract %v", err)
}
testAcc.backend.Commit()
@@ -819,11 +819,11 @@ func TestUnpackChainStartLogs(t *testing.T) {
}
// 8 Validators are used as size required for beacon-chain to start. This number
// is defined in the VRC as the number required for the testnet.
// is defined in the deposit contract as the number required for the testnet.
for i := 0; i < depositsReqForChainStart; i++ {
testAcc.txOpts.Value = amount32Eth
if _, err := testAcc.contract.Deposit(testAcc.txOpts, serializedData.Bytes()); err != nil {
t.Fatalf("Could not deposit to VRC %v", err)
t.Fatalf("Could not deposit to deposit contract %v", err)
}
testAcc.backend.Commit()
@@ -894,11 +894,11 @@ func TestHasChainStartLogOccurred(t *testing.T) {
}
// 8 Validators are used as size required for beacon-chain to start. This number
// is defined in the VRC as the number required for the testnet.
// is defined in the deposit contract as the number required for the testnet.
for i := 0; i < depositsReqForChainStart; i++ {
testAcc.txOpts.Value = amount32Eth
if _, err := testAcc.contract.Deposit(testAcc.txOpts, serializedData.Bytes()); err != nil {
t.Fatalf("Could not deposit to VRC %v", err)
t.Fatalf("Could not deposit to deposit contract %v", err)
}
testAcc.backend.Commit()
}

View File

@@ -17,15 +17,10 @@ var (
Usage: "A mainchain web3 provider string endpoint. Can either be an IPC file string or a WebSocket endpoint. Uses WebSockets by default at ws://127.0.0.1:8546. Cannot be an HTTP endpoint.",
Value: "ws://127.0.0.1:8546",
}
// VrcContractFlag defines a flag for VRC contract address.
VrcContractFlag = cli.StringFlag{
Name: "vrcaddr",
Usage: "Validator registration contract address. Beacon chain node will listen logs coming from VRC to determine when validator is eligible to participate.",
}
// PubKeyFlag defines a flag for validator's public key on the mainchain
PubKeyFlag = cli.StringFlag{
Name: "pubkey",
Usage: "Validator's public key. Beacon chain node will listen to VRC log to determine when registration has completed based on this public key address.",
// DepositContractFlag defines a flag for the deposit contract address.
DepositContractFlag = cli.StringFlag{
Name: "deposit-contract",
Usage: "Deposit contract address. Beacon chain node will listen logs coming from the deposit contract to determine when validator is eligible to participate.",
}
// RPCPort defines a beacon node RPC port to open.
RPCPort = cli.StringFlag{

View File

@@ -65,7 +65,7 @@ container_push(
format = "Docker",
image = ":image",
registry = "gcr.io",
repository = "prysmaticlabs/prysm/deployvrc",
repository = "prysmaticlabs/prysm/deploy-deposit-contract",
tag = "latest",
tags = ["manual"],
visibility = ["//visibility:private"],

View File

@@ -5,52 +5,32 @@ This is a utility to help users deploy deposit contract for running their own be
### Usage
*Name:*
**deployVRC** - this is a util to deploy deposit contract
**deployContract** - this is a util to deploy deposit contract
*Usage:*
deployVRC [global options] command [command options] [arguments...]
deployContract [global options] command [command options] [arguments...]
*Flags:*
**--keystoreUTCPath** Keystore UTC file to unlock account (default: "./datadir/keystore/UTC...")
**--ipcPath** Filename for IPC socket/pipe within the datadir (default: "./geth.ipc")
**--httpPath** HTTP-RPC server listening interface (default: "http://localhost:8545/")
**--passwordFile** Password file for unlock account (default: "./password.txt")
**--privKey** Private key to unlock account
**--help, -h** show help
**--version, -v** print the version
- --skipChainstartDelay Whether to skip ChainStart log being fired a day later
- --ipcPath value Filename for IPC socket/pipe within the datadir
- --httpPath value HTTP-RPC server listening interface (default: "http://localhost:8545/")
- --passwordFile value Password file for unlock account (default: "./password.txt")
- --privKey value Private key to unlock account
- --k8sConfig value Name of kubernetes config map to update with the contract address
- --chainStart value Number of validators required for chain start (default: 16384)
- --minDeposit value Minimum deposit value allowed in contract (default: 1000000000)
- --maxDeposit value Maximum deposit value allowed in contract (default: 32000000000)
- --help, -h show help
- --version, -v print the version
### Example
To use private key with default RPC:
```
bazel run //deployVRC -- --privKey yourPrivateKey
bazel run //contracts/deposit-contract/deployContract -- --httpPath=https://goerli.prylabs.net --privKey=$(echo /path/to/private/key/file) --chainStart=8 --minDeposit=100 --maxDeposit=3200
```
To use UTC JSON with IPC:
```
bazel run //deployVRC --\
--ipcPath /path/to/your/geth.ipc \
--keystoreUTCPath /path/to/your/keystore/UTCJSON \
--passwordFile /path/to/your/password.txt
```
To use UTC JSON with RPC:
```
bazel run //deployVRC --\
--httpPath http://localhost:8545/ \
--keystoreUTCPath /path/to/your/keystore/UTCJSON \
--passwordFile /path/to/your/password.txt
```
or
```
bazel run //deployVRC --\
--keystoreUTCPath /path/to/your/keystore/UTCJSON \
--passwordFile /path/to/your/password.txt
```
### Output

View File

@@ -44,7 +44,7 @@ func main() {
log := logrus.WithField("prefix", "main")
app := cli.NewApp()
app.Name = "deployVRC"
app.Name = "deployDepositContract"
app.Usage = "this is a util to deploy deposit contract"
app.Version = version.GetVersion()
app.Flags = []cli.Flag{
@@ -131,7 +131,7 @@ func main() {
}
txOps = bind.NewKeyedTransactor(privKey)
txOps.Value = big.NewInt(0)
txOps.GasLimit = 4000000
// User inputs keystore json file, sign tx with keystore json
} else {
// #nosec - Inclusion of file via variable is OK for this tool.
@@ -157,6 +157,7 @@ func main() {
txOps = bind.NewKeyedTransactor(privKey.PrivateKey)
txOps.Value = big.NewInt(0)
txOps.GasLimit = 4000000
}
// Deploy validator registration contract
@@ -198,8 +199,8 @@ func main() {
}
// updateKubernetesConfigMap in the beacon-chain namespace. This specifically
// updates the data value for VALIDATOR_REGISTRATION_CONTRACT_ADDRESS.
func updateKubernetesConfigMap(configMapName string, vrcAddr string) error {
// updates the data value for DEPOSIT_CONTRACT_ADDRESS.
func updateKubernetesConfigMap(configMapName string, contractAddr string) error {
config, err := rest.InClusterConfig()
if err != nil {
return err
@@ -215,10 +216,10 @@ func updateKubernetesConfigMap(configMapName string, vrcAddr string) error {
return err
}
if cm.Data["VALIDATOR_REGISTRATION_CONTRACT_ADDRESS"] != "0x0" {
return fmt.Errorf("existing vcr address in config map = %v", cm.Data["VALIDATOR_REGISTRATION_CONTRACT_ADDRESS"])
if cm.Data["DEPOSIT_CONTRACT_ADDRESS"] != "0x0" {
return fmt.Errorf("existing vcr address in config map = %v", cm.Data["DEPOSIT_CONTRACT_ADDRESS"])
}
cm.Data["VALIDATOR_REGISTRATION_CONTRACT_ADDRESS"] = vrcAddr
cm.Data["DEPOSIT_CONTRACT_ADDRESS"] = contractAddr
_, err = client.CoreV1().ConfigMaps("beacon-chain").Update(cm)

View File

@@ -52,7 +52,7 @@ bazel build //validator:validator
## Deploy a Validator Registation Contract
Deploy the Validator Registration Contract into the chain of the running geth node by following the instructions [here](https://github.com/prysmaticlabs/prysm/blob/master/contracts/validator-registration-contract/deployVRC/README.md).
Deploy the Validator Registration Contract into the chain of the running geth node by following the instructions [here](https://github.com/prysmaticlabs/prysm/blob/master/contracts/deposit-contract/deployContract/README.md).
## Running a Beacon Node as a Validator

View File

@@ -94,7 +94,7 @@ deployment yaml.
TODO: This process is currently manual and needs to be improved!
Using the private key above and the deployVRC tool, deploy the validator
Using the private key above and the deployContract tool, deploy the validator
registration contract.
```bash
@@ -109,10 +109,10 @@ http://192.168.99.100:30051
http://192.168.99.100:31745
```
Using the first port provided (RPC). Run the deploy VRC tool
Using the first port provided (RPC). Run the deployContract tool
```
bazel run //contracts/validator-registration-contract/deployVRC --\
bazel run //contracts/deposit-contract/deployContract --\
--privKey=783da8ef5343c3019748506305d400bca8c324a5819f3a7f7fbf0c0a0d799b09 \
--httpPath=http://192.168.99.100:30051
```
@@ -123,7 +123,7 @@ Example output:
INFO main: New contract deployed address=0x541AfaC5266c534de039B4A1a53519e76ea82846
```
Set this value for the vrcaddr flag in
Set this value for the deposit contract addr flag in
k8s/beacon-chain/beacon-chain.deploy.yaml.
Ensure that the beacon-chain and client docker images are up to date.

View File

@@ -32,7 +32,7 @@ _deployments = [
]
_jobs = [
"deployvrc",
"deploydepositcontract",
]
_services = [
@@ -42,7 +42,7 @@ _services = [
]
_service_accounts = [
"deployvrc",
"deploydepositcontract",
]
k8s_objects(

View File

@@ -25,7 +25,7 @@ spec:
args:
- "--web3provider=ws://geth-nodes.pow.svc.cluster.local:8546"
- "--verbosity=debug"
- "--vrcaddr=$(VALIDATOR_REGISTRATION_CONTRACT_ADDRESS)"
- "--deposit-contract=$(DEPOSIT_CONTRACT_ADDRESS)"
- "--rpc-port=4000"
- "--monitoring-port=9090"
- "--bootstrap-node=/ip4/$(BOOTNODE_SERVICE_HOST)/tcp/$(BOOTNODE_SERVICE_PORT)/p2p/QmUWTsZwoJ51tey4fEE9EAqzQeHFHm4FE9aSfgTv8xyuG5"
@@ -46,8 +46,8 @@ spec:
- containerPort: 9090
name: prometheus
env:
- name: VALIDATOR_REGISTRATION_CONTRACT_ADDRESS
- name: DEPOSIT_CONTRACT_ADDRESS
valueFrom:
configMapKeyRef:
name: beacon-config
key: VALIDATOR_REGISTRATION_CONTRACT_ADDRESS
key: DEPOSIT_CONTRACT_ADDRESS

View File

@@ -4,4 +4,4 @@ metadata:
name: beacon-config
namespace: beacon-chain
data:
VALIDATOR_REGISTRATION_CONTRACT_ADDRESS: "0x0"
DEPOSIT_CONTRACT_ADDRESS: "0x0"

View File

@@ -1,7 +1,7 @@
apiVersion: batch/v1
kind: Job
metadata:
name: deploy-vrc
name: deploy-deposit-contract
namespace: beacon-chain
spec:
#ttlSecondsAfterFinished: 7200
@@ -10,10 +10,10 @@ spec:
template:
spec:
priorityClassName: batch-priority
serviceAccountName: deployvrc
serviceAccountName: deploydepositcontract
containers:
- name: deployvcr
image: gcr.io/prysmaticlabs/prysm/deployvrc:latest
image: gcr.io/prysmaticlabs/prysm/deploy-deposit-contract:latest
args:
- "--httpPath=http://geth-nodes.pow.svc.cluster.local:8545"
- "--privKey=783da8ef5343c3019748506305d400bca8c324a5819f3a7f7fbf0c0a0d799b09"

View File

@@ -1,13 +1,13 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: deployvrc
name: deploydepositcontract
namespace: beacon-chain
---
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: deployvrc
name: deploydepositcontract
rules:
- apiGroups:
- ""
@@ -20,13 +20,13 @@ rules:
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1beta1
metadata:
name: deployvrc
name: deploydepositcontract
subjects:
- kind: ServiceAccount
name: deployvrc
name: deploydepositcontract
namespace: beacon-chain
roleRef:
kind: ClusterRole
name: deployvrc
name: deploydepositcontract
apiGroup: rbac.authorization.k8s.io