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

Support for BIP 23 block proposal #1816

Merged
merged 9 commits into from
Nov 24, 2014
Merged

Conversation

luke-jr
Copy link
Member

@luke-jr luke-jr commented Sep 10, 2012

This would aide greatly in ensuring miners aren't messing up blocks, without the expense of losing 50 BTC.

@BitcoinPullTester
Copy link

Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/c077555c77dd1a58bedd6466a086c4f116fd0e57 for binaries and test log.

@gavinandresen
Copy link
Contributor

Nested-three-deep reject(DoS(error(...))) with two different error strings seems kinda crazy. If I wasn't familiar with the history of how that came to be I'd be befuddled.

Could it be simplified to just:
return reject(errorMessage, int nDoS=0) ?

... where reject prints errorMessage to debug.log and saves it in the block, and then does the DoS thing if nDoS > 0. Then returns false.

@luke-jr
Copy link
Member Author

luke-jr commented Sep 11, 2012

I'll flatten this later and collapse the 3 levels of function wrappers, just needed to get something working for Eligius...

@BitcoinPullTester
Copy link

Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/8f976aaa862c933c41c153007d0ffe3093ff475b for binaries and test log.

@@ -837,6 837,8 @@ class CBlock
// Denial-of-service detection:
mutable int nDoS;
bool DoS(int nDoSIn, bool fIn) const { nDoS = nDoSIn; return fIn; }
mutable std::string strRejectReason;
bool reject(const std::string& strRejectReasonIn, bool fIn) const { strRejectReason = strRejectReasonIn; return fIn; }
Copy link
Member

Choose a reason for hiding this comment

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

I really don't like CBlocks storing their own reject string, seems like a layer violation. Maybe not directly related to this change, as nDoS does the same.

I'd rather see a CValidationResult which stores such information, which is returned or pass-by-ref inside the block- and transaction validation functions. That's maybe out of scope for this change, though.

@luke-jr
Copy link
Member Author

luke-jr commented Nov 15, 2012

Rebased and implemented @sipa 's CValidationResult solution.

@BitcoinPullTester
Copy link

Automatic sanity-testing: FAILED MERGE, see http://jenkins.bluematt.me/pull-tester/212089d306d351e63111e91a969e9da1b1920cbc for test log.

This pull does not merge cleanly onto current master

@BitcoinPullTester
Copy link

Automatic sanity-testing: PASSED, see http://jenkins.bluematt.me/pull-tester/46888e6abca27dd6d2132aab7cd63f25363057c6 for binaries and test log.

indexDummy.pprev = pindexPrev;
indexDummy.nHeight = pindexPrev->nHeight 1;
CCoinsViewCache viewNew(*pcoinsTip, true);
return pblock->ConnectBlock(state, &indexDummy, viewNew, true);
Copy link
Member Author

Choose a reason for hiding this comment

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

This seems to have a race condition - or maybe just a bug when proposing based on a not-the-most-recent prevblock.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in current code (stale-prevblk check above)

@jgarzik
Copy link
Contributor

jgarzik commented May 30, 2013

No objections to the code. Driving use case?

@luke-jr
Copy link
Member Author

luke-jr commented May 30, 2013

Ability to test block templates before putting the effort into mining them.

@jgarzik
Copy link
Contributor

jgarzik commented May 30, 2013

That's a use case. What size user constituency is driving this? Do multiple pools want this?

@luke-jr
Copy link
Member Author

luke-jr commented May 30, 2013

As far as I know, only Eligius and EclipseMC are actively using this today. Any pool using Eloipool for their poolserver would be able to immediately take advantage of it in the simplest case. It is also necessary for both a multiple-validating-node-implementation economy, and miner-chooses-his-own-transactions GBT-based pool mining.

@sipa
Copy link
Member

sipa commented May 30, 2013

@jgarzik I don't think that's a requirement (though certainly something to take into consideration).

I like the idea of such functionality, as it allows miners to validate their work against multiple implementations. Especially with alternative full node implementations becoming available, having something like this may be inevitable. Plus it's a good debugging tool for checking whether new (unreleased) versions can accept the best chain.

On the other hand, I don't like the evolution that may follow from this, where miners become required to validate against a dozen implementations that may or may not differ in validation rules... that has nothing to do with this PR though.

@petertodd
Copy link
Contributor

@sipa A good example where the validation is extremely useful is a safety net for bitcoin changes that could potentially create invalid blocks. For instance in discussions with pools and miners something that comes up with implementing replace-by-fee and the child-pays-for-parent code I'm working on is the danger that there will be some kind of bug that leads to an invalid block. (let alone a delibrate exploit) Sure you can test all you want on testnet, but it's impossible to be 100% sure, and any orphan costs ~$3000USD; I've got one pool that wants to implement replace-by-fee that has said they are going to wait until it's been tested on Eligius first.

