Skip to content

Conversation

@luke-jr
Copy link
Member

@luke-jr luke-jr commented May 9, 2012

Without this, the following bugs are possible:

  1. NULL pointer dereference
  • CreateNewBlock returns NULL (out of memory); pblock is left NULL and JSON error thrown
  • Next call sees pindexPrev/nTransactionsUpdatedLast/nStart up to date, so skips over making a new one
  • This next call then tries to update the time on the "current" pblock (NULL)
  1. Deleted object dereference
  • CreateNewBlock throws an exception (not sure if this is possible right now); pblock is left with a pointer to a deleted CBlock
  • Next call sees pindexPrev/nTransactionsUpdatedLast/nStart up to date, so skips over making a new one
  • This next call then tried to update the time on the 'current' pblock (which is deleted)
  • Consequences of this memory corruption are undefined!

luke-jr added a commit to luke-jr/bitcoin that referenced this pull request May 10, 2012
…for proof-of-work and merkletree, since those need to be provided later)

This throws an exception from CreateNewBlock otherwise, which is not safe without bitcoin#1245!
@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 added a commit to luke-jr/bitcoin that referenced this pull request May 27, 2012
…for proof-of-work and merkletree, since those need to be provided later)

This throws an exception from CreateNewBlock otherwise, which is not safe without bitcoin#1245!
@gavinandresen
Copy link
Contributor

ACK

@gavinandresen gavinandresen merged commit 5d53f48 into bitcoin:master Jul 26, 2012
suprnurd pushed a commit to chaincoin-legacy/chaincoin that referenced this pull request Dec 5, 2017
lateminer pushed a commit to lateminer/bitcoin that referenced this pull request Jan 22, 2019
Use accessor methods for Value() and Set() where appropriate.
lateminer pushed a commit to lateminer/bitcoin that referenced this pull request May 6, 2020
3893739 [RPC] Fix getstakingstatus removing compile-time conditional (random-zebra)
9362e88 [Wallet][Cleanup][GUI] minor updates to staking status (random-zebra)
968d861 [Wallet] CStakerStatus: save a pointer to the tip instead of the hash (random-zebra)
bb2a987 [GUI] Refactor updateStakingStatus and set it to inactive after locking (random-zebra)
d2aebc5 [Trivial] Fix lastHashTime type in miner (random-zebra)
b8ed76f [RPC] Add CStakerStatus data to getstakingstatus (random-zebra)
d2d5f08 [PoS] Lock cs_main when getting chainActive data in miner (random-zebra)
dbc46d8 [Cleanup] Remove unused variables in miner (random-zebra)
01173e9 [Core][PoS] Replace mapHashedBlocks and nLastCoinStakeSearchInterval (random-zebra)
6b2b813 [Cleanup][Wallet] Remove unused nSearchInterval field in CreateCoinStake (random-zebra)

Pull request description:

  This PR cleans up the miner code and streamlines the logic used by the client (both in the RPC and in the GUI) to determine whether the wallet is staking or not.
  Currently it relies on a collection of variables (`mapHashedBlocks`, `nLastCoinStakeInterval`, `nSearchInterval`, etc...) updated in kernel.
  These are here replaced with a new class `CStakerStatus`, updated in `CreateCoinStake` (thus directly in wallet), and an instance of  `CStakerStatus` is introduced as member of CWallet.
  This class keeps two variables, `timeLastStakeAttempt ` and `tipLastStakeAttempt`, containing respectively the time of last stake attempt and a pointer to the index of the block upon which last stake attempt was made.

  The Staking Status is Active whenever timeLastStakeAttempt is less than
  30 seconds in the past.

  This PR also expands the output of `getstakingstatus` rpc call adding:

  - `staking_enabled` to tell whether or not staking has been disabled via conf file / startup flag
  - `hashLastStakeAttempt` and `timeLastStakeAttempt` values
  - `heightLastStakeAttempt` (the height of the block with hash `hashLastStakeAttempt`)
  - `tiptime` (the time of the chaintip block) to compare with `timeLastStakeAttempt`. This field replaces  `valid_time` which is unnecessary now).

  and fixes `enoughcoins` with proper staking balance.

ACKs for top commit:
  furszy:
    Pretty nice cleanup 👌 , ACK 3893739
  Fuzzbawls:
    ACK 3893739

Tree-SHA512: f145650f59d2799641e64359c2656f0fd47397ab88893f4c179fa47b57ff5f166929b2af35741124a8a937431b072392f36b4ce50cce564a55df52a78aa9af0e
lateminer pushed a commit to lateminer/bitcoin that referenced this pull request May 6, 2020
7a8d755 [Tests] Remove '-staking' from extra-args (random-zebra)
72d5a31 [Tests] Fix/Update mining_pos_coldstaking test (random-zebra)
5ffa6b5 [Trivial] Rename mintablecoins --> stakeablecoins (random-zebra)
e781cd0 [Cleanup] zPIV Don't validate Accumulator Checkpoints anymore (random-zebra)
5b192e0 [Tests][Bug] Fix staking status in generate_pos() (random-zebra)

Pull request description:

  This is based on top of bitcoin#1276 and bitcoin#1277 which should be reviewed before.
  `generate_pos` framework function relies on the output of `getstakingstatus` RPC which was recently changed.
  Since bitcoin#1245, "validtime" is not returned anymore (nor it was ever really needed here).
  Only things that we need in `generate_pos` are "walletunlocked" and "mintablecoins" (renamed "stakeablecoins").
  "enoughcoins" is going to be removed in bitcoin#1277 , and "haveconnections" is not required on regtest.
  This also updates coldstaking test.

ACKs for top commit:
  Fuzzbawls:
    ACK 7a8d755
  furszy:
    ACK 7a8d755

Tree-SHA512: 0f45d8b3880d8d88258861fc85c04e0c62a834cede8991e1370afcaef05a2fb714a4441e201d0bdfd89251628e92aa51496182b8088917a8f3a9b740a21272f6
@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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants