# Hidden hardcoded Duniter variables

**URL:** https://forum.duniter.org/t/hidden-hardcoded-duniter-variables/10169
**Category:** Duniter-v2s
**Created:** [14 December 2022 14:25 UTC](https://forum.duniter.org/t/hidden-hardcoded-duniter-variables/10169 "2022-12-14T14:25:50Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![HugoTrentesaux](https://forum.duniter.org/user_avatar/forum.duniter.org/hugotrentesaux/32/6396_2.png) [@HugoTrentesaux](https://forum.duniter.org/u/HugoTrentesaux)
#### Post date: [14 December 2022 14:25 UTC](https://forum.duniter.org/t/hidden-hardcoded-duniter-variables/10169/1 "2022-12-14T14:25:50Z")

</div>

I’m creating this thread to list hidden hardcoded Duniter variables that should be exposed in a cleaner way (for example in `pallet_config`) so that we have easier control over Duniter parameters tuning.

Most of the constants are common in `pallets_config.rs`:

> **[runtime/common/src/pallets\_config.rs · master · nodes / rust / Duniter v2S ·...](https://git.duniter.org/nodes/rust/duniter-v2s/-/blob/master/runtime/common/src/pallets_config.rs)**
>
> Duniter v2 based on Substrate framework

> [https://git.duniter.org/nodes/rust/duniter-v2s/-/blob/master/runtime/common/src/pallets\_config.rs](https://git.duniter.org/nodes/rust/duniter-v2s/-/blob/master/runtime/common/src/pallets_config.rs)

Some are specific to gdev, gtest, or g1. Example:

> [https://git.duniter.org/nodes/rust/duniter-v2s/-/blob/master/runtime/g1/src/parameters.rs](https://git.duniter.org/nodes/rust/duniter-v2s/-/blob/master/runtime/g1/src/parameters.rs)

---

<div class="post-metadata">

### Author: ![HugoTrentesaux](https://forum.duniter.org/user_avatar/forum.duniter.org/hugotrentesaux/32/6396_2.png) [@HugoTrentesaux](https://forum.duniter.org/u/HugoTrentesaux)
#### Post date: [14 December 2022 14:28 UTC](https://forum.duniter.org/t/hidden-hardcoded-duniter-variables/10169/2 "2022-12-14T14:28:46Z")

</div>

```rust
const TOKEN_DECIMALS: usize = 2;

```

```rust
const EXISTENTIAL_DEPOSIT: u64 = 200;

```

both hardcoded in chainspec, should be somewhere else

---

<div class="post-metadata">

### Author: ![HugoTrentesaux](https://forum.duniter.org/user_avatar/forum.duniter.org/hugotrentesaux/32/6396_2.png) [@HugoTrentesaux](https://forum.duniter.org/u/HugoTrentesaux)
#### Post date: [14 December 2022 15:20 UTC](https://forum.duniter.org/t/hidden-hardcoded-duniter-variables/10169/3 "2022-12-14T15:20:28Z")

</div>

```rust
idty_name.len() >= 3
        && idty_name.len() <= 64

```

The bounds of identity length should be in `pallet_config` and not hardcoded. Without this, the wallets will not be able to get the values programmatically.

---

<div class="post-metadata">

### Author: ![HugoTrentesaux](https://forum.duniter.org/user_avatar/forum.duniter.org/hugotrentesaux/32/6396_2.png) [@HugoTrentesaux](https://forum.duniter.org/u/HugoTrentesaux)
#### Post date: [14 December 2022 15:30 UTC](https://forum.duniter.org/t/hidden-hardcoded-duniter-variables/10169/4 "2022-12-14T15:30:30Z")

</div>

Duniter uses some environment variables. I do not consider it good practice as it is less explicit than a proper configuration file when not properly documented.

```rust
if let Ok(genesis_timestamp) = std::env::var("DUNITER_GENESIS_TIMESTAMP") {
    genesis_timestamp
        .parse()
        .map_err(|_| "DUNITER_GENESIS_TIMESTAMP must be a number".to_owned())?

```

Maybe the genesis timestamp could be directly in the genesis json. @poka do you know the genesis timestamp you used for ĞDev5 ? Or it can be provided by a system call like `now()`.

[edit] actually it was the other option if genesis timestamp was not provided

```rust
use std::time::SystemTime;
SystemTime::now()
    .duration_since(SystemTime::UNIX_EPOCH)
    .expect("SystemTime before UNIX EPOCH!")
    .as_secs()

```

---

<div class="post-metadata">

### Author: ![poka](https://forum.duniter.org/user_avatar/forum.duniter.org/poka/32/6827_2.png) [@poka](https://forum.duniter.org/u/poka)
#### Post date: [14 December 2022 15:33 UTC](https://forum.duniter.org/t/hidden-hardcoded-duniter-variables/10169/5 "2022-12-14T15:33:49Z")

</div>

> [@HugoTrentesaux](#):
>
> @poka do you know the genesis timestamp you used for ĞDev5 ?

No, I don’t know.  
Please don’t remind me nightmares…

> [@On another topic](https://forum.duniter.org/t/9426/79):
>
> Quand j’essai de le faire:
> 
> ```auto
> final blockHash =
> await sdk.webView!.evalJavascript('api.rpc.chain.getBlockHash(1)');
> final Map blockContent = await sdk.webView!
> .evalJavascript('api.rpc.chain.getBlock("$blockHash")');
> final String dateBrut = blockContent['block']['extrinsics'][0];
> 
> final dateTextByte = hex.decode(dateBrut.substring(2));
> 
> // log.d('aaaaaaaaaaaaaaaaaaaaa: $dateTextByte');
> final dateText = await sdk.webView!.evalJavascript(
> 'api.tx($dateTextByte)',
> wrapPromise: false);
> 
> log.d('aaaaaaaaaaaaaaaaaaaaa: $dateText');
> 
> ```
> 
> Je reçois une Map vide:
> 
> `I/flutter ( 3786): │ 🐛 aaaaaaaaaaaaaaaaaaaaa: {}`
> 
> Pourtant je suis sur un noeud archive.

> [@On another topic](https://forum.duniter.org/t/9426/81):
>
> putaaaaiiinnn je veux juste la date du bloc 1 ! c’est pas dans le metadata juste sinon ??

[…]

> [@On another topic](https://forum.duniter.org/t/9426/84):
>
> Bon allez, balek, je passe par l’indexer
> 
> ```auto
> {
> block(limit: 1) {
> created_at
> number
> }
> }
> 
> ```

---

<div class="post-metadata">

### Author: ![HugoTrentesaux](https://forum.duniter.org/user_avatar/forum.duniter.org/hugotrentesaux/32/6396_2.png) [@HugoTrentesaux](https://forum.duniter.org/u/HugoTrentesaux)
#### Post date: [14 December 2022 15:37 UTC](https://forum.duniter.org/t/hidden-hardcoded-duniter-variables/10169/6 "2022-12-14T15:37:02Z")

</div>

It seems that the genesis timestamp isn’t used anywhere else than for computing membership expiration in number of blocks. So you could not have found it. The first timestamp is the one of the first block `set_timestamp` event.

---

<div class="post-metadata">

### Author: ![poka](https://forum.duniter.org/user_avatar/forum.duniter.org/poka/32/6827_2.png) [@poka](https://forum.duniter.org/u/poka)
#### Post date: [14 December 2022 15:38 UTC](https://forum.duniter.org/t/hidden-hardcoded-duniter-variables/10169/7 "2022-12-14T15:38:11Z")

</div>

> [@HugoTrentesaux](#):
>
> The first timestamp is the one of the first block `set_timestamp` event.

I know, but…

> [@On another topic](https://forum.duniter.org/t/9426/84):
>
> SCALE de mes 2.
> 
> Je comprends kedal à qu’est-ce que je dois faire de ce `0x280404000b4100a06c8401`
> 
> … Je dois décoder le SCALE format à la mano ?
> 
> * * *
> 
> @ManUtopiK ton code ne m’aide pas trop dans l’indexer, mais merci d’avoir commenté au moins mdr
> 
> ```auto
> // Extract block date. Ugly, I can't find a better way to get the date of the block ?
> // The only polkadot issue for that : https://github.com/polkadot-js/api/issues/2603
> const created_at = new Date(
> signedBlock.block.extrinsics
> .filter(
> ({ method: { section, method } }) =>
> section === 'timestamp' && method === 'set'
> )[0]
> .args[0].toNumber()
> )
> 
> ```
> 
> Je sais pas quoi faire de ça dans mon dart…
> 
> merci pour vos éclaircissements 😇

---

<div class="post-metadata">

### Author: ![HugoTrentesaux](https://forum.duniter.org/user_avatar/forum.duniter.org/hugotrentesaux/32/6396_2.png) [@HugoTrentesaux](https://forum.duniter.org/u/HugoTrentesaux)
#### Post date: [14 December 2022 15:47 UTC](https://forum.duniter.org/t/hidden-hardcoded-duniter-variables/10169/8 "2022-12-14T15:47:26Z")

</div>

When you provide a runtime name you should know that its beginning determines the runtime type:

```rust
impl IdentifyRuntimeType for Box<dyn sc_chain_spec::ChainSpec> {
    fn runtime_type(&self) -> RuntimeType {
        if self.id().starts_with("g1") {
            RuntimeType::G1
        } else if self.id().starts_with("gdem") {
            RuntimeType::GTest
        } else if self.id().starts_with("dev") || self.id().starts_with("gdev") {
            RuntimeType::GDev
        } else if self.id().starts_with("gt") {
            RuntimeType::GTest
        } else {
            panic!("unknown runtime")
        }
    }
}

```

Who did know about “gdem” or so?

---

<div class="post-metadata">

### Author: ![tuxmain](https://forum.duniter.org/user_avatar/forum.duniter.org/tuxmain/32/6423_2.png) [@tuxmain](https://forum.duniter.org/u/tuxmain)
#### Post date: [14 December 2022 18:21 UTC](https://forum.duniter.org/t/hidden-hardcoded-duniter-variables/10169/9 "2022-12-14T18:21:28Z")

</div>

IIRC we have 2 options:

1. place them in storage, so they can be mutated by governance  
But it makes any access slower.
2. place them in runtime constants, so they can be mutated by runtime upgrade

I can’t find the issues. It could be a `D-easy` issue I think?

---

<div class="post-metadata">

### Author: ![HugoTrentesaux](https://forum.duniter.org/user_avatar/forum.duniter.org/hugotrentesaux/32/6396_2.png) [@HugoTrentesaux](https://forum.duniter.org/u/HugoTrentesaux)
#### Post date: [14 December 2022 20:06 UTC](https://forum.duniter.org/t/hidden-hardcoded-duniter-variables/10169/10 "2022-12-14T20:06:09Z")

</div>

> [@tuxmain](#):
>
> IIRC

The answer might be in [Liste des paramètres (protocolaires) de Duniter-v2s](https://forum.duniter.org/t/liste-des-parametres-protocolaires-de-duniter-v2s/9297)
