Skip to content
Snippets Groups Projects
Commit a8ea0772 authored by Moul's avatar Moul
Browse files

Fix cmds requesting too quickly in a loop uids from pubkey with BMA (#438)

Specially happening in local condition, where there is no network
latency

blocks, history -u, and tx commands
Define BMA_SLEEP constant to 0.1 second
Set time.sleep(BMA_SLEEP) between the requests
parent 0c5db65e
No related branches found
No related tags found
1 merge request!220Fix cmds requesting too quickly in a loop uids from pubkey with BMA (#438)
Pipeline #17537 failed
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with Silkaj. If not, see <https://www.gnu.org/licenses/>. # along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
import time
from collections import OrderedDict from collections import OrderedDict
from operator import itemgetter from operator import itemgetter
from typing import List from typing import List
...@@ -24,7 +25,7 @@ from pendulum import from_timestamp ...@@ -24,7 +25,7 @@ from pendulum import from_timestamp
from silkaj import tui from silkaj import tui
from silkaj.blockchain.tools import get_head_block from silkaj.blockchain.tools import get_head_block
from silkaj.constants import ALL from silkaj.constants import ALL, BMA_SLEEP
from silkaj.network import client_instance from silkaj.network import client_instance
from silkaj.wot.tools import identity_of from silkaj.wot.tools import identity_of
...@@ -61,6 +62,7 @@ def list_blocks(number: int, detailed: bool) -> None: ...@@ -61,6 +62,7 @@ def list_blocks(number: int, detailed: bool) -> None:
issuers.append(issuer) issuers.append(issuer)
for pubkey in issuers_dict.keys(): for pubkey in issuers_dict.keys():
issuer = issuers_dict[pubkey] issuer = issuers_dict[pubkey]
time.sleep(BMA_SLEEP)
try: try:
idty = identity_of(issuer["pubkey"]) idty = identity_of(issuer["pubkey"])
except HTTPError: except HTTPError:
......
...@@ -21,6 +21,7 @@ G1_TEST_DEFAULT_ENDPOINT = "BMAS g1-test.duniter.org 443" ...@@ -21,6 +21,7 @@ G1_TEST_DEFAULT_ENDPOINT = "BMAS g1-test.duniter.org 443"
SUCCESS_EXIT_STATUS = 0 SUCCESS_EXIT_STATUS = 0
FAILURE_EXIT_STATUS = 1 FAILURE_EXIT_STATUS = 1
BMA_MAX_BLOCKS_CHUNK_SIZE = 5000 BMA_MAX_BLOCKS_CHUNK_SIZE = 5000
BMA_SLEEP = 0.1
PUBKEY_MIN_LENGTH = 43 PUBKEY_MIN_LENGTH = 43
PUBKEY_MAX_LENGTH = 44 PUBKEY_MAX_LENGTH = 44
PUBKEY_PATTERN = f"[1-9A-HJ-NP-Za-km-z]{{{PUBKEY_MIN_LENGTH},{PUBKEY_MAX_LENGTH}}}" PUBKEY_PATTERN = f"[1-9A-HJ-NP-Za-km-z]{{{PUBKEY_MIN_LENGTH},{PUBKEY_MAX_LENGTH}}}"
......
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
import math import math
import re import re
import shlex import shlex
import time
from typing import List, Tuple from typing import List, Tuple
import click import click
...@@ -34,6 +35,7 @@ from duniterpy.key import SigningKey ...@@ -34,6 +35,7 @@ from duniterpy.key import SigningKey
from silkaj import auth, network, public_key, tools, tui from silkaj import auth, network, public_key, tools, tui
from silkaj.blockchain import tools as bc_tools from silkaj.blockchain import tools as bc_tools
from silkaj.constants import ( from silkaj.constants import (
BMA_SLEEP,
CENT_MULT_TO_UNIT, CENT_MULT_TO_UNIT,
MINIMAL_ABSOLUTE_TX_AMOUNT, MINIMAL_ABSOLUTE_TX_AMOUNT,
MINIMAL_RELATIVE_TX_AMOUNT, MINIMAL_RELATIVE_TX_AMOUNT,
...@@ -357,6 +359,7 @@ def gen_confirmation_table( ...@@ -357,6 +359,7 @@ def gen_confirmation_table(
# display outputs and amounts # display outputs and amounts
for outputAddress, tx_amount in zip(outputAddresses, tx_amounts): for outputAddress, tx_amount in zip(outputAddresses, tx_amounts):
m_tools.display_pubkey(tx, "To", outputAddress) m_tools.display_pubkey(tx, "To", outputAddress)
time.sleep(BMA_SLEEP)
m_tools.display_amount(tx, "Amount", tx_amount, ud_value, currency_symbol) m_tools.display_amount(tx, "Amount", tx_amount, ud_value, currency_symbol)
# display last informations # display last informations
if outputBackChange: if outputBackChange:
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
# You should have received a copy of the GNU Affero General Public License # You should have received a copy of the GNU Affero General Public License
# along with Silkaj. If not, see <https://www.gnu.org/licenses/>. # along with Silkaj. If not, see <https://www.gnu.org/licenses/>.
import time
import urllib import urllib
from typing import Dict, List, Optional, Tuple from typing import Dict, List, Optional, Tuple
from urllib.error import HTTPError from urllib.error import HTTPError
...@@ -20,6 +21,7 @@ from urllib.error import HTTPError ...@@ -20,6 +21,7 @@ from urllib.error import HTTPError
import click import click
from duniterpy.api.bma import wot from duniterpy.api.bma import wot
from silkaj.constants import BMA_SLEEP
from silkaj.network import client_instance, exit_on_http_error from silkaj.network import client_instance, exit_on_http_error
from silkaj.public_key import gen_pubkey_checksum from silkaj.public_key import gen_pubkey_checksum
from silkaj.tui import Table from silkaj.tui import Table
...@@ -67,6 +69,7 @@ def identities_from_pubkeys(pubkeys: List[str], uids: bool) -> List: ...@@ -67,6 +69,7 @@ def identities_from_pubkeys(pubkeys: List[str], uids: bool) -> List:
uniq_pubkeys = list(filter(None, set(pubkeys))) uniq_pubkeys = list(filter(None, set(pubkeys)))
identities = [] identities = []
for pubkey in uniq_pubkeys: for pubkey in uniq_pubkeys:
time.sleep(BMA_SLEEP)
try: try:
identities.append(identity_of(pubkey)) identities.append(identity_of(pubkey))
except HTTPError: except HTTPError:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment