Skip to content
Permalink
Browse files

change to DiffTime from Quantity second in slot duration

correct unit tests
  • Loading branch information...
paweljakubas committed Jul 12, 2019
1 parent debb5ff commit 4cc7190a8b0c3f574abc6e94917fc951b90a2d17
@@ -167,7 +167,7 @@ import Data.Text
import Data.Text.Class
( toText )
import Data.Time.Clock
( getCurrentTime )
( diffTimeToPicoseconds, getCurrentTime )
import Fmt
( Buildable, blockListF, pretty, (+|), (+||), (|+), (||+) )

@@ -381,7 +381,7 @@ newWalletLayer
-> IO (WalletLayer s t)
newWalletLayer
tracer
(BlockchainParameters block0 feePolicy (SlotLength (Quantity slotLength)))
(BlockchainParameters block0 feePolicy (SlotLength slotLength))
db nw tl = do
logDebugT $ "Wallet layer starting with: "
<> "block0: "+| block0 |+ ", "
@@ -545,14 +545,15 @@ newWalletLayer
-> WalletId
-> BlockHeader
-> IO ()
restoreSleep t wid slot = do
let halfSlotLengthDelay = 500000 * (fromIntegral slotLength) in threadDelay halfSlotLengthDelay
runExceptT (networkTip nw) >>= \case
Left e -> do
logError t $ "Failed to get network tip: " +|| e ||+ ""
restoreSleep t wid slot
Right tip ->
restoreStep t wid (slot, tip)
restoreSleep t wid slot =
let halfSlotLengthDelay = fromIntegral $ (diffTimeToPicoseconds slotLength `div` 500000) in do
threadDelay halfSlotLengthDelay
runExceptT (networkTip nw) >>= \case
Left e -> do
logError t $ "Failed to get network tip: " +|| e ||+ ""
restoreSleep t wid slot
Right tip ->
restoreStep t wid (slot, tip)

-- | Apply the given blocks to the wallet and update the wallet state,
-- transaction history and corresponding metadata.
@@ -130,8 +130,10 @@ import Data.Text.Class
)
import Data.Time
( UTCTime )
import Data.Time.Clock
( DiffTime )
import Data.Word
( Word16, Word32, Word64, Word8 )
( Word16, Word32, Word64 )
import Fmt
( Buildable (..)
, blockListF
@@ -705,7 +707,7 @@ fromFlatSlot n = SlotId e (fromIntegral s)
epochLength :: Integral a => a
epochLength = 21600

newtype SlotLength = SlotLength (Quantity "second" Word8)
newtype SlotLength = SlotLength DiffTime
deriving (Show, Eq)

{-------------------------------------------------------------------------------
@@ -106,6 +106,8 @@ import Data.Ord
( Down (..) )
import Data.Quantity
( Quantity (..) )
import Data.Time.Clock
( secondsToDiffTime )
import Data.Word
( Word32 )
import GHC.Generics
@@ -370,14 +372,8 @@ setupFixture (wid, wname, wstate) = do
db <- newDBLayer
let nl = error "NetworkLayer"
let tl = dummyTransactionLayer
wl <- newWalletLayer
@_
@DummyTarget
nullTracer
(BlockchainParameters block0 dummyPolicy dummySlotLength)
db
nl
tl
let bp = BlockchainParameters block0 dummyPolicy dummySlotLength
wl <- newWalletLayer @_ @DummyTarget nullTracer bp db nl tl
res <- runExceptT $ createWallet wl wid wname wstate
let wal = case res of
Left _ -> []
@@ -388,7 +384,7 @@ setupFixture (wid, wname, wstate) = do
dummyPolicy = LinearFee (Quantity 14) (Quantity 42)

dummySlotLength :: SlotLength
dummySlotLength = SlotLength $ Quantity 1
dummySlotLength = SlotLength $ secondsToDiffTime 1

-- | A dummy transaction layer to see the effect of a root private key. It
-- implements a fake signer that still produces sort of witnesses
@@ -55,6 +55,7 @@ library
, servant-client-core
, text
, text-class
, time
, transformers
hs-source-dirs:
src
@@ -60,6 +60,8 @@ import Data.Quantity
( Quantity (..) )
import Data.Text.Class
( TextDecodingError (..) )
import Data.Time.Clock
( secondsToDiffTime )

import qualified Cardano.Wallet.HttpBridge.Binary as CBOR
import qualified Cardano.Wallet.HttpBridge.Primitive.Types as W
@@ -160,4 +162,4 @@ byronFeePolicy = LinearFee (Quantity 155381) (Quantity 43.946)

-- | Hard-coded slot duration
byronSlotLength :: SlotLength
byronSlotLength = SlotLength $ Quantity 20
byronSlotLength = SlotLength $ secondsToDiffTime 20
@@ -54,6 +54,7 @@ library
, servant-client-core
, text
, text-class
, time
, transformers
hs-source-dirs:
src
@@ -124,6 +124,8 @@ import Data.Proxy
( Proxy (..) )
import Data.Quantity
( Quantity (..) )
import Data.Time.Clock
( DiffTime, secondsToDiffTime )
import Data.Word
( Word16, Word32, Word64, Word8 )

@@ -359,7 +361,7 @@ data ConfigParam
-- ^ Consensus version. BFT / Genesis Praos.
| SlotsPerEpoch (Quantity "slot/epoch" Word32)
-- ^ Number of slots in an epoch.
| SlotDuration (Quantity "second" Word8)
| SlotDuration DiffTime
-- ^ Slot duration in seconds.
| EpochStabilityDepth (Quantity "block" Word32)
-- ^ The length of the suffix of the chain (in blocks) considered unstable.
@@ -400,7 +402,7 @@ getConfigParam = label "getConfigParam" $ do
2 -> Block0Date <$> getWord64be
3 -> Consensus <$> getConsensusVersion
4 -> SlotsPerEpoch . Quantity <$> getWord32be
5 -> SlotDuration . Quantity <$> getWord8
5 -> SlotDuration . secondsToDiffTime . fromIntegral <$> getWord8
6 -> EpochStabilityDepth . Quantity <$> getWord32be
8 -> ConsensusGenesisPraosParamF <$> getMilli
9 -> MaxNumberOfTransactionsPerBlock <$> getWord32be
@@ -182,12 +182,11 @@ cardanoWalletServer
cardanoWalletServer mlisten = do
logConfig <- CM.empty
tracer <- initTracer Info "serve"
(nl, block0, feePolicy, slotLength) <- newNetworkLayer jormungandrUrl block0H
(nl, bp) <- newNetworkLayer jormungandrUrl block0H
(sqlCtx, db) <- Sqlite.newDBLayer @_ @network logConfig tracer Nothing
mvar <- newEmptyMVar
handle <- async $ do
let tl = Jormungandr.newTransactionLayer block0H
let bp = BlockchainParameters block0 feePolicy slotLength
wallet <- newWalletLayer tracer bp db nl tl
let listen = fromMaybe (ListenOnPort defaultPort) mlisten
Server.withListeningSocket listen $ \(port, socket) -> do

Some generated files are not rendered by default. Learn more.

Some generated files are not rendered by default. Learn more.

0 comments on commit 4cc7190

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