github.com/annchain/OG@v0.0.9/consensus/term/archive/campaign.go (about) 1 package archive 2 3 //import ( 4 // "fmt" 5 // "github.com/annchain/OG/common" 6 // "github.com/annchain/OG/common/hexutil" 7 //) 8 9 //func (d *DkgPartner) zSelectCandidates(seq *tx_types.Sequencer) { 10 // d.mu.RLock() 11 // defer d.mu.RUnlock() 12 // defer func() { 13 // //set nil after select 14 // d.term.ClearCampaigns() 15 // }() 16 // log := d.log() 17 // campaigns := d.term.Campaigns() 18 // if len(campaigns) == d.partner.NbParticipants { 19 // log.Debug("campaign number is equal to participant number ,all will be senator") 20 // var txs types.Txis 21 // for _, cp := range campaigns { 22 // if bytes.Equal(cp.PublicKey, d.myAccount.PublicKey.KeyBytes) { 23 // d.isValidPartner = true 24 // d.dkgOn = true 25 // } 26 // txs = append(txs, cp) 27 // } 28 // sort.Sort(txs) 29 // log.WithField("txs ", txs).Debug("lucky cps") 30 // for _, tx := range txs { 31 // cp := tx.(*tx_types.Campaign) 32 // publicKey := ogcrypto.Signer.PublicKeyFromBytes(cp.PublicKey) 33 // d.term.AddCandidate(cp, publicKey) 34 // if d.isValidPartner { 35 // d.addPartner(cp) 36 // } 37 // } 38 // 39 // if d.isValidPartner { 40 // //d.generateDkg() 41 // log.Debug("you are lucky one") 42 // } 43 // return 44 // } 45 // if len(campaigns) < d.partner.NbParticipants { 46 // panic("never come here , programmer error") 47 // } 48 // randomSeed := CalculateRandomSeed(seq.Signature) 49 // log.WithField("rand seed ", hexutil.Encode(randomSeed)).Debug("generated") 50 // var vrfSelections VrfSelections 51 // var j int 52 // for addr, cp := range campaigns { 53 // vrfSelect := VrfSelection{ 54 // addr: addr, 55 // Vrf: cp.Vrf.Vrf, 56 // XORVRF: XOR(cp.Vrf.Vrf, randomSeed), 57 // Id: j, 58 // } 59 // j++ 60 // vrfSelections = append(vrfSelections, vrfSelect) 61 // } 62 // log.Debugf("we have %d capmpaigns, select %d of them ", len(campaigns), d.partner.NbParticipants) 63 // for j, v := range vrfSelections { 64 // log.WithField("v", v).WithField(" j ", j).Trace("before sort") 65 // } 66 // //log.Trace(vrfSelections) 67 // sort.Sort(vrfSelections) 68 // log.WithField("txs ", vrfSelections).Debug("lucky cps") 69 // for j, v := range vrfSelections { 70 // if j == d.partner.NbParticipants { 71 // break 72 // } 73 // cp := d.term.GetCampaign(v.addr) 74 // if cp == nil { 75 // panic("cp is nil") 76 // } 77 // publicKey := ogcrypto.Signer.PublicKeyFromBytes(cp.PublicKey) 78 // d.term.AddCandidate(cp, publicKey) 79 // log.WithField("v", v).WithField(" j ", j).Trace("you are lucky one") 80 // if bytes.Equal(cp.PublicKey, d.myAccount.PublicKey.KeyBytes) { 81 // log.Debug("congratulation i am a partner of dkg") 82 // d.isValidPartner = true 83 // d.partner.Id = uint32(j) 84 // } 85 // //add here with sorted 86 // d.addPartner(cp) 87 // } 88 // if !d.isValidPartner { 89 // log.Debug("unfortunately i am not a partner of dkg") 90 // } else { 91 // d.dkgOn = true 92 // //d.generateDkg() 93 // } 94 // 95 // //log.Debug(vrfSelections) 96 // 97 // //for _, camp := range camps { 98 // // d.partner.PartPubs = append(d.partner.PartPubs, camp.GetDkgPublicKey()) 99 // // d.partner.addressIndex[camp.Sender()] = len(d.partner.PartPubs) - 1 100 // //} 101 //} 102 103 //type VrfSelection struct { 104 // addr common.Address 105 // Vrf hexutil.KeyBytes 106 // XORVRF hexutil.KeyBytes 107 // Id int //for test 108 //} 109 // 110 // 111 // 112 //type VrfSelections []VrfSelection 113 // 114 //func (a VrfSelections) Len() int { return len(a) } 115 //func (a VrfSelections) Swap(i, j int) { a[i], a[j] = a[j], a[i] } 116 //func (a VrfSelections) Less(i, j int) bool { 117 // return hexutil.Encode(a[i].XORVRF) < hexutil.Encode(a[j].XORVRF) 118 //} 119 // 120 //func (v VrfSelection) String() string { 121 // return fmt.Sprintf("id-%d-a-%s-v-%s-xor-%s", v.Id, hexutil.Encode(v.addr.KeyBytes[:4]), hexutil.Encode(v.Vrf[:4]), hexutil.Encode(v.XORVRF[:4])) 122 //} 123 // 124 //// XOR takes two byte slices, XORs them together, returns the resulting slice. 125 //func XOR(a, b []byte) []byte { 126 // c := make([]byte, len(a)) 127 // for i := 0; i < len(a); i++ { 128 // c[i] = a[i] ^ b[i] 129 // } 130 // return c 131 //} 132 //