github.com/aakash4dev/cometbft@v0.38.2/spec/consensus/creating-proposal.md (about)

     1  ---
     2  order: 2
     3  ---
     4  # Creating a proposal
     5  
     6  A block consists of a header, transactions, votes (the commit),
     7  and a list of evidence of malfeasance (eg. signing conflicting votes).
     8  
     9  Outstanding evidence items get priority over outstanding transactions in the mempool.
    10  All in all, the block MUST NOT exceed  `ConsensusParams.Block.MaxBytes`,
    11  or 100MB if `ConsensusParams.Block.MaxBytes == -1`.
    12  
    13  ## Reaping transactions from the mempool
    14  
    15  When we reap transactions from the mempool, we calculate maximum data
    16  size by subtracting maximum header size (`MaxHeaderBytes`), the maximum
    17  protobuf overhead for a block (`MaxOverheadForBlock`), the size of
    18  the last commit (if present) and evidence (if present). While reaping
    19  we account for protobuf overhead for each transaction.
    20  
    21  ```go
    22  func MaxDataBytes(maxBytes, evidenceBytes int64, valsCount int) int64 {
    23    return maxBytes -
    24    MaxOverheadForBlock -
    25    MaxHeaderBytes -
    26    MaxCommitBytes(valsCount) -
    27    evidenceBytes
    28  }
    29  ```
    30  
    31  If `ConsensusParams.Block.MaxBytes == -1`, we reap *all* outstanding transactions from the mempool
    32  
    33  ## Preparing the proposal
    34  
    35  Once the transactions have been reaped from the mempool according to the rules described above,
    36  CometBFT calls `PrepareProposal` to the application with the transaction list that has just been reaped.
    37  As part of this call the application can remove, add, or reorder transactions in the transaction list.
    38  
    39  The `RequestPrepareProposal` contains two important fields:
    40  
    41  * `MaxTxBytes`, which contains the value returned by `MaxDataBytes` described above.
    42    The application MUST NOT return a list of transactions whose size exceeds this number.
    43  * `Txs`, which contains the list of reaped transactions.
    44  
    45  For more details on `PrepareProposal`, please see the
    46  [relevant part of the spec](../abci/abci%2B%2B_methods.md#prepareproposal)
    47  
    48  ## Validating transactions in the mempool
    49  
    50  Before we accept a transaction in the mempool, we check if its size is no more
    51  than {MaxDataSize}. {MaxDataSize} is calculated using the same formula as
    52  above, except we assume there is no evidence.
    53  
    54  ```go
    55  func MaxDataBytesNoEvidence(maxBytes int64, valsCount int) int64 {
    56    return maxBytes -
    57      MaxOverheadForBlock -
    58      MaxHeaderBytes -
    59      MaxCommitBytes(valsCount)
    60  }
    61  ```