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

BIP22: getblocktemplate #936

Merged
merged 2 commits into from Aug 13, 2012
Merged

BIP22: getblocktemplate #936

merged 2 commits into from Aug 13, 2012

Conversation

luke-jr
Copy link
Member

@luke-jr luke-jr commented Mar 13, 2012

Replacement for getmemorypool compatible with new BIP 22 specification.

@gavinandresen
Copy link
Contributor

What does @forrestv think?

@forrestv
Copy link
Contributor

I don't see any reason to separate submitblock, further cluttering the RPC interface, if the old way will continue to be supported. Other than that, looks good!

@luke-jr
Copy link
Member Author

luke-jr commented Mar 14, 2012

I only kept the old way in there for backward compatibility. There's really no reason to use the same method for two different functions - it's like sending coins using getbalance. More importantly, "getmemorypool(<data>)" doesn't provide any way to communicate the reason for rejections. During BIP discussion, some developers expressed interest in keeping the JSON-RPC protocol HTTP-independent, and abusing HTTP headers like getwork does violates this.

There is also a need for passing "features supported" from clients to getmemorypool() so that clients can opt to not implement "noncerange" and inform the server on their support (or lack thereof) of other features (so it might possibly optimize its own processes based on that). So far, nobody has come up with a backward-compatible way to do this; perhaps it would be desirable to ignore non-string , so that a future draft can turn it into an options Object?

@forrestv
Copy link
Contributor

Ah, I see. ACK then.

@gavinandresen
Copy link
Contributor

Too late in the 0.6 release cycle for a new RPC call. I think we should pull this early in the 0.7 release cycle so it gets lots of testing.

@sipa
Copy link
Member

sipa commented Apr 4, 2012

I disagree with the term bugfix here, but ACK on the changes.

@jgarzik
Copy link
Contributor

jgarzik commented Apr 10, 2012

ACK (and agree w/ sipa on term)

@luke-jr
Copy link
Member Author

luke-jr commented May 13, 2012

Rewrote based on recent BIP 22 revisions, including longpolling support.

@luke-jr
Copy link
Member Author

luke-jr commented May 18, 2012

Moved longpolling to #1355

@forrestv
Copy link
Contributor

ACK, now.

@luke-jr
Copy link
Member Author

luke-jr commented May 19, 2012

Eligius has been running this from block 179513 (56 blocks found) and EclipseMC from 180573 (11 blocks), totalling 67 valid blocks with no problems found.

@luke-jr
Copy link
Member Author

luke-jr commented Jun 1, 2012

Rebased, plus the changes to BIP 22 discussed on IRC (getmemorypool now requires exactly one argument, the parameters Object, but tolerates the old calling methods for compatibility)

Also stripped whitespace when parsing JSON Object in bitcoind-CLI-test-tool (while it could just convert input to Object regardless, it seemed sensible to keep the CLI working with older servers).

@sipa
Copy link
Member

sipa commented Jun 11, 2012

I've been trying to send a mail to the mailing list about BIP22, but it doesn't seem to come through.

As it's a bit too long to paste here, you can read it on https://gist.github.com/2909725.

@jgarzik
Copy link
Contributor

jgarzik commented Jun 11, 2012

@sipa can you pipe that through "fmt -72" or similar? Even 'raw' requires a horizontal scroll bar, which is unreadable in these modern times...

@sipa
Copy link
Member

sipa commented Jun 11, 2012

@jgarzik done

@luke-jr
Copy link
Member Author

luke-jr commented Jun 11, 2012

@sipa Hope this addresses everything:

  1. Servers are not required to have access to the transaction database, and miners may wish to include transactions that have not been relayed on the main network.
  2. The "submit/hash" mutation allows miners to replace actual transaction data with a reference, for servers which support this. The pull-request here does not support this functionality, since it is unlikely to be needed in bitcoind (solo miners and downstream pool servers are probably always going to be local and without bandwidth concerns); there are also mutations which servers can opt to use to allow miners to omit the transaction list entirely when it hasn't been modified, effectively reducing the bandwidth requirements to the same as getwork
  3. Your suggestion for a list of required coinbase outputs would involve specifying a format for that list, and actually increases the complexity since the same thing is expressed by what is effectively a boolean right now. I see the benefit of doing it that way, to allow miners to claim fees of transactions they add themselves - but what if a pool doesn't want to allow that?
  4. With restricted coinbase input, it is possible for servers to implement BIP 22 in the same way as they currently use getwork, but allowing miners to still audit the block they are working on.
  5. Clients are not required to support noncerange limiting, so the added complexity is itself optional
  6. "time/*" can usually in practice be ignored, since it is implied if the min/max are provided; it is listed so it is clear the time can be changed, and so servers might have a defined way to express "change the time to anything you want" - it's specified explicitly by bitcoind since there is no practical upper limit to the time miners can send it.
  7. The use case for adding transactions is... so miners can add other transactions. Kinda half the point of decentralized mining IMO. :p
  8. I don't mind removing "transactions/remove", but I'd rather just note it as being always implied to express that it can be done explicitly
  9. "prevblock" mutation is for the scenario where the miner has validated a new block before the server
  10. the "required" key on transaction objects is necessary for the flexibility of pools negotiating contracts for transaction acceptance, but "txrequired" allows saving a lot of bandwidth; I agree the mutation should be implicit given these two other methods
  11. "mintime" and "maxtime" are needed in addition to their "*off" versions, for servers such as bitcoind which only care about the network rules; in this case, "mintime" is a fixed time, not related to the current time at all.
  12. "target" is needed to allow shares of varying sizes; pools do make use of this
  13. "workid" is needed to allow the server to identify which work issued the block is being submitted against, so it can properly validate the share
  14. Transaction objects must include sigop count, as there is no way for dumb miners to calculate it thanks to BIP16

@gavinandresen
Copy link
Contributor

@luke-jr you didn't respond to the big-picture design question about whether you agree that BIP22 is over-complicated.

I agree with @sipa, I think there are way too many optional features, different ways of doing things, etc.

@luke-jr
Copy link
Member Author

luke-jr commented Jun 11, 2012

