From 0ca5be22348fe2799e1c396e88d7da280e24018f Mon Sep 17 00:00:00 2001
From: Hugo Trentesaux <hugo@trentesaux.fr>
Date: Fri, 21 Jul 2023 18:58:08 +0200
Subject: [PATCH] add reproducibility

---
 node/src/chain_spec/gtest_genesis.rs | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/node/src/chain_spec/gtest_genesis.rs b/node/src/chain_spec/gtest_genesis.rs
index d8a4a03a9..f7a341ed0 100644
--- a/node/src/chain_spec/gtest_genesis.rs
+++ b/node/src/chain_spec/gtest_genesis.rs
@@ -116,9 +116,7 @@ pub fn build_genesis(
     // track if fatal error occured, but let processing continue
     let mut fatal = false;
     // monetary mass for double check
-    let mut monetary_mass = 0u64; // u128
-                                  // wallet index to generate random id
-    let mut wallet_index: u32 = 0;
+    let mut monetary_mass = 0u64;
     // counter for online authorities at genesis
     let mut counter_online_authorities = 0;
     // track identity index
@@ -162,12 +160,11 @@ pub fn build_genesis(
         // double check the monetary mass
         monetary_mass += balance;
 
-        wallet_index += 1;
         // json prevents duplicate wallets
         accounts.insert(
             pubkey.clone(),
             GenesisAccountData {
-                random_id: H256(blake2_256(&(wallet_index, &pubkey).encode())),
+                random_id: H256(blake2_256(&(balance, &pubkey).encode())),
                 balance: *balance,
                 is_identity: false,
             },
@@ -265,6 +262,8 @@ pub fn build_genesis(
             );
         }
     }
+    // sort the identities by index for reproducibility (should have been a vec in json)
+    identities.sort_unstable_by(|a, b| (a.index as u32).cmp(&(b.index as u32)));
 
     // Technical Comittee //
     // NOTE : when changing owner key, the technical committee is not changed
-- 
GitLab