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

BIP++1: First pass. #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

BIP++1: First pass. #1

wants to merge 4 commits into from

Conversation

xanather
Copy link

@xanather xanather commented Oct 15, 2022

BIP++1 is only described in the adjusted readme.md.

DO NOT USE YET outside testnets. Read readme.md.

I've only been studying bitcoin core code for a few days. Things I've noticed need looking at:

TODO:

  • Versionbit 27 tests
  • Larger CompactBlock support (larger indices). Adjusting bucket checking sizes etc... Potentially need to add feature flagging here to only transmit indices > 3 bytes after activation.
  • Other buffering, net code constants that may need to be adjusted that aren't immediately apparent.
  • Not so sure about concurrency locks on new DeploymentActiveAfter/DeploymentActiveAt calls.
  • All comments I have placed on the PR commits answered.

Please assist me in making this patch more viable before more formal validation takes place. Submit a PR to the BIP++1 branch.

DO NOT USE YET outside testnets. Read readme.md.
@xanather
Copy link
Author

if (cmpctblock.shorttxids.size() + cmpctblock.prefilledtxn.size() > MAX_BLOCK_WEIGHT / MIN_SERIALIZABLE_TRANSACTION_WEIGHT)

Non consensus code, immediately increase max size. Larger actual compact block sizes support will come soon.

@xanather
Copy link
Author

static const size_t MAX_OUTPUTS_PER_BLOCK = MAX_BLOCK_WEIGHT / MIN_TRANSACTION_OUTPUT_WEIGHT;

This only affects AccessByTxid, used in DisconnectBlock and gettxproofs. Non-consensus.

@xanather
Copy link
Author

xanather commented Oct 15, 2022

if (nTransactions > MAX_BLOCK_WEIGHT / MIN_TRANSACTION_WEIGHT)

Non consensus code quick validity check. Used by backup and txoutproof only.

@xanather
Copy link
Author

xanather commented Oct 15, 2022

if (nSigOpsCost > MAX_STANDARD_TX_SIGOPS_COST)

As mentioned previously, per TX limits aren't changing.

@xanather
Copy link
Author

const uint64_t buffer = timeLeftInCycle / std::chrono::minutes{10} * MAX_BLOCK_SERIALIZED_SIZE;

Network IO limit already adjusted before activation. Required when disconnecting blocks near activation. May need to change other constants such as MAX_UPLOAD_TIMEFRAME.

@xanather
Copy link
Author

CBufferedFile blkdat(fileIn, 2 * MAX_BLOCK_SERIALIZED_SIZE, MAX_BLOCK_SERIALIZED_SIZE + 8, SER_DISK, CLIENT_VERSION);

Read disk buffer will become 1GB in-memory size. Mentioned in the readme. Non-concurrent from first look so would not blow out.

static const unsigned int minTxOutSz = 9;
static const unsigned int maxVout = MAX_BLOCK_WEIGHT / (WITNESS_SCALE_FACTOR * minTxOutSz);
static const unsigned int maxVout = MAX_BLOCK_WEIGHT_LEGACY / (WITNESS_SCALE_FACTOR * minTxOutSz);
Copy link
Author

Choose a reason for hiding this comment

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

Rationalize: No need to adjust this limit. tx_check.cpp also uses the legacy MAX_BLOCK_WEIGHT for tx sizes. There is enough UTX IN/OUT count in the base protocol size.

@@ -16,7 +16,7 @@ bool CheckTransaction(const CTransaction& tx, TxValidationState& state)
if (tx.vout.empty())
return state.Invalid(TxValidationResult::TX_CONSENSUS, "bad-txns-vout-empty");
// Size limits (this doesn't take the witness into account, as that hasn't been checked for malleability)
if (::GetSerializeSize(tx, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) * WITNESS_SCALE_FACTOR > MAX_BLOCK_WEIGHT)
if (::GetSerializeSize(tx, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) * WITNESS_SCALE_FACTOR > MAX_BLOCK_WEIGHT_LEGACY /* Retain old block weight for max sz tx size. */)
Copy link
Author

Choose a reason for hiding this comment

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

Mentioned above, no need to adjust this rule. Feel free to argue otherwise.

