mirror of https://github.com/poanetwork/gecko.git
removed xputtests to get the build to pass
This commit is contained in:
parent
b004e9a014
commit
34909f72f5
13
node/node.go
13
node/node.go
|
@ -120,19 +120,20 @@ func (n *Node) initNetworking() error {
|
|||
|
||||
var serverUpgrader, clientUpgrader network.Upgrader
|
||||
if n.Config.EnableStaking {
|
||||
// TODO: this TLS config will never accept a connection because the cert pool is empty.
|
||||
cert, err := tls.LoadX509KeyPair(n.Config.StakingCertFile, n.Config.StakingKeyFile)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
certPool := x509.NewCertPool()
|
||||
tlsConfig := &tls.Config{
|
||||
Certificates: []tls.Certificate{cert},
|
||||
RootCAs: certPool,
|
||||
ServerName: "ava",
|
||||
ClientAuth: tls.RequireAndVerifyClientCert,
|
||||
ClientCAs: certPool,
|
||||
ClientAuth: tls.RequireAnyClientCert,
|
||||
// We do not use TLS's CA functionality, we just require an
|
||||
// authenticated channel. Therefore, we can safely skip verification
|
||||
// here.
|
||||
//
|
||||
// TODO: Security audit required
|
||||
InsecureSkipVerify: true,
|
||||
}
|
||||
|
||||
serverUpgrader = network.NewTLSServerUpgrader(tlsConfig)
|
||||
|
|
|
@ -36,9 +36,8 @@ else
|
|||
fi
|
||||
|
||||
go build -o "$PREFIX/ava" "$GECKO_PATH/main/"*.go
|
||||
go build -o "$PREFIX/xputtest" "$GECKO_PATH/xputtest/"*.go
|
||||
go build -o "$PLUGIN_PREFIX/evm" "$CORETH_PATH/plugin/"*.go
|
||||
if [[ -f "$PREFIX/ava" && -f "$PREFIX/xputtest" && -f "$PLUGIN_PREFIX/evm" ]]; then
|
||||
if [[ -f "$PREFIX/ava" && -f "$PLUGIN_PREFIX/evm" ]]; then
|
||||
echo "Build Successful"
|
||||
else
|
||||
echo "Build failure"
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
# Throughput testing
|
||||
|
||||
A throughput test is run in two parts. First a network must be running with at least one of the nodes running a throughput server. To start a throughput server when running a node the `--xput-server-enabled=true` flag should be passed.
|
||||
|
||||
An example single node network can be started with:
|
||||
|
||||
```sh
|
||||
./build/ava --public-ip=127.0.0.1 --xput-server-port=9652 --xput-server-enabled=true --db-enabled=false --staking-tls-enabled=false --snow-sample-size=1 --snow-quorum-size=1
|
||||
```
|
||||
|
||||
The thoughput node can be started with:
|
||||
|
||||
```sh
|
||||
./build/xputtest --ip=127.0.0.1 --port=9652 --sp-chain
|
||||
```
|
||||
|
||||
The above example with run a throughput test on the simple payment chain. Tests can be run with `--sp-dag` to run throughput tests on the simple payment dag. Tests can be run with `--avm` to run throughput tests on the AVA virtual machine.
|
108
xputtest/avm.go
108
xputtest/avm.go
|
@ -1,108 +0,0 @@
|
|||
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/ava-labs/salticidae-go"
|
||||
|
||||
"github.com/ava-labs/gecko/ids"
|
||||
"github.com/ava-labs/gecko/networking"
|
||||
"github.com/ava-labs/gecko/utils/crypto"
|
||||
"github.com/ava-labs/gecko/utils/timer"
|
||||
"github.com/ava-labs/gecko/vms/avm"
|
||||
"github.com/ava-labs/gecko/vms/platformvm"
|
||||
"github.com/ava-labs/gecko/xputtest/avmwallet"
|
||||
)
|
||||
|
||||
// benchmark an instance of the avm
|
||||
func (n *network) benchmarkAVM(chain *platformvm.CreateChainTx) {
|
||||
genesisBytes := chain.GenesisData
|
||||
wallet, err := avmwallet.NewWallet(n.log, n.networkID, chain.ID(), config.AvaTxFee)
|
||||
n.log.AssertNoError(err)
|
||||
|
||||
factory := crypto.FactorySECP256K1R{}
|
||||
sk, err := factory.ToPrivateKey(config.Key)
|
||||
n.log.AssertNoError(err)
|
||||
wallet.ImportKey(sk.(*crypto.PrivateKeySECP256K1R))
|
||||
|
||||
codec := wallet.Codec()
|
||||
|
||||
genesis := avm.Genesis{}
|
||||
n.log.AssertNoError(codec.Unmarshal(genesisBytes, &genesis))
|
||||
|
||||
genesisTx := genesis.Txs[0]
|
||||
tx := avm.Tx{
|
||||
UnsignedTx: &genesisTx.CreateAssetTx,
|
||||
}
|
||||
txBytes, err := codec.Marshal(&tx)
|
||||
n.log.AssertNoError(err)
|
||||
tx.Initialize(txBytes)
|
||||
|
||||
for _, utxo := range tx.UTXOs() {
|
||||
wallet.AddUTXO(utxo)
|
||||
}
|
||||
|
||||
assetID := genesisTx.ID()
|
||||
|
||||
n.log.AssertNoError(wallet.GenerateTxs(config.NumTxs, assetID))
|
||||
|
||||
go n.log.RecoverAndPanic(func() { n.IssueAVM(chain.ID(), assetID, wallet) })
|
||||
}
|
||||
|
||||
// issue transactions to the instance of the avm funded by the provided wallet
|
||||
func (n *network) IssueAVM(chainID ids.ID, assetID ids.ID, wallet *avmwallet.Wallet) {
|
||||
n.log.Debug("Issuing with %d", wallet.Balance(assetID))
|
||||
numAccepted := 0
|
||||
numPending := 0
|
||||
|
||||
n.decided <- ids.ID{}
|
||||
|
||||
// track the last second of transactions
|
||||
meter := timer.TimedMeter{Duration: time.Second}
|
||||
for d := range n.decided {
|
||||
// display the TPS every 1000 txs
|
||||
if numAccepted%1000 == 0 {
|
||||
n.log.Info("TPS: %d", meter.Ticks())
|
||||
}
|
||||
|
||||
// d is the ID of the tx that was accepted
|
||||
if !d.IsZero() {
|
||||
meter.Tick()
|
||||
n.log.Debug("Finalized %s", d)
|
||||
numAccepted++
|
||||
numPending--
|
||||
}
|
||||
|
||||
// Issue all the txs that we can right now
|
||||
for numPending < config.MaxOutstandingTxs && wallet.Balance(assetID) > 0 && numAccepted+numPending < config.NumTxs {
|
||||
tx := wallet.NextTx()
|
||||
n.log.AssertTrue(tx != nil, "Tx creation failed")
|
||||
|
||||
// send the IssueTx message
|
||||
it, err := n.build.IssueTx(chainID, tx.Bytes())
|
||||
n.log.AssertNoError(err)
|
||||
ds := it.DataStream()
|
||||
ba := salticidae.NewByteArrayMovedFromDataStream(ds, false)
|
||||
newMsg := salticidae.NewMsgMovedFromByteArray(networking.IssueTx, ba, false)
|
||||
|
||||
n.conn.GetNet().SendMsg(newMsg, n.conn)
|
||||
|
||||
ds.Free()
|
||||
ba.Free()
|
||||
newMsg.Free()
|
||||
|
||||
numPending++
|
||||
n.log.Debug("Sent tx, pending = %d, accepted = %d", numPending, numAccepted)
|
||||
}
|
||||
|
||||
// If we are done issuing txs, return from the function
|
||||
if numAccepted+numPending >= config.NumTxs {
|
||||
n.log.Info("done with test")
|
||||
net.ec.Stop()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package main
|
||||
|
||||
// ChainType ...
|
||||
type ChainType int
|
||||
|
||||
// Chain types
|
||||
const (
|
||||
unknown ChainType = iota
|
||||
spChain
|
||||
spDAG
|
||||
avmDAG
|
||||
)
|
|
@ -1,32 +0,0 @@
|
|||
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/ava-labs/gecko/utils"
|
||||
"github.com/ava-labs/gecko/utils/logging"
|
||||
)
|
||||
|
||||
// Config contains all of the configurations of an Ava client.
|
||||
type Config struct {
|
||||
// Networking configurations
|
||||
RemoteIP utils.IPDesc // Which Ava node to connect to
|
||||
|
||||
// ID of the network that this client will be issuing transactions to
|
||||
NetworkID uint32
|
||||
|
||||
// Transaction fee
|
||||
AvaTxFee uint64
|
||||
|
||||
EnableCrypto bool
|
||||
LoggingConfig logging.Config
|
||||
|
||||
// Key describes which key to use to issue transactions
|
||||
Key []byte
|
||||
|
||||
// NumTxs describes the number of transactions to issue
|
||||
// MaxOutstandingTxs describes how many txs to pipeline
|
||||
NumTxs, MaxOutstandingTxs int
|
||||
Chain ChainType
|
||||
}
|
|
@ -1,97 +0,0 @@
|
|||
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path"
|
||||
"runtime"
|
||||
"runtime/pprof"
|
||||
|
||||
"github.com/ava-labs/salticidae-go"
|
||||
|
||||
"github.com/ava-labs/gecko/genesis"
|
||||
"github.com/ava-labs/gecko/ids"
|
||||
"github.com/ava-labs/gecko/utils/crypto"
|
||||
"github.com/ava-labs/gecko/utils/logging"
|
||||
"github.com/ava-labs/gecko/vms/avm"
|
||||
"github.com/ava-labs/gecko/vms/spchainvm"
|
||||
"github.com/ava-labs/gecko/vms/spdagvm"
|
||||
)
|
||||
|
||||
func main() {
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to parse arguments: %s\n", err)
|
||||
}
|
||||
|
||||
// set up logging
|
||||
config.LoggingConfig.Directory = path.Join(config.LoggingConfig.Directory, "client")
|
||||
log, err := logging.New(config.LoggingConfig)
|
||||
if err != nil {
|
||||
fmt.Printf("Failed to start the logger: %s\n", err)
|
||||
return
|
||||
}
|
||||
|
||||
defer log.Stop()
|
||||
|
||||
// initialize state based on CLI args
|
||||
net.log = log
|
||||
crypto.EnableCrypto = config.EnableCrypto
|
||||
net.decided = make(chan ids.ID, config.MaxOutstandingTxs)
|
||||
|
||||
// Init the network
|
||||
log.AssertNoError(net.Initialize())
|
||||
|
||||
net.net.Start()
|
||||
defer net.net.Stop()
|
||||
|
||||
// connect to the node
|
||||
serr := salticidae.NewError()
|
||||
remoteIP := salticidae.NewNetAddrFromIPPortString(config.RemoteIP.String(), true, &serr)
|
||||
if code := serr.GetCode(); code != 0 {
|
||||
log.Fatal("Sync error %s", salticidae.StrError(serr.GetCode()))
|
||||
return
|
||||
}
|
||||
|
||||
net.conn = net.net.ConnectSync(remoteIP, true, &serr)
|
||||
if serr.GetCode() != 0 {
|
||||
log.Fatal("Sync error %s", salticidae.StrError(serr.GetCode()))
|
||||
return
|
||||
}
|
||||
|
||||
// start a cpu profile
|
||||
file, gErr := os.Create("cpu_client.profile")
|
||||
log.AssertNoError(gErr)
|
||||
gErr = pprof.StartCPUProfile(file)
|
||||
log.AssertNoError(gErr)
|
||||
runtime.SetMutexProfileFraction(1)
|
||||
|
||||
defer file.Close()
|
||||
defer pprof.StopCPUProfile()
|
||||
|
||||
net.networkID = config.NetworkID
|
||||
|
||||
// start the benchmark we want to run
|
||||
switch config.Chain {
|
||||
case spChain:
|
||||
tx, err := genesis.VMGenesis(config.NetworkID, spchainvm.ID)
|
||||
log.AssertNoError(err)
|
||||
net.benchmarkSPChain(tx)
|
||||
case spDAG:
|
||||
tx, err := genesis.VMGenesis(config.NetworkID, spdagvm.ID)
|
||||
log.AssertNoError(err)
|
||||
net.benchmarkSPChain(tx)
|
||||
case avmDAG:
|
||||
tx, err := genesis.VMGenesis(config.NetworkID, avm.ID)
|
||||
log.AssertNoError(err)
|
||||
net.benchmarkSPChain(tx)
|
||||
default:
|
||||
log.Fatal("did not specify whether to test dag or chain. Exiting")
|
||||
return
|
||||
}
|
||||
|
||||
// start processing network messages
|
||||
net.ec.Dispatch()
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package main
|
||||
|
||||
// #include "salticidae/network.h"
|
||||
// void onTerm(int sig, void *);
|
||||
// void decidedTx(msg_t *, msgnetwork_conn_t *, void *);
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"unsafe"
|
||||
|
||||
"github.com/ava-labs/salticidae-go"
|
||||
|
||||
"github.com/ava-labs/gecko/ids"
|
||||
"github.com/ava-labs/gecko/networking"
|
||||
"github.com/ava-labs/gecko/utils/logging"
|
||||
)
|
||||
|
||||
// network stores the persistent data needed when running the test.
|
||||
type network struct {
|
||||
ec salticidae.EventContext
|
||||
build networking.Builder
|
||||
|
||||
net salticidae.MsgNetwork
|
||||
conn salticidae.MsgNetworkConn
|
||||
|
||||
log logging.Logger
|
||||
decided chan ids.ID
|
||||
|
||||
networkID uint32
|
||||
}
|
||||
|
||||
var net = network{}
|
||||
|
||||
func (n *network) Initialize() error {
|
||||
n.ec = salticidae.NewEventContext()
|
||||
evInt := salticidae.NewSigEvent(n.ec, salticidae.SigEventCallback(C.onTerm), nil)
|
||||
evInt.Add(salticidae.SIGINT)
|
||||
evTerm := salticidae.NewSigEvent(n.ec, salticidae.SigEventCallback(C.onTerm), nil)
|
||||
evTerm.Add(salticidae.SIGTERM)
|
||||
|
||||
serr := salticidae.NewError()
|
||||
netconfig := salticidae.NewMsgNetworkConfig()
|
||||
n.net = salticidae.NewMsgNetwork(n.ec, netconfig, &serr)
|
||||
if serr.GetCode() != 0 {
|
||||
return fmt.Errorf("sync error %s", salticidae.StrError(serr.GetCode()))
|
||||
}
|
||||
|
||||
n.net.RegHandler(networking.DecidedTx, salticidae.MsgNetworkMsgCallback(C.decidedTx), nil)
|
||||
return nil
|
||||
}
|
||||
|
||||
//export onTerm
|
||||
func onTerm(C.int, unsafe.Pointer) {
|
||||
net.log.Info("Terminate signal received")
|
||||
net.ec.Stop()
|
||||
}
|
||||
|
||||
// decidedTx handles the recept of a decidedTx message
|
||||
//export decidedTx
|
||||
func decidedTx(_msg *C.struct_msg_t, _conn *C.struct_msgnetwork_conn_t, _ unsafe.Pointer) {
|
||||
msg := salticidae.MsgFromC(salticidae.CMsg(_msg))
|
||||
|
||||
pMsg, err := net.build.Parse(networking.DecidedTx, msg.GetPayloadByMove())
|
||||
if err != nil {
|
||||
net.log.Warn("Failed to parse DecidedTx message")
|
||||
return
|
||||
}
|
||||
|
||||
txID, err := ids.ToID(pMsg.Get(networking.TxID).([]byte))
|
||||
net.log.AssertNoError(err) // Length is checked in message parsing
|
||||
|
||||
net.log.Debug("Decided %s", txID)
|
||||
net.decided <- txID
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"flag"
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
stdnet "net"
|
||||
|
||||
"github.com/ava-labs/gecko/genesis"
|
||||
"github.com/ava-labs/gecko/utils"
|
||||
"github.com/ava-labs/gecko/utils/formatting"
|
||||
"github.com/ava-labs/gecko/utils/logging"
|
||||
"github.com/ava-labs/gecko/utils/wrappers"
|
||||
)
|
||||
|
||||
var (
|
||||
config Config
|
||||
err error
|
||||
)
|
||||
|
||||
// Parse the CLI arguments
|
||||
func init() {
|
||||
errs := &wrappers.Errs{}
|
||||
defer func() { err = errs.Err }()
|
||||
|
||||
loggingConfig, err := logging.DefaultConfig()
|
||||
errs.Add(err)
|
||||
|
||||
fs := flag.NewFlagSet("xputtest", flag.ContinueOnError)
|
||||
|
||||
// NetworkID:
|
||||
networkName := fs.String("network-id", genesis.LocalName, "Network ID this node will connect to")
|
||||
|
||||
// Ava fees:
|
||||
fs.Uint64Var(&config.AvaTxFee, "ava-tx-fee", 0, "Ava transaction fee, in $nAva")
|
||||
|
||||
// Assertions:
|
||||
fs.BoolVar(&loggingConfig.Assertions, "assertions-enabled", true, "Turn on assertion execution")
|
||||
|
||||
// Crypto:
|
||||
fs.BoolVar(&config.EnableCrypto, "signature-verification-enabled", true, "Turn on signature verification")
|
||||
|
||||
// Remote Server:
|
||||
ip := fs.String("ip", "127.0.0.1", "IP address of the remote server socket")
|
||||
port := fs.Uint("port", 9652, "Port of the remote server socket")
|
||||
|
||||
// Logging:
|
||||
logsDir := fs.String("log-dir", "", "Logging directory for Ava")
|
||||
logLevel := fs.String("log-level", "info", "The log level. Should be one of {all, debug, info, warn, error, fatal, off}")
|
||||
|
||||
// Test Variables:
|
||||
spchain := fs.Bool("sp-chain", false, "Execute simple payment chain transactions")
|
||||
spdag := fs.Bool("sp-dag", false, "Execute simple payment dag transactions")
|
||||
avm := fs.Bool("avm", false, "Execute avm transactions")
|
||||
key := fs.String("key", "", "Funded key in the genesis key to use to issue transactions")
|
||||
fs.IntVar(&config.NumTxs, "num-txs", 25000, "Total number of transaction to issue")
|
||||
fs.IntVar(&config.MaxOutstandingTxs, "max-outstanding", 1000, "Maximum number of transactions to leave outstanding")
|
||||
|
||||
ferr := fs.Parse(os.Args[1:])
|
||||
|
||||
if ferr == flag.ErrHelp {
|
||||
// display usage/help text and exit successfully
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
if ferr != nil {
|
||||
// other type of error occurred when parsing args
|
||||
os.Exit(2)
|
||||
}
|
||||
|
||||
networkID, err := genesis.NetworkID(*networkName)
|
||||
errs.Add(err)
|
||||
|
||||
config.NetworkID = networkID
|
||||
|
||||
// Remote:
|
||||
parsedIP := stdnet.ParseIP(*ip)
|
||||
if parsedIP == nil {
|
||||
errs.Add(fmt.Errorf("invalid IP Address %s", *ip))
|
||||
}
|
||||
config.RemoteIP = utils.IPDesc{
|
||||
IP: parsedIP,
|
||||
Port: uint16(*port),
|
||||
}
|
||||
|
||||
cb58 := formatting.CB58{}
|
||||
errs.Add(cb58.FromString(*key))
|
||||
config.Key = cb58.Bytes
|
||||
|
||||
// Logging:
|
||||
if *logsDir != "" {
|
||||
loggingConfig.Directory = *logsDir
|
||||
}
|
||||
level, err := logging.ToLevel(*logLevel)
|
||||
errs.Add(err)
|
||||
loggingConfig.LogLevel = level
|
||||
loggingConfig.DisplayLevel = level
|
||||
config.LoggingConfig = loggingConfig
|
||||
|
||||
// Test Variables:
|
||||
switch {
|
||||
case *spchain:
|
||||
config.Chain = spChain
|
||||
case *spdag:
|
||||
config.Chain = spDAG
|
||||
case *avm:
|
||||
config.Chain = avmDAG
|
||||
default:
|
||||
config.Chain = unknown
|
||||
}
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/ava-labs/salticidae-go"
|
||||
|
||||
"github.com/ava-labs/gecko/ids"
|
||||
"github.com/ava-labs/gecko/networking"
|
||||
"github.com/ava-labs/gecko/utils/crypto"
|
||||
"github.com/ava-labs/gecko/utils/timer"
|
||||
"github.com/ava-labs/gecko/vms/platformvm"
|
||||
"github.com/ava-labs/gecko/vms/spchainvm"
|
||||
"github.com/ava-labs/gecko/xputtest/chainwallet"
|
||||
)
|
||||
|
||||
// benchmark an instance of the sp chain
|
||||
func (n *network) benchmarkSPChain(chain *platformvm.CreateChainTx) {
|
||||
genesisBytes := chain.GenesisData
|
||||
wallet := chainwallet.NewWallet(n.log, n.networkID, chain.ID())
|
||||
|
||||
codec := spchainvm.Codec{}
|
||||
accounts, err := codec.UnmarshalGenesis(genesisBytes)
|
||||
n.log.AssertNoError(err)
|
||||
|
||||
factory := crypto.FactorySECP256K1R{}
|
||||
skGen, err := factory.ToPrivateKey(config.Key)
|
||||
n.log.AssertNoError(err)
|
||||
sk := skGen.(*crypto.PrivateKeySECP256K1R)
|
||||
wallet.ImportKey(sk)
|
||||
|
||||
for _, account := range accounts {
|
||||
wallet.AddAccount(account)
|
||||
break
|
||||
}
|
||||
|
||||
n.log.AssertNoError(wallet.GenerateTxs(config.NumTxs))
|
||||
|
||||
go n.log.RecoverAndPanic(func() { n.IssueSPChain(chain.ID(), wallet) })
|
||||
}
|
||||
|
||||
func (n *network) IssueSPChain(chainID ids.ID, wallet *chainwallet.Wallet) {
|
||||
n.log.Debug("Issuing with %d", wallet.Balance())
|
||||
numAccepted := 0
|
||||
numPending := 0
|
||||
|
||||
n.decided <- ids.ID{}
|
||||
|
||||
meter := timer.TimedMeter{Duration: time.Second}
|
||||
for d := range n.decided {
|
||||
if numAccepted%1000 == 0 {
|
||||
n.log.Info("TPS: %d", meter.Ticks())
|
||||
}
|
||||
if !d.IsZero() {
|
||||
meter.Tick()
|
||||
n.log.Debug("Finalized %s", d)
|
||||
numAccepted++
|
||||
numPending--
|
||||
}
|
||||
|
||||
for numPending < config.MaxOutstandingTxs && wallet.Balance() > 0 && numAccepted+numPending < config.NumTxs {
|
||||
tx := wallet.NextTx()
|
||||
n.log.AssertTrue(tx != nil, "Tx creation failed")
|
||||
|
||||
it, err := n.build.IssueTx(chainID, tx.Bytes())
|
||||
n.log.AssertNoError(err)
|
||||
ds := it.DataStream()
|
||||
ba := salticidae.NewByteArrayMovedFromDataStream(ds, false)
|
||||
newMsg := salticidae.NewMsgMovedFromByteArray(networking.IssueTx, ba, false)
|
||||
|
||||
n.conn.GetNet().SendMsg(newMsg, n.conn)
|
||||
|
||||
ds.Free()
|
||||
ba.Free()
|
||||
newMsg.Free()
|
||||
|
||||
numPending++
|
||||
n.log.Debug("Sent tx, pending = %d, accepted = %d", numPending, numAccepted)
|
||||
}
|
||||
if numAccepted+numPending >= config.NumTxs {
|
||||
n.log.Info("done with test")
|
||||
net.ec.Stop()
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
// (c) 2019-2020, Ava Labs, Inc. All rights reserved.
|
||||
// See the file LICENSE for licensing terms.
|
||||
|
||||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/ava-labs/salticidae-go"
|
||||
|
||||
"github.com/ava-labs/gecko/ids"
|
||||
"github.com/ava-labs/gecko/networking"
|
||||
"github.com/ava-labs/gecko/utils/crypto"
|
||||
"github.com/ava-labs/gecko/utils/timer"
|
||||
"github.com/ava-labs/gecko/vms/platformvm"
|
||||
"github.com/ava-labs/gecko/vms/spdagvm"
|
||||
"github.com/ava-labs/gecko/xputtest/dagwallet"
|
||||
)
|
||||
|
||||
// benchmark an instance of the sp dag
|
||||
func (n *network) benchmarkSPDAG(chain *platformvm.CreateChainTx) {
|
||||
genesisBytes := chain.GenesisData
|
||||
wallet := dagwallet.NewWallet(n.networkID, chain.ID(), config.AvaTxFee)
|
||||
|
||||
codec := spdagvm.Codec{}
|
||||
tx, err := codec.UnmarshalTx(genesisBytes)
|
||||
n.log.AssertNoError(err)
|
||||
|
||||
factory := crypto.FactorySECP256K1R{}
|
||||
skGen, err := factory.ToPrivateKey(config.Key)
|
||||
n.log.AssertNoError(err)
|
||||
sk := skGen.(*crypto.PrivateKeySECP256K1R)
|
||||
wallet.ImportKey(sk)
|
||||
|
||||
for _, utxo := range tx.UTXOs() {
|
||||
wallet.AddUTXO(utxo)
|
||||
}
|
||||
|
||||
go n.log.RecoverAndPanic(func() { n.IssueSPDAG(chain.ID(), wallet) })
|
||||
}
|
||||
|
||||
// issue transactions to the instance of the spdag funded by the provided wallet
|
||||
func (n *network) IssueSPDAG(chainID ids.ID, wallet *dagwallet.Wallet) {
|
||||
n.log.Info("starting avalanche benchmark")
|
||||
pending := make(map[[32]byte]*spdagvm.Tx)
|
||||
canAdd := []*spdagvm.Tx{}
|
||||
numAccepted := 0
|
||||
|
||||
n.decided <- ids.ID{}
|
||||
meter := timer.TimedMeter{Duration: time.Second}
|
||||
for d := range n.decided {
|
||||
if numAccepted%1000 == 0 {
|
||||
n.log.Info("TPS: %d", meter.Ticks())
|
||||
}
|
||||
if !d.IsZero() {
|
||||
meter.Tick()
|
||||
key := d.Key()
|
||||
if tx := pending[key]; tx != nil {
|
||||
canAdd = append(canAdd, tx)
|
||||
|
||||
n.log.Debug("Finalized %s", d)
|
||||
delete(pending, key)
|
||||
numAccepted++
|
||||
}
|
||||
}
|
||||
|
||||
for len(pending) < config.MaxOutstandingTxs && (wallet.Balance() > 0 || len(canAdd) > 0) {
|
||||
if wallet.Balance() == 0 {
|
||||
tx := canAdd[0]
|
||||
canAdd = canAdd[1:]
|
||||
|
||||
for _, utxo := range tx.UTXOs() {
|
||||
wallet.AddUTXO(utxo)
|
||||
}
|
||||
}
|
||||
|
||||
tx := wallet.Send(1, 0, wallet.GetAddress())
|
||||
n.log.AssertTrue(tx != nil, "Tx creation failed")
|
||||
|
||||
it, err := n.build.IssueTx(chainID, tx.Bytes())
|
||||
n.log.AssertNoError(err)
|
||||
ds := it.DataStream()
|
||||
ba := salticidae.NewByteArrayMovedFromDataStream(ds, false)
|
||||
newMsg := salticidae.NewMsgMovedFromByteArray(networking.IssueTx, ba, false)
|
||||
|
||||
n.conn.GetNet().SendMsg(newMsg, n.conn)
|
||||
|
||||
ds.Free()
|
||||
ba.Free()
|
||||
newMsg.Free()
|
||||
|
||||
pending[tx.ID().Key()] = tx
|
||||
n.log.Debug("Sent tx, pending = %d, accepted = %d", len(pending), numAccepted)
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue