MCPcopy Create free account
hub / github.com/DNAProject/DNA / calcParticipant

Function calcParticipant

consensus/vbft/node_utils.go:293–314  ·  view source on GitHub ↗
(vrf vconfig.VRFValue, dposTable []uint32, k uint32)

Source from the content-addressed store, hash-verified

291}
292
293func 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

Callers 1

calcParticipantPeersFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected