Skip to content

Commit

Permalink
more stake amplification fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
zabtc committed Jan 27, 2019
1 parent 3c2b000 commit 93c224e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
4 changes: 2 additions & 2 deletions configure.ac
Expand Up @@ -2,10 +2,10 @@ dnl require autoconf 2.60 (AS_ECHO/AS_ECHO_N)
AC_PREREQ([2.60])
define(_CLIENT_VERSION_MAJOR, 2)
define(_CLIENT_VERSION_MINOR, 2)
define(_CLIENT_VERSION_REVISION, 0)
define(_CLIENT_VERSION_REVISION, 1)
define(_CLIENT_VERSION_BUILD, 0)
define(_CLIENT_VERSION_IS_RELEASE, true)
define(_COPYRIGHT_YEAR, 2018)
define(_COPYRIGHT_YEAR, 2019)
AC_INIT([Epic Core],[_CLIENT_VERSION_MAJOR._CLIENT_VERSION_MINOR._CLIENT_VERSION_REVISION],[www.savebitcoin.io],[epic])
AC_CONFIG_SRCDIR([src/main.cpp])
AC_CONFIG_HEADERS([src/config/epic-config.h])
Expand Down
4 changes: 2 additions & 2 deletions src/clientversion.h
Expand Up @@ -16,7 +16,7 @@
//! These need to be macros, as clientversion.cpp's and epic*-res.rc's voodoo requires it
#define CLIENT_VERSION_MAJOR 2
#define CLIENT_VERSION_MINOR 2
#define CLIENT_VERSION_REVISION 0
#define CLIENT_VERSION_REVISION 1
#define CLIENT_VERSION_BUILD 0

//! Set to true for release, false for prerelease or test build
Expand All @@ -26,7 +26,7 @@
* Copyright year (2009-this)
* Todo: update this when changing our copyright comments in the source
*/
#define COPYRIGHT_YEAR 2018
#define COPYRIGHT_YEAR 2019

#endif //HAVE_CONFIG_H

Expand Down
29 changes: 28 additions & 1 deletion src/main.cpp
Expand Up @@ -58,6 +58,7 @@ using namespace std;
*/

CCriticalSection cs_main;
CCriticalSection cs_mapstake;

BlockMap mapBlockIndex;
map<uint256, uint256> mapProofOfStake;
Expand Down Expand Up @@ -2018,7 +2019,9 @@ bool DisconnectBlock(CBlock& block, CValidationState& state, CBlockIndex* pindex
coins->vout.resize(out.n + 1);
coins->vout[out.n] = undo.txout;

mapStakeSpent.erase(out);
LOCK(cs_mapstake);
// erase the spent input
mapStakeSpent.erase(out);
}
}
}
Expand Down Expand Up @@ -2251,6 +2254,28 @@ bool ConnectBlock(const CBlock& block, CValidationState& state, CBlockIndex* pin
if (!pblocktree->WriteTxIndex(vPos))
return state.Abort("Failed to write transaction index");

{
LOCK(cs_mapstake);

// add new entries
for (const CTransaction tx: block.vtx) {
if (tx.IsCoinBase())
continue;
for (const CTxIn in: tx.vin) {
mapStakeSpent.insert(std::make_pair(in.prevout, pindex->nHeight));
}
}

// delete old entries
for (auto it = mapStakeSpent.begin(); it != mapStakeSpent.end();) {
if (it->second < pindex->nHeight - Params().MaxReorganizationDepth()) {
it = mapStakeSpent.erase(it);
} else {
it++;
}
}
}

// add this block to the view's block chain
view.SetBestBlock(pindex->GetBlockHash());

Expand Down Expand Up @@ -3420,6 +3445,8 @@ bool AcceptBlock(CBlock& block, CValidationState& state, CBlockIndex** ppindex,

if (!coins.HaveInputs(block.vtx[1])) {

LOCK(cs_mapstake);

// the inputs are spent at the chain tip so we should look at the recently spent outputs
for (CTxIn in : block.vtx[1].vin) {
auto it = mapStakeSpent.find(in.prevout);
Expand Down
6 changes: 3 additions & 3 deletions src/version.h
Expand Up @@ -11,7 +11,7 @@
* network protocol versioning
*/

static const int PROTOCOL_VERSION = 70930;
static const int PROTOCOL_VERSION = 70940;

//! initial proto version, to be increased after version/verack negotiation
static const int INIT_PROTO_VERSION = 209;
Expand All @@ -20,8 +20,8 @@ static const int INIT_PROTO_VERSION = 209;
static const int GETHEADERS_VERSION = 70077;

//! disconnect from peers older than this proto version
static const int MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT = 70912;
static const int MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT = 70920;
static const int MIN_PEER_PROTO_VERSION_BEFORE_ENFORCEMENT = 70920;
static const int MIN_PEER_PROTO_VERSION_AFTER_ENFORCEMENT = 70940;

//! nTime field added to CAddress, starting with this version;
//! if possible, avoid requesting addresses nodes older than this
Expand Down

0 comments on commit 93c224e

Please sign in to comment.