Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
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
exchain
nebula
Commits
06e42cbd
Commit
06e42cbd
authored
May 09, 2023
by
Felipe Andrade
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
prevent direct access to backend state struct
parent
6d4f5253
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
14 deletions
+19
-14
consensus_poller.go
proxyd/consensus_poller.go
+19
-14
No files found.
proxyd/consensus_poller.go
View file @
06e42cbd
...
...
@@ -203,23 +203,23 @@ func NewConsensusPoller(bg *BackendGroup, opts ...ConsensusOpt) *ConsensusPoller
// UpdateBackend refreshes the consensus state of a single backend
func
(
cp
*
ConsensusPoller
)
UpdateBackend
(
ctx
context
.
Context
,
be
*
Backend
)
{
bs
:=
cp
.
backendState
[
be
]
if
time
.
Now
()
.
Before
(
b
s
.
b
annedUntil
)
{
log
.
Debug
(
"skipping backend banned"
,
"backend"
,
be
.
Name
,
"bannedUntil"
,
b
s
.
b
annedUntil
)
_
,
_
,
_
,
_
,
bannedUntil
:=
cp
.
getBackendState
(
be
)
if
time
.
Now
()
.
Before
(
bannedUntil
)
{
log
.
Debug
(
"skipping backend banned"
,
"backend"
,
be
.
Name
,
"bannedUntil"
,
bannedUntil
)
return
}
// if backend it not online or not in a health state we'll only resume checkin it after ban
if
!
be
.
Online
()
||
!
be
.
IsHealthy
()
{
log
.
Warn
(
"backend banned - not online or not healthy"
,
"backend"
,
be
.
Name
,
"bannedUntil"
,
b
s
.
b
annedUntil
)
b
s
.
b
annedUntil
=
time
.
Now
()
.
Add
(
cp
.
banPeriod
)
log
.
Warn
(
"backend banned - not online or not healthy"
,
"backend"
,
be
.
Name
,
"bannedUntil"
,
bannedUntil
)
bannedUntil
=
time
.
Now
()
.
Add
(
cp
.
banPeriod
)
}
// if backend it not in sync we'll check again after ban
inSync
,
err
:=
cp
.
isInSync
(
ctx
,
be
)
if
err
!=
nil
||
!
inSync
{
log
.
Warn
(
"backend banned - not in sync"
,
"backend"
,
be
.
Name
,
"bannedUntil"
,
b
s
.
b
annedUntil
)
b
s
.
b
annedUntil
=
time
.
Now
()
.
Add
(
cp
.
banPeriod
)
log
.
Warn
(
"backend banned - not in sync"
,
"backend"
,
be
.
Name
,
"bannedUntil"
,
bannedUntil
)
bannedUntil
=
time
.
Now
()
.
Add
(
cp
.
banPeriod
)
}
// if backend exhausted rate limit we'll skip it for now
...
...
@@ -246,7 +246,11 @@ func (cp *ConsensusPoller) UpdateBackend(ctx context.Context, be *Backend) {
if
changed
{
RecordBackendLatestBlock
(
be
,
latestBlockNumber
)
log
.
Debug
(
"backend state updated"
,
"name"
,
be
.
Name
,
"state"
,
bs
)
log
.
Debug
(
"backend state updated"
,
"name"
,
be
.
Name
,
"peerCount"
,
peerCount
,
"latestBlockNumber"
,
latestBlockNumber
,
"latestBlockHash"
,
latestBlockHash
)
}
}
...
...
@@ -258,7 +262,7 @@ func (cp *ConsensusPoller) UpdateBackendGroupConsensus(ctx context.Context) {
currentConsensusBlockNumber
:=
cp
.
GetConsensusBlockNumber
()
for
_
,
be
:=
range
cp
.
backendGroup
.
Backends
{
peerCount
,
backendLatestBlockNumber
,
backendLatestBlockHash
,
lastUpdate
:=
cp
.
getBackendState
(
be
)
peerCount
,
backendLatestBlockNumber
,
backendLatestBlockHash
,
lastUpdate
,
_
:=
cp
.
getBackendState
(
be
)
if
!
be
.
skipPeerCountCheck
&&
peerCount
<
cp
.
minPeerCount
{
continue
...
...
@@ -306,10 +310,10 @@ func (cp *ConsensusPoller) UpdateBackendGroupConsensus(ctx context.Context) {
- with minimum peer count
- updated recently
*/
bs
:=
cp
.
backendState
[
be
]
notUpdated
:=
bs
.
lastUpdate
.
Add
(
cp
.
maxUpdateThreshold
)
.
Before
(
time
.
Now
())
isBanned
:=
time
.
Now
()
.
Before
(
b
s
.
b
annedUntil
)
notEnoughPeers
:=
!
be
.
skipPeerCountCheck
&&
bs
.
peerCount
<
cp
.
minPeerCount
peerCount
,
_
,
_
,
lastUpdate
,
bannedUntil
:=
cp
.
getBackendState
(
be
)
notUpdated
:=
lastUpdate
.
Add
(
cp
.
maxUpdateThreshold
)
.
Before
(
time
.
Now
())
isBanned
:=
time
.
Now
()
.
Before
(
bannedUntil
)
notEnoughPeers
:=
!
be
.
skipPeerCountCheck
&&
peerCount
<
cp
.
minPeerCount
if
!
be
.
IsHealthy
()
||
be
.
IsRateLimited
()
||
!
be
.
Online
()
||
notUpdated
||
isBanned
||
notEnoughPeers
{
filteredBackendsNames
=
append
(
filteredBackendsNames
,
be
.
Name
)
continue
...
...
@@ -432,13 +436,14 @@ func (cp *ConsensusPoller) isInSync(ctx context.Context, be *Backend) (result bo
return
res
,
nil
}
func
(
cp
*
ConsensusPoller
)
getBackendState
(
be
*
Backend
)
(
peerCount
uint64
,
blockNumber
hexutil
.
Uint64
,
blockHash
string
,
lastUpdate
time
.
Time
)
{
func
(
cp
*
ConsensusPoller
)
getBackendState
(
be
*
Backend
)
(
peerCount
uint64
,
blockNumber
hexutil
.
Uint64
,
blockHash
string
,
lastUpdate
time
.
Time
,
bannedUntil
time
.
Time
)
{
bs
:=
cp
.
backendState
[
be
]
bs
.
backendStateMux
.
Lock
()
peerCount
=
bs
.
peerCount
blockNumber
=
bs
.
latestBlockNumber
blockHash
=
bs
.
latestBlockHash
lastUpdate
=
bs
.
lastUpdate
bannedUntil
=
bs
.
bannedUntil
bs
.
backendStateMux
.
Unlock
()
return
}
...
...
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