RGB-WG / rgb-tests

RGB tests
Apache License 2.0
2 stars 9 forks source link

[Bug Report] Missing Transaction History for RGB Asset Transfers #4

Closed k0k0ne closed 1 month ago

k0k0ne commented 1 month ago

Description

We've identified two issues with the transaction history recording for RGB asset transfers:

  1. Incomplete transfer records between wallets: When transferring assets from Wallet A to Wallet B, only the sender's (Wallet A) transaction history shows the outgoing transfer. The recipient's (Wallet B) history does not reflect the incoming transfer, despite the assets being successfully received.

  2. Missing self-transfer records: When a wallet transfers assets to itself, neither the outgoing nor the incoming transaction is recorded in the wallet's history. The balance is updated correctly, but there's no trace of the transfer in the transaction history.

Steps to Reproduce

  1. Run the integration test located at tests/history-missing-bug.rs (https://github.com/RGB-WG/rgb-integration-tests/pull/3)
  2. Observe the output logs for both scenarios

Expected Behavior

  1. Inter-wallet transfers: Both the sender and recipient wallets should have transaction records reflecting the transfer.
  2. Self-transfers: The wallet should record both the outgoing and incoming transactions for self-transfers.

Actual Behavior

  1. Inter-wallet transfers: Only the sender's wallet shows the outgoing transaction. The recipient's wallet history is empty.
  2. Self-transfers: No transaction records are created for self-transfers in the wallet's history.

Additional Information:

k0k0ne commented 1 month ago

Log

---- missing_history_bug stdout ----
Starting test: missing_history_bug
starting test services...
waiting for indexer to sync with bitcoind...
wallet dir: "tests/tmp/1bfd3b97"
 keychain 0 .......... keychain 1 .......... keychain 9 ..........wallet dir: "tests/tmp/7acf740f"
 keychain 0 .......... keychain 1 .......... keychain 9 ..........Wallets created: wlt_1 and wlt_2
Initial amount: 100000
 keychain 0 .......... keychain 1 .......... keychain 9 ...........Contract issued - ID: ContractId(Array<32>(338b88a2a45510ca0f820a74af1341203861b91b18a3ba2732802f081134e798)), Interface type: RGB20Fixed
Initial height: 104
Amount  Counterparty    Witness Id
Transfer amount: 200
Invoice created: RgbInvoice { transports: [UnspecifiedMeans], contract: Some(ContractId(Array<32>(338b88a2a45510ca0f820a74af1341203861b91b18a3ba2732802f081134e798))), iface: Some(TypeName("RGB20Fixed")), operation: None, assignment: None, beneficiary: BitcoinRegtest(WitnessVout(Pay2Vout { method: OpretFirst, address: Wpkh(WPubkeyHash(Array<20>(2c640e65f331d9d012d4467ff617415cc2844cc2))) })), owned_state: Amount(Amount(200)), expiry: None, unknown_query: {} }
 keychain 0 .......... keychain 1 .......... keychain 9 ...........transfer txid: "197b2005e5822d831285cca9e406e5f65c82b48db5c7199bb7f272b69dd16a98"
Height: 104
 keychain 0 .......... keychain 1 .......... keychain 9 ........... keychain 0 .......... keychain 1 .......... keychain 9 ............ keychain 0 .......... keychain 1 .......... keychain 9 ...........Height: 105
History 1:
Amount  Counterparty    Witness Id
-200,-Sa        none    bc:197b2005e5822d831285cca9e406e5f65c82b48db5c7199bb7f272b69dd16a98
Balance 1:
Global:
  spec := (ticker=("NIATCKR"), name=("NIA asset name"), details=~, precision=2)
  terms := (text=("NIA terms"), media=~)
  issuedSupply := (100000)

Owned:
  assetOwner:
    amount=VccFc, utxo=bc:opret1st:197b2005e5822d831285cca9e406e5f65c82b48db5c7199bb7f272b69dd16a98:1, witness=Some(Bitcoin(Array<32>(197b2005e5822d831285cca9e406e5f65c82b48db5c7199bb7f272b69dd16a98))) # owned by the wallet
    amount=Mcdac, utxo=bc:opret1st:c32dd7038dd14b7de4972d1ec16d93a7cb59b3b28af586dc091ff0ea656bf8df:0, witness=None # owner unknown
    amount=Sa, utxo=bc:opret1st:197b2005e5822d831285cca9e406e5f65c82b48db5c7199bb7f272b69dd16a98:0, witness=Some(Bitcoin(Array<32>(197b2005e5822d831285cca9e406e5f65c82b48db5c7199bb7f272b69dd16a98))) # owner unknown

Height     Amount, ṩ    Outpoint                                                            
bcrt1q62g5jsuwg3uncu25u22mampvhyague7syggdqy    &9/1
105         99996766    197b2005e5822d831285cca9e406e5f65c82b48db5c7199bb7f272b69dd16a98:1

Wallet total balance: 99996766 ṩ
()
History 2:
Amount  Counterparty    Witness Id
Balance 2:
Global:
  spec := (ticker=("NIATCKR"), name=("NIA asset name"), details=~, precision=2)
  terms := (text=("NIA terms"), media=~)
  issuedSupply := (100000)

Owned:
  assetOwner:
    amount=Mcdac, utxo=bc:opret1st:c32dd7038dd14b7de4972d1ec16d93a7cb59b3b28af586dc091ff0ea656bf8df:0, witness=None # owner unknown

Height     Amount, ṩ    Outpoint                                                            
bcrt1q93jque0nx8vaqyk5gellv96ptnpggnxztvwygq    &9/0
105             2000    197b2005e5822d831285cca9e406e5f65c82b48db5c7199bb7f272b69dd16a98:0

Wallet total balance: 2000 ṩ
()

---- self_transfer_example stdout ----
Starting test: self_transfer_example
starting test services...
waiting for indexer to sync with bitcoind...
wallet dir: "tests/tmp/21563e33"
 keychain 0 .......... keychain 1 .......... keychain 9 ..........Wallet created: wlt
Initial amount: 100000
 keychain 0 .......... keychain 1 .......... keychain 9 ...........Contract issued - ID: ContractId(Array<32>(053e1566d7b1cb7e043e835dd57b9683563b0e355424ca19d8b788bafd2df411)), Interface type: RGB20Fixed
Amount  Counterparty    Witness Id
Transfer amount: 300
Invoice created: RgbInvoice { transports: [UnspecifiedMeans], contract: Some(ContractId(Array<32>(053e1566d7b1cb7e043e835dd57b9683563b0e355424ca19d8b788bafd2df411))), iface: Some(TypeName("RGB20Fixed")), operation: None, assignment: None, beneficiary: BitcoinRegtest(WitnessVout(Pay2Vout { method: OpretFirst, address: Wpkh(WPubkeyHash(Array<20>(2bb6bd3344e75ee6eab70dd16fa5c06b3567cbba))) })), owned_state: Amount(Amount(300)), expiry: None, unknown_query: {} }
 keychain 0 .......... keychain 1 .......... keychain 9 ...........transfer txid: "a2eee953dbb1794ae6e9cb0c8b47b3c18c1199913e8883ed345c875ed5bb34f8"
Height: 104
 keychain 0 .......... keychain 1 .......... keychain 9 ............ keychain 0 .......... keychain 1 .......... keychain 9 ............Height after sync: 105
Final History:
Amount  Counterparty    Witness Id
Balance:
Global:
  spec := (ticker=("NIATCKR"), name=("NIA asset name"), details=~, precision=2)
  terms := (text=("NIA terms"), media=~)
  issuedSupply := (100000)

Owned:
  assetOwner:
    amount=Mcdac, utxo=bc:opret1st:dcabd0c11a310ef8a0887a1cc5e83cb6b1b3967dae2bb9f5f0101a3044423c6a:0, witness=None # owner unknown

Height     Amount, ṩ    Outpoint                                                            
bcrt1q9wmt6v6yua0wd64hphgklfwqdv6k0ja60whw06    &9/0
105             2000    a2eee953dbb1794ae6e9cb0c8b47b3c18c1199913e8883ed345c875ed5bb34f8:0

bcrt1q5t6kqnnyzk8cytvedzpdzafher0mrlcxlgkue8    &9/1
105         99996766    a2eee953dbb1794ae6e9cb0c8b47b3c18c1199913e8883ed345c875ed5bb34f8:1

Wallet total balance: 99998766 ṩ
()
zoedberg commented 1 month ago

This is not an issue of the integration tests so I would move this to https://github.com/RGB-WG/rgb

zoedberg commented 1 month ago

Closing this in favor of https://github.com/RGB-WG/rgb/issues/252