Skip to content

Commit 6ee2e7c

Browse files
authored
Chore: Eliminate BlockEvaluator.Transaction (#6515)
1 parent 3780647 commit 6ee2e7c

28 files changed

+74
-102
lines changed

cmd/algoh/blockstats_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ func TestEventWithDetails(t *testing.T) {
7777

7878
// Create blocks with some senders in the payload.
7979
makeStxnWithAddr := func(addr basics.Address) transactions.SignedTxnInBlock {
80-
return transactions.SignedTxnInBlock{SignedTxnWithAD: transactions.SignedTxnWithAD{SignedTxn: transactions.SignedTxn{Txn: transactions.Transaction{Header: transactions.Header{Sender: addr}}}}}
80+
return transactions.SignedTxnInBlock{SignedTxnWithAD: transactions.SignedTxn{Txn: transactions.Transaction{Header: transactions.Header{Sender: addr}}}.WithAD()}
8181
}
8282
addr := basics.Address{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}
8383
otherAddr := basics.Address{0x7, 0xda, 0xcb, 0x4b, 0x6d, 0x9e, 0xd1, 0x41, 0xb1, 0x75, 0x76, 0xbd, 0x45, 0x9a, 0xe6, 0x42, 0x1d, 0x48, 0x6d, 0xa3, 0xd4, 0xef, 0x22, 0x47, 0xc4, 0x9, 0xa3, 0x96, 0xb8, 0x2e, 0xa2, 0x21}

daemon/algod/api/server/v2/test/handlers_test.go

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,17 +1261,12 @@ int 1`,
12611261
FailedAt: expectedFailedAt,
12621262
Txns: []v2.PreEncodedSimulateTxnResult{
12631263
{
1264-
Txn: makePendingTxnResponse(t, transactions.SignedTxnWithAD{
1265-
SignedTxn: stxns[0],
1266-
// expect no ApplyData info
1267-
}),
1264+
// expect no ApplyData info
1265+
Txn: makePendingTxnResponse(t, stxns[0].WithAD()),
12681266
AppBudgetConsumed: txnAppBudgetUsed[0],
12691267
},
12701268
{
1271-
Txn: makePendingTxnResponse(t, transactions.SignedTxnWithAD{
1272-
SignedTxn: stxns[1],
1273-
ApplyData: scenario.ExpectedSimulationAD,
1274-
}),
1269+
Txn: makePendingTxnResponse(t, stxns[1].WithAD(scenario.ExpectedSimulationAD)),
12751270
AppBudgetConsumed: txnAppBudgetUsed[1],
12761271
},
12771272
},
@@ -1997,7 +1992,7 @@ func addStateProof(blk bookkeeping.Block) bookkeeping.Block {
19971992
},
19981993
},
19991994
}
2000-
txnib := transactions.SignedTxnInBlock{SignedTxnWithAD: transactions.SignedTxnWithAD{SignedTxn: tx}}
1995+
txnib := transactions.SignedTxnInBlock{SignedTxnWithAD: tx.WithAD()}
20011996
blk.Payset = append(blk.Payset, txnib)
20021997

20031998
updatedStateProofTracking := bookkeeping.StateProofTrackingData{
@@ -2316,13 +2311,13 @@ func TestDeltasForTxnGroup(t *testing.T) {
23162311
blk2 := bookkeeping.BlockHeader{Round: 2}
23172312
delta1 := ledgercore.StateDelta{Hdr: &blk1}
23182313
delta2 := ledgercore.StateDelta{Hdr: &blk2, KvMods: map[string]ledgercore.KvValueDelta{"bx1": {Data: []byte("foobar")}}}
2319-
txn1 := transactions.SignedTxnWithAD{SignedTxn: transactions.SignedTxn{Txn: transactions.Transaction{Type: protocol.PaymentTx}}}
2314+
txn1 := transactions.SignedTxn{Txn: transactions.Transaction{Type: protocol.PaymentTx}}.WithAD()
23202315
groupID1, err := crypto.DigestFromString(crypto.Hash([]byte("hello")).String())
23212316
require.NoError(t, err)
2322-
txn2 := transactions.SignedTxnWithAD{SignedTxn: transactions.SignedTxn{Txn: transactions.Transaction{
2317+
txn2 := transactions.SignedTxn{Txn: transactions.Transaction{
23232318
Type: protocol.AssetTransferTx,
23242319
Header: transactions.Header{Group: groupID1}},
2325-
}}
2320+
}.WithAD()
23262321

23272322
tracer := eval.MakeTxnGroupDeltaTracer(2)
23282323
handlers := v2.Handlers{

data/bookkeeping/encoding_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,7 @@ func TestBlockWithTxnEncoding(t *testing.T) {
5454
var b Block
5555
b.Payset = []transactions.SignedTxnInBlock{
5656
{
57-
SignedTxnWithAD: transactions.SignedTxnWithAD{
58-
SignedTxn: sigtxn,
59-
},
57+
SignedTxnWithAD: sigtxn.WithAD(),
6058
},
6159
}
6260
enc := protocol.Encode(&b)

data/ledger_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,7 @@ func TestLedgerCirculation(t *testing.T) {
190190
tx.Type = protocol.PaymentTx
191191
signedTx := tx.Sign(srcAccountKey)
192192
blk.Payset = transactions.Payset{transactions.SignedTxnInBlock{
193-
SignedTxnWithAD: transactions.SignedTxnWithAD{
194-
SignedTxn: signedTx,
195-
},
193+
SignedTxnWithAD: signedTx.WithAD(),
196194
}}
197195
require.NoError(t, l.AddBlock(blk, agreement.Certificate{}))
198196
l.WaitForCommit(rnd)

data/pools/transactionPool.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ type BlockEvaluator interface {
109109
TestTransactionGroup(txgroup []transactions.SignedTxn) error
110110
Round() basics.Round
111111
PaySetSize() int
112-
TransactionGroup(txads []transactions.SignedTxnWithAD) error
113-
Transaction(txn transactions.SignedTxn, ad transactions.ApplyData) error
112+
TransactionGroup(txads ...transactions.SignedTxnWithAD) error
114113
GenerateBlock(addrs []basics.Address) (*ledgercore.UnfinishedBlock, error)
115114
ResetTxnBytes()
116115
}
@@ -616,7 +615,7 @@ func (pool *TransactionPool) addToPendingBlockEvaluatorOnce(txgroup []transactio
616615
transactionGroupStartsTime = time.Now()
617616
}
618617

619-
err := pool.pendingBlockEvaluator.TransactionGroup(txgroupad)
618+
err := pool.pendingBlockEvaluator.TransactionGroup(txgroupad...)
620619

621620
if recomputing {
622621
if !pool.assemblyResults.assemblyCompletedOrAbandoned {

data/pools/transactionPool_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -565,7 +565,7 @@ func TestRememberForget(t *testing.T) {
565565
tx.Note[1] = byte(j)
566566
signedTx := tx.Sign(secrets[i])
567567
transactionPool.RememberOne(signedTx)
568-
err := eval.Transaction(signedTx, transactions.ApplyData{})
568+
err := eval.TransactionGroup(signedTx.WithAD())
569569
require.NoError(t, err)
570570
}
571571
}
@@ -733,7 +733,7 @@ func TestFixOverflowOnNewBlock(t *testing.T) {
733733
signedTx := tx.Sign(secrets[0])
734734

735735
blockEval := newBlockEvaluator(t, mockLedger)
736-
err := blockEval.Transaction(signedTx, transactions.ApplyData{})
736+
err := blockEval.TransactionGroup(signedTx.WithAD())
737737
require.NoError(t, err)
738738

739739
// simulate this transaction was applied
@@ -1272,7 +1272,7 @@ func BenchmarkTransactionPoolSteadyState(b *testing.B) {
12721272
eval := newBlockEvaluator(b, l)
12731273
for len(ledgerTxnQueue) > 0 {
12741274
stx := ledgerTxnQueue[0]
1275-
err := eval.Transaction(stx, transactions.ApplyData{})
1275+
err := eval.TransactionGroup(stx.WithAD())
12761276
if err == ledgercore.ErrNoSpace {
12771277
break
12781278
}
@@ -1522,7 +1522,7 @@ func TestStateProofLogging(t *testing.T) {
15221522
eval, err := mockLedger.StartEvaluator(b.BlockHeader, 0, 1000000, nil)
15231523
require.NoError(t, err)
15241524

1525-
err = eval.Transaction(stxn, transactions.ApplyData{})
1525+
err = eval.TransactionGroup(stxn.WithAD())
15261526
require.NoError(t, err)
15271527

15281528
err = transactionPool.RememberOne(stxn)

data/transactions/logic/blackbox_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ func TestNewAppEvalParams(t *testing.T) {
4343
Sender: basics.Address{1, 2, 3, 4},
4444
Receiver: basics.Address{4, 3, 2, 1},
4545
Amount: 100,
46-
}.SignedTxnWithAD()
46+
}.SignedTxn().WithAD()
4747

4848
appcall1 := txntest.Txn{
4949
Type: protocol.ApplicationCallTx,
5050
Sender: basics.Address{1, 2, 3, 4},
5151
ApplicationID: basics.AppIndex(1),
52-
}.SignedTxnWithAD()
52+
}.SignedTxn().WithAD()
5353

5454
appcall2 := appcall1
5555
appcall2.Txn.ApplicationID = basics.AppIndex(2)

data/transactions/logic/eval.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2986,12 +2986,12 @@ func TxnFieldToTealValue(txn *transactions.Transaction, groupIndex int, field Tx
29862986
return basics.TealValue{}, fmt.Errorf("negative groupIndex %d", groupIndex)
29872987
}
29882988
var cx EvalContext
2989-
stxnad := &transactions.SignedTxnWithAD{SignedTxn: transactions.SignedTxn{Txn: *txn}}
2989+
stxnad := transactions.SignedTxn{Txn: *txn}.WithAD()
29902990
fs, ok := txnFieldSpecByField(field)
29912991
if !ok {
29922992
return basics.TealValue{}, fmt.Errorf("invalid field %s", field)
29932993
}
2994-
sv, err := cx.txnFieldToStack(stxnad, &fs, arrayFieldIdx, groupIndex, inner)
2994+
sv, err := cx.txnFieldToStack(&stxnad, &fs, arrayFieldIdx, groupIndex, inner)
29952995
return sv.ToTealValue(), err
29962996
}
29972997

data/transactions/payset_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ func generatePayset(txnCount, acctCount int) Payset {
2727
stxnb := make([]SignedTxnInBlock, txnCount)
2828
for i, stxn := range generateSignedTxns(txnCount, acctCount) {
2929
stxnb[i] = SignedTxnInBlock{
30-
SignedTxnWithAD: SignedTxnWithAD{
31-
SignedTxn: stxn,
32-
},
30+
SignedTxnWithAD: stxn.WithAD(),
3331
}
3432
}
3533
return Payset(stxnb)

data/transactions/signedtxn.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,18 @@ func (s SignedTxn) ID() Txid {
6262
return s.Txn.ID()
6363
}
6464

65+
// WithAD returns a SignedTxnWithAD with an (optional) ApplyData.
66+
func (s SignedTxn) WithAD(ad ...ApplyData) SignedTxnWithAD {
67+
switch len(ad) {
68+
case 0:
69+
return SignedTxnWithAD{SignedTxn: s}
70+
case 1:
71+
return SignedTxnWithAD{SignedTxn: s, ApplyData: ad[0]}
72+
default:
73+
panic("WithAD called incorrectly")
74+
}
75+
}
76+
6577
// ID on SignedTxnInBlock should never be called, because the ID depends
6678
// on the block from which this transaction will be decoded. By having
6779
// a different return value from SignedTxn.ID(), we will catch errors at

0 commit comments

Comments
 (0)