-
Notifications
You must be signed in to change notification settings - Fork 107
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
[email protected] tx.id() not equal to rpc getblock(blockhash, 1) tx id #176
Comments
I've been able to recreate this too. I used the tools included in the repo and files instead of an rpc connection: it('parse a hex block generate the right txids', async () => {
// const height = 147056
// const blockHash = '00000000000007a678f2e1316e0f7f7acf2b967d998558aed8dadcd4430fd5f1'
const blockHex = await new Promise(resolve => {
fs.readFile('test/block.txt', 'utf-8', (err, data) => {
if (err) {
throw err
}
resolve(data)
})
})
const blockDataFromRpc = await new Promise(resolve => {
fs.readFile('test/block.json', 'utf-8', (err, data) => {
if (err) {
throw err
}
resolve(JSON.parse(data))
})
})
const blockFromLibrary = Block.fromBuffer(Buffer.from(blockHex, 'hex'))
const firstTxIdFromRpc = blockDataFromRpc.tx[0]
const firstTxIdFromLibrary = blockFromLibrary.txs[0].id()
const otherTxidsFromParsedBlock = blockFromLibrary.txs.map(tx => tx.id()).slice(1)
const otherTxIdsFromRawBlock = blockDataFromRpc.tx.slice(1)
should(otherTxidsFromParsedBlock).be.eql(otherTxIdsFromRawBlock)
should(firstTxIdFromRpc).be.eql(firstTxIdFromLibrary)
}) It fails exactly as in the report. |
The issue happens parsing this script: The first thing that I notice is that there is a weird behavior when I tried to encode it using different languages: const weirdScript = bsv.Script.fromHex('fc70035c7a81bc6fcc36947f7c1b2d63620560bec2aa336a676213bab74c9f03d46788100dca84c0f19a0f1c14ef0d67f3fc63c011ba4787510d55fde9554e554e')
weirdScript.toString()
// => '0xfc OP_2OVER 3 0x5c7a81 0xbc OP_3DUP 0xcc 54 0x947f7c1b2d63620560bec2aa336a676213bab74c9f03d46788100dca84c0f19a0f1c14ef0d67f3fc63c011ba4787510d55fde9554e55 OP_PUSHDATA4 0 0x'
weirdScript.toAsmString()
// => 'fc OP_2OVER 5c7a81 bc OP_3DUP cc 947f7c1b2d63620560bec2aa336a676213bab74c9f03d46788100dca84c0f19a0f1c14ef0d67f3fc63c011ba4787510d55fde9554e55' the asm version doesn't include the last push data. And the last push data is causing the issue. |
Bsv legacy fails when trying to parse that as a script: bsv.Script.fromHex('fc70035c7a81bc6fcc36947f7c1b2d63620560bec2aa336a676213bab74c9f03d46788100dca84c0f19a0f1c14ef0d67f3fc63c011ba4787510d55fde9554e554e')
Invalid script buffer: can't parse valid script from given buffer fc70035c7a81bc6fcc36947f7c1b2d63620560bec2aa336a676213bab74c9f03d46788100dca84c0f19a0f1c14ef0d67f3fc63c011ba4787510d55fde9554e554e
Uncaught Error
at new NodeError (/home/migue/Projects/yours/money-button/node_modules/bsv/lib/errors/index.js:20:41)
at Function.Script.fromBuffer (/home/migue/Projects/yours/money-button/node_modules/bsv/lib/script/script.js:100:15)
at new Script (/home/migue/Projects/yours/money-button/node_modules/bsv/lib/script/script.js:33:19)
at Function.Script.fromHex (/home/migue/Projects/yours/money-button/node_modules/bsv/lib/script/script.js:192:10)
at repl:1:8
at Script.runInThisContext (vm.js:120:20)
at REPLServer.defaultEval (repl.js:431:29)
at bound (domain.js:426:14)
at REPLServer.runBound [as eval] (domain.js:439:12)
at REPLServer.onLine (repl.js:759:10) |
@hojarasca thanks for the response. Looking forward the fix. This issue really block my progress. Thanks again. |
any progress? |
@ryanxcharles can you help to check? Thanks! |
@hojarasca Your comment is correct. The root cause is the script parse process. |
Workaround is here : 86chenjie@fe41812 |
This has been open for ever. I'm going to make time to fix this next week. |
test code:
The two tx ids should be equal. Obviously block_tx0_id is not correct.
The text was updated successfully, but these errors were encountered: