hyperledger-iroha / iroha

Iroha - A simple, enterprise-grade decentralized ledger
https://wiki.hyperledger.org/display/iroha
Apache License 2.0
438 stars 280 forks source link

Implement human-readable bytes in the config #4295

Open 0x009922 opened 8 months ago

0x009922 commented 8 months ago

Description

Actually implement parsing from a human-readable string for HumanBytes:

https://github.com/hyperledger/iroha/blob/964476722e2a219becaacdb3676ca058ec5748cd/config/base/src/lib.rs#L36-L38

Specification

Here is an excerpt from the config reference draft:

Bytes amount is specified as a human-readable string:

# 42 bytes
value1 = "42B"

# 1 kilobyte = 1000 bytes
value2 = "1KB"

# 1 kilobyte (binary format) = 1024 bytes
value3 = "1KiB"

# Sum of multiple
value4 = "1GB 5MB"

Iroha can parse sizes in bytes, kilobytes (K), megabytes (M), gigabytes (G), terabytes (T), and petabytes (P).

The format of suffixes:

  • {size}iB: Binary size
  • {size}B: Decimal size

I used humanfriendly Python package as a reference.

Also

mversic commented 8 months ago

as discussed https://github.com/hyperledger/iroha-2-docs/issues/392 I'm not sure we want to complicate config files. Simple fixed suffix on the field name should suffice IMO. We need to discuss this before proceeding

DCNick3 commented 3 months ago

I am in favor of having human-readable suffixes in config, this makes it much easier to write large values by hand.

Oftentimes, when a large value is needed, you would still end up having a comment to explain what the value actually is, like max_transfer_bytes = 1048576 # 1 MiB, so having this natively supported by the config system is better UX IMO.

Same opinion on the #4294 with the same arguments, time_value = "1h" is better than time_value_ms = 3600000 # 1 hour