cardano-sl-0.4.3: Cardano SL main implementation

Safe HaskellNone
LanguageHaskell2010

Pos.Txp

Contents

Description

Txp system reexports.

Synopsis

Documentation

txpGlobalSettings :: TxpGlobalSettings Source #

Settings used for global transactions data processing used by a simple full node.

Helpers

data ApplyBlocksSettings extra m Source #

Constructors

ApplyBlocksSettings 

Fields

genericToilModifierToBatch :: (e -> SomeBatchOp) -> GenericToilModifier e -> SomeBatchOp Source #

Convert GenericToilModifier to batch of database operations.

runToilAction :: (MonadDB m, Default e) => ToilT e (DBTxp m) a -> m (a, GenericToilModifier e) Source #

Run action which requires toil interfaces.

txProcessTransaction :: TxpLocalWorkMode m => (TxId, TxAux) -> m () Source #

txNormalize :: (MonadDB m, MonadTxpMem () m) => m () Source #

  1. Recompute UtxoView by current MemPool | 2. Remove invalid transactions from MemPool | 3. Set new tip to txp local data

type MonadTxpMem ext = MonadReader TxpHolderTag (GenericTxpLocalData ext) Source #

Reduced equivalent of MonadReader (GenericTxpLocalData mw) m.

data GenericTxpLocalData extra Source #

