Skip to content
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
2 changes: 1 addition & 1 deletion cmd/algoh/blockstats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestEventWithDetails(t *testing.T) {

// Create blocks with some senders in the payload.
makeStxnWithAddr := func(addr basics.Address) transactions.SignedTxnInBlock {
return transactions.SignedTxnInBlock{SignedTxnWithAD: transactions.SignedTxnWithAD{SignedTxn: transactions.SignedTxn{Txn: transactions.Transaction{Header: transactions.Header{Sender: addr}}}}}
return transactions.SignedTxnInBlock{SignedTxnWithAD: transactions.SignedTxn{Txn: transactions.Transaction{Header: transactions.Header{Sender: addr}}}.WithAD()}
}
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}
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}
Expand Down
19 changes: 7 additions & 12 deletions daemon/algod/api/server/v2/test/handlers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1261,17 +1261,12 @@ int 1`,
FailedAt: expectedFailedAt,
Txns: []v2.PreEncodedSimulateTxnResult{
{
Txn: makePendingTxnResponse(t, transactions.SignedTxnWithAD{
SignedTxn: stxns[0],
// expect no ApplyData info
}),
// expect no ApplyData info
Txn: makePendingTxnResponse(t, stxns[0].WithAD()),
AppBudgetConsumed: txnAppBudgetUsed[0],
},
{
Txn: makePendingTxnResponse(t, transactions.SignedTxnWithAD{
SignedTxn: stxns[1],
ApplyData: scenario.ExpectedSimulationAD,
}),
Txn: makePendingTxnResponse(t, stxns[1].WithAD(scenario.ExpectedSimulationAD)),
AppBudgetConsumed: txnAppBudgetUsed[1],
},
},
Expand Down Expand Up @@ -1997,7 +1992,7 @@ func addStateProof(blk bookkeeping.Block) bookkeeping.Block {
},
},
}
txnib := transactions.SignedTxnInBlock{SignedTxnWithAD: transactions.SignedTxnWithAD{SignedTxn: tx}}
txnib := transactions.SignedTxnInBlock{SignedTxnWithAD: tx.WithAD()}
blk.Payset = append(blk.Payset, txnib)

updatedStateProofTracking := bookkeeping.StateProofTrackingData{
Expand Down Expand Up @@ -2316,13 +2311,13 @@ func TestDeltasForTxnGroup(t *testing.T) {
blk2 := bookkeeping.BlockHeader{Round: 2}
delta1 := ledgercore.StateDelta{Hdr: &blk1}
delta2 := ledgercore.StateDelta{Hdr: &blk2, KvMods: map[string]ledgercore.KvValueDelta{"bx1": {Data: []byte("foobar")}}}
txn1 := transactions.SignedTxnWithAD{SignedTxn: transactions.SignedTxn{Txn: transactions.Transaction{Type: protocol.PaymentTx}}}
txn1 := transactions.SignedTxn{Txn: transactions.Transaction{Type: protocol.PaymentTx}}.WithAD()
groupID1, err := crypto.DigestFromString(crypto.Hash([]byte("hello")).String())
require.NoError(t, err)
txn2 := transactions.SignedTxnWithAD{SignedTxn: transactions.SignedTxn{Txn: transactions.Transaction{
txn2 := transactions.SignedTxn{Txn: transactions.Transaction{
Type: protocol.AssetTransferTx,
Header: transactions.Header{Group: groupID1}},
}}
}.WithAD()

tracer := eval.MakeTxnGroupDeltaTracer(2)
handlers := v2.Handlers{
Expand Down
4 changes: 1 addition & 3 deletions data/bookkeeping/encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ func TestBlockWithTxnEncoding(t *testing.T) {
var b Block
b.Payset = []transactions.SignedTxnInBlock{
{
SignedTxnWithAD: transactions.SignedTxnWithAD{
SignedTxn: sigtxn,
},
SignedTxnWithAD: sigtxn.WithAD(),
},
}
enc := protocol.Encode(&b)
Expand Down
4 changes: 1 addition & 3 deletions data/ledger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,7 @@ func TestLedgerCirculation(t *testing.T) {
tx.Type = protocol.PaymentTx
signedTx := tx.Sign(srcAccountKey)
blk.Payset = transactions.Payset{transactions.SignedTxnInBlock{
SignedTxnWithAD: transactions.SignedTxnWithAD{
SignedTxn: signedTx,
},
SignedTxnWithAD: signedTx.WithAD(),
}}
require.NoError(t, l.AddBlock(blk, agreement.Certificate{}))
l.WaitForCommit(rnd)
Expand Down
5 changes: 2 additions & 3 deletions data/pools/transactionPool.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@ type BlockEvaluator interface {
TestTransactionGroup(txgroup []transactions.SignedTxn) error
Round() basics.Round
PaySetSize() int
TransactionGroup(txads []transactions.SignedTxnWithAD) error
Transaction(txn transactions.SignedTxn, ad transactions.ApplyData) error
TransactionGroup(txads ...transactions.SignedTxnWithAD) error
GenerateBlock(addrs []basics.Address) (*ledgercore.UnfinishedBlock, error)
ResetTxnBytes()
}
Expand Down Expand Up @@ -616,7 +615,7 @@ func (pool *TransactionPool) addToPendingBlockEvaluatorOnce(txgroup []transactio
transactionGroupStartsTime = time.Now()
}

err := pool.pendingBlockEvaluator.TransactionGroup(txgroupad)
err := pool.pendingBlockEvaluator.TransactionGroup(txgroupad...)

if recomputing {
if !pool.assemblyResults.assemblyCompletedOrAbandoned {
Expand Down
8 changes: 4 additions & 4 deletions data/pools/transactionPool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ func TestRememberForget(t *testing.T) {
tx.Note[1] = byte(j)
signedTx := tx.Sign(secrets[i])
transactionPool.RememberOne(signedTx)
err := eval.Transaction(signedTx, transactions.ApplyData{})
err := eval.TransactionGroup(signedTx.WithAD())
require.NoError(t, err)
}
}
Expand Down Expand Up @@ -733,7 +733,7 @@ func TestFixOverflowOnNewBlock(t *testing.T) {
signedTx := tx.Sign(secrets[0])

blockEval := newBlockEvaluator(t, mockLedger)
err := blockEval.Transaction(signedTx, transactions.ApplyData{})
err := blockEval.TransactionGroup(signedTx.WithAD())
require.NoError(t, err)

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

err = eval.Transaction(stxn, transactions.ApplyData{})
err = eval.TransactionGroup(stxn.WithAD())
require.NoError(t, err)

err = transactionPool.RememberOne(stxn)
Expand Down
4 changes: 2 additions & 2 deletions data/transactions/logic/blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ func TestNewAppEvalParams(t *testing.T) {
Sender: basics.Address{1, 2, 3, 4},
Receiver: basics.Address{4, 3, 2, 1},
Amount: 100,
}.SignedTxnWithAD()
}.SignedTxn().WithAD()

appcall1 := txntest.Txn{
Type: protocol.ApplicationCallTx,
Sender: basics.Address{1, 2, 3, 4},
ApplicationID: basics.AppIndex(1),
}.SignedTxnWithAD()
}.SignedTxn().WithAD()

appcall2 := appcall1
appcall2.Txn.ApplicationID = basics.AppIndex(2)
Expand Down
4 changes: 2 additions & 2 deletions data/transactions/logic/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -2986,12 +2986,12 @@ func TxnFieldToTealValue(txn *transactions.Transaction, groupIndex int, field Tx
return basics.TealValue{}, fmt.Errorf("negative groupIndex %d", groupIndex)
}
var cx EvalContext
stxnad := &transactions.SignedTxnWithAD{SignedTxn: transactions.SignedTxn{Txn: *txn}}
stxnad := transactions.SignedTxn{Txn: *txn}.WithAD()
fs, ok := txnFieldSpecByField(field)
if !ok {
return basics.TealValue{}, fmt.Errorf("invalid field %s", field)
}
sv, err := cx.txnFieldToStack(stxnad, &fs, arrayFieldIdx, groupIndex, inner)
sv, err := cx.txnFieldToStack(&stxnad, &fs, arrayFieldIdx, groupIndex, inner)
return sv.ToTealValue(), err
}

Expand Down
4 changes: 1 addition & 3 deletions data/transactions/payset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ func generatePayset(txnCount, acctCount int) Payset {
stxnb := make([]SignedTxnInBlock, txnCount)
for i, stxn := range generateSignedTxns(txnCount, acctCount) {
stxnb[i] = SignedTxnInBlock{
SignedTxnWithAD: SignedTxnWithAD{
SignedTxn: stxn,
},
SignedTxnWithAD: stxn.WithAD(),
}
}
return Payset(stxnb)
Expand Down
12 changes: 12 additions & 0 deletions data/transactions/signedtxn.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,18 @@ func (s SignedTxn) ID() Txid {
return s.Txn.ID()
}

// WithAD returns a SignedTxnWithAD with an (optional) ApplyData.
func (s SignedTxn) WithAD(ad ...ApplyData) SignedTxnWithAD {
switch len(ad) {
case 0:
return SignedTxnWithAD{SignedTxn: s}
case 1:
return SignedTxnWithAD{SignedTxn: s, ApplyData: ad[0]}
default:
panic("WithAD called incorrectly")
}
}

// ID on SignedTxnInBlock should never be called, because the ID depends
// on the block from which this transaction will be decoded. By having
// a different return value from SignedTxn.ID(), we will catch errors at
Expand Down
7 changes: 0 additions & 7 deletions data/txntest/txn.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,13 +320,6 @@ func (tx Txn) SignedTxn() transactions.SignedTxn {
return transactions.SignedTxn{Txn: tx.Txn()}
}

// SignedTxnWithAD produces unsigned, transactions.SignedTxnWithAD
// from the fields in this Txn. This seemingly pointless operation
// exists, again, for convenience when driving tests.
func (tx Txn) SignedTxnWithAD() transactions.SignedTxnWithAD {
return transactions.SignedTxnWithAD{SignedTxn: tx.SignedTxn()}
}

// Group turns a list of Txns into a slice of SignedTxns with
// GroupIDs set properly to make them a transaction group. The input
// Txns are modified with the calculated GroupID.
Expand Down
6 changes: 2 additions & 4 deletions ledger/archival_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,11 +655,9 @@ func TestArchivalCreatables(t *testing.T) {

func makeSignedTxnInBlock(tx transactions.Transaction) transactions.SignedTxnInBlock {
return transactions.SignedTxnInBlock{
SignedTxnWithAD: transactions.SignedTxnWithAD{
SignedTxn: transactions.SignedTxn{
SignedTxnWithAD: transactions.SignedTxn{
Txn: tx,
},
},
}.WithAD(),
HasGenesisID: true,
}
}
Expand Down
22 changes: 5 additions & 17 deletions ledger/eval/eval.go
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ func (eval *BlockEvaluator) TestTransactionGroup(txgroup []transactions.SignedTx

var group transactions.TxGroup
for gi, txn := range txgroup {
err := eval.TestTransaction(txn)
err := eval.testTransaction(txn)
if err != nil {
return err
}
Expand Down Expand Up @@ -973,10 +973,10 @@ func (eval *BlockEvaluator) TestTransactionGroup(txgroup []transactions.SignedTx
return nil
}

// TestTransaction performs basic duplicate detection and well-formedness checks
// 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 *BlockEvaluator) testTransaction(txn transactions.SignedTxn) error {
// Transaction valid (not expired)?
err := eval.block.Alive(txn.Txn.Header)
if err != nil {
Expand All @@ -999,22 +999,10 @@ func (eval *BlockEvaluator) TestTransaction(txn transactions.SignedTxn) error {
return nil
}

// Transaction tentatively adds a new transaction as part of this block evaluation.
// If the transaction cannot be added to the block without violating some constraints,
// an error is returned and the block evaluator state is unchanged.
func (eval *BlockEvaluator) Transaction(txn transactions.SignedTxn, ad transactions.ApplyData) error {
return eval.TransactionGroup([]transactions.SignedTxnWithAD{
{
SignedTxn: txn,
ApplyData: ad,
},
})
}

// TransactionGroup tentatively adds a new transaction group as part of this block evaluation.
// If the transaction group cannot be added to the block without violating some constraints,
// an error is returned and the block evaluator state is unchanged.
func (eval *BlockEvaluator) TransactionGroup(txgroup []transactions.SignedTxnWithAD) (err error) {
func (eval *BlockEvaluator) TransactionGroup(txgroup ...transactions.SignedTxnWithAD) (err error) {
// Nothing to do if there are no transactions.
if len(txgroup) == 0 {
return nil
Expand Down Expand Up @@ -2168,7 +2156,7 @@ transactionGroupLoop:
}
}
}
err = eval.TransactionGroup(txgroup.TxnGroup)
err = eval.TransactionGroup(txgroup.TxnGroup...)
if err != nil {
return ledgercore.StateDelta{}, err
}
Expand Down
19 changes: 9 additions & 10 deletions ledger/eval/eval_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ ok:
if err != nil {
return eval, addrs[0], err
}
err = eval.TransactionGroup(g)
err = eval.TransactionGroup(g...)
return eval, addrs[0], err
}

Expand Down Expand Up @@ -221,12 +221,12 @@ func TestPrivateTransactionGroup(t *testing.T) {

var txgroup []transactions.SignedTxnWithAD
eval := BlockEvaluator{}
err := eval.TransactionGroup(txgroup)
err := eval.TransactionGroup(txgroup...)
require.NoError(t, err) // nothing to do, no problem

eval.proto = config.Consensus[protocol.ConsensusCurrentVersion]
txgroup = make([]transactions.SignedTxnWithAD, eval.proto.MaxTxGroupSize+1)
err = eval.TransactionGroup(txgroup)
err = eval.TransactionGroup(txgroup...)
require.ErrorContains(t, err, "group size")
}

Expand Down Expand Up @@ -399,7 +399,7 @@ int 1`,

require.Len(t, eval.block.Payset, 0)

err = eval.TransactionGroup(txgroup)
err = eval.TransactionGroup(txgroup...)
switch testCase.firstTxnBehavior {
case "approve":
if len(scenario.ExpectedError) != 0 {
Expand Down Expand Up @@ -666,7 +666,7 @@ func testnetFixupExecution(t *testing.T, headerRound basics.Round, poolBonus uin
},
}
st := txn.Sign(keys[0])
err = eval.Transaction(st, transactions.ApplyData{})
err = eval.TransactionGroup(st.WithAD())
require.NoError(t, err)

poolOld, err := eval.workaroundOverspentRewards(rewardPoolBalance, headerRound)
Expand Down Expand Up @@ -1420,12 +1420,11 @@ func TestAbsenteeChecks(t *testing.T) {
return pay(i, addrs[i]).Sign(keys[i])
}

require.NoError(t, blkEval.Transaction(selfpay(0), transactions.ApplyData{}))
require.NoError(t, blkEval.Transaction(selfpay(1), transactions.ApplyData{}))
require.NoError(t, blkEval.Transaction(selfpay(2), transactions.ApplyData{}))
require.NoError(t, blkEval.TransactionGroup(selfpay(0).WithAD()))
require.NoError(t, blkEval.TransactionGroup(selfpay(1).WithAD()))
require.NoError(t, blkEval.TransactionGroup(selfpay(2).WithAD()))
for i := 0; i < 32; i++ {
require.NoError(t, blkEval.Transaction(pay(0, basics.Address{byte(i << 3), 0xaa}).Sign(keys[0]),
transactions.ApplyData{}))
require.NoError(t, blkEval.TransactionGroup(pay(0, basics.Address{byte(i << 3), 0xaa}).Sign(keys[0]).WithAD()))
}

// Make sure we validate our block as well
Expand Down
2 changes: 1 addition & 1 deletion ledger/eval/evalindexer.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (eval *BlockEvaluator) ProcessBlockForIndexer(block *bookkeeping.Block) (le
}

for _, group := range paysetgroups {
err = eval.TransactionGroup(group)
err = eval.TransactionGroup(group...)
if err != nil {
return ledgercore.StateDelta{}, []transactions.SignedTxnInBlock{},
fmt.Errorf("ProcessBlockForIndexer() err: %w", err)
Expand Down
2 changes: 1 addition & 1 deletion ledger/eval/prefetcher/prefetcher_alignment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ func runEval(t *testing.T, l *prefetcherAlignmentTestLedger, txn transactions.Tr
eval, err := eval.StartEvaluator(l, block.BlockHeader, eval.EvaluatorOptions{})
require.NoError(t, err)

err = eval.TransactionGroup(makeGroupFromTxn(txn))
err = eval.TransactionGroup(makeGroupFromTxn(txn)...)
require.NoError(t, err)
}

Expand Down
7 changes: 2 additions & 5 deletions ledger/eval/txntracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ int 1`

require.Len(t, eval.block.Payset, 0)

err = eval.TransactionGroup(txgroup)
err = eval.TransactionGroup(txgroup...)
require.NoError(t, err)
require.Len(t, eval.block.Payset, 4)

Expand All @@ -226,10 +226,7 @@ int 1`
Fee: minFee,
GenesisHash: genHash,
}
secondTxGroup := transactions.WrapSignedTxnsWithAD([]transactions.SignedTxn{
secondPayTxn.Txn().Sign(keys[2]),
})
err = eval.TransactionGroup(secondTxGroup)
err = eval.TransactionGroup(secondPayTxn.Txn().Sign(keys[2]).WithAD())
require.NoError(t, err)

// Calculate expected balances dynamically based on proto.MinTxnFee
Expand Down
Loading