-
Notifications
You must be signed in to change notification settings - Fork 172
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
Segwit Compatibility #47
Conversation
235994b
to
01a9fdb
Compare
I did not write unit tests for this since I don't know how. I can however provide segwit transactions and blocks for unit tests if you need them. To test to see if this works by hand, you will need to have Bitcoin Core 0.13+ (Either use an rc release or build from the repo). Then start both Bitcoin Core and Armory in regtest mode. In Bitcoin Core, go to the console and generate 432 blocks. That should activate segwit (check by using getblockchaininfo). Then you can test all of the different sending scenarios. Witness addresses can be made using addwitnessaddress in Bitcoin Core. |
a3b0df7
to
48aefc2
Compare
return TXOUT_SCRIPT_NONSTANDARD; | ||
else if (sz == 21 && | ||
s[0] == 0x00) | ||
return TXOUT_SCRIPT_P2WPKH; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs to check the size of the rest of the script data. Check for 0x14 byte
4c69bbd
to
6029b45
Compare
witLen += viStackLen; | ||
for(uint32_t i=0; i<stackLen; i++) | ||
{ | ||
uint32_t viLen; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should check there's at least 1 byte left to grab a varint here (per iteration)
6029b45
to
2b2eca1
Compare
lockTime_ = READ_UINT32_LE(ptr + offsetsTxOut_[numTxOut]); | ||
uint32_t numTxOut = offsetsTxOut_.size() - 1; | ||
version_ = READ_UINT32_LE(ptr); | ||
if (4 > size - offsetsTxOut_[numTxOut]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this check doesn't work anymore, you need to check against the end of the witness data. this means you need to set offsetWitness_ in all cases (with or without witness data), and check
(4 > size - offsetsWitness_[numWitness])
where numWitness is
offsetWitness_.size() - 1;
This implies offsetWitness is set to offsetsTxOut[numTxOut] where there is no witness data.
2b2eca1
to
5edf9ec
Compare
if stackSize > 0: | ||
for i in range(0, stackSize, 1): | ||
stackItemSize = txWitnessData.get(VAR_INT) | ||
debugremsize = txWitnessData.getRemainingSize() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unused local variable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oops. that was for debugging
5edf9ec
to
4c5e05b
Compare
indstr2 = indstr + indent | ||
result = indstr + 'PyWitness:' | ||
result = ''.join([result, '\n', indstr2 + 'Stack Size:', \ | ||
str(self.binWitnesses[0])]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where is self.binWitnesses defined? I only see self.binWitness
4c5e05b
to
aaa2ba6
Compare
self.version = txData.get(UINT32) | ||
marker = txData.get(UINT8) | ||
flag = txData.get(UINT8) | ||
if marker == MARKER and flag == FLAG: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe rename these as WITNESS_MARKER and WITNESS_FLAG across the board, it will be confusing a year down the road when no one is thinking about segwit when reviewing code
dedb731
to
6f7987f
Compare
If I run ArmoryDB and ArmoryQt separately, I get a few errors on each network. On regtest, it segfaults due to a buffer overflow somewhere. On testnet, I get
But when I ran it again, it worked And on mainnet I get the same thing as testnet and a dialog saying something about the wrong magic bytes were detected. Running just ArmoryQt.py without the db already running gets the below for mainnet and regtest
There was also a dialog about invalid magic word. Testnet worked. |
6f7987f
to
8daaed3
Compare
Adds negotiation of witness usage through NODE_WITNESS service bit. Adds the new inv types in order to get witness serialization. Also bumps the protocol version and added additional network stuff for handling the new protocol version
Add recognization of the new input and output types used by segwit
Added transaction witness serialization stuff to PyTx.
Block file parsing with witnesses is completely fixed.
Added everything required to function on the Bitcoin Core Regtest network
Fixes the issues that having wrong transaction unserialization caused.
If a transaction is in witness serialization, the part of the transaction without the witness is properly extracted to be hashed.
Transaction hash is properly calculated before db stuff happens. Also fixed blank regtest explorer and did some MSG_INV_WITNESS stuff
Additional check for determining a segwit output. Checks that the second byte of the output is the correct size for witness v0 programs. Checks for remaining buffers when calculating witness length.
Rename MARKER and FLAG to WITNESS_MARKER and WITNESS_FLAG
Removed copies from BlockDataMap so that noWitData is only calculated if there is a witness.
Adds networking changes for segwit into cpp code.
8093d9c
to
ef06491
Compare
ef06491
to
a3c1af3
Compare
merged in a1a6a29 |
This PR should be everything that is needed in order to be compatible with segwit. This means that Armory will still be able to work with the changes to block and transaction formats. However it does not actually use segwit yet; that is the next step.
This PR also merges #22 for the regtest mode. This was done in order to test the segwit compatibility in an isolated environment where I could control everything.