Giter Club home page Giter Club logo

peggo's Introduction

Injective's Peggo Peggy.sol MythX

Peggo is a Go implementation of the Peggy Orchestrator for the Injective Chain.

Important Commands:

  • peggo orchestrator starts the orchestrator main loop.
  • peggo tx register-eth-key is a special command to submit an Ethereum key that will be used to sign messages on behalf of your Validator

Installation

Get yourself Go 1.15+ at https://golang.org/dl/ first, then:

$ go get github.com/InjectiveLabs/peggo/orchestrator/cmd/...

peggo

Peggo is a companion executable for orchestrating a Peggy validator.

Configuration

Use CLI args, flags or create .env with environment variables

Usage

$ peggo --help

Usage: peggo [OPTIONS] COMMAND [arg...]

Peggo is a companion executable for orchestrating a Peggy validator.

Options:
  -e, --env                The environment name this app runs in. Used for metrics and error reporting. (env $PEGGO_ENV) (default "local")
  -l, --log-level          Available levels: error, warn, info, debug. (env $PEGGO_LOG_LEVEL) (default "info")
      --svc-wait-timeout   Standard wait timeout for external services (e.g. Cosmos daemon GRPC connection) (env $PEGGO_SERVICE_WAIT_TIMEOUT) (default "1m")

Commands:
  orchestrator             Starts the orchestrator main loop.
  q, query                 Query commands that can get state info from Peggy.
  tx                       Transactions for Peggy governance and maintenance.
  version                  Print the version information and exit.

Run 'peggo COMMAND --help' for more information on a command.      

Commands

peggo orchestrator

$ peggo orchestrator -h

Usage: peggo orchestrator [OPTIONS]

Starts the orchestrator main loop.

Options:
      --cosmos-chain-id                  Specify Chain ID of the Cosmos network. (env $PEGGO_COSMOS_CHAIN_ID) (default "888")
      --cosmos-grpc                      Cosmos GRPC querying endpoint (env $PEGGO_COSMOS_GRPC) (default "tcp://localhost:9900")
      --tendermint-rpc                   Tendermint RPC endpoint (env $PEGGO_TENDERMINT_RPC) (default "http://localhost:26657")
      --cosmos-gas-prices                Specify Cosmos chain transaction fees as DecCoins gas prices (env $PEGGO_COSMOS_GAS_PRICES)
      --cosmos-keyring                   Specify Cosmos keyring backend (os|file|kwallet|pass|test) (env $PEGGO_COSMOS_KEYRING) (default "file")
      --cosmos-keyring-dir               Specify Cosmos keyring dir, if using file keyring. (env $PEGGO_COSMOS_KEYRING_DIR)
      --cosmos-keyring-app               Specify Cosmos keyring app name. (env $PEGGO_COSMOS_KEYRING_APP) (default "peggo")
      --cosmos-from                      Specify the Cosmos validator key name or address. If specified, must exist in keyring, ledger or match the privkey. (env $PEGGO_COSMOS_FROM)
      --cosmos-from-passphrase           Specify keyring passphrase, otherwise Stdin will be used. (env $PEGGO_COSMOS_FROM_PASSPHRASE) (default "peggo")
      --cosmos-pk                        Provide a raw Cosmos account private key of the validator in hex. USE FOR TESTING ONLY! (env $PEGGO_COSMOS_PK)
      --cosmos-use-ledger                Use the Cosmos app on hardware ledger to sign transactions. (env $PEGGO_COSMOS_USE_LEDGER)
      --eth-chain-id                     Specify Chain ID of the Ethereum network. (env $PEGGO_ETH_CHAIN_ID) (default 42)
      --eth-node-http                    Specify HTTP endpoint for an Ethereum node. (env $PEGGO_ETH_RPC) (default "http://localhost:1317")
      --eth-node-alchemy-ws              Specify websocket url for an Alchemy ethereum node. (env $PEGGO_ETH_ALCHEMY_WS)
      --eth_gas_price_adjustment         gas price adjustment for Ethereum transactions (env $PEGGO_ETH_GAS_PRICE_ADJUSTMENT) (default 1.3)
      --eth-keystore-dir                 Specify Ethereum keystore dir (Geth-format) prefix. (env $PEGGO_ETH_KEYSTORE_DIR)
      --eth-from                         Specify the from address. If specified, must exist in keystore, ledger or match the privkey. (env $PEGGO_ETH_FROM)
      --eth-passphrase                   Passphrase to unlock the private key from armor, if empty then stdin is used. (env $PEGGO_ETH_PASSPHRASE)
      --eth-pk                           Provide a raw Ethereum private key of the validator in hex. USE FOR TESTING ONLY! (env $PEGGO_ETH_PK)
      --eth-use-ledger                   Use the Ethereum app on hardware ledger to sign transactions. (env $PEGGO_ETH_USE_LEDGER)
      --relay_valsets                    If enabled, relayer will relay valsets to ethereum (env $PEGGO_RELAY_VALSETS)
      --relay_valset_offset_dur          If set, relayer will broadcast valsetUpdate only after relayValsetOffsetDur has passed from time of valsetUpdate creation (env $PEGGO_RELAY_VALSET_OFFSET_DUR) (default "5m")
      --relay_batches                    If enabled, relayer will relay batches to ethereum (env $PEGGO_RELAY_BATCHES)
      --relay_batch_offset_dur           If set, relayer will broadcast batches only after relayBatchOffsetDur has passed from time of batch creation (env $PEGGO_RELAY_BATCH_OFFSET_DUR) (default "5m")
      --relay_pending_tx_wait_duration   If set, relayer will broadcast pending batches/valsetupdate only after pendingTxWaitDuration has passed (env $PEGGO_RELAY_PENDING_TX_WAIT_DURATION) (default "20m")
      --min_batch_fee_usd                If set, batch request will create batches only if fee threshold exceeds (env $PEGGO_MIN_BATCH_FEE_USD) (default 23.3)
      --coingecko_api                    Specify HTTP endpoint for coingecko api. (env $PEGGO_COINGECKO_API) (default "https://api.coingecko.com/api/v3")

peggo tx register-eth-key

 peggo tx register-eth-key --help

Usage: peggo tx register-eth-key [OPTIONS]

Submits an Ethereum key that will be used to sign messages on behalf of your Validator

Options:
      --cosmos-chain-id          Specify Chain ID of the Cosmos network. (env $PEGGO_COSMOS_CHAIN_ID) (default "888")
      --cosmos-grpc              Cosmos GRPC querying endpoint (env $PEGGO_COSMOS_GRPC) (default "tcp://localhost:9900")
      --tendermint-rpc           Tendermint RPC endpoint (env $PEGGO_TENDERMINT_RPC) (default "http://localhost:26657")
      --cosmos-gas-prices        Specify Cosmos chain transaction fees as DecCoins gas prices (env $PEGGO_COSMOS_GAS_PRICES)
      --cosmos-keyring           Specify Cosmos keyring backend (os|file|kwallet|pass|test) (env $PEGGO_COSMOS_KEYRING) (default "file")
      --cosmos-keyring-dir       Specify Cosmos keyring dir, if using file keyring. (env $PEGGO_COSMOS_KEYRING_DIR)
      --cosmos-keyring-app       Specify Cosmos keyring app name. (env $PEGGO_COSMOS_KEYRING_APP) (default "peggo")
      --cosmos-from              Specify the Cosmos validator key name or address. If specified, must exist in keyring, ledger or match the privkey. (env $PEGGO_COSMOS_FROM)
      --cosmos-from-passphrase   Specify keyring passphrase, otherwise Stdin will be used. (env $PEGGO_COSMOS_FROM_PASSPHRASE) (default "peggo")
      --cosmos-pk                Provide a raw Cosmos account private key of the validator in hex. USE FOR TESTING ONLY! (env $PEGGO_COSMOS_PK)
      --cosmos-use-ledger        Use the Cosmos app on hardware ledger to sign transactions. (env $PEGGO_COSMOS_USE_LEDGER)
      --eth-keystore-dir         Specify Ethereum keystore dir (Geth-format) prefix. (env $PEGGO_ETH_KEYSTORE_DIR)
      --eth-from                 Specify the from address. If specified, must exist in keystore, ledger or match the privkey. (env $PEGGO_ETH_FROM)
      --eth-passphrase           Passphrase to unlock the private key from armor, if empty then stdin is used. (env $PEGGO_ETH_PASSPHRASE)
      --eth-pk                   Provide a raw Ethereum private key of the validator in hex. USE FOR TESTING ONLY! (env $PEGGO_ETH_PK)
      --eth-use-ledger           Use the Ethereum app on hardware ledger to sign transactions. (env $PEGGO_ETH_USE_LEDGER)
  -y, --yes                      Always auto-confirm actions, such as transaction sending. (env $PEGGO_ALWAYS_AUTO_CONFIRM)

License

Apache 2.0

peggo's People

Contributors

achilleas-kal avatar albertchon avatar albttx avatar davidtian90 avatar dbrajovic avatar facundomedica avatar gorgos avatar mankenavenkatesh avatar mistmorn0 avatar nhannamsiu avatar nmarcetic avatar ri-go avatar smartdev-125 avatar thomasralee avatar vinhphuctadang avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

peggo's Issues

Move some of the key parameters to env vars or config file

Following hardcoded settings increase Ethereum-based events detection on environments like our devnet to anything between a couple of minutes to 20 minutes, which makes it unfeasable for testing and test automation. Let's move them to env vars or a config file.

Settings in question:

  • main_loop.go -> const defaultLoopDur
  • orchestrator/eth_event_watcher.go -> const defaultBlocksToSearch

Add metrics

It's important to have monitoring and observability for peggo.

We should:

  • setup proper metrics configuration
  • add metrics hooks everywhere
  • create a peggo Grafana dashboard
  • deploy updated code on Mainnet/Testnet/Devnet

Check Coingecko prices separately from BatchRequesterLoop

In the current BatchRequesterLoop, if the Coingecko API is down AND orchestrators have a non-zero minFeeInUSD, then no batches will be requested aka no withdrawals back to Ethereum will occur.

// send batch request only if fee threshold is met.
if s.CheckFeeThreshod(tokenAddr, unbatchedToken.TotalFees, s.minBatchFeeUSD) {
logger.WithFields(log.Fields{"tokenContract": tokenAddr, "denom": denom}).Infoln("sending batch request")
_ = s.peggyBroadcastClient.SendRequestBatch(ctx, denom)
}

func (s *peggyOrchestrator) CheckFeeThreshod(erc20Contract common.Address, totalFee cosmtypes.Int, minFeeInUSD float64) bool {
if minFeeInUSD == 0 {
return true
}
tokenPriceInUSD, err := s.priceFeeder.QueryUSDPrice(erc20Contract)
if err != nil {
return false
}

Empirically I've noticed the Coingecko public API can be a bit flaky sometimes (at least in the trading bot's usage) so we shouldn't depend on it to function in order to process withdrawals. It's nice that we have retries currently at least but ideally, we should make this flow independent of whether Coingecko works or not, as it's entirely plausible that their API goes down for a day.

I propose the following change:

  • add a separate goroutine that periodically checks Coingecko prices in the background (e.g. once per hour) and updates it in a coingeckoPrices map[common.Address]float64 defined on the peggyOrchestrator struct. This will keep a reasonably up to date mapping of the prices from Coingecko. The denoms for which this should be fetched are for any ERC-20 denom in the bank supply
  • Change the CheckFeeThreshold function to return the price from coingeckoPrices if the s.priceFeeder.QueryUSDPrice returns an error. So
	tokenPriceInUSD, err := s.priceFeeder.QueryUSDPrice(erc20Contract)
	if err != nil {
	        price, ok := s.coingeckoPrices[erc20Contract]
	        if ok {
	            tokenPriceInUSD = price
	        } else {
                    return false
	        }
	}

Note: currently this isn't an issue since we're running the orchestrators with a 0 minFeeInUSD setting but in the future we should change this in order to increase the economic robustness of the bridge.

Peggos orchestrator --cosmos-from-passphrase option is not working as expected

In the current implementation of peggo orchestrator executable, when I start the peggo orchestrator and pass the cosmos passphrase via cli using --cosmos-from-passphrase option, it still prompts for keyring passphrase. It works as expected if I set the param in .env file and then start the peggo orchestrator. The peggo orchestrator starts without any further prompts.

I've tried a couple of troubleshooting steps as advised in discord which includes passing cosmos-keyring-dir , cosmos-from, cosmos-from-passphrase option but it didn't work.

I'm running the validator on an Amazon Linux 2 instance. Also see below the current binary version

sh-4.2$ peggo version
Version dev (c0cb909)
Compiled at 20220220-1014 using Go go1.17.6 (amd64)

sh-4.2$ injectived version
Version dev (30b3dbf)
Compiled at 20220220-1014 using Go go1.17.6 (amd64)

Create Peggy Subgraph

The current bridge UI is rather simple and does not provide users any visual indication of the progress of one's transfers.

We can use The Graph as a general purpose backend API for use by client-facing services as well as internal monitoring/alerting.

injective-station

The station (and possibly also DEX) can use this API to show historical cross-chain deposits/withdrawals as well as real-time estimates for pending deposits.

  • obtaining historical ERC-20 deposits from Ethereum -> Injective (by scanning SendToCosmosEvent)
  • obtaining a historical ERC-20 withdrawals from Injective -> Ethereum (by using CallHandlers on the submitBatch)

internal monitoring

Although this won't be used by any mission critical services, having this nice GraphQL API can easily allow us to make sure Peggy is functioning properly. With this API, we can create monitoring bots or even a future analytics site which uses this API as well.

  • tracking the last updated Validator set & powers (also by using CallHandlers on the updateValset function)
  • tracking all of the Deployed ERC-20's (by scanning ERC20DeployedEvent)
  • tracking the up-to-date state variables for convenience

Implementation Checklist

  • Define GraphQL Schema
  • Implement event and call handler mappings
  • Deploy on The Graph's hosted Ethereum Subgraph service

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.