: chainparams{chainstate.m_chainman.GetParams()},
m_mempool(mempool),
m_chainstate(chainstate)
{
blockMinFeeRate = options.blockMinFeeRate;
// Limit weight to between 4K and MAX_BLOCK_WEIGHT-4K for sanity:
nBlockMaxWeight = std::max<size_t>(4000, std::min<size_t>(MAX_BLOCK_WEIGHT - 4000, options.nBlockMaxWeight));
nBlockMaxWeight = std::max<size_t>(4000, std::min<size_t>((fPlusPlusActivated ? MAX_BLOCK_WEIGHT : MAX_BLOCK_WEIGHT_LEGACY) - 4000, options.nBlockMaxWeight));
Copy link
Author

Choose a reason for hiding this comment

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

nBlockMaxWeight will only adjust in block assembler once BIP++1 activated.
Old limit will remain indefinitely until then. After activation and no limit is specified by the miner then 2MB non-weighted will become the default.

@@ -20,7 +20,7 @@ class CFeeRate;
class CScript;

/** Default for -blockmaxweight, which controls the range of block weights the mining code will create **/
static constexpr unsigned int DEFAULT_BLOCK_MAX_WEIGHT{MAX_BLOCK_WEIGHT - 4000};
static constexpr unsigned int DEFAULT_BLOCK_MAX_WEIGHT{MAX_BLOCK_WEIGHT_LEGACY - 4000};
Copy link
Author

Choose a reason for hiding this comment

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

See comment in miner.cpp. This gets overridden by option value anyway.

@@ -3406,7 +3412,8 @@ bool CheckBlock(const CBlock& block, BlockValidationState& state, const Consensu
// checks that use witness data may be performed here.

// Size limits
if (block.vtx.empty() || block.vtx.size() * WITNESS_SCALE_FACTOR > MAX_BLOCK_WEIGHT || ::GetSerializeSize(block, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) * WITNESS_SCALE_FACTOR > MAX_BLOCK_WEIGHT)
const unsigned int maxWeight = fPlusPlusActivated ? MAX_BLOCK_WEIGHT : MAX_BLOCK_WEIGHT_LEGACY;
if (block.vtx.empty() || block.vtx.size() * WITNESS_SCALE_FACTOR > maxWeight || ::GetSerializeSize(block, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) * WITNESS_SCALE_FACTOR > maxWeight)
Copy link
Author

Choose a reason for hiding this comment

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

Contextual flag has been put in this routine. I did not want to move the check into AcceptBlock().

@@ -3433,7 +3440,7 @@ bool CheckBlock(const CBlock& block, BlockValidationState& state, const Consensu
{
nSigOps += GetLegacySigOpCount(*tx);
}
if (nSigOps * WITNESS_SCALE_FACTOR > MAX_BLOCK_SIGOPS_COST)
if (nSigOps * WITNESS_SCALE_FACTOR > (fPlusPlusActivated ? MAX_BLOCK_SIGOPS_COST : MAX_BLOCK_SIGOPS_COST_LEGACY))
Copy link
Author

Choose a reason for hiding this comment

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

Same as above.

@@ -201,7 +202,7 @@ bool BlockAssembler::TestPackage(uint64_t packageSize, int64_t packageSigOpsCost
if (nBlockWeight + WITNESS_SCALE_FACTOR * packageSize >= nBlockMaxWeight) {
return false;
}
if (nBlockSigOpsCost + packageSigOpsCost >= MAX_BLOCK_SIGOPS_COST) {
if (nBlockSigOpsCost + packageSigOpsCost >= (nPlusPlusActivated ? MAX_BLOCK_SIGOPS_COST : MAX_BLOCK_SIGOPS_COST_LEGACY)) {
Copy link
Author

Choose a reason for hiding this comment

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

Block assembly max ops only bumped after activation.

@@ -30,7 +30,7 @@ static constexpr unsigned int MIN_STANDARD_TX_NONWITNESS_SIZE{82};
/** Maximum number of signature check operations in an IsStandard() P2SH script */
static constexpr unsigned int MAX_P2SH_SIGOPS{15};
/** The maximum number of sigops we're willing to relay/mine in a single tx */
static constexpr unsigned int MAX_STANDARD_TX_SIGOPS_COST{MAX_BLOCK_SIGOPS_COST/5};
static constexpr unsigned int MAX_STANDARD_TX_SIGOPS_COST{MAX_BLOCK_SIGOPS_COST_LEGACY / 5};
Copy link
Author

Choose a reason for hiding this comment

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

As mentioned previously, per TX limits aren't changing.

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.

None yet

1 participant