@gavinandresen "Overcomplicated" is relative based on what it needs to do. I think for the most part (there are exceptions, which I hope to simplify based on sipa's suggestions) BIP22 as it is can't get too much simpler with its given requirements.

@gavinandresen
Copy link
Contributor

I guess @sipa and I think maybe you're throwing in too many requirements. I say start simple, and if there is demand for a feature add it later. I'm OK with planning ahead with a design that allows stuff like adding/removing transactions, but that's a feature I've never heard "dumb miners" say they want.

Also: being explicit about the requirements in the BIP might help. I see only a very vague description of them in the 'motivation' section.

@luke-jr
Copy link
Member Author

luke-jr commented Jun 11, 2012

Optional things means fewer requirements, not many. "Dumb miners" don't care about any of this, they're fine using getwork with centralized pools. BIP22 is aimed at "smart miners" which want to (at least) audit the blocks they're working on to keep Bitcoin secure against potential poolop attacks. One practical superiority of decentralized mining is that miners are restored the freedom to choose their own minimum fee policies - that requires being able to pick and choose transactions that go into their blocks. At the same time, pools negotiating bulk fees has been an accepted "plan" for a while, and BIP22 can support that also.

I will try to expand on the Motivation section.

@luke-jr
Copy link
Member Author

luke-jr commented Jun 11, 2012

Updated BIP22 based on @sipa and @gavinandresen 's suggestions.

Unless there are problems with the subset of BIP22 supported by bitcoind (in this pull request), however, let's move BIP22 discussion back to the mailing list. I don't think it makes sense to hold up this pullrequest due to unrelated concerns.

transactions.push_back(HexStr(ssTx.begin(), ssTx.end()));
uint256 hashTarget = CBigNum().SetCompact(pblock->nBits).getuint256();

static Array*paMutable = NULL;
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is this being cached? If it really needs to be cached, then I'd suggest static Array mutable; if mutable.size == 0 ... then initialize.... to avoid memory-leak-checking tools complaining about leaking paMutable at shutdown.

Copy link
Member Author

Choose a reason for hiding this comment

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

Why make it slower by not caching it? Adding the static Array idea to rebase.

Copy link
Member

Choose a reason for hiding this comment

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

I doubt caching it helps a lot, as the values need to be copied into the output Object anyway. Doing that directly is probably just as slow as copying it from a cached value. That said, I doubt it's the only place where we use allocated objects in static variables, so I don't really care.

@luke-jr
Copy link
Member Author

luke-jr commented Jun 12, 2012

Rebased addressing Gavin's most recent comments.

@sipa
Copy link
Member

sipa commented Jun 13, 2012

One thing that still bothers me in the implementation is that is supports different decompositions for transactions. I understand the fee/sigops/dependencies/size meta-data is necessary, but do we really need to retain the origin (hex) encoding as well? Sure, dumb miners don't need this, but the protocol is aimed at non-dumb miners.

@luke-jr
Copy link
Member Author

luke-jr commented Jun 13, 2012

Smart miners don't necessarily have a transaction database available either. In fact, I'm not aware of a single getmemorypool client that has easy access to one right now.

@luke-jr
Copy link
Member Author

luke-jr commented Jun 13, 2012

Also, support for fetching transaction list as hashes exists for non-mining tools (I find it handy via the CLI as a human, to see what transactions are in the mempool). Support for fetching them as hex only is mainly a backward compatibility thing.

@sipa
Copy link
Member

sipa commented Jun 14, 2012

@luke-jr What I was talking about in my latest comment here, is the availability of {"tx" : "hex"}, as {"tx" : "obj"} provides a strict superset of that. It would indeed mean breaking backward compatibility, indeed.

@luke-jr
Copy link
Member Author

luke-jr commented Jun 28, 2012

So... seems nobody has anything else that needs addressing - time to merge?

@jgarzik
Copy link
Contributor

jgarzik commented Aug 1, 2012

Conditional NAK[1]: pick one of DM_OBJ or DM_HEX, not both.

ACK, if one of those is removed.

[1] Red Hat's "conditional NAK" means that if the described condition disappears, then the NAK disappears.

@jgarzik
Copy link
Contributor

jgarzik commented Aug 2, 2012

Looks good to a quick review. I'll have to apply the patch and read to be thorough.

Please edit the OP to indicate name change and consensus "why?" opinion.

@luke-jr
Copy link
Member Author

luke-jr commented Aug 2, 2012

Will do as soon as we have a final on the new name. I emailed @gavinandresen so hopefully he'll provide input next time he's got email access.

@gavinandresen
Copy link
Contributor

Encore on the name.

Gavin Andresen

On Aug 2, 2012, at 11:02 AM, Luke-Jrreply@reply.github.com wrote:

Will do as soon as we have a final on the new name. I emailed @gavinandresen so hopefully he'll provide input next time he's got email access.


Reply to this email directly or view it on GitHub:
#936 (comment)

@jgarzik
Copy link
Contributor

jgarzik commented Aug 2, 2012

The following review comes from reading the code directly, and may or may not reflect a change you made. Regardless, it is something that warranted a note.

  1. is mode=foo the preferred form? if yes, update help text to reflect this.

  2. help text is missing description of 'time'

  3. like 'getwork' this should prevent any progress if !connected || IBD. presently, it only does that check for template mode.

  4. if strmode==submit should be "else if"

  5. would prefer optional BIP 22 sections moved to another BIP

  6. BIP 22 fails to document everything getblocktemplate handles, such as e.g. mutable. Other keys are listed in BIP 22 as required, but your patch does not provide them, like coinbasetxn. Review and sync up code and BIP.

@jgarzik
Copy link
Contributor

jgarzik commented Aug 2, 2012

  1. Submit mode should mimic getwork, and return true if the block is accepted, or false if not.

- Replaces getmemorypool with new getblocktemplate
- Add missing keys: coinbaseaux, target, mutable, noncerange, sigoplimit, sizelimit, and height
- Accept and send parameter Objects, checking "mode" key if present
- Return rejection reason "rejected" for submit mode
Conflicts:
	src/bitcoinrpc.cpp
@luke-jr
Copy link
Member Author

luke-jr commented Aug 3, 2012

  1. Neither form is necessarily preferred; what is important is that the code doesn't take a path if it's set to something unexpected.

  2. 'time' was for backward compatibility: removed

  3. Why should submissions be prevented if not connected? Right now, it's possible this node has no network connections, but is getting its blocks (only) from a JSON-RPC source (perhaps HAM radio?)

  4. Changed.

5,6) The pooled mining sections are moved to BIP 23. coinbasetxn is not required, since coinbasevalue is provided, and it's not very trivial to add (it would break the template caching).

  1. Accepted design flaws in getwork are not reasonable to propagate into new protocols. (Please review past getwork and BIP22 discussions, and keep in mind bitcoind is not the only or even primary focus of this protocol)

@sipa
Copy link
Member

sipa commented Aug 13, 2012

ACK

gmaxwell added a commit that referenced this pull request Aug 13, 2012
@gmaxwell gmaxwell merged commit 14486dc into bitcoin:master Aug 13, 2012
suprnurd pushed a commit to chaincoin-legacy/chaincoin that referenced this pull request Dec 5, 2017
…atch PROTOCOL_VERSION

411ad29 Bump NO_BLOOM_VERSION and SENDHEADERS_VERSION to match PROTOCOL_VERSION
maflcko pushed a commit that referenced this pull request Jul 22, 2018
…er been used.

ac8a1d0 [RPC] Remove field in getblocktemplate help that has never been used (Conor Scott)

Pull request description:

  [BIP 22 - getblocktemplate](https://github.com/bitcoin/bips/blob/master/bip-0022.mediawiki#Transactions%20Object%20Format) specifies an optional flag, `required` if the transaction must be in the block.

  Luke's implementation #936 did not include this flag, and it was later added to the help description in #3246 (more than a year later) but the field was still never actually implemented. As far as I can tell, bitcoin core would have never actually included this in a `getblocktemplate` call, so it seems logical to remove it from the help description.

  If I am missing something or this is considered harmless - I can close the PR.

Tree-SHA512: f25dda51cc4e1512aff69309be04e3053bdccc1cf03c8d58e8866aa1fdf9d86cc57df872e85528351fc8a8d6d64a8f46a36c513680834762d854f368fbeb0f44
lateminer pushed a commit to lateminer/bitcoin that referenced this pull request Oct 30, 2019
…r Signature

6cf4922 [Bug][Wallet] Guard chainActive access in GetMintMaturityHeight (random-zebra)
95c1532 [Build] Fix CMake linking order (random-zebra)
46f1e53 [Build] Add CoinRandomnessSchnorrSignature to CMakeLists.txt (random-zebra)
183bce4 [zPIV] Add schnorr pk to challenge hash (random-zebra)
0178bbc [Tests] Additional cases for zc public spends v4 (random-zebra)
64efc69 [Tests] Add v4 Spends to zerocoin_valid_public_spend functional test (random-zebra)
3398090 [Refactor] add BN_THREE hardcoded constant for CBigNum(3) (random-zebra)
95952f1 [Cleanup] Fix non UTF-8 chars in ParamGeneration comments (random-zebra)
6288bb7 [Tests] PublicCoinSpend v4 / CRSchnorrSig unit tests (random-zebra)
7b81e54 [zPIV] Remove v2 serials from serialized v4 PublicCoinSpend (random-zebra)
a9b8aa0 [Consensus] PublicCoinSpend v4 enforcement (random-zebra)
ecd9bcd [zPIV] PublicCoinSpend v4 definition (random-zebra)
0f1f881 [zPIV] CoinSpend: define getCoinVersion() (random-zebra)
5a2ab57 [Consensus] set placeholder for nPublicZCSpendsV4 (random-zebra)
e346308 [zPIV] CoinRandomnessSchnorrSignature class definition (random-zebra)
5f9de6d [Refactor] Use hardcoded constants for CBigNum 0, 1, 2 (random-zebra)

Pull request description:

  This PR proposes (as hard fork) a new PublicCoinSpend protocol suitable to be used also with zerocoins version 1. Closes PIVX-Project#937

  Motivation and overview in the following document:
  https://github.com/random-zebra/PIVX-Wiki/blob/master/Developer-Documentation/Specs/zPIV/CoinRandomnessSchnorrSignature.mediawiki

  Enforcement height uses placeholder values (one million blocks after the activation of spends v3 for main net and testnet, and 100 blocks for regnet).

  Changes
  - replaces many instances of `CBigNum(0)`, `CBigNum(1)`, `CBigNum(2)` throughout the code with fixed constants defined in bignum.h.

  - defines the `CoinRandomnessSchnorrSignature` using the algorithm described in the [wiki](https://github.com/random-zebra/PIVX-Wiki/blob/master/Developer-Documentation/Specs/zPIV/CoinRandomnessSchnorrSignature.mediawiki).

  - defines the temporary activation height and also defines an helper function `Zerocoin_PublicSpendVersion` which returns the version active at a given block height.

  - defines a convenient method to retrieve the coin version from a `PublicCoinSpend` class (now that coin version and spend version are different).

  - defines `PublicCoinSpend` behaviour for v4.

  - enforces the PublicCoinSpend version in `ContextualCheckZerocoinSpendNoSerialCheck`.

  - provides unit tests for the new v4 `PublicCoinSpend` class.

ACKs for top commit:
  furszy:
    We can merge this already, ACK 6cf4922 .
  Mrs-X:
    utACK PIVX-Project@6cf4922 (unfortunately cannot really test it)

Tree-SHA512: 56a4e796323862453e593035d2ee9c1148e67db85bd90af015916c5e2be71e586aad289ebcfa63dc076bd4a6be9a5430ae01b5d42c8f9df7027bfee908dfdb99
lateminer pushed a commit to lateminer/bitcoin that referenced this pull request Oct 30, 2019
e06f7b6 [Tests] Minor optimizations in zerocoin_valid_public_spend test (random-zebra)
cdc18ea [RPC] fix parameters check for spendzerocoin (missing ispublicspend) (random-zebra)
72bc39a [Tests] Add zerocoin_valid_public_spend to testRunner (random-zebra)
26045d3 [Consensus] Set zc PublicSpend version v3/v4 via SPORK (random-zebra)

Pull request description:

  This follows bitcoin#936
  It sets the required version for zerocoin PublicSpends via SPORK instead of having it height-based.

  When `SPORK_18_ZEROCOIN_PUBLICSPEND_V4` is not active (default), the required version is v3 (where old version 1 serials cannot be spent. ref: bitcoin#891 ).

  It also fixes the relative functional test `zerocoin_valid_public_spend.py` and adds it to the test_runner.

ACKs for top commit:
  furszy:
    utACK e06f7b6
  Warrows:
    utACK e06f7b6

Tree-SHA512: 07f18e77a91503f5d48dafad32364cc6292ffd1f9a3f9286a78de72dafc98b07342e6abd96eaabe55d20193f10be383c8d5bbac1b33c45712ade8c522e457b3f
@bitcoin bitcoin locked and limited conversation to collaborators May 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants