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

performance: Update two transaction verification benchmarks #4552

Merged
merged 2 commits into from
Sep 14, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 10 additions & 1 deletion data/bookkeeping/txn_merkle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ func BenchmarkTxnRoots(b *testing.B) {
crypto.RandBytes(txn.PaymentTxnFields.Receiver[:])

sigtxn := transactions.SignedTxn{Txn: txn}
crypto.RandBytes(sigtxn.Sig[:])
ad := transactions.ApplyData{}

stib, err := blk.BlockHeader.EncodeSignedTxn(sigtxn, ad)
Expand All @@ -173,7 +174,7 @@ func BenchmarkTxnRoots(b *testing.B) {
break
}
}

b.Logf("Made block with %d transactions and %d txn bytes", len(blk.Payset), len(protocol.Encode(blk.Payset)))
var r crypto.Digest

b.Run("FlatCommit", func(b *testing.B) {
Expand All @@ -192,6 +193,14 @@ func BenchmarkTxnRoots(b *testing.B) {
}
})

b.Run("SHA256MerkleCommit", func(b *testing.B) {
for i := 0; i < b.N; i++ {
var err error
r, err = blk.paysetCommitSHA256()
require.NoError(b, err)
}
})

_ = r
}

Expand Down
67 changes: 51 additions & 16 deletions data/txHandler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,15 @@ import (
"github.com/algorand/go-algorand/data/bookkeeping"
"github.com/algorand/go-algorand/data/pools"
"github.com/algorand/go-algorand/data/transactions"
"github.com/algorand/go-algorand/data/transactions/verify"
"github.com/algorand/go-algorand/logging"
"github.com/algorand/go-algorand/network"
"github.com/algorand/go-algorand/protocol"
"github.com/algorand/go-algorand/test/partitiontest"
"github.com/algorand/go-algorand/util/execpool"
)

func BenchmarkTxHandlerProcessDecoded(b *testing.B) {
b.StopTimer()
b.ResetTimer()
func BenchmarkTxHandlerProcessing(b *testing.B) {
const numUsers = 100
log := logging.TestingLog(b)
log.SetLevel(logging.Warn)
Expand Down Expand Up @@ -76,17 +75,20 @@ func BenchmarkTxHandlerProcessDecoded(b *testing.B) {

l := ledger

cfg.TxPoolSize = 20000
cfg.TxPoolSize = 75000
cfg.EnableProcessBlockStats = false
tp := pools.MakeTransactionPool(l.Ledger, cfg, logging.Base())
signedTransactions := make([]transactions.SignedTxn, 0, b.N)
for i := 0; i < b.N/numUsers; i++ {
for u := 0; u < numUsers; u++ {
backlogPool := execpool.MakeBacklog(nil, 0, execpool.LowPriority, nil)
txHandler := MakeTxHandler(tp, l, &mocks.MockNetwork{}, "", crypto.Digest{}, backlogPool)

makeTxns := func(N int) [][]transactions.SignedTxn {
ret := make([][]transactions.SignedTxn, 0, N)
for u := 0; u < N; u++ {
// generate transactions
tx := transactions.Transaction{
Type: protocol.PaymentTx,
Header: transactions.Header{
Sender: addresses[u],
Sender: addresses[u%numUsers],
Fee: basics.MicroAlgos{Raw: proto.MinTxnFee * 2},
FirstValid: 0,
LastValid: basics.Round(proto.MaxTxnLife),
Expand All @@ -97,17 +99,50 @@ func BenchmarkTxHandlerProcessDecoded(b *testing.B) {
Amount: basics.MicroAlgos{Raw: mockBalancesMinBalance + (rand.Uint64() % 10000)},
},
}
signedTx := tx.Sign(secrets[u])
signedTransactions = append(signedTransactions, signedTx)
signedTx := tx.Sign(secrets[u%numUsers])
ret = append(ret, []transactions.SignedTxn{signedTx})
}
return ret
}
backlogPool := execpool.MakeBacklog(nil, 0, execpool.LowPriority, nil)
txHandler := MakeTxHandler(tp, l, &mocks.MockNetwork{}, "", crypto.Digest{}, backlogPool)
b.StartTimer()
for _, signedTxn := range signedTransactions {
txHandler.processDecoded([]transactions.SignedTxn{signedTxn})
}

b.Run("processDecoded", func(b *testing.B) {
signedTransactionGroups := makeTxns(b.N)
b.ResetTimer()
for i := range signedTransactionGroups {
txHandler.processDecoded(signedTransactionGroups[i])
}
})
b.Run("verify.TxnGroup", func(b *testing.B) {
signedTransactionGroups := makeTxns(b.N)
b.ResetTimer()
// make a header including only the fields needed by PrepareGroupContext
hdr := bookkeeping.BlockHeader{}
hdr.FeeSink = basics.Address{}
hdr.RewardsPool = basics.Address{}
hdr.CurrentProtocol = protocol.ConsensusCurrentVersion
vtc := vtCache{}
b.Logf("verifying %d signedTransactionGroups", len(signedTransactionGroups))
b.ResetTimer()
for i := range signedTransactionGroups {
verify.TxnGroup(signedTransactionGroups[i], hdr, vtc, l)
}
})
}

// vtCache is a noop VerifiedTransactionCache
type vtCache struct{}

func (vtCache) Add(txgroup []transactions.SignedTxn, groupCtx *verify.GroupContext) {}
func (vtCache) AddPayset(txgroup [][]transactions.SignedTxn, groupCtxs []*verify.GroupContext) error {
return nil
}
func (vtCache) GetUnverifiedTranscationGroups(payset [][]transactions.SignedTxn, CurrSpecAddrs transactions.SpecialAddresses, CurrProto protocol.ConsensusVersion) [][]transactions.SignedTxn {
return nil
}
func (vtCache) UpdatePinned(pinnedTxns map[transactions.Txid]transactions.SignedTxn) error {
return nil
}
func (vtCache) Pin(txgroup []transactions.SignedTxn) error { return nil }

func BenchmarkTimeAfter(b *testing.B) {
b.StopTimer()
Expand Down