# Tx Rollup Ticket Transfer Investigation logs and notes
This document's purpose is to keep track of the findings and document the process so far to ensure easier hand off to other engineers that would like to dive into TORU ticket transfers
## Docker Container
There's currently a Docker image available that will allow users to use the most up-to-date Tezos client as well as the newly introduced rollup client.
- Tezos client commands start with: `tezos-client`
- Rollup client commands start with: `tezos-tx-rollup-client-013-PtJakart` or something similar (`tezos-tx-rollup-client-alpha`, `tezos-tx-rollup-node-alpha`, etc)
To spin up your own Docker container refer to these steps:
```
docker run -it -v {volume_path}:/home/tezos/tmp --name tx --entrypoint=/bin/sh tezos/tezos:master_c470f92d_20220710222321
```
- `volume_path` should be absolute path in your host machine to your volume directory.
on my MacOS machine, it looks something like `/Users/dsawali/Desktop/rollup_dailynet`
- If testing on Mondaynet, check [here](https://teztnets.xyz/mondaynet-about) for the most up to date Docker image.
## Setting up the Docker container to toy with rollup nodes
The Docker container comes pre-installed with `tezos-client` and the rollup client, so we won't be needing to install that. But you will need to activate your own implicit accounts from the faucet.
## Creating a Rollup node instance inside the container
Once inside the docker container CLI, you are now able to start your own rollup node.
To do so, follow the steps in this documentation: https://gitlab.com/tezos/tezos/-/blob/lthms@tx-rollup-getting-started/docs/jakarta/transaction_rollups.rst
### Originating a rollup node
Specifically look under the ***'Starting a Rollup Node'*** section. It is again, however, an incomplete documentation. It's a great baseline, but essentially we'd need to run these following commands to initialize a rollup node:
```
tezos-client originate tx rollup ${tx_rollup_allias} from ${implicit_account_alias} --burn-cap 1
```
`tx_rollup_alias` can be whatever name you want your rollup alias to be
`implicit_account_alias` will be whichever name we gave our activated a faucet account
We will then be given a rollup node address (`txr1` address) that we can use to initialize our node with, in the following examples that alias name will be `alice`
### Initializing a rollup node config folder/file
After that we will need to initialize a config folder that our rollup node will use as a reference:
```
tezos-tx-rollup-node-alpha init operator config \
for txr1hA1fBZtctY7txNY9pPVp9CVfKBzzaGh4u \
--data-dir "rollup" \
--rpc-addr 0.0.0.0:9999 \
--operator alias:alice \
--batch-signer alias:bob \
--rejection-signer alias:charlie \
--finalize-commitment-signer alias:dan \
--remove-commitment-signer alias:dan \
--dispatch-withdrawals-signer alias:elaine
```
:::danger
**Important**: The account `alice` in this instance is the Operator alias. An Operator alias needs to have _at least_ 10,000ꜩ in order for the TORU node to work properly
:::
:::warning
**Note**: Be mindful of which folder we point our `--data-dir` parameter to. It will vary depending on which folder in the file system we are currently at.
:::
:::warning
**Note**: Notice different aliases being used for different signers. To safeguard against a behavioural bug on the node, it is highly recommended to use different accounts to initialize the rollup config
:::
### Running the rollup node
```
tezos-tx-rollup-node-alpha run operator for txr1hA1fBZtctY7txNY9pPVp9CVfKBzzaGh4u --data-dir "rollup" --allow-deposit
```
The rollup node is now running.
## Interacting with the rollup node
In another terminal window, run
```
docker exec -it tx sh
```
We will leave the other window with the rollup node running.
~~Follow [this](https://gitlab.com/tezos/tezos/-/blob/lthms@tx-rollup-getting-started/docs/jakarta/transaction_rollups.rst) documentation again, but this time starting from ***'Depositing Assets on a Rollup'***~~
~~Make sure to have [this contract](https://gitlab.com/tezos/tezos/-/blob/lthms@tx-rollup-getting-started/tezt/tests/contracts/proto_alpha/tx_rollup_deposit.tz) available in your container (You can either utilize a volume or just `cp` from host).~~
~~From there on, you can follow along the documentation pretty much as is.~~
### Originate the smart contract to receive tickets
```
parameter (ticket string);
storage (option (ticket string));
code { CAR ; SOME ; NIL operation ; PAIR }
```
Copy the contents of the text above, save it in a file called `tx_tickets.tz` (or whatever name you would like) into our volume folder in our host machine to have it accessible from our container.
Originate contract:
```
tezos-client originate contract tx_tickets \
transferring 0 from ${alias} running ${path_to_contract.tz} \
--init None \
--burn-cap 0.401 \
--force
```
### Generate tz4 address
```
# generate a pair of public and secret keys
tezos-client bls gen keys ${alias}
# display the keys (including the ``tz4`` hash)
tezos-client bls show address ${alias}
```
You will get something like this:
```
Hash: tz4QsWvALZ6SMtqCDjr2PBxo73TfKEXXos6p
Public Key: BLpk1zMmRAyKCPbsCUp8xGY5VW9ER63FmpgrzagZdum6TYPboJUTQudfnmYkq6qmyATevE8a9XRN****
```
### Depositing a ticket string
Now you can deposit a ticket string using the `tz4` address hash as such:
```
tezos-client transfer 0 from alice to rollup_deposit \
--arg '(Pair "foobar" 10 "tz4QsWvALZ6SMtqCDjr2PBxo73TfKEXXos6p" \
"txr1jenAFnH341L9JEFMfKnzv2wUEKKN69m5q")' \
--burn-cap 0.068
```
You will see something like this:
```
This sequence of operations was run:
Manager signed operations:
From: tz1VgGiBU2DJ85WRfvvZJaJgTPXcNKEW76cB
Fee to the baker: ꜩ0.000866
Expected counter: 1102
Gas limit: 5056
Storage limit: 86 bytes
Balance updates:
tz1VgGiBU2DJ85WRfvvZJaJgTPXcNKEW76cB ... -ꜩ0.000866
payload fees(the block proposer) ....... +ꜩ0.000866
Transaction:
Amount: ꜩ0
From: tz1VgGiBU2DJ85WRfvvZJaJgTPXcNKEW76cB
To: KT1EaXiaQ8ExgttWGTDTd9id79dEqBY7qSHj
Parameter: (Pair "foobar"
10
"tz4QsWvALZ6SMtqCDjr2PBxo73TfKEXXos6p"
"txr1jenAFnH341L9JEFMfKnzv2wUEKKN69m5q")
This transaction was successfully applied
Updated storage: Unit
Storage size: 132 bytes
Paid storage size diff: 66 bytes
Consumed gas: 2860.115
Balance updates:
tz1VgGiBU2DJ85WRfvvZJaJgTPXcNKEW76cB ... -ꜩ0.0165
storage fees ........................... +ꜩ0.0165
Internal operations:
Internal Transaction:
Amount: ꜩ0
From: KT1EaXiaQ8ExgttWGTDTd9id79dEqBY7qSHj
To: txr1jenAFnH341L9JEFMfKnzv2wUEKKN69m5q
Entrypoint: deposit
Parameter: { Pair (Pair 0x0141c531e55cfd08b47eaa828d93f35cf983524d4800 (Pair "foobar" 10))
0xae0b7bd62894aba29b76ba67fca974d70d477caa ;
string }
This transaction was successfully applied
Consumed gas: 2095.035
Ticket hash: expruQsFHco313EJQhGjLF8J2m1g3JYNrfRoyEk5yAG58M1hX1igV6
```
:::warning
Keep note of the `Ticket hash` for withdrawals and transfers
:::
### Checking the balance
```
tezos-tx-rollup-client-alpha get balance for ${tz4_alias} of expruQsFHco313EJQhGjLF8J2m1g3JYNrfRoyEk5yAG58M1hX1igV6
```
The above command will inspect the balance of a tz4 address for a given ticket hash.
At this point it should show
```
10
```
### Withdrawing a ticket and injecting it back to L1
```
tezos-tx-rollup-client-alpha withdraw 4 of expruQsFHco313EJQhGjLF8J2m1g3JYNrfRoyEk5yAG58M1hX1igV6 from ${tz4} to ${l1_dst}
```
Now we wait for the finality period. On mainnet and other testnets it's 40k blocks. On Mondaynet/Dailynet the finality period is 10 blocks.
To check whether your commitments are finalized or not, run
```
tezos-tx-rollup-client-alpha rpc get "/block/head/"
```
look for the `finalized` property; it will either show `true` or `false`
### Dispatch and transfer ticket to smart contract
You need some extra information in order to do so. First, you'll need the `micheline_contents`, `type`, and `ticketer`.
```
tezos-tx-rollup-client-alpha rpc get "/context/head/tickets/${ticket_hash}"
```
You should get something like this:
```
{
"ticketer": "KT1EaXiaQ8ExgttWGTDTd9id79dEqBY7qSHj",
"ty": { "prim": "string" }, "contents": { "string": "foobar" },
"hash": "expruQsFHco313EJQhGjLF8J2m1g3JYNrfRoyEk5yAG58M1hX1igV6"
}
```
After the finality period is complete, you can now do a transfer with the information you gained above:
```
tezos-client transfer 2 tickets from alice to tx_tickets \
with entrypoint default and contents '"foobar"' \
and type string \
and ticketer KT1EaXiaQ8ExgttWGTDTd9id79dEqBY7qSHj \
--burn-cap 1
```
:::warning
**Note**: '"foobar"' (the content) has to be in that specific format to be recognized as michelson and not `string`
:::
result:
```
Node is bootstrapped.
Estimated gas: 4908.650 units (will add 100 for safety)
Estimated storage: 110 bytes added (will add 20 for safety)
Operation successfully injected in the node.
Operation hash is 'ooTm8aU6KJEJrKJdeUiyP7qfj4aKZD5tb77hJCy7Qy36gs7sz9C'
Waiting for the operation to be included...
Operation found in block: BMCMugNZbMKtdYHJwyPUTwgTevsMMEjFrnB5Y5xR596RoZ8VNsT (pass: 3, offset: 0)
This sequence of operations was run:
Manager signed operations:
From: tz1VgGiBU2DJ85WRfvvZJaJgTPXcNKEW76cB
Fee to the baker: ꜩ0.000804
Expected counter: 1105
Gas limit: 5009
Storage limit: 130 bytes
Balance updates:
tz1VgGiBU2DJ85WRfvvZJaJgTPXcNKEW76cB ... -ꜩ0.000804
payload fees(the block proposer) ....... +ꜩ0.000804
Transfer tickets:
From: tz1VgGiBU2DJ85WRfvvZJaJgTPXcNKEW76cB
This tickets transfer was successfully applied
Paid storage size diff: 66 bytes
Consumed gas: 2122.881
Balance updates:
tz1VgGiBU2DJ85WRfvvZJaJgTPXcNKEW76cB ... -ꜩ0.0165
storage fees ........................... +ꜩ0.0165
Internal operations:
Internal Transaction:
Amount: ꜩ0
From: tz1VgGiBU2DJ85WRfvvZJaJgTPXcNKEW76cB
To: KT1MFcfaZjo8JvUHcZQzfCjHrngXz3gzqoi3
Parameter: (Pair 0x0141c531e55cfd08b47eaa828d93f35cf983524d4800 (Pair "foobar" 2))
This transaction was successfully applied
Updated storage:
(Some (Pair 0x0141c531e55cfd08b47eaa828d93f35cf983524d4800 (Pair "foobar" 2)))
Storage size: 90 bytes
Paid storage size diff: 44 bytes
Consumed gas: 2785.769
Balance updates:
tz1VgGiBU2DJ85WRfvvZJaJgTPXcNKEW76cB ... -ꜩ0.011
storage fees ........................... +ꜩ0.011
The operation has only been included 0 blocks ago.
We recommend to wait more.
Use command
tezos-client wait for ooTm8aU6KJEJrKJdeUiyP7qfj4aKZD5tb77hJCy7Qy36gs7sz9C to be included --confirmations 1 --branch BKu8DoYUtJwNULDF6ZecqBYswU2smJxXNEa4Dtc6tc44vExyTy1
and/or an external block explorer.
```
# Notes
###
:::success
The error below had been addressed in the above documentation (Needing 10,000ꜩ for operator alias and using different aliases for signers when initializing the rollup config)
:::
Currently we have not been successful in withdrawing the tickets from `l2` to `l1` with this error:
```
Error:
Attempted to set negative ticket balance value '-1' for key expruNkrr2C2CrNWs8DyCmM9qEAj6hTtRN4KbhKdsSozLsVMwRTA7L.
/tezos/tmp $ tezos-client transfer 1 tickets from tz1hm7hf87A2zJW2pZrWtT42d3ZHmxSLmLW9 to rollup_deposit with entrypoint default and contents '"foobar"' and type string and ticke
ter KT1KtdeZifnahHAXrkiCQGhyUUnQmh1Wc4co
```
It looks as if the tickets were supposedly synchronized between `l2` and `l1` but the ticket in `l1` didn't have the same balances as the one we have on `l2`. `l1` tickets were still 0, so trying
# Helpful commands
### important:
docker container image: registry.gitlab.com/tezos/tezos/bare:amd64_tx_rollup_docker
### helpful docker commands
docker ps -> see running containers
docker ps -a -> see all run containers including shutdown ones
docker container prune -> remove exited containers
docker run flags:
-v -> volume \${your directory to store the files from the docker container}:${name of dir to connect docker container to your personal directory} example: ~/Documents/Faucets/jakarta:/faucets (allows access of faucet files from computers file system to docker file system) NOTE needs abolute path
--rm -> remove container after closing. no need to run docker container prune to remove exited containers
NOTE: -v path/to/directory:path/to/container/directory must bet exact paths
### helpful tx rollup tezos-client commands:
tezos-client bls list keys -> list tz4 addresses
tezos-client list known addresses -> list tz1/2/3 keys attached to tezos-client
tezos-client originate tx rollup ${alias for txr1 address (this is optional)} from ${pkh alias or tz1/2/3 address} --burn-cap 1 -> originate a txr1 address
tezos-client config show -> show current node tezos-client is interacting with