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
27e96b0e
Unverified
Commit
27e96b0e
authored
Nov 20, 2020
by
Ralph Pichler
Committed by
GitHub
Nov 20, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
don't hold global chequebook lock while sending cheque (#986)
parent
649e64e5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
18 deletions
+39
-18
chequebook.go
pkg/settlement/swap/chequebook/chequebook.go
+39
-18
No files found.
pkg/settlement/swap/chequebook/chequebook.go
View file @
27e96b0e
...
...
@@ -71,8 +71,9 @@ type service struct {
erc20ABI
abi
.
ABI
erc20Instance
ERC20Binding
store
storage
.
StateStorer
chequeSigner
ChequeSigner
store
storage
.
StateStorer
chequeSigner
ChequeSigner
totalIssuedReserved
*
big
.
Int
}
// New creates a new chequebook service for the provided chequebook contract.
...
...
@@ -98,17 +99,18 @@ func New(backend transaction.Backend, transactionService transaction.Service, ad
}
return
&
service
{
backend
:
backend
,
transactionService
:
transactionService
,
address
:
address
,
chequebookABI
:
chequebookABI
,
chequebookInstance
:
chequebookInstance
,
ownerAddress
:
ownerAddress
,
erc20Address
:
erc20Address
,
erc20ABI
:
erc20ABI
,
erc20Instance
:
erc20Instance
,
store
:
store
,
chequeSigner
:
chequeSigner
,
backend
:
backend
,
transactionService
:
transactionService
,
address
:
address
,
chequebookABI
:
chequebookABI
,
chequebookInstance
:
chequebookInstance
,
ownerAddress
:
ownerAddress
,
erc20Address
:
erc20Address
,
erc20ABI
:
erc20ABI
,
erc20Instance
:
erc20Instance
,
store
:
store
,
chequeSigner
:
chequeSigner
,
totalIssuedReserved
:
big
.
NewInt
(
0
),
},
nil
}
...
...
@@ -202,10 +204,7 @@ func lastIssuedChequeKey(beneficiary common.Address) string {
return
fmt
.
Sprintf
(
"chequebook_last_issued_cheque_%x"
,
beneficiary
)
}
// Issue issues a new cheque and passes it to sendChequeFunc
// if sendChequeFunc succeeds the cheque is considered sent and saved
func
(
s
*
service
)
Issue
(
ctx
context
.
Context
,
beneficiary
common
.
Address
,
amount
*
big
.
Int
,
sendChequeFunc
SendChequeFunc
)
error
{
// don't allow concurrent issuing of cheques
func
(
s
*
service
)
reserveTotalIssued
(
ctx
context
.
Context
,
amount
*
big
.
Int
)
error
{
s
.
lock
.
Lock
()
defer
s
.
lock
.
Unlock
()
...
...
@@ -214,10 +213,29 @@ func (s *service) Issue(ctx context.Context, beneficiary common.Address, amount
return
err
}
if
amount
.
Cmp
(
availableBalance
)
>
0
{
if
amount
.
Cmp
(
big
.
NewInt
(
0
)
.
Sub
(
availableBalance
,
s
.
totalIssuedReserved
)
)
>
0
{
return
ErrOutOfFunds
}
s
.
totalIssuedReserved
=
s
.
totalIssuedReserved
.
Add
(
s
.
totalIssuedReserved
,
amount
)
return
nil
}
func
(
s
*
service
)
unreserveTotalIssued
(
amount
*
big
.
Int
)
{
s
.
lock
.
Lock
()
defer
s
.
lock
.
Unlock
()
s
.
totalIssuedReserved
=
s
.
totalIssuedReserved
.
Sub
(
s
.
totalIssuedReserved
,
amount
)
}
// Issue issues a new cheque and passes it to sendChequeFunc
// if sendChequeFunc succeeds the cheque is considered sent and saved
func
(
s
*
service
)
Issue
(
ctx
context
.
Context
,
beneficiary
common
.
Address
,
amount
*
big
.
Int
,
sendChequeFunc
SendChequeFunc
)
error
{
err
:=
s
.
reserveTotalIssued
(
ctx
,
amount
)
if
err
!=
nil
{
return
err
}
defer
s
.
unreserveTotalIssued
(
amount
)
var
cumulativePayout
*
big
.
Int
lastCheque
,
err
:=
s
.
LastCheque
(
beneficiary
)
if
err
!=
nil
{
...
...
@@ -262,6 +280,9 @@ func (s *service) Issue(ctx context.Context, beneficiary common.Address, amount
return
err
}
s
.
lock
.
Lock
()
defer
s
.
lock
.
Unlock
()
totalIssued
,
err
:=
s
.
totalIssued
()
if
err
!=
nil
{
return
err
...
...
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