Skip to content
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

Construct/sign/submit tx with delegation shared wallets #3738

Conversation

paweljakubas
Copy link
Contributor

@paweljakubas paweljakubas commented Feb 10, 2023

  • sneak delegation action to ctxTx
  • refactor constraints in constructSharedTx
  • introduce ErrConstructTxStakingInvalid with integration test
  • create proper staking credential during tx construction
  • introduce script as credential in shelley module
  • introduce dScriptTemplateM in balanceTransaction
  • introduce txStakingTemplate in TxSkeleton
  • fee adjustment
  • inject delegation script if it is valid
  • add emptySharedWalletDelegating and fixtureSharedWalletdelegating
  • constructTx with delegation integration test
  • account deposit/refunds
  • make sure decodeSharedTransaction account deposits/refunds and certificates properly
  • extending WitnessCtx in the context of decodeSharedTransaction
  • signing mechanism
  • show signing in integration testing
  • sneaking WitnessCtx in signTransaction
  • guarding submission and adding proper integration tests

Comments

Issue Number

adp-2602

@paweljakubas paweljakubas self-assigned this Feb 10, 2023
@paweljakubas paweljakubas force-pushed the paweljakubas/adp-2602/construct-tx-with-delegation-shared-wallets branch 2 times, most recently from 51fef79 to de18bc7 Compare February 17, 2023 15:58
@paweljakubas paweljakubas changed the title construct tx with delegation shared wallets Construct/sign/submit tx with delegation shared wallets Feb 20, 2023
@paweljakubas paweljakubas force-pushed the paweljakubas/adp-2602/construct-tx-with-delegation-shared-wallets branch 2 times, most recently from 050ad1b to c8fb348 Compare February 22, 2023 17:16
@paweljakubas paweljakubas force-pushed the paweljakubas/adp-2602/construct-tx-with-delegation-shared-wallets branch from dd0e09d to 5e290cd Compare February 24, 2023 16:06
@paweljakubas paweljakubas marked this pull request as ready for review February 24, 2023 16:07
toCANetworkDistriminant
:: forall (n :: NetworkDiscriminant). Typeable n
=> CA.NetworkDiscriminant CA.Shelley
toCANetworkDistriminant =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function seems unused. Do you have plans for it, or should it be removed?

Comment on lines +2995 to +2998
<$ filter ourRewardAccountRegistration certs
, depositsReturned =
(Quantity . fromIntegral . unCoin . W.stakeKeyDeposit $ pp)
<$ filter ourRewardAccountDeregistration certs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does not expose external deposits and returns. Should it not? Otherwise the tx may look unbalanced based on the response.

decodeTx tl era witCountCtx sealedTx

let numberStakingNativeScripts =
length $ filter hasDelegationKeyHash nativeScripts
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not get this from delegationScriptTemplateM?

@@ -2141,6 +2229,7 @@ estimateTxSize era skeleton =
+ sizeOf_VKeyWitnesses
+ sizeOf_NativeScripts txMintOrBurnScripts
+ maybe 0 (determinePaymentTemplateSize txMintOrBurnScripts) txPaymentTemplate
+ maybe 0 determineStakingTemplateSize txStakingTemplate
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not seen by balanceTx, so any change to estimateTxSize should not be needed.

let accXPub = getRawKey $ Shared.accountXPub s
let xpub = CA.getKey $
deriveDelegationPublicKey (CA.liftXPub accXPub) minBound
let delCred = maybeToRight xpub scriptM
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With ErrConstructTxStakingInvalid, I don't think we can ever hit the xpub case? If so, I suspect an error would be clearer (and obviously, rewriting everything such that the error is not needed would be even clearer, but I think that's for the future.)

let
rewardAcnt :: (XPrv, Passphrase "encryption")
rewardAcnt =
(getRawKey $ deriveRewardAccount @k rootPwd rootKey, rootPwd)
(getRawKey $ deriveRewardAccount @k rootPwd rootKey minBound, rootPwd)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe rewardAcnt is redundant in the case of shared wallets; if we stake the XPrv for signing withdrawals and certificates will always be the same. This doesn't really matter, but could be confusing. I suspect it could be fixed now, but otherwise ADP-2675 should make this easier to deal with.

Cardano.StakeAddressDeregistrationCertificate cred ->
estimateWitNumForCred cred
Cardano.StakeAddressDelegationCertificate cred _ ->
estimateWitNumForCred cred
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to resolve the scripts from ByScript credentials. We already have scriptVkWitsUpperBound, and could handle it in a simpler and possible safer way by:

  1. Make estimateWitNumForCred only return 1 for key credentials and 0 otherwise.
  2. Drop apiScriptHashes - we don't need the resolution

I tried this locally and it fails with (FeeTooSmallUTxO (Coin 176900) (Coin 166800). But I suspect this is because we somehow sign with one witness too much, probably because of duplication between:

        , mapMaybe mkWdrlCertWitness certs
        , mapMaybe mkStakingScriptWitness stakingScriptsKeyHashes

@Anviking
Copy link
Member

Anviking commented Mar 1, 2023

Haven't made the final review (waiting for response now & happy to chat), but I wanted to also point out / emphasise overall that I really feel

  1. Refactoring signTx / estimateNumberOfWitnesses https://input-output.atlassian.net/browse/ADP-2676 / https://input-output.atlassian.net/browse/ADP-2675 / using Ledger.witsVKeysNeeded
  2. Refactoring TransactionCtx and mkUnsignedTx somehow (I think likely stop trying very hard to generalise, and instead splitting into more specialised parts)

would make the logic in this PR much neater and is something we should do fairly soon.

decodeErrorInfo rTx `shouldBe` StakingInvalid

it "SHARED_TRANSACTIONS_DELEGATION_01a - \
\Can join stakepool, rejoin another and quit" $ \ctx -> runResourceT $ do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Integration tests only covers join atm. rejoin and quit are missing if I'm not mistaken.

Also, I've noticed (after joining shared wallet on preprod) that the delegation settings returned as part of getSharedWallet are not updated and still show:

  "delegation": {
    "active": {
      "status": "not_delegating"
    },
    "next": []
  }

Therefore we need to make sure to also check something like this.

@paweljakubas
Copy link
Contributor Author

closing in favor of #3830

@paweljakubas paweljakubas deleted the paweljakubas/adp-2602/construct-tx-with-delegation-shared-wallets branch April 4, 2023 13:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants