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

add signet support #291

Open
wants to merge 3 commits into
base: master
from
Open

Conversation

@kallewoof
Copy link

kallewoof commented Jul 10, 2019

This PR adds the "signet" network type to the list of networks.

See also:

@stevenroose

This comment has been minimized.

Copy link
Collaborator

stevenroose commented Jul 10, 2019

FWIW, #255 removed our dependency on rust-bech32-bitcoin but is blocked on a bech32 PR, but that should land soon.

@stevenroose

This comment has been minimized.

Copy link
Collaborator

stevenroose commented Jul 10, 2019

Getting bitcoin_constants in would make this a lot nicer. It would also solve the problem I have with having to duplicate a lot of code for Elements and Liquid.

@kallewoof

This comment has been minimized.

Copy link
Author

kallewoof commented Jul 10, 2019

@stevenroose Yeah I noticed a lot of duplicate code all over the place. Wasn't sure what that was about but hopefully it can be reduced. :) I am gonna leave the bech32 PR for now, even if it is not going to relate to this repo specifically in the end.

@clarkmoody

This comment has been minimized.

Copy link
Member

clarkmoody commented Jul 10, 2019

Yeah #255 looks good and should allow us to narrow dependency scope for some projects. I believe we're closing in on rust-bitcoin/rest-bech32#35.

@kallewoof kallewoof force-pushed the kallewoof:2019-07-signet branch 2 times, most recently from 5be1545 to 973936a Jul 10, 2019
@kallewoof kallewoof changed the title [DONOTMERGE] add signet support add signet support Jul 10, 2019
@kallewoof kallewoof force-pushed the kallewoof:2019-07-signet branch 2 times, most recently from 19b0295 to ed1fb0a Jul 27, 2019
@codecov-io

This comment has been minimized.

Copy link

codecov-io commented Jul 30, 2019

Codecov Report

Merging #291 into master will decrease coverage by 0.89%.
The diff coverage is 76.47%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master     #291     +/-   ##
=========================================
- Coverage   85.98%   85.09%   -0.9%     
=========================================
  Files          40       40             
  Lines        8083     7405    -678     
=========================================
- Hits         6950     6301    -649     
+ Misses       1133     1104     -29
Impacted Files Coverage Δ
src/util/bip32.rs 87.14% <0%> (+0.22%) ⬆️
src/consensus/params.rs 0% <0%> (ø) ⬆️
src/util/key.rs 72.41% <0%> (-0.5%) ⬇️
src/util/address.rs 84.35% <10%> (-3.52%) ⬇️
src/network/constants.rs 85.61% <90%> (ø) ⬆️
src/blockdata/constants.rs 89.83% <97.67%> (+7.01%) ⬆️
src/util/psbt/mod.rs 86.06% <0%> (-3.71%) ⬇️
src/blockdata/script.rs 78.55% <0%> (-2.6%) ⬇️
src/util/base58.rs 80.68% <0%> (-1.48%) ⬇️
... and 23 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1b946b0...63e0dc4. Read the comment docs.

@dongcarl

This comment has been minimized.

Copy link
Member

dongcarl commented Aug 16, 2019

@kallewoof I'd be happy to review after rebase ☺️

@kallewoof kallewoof force-pushed the kallewoof:2019-07-signet branch from ed1fb0a to 6e6a02c Aug 17, 2019
@kallewoof

This comment has been minimized.

Copy link
Author

kallewoof commented Aug 17, 2019

@dongcarl I didn't realize it was in need of a rebase until you nudged, thanks. I think I've rebased it and it works, but my account is flagged at Travis right now so I don't think that CI will ever finish..

@kallewoof kallewoof force-pushed the kallewoof:2019-07-signet branch from 6e6a02c to a721117 Aug 19, 2019
Copy link
Member

dongcarl left a comment

I believe we only need to complete the TODO before this is usable?

merkle_root: txdata[0].txid(),
time: 1534313275,
bits: 0x1e2adc28,
nonce: 621297

This comment has been minimized.

Copy link
@dongcarl

dongcarl Aug 23, 2019

Member

Note to reviewers: you can verify the time, bits, and nonce parameters by checking:

https://github.com/kallewoof/bitcoin/blob/2b9db9ac0936cf278ad27c59497d9feec61f6440/src/chainparams.cpp#L512

and

https://github.com/kallewoof/bitcoin/blob/2b9db9ac0936cf278ad27c59497d9feec61f6440/src/chainparams.cpp#L270

We need to make sure that, before merging, there's some way of passing in the blockscript and creating the Coinbase signature like so:

https://github.com/kallewoof/bitcoin/blob/2b9db9ac0936cf278ad27c59497d9feec61f6440/src/chainparams.cpp#L505-L513

0x62a429192f9e8ce5u64,
0xc63b5f100aa5d8dfu64,
0x3c82faa55d83e40au64,
0x00002adc28cf53b6u64,

This comment has been minimized.

pow_target_spacing: 10 * 60, // 10 minutes.
pow_target_timespan: 14 * 24 * 60 * 60, // 2 weeks.
allow_min_difficulty_blocks: false,
no_pow_retargeting: false,

This comment has been minimized.

Copy link
@dongcarl

dongcarl Aug 23, 2019

Member

The above parameters can be verified here: https://github.com/kallewoof/bitcoin/blob/2b9db9ac0936cf278ad27c59497d9feec61f6440/src/chainparams.cpp#L295-L306

@kallewoof Any particular reason the BIP{34,65,66} heights differ from your Core implementation?

This comment has been minimized.

Copy link
@kallewoof

kallewoof Aug 24, 2019

Author

Mistake; changed here to match (425446c).

@@ -94,6 +97,7 @@ impl Network {
match *self {
Network::Bitcoin => 0xD9B4BEF9,
Network::Testnet => 0x0709110B,
Network::Signet => 0x6A70C7F0,
@@ -584,7 +584,7 @@ impl fmt::Display for ExtendedPrivKey {
let mut ret = [0; 78];
ret[0..4].copy_from_slice(&match self.network {
Network::Bitcoin => [0x04, 0x88, 0xAD, 0xE4],
Network::Testnet | Network::Regtest => [0x04, 0x35, 0x83, 0x94],
Network::Testnet | Network::Signet | Network::Regtest => [0x04, 0x35, 0x83, 0x94],

This comment has been minimized.

@@ -128,6 +128,7 @@ impl PrivateKey {
let mut ret = [0; 34];
ret[0] = match self.network {
Network::Bitcoin => 128,
Network::Signet => 217,
@@ -370,6 +370,7 @@ impl Display for Address {
let mut prefixed = [0; 21];
prefixed[0] = match self.network {
Network::Bitcoin => 0,
Network::Signet => 125,

This comment has been minimized.

@dongcarl

This comment has been minimized.

Copy link
Member

dongcarl commented Aug 23, 2019

Kicking Travis!

@dongcarl dongcarl closed this Aug 23, 2019
@dongcarl dongcarl reopened this Aug 23, 2019
@kallewoof kallewoof force-pushed the kallewoof:2019-07-signet branch from 425446c to 1c03850 Aug 26, 2019
@kallewoof kallewoof force-pushed the kallewoof:2019-07-signet branch 3 times, most recently from 43a5912 to 1c03850 Jan 23, 2020
@kallewoof kallewoof closed this Jan 23, 2020
@dr-orlovsky

This comment has been minimized.

Copy link
Contributor

dr-orlovsky commented Jan 23, 2020

Why is it closed?

@kallewoof

This comment has been minimized.

Copy link
Author

kallewoof commented Jan 24, 2020

@dr-orlovsky Nobody has looked at it for 5 months. Maybe after signet is merged into core it will have more interest.

@dr-orlovsky

This comment has been minimized.

Copy link
Contributor

dr-orlovsky commented Jan 24, 2020

Well, I do need it in rust-bitcoin... Probably I will integrate it into my develop branch directly at this stage.

@kallewoof

This comment has been minimized.

Copy link
Author

kallewoof commented Jan 24, 2020

I actually didn't realize I can't reopen PRs I close on my own, but in either case, I do intend to make a PR, and I will maintain this branch so feel free to use it! If you need help don't hesitate to ping me btw. I'd love to see what you're working on.

@dr-orlovsky

This comment has been minimized.

Copy link
Contributor

dr-orlovsky commented Jan 24, 2020

Thank you! Actually I think it should be possible to re-open PR, at least I've done this myself in the past. It's strange, maybe GitHub changed something since that time.

I'm working on LNP/BP standards and library — layer 2 & 3 solutions on top of Bitcoin and Lightning, including RGB (client-validated rich state management system, like for assets, collectibles, reputation etc), Spectrum (DEX over Lightning), Storm (trustless storage and messaging), Prometheus (trustless computing). You can see more on https://github.com/lnp-bp/. The first priority is RGB, which is sort of "Confidential Assets" in Liquid, but with no on-chain data and able to work on LN w/o its modifications and I need Signet to test it, since we are already at pre-release stage (and one of the first asset will be USDT).

@stevenroose

This comment has been minimized.

Copy link
Collaborator

stevenroose commented Jan 31, 2020

I'm also interested in revisiting this and getting it in. Please reopen PR :)

@kallewoof

This comment has been minimized.

Copy link
Author

kallewoof commented Feb 1, 2020

@stevenroose Would love to, but the "Reopen" button is grayed out for some reason :)

@apoelstra

This comment has been minimized.

Copy link
Member

apoelstra commented Feb 2, 2020

When I hover over the "Reopen" button it says the branch was "force-pushed or recreated". I think it won't let us reopen if the branch changed in the time that it was closed. Frustrating.

@kallewoof kallewoof mentioned this pull request Feb 3, 2020
@ryanofsky

This comment has been minimized.

Copy link

ryanofsky commented Feb 3, 2020

I think it won't let us reopen if the branch changed in the time that it was closed. Frustrating.

If you reset the branch to 1c03850, the tip at the time the PR was closed, github will let you reopen

@kallewoof kallewoof reopened this Feb 3, 2020
@kallewoof kallewoof force-pushed the kallewoof:2019-07-signet branch from 1c03850 to d198226 Feb 3, 2020
@kallewoof

This comment has been minimized.

Copy link
Author

kallewoof commented Feb 3, 2020

@ryanofsky Thanks!

@@ -128,6 +128,21 @@ pub fn genesis_block(network: Network) -> Block {
txdata: txdata
}
}
Network::Signet => {
// TODO: somehow obtain the block script and generate coinbase tx from it

This comment has been minimized.

Copy link
@stevenroose

stevenroose Feb 4, 2020

Collaborator

Does this mean it's currently incorrect?

This comment has been minimized.

Copy link
@kallewoof

kallewoof Feb 5, 2020

Author

No, it means the block hash is not derived automatically, but hard coded. There's a related discussion at bitcoin/bitcoin#16411 (comment) which suggests that we use a hard coded genesis block for all signet instances -- right now, signet derives the genesis block from the challenge (i.e. scriptPubKey of the blocks).

This comment has been minimized.

Copy link
@kallewoof

kallewoof Feb 5, 2020

Author

Actually, I take that back. I'm actually unsure about this one. Will have to verify this one.

This comment has been minimized.

Copy link
@kallewoof

kallewoof Feb 6, 2020

Author

I've pushed a to-squash commit that properly derives the signet genesis based on the block script. Note that bitcoin/bitcoin#16411 (comment) is still up in the air, but currently keeping things as is.

This comment has been minimized.

Copy link
@stevenroose

stevenroose Feb 7, 2020

Collaborator

So currently all signets will have the same genesis hash with the signet0 pubkey in it? Cool.

ACK if that's what Core is doing.

This comment has been minimized.

Copy link
@kallewoof

kallewoof Feb 8, 2020

Author

In practice, it is possible to specify a custom block script which would result in a different genesis hash, but recent discussion indicates we will usually have only one signet at a time, most of the time.

// TODO: somehow obtain the block script and generate coinbase tx from it
let txdata = vec![bitcoin_genesis_tx()];
let block_script = script::Builder::new().push_opcode(opcodes::all::OP_PUSHNUM_1)
.push_slice(&Vec::from_hex("03ad5e0edad18cb1f0fc0d28a3d4f1f3e445640337489abb10404f2d1e086be430").unwrap())

This comment has been minimized.

Copy link
@stevenroose

stevenroose Feb 7, 2020

Collaborator

So this is the default signet signer key?

This comment has been minimized.

Copy link
@kallewoof

kallewoof Feb 8, 2020

Author

Yes. It may change at some point, but this shouldn't be a common occurrence.

Block {
header: BlockHeader {
version: 1,
prev_blockhash: Default::default(),
merkle_root,
merkle_root: signet_merkle_root,

This comment has been minimized.

Copy link
@stevenroose

stevenroose Feb 7, 2020

Collaborator

I think this can be signet_txdata[0].txid().as_hash().into() so you can avoid the 2 lines of conversion above.

This comment has been minimized.

Copy link
@kallewoof

kallewoof Feb 8, 2020

Author

Sounds good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

8 participants
You can’t perform that action at this time.