Skip to content
Permalink
Browse files

Use GenTx(Id) to instantiate MempoolSnapshot

Instead of being parameterised over `txid` and `tx`, just use `blk`, and use
`GenTxId blk` and `GenTx blk` in the field types. Since this is the only way
we're ever using `MempoolSnapshot`, there is no need to abstract over these
types, it just makes the instantiated type longer.
  • Loading branch information...
mrBliss committed Jul 12, 2019
1 parent 82322b9 commit b9099780e5fe663b4dc730ede421d1bb5efe4f43
@@ -170,11 +170,11 @@ data Mempool m blk idx = Mempool {

-- | Get a snapshot of the current mempool state. This allows for
-- further pure queries on the snapshot.
, getSnapshot :: STM m (MempoolSnapshot (GenTxId blk) (GenTx blk) idx)
, getSnapshot :: STM m (MempoolSnapshot blk idx)

-- | Represents the initial value at which the transaction ticket number
-- counter will start (i.e. the zeroth ticket number).
, zeroIdx :: idx
, zeroIdx :: idx
}

-- | A pure snapshot of the contents of the mempool. It allows fetching
@@ -191,19 +191,19 @@ data Mempool m blk idx = Mempool {
-- even for tx sequence numbers returned in previous snapshots. This happens
-- when the transaction has been removed from the mempool between snapshots.
--
data MempoolSnapshot txid tx idx = MempoolSnapshot {
data MempoolSnapshot blk idx = MempoolSnapshot {
-- | Get all transactions in the mempool snapshot along with their
-- associated ticket numbers (oldest to newest).
getTxs :: [(txid, tx, idx)]
getTxs :: [(GenTxId blk, GenTx blk, idx)]

-- | Get all transactions in the mempool snapshot, along with their
-- associated ticket numbers, which are associated with a ticket number
-- greater than the one provided.
, getTxsAfter :: idx -> [(txid, tx, idx)]
, getTxsAfter :: idx -> [(GenTxId blk, GenTx blk, idx)]

-- | Get a specific transaction from the mempool snapshot by its ticket
-- number, if it exists.
, getTx :: idx -> Maybe (txid, tx)
, getTx :: idx -> Maybe (GenTx blk)
}

-- | Events traced by the Mempool.
@@ -164,7 +164,7 @@ implGetSnapshot :: ( MonadSTM m
, ApplyTx blk
)
=> MempoolEnv m blk
-> STM m (MempoolSnapshot (GenTxId blk) (GenTx blk) TicketNo)
-> STM m (MempoolSnapshot blk TicketNo)
implGetSnapshot MempoolEnv{mpEnvStateVar} = do
is <- readTVar mpEnvStateVar
pure MempoolSnapshot
@@ -198,11 +198,8 @@ implSnapshotGetTxsAfter IS{isTxs} tn = map
implSnapshotGetTx :: ApplyTx blk
=> InternalState blk
-> TicketNo
-> Maybe (GenTxId blk, GenTx blk)
implSnapshotGetTx IS{isTxs} tn =
case isTxs `lookupByTicketNo` tn of
Nothing -> Nothing
Just tx -> Just (computeGenTxId tx, tx)
-> Maybe (GenTx blk)
implSnapshotGetTx IS{isTxs} tn = isTxs `lookupByTicketNo` tn

{-------------------------------------------------------------------------------
Validation
@@ -185,7 +185,7 @@ testAddTxsWithMempoolAndSnapshot
-> [TestTx]
-> ( forall m.
Mempool m TestBlock TicketNo
-> MempoolSnapshot (GenTxId TestBlock) (GenTx TestBlock) TicketNo
-> MempoolSnapshot TestBlock TicketNo
-> prop
)
-> Property

0 comments on commit b909978

Please sign in to comment.
You can’t perform that action at this time.