Improved UX for xput tests

This commit is contained in:
StephenButtolph 2020-03-18 16:10:03 -04:00
parent 9da52187b1
commit ddf784284b
5 changed files with 64 additions and 22 deletions

View File

@ -22,7 +22,7 @@ import (
// benchmark an instance of the avm // benchmark an instance of the avm
func (n *network) benchmarkAVM(chain *platformvm.CreateChainTx) { func (n *network) benchmarkAVM(chain *platformvm.CreateChainTx) {
genesisBytes := chain.GenesisData genesisBytes := chain.GenesisData
wallet, err := avmwallet.NewWallet(n.networkID, chain.ID(), config.AvaTxFee) wallet, err := avmwallet.NewWallet(n.log, n.networkID, chain.ID(), config.AvaTxFee)
n.log.AssertNoError(err) n.log.AssertNoError(err)
cb58 := formatting.CB58{} cb58 := formatting.CB58{}
@ -106,6 +106,7 @@ func (n *network) IssueAVM(chainID ids.ID, assetID ids.ID, wallet *avmwallet.Wal
// If we are done issuing txs, return from the function // If we are done issuing txs, return from the function
if numAccepted+numPending >= config.NumTxs { if numAccepted+numPending >= config.NumTxs {
n.log.Info("done with test") n.log.Info("done with test")
net.ec.Stop()
return return
} }
} }

View File

@ -13,6 +13,7 @@ import (
"github.com/ava-labs/gecko/snow" "github.com/ava-labs/gecko/snow"
"github.com/ava-labs/gecko/utils/crypto" "github.com/ava-labs/gecko/utils/crypto"
"github.com/ava-labs/gecko/utils/hashing" "github.com/ava-labs/gecko/utils/hashing"
"github.com/ava-labs/gecko/utils/logging"
"github.com/ava-labs/gecko/utils/math" "github.com/ava-labs/gecko/utils/math"
"github.com/ava-labs/gecko/utils/timer" "github.com/ava-labs/gecko/utils/timer"
"github.com/ava-labs/gecko/utils/wrappers" "github.com/ava-labs/gecko/utils/wrappers"
@ -25,19 +26,23 @@ import (
type Wallet struct { type Wallet struct {
networkID uint32 networkID uint32
chainID ids.ID chainID ids.ID
clock timer.Clock
codec codec.Codec clock timer.Clock
keychain *secp256k1fx.Keychain // Mapping from public address to the SigningKeys codec codec.Codec
utxoSet *UTXOSet // Mapping from utxoIDs to UTXOs log logging.Logger
balance map[[32]byte]uint64
txFee uint64 keychain *secp256k1fx.Keychain // Mapping from public address to the SigningKeys
utxoSet *UTXOSet // Mapping from utxoIDs to UTXOs
balance map[[32]byte]uint64
txFee uint64
txsSent int32 txsSent int32
txs []*avm.Tx txs []*avm.Tx
} }
// NewWallet returns a new Wallet // NewWallet returns a new Wallet
func NewWallet(networkID uint32, chainID ids.ID, txFee uint64) (*Wallet, error) { func NewWallet(log logging.Logger, networkID uint32, chainID ids.ID, txFee uint64) (*Wallet, error) {
c := codec.NewDefault() c := codec.NewDefault()
errs := wrappers.Errs{} errs := wrappers.Errs{}
errs.Add( errs.Add(
@ -54,6 +59,7 @@ func NewWallet(networkID uint32, chainID ids.ID, txFee uint64) (*Wallet, error)
networkID: networkID, networkID: networkID,
chainID: chainID, chainID: chainID,
codec: c, codec: c,
log: log,
keychain: secp256k1fx.NewKeychain(), keychain: secp256k1fx.NewKeychain(),
utxoSet: &UTXOSet{}, utxoSet: &UTXOSet{},
balance: make(map[[32]byte]uint64), balance: make(map[[32]byte]uint64),
@ -249,10 +255,17 @@ func (w *Wallet) CreateTx(assetID ids.ID, amount uint64, destAddr ids.ShortID) (
// Generate them all on test initialization so tx generation is not bottleneck // Generate them all on test initialization so tx generation is not bottleneck
// in testing // in testing
func (w *Wallet) GenerateTxs(numTxs int, assetID ids.ID) error { func (w *Wallet) GenerateTxs(numTxs int, assetID ids.ID) error {
w.log.Info("Generating %d transactions", numTxs)
ctx := snow.DefaultContextTest() ctx := snow.DefaultContextTest()
ctx.NetworkID = w.networkID ctx.NetworkID = w.networkID
ctx.ChainID = w.chainID ctx.ChainID = w.chainID
frequency := numTxs / 50
if frequency > 1000 {
frequency = 1000
}
w.txs = make([]*avm.Tx, numTxs) w.txs = make([]*avm.Tx, numTxs)
for i := 0; i < numTxs; i++ { for i := 0; i < numTxs; i++ {
addr, err := w.CreateAddress() addr, err := w.CreateAddress()
@ -271,8 +284,14 @@ func (w *Wallet) GenerateTxs(numTxs int, assetID ids.ID) error {
w.AddUTXO(utxo) w.AddUTXO(utxo)
} }
if numGenerated := i + 1; numGenerated%frequency == 0 {
w.log.Info("Generated %d out of %d transactions", numGenerated, numTxs)
}
w.txs[i] = tx w.txs[i] = tx
} }
w.log.Info("Finished generating %d transactions", numTxs)
return nil return nil
} }

View File

@ -11,6 +11,7 @@ import (
"github.com/ava-labs/gecko/snow" "github.com/ava-labs/gecko/snow"
"github.com/ava-labs/gecko/utils/crypto" "github.com/ava-labs/gecko/utils/crypto"
"github.com/ava-labs/gecko/utils/formatting" "github.com/ava-labs/gecko/utils/formatting"
"github.com/ava-labs/gecko/utils/logging"
"github.com/ava-labs/gecko/utils/units" "github.com/ava-labs/gecko/utils/units"
"github.com/ava-labs/gecko/vms/avm" "github.com/ava-labs/gecko/vms/avm"
"github.com/ava-labs/gecko/vms/secp256k1fx" "github.com/ava-labs/gecko/vms/secp256k1fx"
@ -18,7 +19,7 @@ import (
func TestNewWallet(t *testing.T) { func TestNewWallet(t *testing.T) {
chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
w, err := NewWallet(12345, chainID, 0) w, err := NewWallet(logging.NoLog{}, 12345, chainID, 0)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -29,7 +30,7 @@ func TestNewWallet(t *testing.T) {
func TestWalletGetAddress(t *testing.T) { func TestWalletGetAddress(t *testing.T) {
chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
w, err := NewWallet(12345, chainID, 0) w, err := NewWallet(logging.NoLog{}, 12345, chainID, 0)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -45,7 +46,7 @@ func TestWalletGetAddress(t *testing.T) {
func TestWalletGetMultipleAddresses(t *testing.T) { func TestWalletGetMultipleAddresses(t *testing.T) {
chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
w, err := NewWallet(12345, chainID, 0) w, err := NewWallet(logging.NoLog{}, 12345, chainID, 0)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -65,7 +66,7 @@ func TestWalletGetMultipleAddresses(t *testing.T) {
func TestWalletEmptyBalance(t *testing.T) { func TestWalletEmptyBalance(t *testing.T) {
chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
w, err := NewWallet(12345, chainID, 0) w, err := NewWallet(logging.NoLog{}, 12345, chainID, 0)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -77,7 +78,7 @@ func TestWalletEmptyBalance(t *testing.T) {
func TestWalletAddUTXO(t *testing.T) { func TestWalletAddUTXO(t *testing.T) {
chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
w, err := NewWallet(12345, chainID, 0) w, err := NewWallet(logging.NoLog{}, 12345, chainID, 0)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -99,7 +100,7 @@ func TestWalletAddUTXO(t *testing.T) {
func TestWalletAddInvalidUTXO(t *testing.T) { func TestWalletAddInvalidUTXO(t *testing.T) {
chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
w, err := NewWallet(12345, chainID, 0) w, err := NewWallet(logging.NoLog{}, 12345, chainID, 0)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -118,7 +119,7 @@ func TestWalletAddInvalidUTXO(t *testing.T) {
func TestWalletCreateTx(t *testing.T) { func TestWalletCreateTx(t *testing.T) {
chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
w, err := NewWallet(12345, chainID, 0) w, err := NewWallet(logging.NoLog{}, 12345, chainID, 0)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -168,7 +169,7 @@ func TestWalletCreateTx(t *testing.T) {
func TestWalletImportKey(t *testing.T) { func TestWalletImportKey(t *testing.T) {
chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
w, err := NewWallet(12345, chainID, 0) w, err := NewWallet(logging.NoLog{}, 12345, chainID, 0)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -193,7 +194,7 @@ func TestWalletImportKey(t *testing.T) {
func TestWalletString(t *testing.T) { func TestWalletString(t *testing.T) {
chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) chainID := ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
w, err := NewWallet(12345, chainID, 0) w, err := NewWallet(logging.NoLog{}, 12345, chainID, 0)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }
@ -225,7 +226,7 @@ func TestWalletWithGenesis(t *testing.T) {
ctx.NetworkID = 12345 ctx.NetworkID = 12345
ctx.ChainID = ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}) ctx.ChainID = ids.NewID([32]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10})
w, err := NewWallet(ctx.NetworkID, ctx.ChainID, 0) w, err := NewWallet(logging.NoLog{}, ctx.NetworkID, ctx.ChainID, 0)
if err != nil { if err != nil {
t.Fatal(err) t.Fatal(err)
} }

View File

@ -10,13 +10,17 @@ import (
"github.com/ava-labs/gecko/ids" "github.com/ava-labs/gecko/ids"
"github.com/ava-labs/gecko/snow" "github.com/ava-labs/gecko/snow"
"github.com/ava-labs/gecko/utils/crypto" "github.com/ava-labs/gecko/utils/crypto"
"github.com/ava-labs/gecko/utils/logging"
"github.com/ava-labs/gecko/vms/spchainvm" "github.com/ava-labs/gecko/vms/spchainvm"
) )
// Wallet is a holder for keys and UTXOs. // Wallet is a holder for keys and UTXOs.
type Wallet struct { type Wallet struct {
networkID uint32 networkID uint32
chainID ids.ID chainID ids.ID
log logging.Logger
keychain *spchainvm.Keychain // Mapping from public address to the SigningKeys keychain *spchainvm.Keychain // Mapping from public address to the SigningKeys
accountSet map[[20]byte]spchainvm.Account // Mapping from addresses to accounts accountSet map[[20]byte]spchainvm.Account // Mapping from addresses to accounts
balance uint64 balance uint64
@ -25,10 +29,11 @@ type Wallet struct {
} }
// NewWallet ... // NewWallet ...
func NewWallet(networkID uint32, chainID ids.ID) *Wallet { func NewWallet(log logging.Logger, networkID uint32, chainID ids.ID) *Wallet {
return &Wallet{ return &Wallet{
networkID: networkID, networkID: networkID,
chainID: chainID, chainID: chainID,
log: log,
keychain: spchainvm.NewKeychain(networkID, chainID), keychain: spchainvm.NewKeychain(networkID, chainID),
accountSet: make(map[[20]byte]spchainvm.Account), accountSet: make(map[[20]byte]spchainvm.Account),
} }
@ -62,18 +67,33 @@ func (w *Wallet) Balance() uint64 { return w.balance }
// Generate them all on test initialization so tx generation is not bottleneck // Generate them all on test initialization so tx generation is not bottleneck
// in testing // in testing
func (w *Wallet) GenerateTxs(numTxs int) error { func (w *Wallet) GenerateTxs(numTxs int) error {
w.log.Info("Generating %d transactions", numTxs)
ctx := snow.DefaultContextTest() ctx := snow.DefaultContextTest()
ctx.NetworkID = w.networkID ctx.NetworkID = w.networkID
ctx.ChainID = w.chainID ctx.ChainID = w.chainID
frequency := numTxs / 50
if frequency > 1000 {
frequency = 1000
}
w.txs = make([]*spchainvm.Tx, numTxs) w.txs = make([]*spchainvm.Tx, numTxs)
for i := range w.txs { for i := range w.txs {
tx, err := w.MakeTx() tx, err := w.MakeTx()
if err != nil { if err != nil {
return err return err
} }
if numGenerated := i + 1; numGenerated%frequency == 0 {
w.log.Info("Generated %d out of %d transactions", numGenerated, numTxs)
}
w.txs[i] = tx w.txs[i] = tx
} }
w.log.Info("Finished generating %d transactions", numTxs)
return nil return nil
} }

View File

@ -22,7 +22,7 @@ import (
// benchmark an instance of the sp chain // benchmark an instance of the sp chain
func (n *network) benchmarkSPChain(chain *platformvm.CreateChainTx) { func (n *network) benchmarkSPChain(chain *platformvm.CreateChainTx) {
genesisBytes := chain.GenesisData genesisBytes := chain.GenesisData
wallet := chainwallet.NewWallet(n.networkID, chain.ID()) wallet := chainwallet.NewWallet(n.log, n.networkID, chain.ID())
codec := spchainvm.Codec{} codec := spchainvm.Codec{}
accounts, err := codec.UnmarshalGenesis(genesisBytes) accounts, err := codec.UnmarshalGenesis(genesisBytes)
@ -88,6 +88,7 @@ func (n *network) IssueSPChain(chainID ids.ID, wallet *chainwallet.Wallet) {
} }
if numAccepted+numPending >= config.NumTxs { if numAccepted+numPending >= config.NumTxs {
n.log.Info("done with test") n.log.Info("done with test")
net.ec.Stop()
return return
} }
} }