Everything that is needed to set up a Rewards Engine Submissions instance or a PropsChain Node.
WIP: This document is only for our staging/production environments.
- Added S3 state files. This will save the terraform.tfstate files on S3 instead of your local machine. Create a new bucket on s3, something like companyname-propschain-states. Then in your main.tf file change the bucket to this name in the s3 backend resource. For example this is the state file for the staging-simple environment
terraform {
backend "s3" {
bucket = "companyname-propschain-states"
key = "staging-simple"
region = "us-east-1"
skip_region_validation = true
workspace_key_prefix = "infrastructure"
profile = "sidechain-staging"
dynamodb_table = "terraform-state-lock-dynamo"
}
}
After you're done you can type terraform init
. Terraform will ask the following, confirm with yes.
Do you want to copy existing state to the new backend?
Pre-existing state was found while migrating the previous "local" backend to the
newly configured "s3" backend. No existing state was found in the newly
configured "s3" backend. Do you want to copy this state to the new "s3"
backend? Enter "yes" to copy and "no" to start with an empty state.
Enter a value: yes
- Added a new variable
state_api_url
in terraform.tfvars.tmp, copy this line to your terraform.tfvars file and doterraform apply
We are using AWS as our cloud provider, thus we provide you with a terraform setup that allows you to quickly create a launch configuration. This launch configuration creates an instance with a sidechain node.
You're not obligated to use these terraform files, you can use them as a guide to create your own instance on AWS or another cloud provider.
- /docker: this contains the docker-compose.yaml file that creates the sidechain node. This is all you need if you don't want to use our terraform files
- /terraform/environments: contains folders for each environment (staging, production, etc) with the terraform configuration for each environment
- /terraform/modules: custom terraform modules
Staging and production share a lot of the same configuration, but the following variables (to be set in terraform.tfvars) are different
- for production use terraform/environments/production-simple
- props_token_contract_address (check terraform.tfvars.tmp)
- ethereum_url (check terraform.tfvars.tmp)
- seconds_in_day (check terraform.tfvars.tmp)
- which_docker_compose (check terraform.tfvars.tmp)
- You need to create a free infura account (https://infura.io/)
Install terraform from https://www.terraform.io/downloads.html
Create a new AWS profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)
$ aws configure --profile sidechain-staging
Copy the terraform.tfvars template
$ cd terraform/environments/staging-simple
$ cp terraform.tfvars.tmp terraform.tfvars
In AWS console create a new key pair (EC2 -> Network & Security -> Key Pairs -> Create Key Pair) and name the key pair sawtooth-staging. You can choose another name if you prefer, but make sure you modify the key_name variable in the next step.
Modify the terraform.tfvars file with your settings. We provide you with a couple of default values. Here's an overview of the variables that you might want or will have to change.
Examples are given after each variable
AWS Configuration
- aws_region: the aws region in which you want to spawn the instances. (e.g. us-east-1)
- aws_availability_zones: choose the availability zones that for the instances, comma separated. (e.g. us-east-1a,us-east-1b,us-east-1c)
- vpc_id: the VPC in which you want to create your instances. The default AWS VPC is always a good starting point. (e.g vpc-abcdefgh)
- subnet_ids: the subnets (comma separated) in which you want to create your instances, I suggest taking the default AWS public subnets, (e.g subnet-abcdefgh,subnet-ijklmnop)
- ami: this is the AMI that the instance is based of, this is the official amazon linux image for AWS. Don't change this value.
Rewards engine configuration
- nodes_count: how many reward instances do you want to launch? (e.g. 1)
- instance_disk_size: how big should the disk be? 10 is a good starting number (e.g. 10)
- ethereum_url: this is the infura url (see requirements above) (e.g. https://rinkeby.infura.io/v3/yourkeyhere>)
- props_token_contract_address: the address of the props token contract address on rinkeby. The default value is good
- which_docker_compose: Keep the default value: staging-simple
- validator_submission_pk: The 'main wallet' private key
- seconds_in_day: 3600
- frequency_hours: *
- frequency_minutes: 5
- rewards_start_timestamp: 1561248000 (for staging, check terraformtfvars.tmp in production-simple for production values)
- sawtooth_rest_url: staging-api.sidechain.propsproject.io (for staging, check terraformtfvars.tmp in production-simple for production values)
- sawtooth_rest_port: 443
- sawtooth_rest_https: true
Once you have modified terraform.tfvars we can now create the instance
Initialize terraform
$ cd terraform/environments/staging-simple
$ terraform init
Create your infrastructure
$ terraform apply
Read the section of doing the validator setup on https://github.com/propsproject/props-ethsync
- ssh into the instance that was created
- run the following
/usr/local/bin/docker-compose -f /opt/sawtooth/docker/staging-simple/docker-compose.yaml run --entrypoint "npm run setup-validator -- {validatorName} {rewardsAddress} {sidechainAddress}" eth-sync
- You need to create a free infura account (https://infura.io/)
- You also need to create an etherscan account and create an API key (https://etherscan.io/myapikey)
This step is optional if you want to configure your own instance with docker, but it will make the setup much easier. These terraform files are for AWS.
If you choose not to use terraform, scroll down and read the section about docker.
Install terraform from https://www.terraform.io/downloads.html
Create a new AWS profile (https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)
$ aws configure --profile sidechain-staging
Copy the terraform.tfvars template
$ cd terraform/environments/staging
$ cp terraform.tfvars.tmp terraform.tfvars
In AWS console create a new key pair (EC2 -> Network & Security -> Key Pairs -> Create Key Pair) and name the key pair sawtooth-staging. You can choose another name if you prefer, but make sure you modify the key_name variable in the next step.
Modify the terraform.tfvars file with your settings. We provide you with a couple of default values. Here's an overview of the variables that you might want or will have to change.
Examples are given after each variable
AWS Configuration
- aws_region: the aws region in which you want to spawn the instances. (e.g. us-east-1)
- aws_availability_zones: choose the availability zones that for the instances, comma separated. (e.g. us-east-1a,us-east-1b,us-east-1c)
- vpc_id: the VPC in which you want to create your instances. The default AWS VPC is always a good starting point. (e.g vpc-abcdefgh)
- subnet_ids: the subnets (comma separated) in which you want to create your instances, I suggest taking the default AWS public subnets, (e.g subnet-abcdefgh,subnet-ijklmnop)
- ami: this is the AMI that the instance is based of, this is the official amazon linux image for AWS. Don't change this value.
Node configuration
- nodes_count: how many sidechains do you want to launch? (e.g. 1)
- instance_disk_size: how big should the disk be? 40 is a good starting number (e.g. 40)
- ethereum_confirmation_block: don't change this value
- ethereum_url: this is the infura url (see requirements above) (e.g. https://rinkeby.infura.io/v3/yourkeyhere>)
- etherscan_url: this is the etherscan api url. The default value should be good (e.g. https://api-rinkeby.etherscan.io/api)
- etherscan_api_key: this is the etherscan api key, see requirements above
- props_token_contract_address: the address of the props token contract address on rinkeby. The default value is good
- props_token_deployed_block: the blockId of the contract address. The default value is good
- sawtooth_pk: the private key of the 'sidechain wallet', for sawtooth to use
- validator_url: the default value is good, will need to be removed at some point
- network_private_key: the zeromq private key, you need to contact us for this key
- network_public_key: the zeromq public key, you need to contact us for this key
- sawtooth_rest_url: the sawtooth rest url to be used, the default 'rest-api' is good since this is the name of the docker container
- sawtooth_rest_port: the sawtooth rest url port, the default is '8008', which is good
- validator_seed_url: the validator to use when the sidechain starts, the default value is good. If you already have a validator running, you can use that ip address instead (format: tcp://ipofvalidator:8800)
Once you have modified terraform.tfvars we can now create the instance
Initialize terraform
$ cd terraform/environments/staging
$ terraform init
Create your infrastructure
$ terraform apply
Go into AWS console EC2 and check if your instances are spawning. Depending on your nodes_count above you will see 1 or more instances being spawned.
Starting an instance will take some time, but after a couple of minutes they should be up and running.
Take the IP address of your node and go to
http://<ipaddress>:8008/peers
or
http://<ipaddress>:8008/blocks
It will take some time to sync your node, so blocks might not give immediate results
If you followed the terraform instructions and built your instance that way, you don't need this section. But it's still useful to read this.
You need to install docker and docker-compose (https://docs.docker.com/compose)
You need the set the following environment variables on your instance
- VALIDATOR_URL=tcp://validator:4004
- ETHEREUM_URL=https://rinkeby.infura.io/v3/
- PROPS_TOKEN_CONTRACT_ADDRESS=0x4dd1c86de2bc220611bd869c6fa14f62f16c0743
- PUBLIC_IP_ADDRESS: This is the public IP address of your instance
- SAWTOOTH_PK: Private key of your 'sidechain wallet'
- NETWORK_PUBLIC_KEY: Contact us for this key
- NETWORK_PRIVATE_KEY: Contact us for this key
- ETHERSCAN_URL=https://rinkeby.infura.io/v3/yourkeyhere
- ETHERSCAN_API: your api key here
- PROPS_TOKEN_DEPLOYED_BLOCK=3950142
- VALIDATOR_URL=tcp://validator:4004
- ENVIRONMENT=staging
- NODE_ENV=staging
- VALIDATOR_SEED_URL: The url to connect to for getting the initial blocks, this should be in the format of tcp://ipofvalidator:8800
Once you have the environment variables set you can run your sidechain node
$ cd docker
$ docker-compose up --force-recreate -d
Take the IP address of your node and go to
http://<ipaddress>:8008/peers
or
http://<ipaddress>:8008/blocks
You should now have a running sidechain node that connects to our staging environment.
The staging environment is in constant flux, and we might restart it once in a while for testing. Contact us and talk to us on slack!