

owned this note

Sign in

# Alpha Casper FFG Testnet Instructions Welcome to the first release of the alpha Casper FFG testnet, built on pyethereum. This network represents the result of years of work on cryptoeconomic proof-of-stake and months of active development of the client, and is a fully-featured and usable network, allowing users to send transactions, mine and become validators. However, this is still several steps away from a network that will be ready for launch. Some parameters are set differently from the intended final settings, and the currently only available client, pyethereum, has a much lower processing capacity than clients implemented in faster languages; as a result, network parameters will be heavily restricted to ensure network sustainability. **Do not expect performance equivalent to test networks operated by more performant clients such as Geth and Parity**. ### What is Casper FFG and how does it work? This is out of scope of this document, but you can find info in these links: * [Proof of stake FAQ](https://github.com/ethereum/wiki/wiki/Proof-of-Stake-FAQ) * [Casper FFG paper](https://arxiv.org/abs/1710.09437) * [Presentation by Karl Floersch](https://www.youtube.com/watch?v=ycF0WFHY5kc) * [Jon Choi's Casper 101](https://medium.com/@jonchoi/ethereum-casper-101-7a851a4f1eb0) The rest of this document assumes some familiarity with Casper FFG. ### Just taking a look If you want to go straight to running a node, feel free to skip straight to the next section ("Running a Node") Look at the ethstats page here: [http://34.203.42.208:3000/](http://34.203.42.208:3000/) Also, you can use web3 (installation: `sudo pip3 install web3`) to connect to a node as follows (assuming python 3): ```python > from web3 import Web3, HTTPProvider > web3 = Web3(HTTPProvider('http://52.87.179.32:8545')) > web3.eth.getBlock('latest') # This should return the head of the chain ``` Then: ```python > import urllib.request, json > # This may take a while depending on your internet connection > casper_abi = json.load(urllib.request.urlopen( "https://gist.githubusercontent.com/vbuterin/868a6213b058fb4f1fdfcf64e54f0e91/raw/33fc177da3863ec320d1ebf95816ba52ffbffbe8/casper_abi")) > casper = web3.eth.contract(abi=casper_abi, address='0xbd832b0cd3291c39ef67691858f35c71dfb3bf21').call() # This should return the current epoch > casper.get_current_epoch() ``` Look through [the Casper contract](https://github.com/ethereum/casper/blob/master/casper/contracts/simple_casper.v.py) to see all the functions that you can call. Any public variable has a corresponding getter method, eg. a variable `x`, if it's public, has the corresponding getter `get_x()`; see the Vyper documentation [here](https://github.com/ethereum/vyper/tree/master/docs) (the latest available info) or [here](http://vyper.readthedocs.io/en/latest/) (this is outdated as of April 2 2018) for a more complete description on what getters are available. ### Running a node To run a node, follow the following instructions to download and run a Docker instance: Installing docker (if you do not yet have it) on Ubuntu: ```bash curl -fsSL get.docker.com -o get-docker.sh sudo sh get-docker.sh sudo usermod -aG docker $USER ``` (Replace $USER with your username, i.e. the one you see in login, in the terminal, in your file directory, etc.) Make sure to log out and log back in after this step. On MacOS, follow the instructions here: https://docs.docker.com/docker-for-mac/install/#install-and-run-docker-for-mac Getting the docker containers for the testnet nodes (warning, this involves a few hundred MB of downloading) ```bash $ git clone http://github.com/karlfloersch/docker-pyeth-dev $ cd docker-pyeth-dev $ sudo make new-account 🌟 Creating keystore directory at ./validator/data/config/keystore 🌟 Enter a new password to encrypt your account: 🌟 Your password is stored at ./validator/data/config/password.txt 🌟 Pyethapp container is creating new address for you, might take few seconds: ``` Running: ```bash $ sudo make run-node bootstrap_node=enode://d3260a710a752b926bb3328ebe29bfb568e4fb3b4c7ff59450738661113fb21f5efbdf42904c706a9f152275890840345a5bc990745919eeb2dfc2c481d778ee@54.167.247.63:30303 ``` If that enode does not work, try replacing with: `enode://a120401858c93f0be73ae7765930174689cad026df332f7e06a047ead917cee193e9210e899c3143cce55dd991493227ecea15de42aa05b9b730d2189e19b567@52.87.179.32:30303` Also, if you have a Geth, Parity or Akasha client or other service already using the port 30303, try changing it to something else, e.g. 30304. If you are running a node, then you can use web3.py to connect to it: ```bash $ docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 20a0dfe1d9e2 casper-validator "sh /root/start.sh p…" 18 minutes ago Up 18 minutes 8545/tcp, 30303/tcp, 30303/udp validator $ docker exec -it 20a0dfe1d9e2 python ``` Replace `20a0dfe1d9e2` with whatever container ID appears in the output when you run `docker ps`. Then repeat the web3 instructions above inside the python console that appears, but use `Web3(HTTPProvider('http://localhost:8545'))` in place of the remote node. To mine: ```bash $ sudo make run-node mine_percent=90 bootstrap_node=enode://d3260a710a752b926bb3328ebe29bfb568e4fb3b4c7ff59450738661113fb21f5efbdf42904c706a9f152275890840345a5bc990745919eeb2dfc2c481d778ee@54.167.247.63:30303 ``` If you get an error like this: ``` docker: Error response from daemon: Conflict. The container name "/validator" is already in use... ``` Then, you can fix by running `sudo docker rm validator`. ### Running a validator First, you will need to have enough testnet ETH to become a validator. You can either mine a lot of blocks, or ask us for ETH (a faucet may be available soon). To ask for ETH, you will need to have an ETH address. You can either use a keystore file you already generated on your own, e.g. using geth or pyeth_keys, or generate one with the docker tools. To login as a validator with the account you generated by running the `sudo make new-account` command above, run: ``` make run-node validate=true deposit=2000 bootstrap_node=enode://d3260a710a752b926bb3328ebe29bfb568e4fb3b4c7ff59450738661113fb21f5efbdf42904c706a9f152275890840345a5bc990745919eeb2dfc2c481d778ee@54.167.247.63:30303 ``` Replacing 2000 with whatever amount of ETH you want to deposit (min 1500). From there, just leave the docker node running. Note that once you log on, it will take ~1.5 dynasties (normally, ~30 minutes) until you are in the active validator set and can start voting. ### Checking your status Aside from the web3 route, you can also play around with the node directly through the python console. Press Ctrl+C inside of it, and you will see an instruction like `Hit [ENTER], to launch console; [Ctrl+C] again to quit! [0s]`. Press Ctrl+C again and you will enter the console. From there, you can use `eth.chain` to access the pyethereum Chain object (see documentation [here](https://github.com/ethereum/pyethereum)). Use `eth.services.accounts.accounts[0].address` to get your validator's address, which is also used as a kind of ID for the validator. You can also create a python object that will let you call commands of the Casper contract as so: ```python >> import urllib.request, json >> casper_abi = casper_abi = json.load(urllib.request.urlopen( "https://gist.githubusercontent.com/vbuterin/868a6213b058fb4f1fdfcf64e54f0e91/raw/33fc177da3863ec320d1ebf95816ba52ffbffbe8/casper_abi")) >> from ethereum.tools import tester >> casper = tester.ABIContract(tester.State(eth.chain.state), casper_abi, '0xbd832b0cd3291c39ef67691858f35c71dfb3bf21') >> casper.get_current_epoch() # This should return the current epoch number ``` To get data about yourself, do: ```python >> my_index = casper.get_validator_indexes(eth.services.accounts.accounts[0].address) >> # This should return your current deposit size >> casper.get_deposit_size(my_index) >> # This should return the current dynasty, and your validator's start and end dynasty >> casper.get_dynasty(), casper.get_validators__start_dynasty(my_index), casper.get_validators__end_dynasty(my_index) ``` Note that you will need to re-run the `casper = tester.ABIContract...` line in order to call Casper with the most recent state. To broadcast a transaction, use `eth.app.services.chain.broadcast_transaction(tx)` To exit pyethapp, type Ctrl+D. ### Logging out You can log out with the command: ``` make run-node validate=true logout=true bootstrap_node=enode://d3260a710a752b926bb3328ebe29bfb568e4fb3b4c7ff59450738661113fb21f5efbdf42904c706a9f152275890840345a5bc990745919eeb2dfc2c481d778ee@54.167.247.63:30303 ``` Then just leave the validator running, and after the withdrawal period ends it will automatically send another transaction to withdraw you. Note that in general, staying online is important. You as a validator will only be profitable if you are online more than half the time in the normal case, and if many other validators are offline than you may need to be online almost all of the time in order not to incur a loss.