-
Notifications
You must be signed in to change notification settings - Fork 213
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
More measures post restoration benchmarks + SeqAnyState #2084
Merged
iohk-bors
merged 7 commits into
master
from
KtorZ/2032/more-measures-post-restore-benchmark
Sep 2, 2020
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
9c2a3f9
extend restoration benchmarks with a special 1% random wallet
KtorZ bb7c307
perform additional checks after restoration benchmarks
KtorZ 5850559
define a 'SeqAnyState' analogous to the 'RndAnyState' for benchmarks
KtorZ 741e74a
make proportion more fine-grained to allow fractions of percent
KtorZ f42602b
remove now obsolete 'Any' wallet scheme
KtorZ 309874f
rename 'qualifier' into 'benchName' & label 'empty' wallets as 0%
KtorZ 9d9734b
Regenerate nix
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -57,6 +57,10 @@ module Cardano.Wallet.Primitive.AddressDiscovery.Sequential | |||||
, SeqState (..) | ||||||
, mkSeqStateFromRootXPrv | ||||||
, mkSeqStateFromAccountXPub | ||||||
|
||||||
-- ** Benchmarking | ||||||
, SeqAnyState (..) | ||||||
, mkSeqAnyState | ||||||
) where | ||||||
|
||||||
import Prelude | ||||||
|
@@ -87,7 +91,7 @@ import Cardano.Wallet.Primitive.AddressDiscovery | |||||
, KnownAddresses (..) | ||||||
) | ||||||
import Cardano.Wallet.Primitive.Types | ||||||
( Address, AddressState (..), invariant ) | ||||||
( Address (..), AddressState (..), ChimericAccount (..), invariant ) | ||||||
import Control.Applicative | ||||||
( (<|>) ) | ||||||
import Control.DeepSeq | ||||||
|
@@ -96,6 +100,8 @@ import Control.Monad | |||||
( unless ) | ||||||
import Data.Bifunctor | ||||||
( first ) | ||||||
import Data.Digest.CRC32 | ||||||
( crc32 ) | ||||||
import Data.Function | ||||||
( (&) ) | ||||||
import Data.Map.Strict | ||||||
|
@@ -118,6 +124,8 @@ import GHC.Generics | |||||
( Generic ) | ||||||
import GHC.Stack | ||||||
( HasCallStack ) | ||||||
import GHC.TypeLits | ||||||
( KnownNat, Nat, natVal ) | ||||||
|
||||||
import qualified Data.List as L | ||||||
import qualified Data.Map.Strict as Map | ||||||
|
@@ -718,3 +726,113 @@ instance | |||||
addresses (liftPaymentAddress @n @k) (externalPool s) | ||||||
in | ||||||
nonChangeAddresses <> changeAddresses | ||||||
|
||||||
-------------------------------------------------------------------------------- | ||||||
-- | ||||||
-- SeqAnyState | ||||||
-- | ||||||
-- For benchmarking and testing arbitrary large sequential wallets. | ||||||
|
||||||
-- | An "unsound" alternative that can be used for benchmarking and stress | ||||||
-- testing. It re-uses the same underlying structure as the `SeqState` but | ||||||
-- it discovers addresses based on an arbitrary ratio instead of respecting | ||||||
-- BIP-44 discovery. | ||||||
-- | ||||||
-- The proportion is stored as a type-level parameter so that we don't have to | ||||||
-- alter the database schema to store it. It simply exists and depends on the | ||||||
-- caller creating the wallet to define it. | ||||||
newtype SeqAnyState (network :: NetworkDiscriminant) key (p :: Nat) = SeqAnyState | ||||||
{ innerState :: SeqState network key | ||||||
} deriving (Generic) | ||||||
|
||||||
deriving instance | ||||||
( Show (k 'AccountK XPub) | ||||||
, Show (k 'AddressK XPub) | ||||||
, Show (KeyFingerprint "payment" k) | ||||||
) => Show (SeqAnyState n k p) | ||||||
|
||||||
instance | ||||||
( NFData (k 'AccountK XPub) | ||||||
, NFData (k 'AddressK XPub) | ||||||
, NFData (KeyFingerprint "payment" k) | ||||||
) | ||||||
=> NFData (SeqAnyState n k p) | ||||||
|
||||||
-- | Initialize the HD random address discovery state from a root key and RNG | ||||||
-- seed. | ||||||
-- | ||||||
-- The type parameter is expected to be a ratio of addresses we ought to simply | ||||||
-- recognize as ours. It is expressed in tenths of percent, so "1" means 0.1%, | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
-- "10" means 1% and 1000 means 100%. | ||||||
mkSeqAnyState | ||||||
:: forall (p :: Nat) n k. | ||||||
( SoftDerivation k | ||||||
, MkKeyFingerprint k (Proxy n, k 'AddressK XPub) | ||||||
, MkKeyFingerprint k Address | ||||||
, WalletKey k | ||||||
, Bounded (Index (AddressIndexDerivationType k) 'AddressK) | ||||||
) | ||||||
=> (k 'RootK XPrv, Passphrase "encryption") | ||||||
-> AddressPoolGap | ||||||
-> SeqAnyState n k p | ||||||
mkSeqAnyState credentials poolGap = SeqAnyState | ||||||
{ innerState = mkSeqStateFromRootXPrv credentials poolGap | ||||||
} | ||||||
|
||||||
instance | ||||||
( SoftDerivation k | ||||||
, MkKeyFingerprint k (Proxy n, k 'AddressK XPub) | ||||||
, KnownNat p | ||||||
) => IsOurs (SeqAnyState n k p) Address | ||||||
where | ||||||
isOurs (Address bytes) st@(SeqAnyState inner) | ||||||
| crc32 bytes < p = | ||||||
let | ||||||
edge = Map.size (indexedKeys $ externalPool inner) | ||||||
ix = toEnum (edge - fromEnum (gap $ externalPool inner)) | ||||||
KtorZ marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
pool' = extendAddressPool @n ix (externalPool inner) | ||||||
in | ||||||
(True, SeqAnyState (inner { externalPool = pool' })) | ||||||
| otherwise = | ||||||
(False, st) | ||||||
where | ||||||
p = floor (double sup * double (natVal (Proxy @p)) / 1000) | ||||||
where | ||||||
sup = maxBound :: Word32 | ||||||
|
||||||
double :: Integral a => a -> Double | ||||||
double = fromIntegral | ||||||
|
||||||
instance IsOurs (SeqAnyState n k p) ChimericAccount | ||||||
where | ||||||
isOurs _account state = (False, state) | ||||||
|
||||||
instance | ||||||
( SoftDerivation k | ||||||
, MkKeyFingerprint k (Proxy n, k 'AddressK XPub) | ||||||
, AddressIndexDerivationType k ~ 'Soft | ||||||
, KnownNat p | ||||||
) => IsOwned (SeqAnyState n k p) k | ||||||
where | ||||||
isOwned _ _ _ = Nothing | ||||||
|
||||||
instance | ||||||
( SoftDerivation k | ||||||
) => GenChange (SeqAnyState n k p) | ||||||
where | ||||||
type ArgGenChange (SeqAnyState n k p) = ArgGenChange (SeqState n k) | ||||||
genChange a (SeqAnyState s) = SeqAnyState <$> genChange a s | ||||||
|
||||||
instance | ||||||
( MkKeyFingerprint k (Proxy n, k 'AddressK XPub) | ||||||
, MkKeyFingerprint k Address | ||||||
, SoftDerivation k | ||||||
) => CompareDiscovery (SeqAnyState n k p) | ||||||
where | ||||||
compareDiscovery (SeqAnyState s) = compareDiscovery s | ||||||
|
||||||
instance | ||||||
( PaymentAddress n k | ||||||
) => KnownAddresses (SeqAnyState n k p) | ||||||
where | ||||||
knownAddresses (SeqAnyState s) = knownAddresses s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.