From 48047c3cb55c93a16cd47dff5f42a21eb50a0913 Mon Sep 17 00:00:00 2001 From: anandrgitnirman Date: Tue, 13 Aug 2019 18:53:48 +0530 Subject: [PATCH 1/3] https://github.com/singnet/snet-daemon/issues/372 The current code read rate_limit_per_minute as an integer always , this fix is to read a decimal value You could now rate limit 1 request for every 2 minutes by configuring your rate_limit_minute as 0.5 ( assuming the average time for processing 1 request is 2 minutes) --- ratelimit/rateLimit.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/ratelimit/rateLimit.go b/ratelimit/rateLimit.go index f8aa531d..b52b1902 100644 --- a/ratelimit/rateLimit.go +++ b/ratelimit/rateLimit.go @@ -4,6 +4,7 @@ import ( "github.com/singnet/snet-daemon/config" "golang.org/x/time/rate" "math" + "strconv" "time" ) @@ -19,7 +20,13 @@ func NewRateLimiter() rate.Limiter { } func getLimit() rate.Limit { - ratePerMin := config.GetInt(config.RateLimitPerMinute) + + + ratePerMin, err := strconv.ParseFloat(config.GetString(config.RateLimitPerMinute), 32) + if err != nil { + return rate.Inf + } + //If the rate limit parameter Value is not defined we will assume it to be Infinity ( no Rate Limiting) , if ratePerMin == 0 { return rate.Inf From 3e5836788b7d483c1fcc6a1751986c3260f4d66e Mon Sep 17 00:00:00 2001 From: anandrgitnirman Date: Wed, 14 Aug 2019 12:15:16 +0530 Subject: [PATCH 2/3] https://github.com/singnet/snet-daemon/issues/371 coverall is up --- scripts/test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test b/scripts/test index c1a32e7e..9923183c 100755 --- a/scripts/test +++ b/scripts/test @@ -24,5 +24,5 @@ for d in */ ; do done echo "mode: set">>coverage.out grep -h -v "mode: set" *.part >>coverage.out -# /go/bin/goveralls -coverprofile=coverage.out -service=circleci -repotoken ${COVERALLS_REPO_TOKEN} + /go/bin/goveralls -coverprofile=coverage.out -service=circleci -repotoken ${COVERALLS_REPO_TOKEN} popd From bbfd2457469935310954ae1e86c2d8eff950076d Mon Sep 17 00:00:00 2001 From: anandrgitnirman Date: Wed, 14 Aug 2019 12:20:53 +0530 Subject: [PATCH 3/3] https://github.com/singnet/snet-daemon/issues/374 Sender can also be a valid signer --- escrow/validation.go | 6 +++--- escrow/validation_test.go | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/escrow/validation.go b/escrow/validation.go index 1ca102a5..b0a063e3 100644 --- a/escrow/validation.go +++ b/escrow/validation.go @@ -82,9 +82,9 @@ func (validator *ChannelPaymentValidator) Validate(payment *Payment, channel *Pa } log = log.WithField("signerAddress", blockchain.AddressToHex(signerAddress)) - if *signerAddress != channel.Signer { - log.WithField("signerAddress", blockchain.AddressToHex(signerAddress)).Warn("Channel signer is not equal to payment signer") - return NewPaymentError(Unauthenticated, "payment is not signed by channel signer") + if *signerAddress != channel.Signer && *signerAddress != channel.Sender { + log.WithField("signerAddress", blockchain.AddressToHex(signerAddress)).Warn("Channel signer is not equal to payment signer/sender") + return NewPaymentError(Unauthenticated, "payment is not signed by channel signer/sender") } currentBlock, e := validator.currentBlock() if e != nil { diff --git a/escrow/validation_test.go b/escrow/validation_test.go index 2871f90b..8edb2721 100644 --- a/escrow/validation_test.go +++ b/escrow/validation_test.go @@ -193,7 +193,7 @@ func (suite *ValidationTestSuite) TestValidatePaymentIncorrectSigner() { err := suite.validator.Validate(payment, suite.channel()) - assert.Equal(suite.T(), NewPaymentError(Unauthenticated, "payment is not signed by channel signer"), err) + assert.Equal(suite.T(), NewPaymentError(Unauthenticated, "payment is not signed by channel signer/sender"), err) } func (suite *ValidationTestSuite) TestValidatePaymentChannelCannotGetCurrentBlock() {