service and command
This commit is contained in:
parent
582296fccd
commit
e441254891
@ -16,36 +16,42 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"sync"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/vulcanize/tx_spammer/pkg"
|
||||
)
|
||||
|
||||
// sendTxsCmd represents the sendTxs command
|
||||
var sendTxsCmd = &cobra.Command{
|
||||
Use: "sendTxs",
|
||||
Short: "A brief description of your command",
|
||||
Long: `A longer description that spans multiple lines and likely contains examples
|
||||
and usage of using your command. For example:
|
||||
|
||||
Cobra is a CLI library for Go that empowers applications.
|
||||
This application is a tool to generate the needed files
|
||||
to quickly create a Cobra application.`,
|
||||
Short: "send large volumes of different tx types to different nodes",
|
||||
Long: `Loads tx configuration from .toml config file
|
||||
Generates txs from configuration and sends them to designated node according to set frequency and number`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
fmt.Println("sendTxs called")
|
||||
sendTxs()
|
||||
},
|
||||
}
|
||||
|
||||
func sendTxs() {
|
||||
params, err := tx_spammer.NewTxParams()
|
||||
if err != nil {
|
||||
logWithCommand.Fatal(err)
|
||||
}
|
||||
txSpammer := tx_spammer.NewTxSpammer(params)
|
||||
wg := new(sync.WaitGroup)
|
||||
quitChan := make(chan bool)
|
||||
txSpammer.Loop(wg, quitChan)
|
||||
|
||||
shutdown := make(chan os.Signal)
|
||||
signal.Notify(shutdown, os.Interrupt)
|
||||
<-shutdown
|
||||
close(quitChan)
|
||||
wg.Wait()
|
||||
|
||||
}
|
||||
func init() {
|
||||
rootCmd.AddCommand(sendTxsCmd)
|
||||
|
||||
// Here you will define your flags and configuration settings.
|
||||
|
||||
// Cobra supports Persistent Flags which will work for this command
|
||||
// and all subcommands, e.g.:
|
||||
// sendTxsCmd.PersistentFlags().String("foo", "", "A help for foo")
|
||||
|
||||
// Cobra supports local flags which will only run when this command
|
||||
// is called directly, e.g.:
|
||||
// sendTxsCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
[eth]
|
||||
txs = ["L2ContractPutCall", "L2ContractGetCall"]
|
||||
txs = ["L2ContractDeployment", "L2ContractPutCall", "L2ContractGetCall"]
|
||||
|
||||
[L2ContractDeployment]
|
||||
type = "L2"
|
||||
@ -11,8 +11,8 @@
|
||||
data = ""
|
||||
senderKeyPath = ""
|
||||
writeSenderPath = ""
|
||||
frequency = 15
|
||||
totalNumber = 1500
|
||||
frequency = 1
|
||||
totalNumber = 1
|
||||
chainID = 420
|
||||
|
||||
[L2ContractPutCall]
|
||||
|
@ -19,58 +19,10 @@ package tx_spammer
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/ethereum/go-ethereum/common"
|
||||
"github.com/ethereum/go-ethereum/common/hexutil"
|
||||
"github.com/ethereum/go-ethereum/rpc"
|
||||
)
|
||||
|
||||
// SendTxArgs represents the arguments to submit a transaction
|
||||
type SendTxArgs struct {
|
||||
From common.MixedcaseAddress `json:"from"`
|
||||
To *common.MixedcaseAddress `json:"to"`
|
||||
Gas hexutil.Uint64 `json:"gas"`
|
||||
GasPrice hexutil.Big `json:"gasPrice"`
|
||||
Value hexutil.Big `json:"value"`
|
||||
Nonce hexutil.Uint64 `json:"nonce"`
|
||||
// We accept "data" and "input" for backwards-compatibility reasons.
|
||||
Data *hexutil.Bytes `json:"data"`
|
||||
Input *hexutil.Bytes `json:"input,omitempty"`
|
||||
}
|
||||
|
||||
/*
|
||||
// SendTransaction creates a transaction for the given argument, sign it and submit it to the
|
||||
// transaction pool.
|
||||
func (s *PublicTransactionPoolAPI) SendTransaction(ctx context.Context, args SendTxArgs) (common.Hash, error) {
|
||||
// Look up the wallet containing the requested signer
|
||||
account := accounts.Account{Address: args.From}
|
||||
|
||||
wallet, err := s.b.AccountManager().Find(account)
|
||||
if err != nil {
|
||||
return common.Hash{}, err
|
||||
}
|
||||
|
||||
if args.Nonce == nil {
|
||||
// Hold the addresse's mutex around signing to prevent concurrent assignment of
|
||||
// the same nonce to multiple accounts.
|
||||
s.nonceLock.LockAddr(args.From)
|
||||
defer s.nonceLock.UnlockAddr(args.From)
|
||||
}
|
||||
|
||||
// Set some sanity defaults and terminate on failure
|
||||
if err := args.setDefaults(ctx, s.b); err != nil {
|
||||
return common.Hash{}, err
|
||||
}
|
||||
// Assemble the transaction and sign with the wallet
|
||||
tx := args.toTransaction()
|
||||
|
||||
signed, err := wallet.SignTx(account, tx, s.b.ChainConfig().ChainID)
|
||||
if err != nil {
|
||||
return common.Hash{}, err
|
||||
}
|
||||
return SubmitTransaction(ctx, s.b, signed)
|
||||
}
|
||||
*/
|
||||
|
||||
type TxSender struct {
|
||||
TxGen *TxGenerator
|
||||
}
|
||||
@ -80,10 +32,15 @@ func NewTxSender(params []TxParams) *TxSender {
|
||||
TxGen: NewTxGenerator(params),
|
||||
}
|
||||
}
|
||||
func (s *TxSender) Send() <-chan error {
|
||||
func (s *TxSender) Send(quitChan <-chan bool) <-chan error {
|
||||
errChan := make(chan error)
|
||||
go func() {
|
||||
for s.TxGen.Next() {
|
||||
select {
|
||||
case <-quitChan:
|
||||
return
|
||||
default:
|
||||
}
|
||||
if err := sendRawTransaction(s.TxGen.Current()); err != nil {
|
||||
errChan <- err
|
||||
}
|
||||
@ -92,6 +49,7 @@ func (s *TxSender) Send() <-chan error {
|
||||
errChan <- s.TxGen.Error()
|
||||
}
|
||||
}()
|
||||
return errChan
|
||||
}
|
||||
|
||||
func sendRawTransaction(rpcClient *rpc.Client, txRlp []byte) error {
|
||||
|
@ -16,19 +16,39 @@
|
||||
|
||||
package tx_spammer
|
||||
|
||||
import "sync"
|
||||
import (
|
||||
"sync"
|
||||
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type Service interface {
|
||||
Loop(wg *sync.WaitGroup) error
|
||||
Loop(wg *sync.WaitGroup, quitChan <-chan bool)
|
||||
}
|
||||
|
||||
type Tx struct {
|
||||
Spammer *Sender
|
||||
Generator *TxGenerator
|
||||
Config *Config
|
||||
type Spammer struct {
|
||||
Sender *TxSender
|
||||
}
|
||||
|
||||
func NewTxSpammer(params []TxParams) (TxSpammer, error) {
|
||||
|
||||
return &txSpammer{}, nil
|
||||
func NewTxSpammer(params []TxParams) Service {
|
||||
return &Spammer{
|
||||
Sender: NewTxSender(params),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Spammer) Loop(wg *sync.WaitGroup, quitChan <-chan bool) {
|
||||
forwardQuit := make(chan bool)
|
||||
errChan := s.Sender.Send(forwardQuit)
|
||||
go func() {
|
||||
wg.Add(1)
|
||||
defer wg.Done()
|
||||
for {
|
||||
select {
|
||||
case err := <-errChan:
|
||||
logrus.Error(err)
|
||||
case forwardQuit <- <-quitChan:
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
34
pkg/util.go
34
pkg/util.go
@ -1,10 +1,27 @@
|
||||
// VulcanizeDB
|
||||
// Copyright © 2020 Vulcanize
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU Affero General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU Affero General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU Affero General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
package tx_spammer
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"math/big"
|
||||
|
||||
"github.com/ethereum/go-ethereum/core/types"
|
||||
"github.com/ethereum/go-ethereum/params"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
// ChainConfig returns the appropriate ethereum chain config for the provided chain id
|
||||
@ -16,9 +33,8 @@ func ChainConfig(chainID uint64) (*params.ChainConfig, error) {
|
||||
return params.TestnetChainConfig, nil // Ropsten
|
||||
case 4:
|
||||
return params.RinkebyChainConfig, nil
|
||||
case 5:
|
||||
case 5, 420:
|
||||
return params.GoerliChainConfig, nil
|
||||
case 420:
|
||||
default:
|
||||
return nil, fmt.Errorf("chain config for chainid %d not available", chainID)
|
||||
}
|
||||
@ -27,16 +43,10 @@ func ChainConfig(chainID uint64) (*params.ChainConfig, error) {
|
||||
// ChainConfig returns the appropriate ethereum chain config for the provided chain id
|
||||
func TxSigner(chainID uint64) (types.Signer, error) {
|
||||
switch chainID {
|
||||
case 1:
|
||||
return params.MainnetChainConfig, nil
|
||||
case 3:
|
||||
return params.TestnetChainConfig, nil // Ropsten
|
||||
case 4:
|
||||
return params.RinkebyChainConfig, nil
|
||||
case 5:
|
||||
return params.GoerliChainConfig, nil
|
||||
case 1, 3, 4, 5:
|
||||
return types.NewEIP155Signer(new(big.Int).SetUint64(chainID)), nil
|
||||
case 420:
|
||||
return types.NewOVMSigner(big.NewInt()), nil
|
||||
return types.NewOVMSigner(new(big.Int).SetUint64(chainID)), nil
|
||||
default:
|
||||
return nil, fmt.Errorf("chain config for chainid %d not available", chainID)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user