Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
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
link33
plugin
Commits
de85e647
Commit
de85e647
authored
Sep 05, 2019
by
张振华
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update
parent
40bfdafd
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
18 deletions
+26
-18
consensus_state.go
plugin/consensus/dpos/consensus_state.go
+5
-3
dpos.go
plugin/consensus/dpos/dpos.go
+1
-1
util.go
plugin/consensus/dpos/types/util.go
+20
-14
No files found.
plugin/consensus/dpos/consensus_state.go
View file @
de85e647
...
...
@@ -595,8 +595,10 @@ func (cs *ConsensusState) Init() {
now
:=
time
.
Now
()
.
Unix
()
task
:=
DecideTaskByTime
(
now
)
cs
.
InitCycleBoundaryInfo
(
task
)
cs
.
InitCycleVrfInfo
(
task
)
cs
.
InitCycleVrfInfos
(
task
)
if
shuffleType
==
dposShuffleTypeOrderByVrfInfo
{
cs
.
InitCycleVrfInfo
(
task
)
cs
.
InitCycleVrfInfos
(
task
)
}
info
:=
CalcTopNVersion
(
cs
.
client
.
GetCurrentHeight
())
cs
.
InitTopNCandidators
(
info
.
Version
)
...
...
@@ -604,7 +606,7 @@ func (cs *ConsensusState) Init() {
// InitTopNCandidators method
func
(
cs
*
ConsensusState
)
InitTopNCandidators
(
version
int64
)
{
for
version
>
0
{
for
version
>
0
&&
whetherUpdateTopN
{
info
,
err
:=
cs
.
client
.
QueryTopNCandidators
(
version
)
if
err
==
nil
&&
info
!=
nil
&&
info
.
Status
==
dty
.
TopNCandidatorsVoteMajorOK
{
cs
.
UpdateTopNCandidators
(
info
)
...
...
plugin/consensus/dpos/dpos.go
View file @
de85e647
...
...
@@ -307,7 +307,7 @@ OuterLoop:
if
err
!=
nil
{
panic
(
err
)
}
if
block
!=
nil
{
if
block
!=
nil
&&
whetherUpdateTopN
{
//time.Sleep(time.Second * 5)
//cands, err := client.QueryCandidators()
info
:=
CalcTopNVersion
(
block
.
Height
)
...
...
plugin/consensus/dpos/types/util.go
View file @
de85e647
...
...
@@ -23,18 +23,24 @@ const (
var
(
randgen
*
rand
.
Rand
randMux
sync
.
Mutex
//
randMux sync.Mutex
// Fmt ...
Fmt
=
fmt
.
Sprintf
once
sync
.
Once
)
// Init ...
func
Init
()
{
if
randgen
==
nil
{
randMux
.
Lock
()
randgen
=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
randMux
.
Unlock
()
}
once
.
Do
(
func
()
{
if
randgen
==
nil
{
randgen
=
rand
.
New
(
rand
.
NewSource
(
time
.
Now
()
.
UnixNano
()))
}
})
//if randgen == nil {
// randMux.Lock()
// randgen = rand.New(rand.NewSource(time.Now().UnixNano()))
// randMux.Unlock()
//}
}
// WriteFile ...
...
...
@@ -137,30 +143,30 @@ func RandIntn(n int) int {
panic
(
"invalid argument to Intn"
)
}
if
n
<=
1
<<
31
-
1
{
randMux
.
Lock
()
//
randMux.Lock()
i32
:=
randgen
.
Int31n
(
int32
(
n
))
randMux
.
Unlock
()
//
randMux.Unlock()
return
int
(
i32
)
}
randMux
.
Lock
()
//
randMux.Lock()
i64
:=
randgen
.
Int63n
(
int64
(
n
))
randMux
.
Unlock
()
//
randMux.Unlock()
return
int
(
i64
)
}
// RandUint32 ...
func
RandUint32
()
uint32
{
randMux
.
Lock
()
//
randMux.Lock()
u32
:=
randgen
.
Uint32
()
randMux
.
Unlock
()
//
randMux.Unlock()
return
u32
}
// RandInt63n ...
func
RandInt63n
(
n
int64
)
int64
{
randMux
.
Lock
()
//
randMux.Lock()
i64
:=
randgen
.
Int63n
(
n
)
randMux
.
Unlock
()
//
randMux.Unlock()
return
i64
}
...
...
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