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

[Rosetta][Data-API] transaction with stx_unlock op has conflicting transaction hash #760

Closed
shermanxiong opened this issue Sep 14, 2021 · 3 comments · Fixed by #763
Closed
Assignees
Labels
P1 Priority 1 Critical functionality not working Impacts all/most customers released rosetta

Comments

@shermanxiong
Copy link

shermanxiong commented Sep 14, 2021

Context

When Zondax initially added support in Rosetta API for stacking: #613 , "forged" transactions were created with stx_unlock operations because there are no actual on-chain transactions to show that accounts' tokens unlocked. This is due CB requiring balance changing events to be on-chain events otherwise addresses will be quarantined.

So the solution was to create a transaction to show these operations happened that only shows up in the Rosetta implementation and doesn't actually exist on-chain.

However, the implementation appears to use the transaction hash of the previous stack_stx operation for the account that shows up in the first stx_unlock operation's. This results in a transaction hash being used in two different blocks and causes issues because we can never actually return the "forged" transaction from /block/transaction.

Simple Example

Account ABC stacked tokens (stack_stx op and stx_lock) in block 5. The transaction hash is 0x01
Then, Account ABC unlocks tokens (stx_unlock) in block 10. The transaction hash for this "forged" transaction shows up also as 0x01. When querying this transaction on /block/transaction, it shows the transaction that includes the stack_stx and stx_lock operations while the "forged" transaction is unable to be queried.

