razor-go v1.0.0
Razor-Go
Official node for running stakers in Golang.
Installation
Linux quick start
Install razor-go pre build binary directly from github and configure into host.
For linux-amd64
curl -sSL https://raw.githubusercontent.com/razor-network/razor-go/main/install.sh | bash For linux-arm64
export PLATFORM=arm64
curl -sSL https://raw.githubusercontent.com/razor-network/razor-go/main/install.sh | bash Check installation
razor -vNOTE: To install the version you want, you can set VERSION: environment variable before running above command.
Docker quick start
One of the quickest ways to get razor-go up and running on your machine is by using Docker:
docker run -d -it--entrypoint /bin/sh --name razor-go -v "$(echo $HOME)"/.razor:/root/.razor razornetwork/razor-go:v1.0.1-incentivised-testnet-phase2NOTE: that we are leveraging docker bind-mounts to mount
.razordirectory so that we have a shared mount of.razordirectory between the host and the container. The.razordirectory holds keys to the addresses that we use inrazor-go, along with logs and config. We do this to persist data in the host machine, otherwise you would lose your keys once you delete the container.
You need to set a provider before you can operate razor-go cli on docker:
docker exec -it razor-go razor setConfig -p <provider_url>You can now execute razor-go cli commands by running:
docker exec -it razor-go razor <command>Prerequisites to building the source
- Golang 1.15 or later must be installed.
- Latest stable version of node is required.
- Silicon chip based Mac users must go for node 15.3.0+
gethandabigenshould be installed. (Skip this step if you don't want to fetch the bindings and build from scratch)solcandjqmust be installed.
Building the source
- Run
npm installto install the node dependencies. If you want to build from scratch i.e., by fetching the smart contract bindings as well, run
npm run build-all.Note: To build from scratch,
gethandabigenmust be installed in your system.If you already have the
pkg/bindingsyou can runnpm run buildinstead ofnpm run build-allto directly build the binary.- If you want to build the binary without wanting to set the configurations use
npm run build-noargs - While building the binary, supply the provider RPC url and the gas multiplier.
- To bypass the interactive mode of providing password, create file in
.razordirectory with providing password in it. - The binary will be generated at
build/bin.
Commands
Go to the build/bin directory where the razor binary is generated.
cd build/bin
Set Config
There are a set of parameters that are configurable. These include:
- Provider: The RPC URL of the provider you are using to connect to the blockchain.
- ChainId: The chain ID is a property of the chain managed by the node. It is used for replay protection of transactions.
- Gas Multiplier: The value with which the gas price will be multiplied while sending every transaction.
- Buffer Size: Buffer size determines, out of all blocks in a state, in how many blocks the voting or any other operation can be performed.
- Wait Time: This is the number of blocks the system will wait while voting.
- Gas Price: The value of gas price if you want to set manually. If you don't provide any value or simply keep it to 1, the razor client will automatically calculate the optimum gas price and send it.
- Log Level: Normally debug logs are not logged into the log file. But if you want you can set
logLeveltodebugand fetch the debug logs. - Gas Limit: The value with which the gas limit will be multiplied while sending every transaction.
The config is set while the build is generated, but if you need to change any of the above parameter, you can use the setConfig command.
razor cli
$ ./razor setConfig --provider <rpc_provider> --chainId <chain_id> --gasmultiplier <multiplier_value> --buffer <buffer_percentage> --wait <wait_for_n_blocks> --gasprice <gas_price> --logLevel <debug_or_info> --gasLimit <gas_limit_multiplier>docker
docker exec -it razor-go razor setConfig --provider <rpc_provider> --chainId <chain_id> --gasmultiplier <multiplier_value> --buffer <buffer_percentage> --wait <wait_for_n_blocks> --gasprice <gas_price> --logLevel <debug_or_info> --gasLimit <gas_limit_multiplier>Example:
$ ./razor setConfig --provider https://infura/v3/matic --chainId 80001 --gasmultiplier 1.5 --buffer 20 --wait 70 --gasprice 1 --logLevel debug --gasLimit 0.8Other than setting these parameters in the config, you can use different values of these parameters in different command. Just add the same flag to any command you want to use and the new config changes will appear for that command.
Example:
$ ./razor vote --address 0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c --gasprice 10This will cause this particular vote command to run with a gas price of 10.
Razor commands
Create Account
Create an account using the create command. You'll be asked to enter a password that'll be used to encrypt the keystore file.
razor cli
$ ./razor createDocker
docker exec -it razor-go razor createExample:
$ ./razor create
Password:Import Account
If you already have an account created, and have it's private key, that account can be imported into the razor-go client.
To do that, you can use the import command. You'll be asked the private key first and then the password which you want to encrypt your keystore file with.
razor cli
$ ./razor importdocker
docker exec -it razor-go razor importExample:
$ ./razor import
š Private Key:
Password:Before staking on Razor Network, please ensure your account has eth and RAZOR. For testnet RAZOR, please contact us on Discord.
Stake
If you have a minimum of 1000 razors in your account, you can stake those using the addStake command.
razor cli
$ ./razor addStake --address <address> --value <value>docker
docker exec -it razor-go razor addStake --address <address> --value <value>Example:
$ ./razor addStake --address 0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c --value 1000Note: --pow flag is used to stake floating number stake
Note: Formula for calculating pow: (value * (1018)) / (10x) where x is no of decimal places and value is integer
The value of pow is : 18 - x here
If you have a 1000.25 razors in your account, you can stake those using the stake command with pow flag.
Example:
$ razor addStake --address 0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c --value 100025 --pow 16If you have a 5678.1001 razors in your account, you can stake those using the stake command with pow flag.
If you have a 5678.1001 razors in your account, you can stake those using the stake command with pow flag.
Example:
$ ./razor addStake --address 0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c --value 56781001 --pow 14Staker Info
If you want to know the details of a staker, you can use stakerInfo command.
razor cli
$ ./razor stakerInfo --stakerId <staker_id_of_the_staker>docker
docker exec -it razor-go razor stakerInfo --stakerId <staker_id_of_the_staker>Example:
$ ./razor stakerInfo --stakerId 2Set Delegation
If you are a staker you can accept delegation from delegators and charge a commission from them.
razor cli
$ ./razor setDelegation --address <address> --status <true_or_false> --commission <commission_percent>docker
docker exec -it razor-go razor setDelegation --address <address> --status <true_or_false> --commission <commission_percent>Example:
$ ./razor setDelegation --address 0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c --status true -c 20Update Commission
If you are a staker and have accepted delegation, you can define your commission rate using this command.
razor cli
$ ./razor updateCommission --address <address> --commission <commission_percent>docker
docker exec -it razor-go razor updateCommission --address <address> --commission <commission_percent>Example:
$ ./razor updateCommission --address 0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c --commission 10Delegate
If you want to become a delegator use the delegate command. The staker whose staker_id is provided, their stake is increased.
razor cli
$ ./razor delegate --address <address> --value <value> --pow <power> --stakerId <staker_id>docker
docker exec -it razor-go razor delegate --address <address> --value <value> --pow <power> --stakerId <staker_id>Example:
$ ./razor delegate --address 0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c --value 1000 --pow 10 --stakerId 1Claim Commission
Staker can claim the rewards earned from delegator's pool share as commission using claimCommission
razor cli
$ ./razor claimCommission --address <address> docker
docker exec -it razor-go razor claimCommission --address <address> Example:
$ ./razor claimCommission --address 0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c Vote
You can start voting once you've staked some razors
razor cli
$ ./razor vote --address <address>docker
docker exec -it razor-go razor vote --address <address>run vote command in background
docker exec -it -d razor-go razor vote --address <address> --password /root/.razor/<file_name>NOTE: To run command with password flag, password file should present in $HOME/.razor/ directory
Example:
$ ./razor vote --address 0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4cIf you want to claim your bounty automatically after disputing staker, you can just pass --autoClaimBounty flag in your vote command.
If you want to report incorrect values, there is a rogue mode available. Just pass an extra flag --rogue to start voting in rogue mode and the client will report wrong medians.
The rogueMode key can be used to specify in which particular voting state (commit, reveal) or for which values i.e. medians/revealedIds (medians, missingIds, extraIds, unsortedIds)you want to report incorrect values.
Example:
$ ./razor vote --address 0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c --rogue --rogueMode commit,reveal,medians,missingIds,extraIds,unsortedIdsUnstake
If you wish to unstake your funds, you can run the unstake command.
razor cli
$ ./razor unstake --address <address> --stakerId <staker_id> --value <value> --pow <power>docker
docker exec -it razor-go razor unstake --address <address> --stakerId <staker_id> --value <value> --pow <power>Example:
$ ./razor unstake --address 0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c --stakerId 1 --amount --pow 10 1000Withdraw
Once unstake has been called, you can withdraw your funds using the initiateWithdraw and unlockWithdraw commands
You need to start the withdrawal process using initiateWithdraw command and once the withdraw lock period is over you can use unlockWithdraw command to get the RZR's back to your account.
razor cli
$ ./razor initiateWithdraw --address <address> --stakerId <staker_id>$ ./razor unlockWithdraw --address <address> --stakerId <staker_id>docker
docker exec -it razor-go razor initiateWithdraw --address <address> --stakerId <staker_id>docker exec -it razor-go razor unlockWithdraw --address <address> --stakerId <staker_id>Example:
$ ./razor initiateWithdraw --address 0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c --stakerId 1$ ./razor unlockWithdraw --address 0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c --stakerId 1Extend Lock
If the withdrawal period is over, then extendLock can be called to extend the lock period.
razor cli
$ ./razor extendLock --address <address> --stakerId <staker_id>docker
docker exec -it razor-go razor extendLock --address <address> --stakerId <staker_id>Example:
$ ./razor extendLock --address 0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c --stakerId 1Claim Bounty
If you want to claim your bounty after disputing a rogue staker, you can run claimBounty command
NOTE: bountyIds are stored in .razor directory with file name in format
YOUR_ADDRESS_disputeData.json file.e.g:
0x2EDc3c6F93e4e20590F480272AB490D2620557xY_disputeData.json
If you know the bountyId, you can pass the value to bountyId flag.
razor cli
$ ./razor claimBounty --address <address> --bountyId <bounty_id>docker
docker exec -it razor-go razor claimBounty --address <address> --bountyId <bounty_id>Example:
$ ./razor claimBounty --address 0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c --bountyId 5You can also run claimBounty command without passing bountyId flag as it will pick up bountyIds associated to your address from the file one at a time.
razor cli
$ ./razor claimBounty --address <address> docker
docker exec -it razor-go razor claimBounty --address <address> Transfer
Transfers razor to other accounts.
razor cli
$ ./razor transfer --value <value> --to <transfer_to_address> --from <transfer_from_address>docker
docker exec -it razor-go razor transfer --value <value> --to <transfer_to_address> --from <transfer_from_address>Example:
$ ./razor transfer --value 100 --to 0x91b1E6488307450f4c0442a1c35Bc314A505293e --from 0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4cCreate Job
Create new jobs using creteJob command.
Note: This command is restricted to "Admin Role"
razor cli
$ ./razor createJob --url <URL> --selector <selector_in_json_or_XHTML_selector_format> --selectorType <0_for_XHTML_or_1_for_JSON> --name <name> --address <address> --power <power> --weight <weight>docker
docker exec -it razor-go razor createJob --url <URL> --selector <selector_in_json_or_XHTML_selector_format> --selectorType <0_for_XHTML_or_1_for_JSON> --name <name> --address <address> --power <power> --weight <weight>Example:
$ ./razor createJob --url https://www.alphavantage.co/query\?function\=GLOBAL_QUOTE\&symbol\=MSFT\&apikey\=demo --selector '[`Global Quote`][`05. price`]" --selectorType 1 --name msft --power 2 --address 0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c --weight 32OR
$ ./razor createJob --address 0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c -n btc_gecko --power 2 -s 'table tbody tr td span[data-coin-id="1"][data-target="price.price"] span' -u https://www.coingecko.com/en --selectorType 0 --weight 100Create Collection
Create new collections using creteCollection command.
Note: This command is restricted to "Admin Role"
razor cli
$ ./razor createCollection --name <collection_name> --address <address> --jobIds <list_of_job_ids> --aggregation <aggregation_method> --power <power> --tolerance <tolerance>docker
docker exec -it razor-go razor createCollection --name <collection_name> --address <address> --jobIds <list_of_job_ids> --aggregation <aggregation_method> --power <power> --tolerance <tolerance>Example:
$ ./razor createCollection --name btcCollectionMean --address 0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c --jobIds 1,2 --aggregation 2 --power 2 --tolerance 200Modify Collection Status
Modify the active status of an collection using the modifyCollectionStatus command.
Note: This command is restricted to "Admin Role"
razor cli
$ ./razor modifyCollectionStatus --collectionId <collectionId> --address <address> --status <true_or_false>docker
docker exec -it razor-go razor modifyCollectionStatus --collectionId <collectionId> --address <address> --status <true_or_false>Example:
$ ./razor modifyCollectionStatus --collectionId 1 --address 0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c --status falseUpdate Collection
Update the collection using updateCollection command.
Note: This command is restricted to "Admin Role"
razor cli
$ ./razor updateCollection --collectionId <collection_id> --jobIds <list_of_jobs> --address <address> --aggregation <aggregation_method> --power <power> --tolerance <tolerance>docker
docker exec -it razor-go razor updateCollection --collectionId <collection_id> --jobIds <list_of_jobs> --address <address> --aggregation <aggregation_method> --power <power> --tolerance <tolerance>Example:
$ ./razor updateCollection -a 0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c --collectionId 3 --jobIds 1,3 --aggregation 2 --power 4 --tolerance 5Update Job
Update the existing parameters of the Job using updateJob command.
Note: This command is restricted to "Admin Role"
razor cli
./razor updateJob --address <address> --jobID <job_Id> -s <selector> --selectorType <selectorType> -u <job_url> --power <power> --weight <weight>docker
docker exec -it razor-go razor updateJob --address <address> --jobID <job_Id> -s <selector> --selectorType <selectorType> -u <job_url> --power <power> --weight <weight>Example:
$ ./razor updateJob -a 0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c --jobId 1 -s last -u https://api.gemini.com/v1/pubticker/btcusd --power 2 --weight 10Job details
Get the list of all jobs with the details like weight, power, Id etc.
Example:
razor cli
$ ./razor jobListdocker
docker exec -it razor-go razor jobListCollection details
Get the list of all collections with the details like power, Id, name etc.
Example:
razor cli
$ ./razor collectionListdocker
docker exec -it razor-go razorcollectionListNote : All the commands have an additional --password flag that you can provide with the file path from which password must be picked.
Expose Metrics
Expose Prometheus-based metrics for monitoring
Example:
razor cli
$ ./razor setConfig --exposeMetrics 2112docker
# Create docker network
docker network create razor_network
# Expose Metrics
docker exec -it razor-go razor setConfig --exposeMetrics 2112Override Job and Adding Your Custom Jobs
Jobs URLs are a placeholder from where to fetch values from. There is a chance that these URLs might either fail, or get razor nodes blacklisted, etc.
You can override the existing job and also add your custom jobs by adding assets.json file in .razor directory so that razor-nodes can fetch data directly from the provided jobs.
Shown below is an example of how your assets.json file should be -
{
"assets": {
"collection": {
"ethCollectionMean": {
"power": 2,
"official jobs": {
"1": {
"URL": "https://data.messari.io/api/v1/assets/eth/metrics",
"selector": "[`data`][`market_data`][`price_usd`]",
"power": 2,
"weight": 2
},
},
"custom jobs": [
{
"URL": "https://api.lunarcrush.com/v2?data=assets&symbol=ETH",
"selector": "[`data`][`0`][`price`]",
"power": 3,
"weight": 2
},
]
}
}
}
}Breaking down into components
- The existing jobs that you want to override should be included in
official jobsand fields like URL, selector should be replaced with your provided inputs respectively.
In the above example for the collection ethCollectionMean, job having jobId:1 is override by provided URL, selector, power and weight.
"official jobs": {
"1": {
"URL": "https://data.messari.io/api/v1/assets/eth/metrics",
"selector": "[`data`][`market_data`][`price_usd`]",
"power": 2,
"weight": 2
},- Additional jobs that you want to add to a collection should be added in
custom jobsfield with their respective URLs and selectors.
In the above example for the collection ethCollectionMean, new custom job having URL https://api.lunarcrush.com/v2?data=assets&symbol=ETH is added.
"custom jobs": [
{
"URL": "https://api.lunarcrush.com/v2?data=assets&symbol=ETH",
"selector": "[`data`][`0`][`price`]",
"power": 3,
"weight": 2
},
]Logs
User can pass a separate flag --logFile followed with any name for log file along with command. The logs will be stored in .razor directory.
razor cli
$ ./razor addStake --address <address> --value <value> --logFile stakingLogsdocker
docker exec -it razor-go razo addStake --address <address> --value <value> --logFile stakingLogsThe logs for above command will be stored at "home/.razor/stakingLogs.log" path
razor cli
$ ./razor delegate --address <address> --value <value> --pow <power> --stakerId <staker_id> --logFile delegationLogsdocker
docker exec -it razor-go razo delegate --address <address> --value <value> --pow <power> --stakerId <staker_id> --logFile delegationLogsThe logs for above command will be stored at "home/.razor/delegationLogs.log" path
Note: If the user runs multiple commands with the same log file name all the logs will be appended in the same log file.
Contract Addresses
This command provides the list of contract addresses.
razor cli
$ ./razor contractAddressesdocker
docker exec -it razor-go razor contractAddressesExample:
$ ./razor contractAddressesSetting up razor-go and commands using docker-compose
- Must have
dockeranddocker-composeinstalled - Building the source
docker-compose build Create razor.yaml at $HOME/.razor/
vi $HOME/.razor/razor.yamlAdd in razor.yaml and use :wq to exit form editor
buffer: 20 gaslimit: 2 gasmultiplier: 1 gasprice: 0 provider: <rpc-url> chainId: 80001 wait: 30Create account , and note address.
docker-compose run razor-go /usr /local/bin/razor createImport account
docker-compose run razor-go /usr/local/bin/razor importGet some RAZOR and MATIC token (or Token of respective RPC) to this address
Start Staking
#Provide password through CLI docker-compose run razor-go /usr/local/bin/razor addStake --address <address> --value 50000 #Provide password through File #Create file and put password string vi ~/.razor/pass #Start Staking docker-compose run razor-go /usr/local/bin/razor addStake --address <address> --value 50000 --password /root/.razor/passTo Start Voting,
- Provide password through CLI
# Run process in foreground and provide password through cli docker-compose run razor-go /usr/local/bin/razor vote --address <address> # Run process in background and provide password through file docker-compose run -d razor-go /usr/local/bin/razor vote --address <address> --password /root/.razor/pass- Provide password through File and run in background with compose up
- replace in docker-compose.yml with your address and create file pass and add your password in file
docker-compose up -dEnable Delegation
#Provide password with cli docker-compose run razor-go /usr/local/bin/razor setDelegation --address <address> --status true --commission 10 #provide password through file docker-compose run razor-go /usr/local/bin/razor setDelegation --address <address> --status true --commission 10 --password /root/.razor/pass
Contribute to razor-go
We would really appreciate your contribution. To see our contribution guideline