Skip to content

Commit

Permalink
refactor_: remove unused code from wakuv2 (#5651)
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-ramos authored Aug 7, 2024
1 parent 152f1c4 commit c688542
Show file tree
Hide file tree
Showing 10 changed files with 6 additions and 331 deletions.
3 changes: 0 additions & 3 deletions eth-node/bridge/geth/envelope_event.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package gethbridge
import (
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/waku"
"github.com/status-im/status-go/wakuv2"

wakucommon "github.com/status-im/status-go/waku/common"
wakuv2common "github.com/status-im/status-go/wakuv2/common"
Expand Down Expand Up @@ -47,8 +46,6 @@ func NewWakuV2EnvelopeEventWrapper(envelopeEvent *wakuv2common.EnvelopeEvent) *t
for index := range data {
wrappedData[index] = *NewWakuV2EnvelopeErrorWrapper(&data[index])
}
case *wakuv2.MailServerResponse:
wrappedData = NewWakuV2MailServerResponseWrapper(data)
}
return &types.EnvelopeEvent{
Event: types.EventType(envelopeEvent.Event),
Expand Down
14 changes: 0 additions & 14 deletions eth-node/bridge/geth/mailserver_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package gethbridge
import (
"github.com/status-im/status-go/eth-node/types"
"github.com/status-im/status-go/waku"
"github.com/status-im/status-go/wakuv2"
)

// NewWakuMailServerResponseWrapper returns a types.MailServerResponse object that mimics Geth's MailServerResponse
Expand All @@ -18,16 +17,3 @@ func NewWakuMailServerResponseWrapper(mailServerResponse *waku.MailServerRespons
Error: mailServerResponse.Error,
}
}

// NewWakuV2MailServerResponseWrapper returns a types.MailServerResponse object that mimics Geth's MailServerResponse
func NewWakuV2MailServerResponseWrapper(mailServerResponse *wakuv2.MailServerResponse) *types.MailServerResponse {
if mailServerResponse == nil {
panic("mailServerResponse should not be nil")
}

return &types.MailServerResponse{
LastEnvelopeHash: types.Hash(mailServerResponse.LastEnvelopeHash),
Cursor: mailServerResponse.Cursor,
Error: mailServerResponse.Error,
}
}
4 changes: 2 additions & 2 deletions eth-node/bridge/geth/wakuv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (w *gethWakuV2Wrapper) Subscribe(opts *types.SubscriptionOptions) (string,
}
}

f, err := w.createFilterWrapper("", keyAsym, keySym, opts.PoW, opts.PubsubTopic, opts.Topics)
f, err := w.createFilterWrapper("", keyAsym, keySym, opts.PubsubTopic, opts.Topics)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -162,7 +162,7 @@ func (w *gethWakuV2Wrapper) UnsubscribeMany(ids []string) error {
return w.waku.UnsubscribeMany(ids)
}

func (w *gethWakuV2Wrapper) createFilterWrapper(id string, keyAsym *ecdsa.PrivateKey, keySym []byte, pow float64, pubsubTopic string, topics [][]byte) (types.Filter, error) {
func (w *gethWakuV2Wrapper) createFilterWrapper(id string, keyAsym *ecdsa.PrivateKey, keySym []byte, pubsubTopic string, topics [][]byte) (types.Filter, error) {
return NewWakuV2FilterWrapper(&wakucommon.Filter{
KeyAsym: keyAsym,
KeySym: keySym,
Expand Down
32 changes: 4 additions & 28 deletions wakuv2/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,11 @@

package common

import (
"time"
)

// Waku protocol parameters
const (
SizeMask = byte(3) // mask used to extract the size of payload size field from the flags

TopicLength = 4 // in bytes
AESKeyLength = 32 // in bytes
KeyIDSize = 32 // in bytes
BloomFilterSize = 64 // in bytes
MaxTopicInterest = 10000

EnvelopeHeaderLength = 20

MaxMessageSize = uint32(10 * 1024 * 1024) // maximum accepted size of a message.
DefaultMaxMessageSize = uint32(1 << 20) // DefaultMaximumMessageSize is 1mb.

ExpirationCycle = time.Second
TransmissionCycle = 300 * time.Millisecond

DefaultTTL = 50 // seconds
DefaultSyncAllowance = 10 // seconds

MaxLimitInSyncMailRequest = 1000

EnvelopeTimeNotSynced uint = iota + 1
EnvelopeOtherError
TopicLength = 4 // in bytes
AESKeyLength = 32 // in bytes
KeyIDSize = 32 // in bytes

MaxLimitInMessagesRequest = 1000
DefaultMaxMessageSize = uint32(1 << 20) // DefaultMaximumMessageSize is 1mb.
)
4 changes: 0 additions & 4 deletions wakuv2/common/errors.go

This file was deleted.

17 changes: 0 additions & 17 deletions wakuv2/common/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,23 +43,6 @@ const (

// EventEnvelopeAvailable fires when envelop is available for filters
EventEnvelopeAvailable EventType = "envelope.available"

// EventMailServerRequestSent fires when such request is sent.
EventMailServerRequestSent EventType = "mailserver.request.sent"

// EventMailServerRequestCompleted fires after mailserver sends all the requested messages
EventMailServerRequestCompleted EventType = "mailserver.request.completed"

// EventMailServerRequestExpired fires after mailserver the request TTL ends.
// This event is independent and concurrent to EventMailServerRequestCompleted.
// Request should be considered as expired only if expiry event was received first.
EventMailServerRequestExpired EventType = "mailserver.request.expired"

// EventMailServerEnvelopeArchived fires after an envelope has been archived
EventMailServerEnvelopeArchived EventType = "mailserver.envelope.archived"

// EventMailServerSyncFinished fires when the sync of messages is finished.
EventMailServerSyncFinished EventType = "mailserver.sync.finished"
)

// EnvelopeEvent represents an envelope event.
Expand Down
56 changes: 0 additions & 56 deletions wakuv2/common/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package common

import (
"crypto/ecdsa"
"errors"
"fmt"
"sync"
"sync/atomic"
"time"
Expand Down Expand Up @@ -62,67 +60,13 @@ type ReceivedMessage struct {
Processed atomic.Bool
}

// MessagesRequest contains details of a request for historic messages.
type MessagesRequest struct {
// ID of the request. The current implementation requires ID to be 32-byte array,
// however, it's not enforced for future implementation.
ID []byte `json:"id"`

// From is a lower bound of time range.
From uint32 `json:"from"`

// To is a upper bound of time range.
To uint32 `json:"to"`

// Limit determines the number of messages sent by the mail server
// for the current paginated request.
Limit uint32 `json:"limit"`

// Cursor is used as starting point for paginated requests.
Cursor []byte `json:"cursor"`

// Topics is a list of topics. A returned message should
// belong to one of the topics from the list.
Topics [][]byte `json:"topics"`
}

func (r MessagesRequest) Validate() error {
if len(r.ID) != common.HashLength {
return errors.New("invalid 'ID', expected a 32-byte slice")
}

if r.From > r.To {
return errors.New("invalid 'From' value which is greater than To")
}

if r.Limit > MaxLimitInMessagesRequest {
return fmt.Errorf("invalid 'Limit' value, expected value lower than %d", MaxLimitInMessagesRequest)
}

return nil
}

// EnvelopeError code and optional description of the error.
type EnvelopeError struct {
Hash common.Hash
Code uint
Description string
}

// ErrorToEnvelopeError converts common golang error into EnvelopeError with a code.
func ErrorToEnvelopeError(hash common.Hash, err error) EnvelopeError {
code := EnvelopeOtherError
switch err.(type) {
case TimeSyncError:
code = EnvelopeTimeNotSynced
}
return EnvelopeError{
Hash: hash,
Code: code,
Description: err.Error(),
}
}

// MessagesResponse sent as a response after processing batch of envelopes.
type MessagesResponse struct {
// Hash is a hash of all envelopes sent in the single batch.
Expand Down
25 changes: 0 additions & 25 deletions wakuv2/common/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,6 @@ var (
Help: "Size of processed Waku envelopes in bytes.",
Buckets: prom.ExponentialBuckets(256, 4, 10),
})
RateLimitsProcessed = prom.NewCounter(prom.CounterOpts{
Name: "waku2_rate_limits_processed_total",
Help: "Number of packets Waku rate limiter processed.",
})
RateLimitsExceeded = prom.NewCounterVec(prom.CounterOpts{
Name: "waku2_rate_limits_exceeded_total",
Help: "Number of times the Waku rate limits were exceeded",
}, []string{"type"})
BridgeSent = prom.NewCounter(prom.CounterOpts{
Name: "waku2_bridge_sent_total",
Help: "Number of envelopes bridged from Waku",
})
BridgeReceivedSucceed = prom.NewCounter(prom.CounterOpts{
Name: "waku2_bridge_received_success_total",
Help: "Number of envelopes bridged to Waku and successfully added",
})
BridgeReceivedFailed = prom.NewCounter(prom.CounterOpts{
Name: "waku2_bridge_received_failure_total",
Help: "Number of envelopes bridged to Waku and failed to be added",
})
)

func init() {
Expand All @@ -76,9 +56,4 @@ func init() {
prom.MustRegister(EnvelopesCacheFailedCounter)
prom.MustRegister(EnvelopesCachedCounter)
prom.MustRegister(EnvelopesSizeMeter)
prom.MustRegister(RateLimitsProcessed)
prom.MustRegister(RateLimitsExceeded)
prom.MustRegister(BridgeSent)
prom.MustRegister(BridgeReceivedSucceed)
prom.MustRegister(BridgeReceivedFailed)
}
Loading

0 comments on commit c688542

Please sign in to comment.