Commit de85e647 authored by 张振华's avatar 张振华

update

parent 40bfdafd
...@@ -595,8 +595,10 @@ func (cs *ConsensusState) Init() { ...@@ -595,8 +595,10 @@ func (cs *ConsensusState) Init() {
now := time.Now().Unix() now := time.Now().Unix()
task := DecideTaskByTime(now) task := DecideTaskByTime(now)
cs.InitCycleBoundaryInfo(task) cs.InitCycleBoundaryInfo(task)
cs.InitCycleVrfInfo(task) if shuffleType == dposShuffleTypeOrderByVrfInfo {
cs.InitCycleVrfInfos(task) cs.InitCycleVrfInfo(task)
cs.InitCycleVrfInfos(task)
}
info := CalcTopNVersion(cs.client.GetCurrentHeight()) info := CalcTopNVersion(cs.client.GetCurrentHeight())
cs.InitTopNCandidators(info.Version) cs.InitTopNCandidators(info.Version)
...@@ -604,7 +606,7 @@ func (cs *ConsensusState) Init() { ...@@ -604,7 +606,7 @@ func (cs *ConsensusState) Init() {
// InitTopNCandidators method // InitTopNCandidators method
func (cs *ConsensusState) InitTopNCandidators(version int64) { func (cs *ConsensusState) InitTopNCandidators(version int64) {
for version > 0 { for version > 0 && whetherUpdateTopN {
info, err := cs.client.QueryTopNCandidators(version) info, err := cs.client.QueryTopNCandidators(version)
if err == nil && info != nil && info.Status == dty.TopNCandidatorsVoteMajorOK { if err == nil && info != nil && info.Status == dty.TopNCandidatorsVoteMajorOK {
cs.UpdateTopNCandidators(info) cs.UpdateTopNCandidators(info)
......
...@@ -307,7 +307,7 @@ OuterLoop: ...@@ -307,7 +307,7 @@ OuterLoop:
if err != nil { if err != nil {
panic(err) panic(err)
} }
if block != nil { if block != nil && whetherUpdateTopN {
//time.Sleep(time.Second * 5) //time.Sleep(time.Second * 5)
//cands, err := client.QueryCandidators() //cands, err := client.QueryCandidators()
info := CalcTopNVersion(block.Height) info := CalcTopNVersion(block.Height)
......
...@@ -23,18 +23,24 @@ const ( ...@@ -23,18 +23,24 @@ const (
var ( var (
randgen *rand.Rand randgen *rand.Rand
randMux sync.Mutex //randMux sync.Mutex
// Fmt ... // Fmt ...
Fmt = fmt.Sprintf Fmt = fmt.Sprintf
once sync.Once
) )
// Init ... // Init ...
func Init() { func Init() {
if randgen == nil { once.Do(func () {
randMux.Lock() if randgen == nil {
randgen = rand.New(rand.NewSource(time.Now().UnixNano())) randgen = rand.New(rand.NewSource(time.Now().UnixNano()))
randMux.Unlock() }
} })
//if randgen == nil {
// randMux.Lock()
// randgen = rand.New(rand.NewSource(time.Now().UnixNano()))
// randMux.Unlock()
//}
} }
// WriteFile ... // WriteFile ...
...@@ -137,30 +143,30 @@ func RandIntn(n int) int { ...@@ -137,30 +143,30 @@ func RandIntn(n int) int {
panic("invalid argument to Intn") panic("invalid argument to Intn")
} }
if n <= 1<<31-1 { if n <= 1<<31-1 {
randMux.Lock() //randMux.Lock()
i32 := randgen.Int31n(int32(n)) i32 := randgen.Int31n(int32(n))
randMux.Unlock() //randMux.Unlock()
return int(i32) return int(i32)
} }
randMux.Lock() //randMux.Lock()
i64 := randgen.Int63n(int64(n)) i64 := randgen.Int63n(int64(n))
randMux.Unlock() //randMux.Unlock()
return int(i64) return int(i64)
} }
// RandUint32 ... // RandUint32 ...
func RandUint32() uint32 { func RandUint32() uint32 {
randMux.Lock() //randMux.Lock()
u32 := randgen.Uint32() u32 := randgen.Uint32()
randMux.Unlock() //randMux.Unlock()
return u32 return u32
} }
// RandInt63n ... // RandInt63n ...
func RandInt63n(n int64) int64 { func RandInt63n(n int64) int64 {
randMux.Lock() //randMux.Lock()
i64 := randgen.Int63n(n) i64 := randgen.Int63n(n)
randMux.Unlock() //randMux.Unlock()
return i64 return i64
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment