From 2e92672f496a40d7b8ab2b05f8da0a1a602648a3 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 26 Sep 2022 16:34:27 -0500 Subject: [PATCH 1/9] chore: modify eth block delay (#367) (#368) * chore: modify eth block delay * chore: modify eth block delay * fix test * fix test * changelog * changelog (cherry picked from commit 86ac6c45b06140ee144b7abc6a1420f878250518) Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com> --- CHANGELOG.md | 1 + orchestrator/main_loops.go | 11 +++++++---- orchestrator/main_loops_test.go | 4 ++-- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a1997238..50ab94ce 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -45,6 +45,7 @@ Ref: https://keepachangelog.com/en/1.0.0/ ### Improvements +[#367] Set ETH block delay to 96 blocks [#362](https://github.com/umee-network/peggo/pull/362) Update umeed to v3. [#343](https://github.com/umee-network/peggo/pull/343) Upgrade to cosmos-sdk v0.46.1. [#341](https://github.com/umee-network/peggo/pull/341) Fix linter. diff --git a/orchestrator/main_loops.go b/orchestrator/main_loops.go index e24fe87c..8c24e2a6 100644 --- a/orchestrator/main_loops.go +++ b/orchestrator/main_loops.go @@ -501,9 +501,12 @@ func (p *gravityOrchestrator) ERC20ToDenom(ctx context.Context, tokenAddr ethcmn // mechanism to prevent relaying an event that is not yet considered final. func getEthBlockDelay(chainID uint64) uint64 { switch chainID { - // Mainline Ethereum, Ethereum classic, or the Ropsten, Kotti, Mordor testnets - // all POW Chains - case 1, 3, 6, 7: + // Mainline Ethereum + case 1: + return 96 + + // Ethereum classic, or the Ropsten, Kotti, Mordor testnets all POW Chains + case 3, 6, 7: return 13 // Dev, our own Gravity Ethereum testnet, and Hardhat respectively @@ -519,6 +522,6 @@ func getEthBlockDelay(chainID uint64) uint64 { // assume the safe option (POW) where we don't know default: - return 13 + return 96 } } diff --git a/orchestrator/main_loops_test.go b/orchestrator/main_loops_test.go index 0d6e2353..754d973d 100644 --- a/orchestrator/main_loops_test.go +++ b/orchestrator/main_loops_test.go @@ -55,8 +55,8 @@ func TestERC20ToDenom(t *testing.T) { } func TestGetEthBlockDelay(t *testing.T) { - assert.Equal(t, uint64(13), getEthBlockDelay(1)) + assert.Equal(t, uint64(96), getEthBlockDelay(1)) assert.Equal(t, uint64(0), getEthBlockDelay(2018)) assert.Equal(t, uint64(10), getEthBlockDelay(5)) - assert.Equal(t, uint64(13), getEthBlockDelay(1235)) + assert.Equal(t, uint64(96), getEthBlockDelay(1235)) } From e086b3a2f0d005b222a44fa5a1e57c42fbe97ce2 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 26 Sep 2022 17:05:21 -0500 Subject: [PATCH 2/9] feat: reduce oracle noise msgs (#365) (#369) * update test scripts * reduce noise messages of pf * add more providers to default * add workflow for v1.0.x * fix branch name (cherry picked from commit 13fb428b9348590bb6f8ed05e16b4ce4185dce09) Co-authored-by: Rafael Tenfen Co-authored-by: Facundo Medica <14063057+facundomedica@users.noreply.github.com> --- .mergify.yml | 9 +++++++++ cmd/peggo/orchestrator.go | 24 +++++++++++++++++++---- orchestrator/oracle/oracle.go | 12 ++++++++++-- test/cosmos/multinode.sh | 2 +- test/eth/run_ganache.sh | 10 ++++++---- test/scripts/valset_update_2000_blocks.sh | 11 +++++++---- 6 files changed, 53 insertions(+), 15 deletions(-) diff --git a/.mergify.yml b/.mergify.yml index 900c3315..9d79ccb5 100644 --- a/.mergify.yml +++ b/.mergify.yml @@ -53,3 +53,12 @@ pull_request_rules: backport: branches: - release/v0.4.x + + - name: Backport patches to release/v1.0.x branch + conditions: + - base=main + - label=S:backport/v1.0.x + actions: + backport: + branches: + - release/v1.x.x diff --git a/cmd/peggo/orchestrator.go b/cmd/peggo/orchestrator.go index c51e7e77..47741992 100644 --- a/cmd/peggo/orchestrator.go +++ b/cmd/peggo/orchestrator.go @@ -276,10 +276,26 @@ func getOrchestratorCmd() *cobra.Command { cmd.Flags().Bool(flagRelayBatches, false, "Relay transaction batches to Ethereum") cmd.Flags().Int64(flagEthBlocksPerLoop, 2000, "Number of Ethereum blocks to process per orchestrator loop") cmd.Flags().String(flagCoinGeckoAPI, "https://api.coingecko.com/api/v3", "Specify the coingecko API endpoint") - //nolint: lll - cmd.Flags().StringSlice(flagOracleProviders, []string{string(umeepfprovider.ProviderBinance), string(umeepfprovider.ProviderKraken)}, - fmt.Sprintf("Specify the providers to use in the oracle, options \"%s\"", strings.Join([]string{string(umeepfprovider.ProviderBinance), string(umeepfprovider.ProviderHuobi), - string(umeepfprovider.ProviderKraken), string(umeepfprovider.ProviderGate), string(umeepfprovider.ProviderOkx), string(umeepfprovider.ProviderOsmosis)}, ","))) + + defaultProviders := []string{ + umeepfprovider.ProviderOsmosis.String(), + umeepfprovider.ProviderHuobi.String(), + umeepfprovider.ProviderOkx.String(), + umeepfprovider.ProviderCoinbase.String(), + umeepfprovider.ProviderBinance.String(), + umeepfprovider.ProviderBitget.String(), + umeepfprovider.ProviderMexc.String(), + } + + allProviders := append([]string{ + umeepfprovider.ProviderKraken.String(), + umeepfprovider.ProviderGate.String(), + umeepfprovider.ProviderFTX.String(), + umeepfprovider.ProviderMock.String(), + }, defaultProviders...) + + cmd.Flags().StringSlice(flagOracleProviders, defaultProviders, + fmt.Sprintf("Specify the providers to use in the oracle, options \"%s\"", strings.Join(allProviders, ","))) cmd.Flags().Duration(flagEthPendingTXWait, 20*time.Minute, "Time for a pending tx to be considered stale") cmd.Flags().String(flagEthAlchemyWS, "", "Specify the Alchemy websocket endpoint") cmd.Flags().Float64(flagProfitMultiplier, 1.0, "Multiplier to apply to relayer profit") diff --git a/orchestrator/oracle/oracle.go b/orchestrator/oracle/oracle.go index 6f2dcebc..5d397a55 100644 --- a/orchestrator/oracle/oracle.go +++ b/orchestrator/oracle/oracle.go @@ -6,6 +6,7 @@ import ( "sync" "time" + sdkmath "cosmossdk.io/math" sdk "github.com/cosmos/cosmos-sdk/types" "github.com/rs/zerolog" "golang.org/x/sync/errgroup" @@ -14,6 +15,7 @@ import ( pfprovider "github.com/umee-network/umee/price-feeder/oracle/provider" pftypes "github.com/umee-network/umee/price-feeder/oracle/types" pfsync "github.com/umee-network/umee/price-feeder/pkg/sync" + umeeparams "github.com/umee-network/umee/v3/app/params" ) const ( @@ -273,7 +275,8 @@ func (o *Oracle) setPrices() error { if tickerErr != nil && candleErr != nil { // only generates error if ticker and candle generate errors - return fmt.Errorf("ticker error: %+v\ncandle error: %+v", tickerErr, candleErr) + o.logger.Debug().Msgf("provider: %s ticker error: %+v\ncandle error: %+v", providerName, tickerErr, candleErr) + return nil } // flatten and collect prices based on the base currency per provider @@ -300,12 +303,17 @@ func (o *Oracle) setPrices() error { o.logger.Debug().Err(err).Msg("failed to get ticker prices from provider") } + deviationTreshold := sdk.NewDecFromIntWithPrec(sdkmath.NewInt(15), 1) + computedPrices, err := pforacle.GetComputedPrices( o.logger, providerCandles, providerPrices, o.providerSubscribedPairs, - make(map[string]sdk.Dec, 0), // uses default deviation + map[string]sdk.Dec{ + SymbolETH: deviationTreshold, + umeeparams.BondDenom: deviationTreshold, + }, // uses default deviation for other bases ) if err != nil { return err diff --git a/test/cosmos/multinode.sh b/test/cosmos/multinode.sh index 162dc183..3d1637d7 100755 --- a/test/cosmos/multinode.sh +++ b/test/cosmos/multinode.sh @@ -239,7 +239,7 @@ fi # data dir check # Start the instances echo "Starting nodes..." -$NODE_BIN $home0 start --api.enable true --grpc.address="0.0.0.0:9090" --grpc-web.enable=false --log_level $LOG_LEVEL > $hdir.n0.log 2>&1 & +$NODE_BIN $home0 start --grpc.address="0.0.0.0:9090" --grpc-web.enable=false --log_level $LOG_LEVEL > $hdir.n0.log 2>&1 & $NODE_BIN $home1 start --grpc.address="0.0.0.0:9091" --grpc-web.enable=false --log_level $LOG_LEVEL > $hdir.n1.log 2>&1 & $NODE_BIN $home2 start --grpc.address="0.0.0.0:9092" --grpc-web.enable=false --log_level $LOG_LEVEL > $hdir.n2.log 2>&1 & diff --git a/test/eth/run_ganache.sh b/test/eth/run_ganache.sh index e59f2e63..ec4868b9 100755 --- a/test/eth/run_ganache.sh +++ b/test/eth/run_ganache.sh @@ -1,10 +1,12 @@ +#!/bin/bash -eux + CWD="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" DATA_DIR=${DATA_DIR:-$CWD/data} rm -rf $DATA_DIR mkdir -p $DATA_DIR -ganache="ganache-cli" +ganache="ganache" if pgrep -x $ganache >/dev/null then @@ -12,11 +14,11 @@ then ps -ef | grep $ganache | grep -v grep | awk '{print $2}' | xargs kill fi -ganache-cli \ - --chain-id 888 \ +$ganache \ + --chain.chainId 888 \ --account '0x88cbead91aee890d27bf06e003ade3d4e952427e88f88d31d61d3ef5e5d54305,1000000000000000000' \ --account '0x741de4f8988ea941d3ff0287911ca4074e62b7d45c991a51186455366f10b544,1000000000000000000' \ --account '0x39a4c898dda351d54875d5ebb3e1c451189116faa556c3c04adc860dd1000608,1000000000000000000' \ --account '0x6c212553111b370a8ffdc682954495b7b90a73cedab7106323646a4f2c4e668f,1000000000000000000' \ - --blockTime 1 \ + --blockTime 1 \ > $DATA_DIR/ganache.log 2>&1 & \ No newline at end of file diff --git a/test/scripts/valset_update_2000_blocks.sh b/test/scripts/valset_update_2000_blocks.sh index 62fdf823..8e62fb45 100755 --- a/test/scripts/valset_update_2000_blocks.sh +++ b/test/scripts/valset_update_2000_blocks.sh @@ -1,9 +1,9 @@ -#!/bin/bash -eu +#!/bin/bash -eux CWD="$( cd -- "$(dirname "$0")" >/dev/null 2>&1 ; pwd -P )" ETH_RPC=${ETH_RPC:-"http://127.0.0.1:8545"} UMMED_BUILD_PATH=$CWD/../umeed-builds -UMEED_BIN=${UMEED_BIN:-$UMMED_BUILD_PATH/umeed-main} +UMEED_BIN=${UMEED_BIN:-$UMMED_BUILD_PATH/umeed-rc4} PEGGO_BUILD_PATH=$CWD/../../build PEGGO_BIN=${PEGGO_BIN:-$PEGGO_BUILD_PATH/peggo} CHAIN_ID="${CHAIN_ID:-888}" @@ -18,7 +18,7 @@ n1dir="$hdir/n1" n2dir="$hdir/n2" umeeBasename=$(basename $UMEED_BIN) -ganache="ganache-cli" +ganache="ganache" # Common flags kbt="--keyring-backend test" @@ -71,18 +71,21 @@ PEGGO_ETH_PK=$val0PrivateKey $PEGGO_BIN orchestrator $bridgeAddr \ $defaultFlags \ --cosmos-grpc="tcp://0.0.0.0:9090" \ --tendermint-rpc="http://0.0.0.0:26657" \ + --oracle-providers="osmosis,huobi,okx,coinbase,binance,bitget,mexc" \ --cosmos-keyring-dir=$n0dir > $peggoLogPath/n0.peggo.log 2>&1 & -PEGGO_ETH_PK=$val1PrivateKey $PEGGO_BIN orchestrator $bridgeAddr \ +# PEGGO_ETH_PK=$val1PrivateKey $PEGGO_BIN orchestrator $bridgeAddr \ $defaultFlags \ --cosmos-grpc="tcp://0.0.0.0:9091" \ --tendermint-rpc="http://0.0.0.0:26667" \ + --oracle-providers="kraken,osmosis,huobi,okx,coinbase,binance,bitget,mexc" \ --cosmos-keyring-dir=$n1dir > $peggoLogPath/n1.peggo.log 2>&1 & PEGGO_ETH_PK=$val2PrivateKey $PEGGO_BIN orchestrator $bridgeAddr \ $defaultFlags \ --cosmos-grpc="tcp://0.0.0.0:9092" \ --tendermint-rpc="http://0.0.0.0:26677" \ + --oracle-providers="kraken,osmosis,huobi,okx,coinbase,binance,bitget,mexc" \ --cosmos-keyring-dir=$n2dir > $peggoLogPath/n2.peggo.log 2>&1 & echo Wait for a few seconds to get the current valset From 935efc085c689e1e6d65f13ed3607d0eaa73b640 Mon Sep 17 00:00:00 2001 From: Facundo Medica <14063057+facundomedica@users.noreply.github.com> Date: Mon, 26 Sep 2022 17:13:09 -0500 Subject: [PATCH 3/9] chore: prepare v1.1.0 release (#371) * chore: prepare v1.1.0 release * chore: prepare v1.1.0 release --- CHANGELOG.md | 35 +++++++++++++++++++++++------------ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50ab94ce..4d2ea464 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,26 +43,37 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +## [v1.1.0](https://github.com/umee-network/peggo/releases/tag/v1.1.0) - 2022-09-26 + ### Improvements -[#367] Set ETH block delay to 96 blocks -[#362](https://github.com/umee-network/peggo/pull/362) Update umeed to v3. -[#343](https://github.com/umee-network/peggo/pull/343) Upgrade to cosmos-sdk v0.46.1. -[#341](https://github.com/umee-network/peggo/pull/341) Fix linter. -[#334](https://github.com/umee-network/peggo/pull/334) Update to go 1.18. -[#326](https://github.com/umee-network/peggo/pull/326) Refactory of eth `getCurrentBlock`. -[#311](https://github.com/umee-network/peggo/pull/311) Add valset update at each 2000 eth blocks. +- [#367] Set ETH block delay to 96 blocks -### Bug Fixes +## [v1.0.1](https://github.com/umee-network/peggo/releases/tag/v1.0.1) - 2022-09-21 + +### Improvements + +- [#365] Reduce oracle noise msgs + +## [v1.0.0](https://github.com/umee-network/peggo/releases/tag/v1.0.0) - 2022-09-14 + +### Improvements + +- [#362](https://github.com/umee-network/peggo/pull/362) Update umeed to v3. +- [#343](https://github.com/umee-network/peggo/pull/343) Upgrade to cosmos-sdk v0.46.1. +- [#341](https://github.com/umee-network/peggo/pull/341) Fix linter. +- [#334](https://github.com/umee-network/peggo/pull/334) Update to go 1.18. +- [#326](https://github.com/umee-network/peggo/pull/326) Refactory of eth `getCurrentBlock`. +- [#311](https://github.com/umee-network/peggo/pull/311) Add valset update at each 2000 eth blocks. ## [v0.4.0](https://github.com/umee-network/peggo/releases/tag/v0.4.0) - 2022-07-14 ### Improvements -[#308](https://github.com/umee-network/peggo/pull/308) Change stablecoin from UST to DAI. -[#299](https://github.com/umee-network/peggo/pull/299) Fix lint warnings. -[#297](https://github.com/umee-network/peggo/pull/297) Update dependabot reviewers. -[#275](https://github.com/umee-network/peggo/pull/275) Add diagrams of main loops. +- [#308](https://github.com/umee-network/peggo/pull/308) Change stablecoin from UST to DAI. +- [#299](https://github.com/umee-network/peggo/pull/299) Fix lint warnings. +- [#297](https://github.com/umee-network/peggo/pull/297) Update dependabot reviewers. +- [#275](https://github.com/umee-network/peggo/pull/275) Add diagrams of main loops. ### Bug Fixes From c36d5a06fa42aea924d77cbbf9a53831548d4e40 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Sat, 1 Oct 2022 10:33:31 -0300 Subject: [PATCH 4/9] feat: Add eth merge pause flag --- cmd/peggo/flags.go | 1 + cmd/peggo/orchestrator.go | 1 + orchestrator/eth_event_watcher.go | 7 ++ orchestrator/eth_event_watcher_test.go | 5 ++ orchestrator/main_loops.go | 90 ++++++++++++++------------ orchestrator/oracle_resync_test.go | 1 + orchestrator/orchestrator.go | 3 + 7 files changed, 67 insertions(+), 41 deletions(-) diff --git a/cmd/peggo/flags.go b/cmd/peggo/flags.go index 66db0251..4a6b9966 100644 --- a/cmd/peggo/flags.go +++ b/cmd/peggo/flags.go @@ -55,6 +55,7 @@ const ( flagRelayerLoopMultiplier = "relayer-loop-multiplier" flagRequesterLoopMultiplier = "requester-loop-multiplier" flagBridgeStartHeight = "bridge-start-height" + flagEthMergePause = "eth-merge-pause" // TODO: remove this after merge is completed ) func cosmosFlagSet() *pflag.FlagSet { diff --git a/cmd/peggo/orchestrator.go b/cmd/peggo/orchestrator.go index 47741992..9e4de1c7 100644 --- a/cmd/peggo/orchestrator.go +++ b/cmd/peggo/orchestrator.go @@ -252,6 +252,7 @@ func getOrchestratorCmd() *cobra.Command { konfig.Int64(flagBridgeStartHeight), symbolRetriever, o, + konfig.Bool(flagEthMergePause), ) g, errCtx := errgroup.WithContext(ctx) diff --git a/orchestrator/eth_event_watcher.go b/orchestrator/eth_event_watcher.go index 46799afc..fe8752b2 100644 --- a/orchestrator/eth_event_watcher.go +++ b/orchestrator/eth_event_watcher.go @@ -202,6 +202,13 @@ func (p *gravityOrchestrator) CheckForEvents( valsetUpdates := filterValsetUpdateEventsByNonce(valsetUpdatedEvents, lastEventResp.EventNonce) deployedERC20Updates := filterERC20DeployedEventsByNonce(erc20DeployedEvents, lastEventResp.EventNonce) + // Don't send anything other than valsetUpdates + if p.ethMergePause { + deposits = []*wrappers.GravitySendToCosmosEvent{} + withdraws = []*wrappers.GravityTransactionBatchExecutedEvent{} + deployedERC20Updates = []*wrappers.GravityERC20DeployedEvent{} + } + if len(deposits) > 0 || len(withdraws) > 0 || len(valsetUpdates) > 0 || len(deployedERC20Updates) > 0 { if err := p.gravityBroadcastClient.SendEthereumClaims( diff --git a/orchestrator/eth_event_watcher_test.go b/orchestrator/eth_event_watcher_test.go index a42dc796..97e56d47 100644 --- a/orchestrator/eth_event_watcher_test.go +++ b/orchestrator/eth_event_watcher_test.go @@ -166,6 +166,7 @@ func TestCheckForEvents(t *testing.T) { 0, nil, nil, + false, ) currentBlock, err := orch.CheckForEvents(context.Background(), 1, 5) @@ -248,6 +249,7 @@ func TestCheckForEvents(t *testing.T) { 0, nil, nil, + false, ) currentBlock, err := orch.CheckForEvents(context.Background(), 1, 5) @@ -357,6 +359,7 @@ func TestCheckForEvents(t *testing.T) { 0, nil, nil, + false, ) currentBlock, err := orch.CheckForEvents(context.Background(), 1, 5) @@ -480,6 +483,7 @@ func TestCheckForEvents(t *testing.T) { 0, nil, nil, + false, ) currentBlock, err := orch.CheckForEvents(context.Background(), 1, 5) @@ -617,6 +621,7 @@ func TestCheckForEvents(t *testing.T) { 0, nil, nil, + false, ) currentBlock, err := orch.CheckForEvents(context.Background(), 1, 5) diff --git a/orchestrator/main_loops.go b/orchestrator/main_loops.go index 8c24e2a6..df4ff5e7 100644 --- a/orchestrator/main_loops.go +++ b/orchestrator/main_loops.go @@ -64,12 +64,14 @@ func (p *gravityOrchestrator) Start(ctx context.Context) error { return p.EthOracleMainLoop(ctx) }) - pg.Go(func() error { - // looks at the BatchFees on Cosmos and uses the query endpoint BatchFees - // to iterate over each token to see if it is profitable, if it is - // it will send an request batch for that denom - return p.BatchRequesterLoop(ctx) - }) + if !p.ethMergePause { + pg.Go(func() error { + // looks at the BatchFees on Cosmos and uses the query endpoint BatchFees + // to iterate over each token to see if it is profitable, if it is + // it will send an request batch for that denom + return p.BatchRequesterLoop(ctx) + }) + } pg.Go(func() error { // Gets the last pending valset to send an MsgValsetConfirm that sends @@ -81,6 +83,8 @@ func (p *gravityOrchestrator) Start(ctx context.Context) error { return p.EthSignerMainLoop(ctx) }) + // Let this function run as is. If we see errors caused by this loop, then + // we might need to enable batch confirms. pg.Go(func() error { // Gets the latest valset available and updating it on the ethereum // smartcontract if needed. Also gets all the pending transaction @@ -268,51 +272,55 @@ func (p *gravityOrchestrator) EthSignerMainLoop(ctx context.Context) (err error) } } - var oldestUnsignedTransactionBatch []types.OutgoingTxBatch - if err := retry.Do(func() error { - // sign the last unsigned batch, TODO check if we already have signed this - txBatch, err := p.cosmosQueryClient.LastPendingBatchRequestByAddr( - ctx, - &types.QueryLastPendingBatchRequestByAddrRequest{ - Address: p.gravityBroadcastClient.AccFromAddress().String(), - }, - ) - - if err != nil { - return err - } + // Do not sent batch confirms while the Eth merge adapting period is active + // otherwise the message will fail causing Peggo to crash. + if !p.ethMergePause { + var oldestUnsignedTransactionBatch []types.OutgoingTxBatch + if err := retry.Do(func() error { + // sign the last unsigned batch, TODO check if we already have signed this + txBatch, err := p.cosmosQueryClient.LastPendingBatchRequestByAddr( + ctx, + &types.QueryLastPendingBatchRequestByAddrRequest{ + Address: p.gravityBroadcastClient.AccFromAddress().String(), + }, + ) - if txBatch == nil || txBatch.Batch == nil { - logger.Debug().Msg("no TransactionBatch waiting to be signed") - return nil - } + if err != nil { + return err + } - oldestUnsignedTransactionBatch = txBatch.Batch - return nil - }, retry.Context(ctx), retry.OnRetry(func(n uint, err error) { - logger.Err(err). - Uint("retry", n). - Msg("failed to get unsigned TransactionBatch for signing; retrying...") - })); err != nil { - logger.Err(err).Msg("got error, loop exits") - return err - } + if txBatch == nil || txBatch.Batch == nil { + logger.Debug().Msg("no TransactionBatch waiting to be signed") + return nil + } - for _, batch := range oldestUnsignedTransactionBatch { - batch := batch - logger.Info(). - Uint64("batch_nonce", batch.BatchNonce). - Msg("sending TransactionBatch confirm for BatchNonce") - if err := retry.Do(func() error { - return p.gravityBroadcastClient.SendBatchConfirm(ctx, p.ethFrom, gravityID, batch) + oldestUnsignedTransactionBatch = txBatch.Batch + return nil }, retry.Context(ctx), retry.OnRetry(func(n uint, err error) { logger.Err(err). Uint("retry", n). - Msg("failed to sign and send TransactionBatch confirmation to Cosmos; retrying...") + Msg("failed to get unsigned TransactionBatch for signing; retrying...") })); err != nil { logger.Err(err).Msg("got error, loop exits") return err } + + for _, batch := range oldestUnsignedTransactionBatch { + batch := batch + logger.Info(). + Uint64("batch_nonce", batch.BatchNonce). + Msg("sending TransactionBatch confirm for BatchNonce") + if err := retry.Do(func() error { + return p.gravityBroadcastClient.SendBatchConfirm(ctx, p.ethFrom, gravityID, batch) + }, retry.Context(ctx), retry.OnRetry(func(n uint, err error) { + logger.Err(err). + Uint("retry", n). + Msg("failed to sign and send TransactionBatch confirmation to Cosmos; retrying...") + })); err != nil { + logger.Err(err).Msg("got error, loop exits") + return err + } + } } return nil diff --git a/orchestrator/oracle_resync_test.go b/orchestrator/oracle_resync_test.go index 9da776ab..40d0cb0a 100644 --- a/orchestrator/oracle_resync_test.go +++ b/orchestrator/oracle_resync_test.go @@ -160,6 +160,7 @@ func TestGetLastCheckedBlock(t *testing.T) { 0, nil, nil, + false, ) block, err := orch.GetLastCheckedBlock(context.Background(), 0) diff --git a/orchestrator/orchestrator.go b/orchestrator/orchestrator.go index 80b906a3..bacf7445 100644 --- a/orchestrator/orchestrator.go +++ b/orchestrator/orchestrator.go @@ -46,6 +46,7 @@ type gravityOrchestrator struct { mtx sync.Mutex erc20DenomCache map[string]string + ethMergePause bool } func NewGravityOrchestrator( @@ -64,6 +65,7 @@ func NewGravityOrchestrator( bridgeStartHeight int64, symbolRetriever relayer.SymbolRetriever, oracle relayer.Oracle, + ethMergePause bool, // TODO: remove this after merge is completed options ...func(GravityOrchestrator), ) GravityOrchestrator { @@ -84,6 +86,7 @@ func NewGravityOrchestrator( bridgeStartHeight: uint64(bridgeStartHeight), symbolRetriever: symbolRetriever, oracle: oracle, + ethMergePause: ethMergePause, } for _, option := range options { From 94aacfd2f70fdd51c5fe65b64b54a37559a50ec9 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Sat, 1 Oct 2022 10:38:16 -0300 Subject: [PATCH 5/9] fix --- orchestrator/main_loops.go | 76 +++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 39 deletions(-) diff --git a/orchestrator/main_loops.go b/orchestrator/main_loops.go index df4ff5e7..de55e26d 100644 --- a/orchestrator/main_loops.go +++ b/orchestrator/main_loops.go @@ -272,55 +272,53 @@ func (p *gravityOrchestrator) EthSignerMainLoop(ctx context.Context) (err error) } } - // Do not sent batch confirms while the Eth merge adapting period is active - // otherwise the message will fail causing Peggo to crash. - if !p.ethMergePause { - var oldestUnsignedTransactionBatch []types.OutgoingTxBatch - if err := retry.Do(func() error { - // sign the last unsigned batch, TODO check if we already have signed this - txBatch, err := p.cosmosQueryClient.LastPendingBatchRequestByAddr( - ctx, - &types.QueryLastPendingBatchRequestByAddrRequest{ - Address: p.gravityBroadcastClient.AccFromAddress().String(), - }, - ) - - if err != nil { - return err - } + //Try to send batch confirms. If this fails, it means there are pending batches + // that we'll need to sign before the next upgrade. + var oldestUnsignedTransactionBatch []types.OutgoingTxBatch + if err := retry.Do(func() error { + // sign the last unsigned batch, TODO check if we already have signed this + txBatch, err := p.cosmosQueryClient.LastPendingBatchRequestByAddr( + ctx, + &types.QueryLastPendingBatchRequestByAddrRequest{ + Address: p.gravityBroadcastClient.AccFromAddress().String(), + }, + ) - if txBatch == nil || txBatch.Batch == nil { - logger.Debug().Msg("no TransactionBatch waiting to be signed") - return nil - } + if err != nil { + return err + } - oldestUnsignedTransactionBatch = txBatch.Batch + if txBatch == nil || txBatch.Batch == nil { + logger.Debug().Msg("no TransactionBatch waiting to be signed") return nil + } + + oldestUnsignedTransactionBatch = txBatch.Batch + return nil + }, retry.Context(ctx), retry.OnRetry(func(n uint, err error) { + logger.Err(err). + Uint("retry", n). + Msg("failed to get unsigned TransactionBatch for signing; retrying...") + })); err != nil { + logger.Err(err).Msg("got error, loop exits") + return err + } + + for _, batch := range oldestUnsignedTransactionBatch { + batch := batch + logger.Info(). + Uint64("batch_nonce", batch.BatchNonce). + Msg("sending TransactionBatch confirm for BatchNonce") + if err := retry.Do(func() error { + return p.gravityBroadcastClient.SendBatchConfirm(ctx, p.ethFrom, gravityID, batch) }, retry.Context(ctx), retry.OnRetry(func(n uint, err error) { logger.Err(err). Uint("retry", n). - Msg("failed to get unsigned TransactionBatch for signing; retrying...") + Msg("failed to sign and send TransactionBatch confirmation to Cosmos; retrying...") })); err != nil { logger.Err(err).Msg("got error, loop exits") return err } - - for _, batch := range oldestUnsignedTransactionBatch { - batch := batch - logger.Info(). - Uint64("batch_nonce", batch.BatchNonce). - Msg("sending TransactionBatch confirm for BatchNonce") - if err := retry.Do(func() error { - return p.gravityBroadcastClient.SendBatchConfirm(ctx, p.ethFrom, gravityID, batch) - }, retry.Context(ctx), retry.OnRetry(func(n uint, err error) { - logger.Err(err). - Uint("retry", n). - Msg("failed to sign and send TransactionBatch confirmation to Cosmos; retrying...") - })); err != nil { - logger.Err(err).Msg("got error, loop exits") - return err - } - } } return nil From d4617c05e13774a1fbf35d690f97c5872ff03f36 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Sat, 1 Oct 2022 13:31:50 -0300 Subject: [PATCH 6/9] fix add flag to cmd --- cmd/peggo/orchestrator.go | 1 + 1 file changed, 1 insertion(+) diff --git a/cmd/peggo/orchestrator.go b/cmd/peggo/orchestrator.go index 9e4de1c7..37ed4358 100644 --- a/cmd/peggo/orchestrator.go +++ b/cmd/peggo/orchestrator.go @@ -277,6 +277,7 @@ func getOrchestratorCmd() *cobra.Command { cmd.Flags().Bool(flagRelayBatches, false, "Relay transaction batches to Ethereum") cmd.Flags().Int64(flagEthBlocksPerLoop, 2000, "Number of Ethereum blocks to process per orchestrator loop") cmd.Flags().String(flagCoinGeckoAPI, "https://api.coingecko.com/api/v3", "Specify the coingecko API endpoint") + cmd.Flags().Bool(flagEthMergePause, false, "Pause some messages related to the adaptation of the Gravity Bridge to the merge") defaultProviders := []string{ umeepfprovider.ProviderOsmosis.String(), From a26cfc2d2dbff7f72e7323128edeef035e2da4eb Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Sat, 1 Oct 2022 14:15:16 -0300 Subject: [PATCH 7/9] lint --- cmd/peggo/orchestrator.go | 2 +- orchestrator/main_loops.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/peggo/orchestrator.go b/cmd/peggo/orchestrator.go index 37ed4358..ee3bc11b 100644 --- a/cmd/peggo/orchestrator.go +++ b/cmd/peggo/orchestrator.go @@ -277,7 +277,7 @@ func getOrchestratorCmd() *cobra.Command { cmd.Flags().Bool(flagRelayBatches, false, "Relay transaction batches to Ethereum") cmd.Flags().Int64(flagEthBlocksPerLoop, 2000, "Number of Ethereum blocks to process per orchestrator loop") cmd.Flags().String(flagCoinGeckoAPI, "https://api.coingecko.com/api/v3", "Specify the coingecko API endpoint") - cmd.Flags().Bool(flagEthMergePause, false, "Pause some messages related to the adaptation of the Gravity Bridge to the merge") + cmd.Flags().Bool(flagEthMergePause, false, "Pause some messages related to the adaptation of the Gravity Bridge to the merge") //nolint: lll defaultProviders := []string{ umeepfprovider.ProviderOsmosis.String(), diff --git a/orchestrator/main_loops.go b/orchestrator/main_loops.go index de55e26d..0c62bf1c 100644 --- a/orchestrator/main_loops.go +++ b/orchestrator/main_loops.go @@ -272,7 +272,7 @@ func (p *gravityOrchestrator) EthSignerMainLoop(ctx context.Context) (err error) } } - //Try to send batch confirms. If this fails, it means there are pending batches + // Try to send batch confirms. If this fails, it means there are pending batches // that we'll need to sign before the next upgrade. var oldestUnsignedTransactionBatch []types.OutgoingTxBatch if err := retry.Do(func() error { From 6c5713e1d43de7f05cc2edf1c09e6a8a78d88118 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Sat, 1 Oct 2022 14:23:52 -0300 Subject: [PATCH 8/9] fix mergify --- .mergify.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.mergify.yml b/.mergify.yml index 9d79ccb5..2e7f5565 100644 --- a/.mergify.yml +++ b/.mergify.yml @@ -57,8 +57,8 @@ pull_request_rules: - name: Backport patches to release/v1.0.x branch conditions: - base=main - - label=S:backport/v1.0.x + - label=S:backport/v1.x.x actions: backport: branches: - - release/v1.x.x + - release/v1.x.x \ No newline at end of file From 08d0901a7ce442b9a4f3d48b6c55566340d64040 Mon Sep 17 00:00:00 2001 From: Facundo Medica Date: Sat, 1 Oct 2022 14:56:07 -0300 Subject: [PATCH 9/9] cl++ --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d2ea464..daf9a8cd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,10 @@ Ref: https://keepachangelog.com/en/1.0.0/ ## [Unreleased] +### Improvements + +- [#376] Add `eth-merge-pause` flag + ## [v1.1.0](https://github.com/umee-network/peggo/releases/tag/v1.1.0) - 2022-09-26 ### Improvements