LocalData of transactions processing. There are two invariants which must hold for local data (where um is UtxoModifier, memPool is MemPool and tip is HeaderHash): 1. Suppose blks is sequence of blocks from the very beginning up to tip. If one applies blks to genesis Utxo, resulting Utxo (let's call it utxo1) will be such that all transactions from memPool are valid with respect to it. 2. If one applies all transactions from memPool to utxo1, resulting Utxo will be equivalent to um with respect to MonadUtxo.

Memory state of Txp. Generic version.

type GenericTxpLocalDataPure extra = (UtxoModifier, MemPool, UndoMap, HeaderHash, extra) Source #

Pure version of GenericTxpLocalData.

type TxpLocalData = GenericTxpLocalData () Source #

Memory state of Txp. This version is used by actual Txp implementation.

type TxpLocalDataPure = GenericTxpLocalDataPure () Source #

Pure version of TxpLocalData.

class MonadUtxoRead m => MonadUtxo m where Source #

Methods

utxoPut :: TxIn -> TxOutAux -> m () Source #

utxoPut :: (MonadTrans t, MonadUtxo m', t m' ~ m) => TxIn -> TxOutAux -> m () Source #

utxoDel :: TxIn -> m () Source #

utxoDel :: (MonadTrans t, MonadUtxo m', t m' ~ m) => TxIn -> m () Source #

Instances

(MonadUtxo m, MonadTrans t, Monad (t m)) => MonadUtxo (t m) Source # 

Methods

utxoPut :: TxIn -> TxOutAux -> t m () Source #

utxoDel :: TxIn -> t m () Source #

Monad m => MonadUtxo (StateT Utxo m) Source # 

Methods

utxoPut :: TxIn -> TxOutAux -> StateT Utxo m () Source #

utxoDel :: TxIn -> StateT Utxo m () Source #

class MonadBalancesRead m => MonadBalances m where Source #

Methods

setStake :: StakeholderId -> Coin -> m () Source #

setTotalStake :: Coin -> m () Source #

setStake :: (MonadTrans t, MonadBalances m', t m' ~ m) => StakeholderId -> Coin -> m () Source #

setTotalStake :: (MonadTrans t, MonadBalances m', t m' ~ m) => Coin -> m () Source #

Instances

(MonadBalances m, MonadTrans t, Monad (t m)) => MonadBalances (t m) Source # 

Methods

setStake :: StakeholderId -> Coin -> t m () Source #

setTotalStake :: Coin -> t m () Source #

class Monad m => MonadToilEnv m where Source #

Type class which lets get some environmental data needed for transactions processing.

class Monad m => MonadTxPool m where Source #

Methods

hasTx :: TxId -> m Bool Source #

poolSize :: m Int Source #

putTxWithUndo :: TxId -> TxAux -> TxUndo -> m () Source #

hasTx :: (MonadTrans t, MonadTxPool m', t m' ~ m) => TxId -> m Bool Source #

poolSize :: (MonadTrans t, MonadTxPool m', t m' ~ m) => m Int Source #

putTxWithUndo :: (MonadTrans t, MonadTxPool m', t m' ~ m) => TxId -> TxAux -> TxUndo -> m () Source #

Instances

(MonadTxPool m, MonadTrans t, Monad (t m)) => MonadTxPool (t m) Source # 

Methods

hasTx :: TxId -> t m Bool Source #

poolSize :: t m Int Source #

putTxWithUndo :: TxId -> TxAux -> TxUndo -> t m () Source #

runDBTxp :: DBTxp m a -> m a Source #

data ToilVerFailure Source #

Result of transaction processing

Constructors

ToilKnown

Transaction is already in the storage (cache)

ToilTipsMismatch 
ToilOverwhelmed

Local transaction storage is full -- can't accept more txs

ToilNotUnspent !TxIn

Tx input is not a known unspent input.

ToilOutGTIn 
ToilInconsistentTxAux !Text 
ToilInvalidOutputs !Text 
ToilInvalidInputs ![Text] 
ToilTooLargeTx 

Fields

ToilUnknownAttributes !ByteString 

verifyToil :: (GlobalToilMode m, MonadError ToilVerFailure m) => Bool -> [TxAux] -> m TxpUndo Source #

Verify transactions correctness with respect to Utxo applying them one-by-one. Note: transactions must be topsorted to pass check. Warning: this function may apply some transactions and fail eventually. Use it only on temporary data.

If the first argument is True, all data (script versions, witnesses, addresses, attributes) must be known. Otherwise unknown data is just ignored.

applyToil :: GlobalToilMode m => [(TxAux, TxUndo)] -> m () Source #

Apply transactions from one block. They must be valid (for example, it implies topological sort).

rollbackToil :: GlobalToilMode m => [(TxAux, TxUndo)] -> m () Source #

Rollback transactions from one block.

normalizeToil :: LocalToilMode m => [(TxId, TxAux)] -> m () Source #

Get rid of invalid transactions. All valid transactions will be added to mem pool and applied to utxo.

processTx :: (LocalToilMode m, MonadError ToilVerFailure m) => (TxId, TxAux) -> m TxUndo Source #

Verify one transaction and also add it to mem pool and apply to utxo if transaction is valid.

type ToilT ext m = StateT (GenericToilModifier ext) m Source #

Monad transformer which stores ToilModifier and implements writable Toil type classes.

WARNING
This transformer uses StateT and is intended for single-threaded usage only. Used for block application now.

runToilTGlobal :: (Default ext, Functor m) => ToilT ext m a -> m (a, GenericToilModifier ext) Source #

Run ToilT using empty modifier. Should be used for global transaction processing.

runToilTLocal :: Functor m => UtxoModifier -> MemPool -> UndoMap -> ToilT () m a -> m (a, ToilModifier) Source #

Run ToilT using empty balances modifier. Should be used for local transaction processing.

execToilTLocal :: Functor m => UtxoModifier -> MemPool -> UndoMap -> ToilT () m a -> m ToilModifier Source #

Execute ToilT using empty balances modifier. Should be used for local transaction processing.

runToilTLocalExtra :: Functor m => UtxoModifier -> MemPool -> UndoMap -> extra -> ToilT extra m a -> m (a, GenericToilModifier extra) Source #

Like runToilTLocal, but takes extra data as argument.

type Utxo = Map TxIn TxOutAux Source #

Unspent transaction outputs.

Transaction inputs are identified by (transaction ID, index in list of output) pairs.

formatUtxo :: Utxo -> Builder Source #

Format Utxo map for showing

utxoF :: Format r (Utxo -> r) Source #

Specialized formatter for Utxo.

data MemPool Source #

Constructors

MemPool 

Fields

Instances

data GenericToilModifier extension Source #

Constructors

ToilModifier 

Instances

tmUtxo :: forall extension. Lens' (GenericToilModifier extension) UtxoModifier Source #

tmBalances :: forall extension. Lens' (GenericToilModifier extension) BalancesView Source #

tmMemPool :: forall extension. Lens' (GenericToilModifier extension) MemPool Source #

tmUndos :: forall extension. Lens' (GenericToilModifier extension) UndoMap Source #

tmExtra :: forall extension extension. Lens (GenericToilModifier extension) (GenericToilModifier extension) extension extension Source #

Env

data ToilEnv Source #

Environment used by Toil.

Constructors

ToilEnv 

Fields

Instances

data VTxContext Source #

Global context data needed for tx verification. VT stands for "Verify Tx". To be populated in further versions.

Constructors

VTxContext 

Fields

  • vtcVerifyAllIsKnown :: !Bool

    Verify that script versions in tx are known, addresses' and witnesses' types are known, attributes are known too.

verifyTxUtxo :: (MonadUtxoRead m, MonadError ToilVerFailure m) => VTxContext -> TxAux -> m TxUndo Source #

CHECK: Verify Tx correctness using MonadUtxoRead. Specifically there are the following checks:

  • every input is a known unspent output;
  • sum of inputs >= sum of outputs;
  • every input has a proper witness verifying that input;
  • script witnesses have matching script versions;
  • if vtcVerifyAllIsKnown is True, addresses' versions are verified to be known, as well as witnesses, attributes, script versions.

Note that verifyTxUtxo doesn't attempt to verify scripts with versions higher than maximum script version we can handle. That's because we want blocks with such transactions to be accepted (to avoid hard forks). However, we won't include such transactions into blocks when we're creating a block (because transactions for inclusion into blocks are verified with vtcVerifyAllIsKnown set to True, so unknown script versions are rejected).

applyTxToUtxo :: MonadUtxo m => WithHash Tx -> TxDistribution -> m () Source #

Remove unspent outputs used in given transaction, add new unspent outputs.

rollbackTxUtxo :: MonadUtxo m => (TxAux, TxUndo) -> m () Source #

Rollback application of given transaction to Utxo using Undo data. This function assumes that transaction has been really applied and doesn't check anything.

evalUtxoStateT :: Monad m => UtxoStateT m a -> Utxo -> m a Source #

applyTxToUtxoPure :: WithHash Tx -> TxDistribution -> Utxo -> Utxo Source #

Pure version of applyTxToUtxo.

verifyTxUtxoPure :: MonadError ToilVerFailure m => VTxContext -> Utxo -> TxAux -> m TxUndo Source #

Pure version of verifyTxUtxo.

filterUtxoByAddr :: Address -> Utxo -> Utxo Source #

Select only TxOuts for given addresses

utxoToStakes :: Utxo -> HashMap StakeholderId Coin Source #

Convert Utxo to map from StakeholderId to stake.