Skip to content

Commit

Permalink
post-merge fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
algorandskiy committed Jun 7, 2024
1 parent 363982b commit 8f9ad90
Show file tree
Hide file tree
Showing 6 changed files with 179 additions and 44 deletions.
45 changes: 32 additions & 13 deletions data/txHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -609,19 +609,6 @@ func (handler *TxHandler) incomingMsgDupErlCheck(data []byte, sender network.Dis
}

var err error
var capguard *util.ErlCapacityGuard
accepted := false
defer func() {
// if we failed to put the item onto the backlog, we should release the capacity if any
if !accepted {
if capguard != nil {
if capErr := capguard.Release(); capErr != nil {
logging.Base().Warnf("Failed to release capacity to ElasticRateLimiter: %v", capErr)
}
}
}
}()

if handler.erl != nil {
congestedERL := float64(cap(handler.backlogQueue))*handler.backlogCongestionThreshold < float64(len(handler.backlogQueue))
// consume a capacity unit
Expand Down Expand Up @@ -720,6 +707,19 @@ func (handler *TxHandler) incomingTxGroupDupRateLimit(unverifiedTxGroup []transa
// - transactions are checked for duplicates
func (handler *TxHandler) processIncomingTxn(rawmsg network.IncomingMessage) network.OutgoingMessage {
msgKey, capguard, shouldDrop := handler.incomingMsgDupErlCheck(rawmsg.Data, rawmsg.Sender)

accepted := false
defer func() {
// if we failed to put the item onto the backlog, we should release the capacity if any
if !accepted {
if capguard != nil {
if capErr := capguard.Release(); capErr != nil {
logging.Base().Warnf("processIncomingTxn: failed to release capacity to ElasticRateLimiter: %v", capErr)

Check warning on line 717 in data/txHandler.go

View check run for this annotation

Codecov / codecov/patch

data/txHandler.go#L717

Added line #L717 was not covered by tests
}
}
}
}()

if shouldDrop {
// this TX message was found in the duplicate cache, or ERL rate-limited it
return network.OutgoingMessage{Action: network.Ignore}
Expand Down Expand Up @@ -775,6 +775,19 @@ type validatedIncomingTxMessage struct {
// validateIncomingTxMessage is the validator for the MessageProcessor implementation used by P2PNetwork.
func (handler *TxHandler) validateIncomingTxMessage(rawmsg network.IncomingMessage) network.ValidatedMessage {
msgKey, capguard, shouldDrop := handler.incomingMsgDupErlCheck(rawmsg.Data, rawmsg.Sender)

Check warning on line 777 in data/txHandler.go

View check run for this annotation

Codecov / codecov/patch

data/txHandler.go#L776-L777

Added lines #L776 - L777 were not covered by tests

accepted := false
defer func() {

Check warning on line 780 in data/txHandler.go

View check run for this annotation

Codecov / codecov/patch

data/txHandler.go#L779-L780

Added lines #L779 - L780 were not covered by tests
// if we failed to put the item onto the backlog, we should release the capacity if any
if !accepted {
if capguard != nil {
if capErr := capguard.Release(); capErr != nil {
logging.Base().Warnf("validateIncomingTxMessage: failed to release capacity to ElasticRateLimiter: %v", capErr)

Check warning on line 785 in data/txHandler.go

View check run for this annotation

Codecov / codecov/patch

data/txHandler.go#L782-L785

Added lines #L782 - L785 were not covered by tests
}
}
}
}()

if shouldDrop {

Check warning on line 791 in data/txHandler.go

View check run for this annotation

Codecov / codecov/patch

data/txHandler.go#L791

Added line #L791 was not covered by tests
// this TX message was found in the duplicate cache, or ERL rate-limited it
return network.ValidatedMessage{Action: network.Ignore, ValidatorData: nil}

Check warning on line 793 in data/txHandler.go

View check run for this annotation

Codecov / codecov/patch

data/txHandler.go#L793

Added line #L793 was not covered by tests
Expand All @@ -793,6 +806,7 @@ func (handler *TxHandler) validateIncomingTxMessage(rawmsg network.IncomingMessa
return network.ValidatedMessage{Action: network.Ignore, ValidatorData: nil}

Check warning on line 806 in data/txHandler.go

View check run for this annotation

Codecov / codecov/patch

data/txHandler.go#L806

Added line #L806 was not covered by tests
}

accepted = true
return network.ValidatedMessage{
Action: network.Accept,
Tag: rawmsg.Tag,
Expand Down Expand Up @@ -829,6 +843,11 @@ func (handler *TxHandler) processIncomingTxMessage(validatedMessage network.Vali
if handler.msgCache != nil && msg.msgKey != nil {
handler.msgCache.DeleteByKey(msg.msgKey)

Check warning on line 844 in data/txHandler.go

View check run for this annotation

Codecov / codecov/patch

data/txHandler.go#L843-L844

Added lines #L843 - L844 were not covered by tests
}
if msg.capguard != nil {
if capErr := msg.capguard.Release(); capErr != nil {
logging.Base().Warnf("processIncomingTxMessage: failed to release capacity to ElasticRateLimiter: %v", capErr)

Check warning on line 848 in data/txHandler.go

View check run for this annotation

Codecov / codecov/patch

data/txHandler.go#L846-L848

Added lines #L846 - L848 were not covered by tests
}
}
}
return network.OutgoingMessage{Action: network.Ignore}

Check warning on line 852 in data/txHandler.go

View check run for this annotation

Codecov / codecov/patch

data/txHandler.go#L852

Added line #L852 was not covered by tests
}
Expand Down
16 changes: 5 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ require (
github.com/libp2p/go-yamux/v4 v4.0.1
github.com/mattn/go-sqlite3 v1.14.16
github.com/miekg/dns v1.1.58
github.com/muesli/termenv v0.15.2
github.com/multiformats/go-multiaddr v0.12.3
github.com/multiformats/go-multiaddr-dns v0.3.1
github.com/olivere/elastic v6.2.14+incompatible
github.com/prometheus/client_golang v1.14.0
github.com/prometheus/client_model v0.4.0
github.com/prometheus/client_golang v1.18.0
github.com/prometheus/client_model v0.6.0
github.com/sirupsen/logrus v1.8.1
github.com/spf13/cobra v1.5.0
github.com/stretchr/testify v1.8.4
Expand Down Expand Up @@ -79,7 +78,7 @@ require (
github.com/flynn/noise v1.1.0 // indirect
github.com/fortytw2/leaktest v1.3.0 // indirect
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/go-logr/logr v1.2.4 // indirect
github.com/go-logr/logr v1.3.0 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/swag v0.19.5 // indirect
Expand All @@ -88,7 +87,6 @@ require (
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt v3.2.2+incompatible // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
github.com/golang/protobuf v1.5.3 // indirect
github.com/google/gopacket v1.1.19 // indirect
github.com/google/pprof v0.0.0-20240207164012-fb44976bdcd5 // indirect
github.com/google/uuid v1.4.0 // indirect
Expand Down Expand Up @@ -117,6 +115,7 @@ require (
github.com/kr/text v0.2.0 // indirect
github.com/labstack/gommon v0.4.0 // indirect
github.com/libp2p/go-buffer-pool v0.1.0 // indirect
github.com/libp2p/go-cidranger v1.1.0 // indirect
github.com/libp2p/go-flow-metrics v0.1.0 // indirect
github.com/libp2p/go-libp2p-asn-util v0.4.1 // indirect
github.com/libp2p/go-libp2p-kbucket v0.6.3 // indirect
Expand All @@ -125,13 +124,10 @@ require (
github.com/libp2p/go-nat v0.2.0 // indirect
github.com/libp2p/go-netroute v0.2.1 // indirect
github.com/libp2p/go-reuseport v0.4.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/marten-seemann/tcp v0.0.0-20210406111302-dfbc87cc63fd // indirect
github.com/mattn/go-colorable v0.1.12 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.14 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mikioh/tcpinfo v0.0.0-20190314235526-30a79bb1804b // indirect
github.com/mikioh/tcpopt v0.0.0-20190314235656-172688c1accc // indirect
github.com/minio/sha256-simd v1.0.1 // indirect
Expand All @@ -153,12 +149,10 @@ require (
github.com/petermattis/goid v0.0.0-20180202154549-b0b1615b78e5 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/prometheus/client_golang v1.18.0 // indirect
github.com/prometheus/client_model v0.6.0 // indirect
github.com/polydawn/refmt v0.89.0 // indirect
github.com/prometheus/common v0.47.0 // indirect
github.com/prometheus/procfs v0.12.0 // indirect
github.com/quic-go/qpack v0.4.0 // indirect
github.com/quic-go/qtls-go1-20 v0.2.3 // indirect
github.com/quic-go/quic-go v0.42.0 // indirect
github.com/quic-go/webtransport-go v0.6.0 // indirect
github.com/raulk/go-watchdog v1.3.0 // indirect
Expand Down
Loading

0 comments on commit 8f9ad90

Please sign in to comment.