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

txscript/v4/stdscript migration #1879

Merged
merged 3 commits into from Dec 16, 2021
Merged

txscript/v4/stdscript migration #1879

merged 3 commits into from Dec 16, 2021

Conversation

chappjc
Copy link
Member

@chappjc chappjc commented Nov 21, 2021

This migrates to the new txscript/v4/stdscript package.

New script class types in dbtypes and api/types are created to maintain the same script class strings.

This uncovered a pg DB bug that has existed since the birth of the dcrpg package. Tickets have always had the is_multisig BOOL column set to false. A DB upgrade would be needed to identify p2sh tickets, or just remove the is_multisig column entirely. I think the idea of this column was to distinguish solo (P2PKH) and legacy stakepool (P2SH) tickets. For some reason the code was checking the subtype of the stake submission but only setting is_multisig was multisig, which was never the case since it is either pkh or sh. I've confirmed that there are no instances of is_multisig being true in a mainnet tickets table. I think I will remove this since clearly no one looks at the column, and the corresponding output type can be determined via the vouts table.

db/dcrpg/queries.go Outdated Show resolved Hide resolved
txhelpers/swap.go Show resolved Hide resolved
db/dcrpg/pgblockchain.go Outdated Show resolved Hide resolved
txhelpers/swap.go Outdated Show resolved Hide resolved
@chappjc chappjc mentioned this pull request Dec 11, 2021
dbtypes: ScriptClass type for stable string values

TxRawResult -> MsgTx unless block info needed
@chappjc
Copy link
Member Author

chappjc commented Dec 12, 2021

Script classes are now being kept unchanged despite the more fine-grained stdscript types on account of the new api and db types in the following key places:

  1. Display on explorer pages
  2. Encoded in JSON API endpoints
  3. Stored in the postgresql DB

In addition to keeping the different stake subtypes combined (e.g. sstxchange-scripthash || sstxchange-pubkeyhash == sstxchange), both (1) and (2) also translate the special odd numbered nulldata outputs of tickets/stakesubmissions as sstxcommitment. The database has always stored these as nulldata, and that is unchanged.

Running as expected on https://tip.dcrdata.org with dcrd 1.7/master.

@chappjc chappjc marked this pull request as ready for review December 12, 2021 16:26
@chappjc
Copy link
Member Author

chappjc commented Dec 15, 2021

3 days on tip.dcrdata.org. script_type summary in postgres:

# select script_type, count(*) from vouts group by script_type;
   script_type   |  count   
-----------------+----------
 nonstandard     |        1
 nulldata        | 11039755
 pubkey          |      951
 pubkeyalt       |        1
 pubkeyhash      | 24744771
 scripthash      |   684404
 sstxchange      |  4278104
 stakegen        |  4150118
 stakerevoke     |    83265
 stakesubmission |  3123067
 treasuryadd     |    63718
 treasurygen     |        1
(12 rows)

This indicates the stored script types are stable with dbtypes.ScriptClass translating from the stdscript type to the internal DB type.

The explorer pages are also showing the same script types, including the "sstxcommitment" pseudo-type, along with the script version: https://tip.dcrdata.org/tx/78f070e11fbccdfc2bb13e0f7b221c873d1656997ac47b91b90c3617d367170c

image

API:

   "vout": [
    {
      "value": 196.73779166,
      "n": 0,
      "version": 0,
      "scriptPubKey": {
        "asm": "OP_SSTX OP_DUP OP_HASH160 064f47471cf7378c93b2330c9ac954cf69692b5d OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "ba76a914064f47471cf7378c93b2330c9ac954cf69692b5d88ac",
        "version": 0,
        "reqSigs": 1,
        "type": "stakesubmission",
        "addresses": [
          "DsRYGWwfSz3pnGgWmSzAzLMVb9NrZWDVa19"
        ]
      }
    },
    {
      "value": 0,
      "n": 1,
      "version": 0,
      "scriptPubKey": {
        "asm": "OP_RETURN 2a372905e48a34601d842ff88bbed0d117932afa8217a694040000000058",
        "hex": "6a1e2a372905e48a34601d842ff88bbed0d117932afa8217a694040000000058",
        "version": 0,
        "type": "sstxcommitment",
        "addresses": [
          "DsUp7x65r9eBnrzoeF6Y6ncZvuaLfXWdoSh"
        ],
        "commitamt": 196.73782146
      }
    },
    {
      "value": 0,
      "n": 2,
      "version": 0,
      "scriptPubKey": {
        "asm": "OP_SSTXCHANGE OP_DUP OP_HASH160 0000000000000000000000000000000000000000 OP_EQUALVERIFY OP_CHECKSIG",
        "hex": "bd76a914000000000000000000000000000000000000000088ac",
        "version": 0,
        "reqSigs": 1,
        "type": "sstxchange",
        "addresses": [
          "DsQxuVRvS4eaJ42dhQEsCXauMWjvopWgrVg"
        ]
      }
    }
  ]

@chappjc chappjc merged commit 365c9dc into decred:master Dec 16, 2021
@chappjc chappjc deleted the txscriptv4 branch December 16, 2021 15:23
@chappjc chappjc added this to the 6.1 milestone Nov 2, 2022
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.

None yet

2 participants