Skip to content

Commit

Permalink
Introduce itxn to get inner transaction results (#2883)
Browse files Browse the repository at this point in the history
Increment TxnCounter with inner transactions

acfg and afrz inner transactions

This also sorts out inner txcounting, so that an innner transaction
knows the current txncount as it executes, so it can get the right id
if it creates.


Co-authored-by: Jason Paulos <[email protected]>
  • Loading branch information
jannotti and jasonpaulos authored Sep 14, 2021
1 parent 827ac62 commit 08d31fa
Show file tree
Hide file tree
Showing 33 changed files with 1,887 additions and 659 deletions.
8 changes: 4 additions & 4 deletions cmd/opdoc/opdoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,12 @@ func assetHoldingFieldsMarkdown(out io.Writer) {

func assetParamsFieldsMarkdown(out io.Writer) {
fmt.Fprintf(out, "\n`asset_params_get` Fields:\n\n")
fieldTableMarkdown(out, logic.AssetParamsFieldNames, logic.AssetParamsFieldTypes, logic.AssetParamsFieldDocs)
fieldTableMarkdown(out, logic.AssetParamsFieldNames, logic.AssetParamsFieldTypes, logic.AssetParamsFieldDocs())
}

func appParamsFieldsMarkdown(out io.Writer) {
fmt.Fprintf(out, "\n`app_params_get` Fields:\n\n")
fieldTableMarkdown(out, logic.AppParamsFieldNames, logic.AppParamsFieldTypes, logic.AppParamsFieldDocs)
fieldTableMarkdown(out, logic.AppParamsFieldNames, logic.AppParamsFieldTypes, logic.AppParamsFieldDocs())
}

func ecDsaCurvesMarkdown(out io.Writer) {
Expand Down Expand Up @@ -373,11 +373,11 @@ func main() {
assetholding.Close()

assetparams, _ := os.Create("asset_params_fields.md")
fieldTableMarkdown(assetparams, logic.AssetParamsFieldNames, logic.AssetParamsFieldTypes, logic.AssetParamsFieldDocs)
fieldTableMarkdown(assetparams, logic.AssetParamsFieldNames, logic.AssetParamsFieldTypes, logic.AssetParamsFieldDocs())
assetparams.Close()

appparams, _ := os.Create("app_params_fields.md")
fieldTableMarkdown(appparams, logic.AppParamsFieldNames, logic.AppParamsFieldTypes, logic.AppParamsFieldDocs)
fieldTableMarkdown(appparams, logic.AppParamsFieldNames, logic.AppParamsFieldTypes, logic.AppParamsFieldDocs())
appparams.Close()

langspecjs, _ := os.Create("langspec.json")
Expand Down
5 changes: 5 additions & 0 deletions config/consensus.go
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,11 @@ func initConsensusProtocols() {

// Enable App calls to pool budget in grouped transactions
vFuture.EnableAppCostPooling = true

// Enable Inner Transactions, and set maximum number. 0 value is
// disabled. Value > 0 also activates storage of creatable IDs in
// ApplyData, as that is required to support REST API when inner
// transactions are activated.
vFuture.MaxInnerTransactions = 16

// Allow 50 app opt ins
Expand Down
22 changes: 20 additions & 2 deletions daemon/algod/api/server/v1/handlers/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ func computeCreatableIndexInPayset(tx node.TxnWithStatus, txnCounter uint64, pay
// computeAssetIndexFromTxn returns the created asset index given a confirmed
// transaction whose confirmation block is available in the ledger. Note that
// 0 is an invalid asset index (they start at 1).
func computeAssetIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) (aidx uint64) {
func computeAssetIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) uint64 {
// Must have ledger
if l == nil {
return 0
Expand All @@ -413,6 +413,15 @@ func computeAssetIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) (aidx uint6
return 0
}

aidx := uint64(tx.ApplyData.ConfigAsset)
if aidx > 0 {
return aidx
}
// If there is no ConfigAsset in the ApplyData, it must be a
// transaction before inner transactions were activated. Therefore
// the computeCreatableIndexInPayset function will work properly
// to deduce the aid. Proceed.

// Look up block where transaction was confirmed
blk, err := l.Block(tx.ConfirmedRound)
if err != nil {
Expand All @@ -430,7 +439,7 @@ func computeAssetIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) (aidx uint6
// computeAppIndexFromTxn returns the created app index given a confirmed
// transaction whose confirmation block is available in the ledger. Note that
// 0 is an invalid asset index (they start at 1).
func computeAppIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) (aidx uint64) {
func computeAppIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) uint64 {
// Must have ledger
if l == nil {
return 0
Expand All @@ -448,6 +457,15 @@ func computeAppIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) (aidx uint64)
return 0
}

aidx := uint64(tx.ApplyData.ApplicationID)
if aidx > 0 {
return aidx
}
// If there is no ApplicationID in the ApplyData, it must be a
// transaction before inner transactions were activated. Therefore
// the computeCreatableIndexInPayset function will work properly
// to deduce the aidx. Proceed.

// Look up block where transaction was confirmed
blk, err := l.Block(tx.ConfirmedRound)
if err != nil {
Expand Down
33 changes: 26 additions & 7 deletions daemon/algod/api/server/v2/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func computeCreatableIndexInPayset(tx node.TxnWithStatus, txnCounter uint64, pay
// computeAssetIndexFromTxn returns the created asset index given a confirmed
// transaction whose confirmation block is available in the ledger. Note that
// 0 is an invalid asset index (they start at 1).
func computeAssetIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) (aidx *uint64) {
func computeAssetIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) *uint64 {
// Must have ledger
if l == nil {
return nil
Expand All @@ -128,6 +128,15 @@ func computeAssetIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) (aidx *uint
return nil
}

aid := uint64(tx.ApplyData.ConfigAsset)
if aid > 0 {
return &aid
}
// If there is no ConfigAsset in the ApplyData, it must be a
// transaction before inner transactions were activated. Therefore
// the computeCreatableIndexInPayset function will work properly
// to deduce the aid. Proceed.

// Look up block where transaction was confirmed
blk, err := l.Block(tx.ConfirmedRound)
if err != nil {
Expand All @@ -145,7 +154,7 @@ func computeAssetIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) (aidx *uint
// computeAppIndexFromTxn returns the created app index given a confirmed
// transaction whose confirmation block is available in the ledger. Note that
// 0 is an invalid asset index (they start at 1).
func computeAppIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) (aidx *uint64) {
func computeAppIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) *uint64 {
// Must have ledger
if l == nil {
return nil
Expand All @@ -163,6 +172,15 @@ func computeAppIndexFromTxn(tx node.TxnWithStatus, l *data.Ledger) (aidx *uint64
return nil
}

aid := uint64(tx.ApplyData.ApplicationID)
if aid > 0 {
return &aid
}
// If there is no ApplicationID in the ApplyData, it must be a
// transaction before inner transactions were activated. Therefore
// the computeCreatableIndexInPayset function will work properly
// to deduce the aid. Proceed.

// Look up block where transaction was confirmed
blk, err := l.Block(tx.ConfirmedRound)
if err != nil {
Expand Down Expand Up @@ -283,12 +301,12 @@ func convertLogs(txn node.TxnWithStatus) *[][]byte {
func convertInners(txn *node.TxnWithStatus) *[]preEncodedTxInfo {
inner := make([]preEncodedTxInfo, len(txn.ApplyData.EvalDelta.InnerTxns))
for i, itxn := range txn.ApplyData.EvalDelta.InnerTxns {
inner[i] = convertTxn(&itxn)
inner[i] = convertInnerTxn(&itxn)
}
return &inner
}

func convertTxn(txn *transactions.SignedTxnWithAD) preEncodedTxInfo {
func convertInnerTxn(txn *transactions.SignedTxnWithAD) preEncodedTxInfo {
// This copies from handlers.PendingTransactionInformation, with
// simplifications because we have a SignedTxnWithAD rather than
// TxnWithStatus, and we know this txn has committed.
Expand All @@ -301,9 +319,10 @@ func convertTxn(txn *transactions.SignedTxnWithAD) preEncodedTxInfo {
response.ReceiverRewards = &txn.ApplyData.ReceiverRewards.Raw
response.CloseRewards = &txn.ApplyData.CloseRewards.Raw

// Indexes can't be set until we allow acfg or appl
// response.AssetIndex = computeAssetIndexFromTxn(txn, v2.Node.Ledger())
// response.ApplicationIndex = computeAppIndexFromTxn(txn, v2.Node.Ledger())
// Since this is an inner txn, we know these indexes will be populated. No
// need to search payset for IDs
response.AssetIndex = numOrNil(uint64(txn.ApplyData.ConfigAsset))
response.ApplicationIndex = numOrNil(uint64(txn.ApplyData.ApplicationID))

// Deltas, Logs, and Inners can not be set until we allow appl
// response.LocalStateDelta, response.GlobalStateDelta = convertToDeltas(txn)
Expand Down
2 changes: 1 addition & 1 deletion data/pools/transactionPool.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ func (pool *TransactionPool) isAssemblyTimedOut() bool {
// we have no deadline, so no reason to timeout.
return false
}
generateBlockDuration := generateBlockBaseDuration + time.Duration(pool.pendingBlockEvaluator.TxnCounter())*generateBlockTransactionDuration
generateBlockDuration := generateBlockBaseDuration + time.Duration(pool.pendingBlockEvaluator.PaySetSize())*generateBlockTransactionDuration
return time.Now().After(pool.assemblyDeadline.Add(-generateBlockDuration))
}

Expand Down
Loading

0 comments on commit 08d31fa

Please sign in to comment.