-
Notifications
You must be signed in to change notification settings - Fork 214
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
Rewards in shared wallets #3842
Rewards in shared wallets #3842
Conversation
cleanings
more WitCountCtx
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.
Just some very early initial comments and suggestions!
let rewardAcctM = case scriptM of | ||
Just script -> | ||
let scriptHash = | ||
CA.unScriptHash $ | ||
CA.toScriptHash script | ||
in Just $ RewardAccount scriptHash | ||
Nothing -> Nothing |
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.
I think we can rewrite this as:
let rewardAcctM = case scriptM of | |
Just script -> | |
let scriptHash = | |
CA.unScriptHash $ | |
CA.toScriptHash script | |
in Just $ RewardAccount scriptHash | |
Nothing -> Nothing | |
let rewardAcctM = | |
RewardAccount . CA.unScriptHash . CA.toScriptHash <$> scriptM |
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.
of course, done
if numberStakingNativeScripts == 0 then | ||
0 | ||
else if numberStakingNativeScripts == 1 then | ||
Shared.estimateMinWitnessRequiredPerInput scriptD | ||
else | ||
error "wallet supports transactions with 0 or 1 staking script" |
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.
Can this be rewritten with pattern guards or MultiwayIf
?
Something like:
if numberStakingNativeScripts == 0 then | |
0 | |
else if numberStakingNativeScripts == 1 then | |
Shared.estimateMinWitnessRequiredPerInput scriptD | |
else | |
error "wallet supports transactions with 0 or 1 staking script" | |
| numberStakingNativeScripts == 0 = | |
0 | |
| numberStakingNativeScripts == 1 = | |
Shared.estimateMinWitnessRequiredPerInput scriptD | |
| otherwise = | |
error "wallet supports transactions with 0 or 1 staking script" |
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.
done
lib/wallet/src/Cardano/Wallet.hs
Outdated
walletState <- getState <$> | ||
withExceptT ErrReadRewardAccountNoSuchWallet | ||
(readWalletCheckpoint db wid) | ||
pure $ Shared.rewardAccountKey walletState |
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.
walletState <- getState <$> | |
withExceptT ErrReadRewardAccountNoSuchWallet | |
(readWalletCheckpoint db wid) | |
pure $ Shared.rewardAccountKey walletState | |
Shared.rewardAccountKey . getState <$> | |
withExceptT ErrReadRewardAccountNoSuchWallet | |
(readWalletCheckpoint db wid) |
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.
it i not in this form anymore. path
was added
lib/wallet/src/Cardano/Wallet.hs
Outdated
readWalletCheckpoint :: | ||
DBLayer IO s k -> WalletId -> ExceptT ErrNoSuchWallet IO (Wallet s) |
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.
readWalletCheckpoint :: | |
DBLayer IO s k -> WalletId -> ExceptT ErrNoSuchWallet IO (Wallet s) | |
readWalletCheckpoint | |
:: DBLayer IO s k -> WalletId -> ExceptT ErrNoSuchWallet IO (Wallet s) |
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.
done
lib/wallet/src/Cardano/Wallet.hs
Outdated
stakingKeyM = case xprvM of | ||
Just xprv -> Just | ||
( hashVerificationKey @k CA.Delegation $ liftRawKey $ toXPub xprv | ||
, xprv | ||
, rootPwd | ||
) | ||
Nothing -> Nothing |
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.
stakingKeyM = case xprvM of | |
Just xprv -> Just | |
( hashVerificationKey @k CA.Delegation $ liftRawKey $ toXPub xprv | |
, xprv | |
, rootPwd | |
) | |
Nothing -> Nothing | |
stakingKeyM = xprvM <&> \xprv -> | |
( hashVerificationKey @k CA.Delegation $ liftRawKey $ toXPub xprv | |
, xprv | |
, rootPwd | |
) |
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.
neat form! done
Left rewardAcct -> | ||
_getCachedRewardAccountBalance rewardsObserverFromKeyHash rewardAcct | ||
Right rewardAcct -> | ||
_getCachedRewardAccountBalance rewardsObserverFromScriptHash rewardAcct |
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.
_getCachedRewardAccountBalance rewardsObserverFromScriptHash rewardAcct | |
_getCachedRewardAccountBalance | |
rewardsObserverFromScriptHash rewardAcct |
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.
done
@@ -453,6 +453,11 @@ instance IsServerError ErrConstructTx where | |||
, "'PATCH /shared-wallets/{walletId}/delegation-script-template'" | |||
, "to make it suitable for constructing transactions." | |||
] | |||
ErrConstructTxStakingInvalid -> | |||
apiError err403 StakingInvalid $ T.unwords | |||
[ "I cannot construct a delegating transaction for a shared wallet " |
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.
[ "I cannot construct a delegating transaction for a shared wallet " | |
[ "I cannot construct a delegating transaction for a shared wallet" |
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.
done
apiError err404 MissingRewardAccount $ mconcat | ||
[ "I couldn't read a reward account which is required for reward " | ||
, "detection. Either there is db malfunction or managing rewards " | ||
, "was used for shared wallets missing delegation template." |
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.
Could you explain a little more about what this means:
"managing rewards was used for shared wallets missing delegation template."
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.
shared wallets can be with and without delegation template. When the delegation template is missing we are having wallet that cannot stake, is generating enterprise addresses (only with payment credential). In that case we should not spin up "managing awards". It is the error that make sure "managing awards service" is used for multisig wallets with delegation templates present
, depositsReturned = [] | ||
, certificates = certs | ||
, depositsTaken = | ||
(Quantity . fromIntegral . unCoin . W.stakeKeyDeposit $ pp) |
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.
Suggestion: use Coin.toQuantity
(this is a statically-checked total function, whereas fromIntegral
is statically-unchecked and partial).
(Quantity . fromIntegral . unCoin . W.stakeKeyDeposit $ pp) | |
(Coin.toQuantity . W.stakeKeyDeposit $ pp) |
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.
good suggestion. done
(Quantity . fromIntegral . unCoin . W.stakeKeyDeposit $ pp) | ||
<$ filter ourRewardAccountRegistration certs | ||
, depositsReturned = | ||
(Quantity . fromIntegral . unCoin . W.stakeKeyDeposit $ pp) |
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.
Suggestion: use Coin.toQuantity
(this is a statically-checked total function, whereas fromIntegral
is statically-unchecked and partial).
(Quantity . fromIntegral . unCoin . W.stakeKeyDeposit $ pp) | |
(Coin.toQuantity . W.stakeKeyDeposit $ pp) |
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.
done
b3c44c7
to
6cde360
Compare
@@ -160,7 +160,8 @@ data NetworkLayer m block = NetworkLayer | |||
-> m StakePoolsSummary | |||
|
|||
, getCachedRewardAccountBalance | |||
:: RewardAccount | |||
:: Either RewardAccount RewardAccount |
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.
Is the distinction between RewardAccount
and RewardAccount
really needed, or could we not get away with just RewardAccount
?
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.
yes, one is key hashes based and another is script hashes based. And this information is need when transforming from node reward account. See how this point is used in Cardano.Wallet.Shelley.Network.Node
module (shelleyQry
)
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.
Ah, so I take it really is a binary tag for script vs keyHash object we need for the query, and is not already in the RewardAccount
bytes...
990aaff
to
2490c5e
Compare
rewardsObserverFromKeyHash <- newRewardBalanceFetcher | ||
tr readNodeTip queryRewardQ RewardAccountFromKeyHash | ||
rewardsObserverFromScriptHash <- newRewardBalanceFetcher | ||
tr readNodeTip queryRewardQ RewardAccountFromScriptHash |
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.
Creating two different fetchers with two different RewardAccountSource
is unnecessary. Batching all script and key credentials into the same local state query should be more efficient. The reason you can't currently do this is the RewardAccount
type containing too little information.
What about:
- Either importing or re-exporting
Cardano.StakeCredential
/Ledger.StakeCredential crypto
or defining something similar to it. (Could also bedata StakeCredential = ...FromKeyHash RewardAccount | ...FromScriptHash RewardAccount
) - Changing
getCachedRewardAccountBalance
to takeStakeCredential
instead ofEither RewardAccount RewardAccount
- Removing
RewardAccountSource
and the duplicate call tonewRewardBalanceFetcher
?
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.
2490c5e
to
76cc989
Compare
closing in favor of #3872 |
Comments
PR on top of #3830
Issue Number
adp-2603