diff --git a/beacon-chain/powchain/BUILD.bazel b/beacon-chain/powchain/BUILD.bazel index 093b34d78..7de728e9d 100644 --- a/beacon-chain/powchain/BUILD.bazel +++ b/beacon-chain/powchain/BUILD.bazel @@ -17,6 +17,8 @@ go_library( "@com_github_ethereum_go_ethereum//accounts/abi/bind:go_default_library", "@com_github_ethereum_go_ethereum//common:go_default_library", "@com_github_ethereum_go_ethereum//core/types:go_default_library", + "@com_github_prometheus_client_golang//prometheus:go_default_library", + "@com_github_prometheus_client_golang//prometheus/promauto:go_default_library", "@com_github_sirupsen_logrus//:go_default_library", ], ) diff --git a/beacon-chain/powchain/service.go b/beacon-chain/powchain/service.go index 365b22af1..7c2a212a0 100644 --- a/beacon-chain/powchain/service.go +++ b/beacon-chain/powchain/service.go @@ -14,6 +14,8 @@ import ( "github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/common" gethTypes "github.com/ethereum/go-ethereum/core/types" + "github.com/prometheus/client_golang/prometheus" + "github.com/prometheus/client_golang/prometheus/promauto" "github.com/prysmaticlabs/prysm/beacon-chain/core/blocks" "github.com/prysmaticlabs/prysm/beacon-chain/db" contracts "github.com/prysmaticlabs/prysm/contracts/deposit-contract" @@ -26,6 +28,25 @@ import ( var log = logrus.WithField("prefix", "powchain") +var ( + validDepositsCount = promauto.NewCounter(prometheus.CounterOpts{ + Name: "powchain_valid_deposits_received", + Help: "The number of valid deposits received in the deposit contract", + }) + totalDepositsCount = promauto.NewCounter(prometheus.CounterOpts{ + Name: "powchain_deposit_logs", + Help: "The total number of deposits received in the deposit contract", + }) + chainStartCount = promauto.NewCounter(prometheus.CounterOpts{ + Name: "powchain_chainstart_logs", + Help: "The number of chainstart logs received from the deposit contract", + }) + blockNumberGauge = promauto.NewGauge(prometheus.GaugeOpts{ + Name: "powchain_block_number", + Help: "The current block number in the proof-of-work chain", + }) +) + // Reader defines a struct that can fetch latest header events from a web3 endpoint. type Reader interface { SubscribeNewHead(ctx context.Context, ch chan<- *gethTypes.Header) (ethereum.Subscription, error) @@ -225,6 +246,7 @@ func (w *Web3Service) ProcessLog(VRClog gethTypes.Log) { // the ETH1.0 chain by trying to ascertain which participant deposited // in the contract. func (w *Web3Service) ProcessDepositLog(VRClog gethTypes.Log) { + totalDepositsCount.Inc() merkleRoot, depositData, MerkleTreeIndex, err := contracts.UnpackDepositLogData(VRClog.Data) if err != nil { log.Errorf("Could not unpack log %v", err) @@ -252,11 +274,14 @@ func (w *Web3Service) ProcessDepositLog(VRClog gethTypes.Log) { "publicKey": fmt.Sprintf("%#x", depositInput.Pubkey), "merkleTreeIndex": index, }).Info("Validator registered in deposit contract") + + validDepositsCount.Inc() } // 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) { + chainStartCount.Inc() receiptRoot, timestampData, err := contracts.UnpackChainStartLogData(VRClog.Data) if err != nil { log.Errorf("Unable to unpack ChainStart log data %v", err) @@ -321,6 +346,7 @@ func (w *Web3Service) run(done <-chan struct{}) { log.Debug("Unsubscribed to log events, exiting goroutine") return case header := <-w.headerChan: + blockNumberGauge.Set(float64(header.Number.Int64())) w.blockNumber = header.Number w.blockHash = header.Hash() log.WithFields(logrus.Fields{