How to calculate the Delegate List order?

Hello,

I’m trying to get the order for the forgers, but I am doing something wrong. Do you know what am I doing wrong?

    const roundNumber = 100274;
    const delegates = [{"address":"5201600508578320196L","missedBlocks":194,"producedBlocks":112135,"rank":1,"rewards":42172800000000,"vote":12350381811418528,"username":"cc001","__typename":"accounts_public"},{"address":"10773624498522558426L","missedBlocks":511,"producedBlocks":111561,"rank":2,"rewards":41955900000000,"vote":3869369984000408,"username":"gr33ndrag0n","__typename":"accounts_public"},{"address":"15395643725490872504L","missedBlocks":729,"producedBlocks":111127,"rank":3,"rewards":41766900000000,"vote":3796827810570691,"username":"corsaro","__typename":"accounts_public"},{"address":"5990019649726305126L","missedBlocks":5906,"producedBlocks":104877,"rank":4,"rewards":38976600000000,"vote":3796493847893438,"username":"mrv","__typename":"accounts_public"},{"address":"16671600588889208369L","missedBlocks":5650,"producedBlocks":103796,"rank":5,"rewards":38666500000000,"vote":3787981251662662,"username":"punkrock","__typename":"accounts_public"},{"address":"2955231261147268436L","missedBlocks":1402,"producedBlocks":110037,"rank":6,"rewards":41375700000000,"vote":3770905983516592,"username":"vipertkd","__typename":"accounts_public"},{"address":"6573868316532588354L","missedBlocks":1458,"producedBlocks":110264,"rank":7,"rewards":41313100000000,"vote":3750953034203089,"username":"slasheks","__typename":"accounts_public"},{"address":"10020978176543317477L","missedBlocks":3239,"producedBlocks":106543,"rank":8,"rewards":40414700000000,"vote":3723284678570631,"username":"samuray","__typename":"accounts_public"},{"address":"3741683474356548491L","missedBlocks":3597,"producedBlocks":107098,"rank":9,"rewards":40639700000000,"vote":3695470943867870,"username":"nerigal","__typename":"accounts_public"},{"address":"3593961629730743620L","missedBlocks":3279,"producedBlocks":107634,"rank":10,"rewards":40534600000000,"vote":3682616755160106,"username":"goldeneye","__typename":"accounts_public"},{"address":"2970958268267411716L","missedBlocks":2241,"producedBlocks":108052,"rank":11,"rewards":40863400000000,"vote":3654151259471392,"username":"splatters","__typename":"accounts_public"},{"address":"16114306741199854767L","missedBlocks":1669,"producedBlocks":109021,"rank":12,"rewards":41025600000000,"vote":3517352672345879,"username":"hmachado","__typename":"accounts_public"},{"address":"10234607838418491979L","missedBlocks":5781,"producedBlocks":103162,"rank":13,"rewards":38736000000000,"vote":3491566183695510,"username":"bioly","__typename":"accounts_public"},{"address":"14532972329284175202L","missedBlocks":1357,"producedBlocks":110233,"rank":14,"rewards":41281600000000,"vote":3467554394105483,"username":"ntelo","__typename":"accounts_public"},{"address":"8191405714437232748L","missedBlocks":1341,"producedBlocks":92687,"rank":15,"rewards":32926900000000,"vote":3316450622129179,"username":"stellardynamic","__typename":"accounts_public"},{"address":"8608501552091746000L","missedBlocks":8638,"producedBlocks":99987,"rank":16,"rewards":36733500000000,"vote":3308835331053916,"username":"redsn0w","__typename":"accounts_public"},{"address":"8705127156785948074L","missedBlocks":3890,"producedBlocks":105928,"rank":17,"rewards":39969000000000,"vote":3267081444432699,"username":"eclipsun","__typename":"accounts_public"},{"address":"765057514163296046L","missedBlocks":4400,"producedBlocks":105548,"rank":18,"rewards":39304600000000,"vote":3224906286481814,"username":"ondin","__typename":"accounts_public"},{"address":"16348134243610516066L","missedBlocks":2018,"producedBlocks":92888,"rank":19,"rewards":32879800000000,"vote":3188238085801203,"username":"mrgr","__typename":"accounts_public"},{"address":"8495182212986447781L","missedBlocks":6216,"producedBlocks":95062,"rank":20,"rewards":35031800000000,"vote":3173494686501634,"username":"forrest","__typename":"accounts_public"},{"address":"3100361607419508033L","missedBlocks":7352,"producedBlocks":101124,"rank":21,"rewards":38991300000000,"vote":3068421138873056,"username":"liskgate","__typename":"accounts_public"},{"address":"18158154284022017392L","missedBlocks":1964,"producedBlocks":93549,"rank":22,"rewards":33695300000000,"vote":3060574789819464,"username":"phinx_r","__typename":"accounts_public"},{"address":"16413460183673241583L","missedBlocks":1027,"producedBlocks":86394,"rank":23,"rewards":29852900000000,"vote":3045268933534547,"username":"tester_of_lisk","__typename":"accounts_public"},{"address":"5794850803291593420L","missedBlocks":7549,"producedBlocks":96769,"rank":24,"rewards":35309500000000,"vote":3043502124530677,"username":"rooney","__typename":"accounts_public"},{"address":"14181809830721103291L","missedBlocks":3622,"producedBlocks":102554,"rank":25,"rewards":37714600000000,"vote":3026557962612024,"username":"vi1son","__typename":"accounts_public"},{"address":"2074128296889030323L","missedBlocks":9407,"producedBlocks":99834,"rank":26,"rewards":38425500000000,"vote":2967067617962599,"username":"xujian","__typename":"accounts_public"},{"address":"4856867543512507900L","missedBlocks":7141,"producedBlocks":99895,"rank":27,"rewards":38057100000000,"vote":2951272894598580,"username":"grumlin","__typename":"accounts_public"},{"address":"3874045467747064535L","missedBlocks":13454,"producedBlocks":94697,"rank":28,"rewards":36733100000000,"vote":2908239967085453,"username":"devasive","__typename":"accounts_public"},{"address":"11295542283500210613L","missedBlocks":2923,"producedBlocks":84803,"rank":29,"rewards":29778600000000,"vote":2899803679272431,"username":"seven","__typename":"accounts_public"},{"address":"13931317158765451094L","missedBlocks":1572,"producedBlocks":82342,"rank":30,"rewards":27940300000000,"vote":2890922060693944,"username":"kylefromohio","__typename":"accounts_public"},{"address":"15576132070436174913L","missedBlocks":9789,"producedBlocks":68590,"rank":31,"rewards":23902500000000,"vote":2885392968425206,"username":"5an1ty","__typename":"accounts_public"},{"address":"14964068902550146827L","missedBlocks":1290,"producedBlocks":85873,"rank":32,"rewards":29711300000000,"vote":2849024321966690,"username":"lwyrup","__typename":"accounts_public"},{"address":"16470624531434014871L","missedBlocks":304,"producedBlocks":62906,"rank":33,"rewards":19144500000000,"vote":2843332966916052,"username":"hirish","__typename":"accounts_public"},{"address":"10934306629196932988L","missedBlocks":7801,"producedBlocks":94557,"rank":34,"rewards":35815500000000,"vote":2818376770023197,"username":"sgdias","__typename":"accounts_public"},{"address":"6238004142195673234L","missedBlocks":2359,"producedBlocks":64902,"rank":35,"rewards":20481600000000,"vote":2801462136150212,"username":"elevate","__typename":"accounts_public"},{"address":"16695730432237461351L","missedBlocks":1020,"producedBlocks":83873,"rank":36,"rewards":28333700000000,"vote":2779367613252439,"username":"goodtimes","__typename":"accounts_public"},{"address":"11074069055723935210L","missedBlocks":1129,"producedBlocks":80561,"rank":37,"rewards":26987200000000,"vote":2778143506187834,"username":"chamberlain","__typename":"accounts_public"},{"address":"6021511972476847954L","missedBlocks":2173,"producedBlocks":92640,"rank":38,"rewards":33178900000000,"vote":2774124289153629,"username":"tembo","__typename":"accounts_public"},{"address":"12152272179182393358L","missedBlocks":7974,"producedBlocks":95226,"rank":39,"rewards":35946600000000,"vote":2747059236110164,"username":"will","__typename":"accounts_public"},{"address":"11855977167160419866L","missedBlocks":1749,"producedBlocks":83537,"rank":40,"rewards":28636500000000,"vote":2715243201018383,"username":"veriform_testnet","__typename":"accounts_public"},{"address":"731651340951240077L","missedBlocks":7091,"producedBlocks":102100,"rank":41,"rewards":37462100000000,"vote":2697810675863085,"username":"hua","__typename":"accounts_public"},{"address":"1527055342645791567L","missedBlocks":4843,"producedBlocks":90728,"rank":42,"rewards":32653900000000,"vote":2688629278488578,"username":"hitobb_testnet","__typename":"accounts_public"},{"address":"6121750279903659323L","missedBlocks":1139,"producedBlocks":50462,"rank":43,"rewards":14445100000000,"vote":2685027398547870,"username":"minions","__typename":"accounts_public"},{"address":"16492307295714669100L","missedBlocks":5370,"producedBlocks":57910,"rank":44,"rewards":18580300000000,"vote":2679861984323941,"username":"carbonara","__typename":"accounts_public"},{"address":"18092199560624026818L","missedBlocks":3776,"producedBlocks":73169,"rank":45,"rewards":23843600000000,"vote":2659225238120285,"username":"blockcoinau","__typename":"accounts_public"},{"address":"15685642188501630198L","missedBlocks":236,"producedBlocks":63265,"rank":46,"rewards":19206300000000,"vote":2654191356389385,"username":"moosty","__typename":"accounts_public"},{"address":"3678934477280810090L","missedBlocks":5260,"producedBlocks":69442,"rank":47,"rewards":22503400000000,"vote":2642304970235660,"username":"gregorst","__typename":"accounts_public"},{"address":"2450278249619677470L","missedBlocks":676,"producedBlocks":56163,"rank":48,"rewards":16506500000000,"vote":2597227263647155,"username":"tonyt908","__typename":"accounts_public"},{"address":"15118820220573795070L","missedBlocks":473,"producedBlocks":68831,"rank":49,"rewards":21451000000000,"vote":2579111769319731,"username":"liskpoland.pl","__typename":"accounts_public"},{"address":"10431374778810601967L","missedBlocks":197,"producedBlocks":49989,"rank":50,"rewards":13877900000000,"vote":2566158884247661,"username":"przemer","__typename":"accounts_public"},{"address":"7134531444980378449L","missedBlocks":441,"producedBlocks":43486,"rank":51,"rewards":11571400000000,"vote":2557045832412500,"username":"korben3","__typename":"accounts_public"},{"address":"9096358076943957197L","missedBlocks":1282,"producedBlocks":57439,"rank":52,"rewards":17221100000000,"vote":2536577764390569,"username":"endro","__typename":"accounts_public"},{"address":"4560518704624832050L","missedBlocks":353,"producedBlocks":49498,"rank":53,"rewards":13776600000000,"vote":2534902869479110,"username":"lemii","__typename":"accounts_public"},{"address":"12056889420610179211L","missedBlocks":1567,"producedBlocks":47671,"rank":54,"rewards":13385800000000,"vote":2527750757519824,"username":"z0wn3ds","__typename":"accounts_public"},{"address":"8004805717140184627L","missedBlocks":4284,"producedBlocks":44160,"rank":55,"rewards":12592500000000,"vote":2465417382104328,"username":"tschakki","__typename":"accounts_public"},{"address":"12263243490950058338L","missedBlocks":9768,"producedBlocks":94732,"rank":56,"rewards":36509600000000,"vote":2399009077819617,"username":"crodam","__typename":"accounts_public"},{"address":"13766568885959378706L","missedBlocks":4487,"producedBlocks":51987,"rank":57,"rewards":16092400000000,"vote":2381685783790492,"username":"soul","__typename":"accounts_public"},{"address":"6281405850162033335L","missedBlocks":10969,"producedBlocks":97262,"rank":58,"rewards":37753300000000,"vote":2349684048156223,"username":"bigfisher","__typename":"accounts_public"},{"address":"1093219811159306396L","missedBlocks":2006,"producedBlocks":95598,"rank":59,"rewards":34287100000000,"vote":2334714252369863,"username":"iii.element.iii","__typename":"accounts_public"},{"address":"3865707283477759335L","missedBlocks":5297,"producedBlocks":49301,"rank":60,"rewards":14744300000000,"vote":2312813227640890,"username":"liskroad","__typename":"accounts_public"},{"address":"8374957317623161724L","missedBlocks":7029,"producedBlocks":87616,"rank":61,"rewards":31694400000000,"vote":2307984243699420,"username":"bawga_testnet","__typename":"accounts_public"},{"address":"214676230899515903L","missedBlocks":6915,"producedBlocks":40684,"rank":62,"rewards":11893100000000,"vote":2278520670664854,"username":"dakk","__typename":"accounts_public"},{"address":"8489184487016694957L","missedBlocks":1450,"producedBlocks":43245,"rank":63,"rewards":11647800000000,"vote":2278063551812910,"username":"jgo","__typename":"accounts_public"},{"address":"18061915355115105944L","missedBlocks":4258,"producedBlocks":105909,"rank":64,"rewards":39715600000000,"vote":2236072345275358,"username":"anamix","__typename":"accounts_public"},{"address":"6398288040044994260L","missedBlocks":12,"producedBlocks":17161,"rank":65,"rewards":3605200000000,"vote":2227365106102767,"username":"gym","__typename":"accounts_public"},{"address":"9297250136087976509L","missedBlocks":554,"producedBlocks":49753,"rank":66,"rewards":13934600000000,"vote":2192405185143140,"username":"araidarun","__typename":"accounts_public"},{"address":"6183301800081823678L","missedBlocks":3207,"producedBlocks":34713,"rank":67,"rewards":9244100000000,"vote":2185776250917703,"username":"thamar","__typename":"accounts_public"},{"address":"14621643025887137539L","missedBlocks":11382,"producedBlocks":96083,"rank":68,"rewards":37260800000000,"vote":2180346810277094,"username":"liskit","__typename":"accounts_public"},{"address":"15895297870025612831L","missedBlocks":3161,"producedBlocks":93350,"rank":69,"rewards":33588400000000,"vote":2166562545926308,"username":"shinekami","__typename":"accounts_public"},{"address":"5687997770441715564L","missedBlocks":3613,"producedBlocks":34842,"rank":70,"rewards":9496400000000,"vote":2164470811089863,"username":"irina18","__typename":"accounts_public"},{"address":"14151049098640942329L","missedBlocks":920,"producedBlocks":20669,"rank":71,"rewards":4785800000000,"vote":2133765858846100,"username":"9up.io_test","__typename":"accounts_public"},{"address":"6894903792404946514L","missedBlocks":1820,"producedBlocks":22988,"rank":72,"rewards":5667200000000,"vote":2101385490458819,"username":"liskecosystem","__typename":"accounts_public"},{"address":"11237438676908077440L","missedBlocks":8900,"producedBlocks":99669,"rank":73,"rewards":39351900000000,"vote":2100909665201014,"username":"carolina","__typename":"accounts_public"},{"address":"14628350534858367799L","missedBlocks":5019,"producedBlocks":32628,"rank":74,"rewards":8666400000000,"vote":2082023295191055,"username":"zero","__typename":"accounts_public"},{"address":"5007121370099988073L","missedBlocks":4506,"producedBlocks":69250,"rank":75,"rewards":22845600000000,"vote":2081548126235190,"username":"philhellmuth_test","__typename":"accounts_public"},{"address":"9327065860680548128L","missedBlocks":902,"producedBlocks":17447,"rank":76,"rewards":3859400000000,"vote":1999677811283630,"username":"hagie.testnet","__typename":"accounts_public"},{"address":"13687555072872361768L","missedBlocks":7533,"producedBlocks":70717,"rank":77,"rewards":24751600000000,"vote":1974814836852907,"username":"liskpro.com","__typename":"accounts_public"},{"address":"10888233854666506133L","missedBlocks":5931,"producedBlocks":76506,"rank":78,"rewards":26831600000000,"vote":1967742075385228,"username":"kc","__typename":"accounts_public"},{"address":"5855970701130754763L","missedBlocks":17405,"producedBlocks":86881,"rank":79,"rewards":34664500000000,"vote":1941394735858151,"username":"popcornbag","__typename":"accounts_public"},{"address":"7114380869858548578L","missedBlocks":164,"producedBlocks":32739,"rank":80,"rewards":8327800000000,"vote":1920601730664551,"username":"j0k3r","__typename":"accounts_public"},{"address":"14403188529144016184L","missedBlocks":1852,"producedBlocks":18312,"rank":81,"rewards":4200900000000,"vote":1908772164238105,"username":"davi","__typename":"accounts_public"},{"address":"15432127119086351058L","missedBlocks":3950,"producedBlocks":78202,"rank":82,"rewards":26039100000000,"vote":1882555033818480,"username":"nimbus76","__typename":"accounts_public"},{"address":"12224522608943050054L","missedBlocks":7592,"producedBlocks":73989,"rank":83,"rewards":26384200000000,"vote":1840476850921953,"username":"zy1349_testnet","__typename":"accounts_public"},{"address":"5054036727426391392L","missedBlocks":7304,"producedBlocks":52914,"rank":84,"rewards":16921800000000,"vote":1821261851971258,"username":"sdrpa","__typename":"accounts_public"},{"address":"11027108891413363651L","missedBlocks":15330,"producedBlocks":90037,"rank":85,"rewards":35781000000000,"vote":1814954376001228,"username":"joel","__typename":"accounts_public"},{"address":"17053847324469608106L","missedBlocks":1435,"producedBlocks":16083,"rank":86,"rewards":3489600000000,"vote":1796931342894748,"username":"nclisk","__typename":"accounts_public"},{"address":"6534417673038435336L","missedBlocks":8963,"producedBlocks":46754,"rank":87,"rewards":14495700000000,"vote":1730519104656678,"username":"openlisk","__typename":"accounts_public"},{"address":"14317292547164929074L","missedBlocks":1151,"producedBlocks":11395,"rank":88,"rewards":2278800000000,"vote":1696426865154745,"username":"shuse2","__typename":"accounts_public"},{"address":"10967906614105152531L","missedBlocks":8095,"producedBlocks":71652,"rank":89,"rewards":25021400000000,"vote":1678264645038398,"username":"endurance","__typename":"accounts_public"},{"address":"8820447240686843261L","missedBlocks":9349,"producedBlocks":48677,"rank":90,"rewards":15267000000000,"vote":1643818836424856,"username":"diego_g","__typename":"accounts_public"},{"address":"3118650874731624905L","missedBlocks":7114,"producedBlocks":39985,"rank":91,"rewards":11850700000000,"vote":1608311842789526,"username":"bloqspace_testnet","__typename":"accounts_public"},{"address":"17449802785255227364L","missedBlocks":12674,"producedBlocks":47198,"rank":92,"rewards":15979000000000,"vote":1604445050152965,"username":"southpaw439","__typename":"accounts_public"},{"address":"17512568150426691038L","missedBlocks":96,"producedBlocks":26410,"rank":93,"rewards":6416700000000,"vote":1524301657523687,"username":"g1zm0","__typename":"accounts_public"},{"address":"1404247228456964737L","missedBlocks":9481,"producedBlocks":32195,"rank":94,"rewards":9374600000000,"vote":1523675493741207,"username":"evangelist","__typename":"accounts_public"},{"address":"16143665213385479811L","missedBlocks":132,"producedBlocks":0,"rank":95,"rewards":0,"vote":1457996124820853,"username":"jesusthehun","__typename":"accounts_public"},{"address":"13010771261775721713L","missedBlocks":7428,"producedBlocks":19000,"rank":96,"rewards":5244700000000,"vote":1427165903345776,"username":"blockvibe.io","__typename":"accounts_public"},{"address":"3897910504949673529L","missedBlocks":14513,"producedBlocks":75274,"rank":97,"rewards":30750500000000,"vote":1411678392719386,"username":"liberspirita","__typename":"accounts_public"},{"address":"825354641079683474L","missedBlocks":4468,"producedBlocks":39868,"rank":98,"rewards":10726500000000,"vote":1365465088555120,"username":"lisk_service","__typename":"accounts_public"},{"address":"11505908555400946683L","missedBlocks":9172,"producedBlocks":27613,"rank":99,"rewards":8059900000000,"vote":1332050776075705,"username":"elum","__typename":"accounts_public"},{"address":"6515576688092110678L","missedBlocks":17698,"producedBlocks":80614,"rank":100,"rewards":33981900000000,"vote":1216834433107841,"username":"phoenix1969","__typename":"accounts_public"},{"address":"3459905047881977079L","missedBlocks":9588,"producedBlocks":56211,"rank":101,"rewards":18790800000000,"vote":1128047921439534,"username":"joo5ty","__typename":"accounts_public"}]

    export const shuffleDelegateListForRound = (
      round: number,
      list: ReadonlyArray<string>,
    ): ReadonlyArray<string> => {
      const seedSource = round.toString();
      console.log('input', ...list);
      const delegateList = [...list];
      // tslint:disable-next-line:no-let
      let currentSeed = hash(seedSource, 'utf8');

      // tslint:disable-next-line one-variable-per-declaration no-let increment-decrement
      for (let i = 0, delCount = delegateList.length; i < delCount; i++) {
        // tslint:disable-next-line no-let increment-decrement no-magic-numbers
        for (let x = 0; x < 4 && i < delCount; i++, x++) {
          const newIndex = currentSeed[x] % delCount;
          const b = delegateList[newIndex];
          delegateList[newIndex] = delegateList[i];
          delegateList[i] = b;
        }
        currentSeed = hash(currentSeed);
      }

      console.log('output', ...delegateList);

      return delegateList;
    };

shuffleDelegateListForRound(roundNumber, [...delegates].map((d: any) => d.username));

console.logs:

"input cc001 gr33ndrag0n corsaro mrv punkrock vipertkd slasheks samuray nerigal goldeneye splatters hmachado bioly ntelo stellardynamic redsn0w eclipsun ondin mrgr forrest liskgate phinx_r tester_of_lisk rooney vi1son xujian grumlin devasive seven kylefromohio 5an1ty lwyrup hirish sgdias elevate goodtimes chamberlain tembo will veriform_testnet hua hitobb_testnet minions carbonara blockcoinau moosty gregorst tonyt908 liskpoland.pl przemer korben3 endro lemii z0wn3ds tschakki crodam soul bigfisher iii.element.iii liskroad bawga_testnet dakk jgo anamix gym araidarun thamar liskit shinekami irina18 9up.io_test liskecosystem carolina zero philhellmuth_test hagie.testnet liskpro.com kc popcornbag j0k3r davi nimbus76 zy1349_testnet sdrpa joel nclisk openlisk shuse2 endurance diego_g bloqspace_testnet southpaw439 g1zm0 evangelist jesusthehun blockvibe.io liberspirita lisk_service elum phoenix1969 joo5ty"

"output 5an1ty tester_of_lisk anamix g1zm0 punkrock tonyt908 moosty hagie.testnet goodtimes splatters samuray 9up.io_test chamberlain evangelist blockvibe.io gregorst liskit blockcoinau bloqspace_testnet eclipsun tembo corsaro zero minions vi1son sgdias seven shinekami diego_g crodam korben3 lwyrup liskgate endro elevate z0wn3ds hmachado elum lisk_service araidarun liskpro.com kylefromohio vipertkd davi ondin endurance dakk soul carolina przemer hua mrgr liskecosystem openlisk nerigal hitobb_testnet cc001 mrv nclisk liskroad redsn0w bawga_testnet devasive will gym gr33ndrag0n rooney liskpoland.pl bigfisher jgo thamar carbonara southpaw439 veriform_testnet philhellmuth_test kc ntelo bioly phinx_r slasheks xujian tschakki nimbus76 irina18 joel zy1349_testnet popcornbag stellardynamic j0k3r grumlin liberspirita forrest sdrpa lemii jesusthehun shuse2 goldeneye iii.element.iii hirish phoenix1969 joo5ty"

The API returns:
NEXT FORGERS
gym
hagie.testnet • rooney • przemer • popcornbag • irina18 • hitobb_testnet • blockcoinau • lisk_service • corsaro

Which clearly makes my output wrong.

Please enable code syntax highlight to make it easier to read.
Also can you be more expansive about what you are trying to achieve with some context ?

Hi @JesusTheHun… I think @michielmulders enabled the highlighting syntax for me, thanks :slight_smile:

What I’m trying to achieve, is to get the sorted array of delegates for the new round next round (like https://github.com/LiskHQ/lisk-sdk/blob/25976b0bd3dee7a42058cc92ef2dc36c220cc7e0/elements/lisk-dpos/src/delegates_list.ts#L81). The code used is the same of Lisk Core, but I’m probably doing something wrong, as the API of Lisk Core (source of truth) return a different order for any given round…

If the function is the same and the function is pure, which is the case, then only the input parameters remains a possible change. Are both API input and your test input arguments the same ?

I am not 100% sure that the arguments are completely the same as the ones that are going on Lisk Core, but they should be… the inputs that I’m passing are: round which is the current round (100274) as number and delegates which is a delegates.map(delegate => delegate.username).

the delegates[] is a sorted (by asc ranking) array of delegates for testnet for round 100274.

I looked around in the base source code and noticed this :

So you are not looking for the delegates at round 100274 but at round 100274 - delegateListRoundOffset.

Can you check if this is indeed your mistake ?

PS : Just for the record, when you call the function and pass the map, you don’t have to expand into a new array, map already returns a new array. Even if it didn’t, you still don’t need to since the function argument is declared as ReadonlyArray<> nothing is gonna happen to your array :wink:

// From
shuffleDelegateListForRound(roundNumber, [...delegates].map((d: any) => d.username));
// To
shuffleDelegateListForRound(roundNumber, delegates.map((d: any) => d.username));

I’m a bit not sure about delegateListRoundOffset… Is it 0?

The offset is set to 2 indeed. Thanks for clarifying @Moosty!
@carbonara I added the types to your code snippet, for some reason, it locked you out from editing and I can’t unlock. Sorry for that!

Okay I’ve managed to test it again… aaand… with current round (100274) - 2 the results are wrong, but if I do current round (100274) + 1 the results are suddenly correct.

Maybe it’s because is testnet? I need to investigate, but if anyone knows the answer, feel free to add it here :slight_smile:

When you calculate delegate with the current protocol,
it should be at the end of the round and before beginning of the round, otherwise, you cannot obtain correct vote weight of the delegate, and the input of the function should be ordered by vote weight and delegate public key for breaking the even
Also, for the current testnet/mainnet protocol, offset should be 0.