-
-
Notifications
You must be signed in to change notification settings - Fork 353
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
Spark coinbase #1494
base: master
Are you sure you want to change the base?
Spark coinbase #1494
Changes from 6 commits
90c9b9c
63f11f1
0ae0b80
d9a3276
dc29f5b
05d5c84
484e80b
2738e20
98d5fc4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -264,6 +264,8 @@ struct Params { | |
|
||
int nSparkStartBlock; | ||
|
||
int nSparkCoinbase; | ||
|
||
Comment on lines
+267
to
+268
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Codebase verification Let me analyze the results and generate a final response. TODO comments and inconsistent initialization need attention The verification reveals several concerns:
Required actions:
🔗 Analysis chainVerify initialization across different networks. Ensure that 🏁 Scripts executedThe following scripts were executed for the analysis: Script: #!/bin/bash
# Description: Check initialization of nSparkCoinbase across network params
# and its relationship with nSparkStartBlock
# Search for nSparkCoinbase initialization
echo "Checking nSparkCoinbase initialization:"
rg "nSparkCoinbase =" -A 1
# Search for nSparkStartBlock initialization for comparison
echo -e "\nChecking nSparkStartBlock initialization:"
rg "nSparkStartBlock =" -A 1
# Verify both parameters are set in all network params
echo -e "\nVerifying presence in network params:"
rg "class C(Main|TestNet|RegTest|DevNet)Params"
Length of output: 2045 |
||
int nLelantusGracefulPeriod; | ||
|
||
// Lelantus Blacklist | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,9 +30,18 @@ std::string CDeterministicMNState::ToString() const | |
std::string operatorPayoutAddress = "none"; | ||
if (ExtractDestination(scriptPayout, dest)) { | ||
payoutAddress = CBitcoinAddress(dest).ToString(); | ||
} else { | ||
std::string strScriptPayout = spark::ToStringSparkAddress(scriptPayout); | ||
if (!strScriptPayout.empty()) | ||
payoutAddress = strScriptPayout; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. std::move(), also in similar cases below |
||
} | ||
|
||
if (ExtractDestination(scriptOperatorPayout, dest)) { | ||
operatorPayoutAddress = CBitcoinAddress(dest).ToString(); | ||
} else { | ||
std::string strScriptPayout = spark::ToStringSparkAddress(scriptOperatorPayout); | ||
if (!strScriptPayout.empty()) | ||
operatorPayoutAddress = strScriptPayout; | ||
} | ||
|
||
return strprintf("CDeterministicMNState(nRegisteredHeight=%d, nLastPaidHeight=%d, nPoSePenalty=%d, nPoSeRevivedHeight=%d, nPoSeBanHeight=%d, nRevocationReason=%d, " | ||
|
@@ -59,11 +68,20 @@ void CDeterministicMNState::ToJson(UniValue& obj) const | |
if (ExtractDestination(scriptPayout, dest)) { | ||
CBitcoinAddress payoutAddress(dest); | ||
obj.push_back(Pair("payoutAddress", payoutAddress.ToString())); | ||
} else { | ||
std::string strScriptPayout = spark::ToStringSparkAddress(scriptPayout); | ||
if (!strScriptPayout.empty()) | ||
obj.push_back(Pair("payoutAddress", strScriptPayout)); | ||
} | ||
|
||
obj.push_back(Pair("pubKeyOperator", pubKeyOperator.Get().ToString())); | ||
if (ExtractDestination(scriptOperatorPayout, dest)) { | ||
CBitcoinAddress operatorPayoutAddress(dest); | ||
obj.push_back(Pair("operatorPayoutAddress", operatorPayoutAddress.ToString())); | ||
} else { | ||
std::string strScriptPayout = spark::ToStringSparkAddress(scriptOperatorPayout); | ||
if (!strScriptPayout.empty()) | ||
obj.push_back(Pair("operatorPayoutAddress", strScriptPayout)); | ||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ Coin::Coin( | |
this->serial_context = serial_context; | ||
|
||
// Validate the type | ||
if (type != COIN_TYPE_MINT && type != COIN_TYPE_SPEND) { | ||
if (type != COIN_TYPE_MINT && type != COIN_TYPE_SPEND && type != COIN_TYPE_COINBASE) { | ||
throw std::invalid_argument("Bad coin type"); | ||
} | ||
this->type = type; | ||
|
@@ -60,7 +60,7 @@ Coin::Coin( | |
// | ||
|
||
|
||
if (this->type == COIN_TYPE_MINT) { | ||
if (this->type == COIN_TYPE_MINT || this->type == COIN_TYPE_COINBASE) { | ||
this->v = v; | ||
// Encrypt recipient data | ||
MintCoinRecipientData r; | ||
|
@@ -81,6 +81,9 @@ Coin::Coin( | |
r_stream << r; | ||
this->r_ = AEAD::encrypt(address.get_Q1()*SparkUtils::hash_k(k), "Spend coin data", r_stream); | ||
} | ||
|
||
if (this->type == COIN_TYPE_COINBASE) | ||
this->k = k; | ||
} | ||
|
||
// Validate a coin for identification | ||
|
@@ -123,7 +126,7 @@ IdentifiedCoinData Coin::identify(const IncomingViewKey& incoming_view_key) { | |
IdentifiedCoinData data; | ||
|
||
// Deserialization means this process depends on the coin type | ||
if (this->type == COIN_TYPE_MINT) { | ||
if (this->type == COIN_TYPE_MINT || this->type == COIN_TYPE_COINBASE) { | ||
MintCoinRecipientData r; | ||
|
||
try { | ||
|
@@ -154,7 +157,7 @@ IdentifiedCoinData Coin::identify(const IncomingViewKey& incoming_view_key) { | |
} catch (const std::exception &) { | ||
throw std::runtime_error("Unable to identify coin"); | ||
} | ||
|
||
// Check that the memo length is valid | ||
unsigned char memo_length = r.padded_memo[0]; | ||
if (memo_length > this->params->get_memo_bytes()) { | ||
|
@@ -221,4 +224,9 @@ void Coin::setParams(const Params* params) { | |
this->params = params; | ||
} | ||
|
||
bool Coin::isValidMNPayment(const spark::Address& addr, const std::vector<unsigned char>& serialContext) const { | ||
Coin c(this->params, COIN_TYPE_COINBASE, k, addr, v, "BlockReward", serial_context); | ||
return this->getHash() == c.getHash(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Add type validation and consider configurable memo
bool Coin::isValidMNPayment(const spark::Address& addr, const std::vector<unsigned char>& serialContext) const {
+ if (this->type != COIN_TYPE_COINBASE) {
+ return false;
+ }
Coin c(this->params, COIN_TYPE_COINBASE, k, addr, v, "BlockReward", serial_context);
return this->getHash() == c.getHash();
}
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,6 +82,9 @@ class Address { | |
std::string encode(const unsigned char network) const; | ||
unsigned char decode(const std::string& str); | ||
|
||
std::vector<unsigned char> toByteVector(const unsigned char network) const; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Top-level const qualifiers are meaningless on parameter types of non-definition function declarations. Please just have |
||
unsigned char fromByteVector(const std::vector<unsigned char>& vch); | ||
|
||
private: | ||
const Params* params; | ||
std::vector<unsigned char> d; | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -13,6 +13,7 @@ struct MintedCoinData { | |||||||||||||||||||||||||||
Address address; | ||||||||||||||||||||||||||||
uint64_t v; | ||||||||||||||||||||||||||||
std::string memo; | ||||||||||||||||||||||||||||
char type; | ||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Document the type field and consider using an enum class. The newly added Consider the following improvements: +// Defines the type of minted coin (e.g., regular mint, coinbase)
+enum class CoinType : char {
+ MINT = 0,
+ COINBASE = 1
+};
+
struct MintedCoinData {
Address address;
uint64_t v;
std::string memo;
- char type;
+ CoinType type; // Type of the minted coin
}; This change would:
📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||
}; | ||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||
class MintTransaction { | ||||||||||||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When serializing (writing), won't this write an empty map and then iterate over that empty map? Is that really the intent?