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

Testing devfee #2

Merged
merged 13 commits into from
Jul 10, 2024
10 changes: 7 additions & 3 deletions src/CryptoNoteConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ const char P2P_STAT_TRUSTED_PUB_KEY[] = "8f80f9a5a434a9f1

//TODO Add here your network seed nodes
const std::initializer_list<const char*> SEED_NODES = {
//"your_seed_ip1.com:8080",
//"your_seed_ip2.com:8080",
"45.32.154.224:49200",
"45.77.148.37:49200",
};

struct CheckpointData {
Expand All @@ -124,7 +124,11 @@ __attribute__((unused))
// You may add here other checkpoints using the following format:
// {<block height>, "<block hash>"},
const std::initializer_list<CheckpointData> CHECKPOINTS = {
//{ 10000, "84b6345731e2702cdaadc6ce5e5238c4ca5ecf48e3447136b2ed829b8a95f3ad" },
{1, "0193545f4b1799f6d1acf3a66ac4331c4a2f75b83de708f4c03a05a3be9e9e08"},
{2, "99877b48dc63adaaa30f2a7d63e12e4e1b4e1d8bcab17fa3d342746c5e27027b"},
{4, "ccead4c6c3d67a68c459318ea5031a9e6e120b22a7b2715975aba0ec241bc3d1"},
{5, "8e640416f7f2aef16f27dc832b2cd352d0f25e401a4a8477e1fdde4137f5c114"},
{10, "7eefa21e77319df6c245528a5e823c53f379c6d6e65326d10b036e4c39d92498"},
};
} // CryptoNote

Expand Down
38 changes: 27 additions & 11 deletions src/CryptoNoteCore/Currency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ bool Currency::constructMinerTx(uint32_t height, size_t medianSize, uint64_t alr
return false;
}

// Calculate dev fee (10% of base reward)
uint64_t devFee = blockReward * 0.10;
uint64_t minerReward = blockReward - devFee;
// Calculate dev fee (10% of base reward + fee)
uint64_t devFee = static_cast<uint64_t>(blockReward * 0.10) + fee;
uint64_t minerReward = blockReward - devFee; // Subtracting the dev fee from the block reward

logger(INFO) << "Block reward: " << blockReward << ", Dev fee: " << devFee << ", Miner reward: " << minerReward << ", Fee: " << fee;

// Decompose amounts for miner and dev fee
std::vector<uint64_t> outAmounts;
Expand All @@ -179,15 +181,15 @@ bool Currency::constructMinerTx(uint32_t height, size_t medianSize, uint64_t alr

bool r = Crypto::generate_key_derivation(minerAddress.viewPublicKey, txkey.secretKey, derivation);

if (!(r)) {
if (!r) {
logger(ERROR, BRIGHT_RED) << "while creating outs: failed to generate_key_derivation("
<< minerAddress.viewPublicKey << ", " << txkey.secretKey << ")";
return false;
}

r = Crypto::derive_public_key(derivation, no, minerAddress.spendPublicKey, outEphemeralPubKey);

if (!(r)) {
if (!r) {
logger(ERROR, BRIGHT_RED) << "while creating outs: failed to derive_public_key("
<< derivation << ", " << no << ", " << minerAddress.spendPublicKey << ")";
return false;
Expand All @@ -204,20 +206,25 @@ bool Currency::constructMinerTx(uint32_t height, size_t medianSize, uint64_t alr

// Add developer fee output
AccountPublicAddress devAddress;
if (!parseAccountAddressString(DEVELOPER_ADDRESS, devAddress)) {
bool parseSuccess = parseAccountAddressString(DEVELOPER_ADDRESS, devAddress);
logger(INFO) << "Parse developer address: " << (parseSuccess ? "success" : "failure");
if (!parseSuccess) {
logger(ERROR, BRIGHT_RED) << "Failed to parse developer address";
return false;
}

Crypto::KeyDerivation devDerivation = boost::value_initialized<Crypto::KeyDerivation>();
Crypto::PublicKey devOutEphemeralPubKey = boost::value_initialized<Crypto::PublicKey>();

if (!Crypto::generate_key_derivation(devAddress.viewPublicKey, txkey.secretKey, devDerivation)) {
Crypto::KeyDerivation devDerivation;
bool keyDerivationSuccess = Crypto::generate_key_derivation(devAddress.viewPublicKey, txkey.secretKey, devDerivation);
logger(INFO) << "Key derivation for developer address: " << (keyDerivationSuccess ? "success" : "failure");
if (!keyDerivationSuccess) {
logger(ERROR, BRIGHT_RED) << "Failed to generate key derivation for developer address";
return false;
}

if (!Crypto::derive_public_key(devDerivation, 0, devAddress.spendPublicKey, devOutEphemeralPubKey)) {
Crypto::PublicKey devOutEphemeralPubKey;
bool derivePubKeySuccess = Crypto::derive_public_key(devDerivation, 0, devAddress.spendPublicKey, devOutEphemeralPubKey);
logger(INFO) << "Public key derivation for developer address: " << (derivePubKeySuccess ? "success" : "failure");
if (!derivePubKeySuccess) {
logger(ERROR, BRIGHT_RED) << "Failed to derive public key for developer address";
return false;
}
Expand All @@ -232,6 +239,7 @@ bool Currency::constructMinerTx(uint32_t height, size_t medianSize, uint64_t alr

summaryAmounts += devFee;

// Ensure summary amounts match block reward
if (summaryAmounts != blockReward) {
logger(ERROR, BRIGHT_RED) << "Failed to construct miner tx, summaryAmounts = " << summaryAmounts << " not equal blockReward = " << blockReward;
return false;
Expand All @@ -240,9 +248,17 @@ bool Currency::constructMinerTx(uint32_t height, size_t medianSize, uint64_t alr
tx.version = CURRENT_TRANSACTION_VERSION;
tx.unlockTime = height + m_minedMoneyUnlockWindow;
tx.inputs.push_back(in);

// Log transaction outputs
logger(INFO) << "Transaction outputs:";
for (const auto& output : tx.outputs) {
logger(INFO) << "Output amount: " << output.amount;
}

return true;
}


bool Currency::isFusionTransaction(const std::vector<uint64_t>& inputsAmounts, const std::vector<uint64_t>& outputsAmounts, size_t size) const {
if (size > fusionTxMaxSize()) {
return false;
Expand Down