Actual Example for Block 6926 in Testnet

      {
        "transaction_identifier": {
          "hash": "0x7cfac55147759a14d163bd96b89138df090dd730df5fa5c34a086011b5e9621e"
        },
        "operations": [
          {
            "operation_identifier": {
              "index": 0
            },
            "type": "stx_unlock",
            "status": "success",
            "account": {
              "address": "ST3C4YVASFG37P8E6210J9KHZJB4MF8ZRBQFKH41N"
            },
            "amount": {
              "value": "5140000000000",
              "currency": {
                "decimals": 6,
                "symbol": "STX"
              }
            },
            "metadata": {
              "tx_id": "0x7cfac55147759a14d163bd96b89138df090dd730df5fa5c34a086011b5e9621e"
            }
          },
          {
            "operation_identifier": {
              "index": 1
            },
            "type": "stx_unlock",
            "status": "success",
            "account": {
              "address": "ST3VR1JMSSCAXPQJSDKCCMX3TXB5RRYWBYK8HVK9S"
            },
            "amount": {
              "value": "6168000000000",
              "currency": {
                "decimals": 6,
                "symbol": "STX"
              }
            },
            "metadata": {
              "tx_id": "0xb078acd27a067d03ef87c3c112e74dc491665d1d7d28a49a2b0bae315ca227ef"
            }
          },
          {
            "operation_identifier": {
              "index": 2
            },
            "type": "stx_unlock",
            "status": "success",
            "account": {
              "address": "ST343J7DNE122AVCSC4HEK4MF871PW470ZV04CFXH"
            },
            "amount": {
              "value": "5500000000000",
              "currency": {
                "decimals": 6,
                "symbol": "STX"
              }
            },
            "metadata": {
              "tx_id": "0xac73fa29e0d9ef4c23ebf0867b6fdeb7ffa3ad249599f37ff9faa974259940e4"
            }
          },
          {
            "operation_identifier": {
              "index": 3
            },
            "type": "stx_unlock",
            "status": "success",
            "account": {
              "address": "ST319CF5WV77KYR1H3GT0GZ7B8Q4AQPY42ETP1VPF"
            },
            "amount": {
              "value": "5000000000000000",
              "currency": {
                "decimals": 6,
                "symbol": "STX"
              }
            },
            "metadata": {
              "tx_id": "0x86a70f4302c1f5a4e723bc5a1bbf21eaa34fc157160f08ed7105e83e0ada82bc"
            }
          },
          {
            "operation_identifier": {
              "index": 4
            },
            "type": "stx_unlock",
            "status": "success",
            "account": {
              "address": "ST221Z6TDTC5E0BYR2V624Q2ST6R0Q71T78WTAX6H"
            },
            "amount": {
              "value": "5000000000000000",
              "currency": {
                "decimals": 6,
                "symbol": "STX"
              }
            },
            "metadata": {
              "tx_id": "0x5d154237eb71d6ec3c8ca2a3aaad158485a90c1b14b841a4c5fcb6e3209105b6"
            }
          },
          {
            "operation_identifier": {
              "index": 5
            },
            "type": "stx_unlock",
            "status": "success",
            "account": {
              "address": "ST3QS01894F67ZQ9V4WQEVC3P0YPVAMGQPXF71YQJ"
            },
            "amount": {
              "value": "6000000000000",
              "currency": {
                "decimals": 6,
                "symbol": "STX"
              }
            },
            "metadata": {
              "tx_id": "0x915f99fb8f37df9480a9ce88a98619e1c450327cb21013e514d1d077a73cf62e"
            }
          },
          {
            "operation_identifier": {
              "index": 6
            },
            "type": "stx_unlock",
            "status": "success",
            "account": {
              "address": "ST33DR7DBHWGT4Z7F1M1KB4KERY99SFNE0RMPZVE5"
            },
            "amount": {
              "value": "6167000000000",
              "currency": {
                "decimals": 6,
                "symbol": "STX"
              }
            },
            "metadata": {
              "tx_id": "0xf1266013ff6b0dbae07d9f7fbaa5aa3773dd634dc15b43877ae4d0bcabcc884e"
            }
          }

Note how transaction_identifier.hash matches the first operation's metadata.tx_id:

        "transaction_identifier": {
          "hash": "0x7cfac55147759a14d163bd96b89138df090dd730df5fa5c34a086011b5e9621e"
        },

        "metadata": {
          "tx_id": "0x7cfac55147759a14d163bd96b89138df090dd730df5fa5c34a086011b5e9621e"
        }

But when you try to look up transaction hash 0x7cfac55147759a14d163bd96b89138df090dd730df5fa5c34a086011b5e9621e on block/transaction, the transaction returned is the transaction for the stacking (that happened in block 5757).

{
  "transaction_identifier": {
    "hash": "0x7cfac55147759a14d163bd96b89138df090dd730df5fa5c34a086011b5e9621e"
  },
  "operations": [
    {
      "operation_identifier": {
        "index": 0
      },
      "type": "fee",
      "status": "success",
      "account": {
        "address": "ST3C4YVASFG37P8E6210J9KHZJB4MF8ZRBQFKH41N"
      },
      "amount": {
        "value": "-260",
        "currency": {
          "decimals": 6,
          "symbol": "STX"
        }
      }
    },
    {
      "operation_identifier": {
        "index": 1
      },
      "type": "stack_stx",
      "status": "success",
      "account": {
        "address": "ST3C4YVASFG37P8E6210J9KHZJB4MF8ZRBQFKH41N"
      },
      "metadata": {
        "lock_period": "1",
        "amount_ustx": "5140000000000",
        "start_burn_height": "2065169",
        "unlock_burn_height": "2067200",
        "stacker_address": "ST3C4YVASFG37P8E6210J9KHZJB4MF8ZRBQFKH41N",
        "pox_addr": "mmPKhbTX4mM4R6LAJDfq3yaRR2WHs6XkJS"
      }
    },
    {
      "operation_identifier": {
        "index": 2
      },
      "type": "stx_lock",
      "status": "success",
      "account": {
        "address": "ST3C4YVASFG37P8E6210J9KHZJB4MF8ZRBQFKH41N"
      },
      "amount": {
        "value": "-5140000000000",
        "currency": {
          "decimals": 6,
          "symbol": "STX"
        }
      },
      "metadata": {
        "locked": "5140000000000",
        "unlock_height": "2067200"
      }
    }
  ]
}

Request

Could the protocol be able to incorporate an actual on-chain event for the token unlock?
Or if not, could the "forged" transaction use a brand new transaction hash (that only Rosetta would use). The caveat to that would be there still could be a conflict if a future block mined by chance uses that transaction hash in one of the transactions.

@zone117x
Copy link
Member

Could the protocol be able to incorporate an actual on-chain event for the token unlock?

This would require changes to the core node which wouldn't happen anytime soon.

Or if not, could the "forged" transaction use a brand new transaction hash (that only Rosetta would use).

Seems like these forged stx_unlock operations should use the block's coinbase tx, that's where we've historically included events that don't fit anywhere else.

@asimm241 is this something you can take on?

@asimm241
Copy link
Contributor

@zone117x sure.

@zone117x zone117x added rosetta P1 Priority 1 Critical functionality not working Impacts all/most customers labels Sep 14, 2021
@asimm241 asimm241 linked a pull request Sep 16, 2021 that will close this issue
9 tasks
blockstack-devops pushed a commit that referenced this issue Sep 16, 2021
# [0.67.0](v0.66.1...v0.67.0) (2021-09-16)

### Bug Fixes

* **rosetta:** use coinbase txs hash instead of stx_lock for forged unlock_transaction [#760](#760) ([37adcc7](37adcc7))
* disable http keep-alive for stacks-node /v2 proxied endpoints ([cebeda0](cebeda0))
* increase the 10 second cap on prometheus http metric reporting ([735874e](735874e))
* replicate query optimizations to other asset txs queries ([05c9931](05c9931))

### Features

* automatically generate postman collection from the openapi spec ([5f07d74](5f07d74))
* **rosetta:** support memos in stx token transfer operations [#752](#752) ([6f4f3e2](6f4f3e2))
@blockstack-devops
Copy link

🎉 This issue has been resolved in version 0.67.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

wileyj added a commit that referenced this issue Nov 16, 2021
* develop: (40 commits)
  feat: added execution cost to block response #735
  feat: ability to configure multiple tx broadcast endpoints #765
  fix: return the latest name by address #714
  fix(rosetta): use coinbase txs hash instead of stx_lock for forged unlock_transaction #760
  feat: automatically generate postman collection from the openapi spec
  fix: disable http keep-alive for stacks-node /v2 proxied endpoints
  fix: increase the 10 second cap on prometheus http metric reporting
  chore: update typescript to 4.4.2
  feat(rosetta): support memos in stx token transfer operations #752
  fix: replicate query optimizations to other asset txs queries
  fix: optimize query that retrieves txs with asset transfers
  fix(rosetta): do not assume encoding of delegate-stx `pox_addr` data #732
  feat: added a new endpoint fee_rate #729
  chore(release): 0.65.0 [skip ci]
  fix: sql optimizations to speed up various tx queries
  feat: add execution cost data to transactions
  feat: token metadata
  fix: short summaries for BNS endpoints
  feat: emit prometheus metrics for socket.io
  fix: added types for search endpoint #645
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 Priority 1 Critical functionality not working Impacts all/most customers released rosetta
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants