Transaction Dependency

Enforce a transaction order on the VeChainThor blockchain.

Introduction

Set dependencies on your transactions to ensure the execution order meets your business needs. Transactions that specify a dependency with theDependOn field in the transaction model will not be executed until the required transaction is processed.

DependsOn

DependsOn stores the ID of the transaction on which the current transaction depends. In other words, the current transaction cannot be processed without the success of the transaction referred by DependsOn. Here by “success”, we mean that the referred transaction has been executed without state reversion.

Implementation

The validation logic below ensures that the DependsOn field of a transaction is enforced when validating transactions within a block (see function verifyBlock in $THORDIR/consensus/validator.go).

// check depended tx 
if dep := tx.DependsOn(); dep != nil { 
  found, reverted, err := findTx(*dep) 
  if err != nil { 
    return nil, nil, err 
  } 
  if !found { 
    return nil, nil, consensusError("tx dep broken") 
  } 
  if reverted { 
    return nil, nil, consensusError("tx dep reverted") 
  } 
}

This article provides additional information and a demonstration of DependsOn on the VeChainThor blockchain.

Last updated