Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adds more configuration flags #556

Merged
merged 4 commits into from
Jul 24, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions e2e/qgb/deployer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ func TestDeployer(t *testing.T) {
HandleNetworkError(t, network, err, false)

// FIXME should we use the evm client here or go for raw queries?
evmClient := orchestrator.NewEvmClient(nil, bridge, nil, network.EVMRPC)
evmClient := orchestrator.NewEvmClient(nil, bridge, nil, network.EVMRPC, orchestrator.DEFAULTEVMGASLIMIT)
rach-id marked this conversation as resolved.
Show resolved Hide resolved

eventNonce, err := evmClient.StateLastEventNonce(&bind.CallOpts{Context: network.Context})
assert.NoError(t, err)
assert.Equal(t, uint64(0), eventNonce)
assert.Equal(t, uint64(1), eventNonce)
evan-forbes marked this conversation as resolved.
Show resolved Hide resolved
}
1 change: 1 addition & 0 deletions e2e/qgb/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ services:
- CELESTIA_GRPC=core0:9090
- EVM_CHAIN_ID=1234
- EVM_ENDPOINT=http://ganache:8545
- STARTING_NONCE=earliest
entrypoint: [
"/bin/bash"
]
Expand Down
2 changes: 1 addition & 1 deletion e2e/qgb/full_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestFullLongBehaviour(t *testing.T) {
bridge, err := network.GetLatestDeployedQGBContract(network.Context)
HandleNetworkError(t, network, err, false)

evmClient := orchestrator.NewEvmClient(nil, bridge, nil, network.EVMRPC)
evmClient := orchestrator.NewEvmClient(nil, bridge, nil, network.EVMRPC, orchestrator.DEFAULTEVMGASLIMIT)

// check whether the relayer relayed all attestations
eventNonce, err := evmClient.StateLastEventNonce(&bind.CallOpts{Context: network.Context})
Expand Down
6 changes: 3 additions & 3 deletions e2e/qgb/relayer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func TestRelayerWithOneValidator(t *testing.T) {
err = network.WaitForRelayerToStart(network.Context, bridge)
HandleNetworkError(t, network, err, false)

evmClient := orchestrator.NewEvmClient(nil, bridge, nil, network.EVMRPC)
evmClient := orchestrator.NewEvmClient(nil, bridge, nil, network.EVMRPC, orchestrator.DEFAULTEVMGASLIMIT)

vsNonce, err := evmClient.StateLastEventNonce(&bind.CallOpts{Context: ctx})
assert.NoError(t, err)
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestRelayerWithTwoValidators(t *testing.T) {
HandleNetworkError(t, network, err, false)

// FIXME should we use the evm client here or go for raw queries?
evmClient := orchestrator.NewEvmClient(nil, bridge, nil, network.EVMRPC)
evmClient := orchestrator.NewEvmClient(nil, bridge, nil, network.EVMRPC, orchestrator.DEFAULTEVMGASLIMIT)

dcNonce, err := evmClient.StateLastEventNonce(&bind.CallOpts{Context: ctx})
assert.NoError(t, err)
Expand Down Expand Up @@ -144,7 +144,7 @@ func TestRelayerWithMultipleValidators(t *testing.T) {
HandleNetworkError(t, network, err, false)

// FIXME should we use the evm client here or go for raw queries?
evmClient := orchestrator.NewEvmClient(nil, bridge, nil, network.EVMRPC)
evmClient := orchestrator.NewEvmClient(nil, bridge, nil, network.EVMRPC, orchestrator.DEFAULTEVMGASLIMIT)

dcNonce, err := evmClient.StateLastEventNonce(&bind.CallOpts{Context: ctx})
assert.NoError(t, err)
Expand Down
5 changes: 3 additions & 2 deletions e2e/qgb/scripts/deploy_qgb_contract.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ fi
# check if environment variables are set
if [[ -z "${EVM_CHAIN_ID}" || -z "${PRIVATE_KEY}" ]] || \
[[ -z "${TENDERMINT_RPC}" || -z "${CELESTIA_GRPC}" ]] || \
[[ -z "${EVM_ENDPOINT}" ]]
[[ -z "${EVM_ENDPOINT}" || -z "${STARTING_NONCE}" ]]
then
echo "Environment not setup correctly. Please set:"
echo "EVM_CHAIN_ID, PRIVATE_KEY, TENDERMINT_RPC, CELESTIA_GRPC, EVM_ENDPOINT variables"
echo "EVM_CHAIN_ID, PRIVATE_KEY, TENDERMINT_RPC, CELESTIA_GRPC, EVM_ENDPOINT, STARTING_NONCE variables"
exit 1
fi

Expand Down Expand Up @@ -59,6 +59,7 @@ echo "deploying QGB contract..."
-t ${TENDERMINT_RPC} \
-c ${CELESTIA_GRPC} \
-z ${EVM_CHAIN_ID} \
-n ${STARTING_NONCE} \
-e ${EVM_ENDPOINT} > /opt/output

echo $(cat /opt/output)
Expand Down
1 change: 1 addition & 0 deletions e2e/qgb/scripts/start_relayer.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ done
if [[ -z "${QGB_CONTRACT}" ]]
then
export DEPLOY_NEW_CONTRACT=true
export STARTING_NONCE=earliest
# expects the script to be mounted to this directory
/bin/bash /opt/deploy_qgb_contract.sh
fi
Expand Down
62 changes: 50 additions & 12 deletions x/qgb/orchestrator/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@ import (
"crypto/ecdsa"
"errors"
"fmt"
"github.com/spf13/cobra"
"log"
"os"
"path/filepath"

"github.com/spf13/cobra"

ethcmn "github.com/ethereum/go-ethereum/common"
ethcrypto "github.com/ethereum/go-ethereum/crypto"
)
Expand Down Expand Up @@ -40,7 +39,10 @@ const (
tendermintRPCFlag = "celes-http-rpc"
evmRPCFlag = "evm-rpc"

contractAddressFlag = "contract-address"
contractAddressFlag = "contract-address"
startingNonceFlag = "starting-nonce"
evmGasLimitFlag = "evm-gas-limit"
celestiaGasLimitFlag = "celestia-gas-limit"
)

func addOrchestratorFlags(cmd *cobra.Command) *cobra.Command {
Expand All @@ -61,6 +63,7 @@ func addOrchestratorFlags(cmd *cobra.Command) *cobra.Command {
"",
"Specify the ECDSA private key used to sign orchestrator commitments in hex",
)
cmd.Flags().Uint64P(celestiaGasLimitFlag, "l", DEFAULTCELESTIAGASLIMIT, "Specify the celestia gas limit")

return cmd
}
Expand All @@ -69,6 +72,7 @@ type orchestratorConfig struct {
keyringBackend, keyringPath, keyringAccount string
celestiaChainID, celesGRPC, tendermintRPC string
privateKey *ecdsa.PrivateKey
celestiaGasLimit uint64
}

func parseOrchestratorFlags(cmd *cobra.Command) (orchestratorConfig, error) {
Expand Down Expand Up @@ -107,15 +111,20 @@ func parseOrchestratorFlags(cmd *cobra.Command) (orchestratorConfig, error) {
if err != nil {
return orchestratorConfig{}, err
}
celestiaGasLimit, err := cmd.Flags().GetUint64(celestiaGasLimitFlag)
if err != nil {
return orchestratorConfig{}, err
}

return orchestratorConfig{
keyringBackend: keyringBackend,
keyringPath: keyringPath,
keyringAccount: keyringAccount,
privateKey: ethPrivKey,
celestiaChainID: chainID,
celesGRPC: celesGRPC,
tendermintRPC: tendermintRPC,
keyringBackend: keyringBackend,
keyringPath: keyringPath,
keyringAccount: keyringAccount,
privateKey: ethPrivKey,
celestiaChainID: chainID,
celesGRPC: celesGRPC,
tendermintRPC: tendermintRPC,
celestiaGasLimit: celestiaGasLimit,
}, nil
}

Expand All @@ -126,6 +135,7 @@ func addRelayerFlags(cmd *cobra.Command) *cobra.Command {
cmd.Flags().StringP(tendermintRPCFlag, "t", "http://localhost:26657", "Specify the rest rpc address")
cmd.Flags().StringP(evmRPCFlag, "e", "http://localhost:8545", "Specify the ethereum rpc address")
cmd.Flags().StringP(contractAddressFlag, "a", "", "Specify the contract at which the qgb is deployed")
cmd.Flags().Uint64P(evmGasLimitFlag, "l", DEFAULTEVMGASLIMIT, "Specify the evm gas limit")

return cmd
}
Expand All @@ -135,6 +145,7 @@ type relayerConfig struct {
evmRPC, celesGRPC, tendermintRPC string
privateKey *ecdsa.PrivateKey
contractAddr ethcmn.Address
evmGasLimit uint64
}

func parseRelayerFlags(cmd *cobra.Command) (relayerConfig, error) {
Expand Down Expand Up @@ -172,7 +183,11 @@ func parseRelayerFlags(cmd *cobra.Command) (relayerConfig, error) {
return relayerConfig{}, fmt.Errorf("valid contract address flag is required: %s", contractAddressFlag)
}
address := ethcmn.HexToAddress(contractAddr)
ethRpc, err := cmd.Flags().GetString(evmRPCFlag)
ethRPC, err := cmd.Flags().GetString(evmRPCFlag)
if err != nil {
return relayerConfig{}, err
}
evmGasLimit, err := cmd.Flags().GetUint64(evmGasLimitFlag)
if err != nil {
return relayerConfig{}, err
}
Expand All @@ -183,7 +198,8 @@ func parseRelayerFlags(cmd *cobra.Command) (relayerConfig, error) {
celesGRPC: celesGRPC,
tendermintRPC: tendermintRPC,
contractAddr: address,
evmRPC: ethRpc,
evmRPC: ethRPC,
evmGasLimit: evmGasLimit,
}, nil
}

Expand All @@ -194,6 +210,16 @@ func addDeployFlags(cmd *cobra.Command) *cobra.Command {
cmd.Flags().StringP(celesGRPCFlag, "c", "localhost:9090", "Specify the grpc address")
cmd.Flags().StringP(tendermintRPCFlag, "t", "http://localhost:26657", "Specify the rest rpc address")
cmd.Flags().StringP(evmRPCFlag, "e", "http://localhost:8545", "Specify the ethereum rpc address")
cmd.Flags().StringP(
startingNonceFlag,
"n",
"latest",
"Specify the nonce to start the QGB contract from. "+
"\"earliest\": for genesis, "+
"\"latest\": for latest valset nonce, "+
"\"nonce\": for the latest valset before the provided nonce, provided nonce included.",
)
cmd.Flags().Uint64P(evmGasLimitFlag, "l", DEFAULTEVMGASLIMIT, "Specify the evm gas limit")

return cmd
}
Expand All @@ -203,6 +229,8 @@ type deployConfig struct {
evmRPC, celesGRPC, tendermintRPC string
evmChainID uint64
privateKey *ecdsa.PrivateKey
startingNonce string
evmGasLimit uint64
}

func parseDeployFlags(cmd *cobra.Command) (deployConfig, error) {
Expand Down Expand Up @@ -237,6 +265,14 @@ func parseDeployFlags(cmd *cobra.Command) (deployConfig, error) {
if err != nil {
return deployConfig{}, err
}
startingNonce, err := cmd.Flags().GetString(startingNonceFlag)
if err != nil {
return deployConfig{}, err
}
evmGasLimit, err := cmd.Flags().GetUint64(evmGasLimitFlag)
if err != nil {
return deployConfig{}, err
}

return deployConfig{
privateKey: ethPrivKey,
Expand All @@ -245,5 +281,7 @@ func parseDeployFlags(cmd *cobra.Command) (deployConfig, error) {
celesGRPC: celesGRPC,
tendermintRPC: tendermintRPC,
evmRPC: evmRPC,
startingNonce: startingNonce,
evmGasLimit: evmGasLimit,
}, nil
}
45 changes: 38 additions & 7 deletions x/qgb/orchestrator/deploy_command.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package orchestrator

import (
"fmt"
"context"
"github.com/celestiaorg/celestia-app/x/qgb/types"
"github.com/cosmos/cosmos-sdk/types/errors"
"os"
"strconv"

"github.com/spf13/cobra"
tmlog "github.com/tendermint/tendermint/libs/log"
Expand All @@ -25,13 +28,11 @@ func DeployCmd() *cobra.Command {
return err
}

// TODO change to get the current valaset
// get the first valset
vs, err := querier.QueryValsetByNonce(cmd.Context(), 1)
vs, err := getStartingValset(cmd.Context(), querier, config.startingNonce)
if err != nil {
return fmt.Errorf(
return errors.Wrap(
err,
"cannot initialize the QGB contract without having a valset request: %s",
err.Error(),
)
}

Expand All @@ -40,13 +41,14 @@ func DeployCmd() *cobra.Command {
nil,
config.privateKey,
config.evmRPC,
config.evmGasLimit,
)

// the deploy QGB contract will handle the logging of the address
_, _, _, err = evmClient.DeployQGBContract(
cmd.Context(),
*vs,
0,
vs.Nonce,
config.evmChainID,
true,
false,
Expand All @@ -61,3 +63,32 @@ func DeployCmd() *cobra.Command {
}
return addDeployFlags(command)
}

func getStartingValset(ctx context.Context, q *querier, snonce string) (*types.Valset, error) {
switch snonce {
case "latest":
return q.QueryLatestValset(ctx)
case "earliest":
return q.QueryValsetByNonce(ctx, 1)
default:
nonce, err := strconv.ParseUint(snonce, 10, 0)
if err != nil {
return nil, err
}
attestation, err := q.QueryAttestationByNonce(ctx, nonce)
if err != nil {
return nil, err
}
if attestation == nil {
return nil, types.ErrNilAttestation
}
if attestation.Type() == types.ValsetRequestType {
value, ok := attestation.(*types.Valset)
if !ok {
return nil, ErrUnmarshallValset
}
return value, nil
}
return q.QueryLastValsetBeforeNonce(ctx, nonce)
}
}
10 changes: 7 additions & 3 deletions x/qgb/orchestrator/evm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/ethereum/go-ethereum/accounts/abi/bind"
)

const DEFAULTEVMGASLIMIT = uint64(25000000)

var _ EVMClient = &evmClient{}

type EVMClient interface {
Expand Down Expand Up @@ -50,6 +52,7 @@ type evmClient struct {
wrapper *wrapper.QuantumGravityBridge
privateKey *ecdsa.PrivateKey
evmRPC string
gasLimit uint64
}

// NewEvmClient Creates a new EVM Client that can be used to deploy the QGB contract and
Expand All @@ -60,12 +63,14 @@ func NewEvmClient(
wrapper *wrapper.QuantumGravityBridge,
privateKey *ecdsa.PrivateKey,
evmRPC string,
gasLimit uint64,
) *evmClient {
return &evmClient{
logger: logger,
wrapper: wrapper,
privateKey: privateKey,
evmRPC: evmRPC,
gasLimit: gasLimit,
}
}

Expand Down Expand Up @@ -137,8 +142,7 @@ func (ec *evmClient) UpdateValidatorSet(
) error {
// TODO in addition to the nonce, log more interesting information
ec.logger.Info("relaying valset", "nonce", newNonce)
// TODO gasLimit ?
opts, err := ec.NewTransactOpts(ctx, 1000000)
opts, err := ec.NewTransactOpts(ctx, ec.gasLimit)
if err != nil {
return err
}
Expand Down Expand Up @@ -195,7 +199,7 @@ func (ec *evmClient) SubmitDataRootTupleRoot(
sigs []wrapper.Signature,
waitToBeMined bool,
) error {
opts, err := ec.NewTransactOpts(ctx, 1000000)
opts, err := ec.NewTransactOpts(ctx, ec.gasLimit)
if err != nil {
return err
}
Expand Down
Loading