8000 release 0.14.2 by backpacker69 · Pull Request #755 · peercoin/peercoin · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

release 0.14.2 #755

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contac 10000 t 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

Merged
merged 25 commits into from
May 7, 2024
Merged

release 0.14.2 #755

merged 25 commits into from
May 7, 2024

Conversation

backpacker69
Copy link
Member

No description provided.

backpacker69 and others added 20 commits April 25, 2024 11:37
warnings are generated e.g.
                 from ./chainparams.h:9,
                 from test/blockmanager_tests.cpp:5:
./protocol.h:316:26: warning: redundant redeclaration of ‘std::vector<std::__cxx11::basic_string<char> > serviceFlagsToStr(uint64_t)’ in same scope [-Wredundant-decls]
  316 | std::vector<std::string> serviceFlagsToStr(uint64_t flags);
      |                          ^~~~~~~~~~~~~~~~~
./protocol.h:309:26: note: previous declaration of ‘std::vector<std::__cxx11::basic_string<char> > serviceFlagsToStr(uint64_t)’
  309 | std::vector<std::string> serviceFlagsToStr(uint64_t flags);
      |                          ^~~~~~~~~~~~~~~~~
warnings are generated e.g.
                 from ./chainparams.h:9,
                 from test/blockmanager_tests.cpp:5:
./protocol.h:316:26: warning: redundant redeclaration of ‘std::vector<std::__cxx11::basic_string<char> > serviceFlagsToStr(uint64_t)’ in same scope [-Wredundant-decls]
  316 | std::vector<std::string> serviceFlagsToStr(uint64_t flags);
      |                          ^~~~~~~~~~~~~~~~~
./protocol.h:309:26: note: previous declaration of ‘std::vector<std::__cxx11::basic_string<char> > serviceFlagsToStr(uint64_t)’
  309 | std::vector<std::string> serviceFlagsToStr(uint64_t flags);
      |                          ^~~~~~~~~~~~~~~~~
Copy link
Member
@peerchemist peerchemist left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

Copy link
Contributor
@MatthewLM MatthewLM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To summarise my suggested improvement:

  • Add up-to 8 inputs assuming only 1 output will be added.
  • In the loop to create the split outputs
    • Re-run the split logic after determining the fee with the new required fee. Remove the complex nDeduct logic.
    • If the tx is over 1KB, start by removing added inputs one at a time and rerunning the loop.
  • If there is only the original input left (or allowing up to 4?) and the tx still exceeds the 1KB limit, then remove as many outputs as required to bring the tx below 1KB and then split the output amount evenly across those remaining outputs.

@MatthewLM
Copy link
Contributor
MatthewLM commented May 5, 2024

@backpacker69 I've not tested this, but it should be clear what I'm suggesting from this code:

    CAmount nMinFee = 0;
    int maxOutputs = 100;
    CAmount nMinFeeBase = (IsProtocolV07(txNew.nTime) ? MIN_TX_FEE : MIN_TX_FEE_PREV7);

    while(true) {

        // Clear outputs
        txNew.vout.erase(txNew.vout.begin() + 1+bMinterKey, txNew.vout.end());

        // Assume success
        bool outputsOk = true;

        // split and set amounts based on rfc28
        if (pwallet->m_split_coins) {

            CAmount current = nCredit - nMinFee;
            double ratio = current / nTarget;

            // Obtain the optimal number of outputs and clamp it to maxOutputs to ensure the fee is not exceeded
            int desiredOutputs = min(
                int(std::floor((std::sqrt(4 * std::pow(ratio, 2) + 1) + 1) / 2)),
                maxOutputs,
            );

            if (bDebug)
                LogPrintf("rfc28: security level is %f, target amount %f, desired outputs %d from %f ppc\n",
                    securityLevel, double(nTarget)/COIN, desiredOutputs, double(current)/COIN);

            CAmount outValue = current / desiredOutputs;
            CAmount remainder = current - outValue*desiredOutputs;

            for (int i=0; i<desiredOutputs; i++) {

                // Add remainder to first output
                txNew.vout.push_back(CTxOut(outValue + (i == 0 ? remainder : 0), scriptPubKeyOut));

                // make sure transaction below 1kb
                // Why 950?
                if (::GetSerializeSize(txNew, SER_NETWORK, PROTOCOL_VERSION) > 950) {
                    // Remove output that goes over max size and set maxOutputs so that the logic can be re-run
                    txNew.vout.pop_back();
                    outputsOk = false;
                    maxOutputs = i;
                    break;
                }

            }

        } else {
            txNew.vout.push_back(CTxOut(nCredit - nMinFee, scriptPubKeyOut));
        }

        // Sign
        // SNIPPED CODE FOR BREVITY. ADD THIS BACK

        // Limit size
        unsigned int nBytes = ::GetSerializeSize(txNew, SER_NETWORK, PROTOCOL_VERSION);
        if (nBytes >= 1000000/5)
            return error("CreateCoinStake : exceeded coinstake size limit");

        // Check enough fee is paid
        CAmount nNeededFee = GetMinFee(CTransaction(txNew), txNew.nTime) - nMinFeeBase;

        // Not enough fee paid or max outputs have changed requiring a new split and fee, so run again
        if (nMinFee < nNeededFee || !outputsOk) {
            nMinFee = nNeededFee;
            continue; // try signing again
        } else {
            if (bDebug)
                LogPrintf("CreateCoinStake : fee for coinstake %s\n", FormatMoney(nMinFee).c_str());
            break;
        }

    }

Copy link
Contributor
@MatthewLM MatthewLM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, though please check the fee-free coinstake size.

I've not tested it however. Certain edge cases should be tested before release. Automated functional tests would be ideal, but without that manual testing of the different branching behaviour and constraints should be done.

I don't expect there should be any problems but I would release this as an RC and ask people to test out on testnet to see if any problems arise before final release.

@backpacker69
Copy link
Member Author

i have manually tested the edge cases including minter key and added extra safety handling of situation when size of inputs exceeds 1000 bytes.

@backpacker69 backpacker69 requested a review from MatthewLM May 7, 2024 01:59
@peerchemist peerchemist requested a review from MatthewLM May 7, 2024 13:47
@backpacker69 backpacker69 merged commit 88e6408 into master May 7, 2024
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants
0