cardano-sl-0.4.3: Cardano SL main implementation

Safe HaskellNone





data DelegationWrap Source #

In-memory storage needed for delegation logic Maybe ncProxyCache should be LRU instead of hashmap, but that's not urgent optimization idea.




type MonadDelegation = MonadReader (TVar DelegationWrap) Source #

Equivalent of MonadReader (TVar DelegationWrap) m. Currently we're locking on the whole delegation wrap at once. Locking on independent components is better in performance, so there's a place for optimization here.

getPSKByIssuerAddressHash :: MonadDB m => StakeholderId -> m (Maybe ProxySKHeavy) Source #

Retrieves certificate by issuer address (hash of public key) if present.

getPSKByIssuer :: MonadDB m => PublicKey -> m (Maybe ProxySKHeavy) Source #

Retrieves certificate by issuer public key if present.

data DelegationOp Source #


AddPSK !ProxySKHeavy

Adds PSK. Overwrites if present.

DelPSK !PublicKey

Removes PSK by issuer PK.

runPskIterator :: forall m a. MonadDB m => DBnIterator PskIter a -> m a Source #

runPskMapIterator :: forall v m a. MonadDB m => DBnMapIterator PskIter v a -> (IterType PskIter -> v) -> m a Source #

type DelegationT = ReaderT (TVar DelegationWrap) Source #

Wrapper of ReaderT (TVar DelegationWrap), nothing smart.

runDelegationT :: MonadIO m => DelegationWrap -> DelegationT m a -> m a Source #

Executes delegationT transformer creating tvar from given wrap.

runDelegationTFromTVar :: TVar DelegationWrap -> DelegationT m a -> m a Source #

Executes delegation wrap using existing delegation wrap tvar.

delegationListeners :: WorkMode ssc m => m (Set NodeId) -> ([ListenerSpec m], OutSpecs) Source #

Listeners for requests related to delegation processing.

handleSendProxySK :: forall ssc m. WorkMode ssc m => m (Set NodeId) -> (ListenerSpec m, OutSpecs) Source #

Handler SendProxySK event.

handleConfirmProxySK :: forall ssc m. WorkMode ssc m => m (Set NodeId) -> (ListenerSpec m, OutSpecs) Source #


type DelegationStateAction = StateT DelegationWrap STM Source #

Convenient monad to work in DelegationWrap context while being in STM.

runDelegationStateAction :: (MonadIO m, MonadDelegation m) => DelegationStateAction a -> m a Source #

Effectively takes a lock on ProxyCaches mvar in NodeContext and allows you to run some computation producing updated ProxyCaches and return value. Will put MVar back on exception.

invalidateProxyCaches :: UTCTime -> DelegationStateAction () Source #

Invalidates proxy caches using built-in constants.


initDelegation :: forall ssc m. (SscHelpersClass ssc, MonadDB m, MonadDelegation m) => m () Source #

Initializes delegation in-memory storage.

  • Sets _dwEpochId to epoch of tip.
  • Loads _dwThisEpochPosted from database

Heavyweight psks handling

getProxyMempool :: (MonadDB m, MonadDelegation m) => m ([ProxySKHeavy], [ProxySKHeavy]) Source #

Retrieves current mempool of heavyweight psks plus undo part.

data PskHeavyVerdict Source #

Datatypes representing a verdict of heavy PSK processing.



If we have exactly the same cert in psk mempool

PHInvalid Text

Can't accept PSK though it's most probably user's error


Broken (signature, most probably attack, we can ban for this)


Message is cached


Verdict can't be made at the moment (we're updating)


Successfully processed/added to psk mempool

processProxySKHeavy :: forall ssc m. (SscHelpersClass ssc, MonadDB m, MonadDelegation m, HasContext LrcContext m) => ProxySKHeavy -> m PskHeavyVerdict Source #

Processes heavyweight psk. Puts it into the mempool depending on issuer's stake, overrides if exists, checks validity and cachemsg state.

delegationApplyBlocks :: forall ssc m. DelegationWorkMode m => OldestFirst NE (Block ssc) -> m (NonEmpty SomeBatchOp) Source #

Applies a sequence of definitely valid blocks to memory state and returns batchops. It works correctly only in case blocks don't cross over epoch. So genesis block is either absent or the head.

delegationVerifyBlocks :: forall ssc m. (SscHelpersClass ssc, MonadDB m, HasContext LrcContext m) => OldestFirst NE (Block ssc) -> m (Either Text (OldestFirst NE [ProxySKHeavy])) Source #

Verifies if blocks are correct relatively to the delegation logic and returns a non-empty list of proxySKs needed for undoing them. Predicate for correctness here is:

  • Issuer can post only one cert per epoch
  • For every new certificate issuer had enough stake at the end of prev. epoch

It's assumed blocks are correct from 'Pos.Types.Block#verifyBlocks' point of view.

delegationRollbackBlocks :: forall ssc m. (SscHelpersClass ssc, MonadDelegation m, MonadDB m, HasContext LrcContext m) => NewestFirst NE (Blund ssc) -> m (NonEmpty SomeBatchOp) Source #

Rollbacks block list. Erases mempool of certificates. Better to restore them after the rollback (see Txp#normalizeTxpLD). You can rollback arbitrary number of blocks.

Lightweight psks handling

data PskLightVerdict Source #

PSK check verdict. It can be unrelated (other key or spoiled, no way to differ), exist in storage already or be cached.

processProxySKLight :: (MonadDelegation m, WithNodeContext ssc m, MonadDB m, MonadMask m) => ProxySKLight -> m PskLightVerdict Source #

Processes proxy secret key (understands do we need it, adds/caches on decision, returns this decision).


processConfirmProxySk :: (MonadDelegation m, MonadIO m) => ProxySKLight -> ProxySigLight ProxySKLight -> m ConfirmPskLightVerdict Source #

Takes a lightweight psk, delegate proof of delivery. Checks if it's valid or not. Caches message in any case.

isProxySKConfirmed :: ProxySKLight -> DelegationStateAction Bool Source #

Checks if we hold a confirmation for given PSK.

delegationLrcConsumer :: MonadDBCore m => LrcConsumer m Source #

Consumer will be called on every Richmen computation.

sendProxySKLight :: MinWorkMode m => m (Set NodeId) -> ProxySKLight -> Action' m () Source #

Sends epoch psk to neighbours

sendProxySKHeavy :: MinWorkMode m => m (Set NodeId) -> ProxySKHeavy -> Action' m () Source #

Sends simple psk to neighbours

sendProxyConfirmSK :: WorkMode ssc m => m (Set NodeId) -> ProxySKLight -> Action' m () Source #

Generates a proof of being a delegate for psk and sends it to neighbors.

data SendProxySK Source #

Message with delegated proxy secret key. Is used to propagate both epoch-oriented psks (lightweight) and simple (heavyweight).

data ConfirmProxySK Source #

Confirmation of proxy signature delivery. Delegate should take the proxy signing key he has and sign this key with itself. If the signature is correct, then it was done by delegate (guaranteed by PSK scheme). Checking w can be done with (const True) predicate, because certificate may be sent in epoch id that's before lower cert's EpochIndex.

dlgWorkers :: WorkMode ssc m => m (Set NodeId) -> ([WorkerSpec m], OutSpecs) Source #

All workers specific to proxy sertificates processing.