Skip to content

Commit 32abe1e

Browse files
committed
Add testnewsb temporary rpc function
1 parent 278aed9 commit 32abe1e

File tree

3 files changed

+152
-0
lines changed

3 files changed

+152
-0
lines changed

src/rpcserver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,7 @@ static const CRPCCommand vRPCCommands[] =
400400
{ "savescraperfilemanifest", &savescraperfilemanifest, cat_developer },
401401
{ "deletecscrapermanifest", &deletecscrapermanifest, cat_developer },
402402
{ "archivescraperlog", &archivescraperlog, cat_developer },
403+
{ "testnewsb", &testnewsb, cat_developer },
403404

404405
// Network commands
405406
{ "addnode", &addnode, cat_network },

src/rpcserver.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ extern UniValue sendscraperfilemanifest(const UniValue& params, bool fHelp);
219219
extern UniValue savescraperfilemanifest(const UniValue& params, bool fHelp);
220220
extern UniValue deletecscrapermanifest(const UniValue& params, bool fHelp);
221221
extern UniValue archivescraperlog(const UniValue& params, bool fHelp);
222+
extern UniValue testnewsb(const UniValue& params, bool fHelp);
222223

223224
// Network
224225
extern UniValue addnode(const UniValue& params, bool fHelp);

src/scraper/scraper.cpp

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4709,3 +4709,153 @@ UniValue archivescraperlog(const UniValue& params, bool fHelp)
47094709
}
47104710

47114711

4712+
4713+
UniValue testnewsb(const UniValue& params, bool fHelp)
4714+
{
4715+
if (fHelp || params.size() != 0 )
4716+
throw std::runtime_error(
4717+
"testnewsb\n"
4718+
"Test the new Superblock class.\n"
4719+
);
4720+
4721+
LOCK(cs_ConvergedScraperStatsCache);
4722+
4723+
if (ConvergedScraperStatsCache.sContract.empty())
4724+
throw std::runtime_error(
4725+
"Wait until a convergence is formed.\n"
4726+
);
4727+
4728+
UniValue res(UniValue::VOBJ);
4729+
4730+
// Contract binary pack/unpack check...
4731+
_log(logattribute::INFO, "testnewsb", "Checking compatibility with binary SB pack/unpack by packing then unpacking, then comparing to the original");
4732+
4733+
std::string& sSBCoreData = ConvergedScraperStatsCache.sContract;
4734+
4735+
std::string sPackedSBCoreData = PackBinarySuperblock(sSBCoreData);
4736+
std::string sSBCoreData_out = UnpackBinarySuperblock(sPackedSBCoreData);
4737+
4738+
if (sSBCoreData == sSBCoreData_out)
4739+
{
4740+
_log(logattribute::INFO, "testnewsb", "Generated contract passed binary pack/unpack");
4741+
res.pushKV("Generated legacy contract", "passed");
4742+
}
4743+
else
4744+
{
4745+
_log(logattribute::ERR, "testnewsb", "Generated contract FAILED binary pack/unpack");
4746+
_log(logattribute::INFO, "testnewsb", "sSBCoreData_out = \n" + sSBCoreData_out);
4747+
res.pushKV("Generated legacy contract", "FAILED");
4748+
4749+
}
4750+
4751+
_log(logattribute::INFO, "testnewsb", "sSBCoreData size = " + std::to_string(sSBCoreData.size()));
4752+
res.pushKV("sSBCoreData size", (uint64_t) sSBCoreData.size());
4753+
_log(logattribute::INFO, "testnewsb", "sPackedSBCoreData size = " + std::to_string(sPackedSBCoreData.size()));
4754+
res.pushKV("sSBPackedCoreData size", (uint64_t) sPackedSBCoreData.size());
4755+
4756+
Superblock NewFormatSuperblock;
4757+
Superblock NewFormatSuperblock_out;
4758+
CDataStream ss(SER_NETWORK, 1);
4759+
CDataStream ss2(SER_NETWORK, 1);
4760+
CDataStream ss3(SER_NETWORK, 1);
4761+
CDataStream ss4(SER_NETWORK, 1);
4762+
uint64_t nNewFormatSuperblockSerSize;
4763+
uint64_t nNewFormatSuperblock_outSerSize;
4764+
uint64_t nNewFormatSuperblockSerSize2;
4765+
uint64_t nNewFormatSuperblock_outSerSize2;
4766+
uint256 nNewFormatSuperblockHash;
4767+
uint256 nNewFormatSuperblock_outHash;
4768+
uint256 nNewFormatSuperblockHash2;
4769+
uint256 nNewFormatSuperblock_outHash2;
4770+
4771+
NewFormatSuperblock.nSBVersion = 2;
4772+
NewFormatSuperblock.nTime = ConvergedScraperStatsCache.nTime;
4773+
NewFormatSuperblock.mScraperSBStats = ConvergedScraperStatsCache.mScraperConvergedStats;
4774+
4775+
NewFormatSuperblock.PopulateReducedMaps();
4776+
4777+
_log(logattribute::INFO, "testnewsb", "mProjRef size = " + std::to_string(NewFormatSuperblock.mProjectRef.size()));
4778+
res.pushKV("mProjRef size", (uint64_t) NewFormatSuperblock.mProjectRef.size());
4779+
_log(logattribute::INFO, "testnewsb", "mCPIDRef size = " + std::to_string(NewFormatSuperblock.mCPIDRef.size()));
4780+
res.pushKV("mCPIDRef size", (uint64_t) NewFormatSuperblock.mCPIDRef.size());
4781+
_log(logattribute::INFO, "testnewsb", "mProjectCPIDStats size = " + std::to_string(NewFormatSuperblock.mProjectCPIDStats.size()));
4782+
res.pushKV("mProjectCPIDStats size", (uint64_t) NewFormatSuperblock.mProjectCPIDStats.size());
4783+
4784+
uint64_t nmProjectCPIDStatsTotalSize = 0;
4785+
for (auto const& entry : NewFormatSuperblock.mProjectCPIDStats)
4786+
{
4787+
_log(logattribute::INFO, "testnewsb", "mProjectCPIDStats ProjID " + std::to_string(entry.first)
4788+
+ ", CPID size " + std::to_string(entry.second.size()));
4789+
nmProjectCPIDStatsTotalSize += entry.second.size();
4790+
}
4791+
4792+
_log(logattribute::INFO, "testnewsb", "mProjectCPIDStats total size = " + std::to_string(nmProjectCPIDStatsTotalSize));
4793+
res.pushKV("mProjectCPIDStats total size", nmProjectCPIDStatsTotalSize);
4794+
4795+
4796+
NewFormatSuperblock.SerializeSuperblock(ss, SER_NETWORK, 1);
4797+
4798+
nNewFormatSuperblockSerSize = ss.size();
4799+
nNewFormatSuperblockHash = Hash(ss.begin(), ss.end());
4800+
4801+
_log(logattribute::INFO, "testnewsb", "nNewFormatSuperblockSerSize = " + std::to_string(nNewFormatSuperblockSerSize));
4802+
res.pushKV("nNewFormatSuperblockSerSize", nNewFormatSuperblockSerSize);
4803+
4804+
NewFormatSuperblock_out.UnserializeSuperblock(ss);
4805+
4806+
NewFormatSuperblock_out.SerializeSuperblock(ss2, SER_NETWORK, 1);
4807+
4808+
4809+
nNewFormatSuperblock_outSerSize = ss2.size();
4810+
nNewFormatSuperblock_outHash = Hash(ss2.begin(), ss2.end());
4811+
4812+
_log(logattribute::INFO, "testnewsb", "nNewFormatSuperblock_outSerSize = " + std::to_string(nNewFormatSuperblock_outSerSize));
4813+
res.pushKV("nNewFormatSuperblock_outSerSize", nNewFormatSuperblock_outSerSize);
4814+
4815+
if (nNewFormatSuperblockHash == nNewFormatSuperblock_outHash)
4816+
{
4817+
_log(logattribute::INFO, "testnewsb", "NewFormatSuperblock serialization passed.");
4818+
res.pushKV("NewFormatSuperblock serialization", "passed");
4819+
}
4820+
else
4821+
{
4822+
_log(logattribute::ERR, "testnewsb", "NewFormatSuperblock serialization FAILED.");
4823+
res.pushKV("NewFormatSuperblock serialization", "FAILED");
4824+
}
4825+
4826+
4827+
4828+
NewFormatSuperblock.SerializeSuperblock2(ss3, SER_NETWORK, 1);
4829+
4830+
nNewFormatSuperblockSerSize2 = ss3.size();
4831+
nNewFormatSuperblockHash2 = Hash(ss3.begin(), ss3.end());
4832+
4833+
_log(logattribute::INFO, "testnewsb", "nNewFormatSuperblockSerSize2 = " + std::to_string(nNewFormatSuperblockSerSize2));
4834+
res.pushKV("nNewFormatSuperblockSerSize2", nNewFormatSuperblockSerSize2);
4835+
4836+
4837+
NewFormatSuperblock_out.UnserializeSuperblock2(ss3);
4838+
4839+
NewFormatSuperblock_out.SerializeSuperblock2(ss4, SER_NETWORK, 1);
4840+
4841+
nNewFormatSuperblock_outSerSize2 = ss4.size();
4842+
nNewFormatSuperblock_outHash2 = Hash(ss4.begin(), ss4.end());
4843+
4844+
_log(logattribute::INFO, "testnewsb", "nNewFormatSuperblock_outSerSize2 = " + std::to_string(nNewFormatSuperblock_outSerSize2));
4845+
res.pushKV("nNewFormatSuperblock_outSerSize2", nNewFormatSuperblock_outSerSize2);
4846+
4847+
if (nNewFormatSuperblockHash2 == nNewFormatSuperblock_outHash2)
4848+
{
4849+
_log(logattribute::INFO, "testnewsb", "NewFormatSuperblock2 serialization passed.");
4850+
res.pushKV("NewFormatSuperblock2 serialization", "passed");
4851+
}
4852+
else
4853+
{
4854+
_log(logattribute::ERR, "testnewsb", "NewFormatSuperblock2 serialization FAILED.");
4855+
res.pushKV("NewFormatSuperblock2 serialization", "FAILED");
4856+
}
4857+
4858+
return res;
4859+
}
4860+
4861+

0 commit comments

Comments
 (0)