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
99fb84db
Commit
99fb84db
authored
Sep 15, 2023
by
Felipe Andrade
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
nits
parent
7b933391
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
14 deletions
+11
-14
consensus_tracker.go
proxyd/consensus_tracker.go
+11
-14
No files found.
proxyd/consensus_tracker.go
View file @
99fb84db
...
@@ -33,10 +33,13 @@ type ConsensusTrackerState struct {
...
@@ -33,10 +33,13 @@ type ConsensusTrackerState struct {
Finalized
hexutil
.
Uint64
`json:"finalized"`
Finalized
hexutil
.
Uint64
`json:"finalized"`
}
}
func
(
s
*
ConsensusTrackerState
)
update
(
o
*
ConsensusTrackerState
)
{
func
(
ct
*
InMemoryConsensusTracker
)
update
(
o
*
ConsensusTrackerState
)
{
s
.
Latest
=
o
.
Latest
ct
.
mutex
.
Lock
()
s
.
Safe
=
o
.
Safe
defer
ct
.
mutex
.
Unlock
()
s
.
Finalized
=
o
.
Finalized
ct
.
state
.
Latest
=
o
.
Latest
ct
.
state
.
Safe
=
o
.
Safe
ct
.
state
.
Finalized
=
o
.
Finalized
}
}
// InMemoryConsensusTracker store and retrieve in memory, async-safe
// InMemoryConsensusTracker store and retrieve in memory, async-safe
...
@@ -169,14 +172,12 @@ func NewRedisConsensusTracker(ctx context.Context,
...
@@ -169,14 +172,12 @@ func NewRedisConsensusTracker(ctx context.Context,
func
(
ct
*
RedisConsensusTracker
)
Init
()
{
func
(
ct
*
RedisConsensusTracker
)
Init
()
{
go
func
()
{
go
func
()
{
for
{
for
{
// follow same context as backend group poller
ctx
:=
ct
.
backendGroup
.
Consensus
.
ctx
timer
:=
time
.
NewTimer
(
ct
.
heartbeatInterval
)
timer
:=
time
.
NewTimer
(
ct
.
heartbeatInterval
)
ct
.
stateHeartbeat
()
ct
.
stateHeartbeat
()
select
{
select
{
case
<-
timer
.
C
:
case
<-
timer
.
C
:
case
<-
ctx
.
Done
()
:
case
<-
ct
.
ct
x
.
Done
()
:
timer
.
Stop
()
timer
.
Stop
()
return
return
}
}
...
@@ -242,9 +243,8 @@ func (ct *RedisConsensusTracker) stateHeartbeat() {
...
@@ -242,9 +243,8 @@ func (ct *RedisConsensusTracker) stateHeartbeat() {
log
.
Error
(
"failed to unmarshal the remote state"
,
"err"
,
err
)
log
.
Error
(
"failed to unmarshal the remote state"
,
"err"
,
err
)
return
return
}
}
ct
.
remote
.
mutex
.
Lock
()
defer
ct
.
remote
.
mutex
.
Unlock
()
ct
.
remote
.
update
(
state
)
ct
.
remote
.
state
.
update
(
state
)
log
.
Debug
(
"updated state from remote"
,
"state"
,
val
,
"leader"
,
leaderName
)
log
.
Debug
(
"updated state from remote"
,
"state"
,
val
,
"leader"
,
leaderName
)
}
}
}
else
{
}
else
{
...
@@ -320,15 +320,12 @@ func (ct *RedisConsensusTracker) postPayload(mutexVal string) {
...
@@ -320,15 +320,12 @@ func (ct *RedisConsensusTracker) postPayload(mutexVal string) {
ct
.
client
.
Set
(
ct
.
ctx
,
ct
.
key
(
fmt
.
Sprintf
(
"state:%s"
,
mutexVal
)),
jsonState
,
ct
.
lockPeriod
)
ct
.
client
.
Set
(
ct
.
ctx
,
ct
.
key
(
fmt
.
Sprintf
(
"state:%s"
,
mutexVal
)),
jsonState
,
ct
.
lockPeriod
)
leader
,
_
:=
os
.
LookupEnv
(
"HOSTNAME"
)
leader
,
_
:=
os
.
LookupEnv
(
"HOSTNAME"
)
if
leader
==
""
{
}
ct
.
client
.
Set
(
ct
.
ctx
,
ct
.
key
(
fmt
.
Sprintf
(
"leader:%s"
,
mutexVal
)),
leader
,
ct
.
lockPeriod
)
ct
.
client
.
Set
(
ct
.
ctx
,
ct
.
key
(
fmt
.
Sprintf
(
"leader:%s"
,
mutexVal
)),
leader
,
ct
.
lockPeriod
)
log
.
Debug
(
"posted state"
,
"state"
,
string
(
jsonState
),
"leader"
,
leader
)
log
.
Debug
(
"posted state"
,
"state"
,
string
(
jsonState
),
"leader"
,
leader
)
ct
.
leaderName
=
leader
ct
.
leaderName
=
leader
ct
.
remote
.
state
.
update
(
ct
.
local
.
state
)
ct
.
remote
.
update
(
ct
.
local
.
state
)
RecordGroupConsensusHALatestBlock
(
ct
.
backendGroup
,
leader
,
ct
.
local
.
state
.
Latest
)
RecordGroupConsensusHALatestBlock
(
ct
.
backendGroup
,
leader
,
ct
.
local
.
state
.
Latest
)
RecordGroupConsensusHASafeBlock
(
ct
.
backendGroup
,
leader
,
ct
.
local
.
state
.
Safe
)
RecordGroupConsensusHASafeBlock
(
ct
.
backendGroup
,
leader
,
ct
.
local
.
state
.
Safe
)
...
...
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