Skip to content

Commit f9f437a

Browse files
random-zebraFuzzbawls
authored andcommitted
[Wallet] CStakerStatus: save a pointer to the tip instead of the hash
Github-Pull: #1245 Rebased-From: 968d861
1 parent f9022cf commit f9f437a

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

src/wallet/wallet.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2701,7 +2701,7 @@ bool CWallet::CreateCoinStake(
27012701
int nAttempts = 0;
27022702

27032703
// update staker status (hash)
2704-
pStakerStatus->SetLastHash(pindexPrev->GetBlockHash());
2704+
pStakerStatus->SetLastTip(pindexPrev);
27052705

27062706
for (std::unique_ptr<CStakeInput>& stakeInput : listInputs) {
27072707
//new block came in, move on

src/wallet/wallet.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -147,19 +147,23 @@ class CKeyPool
147147
}
148148
};
149149

150-
/** Record metadata about last kernel stake operation (time and prev hash)**/
150+
/** Record info about last kernel stake operation (time and chainTip)**/
151151
class CStakerStatus {
152152
private:
153-
uint256 hashLastStakeAttempt;
153+
const CBlockIndex* tipLastStakeAttempt;
154154
int64_t timeLastStakeAttempt;
155155
public:
156-
uint256 GetLastHash() const { return hashLastStakeAttempt; }
156+
const CBlockIndex* GetLastTip() const { return tipLastStakeAttempt; }
157+
uint256 GetLastHash() const
158+
{
159+
return (tipLastStakeAttempt == nullptr ? 0 : tipLastStakeAttempt->GetBlockHash());
160+
}
157161
int64_t GetLastTime() const { return timeLastStakeAttempt; }
158-
void SetLastHash(const uint256& lastHash) { hashLastStakeAttempt = lastHash; }
162+
void SetLastTip(const CBlockIndex* lastTip) { tipLastStakeAttempt = lastTip; }
159163
void SetLastTime(const uint64_t lastTime) { timeLastStakeAttempt = lastTime; }
160-
void Update(const uint256& lastHash, const uint64_t lastTime)
164+
void Update(CBlockIndex* lastTip, const uint64_t lastTime)
161165
{
162-
SetLastHash(lastHash);
166+
SetLastTip(lastTip);
163167
SetLastTime(lastTime);
164168
}
165169
bool IsActive() { return (timeLastStakeAttempt + 30) >= GetTime(); }

0 commit comments

Comments
 (0)