@sipa
Copy link
Member

sipa commented Jun 1, 2013

@petertodd Sure, I agree it's a very good way to debug and test potentially forking changes. I just don't like what it may lead to.

@rebroad
Copy link
Contributor

rebroad commented Jun 2, 2013

@sipa I agree it is good to be wary of where this may lead to. Are you meaning to imply that leaving things as they are may be a better alternative to the proposed solution made by Luke?

@DrHaribo
Copy link

DrHaribo commented Jun 4, 2013

I would like to have block proposal functionality for BitMinter as well.

@ghost
Copy link

ghost commented Jul 10, 2013

I'd very much like this for my new pool (currently in private testing), if another "driver" is needed :)

@gavinandresen
Copy link
Contributor

Rebase needed.

@luke-jr
Copy link
Member Author

luke-jr commented Oct 25, 2013

Rebased.

@laanwj
Copy link
Member

laanwj commented Nov 11, 2013

Should this be closed now that #3185 is in?

@luke-jr
Copy link
Member Author

luke-jr commented Nov 11, 2013

No, #3185 is entirely unrelated.

@luke-jr
Copy link
Member Author

luke-jr commented Dec 3, 2013

Rebased on top of #3185.

@jgarzik
Copy link
Contributor

jgarzik commented Jun 6, 2014

Seems nominally OK, but I'm not convinced the CValidationState stuff is correct for all cases.

@@ -2307,6 2307,9 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CDiskBlockPos* dbp)
}
}

if (!fWriteToDisk)
Copy link
Member

Choose a reason for hiding this comment

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

Instead of adding a fWriteToDisk boolean argument, wouldn't it be more clear to split up the function in a checking and disk-writing part?

Copy link
Member Author

Choose a reason for hiding this comment

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

Splitting up these means the new split functions would need to assume the mutex is held already (thus not get it themselves) to ensure the mutex isn't released between checks & writing - forcing the callers to hold the mutex instead. In which case IMO those new methods would best be private, and the current AcceptBlock interface (with fWriteToDisk added) exposed as a wrapper. Is that a change that still makes sense to you?

Copy link
Member

Choose a reason for hiding this comment

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

Sounds fair to me. Except for adding a fWriteToDisk boolean argument, which was my problem with this in the first place. The idea would be to have two functions, one that only checks and one that checks and writes to disk.

@luke-jr luke-jr force-pushed the blkproposal branch 3 times, most recently from d098487 to c39a58c Compare November 18, 2014 19:13
@luke-jr luke-jr force-pushed the blkproposal branch 2 times, most recently from 6c55698 to 720efbe Compare November 18, 2014 19:28
@laanwj
Copy link
Member

laanwj commented Nov 19, 2014

Seems ready to merge now? Ready to ACK this now @gmaxwell @sipa @gavinandresen ?

BlockMap::iterator mi = mapBlockIndex.find(hash);
if (mi != mapBlockIndex.end()) {
CBlockIndex *pindex = mi->second;
if (pindex->nStatus & BLOCK_VALID_MASK == BLOCK_VALID_SCRIPTS)
Copy link
Member

Choose a reason for hiding this comment

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

nit: pindex->IsValid(BLOCK_VALID_SCRIPTS)

@sipa
Copy link
Member

sipa commented Nov 19, 2014

Untested ACK.

@luke-jr
Copy link
Member Author

luke-jr commented Nov 20, 2014

(Made the change @sipa suggested.)

@@ -16,6 17,7 @@ class UniValue;
// core_read.cpp
extern CScript ParseScript(std::string s);
extern bool DecodeHexTx(CTransaction& tx, const std::string& strHexTx);
extern bool DecodeHexBlk(CBlock&, const std::string& strHexBlk);
Copy link

Choose a reason for hiding this comment

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

Just for completeness, every other function here has a variable (name) specified, while CBlock has not. In the definition you use block.

Copy link
Member Author

Choose a reason for hiding this comment

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

Better not to add redundant content.

Copy link

Choose a reason for hiding this comment

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

You are such a contra guy sometimes ^^.

@laanwj laanwj merged commit b867e40 into bitcoin:master Nov 24, 2014
laanwj added a commit that referenced this pull request Nov 24, 2014
b867e40 CreateNewBlock: Stick height in coinbase so we pass template sanity check (Luke Dashjr)
60755db submitblock: Check for duplicate submissions explicitly (Luke Dashjr)
bc6cb41 QA RPC tests: Add tests block block proposals (Luke Dashjr)
9765a50 Implement BIP 23 Block Proposal (Luke Dashjr)
3dcbb9b Abstract DecodeHexBlk and BIP22ValidationResult functions out of submitblock (Luke Dashjr)
132ea9b miner_tests: Disable checkpoints so they don't fail the subsidy-change test (Luke Dashjr)
df08a62 TestBlockValidity function for CBlock proposals (used by CreateNewBlock) (Luke Dashjr)
4ea1be7 CreateNewBlock and miner_tests: Also check generated template is valid by CheckBlockHeader, ContextualCheckBlockHeader, CheckBlock, and ContextualCheckBlock (Luke Dashjr)
a48f2d6 Abstract context-dependent block checking from acceptance (Luke Dashjr)
sdaftuar added a commit to sdaftuar/bitcoin that referenced this pull request May 14, 2015
KolbyML pushed a commit to KolbyML/bitcoin that referenced this pull request Dec 5, 2020
…further clean up.

063401c PoS miner: add height to the first input scriptSig of the coinstake tx   remove unneded IncrementExtraNonce call in PoS blocks. (furszy)
7fc4680 Do not calculate the block value twice for the same block. (furszy)
7893818 Removing not needed CBlock::payee member. (furszy)
3e07280 Remove unused zPIVStake argument in FillBlockPayee. (furszy)
f702628 miner: decouple coinbase transaction creation into its own function. (furszy)
377f87e FillBlockPayee: reworked to not require chainActive.Tip redundant access. (furszy)
920652b miner: remove FillBlockPayee unneded fee argument   refactor coinbase tx creation to be in one single place and not dispersed across the CreateNewBlock method. (furszy)

Pull request description:

  Another step forward improving the miner `CreateNewBlock` function.
  This time, have unified the coinbase tx creation flow that was previously dispersed over the function and having some redundant initializations/sets.
  Plus, cleaned up some unused and/or unneeded fields and function arguments.

  This is a preparation for bitcoin#1815 work.  It will not be possible to modify any of the elements of a transaction once them are appended to a block, thus why the transaction needs (more than ever) to be crafted in one single place and not all over the sources.

ACKs for top commit:
  Fuzzbawls:
    ACK 063401c
  random-zebra:
    utACK 063401c and merging...

Tree-SHA512: c32cd87f82d9b31dedf9d47063a67978ef683bf35ff625823d6ece1a2d2904599dcbf15791682ffc1deb412082b1ecc24d11b364e300d4ceb259c65e65b0e9f6
KolbyML pushed a commit to KolbyML/bitcoin that referenced this pull request Dec 5, 2020
…y once.

261bd22 Staking process: calculate the stakeable utxo only once. (furszy)

Pull request description:

  Work on top of bitcoin#1816 and part of bitcoin#1817 coinstake transaction creation speedup goal. Starting on 01814d5

  Improving the following situation: we are calculating the stakeable utxo twice for the same PoS block creation process (looping over the entire wallet's transactions map twice), one before calling `CreateNewBlock` in `CheckForCoins` and the second one inside the `CreateNewBlock` method when we call `CWallet::CreateCoinStake`.
  This PR fixes it adding an unique available coins vector calculated before the block creation, only once per try, in the `CheckForCoins` function and feeding `CreateNewBlock` with it.

ACKs for top commit:
  random-zebra:
    utACK 261bd22

Tree-SHA512: f553667fd48d0d7eb78e2ce87b438c915dc216b32e0426e0214caa52f16a2627143319233c6dd93e4b5d45dcfbb825787c1b39cd209c8e6516bf2391f0516e00
KolbyML pushed a commit to KolbyML/bitcoin that referenced this pull request Dec 5, 2020
911e31c Make CBlock::vtx a vector of shared_ptr<CTransaction> (furszy)
9d27b75 Add deserializing constructors to CTransaction and CMutableTransaction (Pieter Wuille)
5f90940 Add serialization for unique_ptr and shared_ptr (Pieter Wuille)

Pull request description:

  Inspired on bitcoin#9125 (with many more adaptations), preparation for bitcoin#8580. Ant work 🐜

  Establishing the bases for the work, we will need to continue migrating `CTransaction` to `std::shared_ptr<const CTransaction>` where is possible. Example bitcoin#8126 (can find more in bitcoin#1726 list).

  TODO:
  * back port final `CTransactionRef` implementation commit.

  EDIT:
  This is now depending on bitcoin#1816 .

ACKs for top commit:
  random-zebra:
    ACK 911e31c
  Fuzzbawls:
    ACK 911e31c

Tree-SHA512: 61d937aba7dce4ac0867496e7f81ae8351dcdd60b4e72c4f0ed58152a7e556bf455836c766bc97bbca331227e5deed92fa5ce609fa63bb9cb71600b430dc4405
@bitcoin bitcoin locked as resolved and limited conversation to collaborators Sep 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.