Skip to content

Commit

Permalink
ledger: refactor maxPaysetHint -> avarageEncodedTxnSizeHint (#3162)
Browse files Browse the repository at this point in the history
## Summary

This refactoring would eliminate the need to change the maxPaysetHint while we modify the block size.

## Test Plan

Use existing tests.
  • Loading branch information
tsachiherman authored Oct 29, 2021
1 parent 9ca31f8 commit b8ac4ba
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions ledger/internal/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,11 @@ type LedgerForCowBase interface {
// ErrRoundZero is self-explanatory
var ErrRoundZero = errors.New("cannot start evaluator for round 0")

// maxPaysetHint makes sure that we don't allocate too much memory up front
// in the block evaluator, since there cannot reasonably be more than this
// many transactions in a block.
const maxPaysetHint = 20000
// averageEncodedTxnSizeHint is an estimation for the encoded transaction size
// which is used for preallocating memory upfront in the payset. Preallocating
// helps to avoid re-allocating storage during the evaluation/validation which
// is considerably slower.
const averageEncodedTxnSizeHint = 150

// asyncAccountLoadingThreadCount controls how many go routines would be used
// to load the account data before the Eval() start processing individual
Expand Down Expand Up @@ -481,6 +482,7 @@ func StartEvaluator(l LedgerForEvaluator, hdr bookkeeping.BlockHeader, evalOpts
// Preallocate space for the payset so that we don't have to
// dynamically grow a slice (if evaluating a whole block).
if evalOpts.PaysetHint > 0 {
maxPaysetHint := evalOpts.MaxTxnBytesPerBlock / averageEncodedTxnSizeHint
if evalOpts.PaysetHint > maxPaysetHint {
evalOpts.PaysetHint = maxPaysetHint
}
Expand Down

0 comments on commit b8ac4ba

Please sign in to comment.