-
Notifications
You must be signed in to change notification settings - Fork 519
eval: split TestTransactionGroup from BlockEvaluator using TransactionGroupTester #5818
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
base: master
Are you sure you want to change the base?
Changes from all commits
f256c0d
b9bc394
7a5a883
a14f3a4
b09a797
38edb5c
59293c2
24bb98b
d04bda9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -904,10 +904,34 @@ func (eval *BlockEvaluator) ResetTxnBytes() { | |
| eval.blockTxBytes = 0 | ||
| } | ||
|
|
||
| // TestTransactionGroup is only called by tests. | ||
| func (eval *BlockEvaluator) TestTransactionGroup(txgroup []transactions.SignedTxn) error { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. then move it to eval_test.go? |
||
| return NewTransactionGroupTester(eval.proto, eval.specials, eval.block, eval.state.checkDup).TestTransactionGroup(txgroup) | ||
| } | ||
|
|
||
| // TransactionGroupTester performs basic transaction checks for well-formedness and duplicate detection. | ||
| type TransactionGroupTester struct { | ||
| proto config.ConsensusParams | ||
| specials transactions.SpecialAddresses | ||
| txnContext transactions.TxnContext | ||
| checkDup func(firstValid, lastValid basics.Round, txid transactions.Txid, txl ledgercore.Txlease) error | ||
| } | ||
|
|
||
| // NewTransactionGroupTester creates a new TransactionGroupTester for use in calling TestTransactionGroup. | ||
| func NewTransactionGroupTester(proto config.ConsensusParams, specials transactions.SpecialAddresses, txnContext transactions.TxnContext, checkDup func(firstValid, lastValid basics.Round, txid transactions.Txid, txl ledgercore.Txlease) error) *TransactionGroupTester { | ||
| return &TransactionGroupTester{ | ||
| proto: proto, | ||
| specials: specials, | ||
| txnContext: txnContext, | ||
| checkDup: checkDup, | ||
| } | ||
| } | ||
|
|
||
| // TestTransactionGroup performs basic duplicate detection and well-formedness checks | ||
| // on a transaction group, but does not actually add the transactions to the block | ||
| // evaluator, or modify the block evaluator state in any other visible way. | ||
| func (eval *BlockEvaluator) TestTransactionGroup(txgroup []transactions.SignedTxn) error { | ||
| // It uses a TestEvalContext to access needed recent ledger state. | ||
| func (eval TransactionGroupTester) TestTransactionGroup(txgroup []transactions.SignedTxn) error { | ||
| // Nothing to do if there are no transactions. | ||
| if len(txgroup) == 0 { | ||
| return nil | ||
|
|
@@ -966,9 +990,9 @@ func (eval *BlockEvaluator) TestTransactionGroup(txgroup []transactions.SignedTx | |
| // TestTransaction performs basic duplicate detection and well-formedness checks | ||
| // on a single transaction, but does not actually add the transaction to the block | ||
| // evaluator, or modify the block evaluator state in any other visible way. | ||
| func (eval *BlockEvaluator) TestTransaction(txn transactions.SignedTxn) error { | ||
| func (eval TransactionGroupTester) TestTransaction(txn transactions.SignedTxn) error { | ||
| // Transaction valid (not expired)? | ||
| err := txn.Txn.Alive(eval.block) | ||
| err := txn.Txn.Alive(eval.txnContext) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -981,7 +1005,8 @@ func (eval *BlockEvaluator) TestTransaction(txn transactions.SignedTxn) error { | |
|
|
||
| // Transaction already in the ledger? | ||
| txid := txn.ID() | ||
| err = eval.state.checkDup(txn.Txn.First(), txn.Txn.Last(), txid, ledgercore.Txlease{Sender: txn.Txn.Sender, Lease: txn.Txn.Lease}) | ||
| // BlockEvaluator.transaction will check again using cow.checkDup later, if the pool tries to add this transaction to the block. | ||
| err = eval.checkDup(txn.Txn.First(), txn.Txn.Last(), txid, ledgercore.Txlease{Sender: txn.Txn.Sender, Lease: txn.Txn.Lease}) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
@@ -1163,6 +1188,7 @@ func (eval *BlockEvaluator) transaction(txn transactions.SignedTxn, evalParams * | |
| } | ||
|
|
||
| // Transaction already in the ledger? | ||
| // this checks against the txns added to this evaluator; testTransaction currently only checks against committed txns. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
This is not 100% accurate, |
||
| err = cow.checkDup(txn.Txn.First(), txn.Txn.Last(), txid, ledgercore.Txlease{Sender: txn.Txn.Sender, Lease: txn.Txn.Lease}) | ||
| if err != nil { | ||
| return err | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.