[go: up one dir, main page]

Proto: update tickets balances in migration to Alpha

Closes #1693 (closed)

When Alpha protocol is initialised - iterate over all contracts, count number of tickets in their storage and add those to the ticket balance table.

Note that usually migrations run at the level of Raw_context, but we do it here at the level of Alpha_context - in order to parse script storage with Script_ir_translator.

Testing in Mockup mode

Create mockup client with Ithaca protocol, deploy and call a contract with ticket in storage.

$ ./tezos-client --base-dir /tmp/mockup --mode mockup \
  --protocol Psithaca2MLRFYargivpo7YvUr7wUDqyxrdhC5CQq78mRvimz6A create mockup

$ ./tezos-client --base-dir /tmp/mockup --mode mockup \
  originate contract foo transferring 100 from bootstrap1 running \
  'parameter unit; storage (list (ticket string)); code { CDR ; PUSH nat 1 ; PUSH string "Red" ; TICKET ; CONS ; NIL operation; PAIR }' \
  --init '{}' --burn-cap 10
...
New contract KT1MNkDcJn3coFJnpWgGPywtWUcbyZ89rf7J originated.
Contract memorized as foo.

$ ./tezos-client --base-dir /tmp/mockup --mode mockup \
  transfer 0 from bootstrap1 to foo --burn-cap 10 --gas-limit 10000

Observe that ticket_balance key is not present in the context.

$ grep ticket_balance /tmp/mockup/mockup/context.json -A 2

Run migration to Alpha.

$ ./tezos-client --base-dir /tmp/mockup --mode mockup \
  migrate mockup to ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK
Migration successful.

Observe that ticket_balance key in the context now contains data (value is not visible via RPC but we can check it in the mockup data file directly).

$ grep ticket_balance /tmp/mockup/mockup/context.json -A 2
              [ "ticket_balance",
                [ [ "370a769e656d209bd555c74eada2b2b79509e5cf02caa7f317b640caf473bcf6",
                    [ [ "data", "01" ], [ "len", "00000001" ] ] ] ] ],

Testing with Mainnet

Download and import a recent snapshot.

$ wget https://mainnet.xtz-shots.io/tezos-mainnet-2021290.rolling

$ ./tezos-node snapshot import tezos-mainnet-2021290.rolling --block BM7wvkrfMDtXHXCh4zGsYiLPVJ9u1ox7QY2k7pt7cRDxe2UxtpV

Create "yes wallet", patch node to accept fake signatures.

$ dune exec scripts/yes-wallet/yes_wallet.exe -- create from context ~/.tezos-node in /tmp/yes-wallet --active-bakers-only
$ patch -p1 < scripts/yes-node.patch

Configure protocol overrides: to Ithaca at the next level, and to Alpha in the next one.

$ patch -p1 <<EOF
diff --git a/src/bin_node/node_config_file.ml b/src/bin_node/node_config_file.ml
index 8f765b050a..7055ea6ae4 100644
--- a/src/bin_node/node_config_file.ml
+++ b/src/bin_node/node_config_file.ml
@@ -87,0 +88,2 @@ let mainnet_user_activated_upgrades =
+    (2021291l, "Psithaca2MLRFYargivpo7YvUr7wUDqyxrdhC5CQq78mRvimz6A");
+    (2021292l, "ProtoALphaALphaALphaALphaALphaALphaALphaALphaDdp3zK");
EOF

Add logging in tickets migration.

$ patch -p1 <<EOF
diff --git a/src/proto_alpha/lib_protocol/ticket_balance_migration_for_j.ml b/src/proto_alpha/lib_protocol/ticket_balance_migration_for_j.ml
index a50e43b99..a7aeed283 100644
--- a/src/proto_alpha/lib_protocol/ticket_balance_migration_for_j.ml
+++ b/src/proto_alpha/lib_protocol/ticket_balance_migration_for_j.ml
@@ -30,2 +30,3 @@ let add_ticket_balance contract ctxt ticket =
   let (token, delta) = Ticket_token.token_and_amount_of_ex_ticket ticket in
+  Logging.(log Notice "TICKET\t%a\t%i" Contract.pp contract (Z.to_int delta)) ;
   Ticket_balance_key.ticket_balance_key ctxt ~owner:contract token
@@ -65,2 +66,3 @@ let is_originated contract =
 let init ctxt =
+  Logging.(log Notice "TICKETS MIGRATION START") ;
   Contract.list ctxt >>= fun contracts ->
@@ -68,2 +70,4 @@ let init ctxt =
   let contracts = List.filter is_originated contracts in
-  List.fold_left_es update_contract_tickets ctxt contracts
+  List.fold_left_es update_contract_tickets ctxt contracts >>=? fun result ->
+  Logging.(log Notice "TICKETS MIGRATION END") ;
+  return result
EOF

Build code, run node in one terminal and bake two blocks in another.

$ make
$ ./tezos-node run --synchronisation-threshold 0 --connections 0 --rpc-addr localhost |& tee tezos-node.log

$ ./tezos-client -d /tmp/yes-wallet bake for foundation3 --minimal-timestamp |& tee tezos-client.log.1
$ ./tezos-client -d /tmp/yes-wallet bake for --minimal-timestamp |& tee tezos-client.log.2

First context will migrate to Ithaca, then to Alpha (~3 minutes). Observe in the node output that tickets migration produced logging.

...
Jan 21 16:06:09.875 - node.store: the protocol table was updated: protocol Psithaca2MLR (level 12) was
Jan 21 16:06:09.875 - node.store:   activated on block BM8unDWxfErJduMV94n1hXUfz1hrtKnSD2Y2hjkbL6FKTstS5jg
Jan 21 16:06:09.875 - node.store:   (level 2021291)
...
Jan 21 16:06:55.022 - node.protocol: alpha: TICKETS MIGRATION START
Jan 21 16:09:21.779 - node.protocol: alpha: TICKET      KT1EmjwdoxRUVdeZAettWrGJYZoBEew3YiFy    3968
Jan 21 16:09:21.779 - node.protocol: alpha: TICKET      KT1CnygLoKfJA66499U9ZQkL6ykUfzgruGfM    0
Jan 21 16:09:21.779 - node.protocol: alpha: TICKET      KT1CnygLoKfJA66499U9ZQkL6ykUfzgruGfM    5
...
Jan 21 16:09:21.799 - node.protocol: alpha: TICKET      KT1CnygLoKfJA66499U9ZQkL6ykUfzgruGfM    1
Jan 21 16:09:21.799 - node.protocol: alpha: TICKET      KT1CnygLoKfJA66499U9ZQkL6ykUfzgruGfM    5
Jan 21 16:09:21.799 - node.protocol: alpha: TICKET      KT1CXhHcNENzq5LEx6nC4zJDNgZvLpPkppSd    300
Jan 21 16:09:21.799 - node.protocol: alpha: TICKETS MIGRATION END
...

Integration tests

We perform migration in mockup client and then check content of context.json file corresponding to ticket balances. A bit hacky, but this data is not exposed via RPC and there seems to be no support for testing internals of the protocol after migration otherwise. Such test doesn't belong to proto_alpha either, because it involves interaction with previous protocol.

$ dune exec tezt/tests/main.exe -- tickets
[16:13:21.480] [SUCCESS] (1/1) (Ithaca -> Alpha) ticket balance migration

Checklist

  • Document the interface of any function added or modified (see the coding guidelines)
  • N/A 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 Fedor Sheremetyev

Merge request reports

Loading