@@ -41,13 +41,13 @@ func NewAlgorand(id PID) *Algorand {
4141
4242func (alg * Algorand ) start () {
4343 alg .quitCh = make (chan struct {})
44- GetPeerPool (). add ( alg .peer )
44+ alg .peer . start ( )
4545 go alg .run ()
4646}
4747
4848func (alg * Algorand ) stop () {
4949 close (alg .quitCh )
50- GetPeerPool (). remove ( alg .peer )
50+ alg .peer . stop ( )
5151}
5252
5353// round returns the latest round number.
@@ -210,8 +210,8 @@ func (alg *Algorand) blockProposal(resolveFork bool) *Block {
210210 round := alg .round () + 1
211211 vrf , proof , subusers := alg .sortition (alg .sortitionSeed (round ), role (iden , round , PROPOSE ), expectedBlockProposers , alg .tokenOwn ())
212212 // have been selected.
213+ log .Infof ("node %d get %d sub-users in block proposal" , alg .id , subusers )
213214 if subusers > 0 {
214- log .Debugf ("node %d has %d sub-users selected as block proposer" , alg .id , subusers )
215215 var (
216216 newBlk * Block
217217 proposalType int
@@ -260,7 +260,11 @@ func (alg *Algorand) blockProposal(resolveFork bool) *Block {
260260 }
261261 case <- ticker .C :
262262 // get the block with the highest priority
263- bhash := alg .peer .getMaxProposal (round ).Hash
263+ pp := alg .peer .getMaxProposal (round )
264+ if pp == nil {
265+ continue
266+ }
267+ bhash := pp .Hash
264268 blk := alg .peer .getBlock (bhash )
265269 if blk != nil {
266270 return blk
@@ -521,12 +525,16 @@ func subUsers(expectedNum int, weight uint64, vrf []byte) int {
521525 // hash / 2^hashlen ∉ [ ∑0,j B(k;w,p), ∑0,j+1 B(k;w,p))
522526 hashBig := new (big.Float ).SetInt (new (big.Int ).SetBytes (vrf ))
523527 maxHash := new (big.Float ).SetInt (new (big.Int ).Exp (big .NewInt (2 ), big .NewInt (common .HashLength ), big .NewInt (0 )))
524- for {
528+ for uint64 ( j ) <= weight {
525529 lower := new (big.Float ).Mul (big .NewFloat (binomial .CDF (float64 (j ))), maxHash )
526530 upper := new (big.Float ).Mul (big .NewFloat (binomial .CDF (float64 (j + 1 ))), maxHash )
527531 if hashBig .Cmp (lower ) >= 0 && hashBig .Cmp (upper ) < 0 {
528532 break
529533 }
534+ j ++
535+ }
536+ if uint64 (j ) > weight {
537+ j = 0
530538 }
531539 return j
532540}
0 commit comments