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

Add serial context into mobile api #1378

Merged
merged 1 commit into from
Dec 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ class CBlockIndex
//! Map id to <hash of the set>
std::map<int, std::vector<unsigned char>> sparkSetHash;
//! map spark coin S to tx hash, this is used when you run with -mobile
std::unordered_map<GroupElement, uint256> sparkTxHash;
std::unordered_map<GroupElement, std::pair<uint256, std::vector<unsigned char>>> sparkTxHashContext;

//! Values of coin serials spent in this block
sigma::spend_info_container sigmaSpentSerials;
Expand Down Expand Up @@ -303,7 +303,7 @@ class CBlockIndex
sparkMintedCoins.clear();
sparkSetHash.clear();
spentLTags.clear();
sparkTxHash.clear();
sparkTxHashContext.clear();
sigmaSpentSerials.clear();
lelantusSpentSerials.clear();
activeDisablingSporks.clear();
Expand Down Expand Up @@ -562,7 +562,7 @@ class CDiskBlockIndex : public CBlockIndex
READWRITE(spentLTags);

if (GetBoolArg("-mobile", false)) {
READWRITE(sparkTxHash);
READWRITE(sparkTxHashContext);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/rpc/misc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ UniValue getsparkanonymityset(const JSONRPCRequest& request)
}

uint256 blockHash;
std::vector<std::pair<spark::Coin, uint256>> coins;
std::vector<std::pair<spark::Coin, std::pair<uint256, std::vector<unsigned char>>>> coins;
std::vector<unsigned char> setHash;

{
Expand All @@ -1261,7 +1261,8 @@ UniValue getsparkanonymityset(const JSONRPCRequest& request)

std::vector<UniValue> data;
data.push_back(EncodeBase64(vch.data(), size_t(vch.size()))); // coin
data.push_back(EncodeBase64(coin.second.begin(), coin.second.size())); // tx hash
data.push_back(EncodeBase64(coin.second.first.begin(), coin.second.first.size())); // tx hash
data.push_back(EncodeBase64(coin.second.second.data(), coin.second.second.size())); // spark serial context

UniValue entity(UniValue::VARR);
entity.push_backV(data);
Expand Down
17 changes: 11 additions & 6 deletions src/spark/state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1017,7 +1017,12 @@ void CSparkState::AddMintsToStateAndBlockIndex(
if (GetBoolArg("-mobile", false)) {
COutPoint outPoint;
GetOutPointFromBlock(outPoint, mint, *pblock);
index->sparkTxHash[mint.S] = outPoint.hash;
CTransactionRef tx;
for (CTransactionRef itr : pblock->vtx) {
if (outPoint.hash == itr->GetHash())
tx = itr;
}
index->sparkTxHashContext[mint.S] = {outPoint.hash, getSerialContext(*tx)};
}
}
}
Expand Down Expand Up @@ -1257,7 +1262,7 @@ void CSparkState::GetCoinsForRecovery(
int coinGroupID,
std::string start_block_hash,
uint256& blockHash_out,
std::vector<std::pair<spark::Coin, uint256>>& coins,
std::vector<std::pair<spark::Coin, std::pair<uint256, std::vector<unsigned char>>>>& coins,
std::vector<unsigned char>& setHash_out) {
coins.clear();
if (coinGroups.count(coinGroupID) == 0) {
Expand Down Expand Up @@ -1290,10 +1295,10 @@ void CSparkState::GetCoinsForRecovery(
numberOfCoins += block->sparkMintedCoins[id].size();
if (block->sparkMintedCoins.count(id) > 0) {
for (const auto &coin : block->sparkMintedCoins[id]) {
uint256 txHash;
if (block->sparkTxHash.count(coin.S))
txHash = block->sparkTxHash[coin.S];
coins.push_back({coin, txHash});
std::pair<uint256, std::vector<unsigned char>> txHashContext;
if (block->sparkTxHashContext.count(coin.S))
txHashContext = block->sparkTxHashContext[coin.S];
coins.push_back({coin, txHashContext});
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/spark/state.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class CSparkState {
int coinGroupID,
std::string start_block_hash,
uint256& blockHash_out,
std::vector<std::pair<spark::Coin, uint256>>& coins,
std::vector<std::pair<spark::Coin, std::pair<uint256, std::vector<unsigned char>>>>& coins,
std::vector<unsigned char>& setHash_out);

std::unordered_map<spark::Coin, CMintedCoinInfo, spark::CoinHash> const & GetMints() const;
Expand Down
2 changes: 1 addition & 1 deletion src/txdb.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ bool CBlockTreeDB::LoadBlockIndexGuts(boost::function<CBlockIndex*(const uint256
pindexNew->sparkMintedCoins = diskindex.sparkMintedCoins;
pindexNew->sparkSetHash = diskindex.sparkSetHash;
pindexNew->spentLTags = diskindex.spentLTags;
pindexNew->sparkTxHash = diskindex.sparkTxHash;
pindexNew->sparkTxHashContext = diskindex.sparkTxHashContext;

pindexNew->activeDisablingSporks = diskindex.activeDisablingSporks;

Expand Down
Loading