(vrf vconfig.VRFValue, dposTable []uint32, k uint32)
| 291 | } |
| 292 | |
| 293 | func calcParticipant(vrf vconfig.VRFValue, dposTable []uint32, k uint32) uint32 { |
| 294 | var v1, v2 uint32 |
| 295 | bIdx := k / 8 |
| 296 | bits1 := k % 8 |
| 297 | bits2 := 8 + bits1 // L - 8 + bits1 |
| 298 | if k >= 512 { |
| 299 | return math.MaxUint32 |
| 300 | } |
| 301 | // Note: take 16bits random variable from vrf, if len(dposTable) is not power of 2, |
| 302 | // this algorithm will break the fairness of vrf. to be fixed |
| 303 | v1 = uint32(vrf[bIdx]) >> bits1 |
| 304 | if bIdx+1 < uint32(len(vrf)) { |
| 305 | v2 = uint32(vrf[bIdx+1]) |
| 306 | } else { |
| 307 | v2 = uint32(vrf[0]) |
| 308 | } |
| 309 | |
| 310 | v2 = v2 & ((1 << bits2) - 1) |
| 311 | v := (v2 << (8 - bits1)) + v1 |
| 312 | v = v % uint32(len(dposTable)) |
| 313 | return dposTable[v] |
| 314 | } |
| 315 | |
| 316 | // |
| 317 | // check if commit msgs has reached consensus |
no outgoing calls
no test coverage detected