Skip to content
This repository has been archived by the owner on Apr 15, 2024. It is now read-only.

Commit

Permalink
Merge branch 'main' into add-updating-evm-address-docs
Browse files Browse the repository at this point in the history
  • Loading branch information
rach-id authored Nov 29, 2023
2 parents 7c60bb5 + bfb2dec commit 415a6d1
Show file tree
Hide file tree
Showing 20 changed files with 277 additions and 93 deletions.
8 changes: 4 additions & 4 deletions benchmark/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func main() {
func DeployContractAndSubmitDataCommitment() error {
logger := tmlog.NewTMLogger(os.Stdout)

path, err := os.MkdirTemp(os.TempDir(), "qgb_bench")
path, err := os.MkdirTemp(os.TempDir(), "blobstream_bench")
if err != nil {
return nil
}
Expand Down Expand Up @@ -107,13 +107,13 @@ func DeployContractAndSubmitDataCommitment() error {

address, tx, bridge, err := evmClient.DeployBlobstreamContract(txOpts, backend, vs, vs.Nonce, true)
if err != nil {
logger.Error("failed to deploy QGB contract")
logger.Error("failed to deploy Blobstream contract")
return err
}

receipt, err := evmClient.WaitForTransaction(ctx, backend, tx)
receipt, err := evmClient.WaitForTransaction(ctx, backend, tx, time.Minute)
if err == nil && receipt != nil && receipt.Status == 1 {
logger.Info("deployed QGB contract", "proxy_address", address.Hex(), "tx_hash", tx.Hash().String())
logger.Info("deployed Blobstream contract", "proxy_address", address.Hex(), "tx_hash", tx.Hash().String())
}

txOpts.Nonce.Add(txOpts.Nonce, big.NewInt(1))
Expand Down
18 changes: 18 additions & 0 deletions cmd/blobstream/base/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ const (
FlagEVMRPC = "evm.rpc"
FlagEVMGasLimit = "evm.gas-limit"
FlagEVMContractAddress = "evm.contract-address"
FlagEVMRetryTimeout = "evm.retry-timeout"

FlagCoreGRPC = "core.grpc"
FlagCoreRPC = "core.rpc"
Expand Down Expand Up @@ -337,3 +338,20 @@ func GetLogger(level string, format string) (tmlog.Logger, error) {

return server.ZeroLogWrapper{Logger: zerolog.New(logWriter).Level(logLvl).With().Timestamp().Logger()}, nil
}

func GetEVMRetryTimeoutFlag(cmd *cobra.Command) (uint64, bool, error) {
changed := cmd.Flags().Changed(FlagEVMRetryTimeout)
val, err := cmd.Flags().GetUint64(FlagEVMRetryTimeout)
if err != nil {
return 0, changed, err
}
return val, changed, nil
}

func AddEVMRetryTimeoutFlag(cmd *cobra.Command) {
cmd.Flags().Uint64(
FlagEVMRetryTimeout,
15,
"The time, in minutes, to wait for transactions to be mined on the target EVM chain before recreating them with a different gas price",
)
}
3 changes: 2 additions & 1 deletion cmd/blobstream/deploy/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package deploy
import (
"context"
"strconv"
"time"

"github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/base"

Expand Down Expand Up @@ -138,7 +139,7 @@ func Command() *cobra.Command {
return err
}

receipt, err := evmClient.WaitForTransaction(cmd.Context(), backend, tx)
receipt, err := evmClient.WaitForTransaction(cmd.Context(), backend, tx, 5*time.Minute)
if err == nil && receipt != nil && receipt.Status == 1 {
logger.Info("deployed Blobstream contract", "proxy_address", address.Hex(), "tx_hash", tx.Hash().String())
}
Expand Down
6 changes: 3 additions & 3 deletions cmd/blobstream/orchestrator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ func LoadFileConfiguration(homeDir string) (*StartConfig, error) {
}
}

conf, err := getStartConfig(v, configPath)
conf, err := GetStartConfig(v, configPath)
if err != nil {
return nil, fmt.Errorf("couldn't get client config: %v", err)
}
Expand Down Expand Up @@ -279,8 +279,8 @@ func writeConfigToFile(configFilePath string, config *StartConfig) error {
return os.WriteFile(configFilePath, buffer.Bytes(), 0o600)
}

// getStartConfig reads values from config.toml file and unmarshalls them into StartConfig
func getStartConfig(v *viper.Viper, configPath string) (*StartConfig, error) {
// GetStartConfig reads values from config.toml file and unmarshalls them into StartConfig
func GetStartConfig(v *viper.Viper, configPath string) (*StartConfig, error) {
v.AddConfigPath(configPath)
v.SetConfigName("config")
v.SetConfigType("toml")
Expand Down
114 changes: 106 additions & 8 deletions cmd/blobstream/query/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@ import (
"fmt"
"math/big"
"os"
"path/filepath"
"strconv"
"time"

"github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/base"
"github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/orchestrator"
"github.com/celestiaorg/orchestrator-relayer/cmd/blobstream/relayer"
"github.com/spf13/viper"

common2 "github.com/ethereum/go-ethereum/common"

celestiatypes "github.com/celestiaorg/celestia-app/x/qgb/types"
Expand Down Expand Up @@ -52,13 +58,17 @@ func Signers() *cobra.Command {
" will query signatures for. It should be either a specific nonce starting from 2 and on." +
" Or, use 'latest' as argument to check the latest attestation nonce",
RunE: func(cmd *cobra.Command, args []string) error {
config, err := parseFlags(cmd)
// creating the logger
logger := tmlog.NewTMLogger(os.Stdout)
fileConfig, err := tryToGetExistingConfig(cmd, logger)
if err != nil {
return err
}
config, err := parseFlags(cmd, &fileConfig)
if err != nil {
return err
}

// creating the logger
logger := tmlog.NewTMLogger(os.Stdout)
logger.Debug("initializing queriers")

ctx, cancel := context.WithCancel(cmd.Context())
Expand All @@ -75,7 +85,12 @@ func Signers() *cobra.Command {
}()

// create tm querier and app querier
tmQuerier, appQuerier, stops, err := common.NewTmAndAppQuerier(logger, config.coreRPC, config.coreGRPC, config.grpcInsecure)
tmQuerier, appQuerier, stops, err := common.NewTmAndAppQuerier(
logger,
config.coreRPC,
config.coreGRPC,
config.grpcInsecure,
)
stopFuncs = append(stopFuncs, stops...)
if err != nil {
return err
Expand Down Expand Up @@ -335,13 +350,17 @@ func Signature() *cobra.Command {
" nonce that the command will query signatures for. The EVM address is the address registered by the validator " +
"in the staking module.",
RunE: func(cmd *cobra.Command, args []string) error {
config, err := parseFlags(cmd)
// creating the logger
logger := tmlog.NewTMLogger(os.Stdout)
fileConfig, err := tryToGetExistingConfig(cmd, logger)
if err != nil {
return err
}
config, err := parseFlags(cmd, &fileConfig)
if err != nil {
return err
}

// creating the logger
logger := tmlog.NewTMLogger(os.Stdout)
logger.Debug("initializing queriers")

ctx, cancel := context.WithCancel(cmd.Context())
Expand All @@ -358,7 +377,7 @@ func Signature() *cobra.Command {
}()

// create tm querier and app querier
tmQuerier, appQuerier, stops, err := common.NewTmAndAppQuerier(logger, config.coreRPC, config.coreGRPC, config.grpcInsecure)
tmQuerier, appQuerier, stops, err := common.NewTmAndAppQuerier(logger, config.coreRPC, config.coreRPC, config.grpcInsecure)
stopFuncs = append(stopFuncs, stops...)
if err != nil {
return err
Expand Down Expand Up @@ -478,3 +497,82 @@ func getSignatureAndPrintIt(
}
return nil
}

// tryToGetExistingConfig tries to get the query config from existing
// orchestrator/relayer homes. It first checks whether the `--home` flag was
// changed. If so, it gets the config from there. If not, then it tries the
// orchestrator default home directory, then the relayer default home directory.
func tryToGetExistingConfig(cmd *cobra.Command, logger tmlog.Logger) (Config, error) {
v := viper.New()
v.SetEnvPrefix("")
v.AutomaticEnv()
homeDir, changed, err := base.GetHomeFlag(cmd)
if err != nil {
return Config{}, err
}
// the --home flag was set to some directory
if changed && homeDir != "" {
logger.Debug("using home", "home", homeDir)
configPath := filepath.Join(homeDir, "config")

// assume this home is an orchestrator home directory
orchConf, err := orchestrator.GetStartConfig(v, configPath)
if err == nil {
// it is an orchestrator, so we get the config from it
return *NewPartialConfig(
orchConf.CoreGRPC,
orchConf.CoreRPC,
orchConf.Bootstrappers,
orchConf.GRPCInsecure,
), nil
}

// assume this home is a relayer home directory
relConf, err := relayer.GetStartConfig(v, configPath)
if err == nil {
// it is a relayer, so we get the config from it
return *NewPartialConfig(
relConf.CoreGRPC,
relConf.CoreRPC,
relConf.Bootstrappers,
relConf.GrpcInsecure,
), nil
}
return Config{}, fmt.Errorf("the provided home directory is neither an orchestrator nor a relayer home directory")
}
// try to get the config from the orchestrator home directory
orchHome, err := base.GetHomeDirectory(cmd, orchestrator.ServiceNameOrchestrator)
if err != nil {
return Config{}, err
}
orchConf, err := orchestrator.GetStartConfig(v, filepath.Join(orchHome, "config"))
if err == nil {
// found orchestrator home, get the config from it
logger.Debug("using home", "home", orchHome)
return *NewPartialConfig(
orchConf.CoreGRPC,
orchConf.CoreRPC,
orchConf.Bootstrappers,
orchConf.GRPCInsecure,
), nil
}

// try to get the config from the relayer home directory
relHome, err := base.GetHomeDirectory(cmd, relayer.ServiceNameRelayer)
if err != nil {
return Config{}, err
}
relConf, err := relayer.GetStartConfig(v, filepath.Join(relHome, "config"))
if err == nil {
// found relayer home, so we get the config from it
logger.Debug("using home", "home", relHome)
return *NewPartialConfig(
relConf.CoreGRPC,
relConf.CoreRPC,
relConf.Bootstrappers,
relConf.GrpcInsecure,
), nil
}

return *DefaultConfig(), nil
}
70 changes: 55 additions & 15 deletions cmd/blobstream/query/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func addFlags(cmd *cobra.Command) *cobra.Command {
cmd.Flags().String(FlagP2PNode, "", "P2P target node multiaddress (eg. /ip4/127.0.0.1/tcp/30000/p2p/12D3KooWBSMasWzRSRKXREhediFUwABNZwzJbkZcYz5rYr9Zdmfn)")
cmd.Flags().String(FlagOutputFile, "", "Path to an output file path if the results need to be written to a json file. Leaving it as empty will result in printing the result to stdout")
base.AddGRPCInsecureFlag(cmd)

cmd.Flags().String(base.FlagHome, "", "The Blobstream orchestrator|relayer home directory. If this flag is not set, it will try the orchestrator's default home directory, then the relayer's default home directory to get the necessary configuration")
return cmd
}

Expand All @@ -31,35 +31,75 @@ type Config struct {
grpcInsecure bool
}

func parseFlags(cmd *cobra.Command) (Config, error) {
coreRPC, err := cmd.Flags().GetString(base.FlagCoreRPC)
func NewPartialConfig(coreGRPC, coreRPC, targetNode string, grpcInsecure bool) *Config {
return &Config{
coreGRPC: coreGRPC,
coreRPC: coreRPC,
targetNode: targetNode,
grpcInsecure: grpcInsecure,
}
}

func DefaultConfig() *Config {
return &Config{
coreGRPC: "localhost:9090",
coreRPC: "tcp://localhost:26657",
targetNode: "",
outputFile: "",
grpcInsecure: true,
}
}

func parseFlags(cmd *cobra.Command, startConf *Config) (Config, error) {
coreRPC, changed, err := base.GetCoreRPCFlag(cmd)
if err != nil {
return Config{}, err
}
if !strings.HasPrefix(coreRPC, "tcp://") {
coreRPC = fmt.Sprintf("tcp://%s", coreRPC)
if changed {
if !strings.HasPrefix(coreRPC, "tcp://") {
coreRPC = fmt.Sprintf("tcp://%s", coreRPC)
}
startConf.coreRPC = coreRPC
}
coreGRPC, err := cmd.Flags().GetString(base.FlagCoreGRPC)

coreGRPC, changed, err := base.GetCoreGRPCFlag(cmd)
if err != nil {
return Config{}, err
}
targetNode, err := cmd.Flags().GetString(FlagP2PNode)
if changed {
startConf.coreGRPC = coreGRPC
}

targetNode, changed, err := getP2PNodeFlag(cmd)
if err != nil {
return Config{}, err
}
if changed {
startConf.targetNode = targetNode
}

outputFile, err := cmd.Flags().GetString(FlagOutputFile)
if err != nil {
return Config{}, err
}
grpcInsecure, err := cmd.Flags().GetBool(base.FlagGRPCInsecure)
startConf.outputFile = outputFile

grpcInsecure, changed, err := base.GetGRPCInsecureFlag(cmd)
if err != nil {
return Config{}, err
}
return Config{
coreGRPC: coreGRPC,
coreRPC: coreRPC,
targetNode: targetNode,
outputFile: outputFile,
grpcInsecure: grpcInsecure,
}, nil
if changed {
startConf.grpcInsecure = grpcInsecure
}

return *startConf, nil
}

func getP2PNodeFlag(cmd *cobra.Command) (string, bool, error) {
changed := cmd.Flags().Changed(FlagP2PNode)
val, err := cmd.Flags().GetString(FlagP2PNode)
if err != nil {
return "", changed, err
}
return val, changed, nil
}
1 change: 1 addition & 0 deletions cmd/blobstream/relayer/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ func Start() *cobra.Command {
logger,
retrier,
s.SignatureStore,
time.Duration(config.EVMRetryTimeout)*time.Minute,
)

// Listen for and trap any OS signal to graceful shutdown and exit
Expand Down
Loading

0 comments on commit 415a6d1

Please sign in to comment.