github.com/ethereum/go-ethereum@v1.14.4-0.20240516095835-473ee8fc07a3/core/txpool/blobpool/slotter.go (about)

     1  // Copyright 2023 The go-ethereum Authors
     2  // This file is part of the go-ethereum library.
     3  //
     4  // The go-ethereum library is free software: you can redistribute it and/or modify
     5  // it under the terms of the GNU Lesser General Public License as published by
     6  // the Free Software Foundation, either version 3 of the License, or
     7  // (at your option) any later version.
     8  //
     9  // The go-ethereum library is distributed in the hope that it will be useful,
    10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
    11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
    12  // GNU Lesser General Public License for more details.
    13  //
    14  // You should have received a copy of the GNU Lesser General Public License
    15  // along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
    16  
    17  package blobpool
    18  
    19  // newSlotter creates a helper method for the Billy datastore that returns the
    20  // individual shelf sizes used to store transactions in.
    21  //
    22  // The slotter will create shelves for each possible blob count + some tx metadata
    23  // wiggle room, up to the max permitted limits.
    24  //
    25  // The slotter also creates a shelf for 0-blob transactions. Whilst those are not
    26  // allowed in the current protocol, having an empty shelf is not a relevant use
    27  // of resources, but it makes stress testing with junk transactions simpler.
    28  func newSlotter() func() (uint32, bool) {
    29  	slotsize := uint32(txAvgSize)
    30  	slotsize -= uint32(blobSize) // underflows, it's ok, will overflow back in the first return
    31  
    32  	return func() (size uint32, done bool) {
    33  		slotsize += blobSize
    34  		finished := slotsize > maxBlobsPerTransaction*blobSize+txMaxSize
    35  
    36  		return slotsize, finished
    37  	}
    38  }