Repository: shardeum/shardeum
File: src/setup/sync.ts (TypeScript)

Code before:
          const level = devPublicKeys[devPublicKey]
          if (level >= DevSecurityLevel.Low) {
            const { account, cycle } = createDevAccount(devPublicKey, shardus.getLatestCycles())
            const devAccount: any = account // eslint-disable-line @typescript-eslint/no-explicit-any
            await AccountsStorage.setAccount(devAccount.id, devAccount)
            const accountCopy: ShardusTypes.AccountsCopy = {
              cycleNumber: cycle.counter,
              accountId: devAccount.id,
              data: devAccount,
              hash: devAccount.hash,
              isGlobal: false,
              timestamp: devAccount.timestamp,
            }
            accountCopies.push(accountCopy)
          }
        }
        await shardus.debugCommitAccountCopies(accountCopies)
        if (ShardeumFlags.forwardGenesisAccounts) {
          accountCopies = accountCopies.map((account) => {
            return Utils.safeJsonParse(Utils.safeStringify(account))
          })
          await shardus.forwardAccounts({ accounts: accountCopies, receipts: [] })
        }
      }
      await sleep(ONE_SECOND * 10)
      const when = shardeumGetTime()
      const value = {
        isInternalTx: true,
        internalTXType: InternalTXType.InitNetwork,
        timestamp: when,
        network: networkAccount,
      }
      shardus.setGlobal(networkAccount, value, when, networkAccount)
    } else {
      while (!(await shardus.getLocalOrRemoteAccount(networkAccount))) {
        /* prettier-ignore */ if (logFlags.important_as_error) console.log('waiting..')
        await sleep(1000)
      }
    }
  }
}

/**
 * This creates an account outside of any EVM transaction
 * @param ethAccountID
 * @param balance
 */
async function manuallyCreateAccount(
  ethAccountID: string,
  balance = defaultBalance,
  evmCommon: any,

Review comment (bug):
this "wait for 5 seconds" in the case of an existing network account is essentially being removed. I have no idea what the acyuall purpose of it was, maybe it fixed some timing bug, but unless we know why we don't need it anymore, we probably shouldn't remove it

Code after:
          // eslint-disable-next-line security/detect-object-injection
          const level = devPublicKeys[devPublicKey]
          if (level >= DevSecurityLevel.Low) {
            const { account, cycle } = createDevAccount(devPublicKey, shardus.getLatestCycles())
            const devAccount: any = account // eslint-disable-line @typescript-eslint/no-explicit-any
            await AccountsStorage.setAccount(devAccount.id, devAccount)
            const accountCopy: ShardusTypes.AccountsCopy = {
              cycleNumber: cycle.counter,
              accountId: devAccount.id,
              data: devAccount,
              hash: devAccount.hash,
              isGlobal: false,
              timestamp: devAccount.timestamp,
            }
            accountCopies.push(accountCopy)
          }
        }
        await shardus.debugCommitAccountCopies(accountCopies)
        if (ShardeumFlags.forwardGenesisAccounts) {
          accountCopies = accountCopies.map((account) => {
            return Utils.safeJsonParse(Utils.safeStringify(account))
          })
          await shardus.forwardAccounts({ accounts: accountCopies, receipts: [] })
        }
      }
      await sleep(ONE_SECOND * 10)
      const when = shardeumGetTime()
      const value = {
        isInternalTx: true,
        internalTXType: InternalTXType.InitNetwork,
        timestamp: when,
        network: networkAccount,
      }
      shardus.setGlobal(networkAccount, value, when, networkAccount)
    } else {
      while (!(await shardus.getLocalOrRemoteAccount(networkAccount))) {
        /* prettier-ignore */ if (logFlags.important_as_error) console.log('waiting..')
        await sleep(1000)
      }
    }
  }
}

/**
 * This creates an account outside of any EVM transaction
 * @param ethAccountID
 * @param balance
 */
async function manuallyCreateAccount(
  ethAccountID: string,
  balance = defaultBalance,