Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mybee
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
vicotor
mybee
Commits
234d0429
Unverified
Commit
234d0429
authored
Jul 30, 2021
by
mrekucci
Committed by
GitHub
Jul 30, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: limit concurrent access to some parts of the api resources (#2379)
parent
991641b7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
0 deletions
+24
-0
chequebook.go
pkg/debugapi/chequebook.go
+8
-0
debugapi.go
pkg/debugapi/debugapi.go
+8
-0
postage.go
pkg/debugapi/postage.go
+8
-0
No files found.
pkg/debugapi/chequebook.go
View file @
234d0429
...
...
@@ -235,6 +235,14 @@ func (s *Service) swapCashoutHandler(w http.ResponseWriter, r *http.Request) {
ctx
=
sctx
.
SetGasLimit
(
ctx
,
l
)
}
if
!
s
.
cashOutChequeSem
.
TryAcquire
(
1
)
{
s
.
logger
.
Debug
(
"debug api: simultaneous on-chain operations not supported"
)
s
.
logger
.
Error
(
"debug api: simultaneous on-chain operations not supported"
)
jsonhttp
.
TooManyRequests
(
w
,
"simultaneous on-chain operations not supported"
)
return
}
defer
s
.
cashOutChequeSem
.
Release
(
1
)
txHash
,
err
:=
s
.
swap
.
CashCheque
(
ctx
,
peer
)
if
err
!=
nil
{
s
.
logger
.
Debugf
(
"debug api: cashout peer: cannot cash %s: %v"
,
addr
,
err
)
...
...
pkg/debugapi/debugapi.go
View file @
234d0429
...
...
@@ -31,6 +31,7 @@ import (
"github.com/ethersphere/bee/pkg/tracing"
"github.com/ethersphere/bee/pkg/transaction"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/sync/semaphore"
)
// Service implements http.Handler interface to be used in HTTP server.
...
...
@@ -62,6 +63,11 @@ type Service struct {
// handler is changed in the Configure method
handler
http
.
Handler
handlerMu
sync
.
RWMutex
// The following are semaphores which exists to limit concurrent access
// to some parts of the resources in order to avoid undefined behaviour.
postageCreateSem
*
semaphore
.
Weighted
cashOutChequeSem
*
semaphore
.
Weighted
}
// New creates a new Debug API Service with only basic routers enabled in order
...
...
@@ -79,6 +85,8 @@ func New(publicKey, pssPublicKey ecdsa.PublicKey, ethereumAddress common.Address
s
.
blockTime
=
blockTime
s
.
metricsRegistry
=
newMetricsRegistry
()
s
.
transaction
=
transaction
s
.
postageCreateSem
=
semaphore
.
NewWeighted
(
1
)
s
.
cashOutChequeSem
=
semaphore
.
NewWeighted
(
1
)
s
.
setRouter
(
s
.
newBasicRouter
())
...
...
pkg/debugapi/postage.go
View file @
234d0429
...
...
@@ -68,6 +68,14 @@ func (s *Service) postageCreateHandler(w http.ResponseWriter, r *http.Request) {
immutable
,
_
=
strconv
.
ParseBool
(
val
[
0
])
}
if
!
s
.
postageCreateSem
.
TryAcquire
(
1
)
{
s
.
logger
.
Debug
(
"create batch: simultaneous on-chain operations not supported"
)
s
.
logger
.
Error
(
"create batch: simultaneous on-chain operations not supported"
)
jsonhttp
.
TooManyRequests
(
w
,
"simultaneous on-chain operations not supported"
)
return
}
defer
s
.
postageCreateSem
.
Release
(
1
)
batchID
,
err
:=
s
.
postageContract
.
CreateBatch
(
ctx
,
amount
,
uint8
(
depth
),
immutable
,
label
)
if
err
!=
nil
{
if
errors
.
Is
(
err
,
postagecontract
.
ErrInsufficientFunds
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment