Revert "Correctly process confirmations"

This reverts commit 1b9bc4450c.
This commit is contained in:
Andrea Maria Piana 2021-11-18 17:19:41 +00:00
parent 0be1b44642
commit b4c4cf6241
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
5 changed files with 44 additions and 38 deletions

View File

@ -1 +1 @@
0.91.1
0.91.2

View File

@ -28,7 +28,7 @@ const (
// And event, ideally, should contain information about peer that sent envelope to us.
EventEnvelopeReceived EventType = "envelope.received"
// EventBatchAcknowledged is sent when batch of envelopes was acknowledged by a peer.
EventBatchAcknowledged EventType = "batch.acknowledged"
EventBatchAcknowledged EventType = "batch.acknowleged"
// EventEnvelopeAvailable fires when envelop is available for filters
EventEnvelopeAvailable EventType = "envelope.available"
// EventMailServerRequestSent fires when such request is sent.

View File

@ -23,11 +23,11 @@ const (
)
type EnvelopesMonitorConfig struct {
EnvelopeEventsHandler EnvelopeEventsHandler
MaxAttempts int
AwaitOnlyMailServerConfirmations bool
IsMailserver func(types.EnodeID) bool
Logger *zap.Logger
EnvelopeEventsHandler EnvelopeEventsHandler
MaxAttempts int
MailserverConfirmationsEnabled bool
IsMailserver func(types.EnodeID) bool
Logger *zap.Logger
}
// EnvelopeEventsHandler used for two different event types.
@ -52,13 +52,13 @@ func NewEnvelopesMonitor(w types.Waku, config EnvelopesMonitorConfig) *Envelopes
}
return &EnvelopesMonitor{
w: w,
api: api,
handler: config.EnvelopeEventsHandler,
awaitOnlyMailServerConfirmations: config.AwaitOnlyMailServerConfirmations,
maxAttempts: config.MaxAttempts,
isMailserver: config.IsMailserver,
logger: logger.With(zap.Namespace("EnvelopesMonitor")),
w: w,
api: api,
handler: config.EnvelopeEventsHandler,
mailServerConfirmation: config.MailserverConfirmationsEnabled,
maxAttempts: config.MaxAttempts,
isMailserver: config.IsMailserver,
logger: logger.With(zap.Namespace("EnvelopesMonitor")),
// key is envelope hash (event.Hash)
envelopes: map[types.Hash]EnvelopeState{},
@ -73,10 +73,11 @@ func NewEnvelopesMonitor(w types.Waku, config EnvelopesMonitorConfig) *Envelopes
// EnvelopesMonitor is responsible for monitoring waku envelopes state.
type EnvelopesMonitor struct {
w types.Waku
api types.PublicWakuAPI
handler EnvelopeEventsHandler
maxAttempts int
w types.Waku
api types.PublicWakuAPI
handler EnvelopeEventsHandler
mailServerConfirmation bool
maxAttempts int
mu sync.Mutex
envelopes map[types.Hash]EnvelopeState
@ -86,8 +87,6 @@ type EnvelopesMonitor struct {
attempts map[types.Hash]int
identifiers map[types.Hash][][]byte
awaitOnlyMailServerConfirmations bool
wg sync.WaitGroup
quit chan struct{}
isMailserver func(peer types.EnodeID) bool
@ -165,7 +164,7 @@ func (m *EnvelopesMonitor) handleEvent(event types.EnvelopeEvent) {
func (m *EnvelopesMonitor) handleEventEnvelopeSent(event types.EnvelopeEvent) {
// Mailserver confirmations for WakuV2 are disabled
if (m.w == nil || m.w.Version() < 2) && m.awaitOnlyMailServerConfirmations {
if (m.w == nil || m.w.Version() < 2) && m.mailServerConfirmation {
if !m.isMailserver(event.Peer) {
return
}
@ -182,20 +181,25 @@ func (m *EnvelopesMonitor) handleEventEnvelopeSent(event types.EnvelopeEvent) {
return
}
m.logger.Debug("envelope is sent", zap.String("hash", event.Hash.String()), zap.String("peer", event.Peer.String()))
confirmationExpected := event.Batch != (types.Hash{})
if confirmationExpected {
if event.Batch != (types.Hash{}) {
if _, ok := m.batches[event.Batch]; !ok {
m.batches[event.Batch] = map[types.Hash]struct{}{}
}
m.batches[event.Batch][event.Hash] = struct{}{}
m.logger.Debug("waiting for a confirmation", zap.String("batch", event.Batch.String()))
} else {
m.envelopes[event.Hash] = EnvelopeSent
if m.handler != nil {
m.handler.EnvelopeSent(m.identifiers[event.Hash])
}
}
}
func (m *EnvelopesMonitor) handleAcknowledgedBatch(event types.EnvelopeEvent) {
if m.awaitOnlyMailServerConfirmations && !m.isMailserver(event.Peer) {
return
if m.mailServerConfirmation {
if !m.isMailserver(event.Peer) {
return
}
}
m.mu.Lock()
@ -287,8 +291,10 @@ func (m *EnvelopesMonitor) handleEnvelopeFailure(hash types.Hash, err error) {
}
func (m *EnvelopesMonitor) handleEventEnvelopeReceived(event types.EnvelopeEvent) {
if m.awaitOnlyMailServerConfirmations && !m.isMailserver(event.Peer) {
return
if m.mailServerConfirmation {
if !m.isMailserver(event.Peer) {
return
}
}
m.mu.Lock()
defer m.mu.Unlock()

View File

@ -32,16 +32,16 @@ func (s *EnvelopesMonitorSuite) SetupTest() {
s.monitor = NewEnvelopesMonitor(
nil,
EnvelopesMonitorConfig{
EnvelopeEventsHandler: nil,
MaxAttempts: 0,
AwaitOnlyMailServerConfirmations: false,
IsMailserver: func(types.EnodeID) bool { return false },
Logger: zap.NewNop(),
EnvelopeEventsHandler: nil,
MaxAttempts: 0,
MailserverConfirmationsEnabled: false,
IsMailserver: func(types.EnodeID) bool { return false },
Logger: zap.NewNop(),
},
)
}
func (s *EnvelopesMonitorSuite) TestEnvelopePosted() {
func (s *EnvelopesMonitorSuite) TestConfirmed() {
s.monitor.Add(testIDs, testHash, types.NewMessage{})
s.Contains(s.monitor.envelopes, testHash)
s.Equal(EnvelopePosted, s.monitor.envelopes[testHash])
@ -50,7 +50,7 @@ func (s *EnvelopesMonitorSuite) TestEnvelopePosted() {
Hash: testHash,
})
s.Contains(s.monitor.envelopes, testHash)
s.Equal(EnvelopePosted, s.monitor.envelopes[testHash])
s.Equal(EnvelopeSent, s.monitor.envelopes[testHash])
}
func (s *EnvelopesMonitorSuite) TestConfirmedWithAcknowledge() {
@ -96,7 +96,7 @@ func (s *EnvelopesMonitorSuite) TestRemoved() {
func (s *EnvelopesMonitorSuite) TestIgnoreNotFromMailserver() {
// enables filter in the tracker to drop confirmations from non-mailserver peers
s.monitor.awaitOnlyMailServerConfirmations = true
s.monitor.mailServerConfirmation = true
s.monitor.Add(testIDs, testHash, types.NewMessage{})
s.monitor.handleEvent(types.EnvelopeEvent{
Event: types.EventEnvelopeSent,

View File

@ -125,8 +125,8 @@ func (s *Service) InitProtocol(nodeName string, identity *ecdsa.PrivateKey, db *
}
envelopesMonitorConfig := &transport.EnvelopesMonitorConfig{
MaxAttempts: s.config.MaxMessageDeliveryAttempts,
AwaitOnlyMailServerConfirmations: s.config.MailServerConfirmations,
MaxAttempts: s.config.MaxMessageDeliveryAttempts,
MailserverConfirmationsEnabled: s.config.MailServerConfirmations,
IsMailserver: func(peer types.EnodeID) bool {
return s.peerStore.Exist(peer)
},