Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Pay: fix duplicated PSBT inputs #136

Merged
merged 2 commits into from
Mar 27, 2024
Merged

Pay: fix duplicated PSBT inputs #136

merged 2 commits into from
Mar 27, 2024

Conversation

dr-orlovsky
Copy link
Member

@dr-orlovsky dr-orlovsky commented Feb 27, 2024

Closes #117 and BP-WG/bp-wallet#14

@Matrix-Zhang this fixes an issue you have reported, can you confirm that it works with this code?

@dr-orlovsky dr-orlovsky added the bug Something isn't working label Feb 27, 2024
@dr-orlovsky dr-orlovsky added this to the v0.11.0 milestone Feb 27, 2024
@dr-orlovsky dr-orlovsky requested a review from nicbus February 27, 2024 01:40
@dr-orlovsky dr-orlovsky self-assigned this Feb 27, 2024
@nicbus
Copy link
Member

nicbus commented Feb 27, 2024

Testing what was originally reported as BP-WG/bp-wallet#14, using an updated rgb-sandbox branch, I now get the following error:

Error: provided transaction batch references inputs which are absent from the PSBT. Possible it was created for a different PSBT.

Note: I had to slightly modify the sandbox in order to trigger the error 100% of the times (by default it creates a new UTXO for each transfer so it worked if the 2nd transfer was not allocated to the same UTXO as the 1st one).

@dr-orlovsky dr-orlovsky force-pushed the master branch 4 times, most recently from a9c5c8d to d49aa9f Compare March 7, 2024 21:33
@nicbus
Copy link
Member

nicbus commented Mar 22, 2024

Tested with an updated rgb-sandbox branch that uses the deps fix cherry-picked on top of the current master branch of rgb-wallet and the issue is still there.

@dr-orlovsky
Copy link
Member Author

I can't run the tests locally so can't see why it is all failing. Can you please re-run it again with the updated code and give me what is printed in the stderr?

@nicbus
Copy link
Member

nicbus commented Mar 26, 2024

Tested it again (rgb-sandbox branch) using the updated rgb branch dups (commit ea858d0) and what I get when calling rgb transfer is:

RGB: command-line wallet for RGB smart contracts
     by LNP/BP Standards Association

Loading descriptor from wallet rcpt1 ... success
Loading stock ... success
Error: provided transaction batch references inputs which are absent from the PSBT. Possible it was created for a different PSBT.

@dr-orlovsky
Copy link
Member Author

In ea858d0 I have added additional eprints. Strange they do not appear in output. Can you doublechexk you are using the right branch with that commit and capture STDERR?

I need them to understand what's going on

@nicbus
Copy link
Member

nicbus commented Mar 26, 2024

Installing rgb-wallet v0.11.0-beta.4 (https://github.com/RGB-WG/rgb?branch=dups#ea858d04)
...

RGB: command-line wallet for RGB smart contracts                                                                                                                                                                                                                                                                               
     by LNP/BP Standards Association                                                                                                                                                                                                                                                                                           
                                                                                                                                                                                                                                                                                                                               
Loading descriptor from wallet rcpt1 ... success                                                                                                                                                                                                                                                                               
Loading stock ... success                                                                                                                                                                                                                                                                                                      
Error: provided transaction batch references inputs which are absent from the PSBT. Possible it was created for a different PSBT.                                                                                                                                                                                              

This is all the output I get. Trying to manually execute the command confirms it, STDERR is included.
The reason why eprintln!s don't show up is therefore that compose() succeeds.

Adding more debug prints I see that the failing instruction in construct_psbt() is:

        psbt.rgb_embed(batch)?;

In rgb_embed() the fail occurs at:

            if !inputs.is_empty() {
                return Err(EmbedError::AbsentInputs);
            }

@dr-orlovsky
Copy link
Member Author

Thank you for pointing out! I have fixed the debugging code and now it should print the info which will help me to understand how something can go wrong there...

@nicbus
Copy link
Member

nicbus commented Mar 27, 2024

Here is the output for a run with rgb dups branch at commit b9f4c51:

RGB: command-line wallet for RGB smart contracts
     by LNP/BP Standards Association

Loading descriptor from wallet rcpt1 ... success
Loading stock ... success
main:
  id: 6ee4c451cc59e2557de8e92972857accc4b0a288dbf9bcb898418e79bb08f423
  inputs:
  - bc:59cadb138e8514cbe81134a832790e07fd9b0ce0785c3f5448270044a9ea8abc:0
  - bc:59cadb138e8514cbe81134a832790e07fd9b0ce0785c3f5448270044a9ea8abc:0
  transition:
    ffv: 0
    contractId: 2c060c73f1c088cf286d4df14fb170dfa3beb0a4d0a57e798befe6f80df74ed6
    transitionType: 10000
    metadata: ''
    globals: {}
    inputs:
    - prevOut:
        op: 9bbedb5909fc3721a36eceee007e6e905cef701e78d29ba14a4d98eaffabb65f
        ty: 4000
        no: 1
    - prevOut:
        op: ac17c3fbb032a5df092a8fa87d194a6da6ce8472f09c6b0b21337907a5f7c266
        ty: 4000
        no: 1
    assignments:
      4000:
        type: fungible
        items:
        - seal:
            chain: bitcoin
            data:
              method: opretFirst
              txid: null
              vout: 0
              blinding: 9654612230337645359
          state:
            value: 50
            blinding: 51d84e2cf48831beb41a74f23038d17499c6c47bf17550bda3b13bd790982ed6
            tag: 8665bf728469454a6ba9746967e93f162fdaee3633f13073772f2c43d64d2422
          lock: null
        - seal:
            chain: bitcoin
            data: 6cb31746a7a2400b7e9ae8999df2e71c74aa922ed284959064ad3d90b0458232
          state:
            value: 250
            blinding: 7db2492bcd33029167b39e19a39d5262dcf9c5ba92507cc5fa16b35591200141
            tag: 8665bf728469454a6ba9746967e93f162fdaee3633f13073772f2c43d64d2422
          lock: null
    valencies: []
    witness: null
    script: null
  methods: opretFirst
blanks: []

version: v2
txVersion: 2
fallbackLocktime: null
inputs:
- previousOutpoint: 59cadb138e8514cbe81134a832790e07fd9b0ce0785c3f5448270044a9ea8abc:0
  sequenceNumber: 0
  requiredTimeLock: null
  requiredHeightLock: null
  nonWitnessTx: null
  witnessUtxo:
    value: 100000000
    scriptPubkey: 0014bb5ff2477675bb424b43fad65c4a88840b0944d1
  partialSigs: {}
  sighashType: null
  redeemScript: null
  witnessScript: null
  bip32Derivation:
    02a992cf5eb89dc0cc63d654210197bcd6d1478defbd9651299d4247272ed98cc3:
      masterFp: 4b3b02fb
      derivation:
      - !hardened 84
      - !hardened 1
      - !hardened 0
      - !normal 9
      - !normal 0
  finalScriptSig: null
  finalWitness: null
  proofOfReserves: null
  ripemd160: {}
  sha256: {}
  hash160: {}
  hash256: {}
  tapKeySig: null
  tapScriptSig: {}
  tapLeafScript: {}
  tapBip32Derivation: {}
  tapInternalKey: null
  tapMerkleRoot: null
  proprietary:
    ? identifier: RGB
      subtype: 1
      data: 2c060c73f1c088cf286d4df14fb170dfa3beb0a4d0a57e798befe6f80df74ed6
    : 6ee4c451cc59e2557de8e92972857accc4b0a288dbf9bcb898418e79bb08f423
  unknown: {}
outputs:
- amount: 99999600
  script: 0014a0df45e278026f26077eea62f9158309a8a31ad6
  redeemScript: null
  witnessScript: null
  bip32Derivation:
    02c6569363ae77cbb0055fee566628413df1b7db5bde3c93c2649957f5379d2f05:
      masterFp: 4b3b02fb
      derivation:
      - !hardened 84
      - !hardened 1
      - !hardened 0
      - !normal 9
      - !normal 1
  tapInternalKey: null
  tapTree: null
  tapBip32Derivation: {}
  proprietary: {}
  unknown: {}
- amount: 0
  script: 6a00
  redeemScript: null
  witnessScript: null
  bip32Derivation: {}
  tapInternalKey: null
  tapTree: null
  tapBip32Derivation: {}
  proprietary:
    ? identifier: OPRET
      subtype: 0
      data: ''
    : ''
  unknown: {}
xpubs:
  tpubDCd6kwfxJH3DK1ofLX7S9BVuPwdYAfUuXm5UUgiGhpEBvCiYwgngQQn4sNfkd33mcWXpEfuUJh6pn3K9SZnXtYaWVWH9H5qPV7EbiyEWYim:
    masterFp: 4b3b02fb
    derivation:
    - 84
    - 1
    - 0
txModifiable:
  inputsModifiable: false
  outputsModifiable: false
  sighashSingle: false
  unknown: 0
proprietary: {}
unknown: {}

{
    Bitcoin(
        ExplicitSeal {
            method: OpretFirst,
            txid: Array<32>(59cadb138e8514cbe81134a832790e07fd9b0ce0785c3f5448270044a9ea8abc),
            vout: Vout(
                0,
            ),
        },
    ),
}
{
    Outpoint {
        txid: Array<32>(59cadb138e8514cbe81134a832790e07fd9b0ce0785c3f5448270044a9ea8abc),
        vout: Vout(
            0,
        ),
    },
}
Error: provided transaction batch references inputs which are absent from the PSBT. Possible it was created for a different PSBT.

@dr-orlovsky
Copy link
Member Author

Ok, thanks for your input I have figured out the source of the problem. Again, it was two independent bugs, not one. The other one is now fixed in RGB-WG/rgb-std#174 and this PR has being updated to use that fix.

Please run the test now - everything should work

@Matrix-Zhang
Copy link

@dr-orlovsky sorry to reply late,
i have test with

rgb-runtime = { git = "https://github.com/RGB-WG/rgb", branch = "dups", features = [
    "esplora_blocking",
    "serde",
] }
rgb-std = { git = "https://github.com/RGB-WG/rgb-std", branch = "dups" }

it fixed

@nicbus
Copy link
Member

nicbus commented Mar 27, 2024

A run with rgb dups branch at commit ee782e2 shows no errors.

Copy link
Member

@nicbus nicbus left a comment

Choose a reason for hiding this comment

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

ACK ee782e2

note: the last commit is not signed

@dr-orlovsky dr-orlovsky merged commit ee58df2 into master Mar 27, 2024
15 of 20 checks passed
@dr-orlovsky dr-orlovsky deleted the dups branch September 5, 2024 11:46
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Something isn't working
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

duplicate outpoint when transfer multi RGB20 from 1 UTXO
3 participants