From 0ca7514b9e5eda24ce5e8579d7258c8f174ca367 Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Thu, 7 Nov 2024 15:32:42 -0800 Subject: [PATCH 1/2] refactor(zetacore)!: remove rosetta api --- cmd/zetacored/root.go | 3 --- docs/cli/zetacored/cli.md | 40 --------------------------- go.mod | 4 +-- server/start.go | 54 +------------------------------------ x/observer/keeper/events.go | 19 +++++++++++-- 5 files changed, 20 insertions(+), 100 deletions(-) diff --git a/cmd/zetacored/root.go b/cmd/zetacored/root.go index 3880b12108..93ae4ba469 100644 --- a/cmd/zetacored/root.go +++ b/cmd/zetacored/root.go @@ -6,7 +6,6 @@ import ( "io" "os" - rosettaCmd "cosmossdk.io/tools/rosetta/cmd" dbm "github.com/cometbft/cometbft-db" tmcfg "github.com/cometbft/cometbft/config" tmcli "github.com/cometbft/cometbft/libs/cli" @@ -177,8 +176,6 @@ func initRootCmd(rootCmd *cobra.Command, encodingConfig types.EncodingConfig) { if err := SetEthereumHDPath(rootCmd); err != nil { fmt.Printf("warning: unable to set default HD path: %v\n", err) } - - rootCmd.AddCommand(rosettaCmd.RosettaCommand(encodingConfig.InterfaceRegistry, encodingConfig.Codec)) } func addModuleInitFlags(startCmd *cobra.Command) { diff --git a/docs/cli/zetacored/cli.md b/docs/cli/zetacored/cli.md index 36440f2704..d7a594d94f 100644 --- a/docs/cli/zetacored/cli.md +++ b/docs/cli/zetacored/cli.md @@ -33,7 +33,6 @@ Zetacore Daemon (server) * [zetacored parse-genesis-file](#zetacored-parse-genesis-file) - Parse the provided genesis file and import the required data into the optionally provided genesis file * [zetacored query](#zetacored-query) - Querying subcommands * [zetacored rollback](#zetacored-rollback) - rollback cosmos-sdk and tendermint state by one height -* [zetacored rosetta](#zetacored-rosetta) - spin up a rosetta server * [zetacored snapshots](#zetacored-snapshots) - Manage local snapshots * [zetacored start](#zetacored-start) - Run the full node * [zetacored status](#zetacored-status) - Query remote node for status @@ -7363,45 +7362,6 @@ zetacored rollback [flags] * [zetacored](#zetacored) - Zetacore Daemon (server) -## zetacored rosetta - -spin up a rosetta server - -``` -zetacored rosetta [flags] -``` - -### Options - -``` - --addr string the address rosetta will bind to - --blockchain string the blockchain type - --denom-to-suggest string default denom for fee suggestion - --enable-fee-suggestion enable default fee suggestion - --gas-to-suggest int default gas for fee suggestion (default 200000) - --grpc string the app gRPC endpoint - -h, --help help for rosetta - --network string the network name - --offline run rosetta only with construction API - --prices-to-suggest string default prices for fee suggestion - --retries int the number of retries that will be done before quitting (default 5) - --tendermint string the tendermint rpc endpoint, without tcp:// -``` - -### Options inherited from parent commands - -``` - --home string directory for config and data - --log_format string The logging format (json|plain) - --log_level string The logging level (trace|debug|info|warn|error|fatal|panic) - --log_no_color Disable colored logs - --trace print out full stack trace on errors -``` - -### SEE ALSO - -* [zetacored](#zetacored) - Zetacore Daemon (server) - ## zetacored snapshots Manage local snapshots diff --git a/go.mod b/go.mod index adb9b1cdb7..795cfb4528 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,7 @@ toolchain go1.22.8 require ( cosmossdk.io/errors v1.0.1 cosmossdk.io/math v1.3.0 - cosmossdk.io/tools/rosetta v0.2.1 + cosmossdk.io/tools/rosetta v0.2.1 // indirect github.com/99designs/keyring v1.2.1 github.com/btcsuite/btcd v0.24.2 github.com/btcsuite/btcd/btcec/v2 v2.3.2 @@ -15,7 +15,7 @@ require ( github.com/btcsuite/btcd/chaincfg/chainhash v1.1.0 github.com/cenkalti/backoff/v4 v4.3.0 github.com/cockroachdb/errors v1.11.1 - github.com/coinbase/rosetta-sdk-go v0.7.9 + github.com/coinbase/rosetta-sdk-go v0.7.9 // indirect github.com/cometbft/cometbft v0.37.5 github.com/cometbft/cometbft-db v0.12.0 github.com/cosmos/btcutil v1.0.5 diff --git a/server/start.go b/server/start.go index 09bb9215c0..14c64482f8 100644 --- a/server/start.go +++ b/server/start.go @@ -27,8 +27,6 @@ import ( "time" errorsmod "cosmossdk.io/errors" - "cosmossdk.io/tools/rosetta" - crgserver "cosmossdk.io/tools/rosetta/lib/server" dbm "github.com/cometbft/cometbft-db" abciserver "github.com/cometbft/cometbft/abci/server" tcmd "github.com/cometbft/cometbft/cmd/cometbft/commands" @@ -50,7 +48,6 @@ import ( "github.com/cosmos/cosmos-sdk/server/types" pruningtypes "github.com/cosmos/cosmos-sdk/store/pruning/types" "github.com/cosmos/cosmos-sdk/telemetry" - sdk "github.com/cosmos/cosmos-sdk/types" ethmetricsexp "github.com/ethereum/go-ethereum/metrics/exp" "github.com/spf13/cobra" "github.com/zeta-chain/ethermint/indexer" @@ -626,61 +623,12 @@ func startInProcess(ctx *server.Context, clientCtx client.Context, opts StartOpt } // At this point it is safe to block the process if we're in query only mode as - // we do not need to start Rosetta or handle any Tendermint related processes. + // we do not need to handle any Tendermint related processes. if gRPCOnly { // wait for signal capture and gracefully return return server.WaitForQuitSignals() } - var rosettaSrv crgserver.Server - if config.Rosetta.Enable { - offlineMode := config.Rosetta.Offline - - // If GRPC is not enabled rosetta cannot work in online mode, so it works in - // offline mode. - if !config.GRPC.Enable { - offlineMode = true - } - - minGasPrices, err := sdk.ParseDecCoins(config.MinGasPrices) - if err != nil { - ctx.Logger.Error("failed to parse minimum-gas-prices", "error", err.Error()) - return err - } - - conf := &rosetta.Config{ - Blockchain: config.Rosetta.Blockchain, - Network: config.Rosetta.Network, - TendermintRPC: ctx.Config.RPC.ListenAddress, - GRPCEndpoint: config.GRPC.Address, - Addr: config.Rosetta.Address, - Retries: config.Rosetta.Retries, - Offline: offlineMode, - GasToSuggest: config.Rosetta.GasToSuggest, - EnableFeeSuggestion: config.Rosetta.EnableFeeSuggestion, - GasPrices: minGasPrices.Sort(), - Codec: clientCtx.Codec.(*codec.ProtoCodec), - InterfaceRegistry: clientCtx.InterfaceRegistry, - } - - rosettaSrv, err = rosetta.ServerFromConfig(conf) - if err != nil { - return err - } - - errCh := make(chan error) - go func() { - if err := rosettaSrv.Start(); err != nil { - errCh <- err - } - }() - - select { - case err := <-errCh: - return err - case <-time.After(types.ServerStartTime): // assume server started successfully - } - } // Wait for SIGINT or SIGTERM signal return server.WaitForQuitSignals() } diff --git a/x/observer/keeper/events.go b/x/observer/keeper/events.go index d1ddbc44ff..aed3b726a9 100644 --- a/x/observer/keeper/events.go +++ b/x/observer/keeper/events.go @@ -1,9 +1,10 @@ package keeper import ( + "encoding/json" + "log" "strconv" - types2 "github.com/coinbase/rosetta-sdk-go/types" sdk "github.com/cosmos/cosmos-sdk/types" types "github.com/zeta-chain/node/x/observer/types" @@ -21,11 +22,25 @@ func EmitEventBallotCreated(ctx sdk.Context, ballot types.Ballot, observationHas } } +// vendor this code from github.com/coinbase/rosetta-sdk-go/types +func prettyPrintStruct(val interface{}) string { + prettyStruct, err := json.MarshalIndent( + val, + "", + " ", + ) + if err != nil { + log.Fatal(err) + } + + return string(prettyStruct) +} + func EmitEventKeyGenBlockUpdated(ctx sdk.Context, keygen *types.Keygen) { err := ctx.EventManager().EmitTypedEvents(&types.EventKeygenBlockUpdated{ MsgTypeUrl: sdk.MsgTypeURL(&types.MsgUpdateKeygen{}), KeygenBlock: strconv.Itoa(int(keygen.BlockNumber)), - KeygenPubkeys: types2.PrettyPrintStruct(keygen.GranteePubkeys), + KeygenPubkeys: prettyPrintStruct(keygen.GranteePubkeys), }) if err != nil { ctx.Logger().Error("Error emitting EventKeygenBlockUpdated :", err) From 207973ec39078dc32fd1f3f667e3019d03b885bc Mon Sep 17 00:00:00 2001 From: Alex Gartner Date: Fri, 8 Nov 2024 08:13:41 -0800 Subject: [PATCH 2/2] remove from localnet --- contrib/localnet/docker-compose.yml | 17 ----------------- contrib/localnet/scripts/start-rosetta.sh | 14 -------------- contrib/localnet/zetacored/common/app.toml | 20 -------------------- 3 files changed, 51 deletions(-) delete mode 100644 contrib/localnet/scripts/start-rosetta.sh diff --git a/contrib/localnet/docker-compose.yml b/contrib/localnet/docker-compose.yml index 670befa7b6..e0078230e7 100644 --- a/contrib/localnet/docker-compose.yml +++ b/contrib/localnet/docker-compose.yml @@ -5,7 +5,6 @@ # - An Ethereum node (eth) # - A secondary optional Ethereum node (eth2) enabled when profile is set to eth2 # - A Bitcoin node (bitcoin) -# - A Rosetta API (rosetta) # - An orchestrator to manage interaction with the localnet (orchestrator) # - An upgrade host to serve binaries for the upgrade tests (upgrade-host). Only enabled when profile is set to upgrade. # - An upgrade orchestrator to send the upgrade governance proposal (upgrade-orchestrator). Only enabled when profile is set to upgrade. @@ -19,22 +18,6 @@ networks: - subnet: 172.20.0.0/24 services: - rosetta: - image: zetanode:latest - container_name: rosetta - hostname: rosetta - depends_on: - zetacore0: - condition: service_healthy - ports: - - "8080:8080" - networks: - mynetwork: - ipv4_address: 172.20.0.200 - entrypoint: ["zetacored", "rosetta", "--tendermint", "zetacore0:26657", "--grpc", "zetacore0:9090", "--network", "athens_101-1", "--blockchain", "zetacore"] - volumes: - - ssh:/root/.ssh - zetacore0: image: zetanode:latest container_name: zetacore0 diff --git a/contrib/localnet/scripts/start-rosetta.sh b/contrib/localnet/scripts/start-rosetta.sh deleted file mode 100644 index e675da6a6a..0000000000 --- a/contrib/localnet/scripts/start-rosetta.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/bin/bash - -# This script is used to start the Rosetta API server for the Zetacore network. - -echo "Waiting for network to start producing blocks" -CURRENT_HEIGHT=0 -WAIT_HEIGHT=1 -while [[ $CURRENT_HEIGHT -lt $WAIT_HEIGHT ]] -do - CURRENT_HEIGHT=$(curl -s zetacore0:26657/status | jq '.result.sync_info.latest_block_height' | tr -d '"') - sleep 5 -done - -zetacored rosetta --tendermint zetacore0:26657 --grpc zetacore0:9090 --network athens_101-1 --blockchain zetacore \ No newline at end of file diff --git a/contrib/localnet/zetacored/common/app.toml b/contrib/localnet/zetacored/common/app.toml index 7bbf48cf96..adee8fb76c 100644 --- a/contrib/localnet/zetacored/common/app.toml +++ b/contrib/localnet/zetacored/common/app.toml @@ -136,26 +136,6 @@ enabled-unsafe-cors = true ### Rosetta Configuration ### ############################################################################### -[rosetta] - -# Enable defines if the Rosetta API server should be enabled. -enable = false - -# Address defines the Rosetta API server to listen on. -address = ":8080" - -# Network defines the name of the blockchain that will be returned by Rosetta. -blockchain = "app" - -# Network defines the name of the network that will be returned by Rosetta. -network = "network" - -# Retries defines the number of retries when connecting to the node before failing. -retries = 3 - -# Offline defines if Rosetta server should run in offline mode. -offline = false - ############################################################################### ### gRPC Configuration ### ###############################################################################