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

2WP: Allow other elements chains as parent chains for pegs #362

Merged
merged 3 commits into from
Sep 6, 2018

Conversation

jtimon
Copy link
Contributor

@jtimon jtimon commented May 25, 2018

Fix #360 (doesn't really fix it as noted in #362 (comment) , but it is still useful for testing)

Dependencies:

@jtimon
Copy link
Contributor Author

jtimon commented Jun 4, 2018

Rebased after #363 was merged, which was a requirement for this (or some other way to do the same).
Also fixed a couple of bugs and greatly improved the testing. The new test is mostly a copy of pegging.py but adapted for the test framework and with some parts commented that are not properly adapted yet.
Ideally in the future we can get rid of pegging.py by offering an option to force a pow chain as parent chain by providing a path to a binary like we do in pegging.py.

@jtimon jtimon changed the title WIP: 2WP: Allow signed blocks chains as parent chains for pegs 2WP: Allow signed blocks chains as parent chains for pegs Jun 5, 2018
@jtimon
Copy link
Contributor Author

jtimon commented Jun 5, 2018

Removed the 'WIP' because now it seems to pass most of the tests.
This doesn't need to replace pegging.py, review and testing should focus on making sure the pervious default behavior is not broken in any way.

@instagibbs
Copy link
Collaborator

Will review

src/init.cpp Outdated
@@ -516,7 +516,7 @@ std::string HelpMessage(HelpMessageMode mode)
strUsage += HelpMessageOpt("-initialfreecoins", strprintf(_("The amount of OP_TRUE coins created in the genesis block. Primarily for testing. (default: %d)"), 0));
strUsage += HelpMessageOpt("-parentpubkeyprefix", strprintf(_("The byte prefix, in decimal, of the parent chain's base58 pubkey address. (default: %d)"), 111));
strUsage += HelpMessageOpt("-parentscriptprefix", strprintf(_("The byte prefix, in decimal, of the parent chain's base58 script address. (default: %d)"), 196));

strUsage += HelpMessageOpt("-con_parent_chain_has_pow", "Whether parent chain uses pow or signed blocks default: 1");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put default in parenthesis

}

template<typename T>
static bool CheckPegoutTx(const std::vector<unsigned char>& tx_data, T& pegtx, const COutPoint& prevout, const CAmount claim_amount, const CScript& claim_script)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CheckPeginTx?

}
if (merkle_block.txn.ExtractMatches(txHashes, txIndices) != merkle_block.header.hashMerkleRoot || txHashes.size() != 1) {
// TODO do this inside to prever DoS ?
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prevent?

@instagibbs
Copy link
Collaborator

concept ACK. Going to have to carefully comb over these changes.

@instagibbs
Copy link
Collaborator

Could we split up these changes into basic refactors, then consensus changes?

@jtimon jtimon force-pushed the e14-parent-sigchain branch 2 times, most recently from 2e077cc to 2f0f2fc Compare June 12, 2018 21:17
@jtimon jtimon force-pushed the e14-parent-sigchain branch 10 times, most recently from 50338cc to 6de5683 Compare June 14, 2018 17:18
@jtimon
Copy link
Contributor Author

jtimon commented Jun 14, 2018

Uncommented more tests.

@jtimon jtimon force-pushed the e14-parent-sigchain branch 3 times, most recently from 5cae62a to 3f10c98 Compare July 22, 2018 06:29
proof = parent.gettxoutproof([txid1])

raw = parent.getrawtransaction(txid1)
import json
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a strange place to import json..

print(e.error["message"])
assert("Given or recovered script is not a witness program." in e.error["message"])

# # Should fail due to non-matching wallet address
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this here because it should fail due to this if it would not fail due to non-witness (clause above)?

This is very good for clarity, but it doesn't really test if it would fail in that case..

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's simply the same test as in https://github.com/ElementsProject/elements/blob/elements-0.14.1/qa/rpc-tests/pegging.py#L233 but commented because I didn't manage to make it work, note here there's a similar one above "Should fail due to non-witness", perhaps that's enough.
Perhaps I should just remove that commented code, but then I will forget about it.
@instagibbs thoughts?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

was this functionality supposed to be working?

@instagibbs
Copy link
Collaborator

How much extra work is it to do this properly and check for the correct asset id? Shouldn't it just be a single check?

@jtimon jtimon force-pushed the e14-parent-sigchain branch 2 times, most recently from dbcc884 to 502357a Compare August 10, 2018 04:16
@jtimon
Copy link
Contributor Author

jtimon commented Aug 10, 2018

Fixed import nit, rebased (was clean).

@instagibbs Added a wip commit doing the check, but the tests fail, unless I'm misunderstanding something, because the asset id in the pegin tx from the parent chain is not explicit but confidential.
If there's an easy way to "always do explicit assets by default" or something similar, I guess this could work.

@instagibbs
Copy link
Collaborator

The output shouldn't be confidential though? The mainchain_address is unconfidential, yes?

@jtimon jtimon force-pushed the e14-parent-sigchain branch 2 times, most recently from 58b09f9 to abc8305 Compare August 10, 2018 21:44
@jtimon
Copy link
Contributor Author

jtimon commented Aug 10, 2018

Right, sorry, it was just a bug that confused me. It seems to work now. Let me know if you prefer me to squash, rename the commit or something else. I would squash, I think.

@jtimon jtimon changed the title 2WP: Allow other elements chains as parent chains for pegs (for testing only) 2WP: Allow other elements chains as parent chains for pegs Aug 10, 2018
@@ -61,6 +61,8 @@ def setup_network(self, split=False):
connect_nodes_bi(self.nodes, 0, 1)
self.parentgenesisblockhash = self.nodes[0].getblockhash(0)
print('parentgenesisblockhash', self.parentgenesisblockhash)
parent_pegged_asset = self.nodes[0].getsidechaininfo()['pegged_asset']
print('parent_pegged_asset', parent_pegged_asset)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

errant print?

This allows other elements chains as parent chains for pegs, for testing purposes

for now it also assumes that the parent chain has CT/CA tx format,
which is orthogonal to the parent chain having pow or signed blocks

It would be nice to also test bitcoin-like chains with signed blocks
instead of pow by adding another parameter -con_parent_chain_has_CT or
similar and decouple the logic

Introduce -con_parent_pegged_asset option to check the asset in the
peg-in txs from the parent chains.

CT: Introduce GetAmountFromParentChainPegin for CT txs
RPC: Adapt rpcwallet to initial -con_parent_chain_has_pow
Introduce CheckProofGeneric
Introduce pow::CheckProofParent
try {
ssTxOutProof >> merkleBlock;
}
catch (...) {
throw JSONRPCError(RPC_TYPE_ERROR, "The included txoutproof is malformed. Are you sure that is the whole string?");
}

if (!ssTxOutProof.empty() || !CheckBitcoinProof(merkleBlock.header.GetHash(), merkleBlock.header.nBits))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we dropping this check?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@instagibbs
Copy link
Collaborator

utACK 3f62b32 other than single question

jtimon referenced this pull request in kallewoof/bitcoin Sep 6, 2018
@jtimon jtimon merged commit 3f62b32 into ElementsProject:elements-0.14.1 Sep 6, 2018
jtimon added a commit to jtimon/elements that referenced this pull request Sep 6, 2018
… chains for pegs

3f62b32 QA: Test 2wp using the test framework (Jorge Timón)
2de5765 2WP: QA: Introduce -con_parent_chain_signblockscript (Jorge Timón)
781953b QA: Optionally allow other chains (Jorge Timón)
@jtimon jtimon deleted the e14-parent-sigchain branch September 6, 2018 22:18
jamesdorfman pushed a commit to jamesdorfman/elements that referenced this pull request Apr 11, 2023
7c33e3a qt: Add missing mnemonics in menu bar options (Shashwat)

Pull request description:

  Since ElementsProject#362 we have defaulted to add mnemonic shortcuts for the context menus.
  The Window -> Minimize option and File -> Load PSBT from clipboard were hitherto missing a mnemonic shortcut. This PR adds mnemonic shortcuts for them

  Changes introduced in this PR:
  | Master | PR |
  | ----------| ---- |
  | ![Screenshot from 2021-08-23 23-10-07](https://user-images.githubusercontent.com/85434418/130494098-c65ec9da-c3f1-4243-9b3d-0c87cb677825.png) | ![Screenshot from 2021-08-23 23-08-41](https://user-images.githubusercontent.com/85434418/130494083-849ffd14-05e9-4a6d-bdc3-b3e55b8a8861.png)|
  |![Screenshot from 2021-08-23 23-10-21](https://user-images.githubusercontent.com/85434418/130494233-1b2e8838-c5d4-48a8-9abf-a4acc8d6146c.png)|![Screenshot from 2021-08-23 23-09-00](https://user-images.githubusercontent.com/85434418/130494181-dcdbf119-a2c6-469d-a6c9-3021506ab40b.png)|

ACKs for top commit:
  jarolrod:
    tACK 7c33e3a
  hebasto:
    ACK 7c33e3a, tested on Linux Mint 20.2 (Qt 5.12.8).

Tree-SHA512: 32f201ae7716b19ca123856292f8bfa0d805f6c7271ac1b5e08eff6b95017443754c8a76e8396ccca1869a57384e11016cbd99d63ccdd2fae6da4eaf3ae32298
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

4 participants