Skip to content

Commit

Permalink
Merge branch 'develop' into implementing_methods_eth_txpool
Browse files Browse the repository at this point in the history
  • Loading branch information
novosandara authored Mar 26, 2024
2 parents 3421560 + c282887 commit 1295b73
Show file tree
Hide file tree
Showing 35 changed files with 217 additions and 51 deletions.
10 changes: 10 additions & 0 deletions command/bridge/common/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"math/big"
"strings"
"time"

"github.com/spf13/cobra"
"github.com/umbracle/ethgo"
Expand Down Expand Up @@ -53,6 +54,7 @@ type BridgeParams struct {
PredicateAddr string
JSONRPCAddr string
ChildChainMintable bool
TxTimeout time.Duration
}

// RegisterCommonFlags registers common bridge flags to a given command
Expand Down Expand Up @@ -84,6 +86,14 @@ func (p *BridgeParams) RegisterCommonFlags(cmd *cobra.Command) {
false,
"flag indicating whether tokens originate from child chain",
)

cmd.Flags().DurationVar(
&p.TxTimeout,
cmdHelper.TxTimeoutFlag,
txrelayer.DefaultTimeoutTransactions,
cmdHelper.TxTimeoutDesc,
)

}

func (p *BridgeParams) Validate() error {
Expand Down
11 changes: 10 additions & 1 deletion command/bridge/deploy/deploy.go
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,13 @@ func GetCommand() *cobra.Command {
helper.ProxyContractsAdminDesc,
)

cmd.Flags().DurationVar(
&params.txTimeout,
cmdHelper.TxTimeoutFlag,
txrelayer.DefaultTimeoutTransactions,
cmdHelper.TxTimeoutDesc,
)

cmd.MarkFlagsMutuallyExclusive(helper.TestModeFlag, deployerKeyFlag)

return cmd
Expand Down Expand Up @@ -429,7 +436,9 @@ func runCommand(cmd *cobra.Command, _ []string) {
// deployContracts deploys and initializes rootchain smart contracts
func deployContracts(outputter command.OutputFormatter, client *jsonrpc.Client, chainID int64,
initialValidators []*validator.GenesisValidator, cmdCtx context.Context) (deploymentResultInfo, error) {
txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithClient(client), txrelayer.WithWriter(outputter))
txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithClient(client), txrelayer.WithWriter(outputter),
txrelayer.WithReceiptsTimeout(params.txTimeout))

if err != nil {
return deploymentResultInfo{RootchainCfg: nil, CommandResults: nil},
fmt.Errorf("failed to initialize tx relayer: %w", err)
Expand Down
2 changes: 2 additions & 0 deletions command/bridge/deploy/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"os"
"time"

"github.com/0xPolygon/polygon-edge/command/helper"
"github.com/0xPolygon/polygon-edge/consensus/polybft"
Expand All @@ -21,6 +22,7 @@ type deployParams struct {
jsonRPCAddress string
rootERC20TokenAddr string
proxyContractsAdmin string
txTimeout time.Duration
isTestMode bool
}

Expand Down
3 changes: 2 additions & 1 deletion command/bridge/deposit/erc1155/deposit_erc1155.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ func runCommand(cmd *cobra.Command, _ []string) {

depositorAddr := depositorKey.Address()

txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(dp.JSONRPCAddr))
txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(dp.JSONRPCAddr),
txrelayer.WithReceiptsTimeout(dp.TxTimeout))
if err != nil {
outputter.SetError(fmt.Errorf("failed to initialize tx relayer: %w", err))

Expand Down
3 changes: 2 additions & 1 deletion command/bridge/deposit/erc20/deposit_erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,8 @@ func runCommand(cmd *cobra.Command, _ []string) {

depositorAddr := depositorKey.Address()

txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(dp.JSONRPCAddr))
txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(dp.JSONRPCAddr),
txrelayer.WithReceiptsTimeout(dp.TxTimeout))
if err != nil {
outputter.SetError(fmt.Errorf("failed to initialize tx relayer: %w", err))

Expand Down
3 changes: 2 additions & 1 deletion command/bridge/deposit/erc721/deposit_erc721.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ func runCommand(cmd *cobra.Command, _ []string) {

depositorAddr := depositorKey.Address()

txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(dp.JSONRPCAddr))
txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(dp.JSONRPCAddr),
txrelayer.WithReceiptsTimeout(dp.TxTimeout))
if err != nil {
outputter.SetError(fmt.Errorf("failed to initialize tx relayer: %w", err))

Expand Down
12 changes: 11 additions & 1 deletion command/bridge/exit/exit.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"strconv"
"time"

"github.com/spf13/cobra"
"github.com/umbracle/ethgo/jsonrpc"
Expand Down Expand Up @@ -35,6 +36,7 @@ type exitParams struct {
exitID uint64
rootJSONRPCAddr string
childJSONRPCAddr string
txTimeout time.Duration
}

var (
Expand Down Expand Up @@ -85,6 +87,13 @@ func GetCommand() *cobra.Command {
"the JSON RPC child chain endpoint",
)

exitCmd.Flags().DurationVar(
&ep.txTimeout,
cmdHelper.TxTimeoutFlag,
txrelayer.DefaultTimeoutTransactions,
cmdHelper.TxTimeoutDesc,
)

_ = exitCmd.MarkFlagRequired(exitHelperFlag)

return exitCmd
Expand All @@ -101,7 +110,8 @@ func run(cmd *cobra.Command, _ []string) {
return
}

rootTxRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(ep.rootJSONRPCAddr))
rootTxRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(ep.rootJSONRPCAddr),
txrelayer.WithReceiptsTimeout(ep.txTimeout))
if err != nil {
outputter.SetError(fmt.Errorf("could not create root chain tx relayer: %w", err))

Expand Down
10 changes: 9 additions & 1 deletion command/bridge/finalize/finalize.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ func setFlags(cmd *cobra.Command) {
bridgeHelper.BladeManagerFlagDesc,
)

cmd.Flags().DurationVar(
&params.txTimeout,
helper.TxTimeoutFlag,
txrelayer.DefaultTimeoutTransactions,
helper.TxTimeoutDesc,
)

cmd.MarkFlagsMutuallyExclusive(polybftsecrets.AccountDirFlag, polybftsecrets.AccountConfigFlag)
cmd.MarkFlagsMutuallyExclusive(polybftsecrets.PrivateKeyFlag, polybftsecrets.AccountConfigFlag)
cmd.MarkFlagsMutuallyExclusive(polybftsecrets.PrivateKeyFlag, polybftsecrets.AccountDirFlag)
Expand All @@ -101,7 +108,8 @@ func runCommand(cmd *cobra.Command, _ []string) error {
return err
}

txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(params.jsonRPC))
txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(params.jsonRPC),
txrelayer.WithReceiptsTimeout(params.txTimeout))
if err != nil {
return fmt.Errorf("enlist validator failed: %w", err)
}
Expand Down
2 changes: 2 additions & 0 deletions command/bridge/finalize/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package finalize
import (
"fmt"
"os"
"time"

"github.com/0xPolygon/polygon-edge/command/helper"
validatorHelper "github.com/0xPolygon/polygon-edge/command/validator/helper"
Expand All @@ -16,6 +17,7 @@ type finalizeParams struct {
jsonRPC string
bladeManager string
genesisPath string
txTimeout time.Duration

bladeManagerAddr types.Address
}
Expand Down
11 changes: 10 additions & 1 deletion command/bridge/fund/fund.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

"github.com/0xPolygon/polygon-edge/command"
"github.com/0xPolygon/polygon-edge/command/bridge/helper"
cmdHelper "github.com/0xPolygon/polygon-edge/command/helper"
polybftsecrets "github.com/0xPolygon/polygon-edge/command/secrets/init"
"github.com/0xPolygon/polygon-edge/txrelayer"
"github.com/0xPolygon/polygon-edge/types"
Expand Down Expand Up @@ -60,6 +61,13 @@ func setFlags(cmd *cobra.Command) {
"",
polybftsecrets.PrivateKeyFlagDesc,
)

cmd.Flags().DurationVar(
&params.txTimeout,
cmdHelper.TxTimeoutFlag,
txrelayer.DefaultTimeoutTransactions,
cmdHelper.TxTimeoutDesc,
)
}

