-
Notifications
You must be signed in to change notification settings - Fork 174
ConwayCERTS: Predicate failure for incomplete withdrawals #5279
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -2,6 +2,7 @@ | |||||||
|
|
||||||||
| ## 1.20.0.0 | ||||||||
|
|
||||||||
| * Add `IncompleteWithdrawalsCERTS` to `ConwayPredFailure`. | ||||||||
|
Contributor
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. You could also mention
Suggested change
|
||||||||
| * Decoupled `ConwayEraTxCert` from `ShelleyEraTxCert`, so added `ShelleyEraTxCert` constraint to: | ||||||||
| * `DecCBOR ConwayTxCert` | ||||||||
| * `transTxCert` | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| {-# LANGUAGE BangPatterns #-} | ||
| {-# LANGUAGE DataKinds #-} | ||
| {-# LANGUAGE DefaultSignatures #-} | ||
| {-# LANGUAGE FlexibleContexts #-} | ||
|
|
@@ -24,6 +25,7 @@ module Cardano.Ledger.State.Account ( | |
| withdrawalsThatDoNotDrainAccounts, | ||
| drainAccounts, | ||
| removeStakePoolDelegations, | ||
| invalidAndIncompleteWithdrawals, | ||
| ) where | ||
|
|
||
| import Cardano.Ledger.Address (RewardAccount (..), Withdrawals (..)) | ||
|
|
@@ -36,6 +38,7 @@ import Cardano.Ledger.Credential | |
| import Control.DeepSeq (NFData) | ||
| import Control.Exception (assert) | ||
| import Data.Aeson (ToJSON) | ||
| import Data.Bifunctor (Bifunctor (..)) | ||
| import Data.Default (Default) | ||
| import Data.Foldable (foldMap') | ||
| import Data.Kind (Type) | ||
|
|
@@ -175,6 +178,42 @@ lookupStakePoolDelegation cred accounts = | |
| lookupAccountState cred accounts | ||
| >>= (^. stakePoolDelegationAccountStateL) | ||
|
|
||
| -- | This function returns a 2-tuple where the `fst` is withdrawals with missing | ||
| -- reward accounts or wrong network, and `snd` is incomplete withdrawals. | ||
| invalidAndIncompleteWithdrawals :: | ||
| EraAccounts era => | ||
| Withdrawals -> | ||
| Network -> | ||
| Accounts era -> | ||
| (Map RewardAccount Coin, Map RewardAccount Coin) | ||
| invalidAndIncompleteWithdrawals (Withdrawals givenWithdrawals) networkId accounts = do | ||
| -- @givenWithdrawals@ is small and @accounts@ is big, better to traverse the | ||
| -- former than the latter. | ||
| Map.foldrWithKey collectBadWithdrawals (mempty, mempty) givenWithdrawals | ||
| where | ||
| -- invalid withdrawal = that which does not have a reward account or is in | ||
| -- the wrong network. | ||
| -- incomplete withdrawal = that which does not withdraw the exact account | ||
| -- balance. | ||
| collectBadWithdrawals :: | ||
| RewardAccount -> | ||
| Coin -> | ||
| (Map RewardAccount Coin, Map RewardAccount Coin) -> | ||
| (Map RewardAccount Coin, Map RewardAccount Coin) | ||
| collectBadWithdrawals | ||
| ra@RewardAccount {raCredential, raNetwork} | ||
| withdrawalAmount | ||
| accum@(!_, !_) = | ||
| case Map.lookup raCredential (accounts ^. accountsMapL) of | ||
| Nothing -> | ||
| first (Map.insert ra withdrawalAmount) accum | ||
|
Contributor
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. Interesting, TIL about this. |
||
| Just accountState | ||
| | raNetwork /= networkId -> | ||
| first (Map.insert ra withdrawalAmount) accum | ||
| | fromCompact (accountState ^. balanceAccountStateL) /= withdrawalAmount -> | ||
|
Contributor
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. If it's both in the wrong network and the amount is incorrect, it's enough to return a predicate for the former? |
||
| second (Map.insert ra withdrawalAmount) accum | ||
| | otherwise -> accum | ||
|
|
||
| -- | This function returns `Nothing` iff all of the accounts that withdrawals are trying to drain are | ||
| -- indeed registered and all of the amounts in the withdrawals match the respective balances exactly. | ||
| withdrawalsThatDoNotDrainAccounts :: | ||
|
|
||
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.
As the ledger release happened, we'll have to change the version in the cabal file to 1.20.1.0 (or maybe even 1.21.1.0?) , and then also the headline in the CHANGELOG.