Skip to content

Commit

Permalink
refactor(zetacore)!: remove rosetta api
Browse files Browse the repository at this point in the history
  • Loading branch information
gartnera committed Nov 7, 2024
1 parent 0e86494 commit 117974d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 60 deletions.
3 changes: 0 additions & 3 deletions cmd/zetacored/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ 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
github.com/btcsuite/btcd/btcutil v1.1.6
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
Expand Down
54 changes: 1 addition & 53 deletions server/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -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()
}
Expand Down
19 changes: 17 additions & 2 deletions x/observer/keeper/events.go
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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)
Expand Down

0 comments on commit 117974d

Please sign in to comment.