Prepare SHA256D and RandomX multi-algo framework
This commit is contained in:
parent
6103c1ef22
commit
b913f39508
2 changed files with 50 additions and 6 deletions
|
|
@ -17,6 +17,25 @@ uint256 CBlockHeader::GetHash() const
|
||||||
return SerializeHash(*this);
|
return SerializeHash(*this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CBlockHeader::GetAlgo() const
|
||||||
|
{
|
||||||
|
switch (nVersion & BLOCK_VERSION_ALGO) {
|
||||||
|
case BLOCK_VERSION_SHA256D:
|
||||||
|
return ALGO_SHA256D;
|
||||||
|
case BLOCK_VERSION_RANDOMX:
|
||||||
|
return ALGO_RANDOMX;
|
||||||
|
default:
|
||||||
|
return ALGO_UNKNOWN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uint256 CBlockHeader::GetPoWAlgoHash(const Consensus::Params& params) const
|
||||||
|
{
|
||||||
|
// RandomX hashing is not enabled yet.
|
||||||
|
// For now, preserve existing SHA256D behavior.
|
||||||
|
return GetHash();
|
||||||
|
}
|
||||||
|
|
||||||
std::string CBlock::ToString(const Consensus::Params& params) const
|
std::string CBlock::ToString(const Consensus::Params& params) const
|
||||||
{
|
{
|
||||||
std::stringstream s;
|
std::stringstream s;
|
||||||
|
|
|
||||||
|
|
@ -14,19 +14,35 @@
|
||||||
namespace Consensus { struct Params; }
|
namespace Consensus { struct Params; }
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
ALGO_UNKNOWN = -1,
|
||||||
|
ALGO_SHA256D = 0,
|
||||||
|
ALGO_RANDOMX = 1,
|
||||||
|
NUM_ALGOS_IMPL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static constexpr int NUM_ALGOS = 2;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
// primary version
|
// primary version
|
||||||
BLOCK_VERSION_DEFAULT = 2,
|
BLOCK_VERSION_DEFAULT = 2,
|
||||||
|
|
||||||
// algo
|
// algo mask / ids
|
||||||
|
BLOCK_VERSION_ALGO = (15 << 8),
|
||||||
BLOCK_VERSION_SHA256D = (2 << 8),
|
BLOCK_VERSION_SHA256D = (2 << 8),
|
||||||
//BLOCK_VERSION_EQUIHASH = (10 << 8),
|
BLOCK_VERSION_RANDOMX = (4 << 8),
|
||||||
//BLOCK_VERSION_ETHASH = (12 << 8),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline int GetVersionForAlgo(int algo)
|
||||||
|
{
|
||||||
|
switch (algo) {
|
||||||
|
case ALGO_SHA256D:
|
||||||
|
return BLOCK_VERSION_SHA256D;
|
||||||
|
case ALGO_RANDOMX:
|
||||||
|
return BLOCK_VERSION_RANDOMX;
|
||||||
|
default:
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** Nodes collect new transactions into a block, hash them into a hash tree,
|
/** Nodes collect new transactions into a block, hash them into a hash tree,
|
||||||
* and scan through nonce values to make the block's hash satisfy proof-of-work
|
* and scan through nonce values to make the block's hash satisfy proof-of-work
|
||||||
|
|
@ -68,8 +84,17 @@ public:
|
||||||
return (nBits == 0);
|
return (nBits == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SetAlgo(int algo)
|
||||||
|
{
|
||||||
|
nVersion &= ~BLOCK_VERSION_ALGO;
|
||||||
|
nVersion |= GetVersionForAlgo(algo);
|
||||||
|
}
|
||||||
|
|
||||||
|
int GetAlgo() const;
|
||||||
|
|
||||||
uint256 GetHash() const;
|
uint256 GetHash() const;
|
||||||
|
|
||||||
|
uint256 GetPoWAlgoHash(const Consensus::Params& params) const;
|
||||||
|
|
||||||
int64_t GetBlockTime() const
|
int64_t GetBlockTime() const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue