Skip to content

Commit

Permalink
Drop txRewardWithdrawal from TxSkeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
Anviking committed May 29, 2023
1 parent 49f4bf7 commit e87240a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 49 deletions.
18 changes: 0 additions & 18 deletions lib/wallet/src/Cardano/Wallet/Shelley/Transaction.hs
Expand Up @@ -215,7 +215,6 @@ import Cardano.Wallet.Transaction
, WitnessCount (..)
, WitnessCountCtx (..)
, mapTxFeeAndChange
, withdrawalToCoin
)
import Cardano.Wallet.TxWitnessTag
( TxWitnessTag (..), TxWitnessTagFor (..) )
Expand Down Expand Up @@ -1433,7 +1432,6 @@ txConstraints protocolParams witnessTag = TxConstraints
data TxSkeleton = TxSkeleton
{ txMetadata :: !(Maybe TxMetadata)
, txDelegationAction :: !(Maybe DelegationAction)
, txRewardWithdrawal :: !Coin
, txWitnessTag :: !TxWitnessTag
, txInputCount :: !Int
, txOutputs :: ![TxOut]
Expand All @@ -1453,7 +1451,6 @@ emptyTxSkeleton :: TxWitnessTag -> TxSkeleton
emptyTxSkeleton txWitnessTag = TxSkeleton
{ txMetadata = Nothing
, txDelegationAction = Nothing
, txRewardWithdrawal = Coin 0
, txWitnessTag
, txInputCount = 0
, txOutputs = []
Expand All @@ -1476,7 +1473,6 @@ mkTxSkeleton
mkTxSkeleton witness context skeleton = TxSkeleton
{ txMetadata = view #txMetadata context
, txDelegationAction = view #txDelegationAction context
, txRewardWithdrawal = withdrawalToCoin $ view #txWithdrawal context
, txWitnessTag = witness
, txInputCount = view #skeletonInputCount skeleton
, txOutputs = view #skeletonOutputs skeleton
Expand Down Expand Up @@ -1721,7 +1717,6 @@ estimateTxSize skeleton =
TxSkeleton
{ txMetadata
, txDelegationAction
, txRewardWithdrawal
, txWitnessTag
, txInputCount
, txOutputs
Expand All @@ -1737,9 +1732,6 @@ estimateTxSize skeleton =
numberOf_CertificateSignatures
= maybe 0 (const 1) txDelegationAction

numberOf_Withdrawals
= if txRewardWithdrawal > Coin 0 then 1 else 0

-- Total number of signatures the scripts require
numberOf_MintingWitnesses
= intCast $ sumVia estimateMaxWitnessRequiredPerInput txMintOrBurnScripts
Expand All @@ -1753,12 +1745,10 @@ estimateTxSize skeleton =
TxWitnessShelleyUTxO ->
if numberOf_ScriptVkeyWitnesses == 0 then
numberOf_Inputs
+ numberOf_Withdrawals
+ numberOf_CertificateSignatures
+ numberOf_MintingWitnesses
else
(numberOf_Inputs * numberOf_ScriptVkeyWitnesses)
+ numberOf_Withdrawals
+ numberOf_CertificateSignatures
+ numberOf_MintingWitnesses

Expand Down Expand Up @@ -1797,7 +1787,6 @@ estimateTxSize skeleton =
+ sizeOf_Fee
+ sizeOf_Ttl
+ sizeOf_Certificates
+ sizeOf_Withdrawals
+ sizeOf_Update
+ sizeOf_MetadataHash
+ sizeOf_ValidityIntervalStart
Expand Down Expand Up @@ -1845,13 +1834,6 @@ estimateTxSize skeleton =
+ sizeOf_SmallArray
+ sizeOf_StakeDeregistration

-- ?5 => withdrawals
sizeOf_Withdrawals
= (if numberOf_Withdrawals > 0
then sizeOf_SmallUInt + sizeOf_SmallMap
else 0)
+ intCast sizeOfSignedWithdrawal * numberOf_Withdrawals

-- ?6 => update
sizeOf_Update
= 0 -- Assuming no updates is running through cardano-wallet
Expand Down
32 changes: 1 addition & 31 deletions lib/wallet/test/unit/Cardano/Wallet/Shelley/TransactionSpec.hs
Expand Up @@ -343,7 +343,7 @@ import Data.Quantity
import Data.Ratio
( (%) )
import Data.Semigroup
( Sum (Sum), getSum, mtimesDefault )
( Sum (Sum), getSum )
import Data.Set
( Set )
import Data.Text
Expand Down Expand Up @@ -1747,8 +1747,6 @@ binaryCalculationsSpec' era = describe ("calculateBinary - "+||era||+"") $ do
transactionConstraintsSpec :: Spec
transactionConstraintsSpec = describe "Transaction constraints" $ do
it "size of empty transaction" prop_txConstraints_txBaseSize
it "size of non-empty transaction" $
property prop_txConstraints_txSize
it "maximum size of output" $
property prop_txConstraints_txOutputMaximumSize

Expand Down Expand Up @@ -2070,34 +2068,6 @@ prop_txConstraints_txBaseSize :: Property
prop_txConstraints_txBaseSize =
txBaseSize mockTxConstraints === estimateTxSize emptyTxSkeleton

-- Tests that using 'txConstraints' to estimate the size of a non-empty
-- selection produces a result that is consistent with the result of using
-- 'estimateTxSize'.
--
prop_txConstraints_txSize :: MockSelection -> Property
prop_txConstraints_txSize mock =
counterexample ("result: " <> show result) $
counterexample ("lower bound: " <> show lowerBound) $
counterexample ("upper bound: " <> show upperBound) $
conjoin
[ result >= lowerBound
, result <= upperBound
]
where
MockSelection {txInputCount, txOutputs, txRewardWithdrawal} = mock
result :: TxSize
result = mconcat
[ txBaseSize mockTxConstraints
, txInputCount `mtimesDefault` txInputSize mockTxConstraints
, F.foldMap (txOutputSize mockTxConstraints . tokens) txOutputs
, txRewardWithdrawalSize mockTxConstraints txRewardWithdrawal
]
lowerBound = estimateTxSize emptyTxSkeleton
{txInputCount, txOutputs, txRewardWithdrawal}
-- We allow a small amount of overestimation due to the slight variation in
-- the marginal size of an input:
upperBound = lowerBound <> txInputCount `mtimesDefault` TxSize 4

newtype Large a = Large { unLarge :: a }
deriving (Eq, Show)

Expand Down

0 comments on commit e87240a

Please sign in to comment.