mirror of
https://github.com/OffchainLabs/prysm.git
synced 2026-01-10 16:08:26 -05:00
Resolve Miscellaneous Bugs in Beacon Node (#4743)
* add in nil check for head block * fix logic * unused import
This commit is contained in:
@@ -18,10 +18,6 @@ var (
|
||||
Name: "beacon_head_slot",
|
||||
Help: "Slot of the head block of the beacon chain",
|
||||
})
|
||||
competingAtts = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Name: "competing_attestations",
|
||||
Help: "The # of attestations received and processed from a competing chain",
|
||||
})
|
||||
competingBlks = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Name: "competing_blocks",
|
||||
Help: "The # of blocks received and processed from a competing chain",
|
||||
@@ -42,10 +38,6 @@ var (
|
||||
Name: "processed_no_pubsub_attestation_counter",
|
||||
Help: "The # of processed attestation without pubsub, this usually means the attestations from sync",
|
||||
})
|
||||
processedAtt = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Name: "processed_attestation_counter",
|
||||
Help: "The # of processed attestation with pubsub and fork choice, this ususally means attestations from rpc",
|
||||
})
|
||||
headFinalizedEpoch = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "chain_service_head_finalized_epoch",
|
||||
Help: "Last finalized epoch of the head state",
|
||||
@@ -62,14 +54,6 @@ var (
|
||||
Name: "chain_service_beacon_finalized_root",
|
||||
Help: "Last finalized root of the processed state",
|
||||
})
|
||||
cacheFinalizedEpoch = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "chain_service_cache_finalized_epoch",
|
||||
Help: "Last cached finalized epoch",
|
||||
})
|
||||
cacheFinalizedRoot = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "chain_service_cache_finalized_root",
|
||||
Help: "Last cached finalized root",
|
||||
})
|
||||
beaconCurrentJustifiedEpoch = promauto.NewGauge(prometheus.GaugeOpts{
|
||||
Name: "chain_service_beacon_current_justified_epoch",
|
||||
Help: "Current justified epoch of the processed state",
|
||||
@@ -86,10 +70,6 @@ var (
|
||||
Name: "chain_service_beacon_previous_justified_root",
|
||||
Help: "Previous justified root of the processed state",
|
||||
})
|
||||
sigFailsToVerify = promauto.NewCounter(prometheus.CounterOpts{
|
||||
Name: "chain_service_att_signature_failed_to_verify_with_cache",
|
||||
Help: "Number of attestation signatures that failed to verify with cache on, but succeeded without cache",
|
||||
})
|
||||
validatorsCount = promauto.NewGaugeVec(prometheus.GaugeOpts{
|
||||
Name: "chain_service_validator_count",
|
||||
Help: "The total number of validators",
|
||||
|
||||
@@ -117,7 +117,7 @@ func (s *Service) processAttestation() {
|
||||
"beaconBlockRoot": fmt.Sprintf("%#x", bytesutil.Trunc(a.Data.BeaconBlockRoot)),
|
||||
"targetRoot": fmt.Sprintf("%#x", bytesutil.Trunc(a.Data.Target.Root)),
|
||||
"aggregationCount": a.AggregationBits.Count(),
|
||||
}).WithError(err).Error("Could not receive attestation in chain service")
|
||||
}).WithError(err).Warn("Could not receive attestation in chain service")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -591,7 +591,7 @@ func (s *Service) run(done <-chan struct{}) {
|
||||
log.Debug("Context closed, exiting goroutine")
|
||||
return
|
||||
case s.runError = <-headSub.Err():
|
||||
log.WithError(s.runError).Error("Subscription to new head notifier failed")
|
||||
log.WithError(s.runError).Warn("Subscription to new head notifier failed")
|
||||
s.connectedETH1 = false
|
||||
s.waitForConnection()
|
||||
headSub, err = s.reader.SubscribeNewHead(s.ctx, s.headerChan)
|
||||
|
||||
@@ -206,6 +206,9 @@ func (bs *Server) StreamChainHead(_ *ptypes.Empty, stream ethpb.BeaconChain_Stre
|
||||
// Retrieve chain head information from the DB and the current beacon state.
|
||||
func (bs *Server) chainHeadRetrieval(ctx context.Context) (*ethpb.ChainHead, error) {
|
||||
headBlock := bs.HeadFetcher.HeadBlock()
|
||||
if headBlock == nil {
|
||||
return nil, status.Error(codes.Internal, "Head block of chain was nil")
|
||||
}
|
||||
headBlockRoot, err := ssz.HashTreeRoot(headBlock.Block)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Could not get head block root: %v", err)
|
||||
|
||||
@@ -346,6 +346,20 @@ func TestServer_GetChainHead_NoFinalizedBlock(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestServer_GetChainHead_NoHeadBlock(t *testing.T) {
|
||||
bs := &Server{
|
||||
HeadFetcher: &mock.ChainService{Block: nil},
|
||||
}
|
||||
if _, err := bs.GetChainHead(context.Background(), nil); err != nil && !strings.Contains(
|
||||
err.Error(),
|
||||
"Head block of chain was nil",
|
||||
) {
|
||||
t.Fatal("Did not get wanted error")
|
||||
} else if err == nil {
|
||||
t.Error("Expected error, received nil")
|
||||
}
|
||||
}
|
||||
|
||||
func TestServer_GetChainHead(t *testing.T) {
|
||||
db := dbTest.SetupDB(t)
|
||||
defer dbTest.TeardownDB(t, db)
|
||||
|
||||
@@ -81,28 +81,28 @@ func (r *Service) registerRPC(topic string, base interface{}, handle rpcHandler)
|
||||
if t.Kind() == reflect.Ptr {
|
||||
msg := reflect.New(t.Elem())
|
||||
if err := r.p2p.Encoding().DecodeWithLength(stream, msg.Interface()); err != nil {
|
||||
log.WithError(err).Error("Failed to decode stream message")
|
||||
log.WithError(err).Warn("Failed to decode stream message")
|
||||
traceutil.AnnotateError(span, err)
|
||||
return
|
||||
}
|
||||
if err := handle(ctx, msg.Interface(), stream); err != nil {
|
||||
messageFailedProcessingCounter.WithLabelValues(topic).Inc()
|
||||
if err != errWrongForkVersion {
|
||||
log.WithError(err).Error("Failed to handle p2p RPC")
|
||||
log.WithError(err).Warn("Failed to handle p2p RPC")
|
||||
}
|
||||
traceutil.AnnotateError(span, err)
|
||||
}
|
||||
} else {
|
||||
msg := reflect.New(t)
|
||||
if err := r.p2p.Encoding().DecodeWithLength(stream, msg.Interface()); err != nil {
|
||||
log.WithError(err).Error("Failed to decode stream message")
|
||||
log.WithError(err).Warn("Failed to decode stream message")
|
||||
traceutil.AnnotateError(span, err)
|
||||
return
|
||||
}
|
||||
if err := handle(ctx, msg.Elem().Interface(), stream); err != nil {
|
||||
messageFailedProcessingCounter.WithLabelValues(topic).Inc()
|
||||
if err != errWrongForkVersion {
|
||||
log.WithError(err).Error("Failed to handle p2p RPC")
|
||||
log.WithError(err).Warn("Failed to handle p2p RPC")
|
||||
}
|
||||
traceutil.AnnotateError(span, err)
|
||||
}
|
||||
|
||||
@@ -132,7 +132,6 @@ func startKademliaDHT(privKey crypto.PrivKey) {
|
||||
}
|
||||
|
||||
fmt.Printf("Running Kademlia DHT bootnode: /ip4/%s/tcp/%d/p2p/%s\n", *externalIP, *kademliaPort, host.ID().Pretty())
|
||||
|
||||
}
|
||||
|
||||
func createListener(ipAddr string, port int, cfg discover.Config) *discover.UDPv5 {
|
||||
|
||||
Reference in New Issue
Block a user