func preRunCommand(_ *cobra.Command, _ []string) error {
Expand All @@ -70,7 +78,8 @@ func runCommand(cmd *cobra.Command, _ []string) {
outputter := command.InitializeOutputter(cmd)
defer outputter.WriteOutput()

txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(params.jsonRPCAddress))
txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(params.jsonRPCAddress),
txrelayer.WithReceiptsTimeout(params.txTimeout))
if err != nil {
outputter.SetError(fmt.Errorf("failed to initialize tx relayer: %w", err))

Expand Down
7 changes: 4 additions & 3 deletions command/bridge/fund/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package fund
import (
"errors"
"math/big"
"time"

bridgeHelper "github.com/0xPolygon/polygon-edge/command/bridge/helper"
cmdhelper "github.com/0xPolygon/polygon-edge/command/helper"
Expand All @@ -24,9 +25,9 @@ type fundParams struct {
amounts []string
deployerPrivateKey string
jsonRPCAddress string

amountValues []*big.Int
addresses []types.Address
txTimeout time.Duration
amountValues []*big.Int
addresses []types.Address
}

func (fp *fundParams) validateFlags() error {
Expand Down
2 changes: 2 additions & 0 deletions command/bridge/premine/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"math/big"
"time"

"github.com/0xPolygon/polygon-edge/command/helper"
validatorHelper "github.com/0xPolygon/polygon-edge/command/validator/helper"
Expand All @@ -25,6 +26,7 @@ type premineParams struct {
jsonRPC string
stakedAmount string
premineAmount string
txTimeout time.Duration

premineAmountValue *big.Int
stakedValue *big.Int
Expand Down
9 changes: 8 additions & 1 deletion command/bridge/premine/premine.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ func setFlags(cmd *cobra.Command) {
"amount to premine as a staked balance",
)

cmd.Flags().DurationVar(
&params.txTimeout,
helper.TxTimeoutFlag,
150*time.Second,
helper.TxTimeoutDesc,
)

cmd.MarkFlagsMutuallyExclusive(polybftsecrets.AccountDirFlag, polybftsecrets.AccountConfigFlag)
cmd.MarkFlagsMutuallyExclusive(polybftsecrets.PrivateKeyFlag, polybftsecrets.AccountConfigFlag)
cmd.MarkFlagsMutuallyExclusive(polybftsecrets.PrivateKeyFlag, polybftsecrets.AccountDirFlag)
Expand All @@ -107,7 +114,7 @@ func runCommand(cmd *cobra.Command, _ []string) error {
}

txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(params.jsonRPC),
txrelayer.WithReceiptTimeout(150*time.Millisecond))
txrelayer.WithReceiptsTimeout(params.txTimeout))
if err != nil {
return err
}
Expand Down
3 changes: 2 additions & 1 deletion command/bridge/withdraw/erc1155/withdraw_erc1155.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ func runCommand(cmd *cobra.Command, _ []string) {
return
}

txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(wp.JSONRPCAddr))
txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(wp.JSONRPCAddr),
txrelayer.WithReceiptsTimeout(wp.TxTimeout))
if err != nil {
outputter.SetError(fmt.Errorf("could not create child chain tx relayer: %w", err))

Expand Down
3 changes: 2 additions & 1 deletion command/bridge/withdraw/erc20/withdraw_erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ func runCommand(cmd *cobra.Command, _ []string) {
return
}

txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(wp.JSONRPCAddr))
txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(wp.JSONRPCAddr),
txrelayer.WithReceiptsTimeout(wp.TxTimeout))
if err != nil {
outputter.SetError(fmt.Errorf("could not create destination chain tx relayer: %w", err))

Expand Down
3 changes: 2 additions & 1 deletion command/bridge/withdraw/erc721/withdraw_erc721.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ func run(cmd *cobra.Command, _ []string) {
return
}

txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(wp.JSONRPCAddr))
txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(wp.JSONRPCAddr),
txrelayer.WithReceiptsTimeout(wp.TxTimeout))
if err != nil {
outputter.SetError(fmt.Errorf("could not create child chain tx relayer: %w", err))

Expand Down
5 changes: 5 additions & 0 deletions command/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ import (
"google.golang.org/grpc/credentials/insecure"
)

const (
TxTimeoutDesc = "timeout for transaction processing wait"
TxTimeoutFlag = "tx-timeout"
)

var ErrBlockTrackerPollInterval = errors.New("block tracker poll interval must be greater than 0")

type ClientCloseResult struct {
Expand Down
10 changes: 9 additions & 1 deletion command/mint/mint_erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,22 @@ func setFlags(cmd *cobra.Command) {
"erc20 token address",
)

cmd.Flags().DurationVar(
&params.txTimeout,
helper.TxTimeoutFlag,
txrelayer.DefaultTimeoutTransactions,
helper.TxTimeoutDesc,
)

_ = cmd.MarkFlagRequired(bridgeHelper.Erc20TokenFlag)
}

func runCommand(cmd *cobra.Command, _ []string) {
outputter := command.InitializeOutputter(cmd)
defer outputter.WriteOutput()

txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(params.jsonRPCAddress))
txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(params.jsonRPCAddress),
txrelayer.WithReceiptsTimeout(params.txTimeout))
if err != nil {
outputter.SetError(fmt.Errorf("failed to initialize tx relayer: %w", err))

Expand Down
2 changes: 2 additions & 0 deletions command/mint/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"fmt"
"math/big"
"time"

rootHelper "github.com/0xPolygon/polygon-edge/command/bridge/helper"
"github.com/0xPolygon/polygon-edge/command/helper"
Expand All @@ -16,6 +17,7 @@ type mintParams struct {
tokenAddr string
minterPrivateKey string
jsonRPCAddress string
txTimeout time.Duration

amountValues []*big.Int
}
Expand Down
2 changes: 2 additions & 0 deletions command/validator/registration/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"errors"
"fmt"
"math/big"
"time"

"github.com/0xPolygon/polygon-edge/command/helper"
sidechainHelper "github.com/0xPolygon/polygon-edge/command/validator/helper"
Expand All @@ -18,6 +19,7 @@ type registerParams struct {
jsonRPC string
amount string
stakeToken string
txTimeout time.Duration

amountValue *big.Int
stakeTokenAddr types.Address
Expand Down
10 changes: 9 additions & 1 deletion command/validator/registration/register_validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,13 @@ func setFlags(cmd *cobra.Command) {
polybftsecrets.StakeTokenFlagDesc,
)

cmd.Flags().DurationVar(
&params.txTimeout,
helper.TxTimeoutFlag,
txrelayer.DefaultTimeoutTransactions,
helper.TxTimeoutDesc,
)

helper.RegisterJSONRPCFlag(cmd)
cmd.MarkFlagsMutuallyExclusive(polybftsecrets.AccountConfigFlag, polybftsecrets.AccountDirFlag)
}
Expand All @@ -85,7 +92,8 @@ func runCommand(cmd *cobra.Command, _ []string) error {
return err
}

txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(params.jsonRPC))
txRelayer, err := txrelayer.NewTxRelayer(txrelayer.WithIPAddress(params.jsonRPC),
txrelayer.WithReceiptsTimeout(params.txTimeout))
if err != nil {
return err
}
Expand Down
Loading

0 comments on commit 1295b73

Please sign in to comment.