Apply whisper metrics patch

This commit is contained in:
Dmitry 2018-09-25 09:42:41 +03:00
parent 3dff91373a
commit d441b04413
2 changed files with 27 additions and 0 deletions

16
whisperv6/metrics.go Normal file
View File

@ -0,0 +1,16 @@
package whisperv6
import "github.com/ethereum/go-ethereum/metrics"
var (
envelopeAddedCounter = metrics.NewRegisteredCounter("whisper/envelopeAdded", nil)
envelopeNewAddedCounter = metrics.NewRegisteredCounter("whisper/envelopeNewAdded", nil)
envelopeClearedCounter = metrics.NewRegisteredCounter("whisper/envelopeCleared", nil)
envelopeErrFromFutureCounter = metrics.NewRegisteredCounter("whisper/envelopeErrFromFuture", nil)
envelopeErrVeryOldCounter = metrics.NewRegisteredCounter("whisper/envelopeErrVeryOld", nil)
envelopeErrExpiredCounter = metrics.NewRegisteredCounter("whisper/envelopeErrExpired", nil)
envelopeErrOversizedCounter = metrics.NewRegisteredCounter("whisper/envelopeErrOversized", nil)
envelopeErrLowPowCounter = metrics.NewRegisteredCounter("whisper/envelopeErrLowPow", nil)
envelopeErrNoBloomMatchCounter = metrics.NewRegisteredCounter("whisper/envelopeErrNoBloomMatch", nil)
envelopeSizeMeter = metrics.NewRegisteredMeter("whisper/envelopeSize", nil)
)

View File

@ -925,8 +925,11 @@ func (whisper *Whisper) add(envelope *Envelope, isP2P bool) (bool, error) {
now := uint32(whisper.timeSource().Unix())
sent := envelope.Expiry - envelope.TTL
envelopeAddedCounter.Inc(1)
if sent > now {
if sent-DefaultSyncAllowance > now {
envelopeErrFromFutureCounter.Inc(1)
return false, fmt.Errorf("envelope created in the future [%x]", envelope.Hash())
}
// recalculate PoW, adjusted for the time difference, plus one second for latency
@ -935,13 +938,16 @@ func (whisper *Whisper) add(envelope *Envelope, isP2P bool) (bool, error) {
if envelope.Expiry < now {
if envelope.Expiry+DefaultSyncAllowance*2 < now {
envelopeErrVeryOldCounter.Inc(1)
return false, fmt.Errorf("very old message")
}
log.Debug("expired envelope dropped", "hash", envelope.Hash().Hex())
envelopeErrExpiredCounter.Inc(1)
return false, nil // drop envelope without error
}
if uint32(envelope.size()) > whisper.MaxMessageSize() {
envelopeErrOversizedCounter.Inc(1)
return false, fmt.Errorf("huge messages are not allowed [%x]", envelope.Hash())
}
@ -950,6 +956,7 @@ func (whisper *Whisper) add(envelope *Envelope, isP2P bool) (bool, error) {
// in this case the previous value is retrieved by MinPowTolerance()
// for a short period of peer synchronization.
if envelope.PoW() < whisper.MinPowTolerance() {
envelopeErrLowPowCounter.Inc(1)
return false, fmt.Errorf("envelope with low PoW received: PoW=%f, hash=[%v]", envelope.PoW(), envelope.Hash().Hex())
}
}
@ -959,6 +966,7 @@ func (whisper *Whisper) add(envelope *Envelope, isP2P bool) (bool, error) {
// in this case the previous value is retrieved by BloomFilterTolerance()
// for a short period of peer synchronization.
if !BloomFilterMatch(whisper.BloomFilterTolerance(), envelope.Bloom()) {
envelopeErrNoBloomMatchCounter.Inc(1)
return false, fmt.Errorf("envelope does not match bloom filter, hash=[%v], bloom: \n%x \n%x \n%x",
envelope.Hash().Hex(), whisper.BloomFilter(), envelope.Bloom(), envelope.Topic)
}
@ -983,6 +991,8 @@ func (whisper *Whisper) add(envelope *Envelope, isP2P bool) (bool, error) {
log.Trace("whisper envelope already cached", "hash", envelope.Hash().Hex())
} else {
log.Trace("cached whisper envelope", "hash", envelope.Hash().Hex())
envelopeNewAddedCounter.Inc(1)
envelopeSizeMeter.Mark(int64(envelope.size()))
whisper.statsMu.Lock()
whisper.stats.memoryUsed += envelope.size()
whisper.statsMu.Unlock()
@ -1084,6 +1094,7 @@ func (whisper *Whisper) expire() {
hashSet.Each(func(v interface{}) bool {
sz := whisper.envelopes[v.(common.Hash)].size()
delete(whisper.envelopes, v.(common.Hash))
envelopeClearedCounter.Inc(1)
whisper.envelopeFeed.Send(EnvelopeEvent{
Hash: v.(common.Hash),
Event: EventEnvelopeExpired,