Client: Add a cache to the wallet

Context

The client use the Module Alias to store and load the wallet keys. This module reads or writes the file each time an access or a modification is done. For files that contains a large number of elements this is costly.

To optimize the Module Alias, this merge request introduce a cache in it. It is loaded at the first access to the data or each time the modification time of the associated file changed.

This merge request change the behavior of Alias.update:

  • legacy behavior: update all the bindings (i.e. if there are multiples bindings for the updated key, they are all associated to the same value),
  • new behavior: remove all the bindings and add a new one (i.e. no matter if there are multiples bindings for the updated key, there will be only one binding for the key).

Manually testing the MR

wallet.tar.gz is an archive containing a wallet with 10 000 keys and some files to prepare the stresstest. In this example, we extract this archive in the directory where the git repository has been cloned.

In a terminal, launch a sandbox node:

rm -r /tmp/test-tz-4005; DATA_DIR="/tmp/test-tz-4005" ./src/bin_node/tezos-sandboxed-node.sh 1 --connections 0

In a second terminal, activate a protocol, bake a block, forget the bootstrap1 key and launch the baker:

# load sandbox client environment
eval "$(./src/bin_client/tezos-init-sandboxed-client.sh 1)"

# activate alpha and test baking
tezos-activate-alpha
tezos-client bake for

# run the baker
tezos-baker-alpha run with local node /tmp/test-tz-4005

In a third terminal, test the stresstest command

# load sandbox client environment
eval "$(./src/bin_client/tezos-init-sandboxed-client.sh 1)"

# prepare needed files
wallet_dir=$(alias | grep "tezos-activate-alpha=" | sed -e "s/.*-base-dir \(.*\) -endpoint.*/\1/")
wget https://gitlab.com/tezos/tezos/uploads/0738d76a076de12184ec5308b7a2eab4/wallet.tar.gz --directory-prefix="$wallet_dir/"
tar xvzf "$wallet_dir"/wallet.tar.gz --directory="$wallet_dir/"

# distribute funds to the accounts to be used
tezos-client multiple transfers from bootstrap2 using "$wallet_dir/multitransfer.json" --burn-cap 16.0625
# start the stresstest
tezos-client stresstest transfer using file:"$wallet_dir/aliases" --single-op-per-pkh-per-block --transfers 500 --verbose

The stresstest command should load fast, i.e. the log all sources have been normalized should appears after a few seconds.

Once the test is finished, you can clean the client directory by using tezos-client-reset in each terminal.

Checklist

  • Document the interface of any function added or modified (see the coding guidelines)
  • Document any change to the user interface, including configuration parameters (see node configuration)
  • Provide automatic testing (see the testing guide).
  • For new features and bug fixes, add an item in the appropriate changelog (docs/protocols/alpha.rst for the protocol and the environment, the Development Version section of CHANGES.md for everything else).
  • Select suitable reviewers using the Reviewers field below.
  • Select as Assignee the next person who should take action on that MR
Edited by Vivien Pelletier

Merge request reports

Loading