Skip to content

Commit

Permalink
[Wallet] CStakerStatus: save a pointer to the tip instead of the hash
Browse files Browse the repository at this point in the history
Github-Pull: #1245
Rebased-From: 968d861
  • Loading branch information
random-zebra authored and Fuzzbawls committed Jan 11, 2020
1 parent f9022cf commit f9f437a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/wallet/wallet.cpp
Expand Up @@ -2701,7 +2701,7 @@ bool CWallet::CreateCoinStake(
int nAttempts = 0;

// update staker status (hash)
pStakerStatus->SetLastHash(pindexPrev->GetBlockHash());
pStakerStatus->SetLastTip(pindexPrev);

for (std::unique_ptr<CStakeInput>& stakeInput : listInputs) {
//new block came in, move on
Expand Down
16 changes: 10 additions & 6 deletions src/wallet/wallet.h
Expand Up @@ -147,19 +147,23 @@ class CKeyPool
}
};

/** Record metadata about last kernel stake operation (time and prev hash)**/
/** Record info about last kernel stake operation (time and chainTip)**/
class CStakerStatus {
private:
uint256 hashLastStakeAttempt;
const CBlockIndex* tipLastStakeAttempt;
int64_t timeLastStakeAttempt;
public:
uint256 GetLastHash() const { return hashLastStakeAttempt; }
const CBlockIndex* GetLastTip() const { return tipLastStakeAttempt; }
uint256 GetLastHash() const
{
return (tipLastStakeAttempt == nullptr ? 0 : tipLastStakeAttempt->GetBlockHash());
}
int64_t GetLastTime() const { return timeLastStakeAttempt; }
void SetLastHash(const uint256& lastHash) { hashLastStakeAttempt = lastHash; }
void SetLastTip(const CBlockIndex* lastTip) { tipLastStakeAttempt = lastTip; }
void SetLastTime(const uint64_t lastTime) { timeLastStakeAttempt = lastTime; }
void Update(const uint256& lastHash, const uint64_t lastTime)
void Update(CBlockIndex* lastTip, const uint64_t lastTime)
{
SetLastHash(lastHash);
SetLastTip(lastTip);
SetLastTime(lastTime);
}
bool IsActive() { return (timeLastStakeAttempt + 30) >= GetTime(); }
Expand Down

0 comments on commit f9f437a

Please sign in to comment.