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
51532f37
Unverified
Commit
51532f37
authored
Jun 18, 2021
by
metacertain
Committed by
GitHub
Jun 18, 2021
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: non-blocking calls in pseudosettle (#2135)
parent
154f7255
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
32 additions
and
47 deletions
+32
-47
accounting.go
pkg/accounting/accounting.go
+8
-19
accounting_test.go
pkg/accounting/accounting_test.go
+22
-26
pseudosettle.go
pkg/settlement/pseudosettle/pseudosettle.go
+2
-2
No files found.
pkg/accounting/accounting.go
View file @
51532f37
...
...
@@ -91,8 +91,7 @@ type accountingPeer struct {
paymentThreshold
*
big
.
Int
// the threshold at which the peer expects us to pay
refreshTimestamp
int64
// last time we attempted time-based settlement
paymentOngoing
bool
// indicate if we are currently settling with the peer
reconnectAllowTimestamp
int64
lastSettlementFailureTimestamp
int64
// time of last unsuccessful attempt to issue a cheque
lastSettlementFailureTimestamp
int64
// time of last unsuccessful attempt to issue a cheque
connected
bool
}
...
...
@@ -1079,15 +1078,6 @@ func (a *Accounting) Connect(peer swarm.Address) {
if
err
!=
nil
{
a
.
logger
.
Errorf
(
"failed to persist surplus balance: %w"
,
err
)
}
if
accountingPeer
.
reconnectAllowTimestamp
!=
0
{
timeNow
:=
a
.
timeNow
()
.
Unix
()
if
timeNow
<
accountingPeer
.
reconnectAllowTimestamp
{
disconnectFor
:=
accountingPeer
.
reconnectAllowTimestamp
-
timeNow
a
.
metrics
.
AccountingDisconnectsReconnectCount
.
Inc
()
_
=
a
.
p2p
.
Blocklist
(
peer
,
time
.
Duration
(
disconnectFor
)
*
time
.
Second
)
}
}
}
// decreaseOriginatedBalanceTo decreases the originated balance to provided limit or 0 if limit is positive
...
...
@@ -1144,15 +1134,14 @@ func (a *Accounting) Disconnect(peer swarm.Address) {
accountingPeer
.
lock
.
Lock
()
defer
accountingPeer
.
lock
.
Unlock
()
timeNow
:=
a
.
timeNow
()
.
Unix
()
disconnectFor
,
err
:=
a
.
blocklistUntil
(
peer
,
1
)
if
err
!=
nil
{
disconnectFor
=
int64
(
60
)
if
accountingPeer
.
connected
{
disconnectFor
,
err
:=
a
.
blocklistUntil
(
peer
,
1
)
if
err
!=
nil
{
disconnectFor
=
int64
(
60
)
}
accountingPeer
.
connected
=
false
_
=
a
.
p2p
.
Blocklist
(
peer
,
time
.
Duration
(
disconnectFor
)
*
time
.
Second
)
}
timestamp
:=
timeNow
+
disconnectFor
accountingPeer
.
connected
=
false
accountingPeer
.
reconnectAllowTimestamp
=
timestamp
}
func
(
a
*
Accounting
)
SetRefreshFunc
(
f
RefreshFunc
)
{
...
...
pkg/accounting/accounting_test.go
View file @
51532f37
...
...
@@ -1405,31 +1405,13 @@ func TestAccountingReconnectBeforeAllowed(t *testing.T) {
acc
.
Disconnect
(
peer
)
if
blocklistTime
!=
0
{
t
.
Fatal
(
"unexpected blocklist"
)
}
//peer attempts to reconnect immediately
acc
.
Connect
(
peer
)
if
blocklistTime
!=
int64
(
4
*
paymentThresholdInRefreshmentSeconds
)
{
t
.
Fatalf
(
"unexpected blocklisting time, got %v expected %v"
,
blocklistTime
,
4
*
paymentThresholdInRefreshmentSeconds
)
}
// 30 seconds pass, check whether we blocklist for the correct leftover time after a later connect attempt
ts
=
int64
(
1030
)
acc
.
SetTime
(
ts
)
acc
.
Connect
(
peer
)
if
blocklistTime
!=
int64
(
paymentThresholdInRefreshmentSeconds
)
{
t
.
Fatalf
(
"unexpected blocklisting time, got %v expected %v"
,
blocklistTime
,
paymentThresholdInRefreshmentSeconds
)
}
}
func
TestAccountingRe
connectAfterAllowed
(
t
*
testing
.
T
)
{
func
TestAccountingRe
setBalanceAfterReconnect
(
t
*
testing
.
T
)
{
logger
:=
logging
.
New
(
ioutil
.
Discard
,
0
)
store
:=
mock
.
NewStateStore
()
...
...
@@ -1437,6 +1419,8 @@ func TestAccountingReconnectAfterAllowed(t *testing.T) {
var
blocklistTime
int64
paymentThresholdInRefreshmentSeconds
:=
new
(
big
.
Int
)
.
Div
(
testPaymentThreshold
,
big
.
NewInt
(
testRefreshRate
))
.
Uint64
()
f
:=
func
(
s
swarm
.
Address
,
t
time
.
Duration
)
error
{
blocklistTime
=
int64
(
t
.
Seconds
())
return
nil
...
...
@@ -1488,16 +1472,28 @@ func TestAccountingReconnectAfterAllowed(t *testing.T) {
acc
.
Disconnect
(
peer
)
if
blocklistTime
!=
0
{
t
.
Fatal
(
"unexpected blocklist"
)
if
blocklistTime
!=
int64
(
4
*
paymentThresholdInRefreshmentSeconds
)
{
t
.
Fatal
f
(
"unexpected blocklisting time, got %v expected %v"
,
blocklistTime
,
4
*
paymentThresholdInRefreshmentSeconds
)
}
ts
=
int64
(
1040
)
acc
.
SetTime
(
ts
)
acc
.
Connect
(
peer
)
if
blocklistTime
!=
0
{
t
.
Fatalf
(
"unexpected blocklisting time, got %v expected %v"
,
blocklistTime
,
0
)
balance
,
err
:=
acc
.
Balance
(
peer
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
balance
.
Int64
()
!=
0
{
t
.
Fatalf
(
"balance for peer %v not as expected got %d, wanted 0"
,
peer
.
String
(),
balance
)
}
surplusBalance
,
err
:=
acc
.
SurplusBalance
(
peer
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
if
surplusBalance
.
Int64
()
!=
0
{
t
.
Fatalf
(
"surplus balance for peer %v not as expected got %d, wanted 0"
,
peer
.
String
(),
balance
)
}
}
pkg/settlement/pseudosettle/pseudosettle.go
View file @
51532f37
...
...
@@ -102,7 +102,7 @@ func (s *Service) init(ctx context.Context, p p2p.Peer) error {
s
.
peers
[
p
.
Address
.
String
()]
=
peerData
}
s
.
accounting
.
Connect
(
p
.
Address
)
go
s
.
accounting
.
Connect
(
p
.
Address
)
return
nil
}
...
...
@@ -112,7 +112,7 @@ func (s *Service) terminate(p p2p.Peer) error {
delete
(
s
.
peers
,
p
.
Address
.
String
())
s
.
accounting
.
Disconnect
(
p
.
Address
)
go
s
.
accounting
.
Disconnect
(
p
.
Address
)
return
nil
}
...
...
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