Skip to content

Commit

Permalink
core/blobpool: implement txpool for blob txs
Browse files Browse the repository at this point in the history
  • Loading branch information
karalabe committed Apr 4, 2023
1 parent d2cf493 commit 08e6251
Show file tree
Hide file tree
Showing 42 changed files with 4,139 additions and 146 deletions.
1 change: 1 addition & 0 deletions build/tools/tools.go
Expand Up @@ -21,6 +21,7 @@ package tools

import (
// Tool imports for go:generate.
_ "github.com/OffchainLabs/methodical-ssz/cmd/ssz"
_ "github.com/fjl/gencodec"
_ "github.com/golang/protobuf/protoc-gen-go"
_ "golang.org/x/tools/cmd/stringer"
Expand Down
6 changes: 5 additions & 1 deletion cmd/geth/main.go
Expand Up @@ -85,6 +85,10 @@ var (
utils.TxPoolAccountQueueFlag,
utils.TxPoolGlobalQueueFlag,
utils.TxPoolLifetimeFlag,
utils.BlobPoolDataDirFlag,
utils.BlobPoolDataCapFlag,
utils.BlobPoolPriceLimitFlag,
utils.BlobPoolPriceBumpFlag,
utils.SyncModeFlag,
utils.SyncTargetFlag,
utils.ExitWhenSyncedFlag,
Expand Down Expand Up @@ -437,7 +441,7 @@ func startNode(ctx *cli.Context, stack *node.Node, backend ethapi.Backend, isCon
}
// Set the gas price to the limits from the CLI and start mining
gasprice := flags.GlobalBig(ctx, utils.MinerGasPriceFlag.Name)
ethBackend.TxPool().SetGasPrice(gasprice)
ethBackend.TxPool().SetGasTip(gasprice)
// start mining
threads := ctx.Int(utils.MinerThreadsFlag.Name)
if err := ethBackend.StartMining(threads); err != nil {
Expand Down
32 changes: 28 additions & 4 deletions cmd/utils/flags.go
Expand Up @@ -387,18 +387,18 @@ var (
TxPoolJournalFlag = &cli.StringFlag{
Name: "txpool.journal",
Usage: "Disk journal for local transaction to survive node restarts",
Value: txpool.DefaultConfig.Journal,
Value: ethconfig.Defaults.TxPool.Journal,
Category: flags.TxPoolCategory,
}
TxPoolRejournalFlag = &cli.DurationFlag{
Name: "txpool.rejournal",
Usage: "Time interval to regenerate the local transaction journal",
Value: txpool.DefaultConfig.Rejournal,
Value: ethconfig.Defaults.TxPool.Rejournal,
Category: flags.TxPoolCategory,
}
TxPoolPriceLimitFlag = &cli.Uint64Flag{
Name: "txpool.pricelimit",
Usage: "Minimum gas price limit to enforce for acceptance into the pool",
Usage: "Minimum gas price tip to enforce for acceptance into the pool",
Value: ethconfig.Defaults.TxPool.PriceLimit,
Category: flags.TxPoolCategory,
}
Expand Down Expand Up @@ -438,7 +438,31 @@ var (
Value: ethconfig.Defaults.TxPool.Lifetime,
Category: flags.TxPoolCategory,
}

// Blob transaction pool settings
BlobPoolDataDirFlag = &cli.StringFlag{
Name: "blobpool.datadir",
Usage: "Data directory to store blob transactions in",
Value: ethconfig.Defaults.BlobPool.Datadir,
Category: flags.BlobPoolCategory,
}
BlobPoolDataCapFlag = &cli.Uint64Flag{
Name: "blobpool.datacap",
Usage: "Disk space to allocate for pending blob transactions (soft limit)",
Value: ethconfig.Defaults.BlobPool.Datacap,
Category: flags.BlobPoolCategory,
}
BlobPoolPriceLimitFlag = &cli.Uint64Flag{
Name: "blobpool.pricelimit",
Usage: "Minimum gas price tip to enforce for acceptance into the blob pool",
Value: ethconfig.Defaults.BlobPool.PriceLimit,
Category: flags.BlobPoolCategory,
}
BlobPoolPriceBumpFlag = &cli.Uint64Flag{
Name: "blobpool.pricebump",
Usage: "Price bump percentage to replace an already existing blob transaction",
Value: ethconfig.Defaults.BlobPool.PriceBump,
Category: flags.BlobPoolCategory,
}
// Performance tuning settings
CacheFlag = &cli.IntFlag{
Name: "cache",
Expand Down
80 changes: 80 additions & 0 deletions common/types.go
Expand Up @@ -130,6 +130,46 @@ func (h Hash) MarshalText() ([]byte, error) {
return hexutil.Bytes(h[:]).MarshalText()
}

// MarshalSSZ implements fastssz.Marshaler.
func (h Hash) MarshalSSZ() ([]byte, error) {
return h[:], nil
}

// MarshalSSZTo implements fastssz.Marshaler.
func (h Hash) MarshalSSZTo(dst []byte) ([]byte, error) {
if len(dst) < HashLength {
return nil, fmt.Errorf("destination buffer too small: len %d < want %d", len(dst), HashLength)
}
copy(dst, h[:])
return dst[HashLength:], nil
}

// SizeSSZ implements fastssz.Marshaler.
func (h Hash) SizeSSZ() int {
return HashLength
}

// UnmarshalSSZ implements fastssz.Unmarshaler.
func (h *Hash) UnmarshalSSZ(buf []byte) error {
if len(buf) != HashLength {
return fmt.Errorf("source buffer size mismatch: have %d < want %d", len(buf), AddressLength)
}
copy(h[:], buf)
return nil
}

// HashTreeRoot implements fastssz.HashRoot.
func (h Hash) HashTreeRoot() ([32]byte, error) {
return [32]byte{}, nil
}

/*
// HashTreeRootWith implements fastssz.HashRoot.
func (h Hash) HashTreeRootWith(hh *ssz.Hasher) error {
hh.Append(h[:])
return nil
}
*/
// SetBytes sets the hash to the value of b.
// If b is larger than len(h), b will be cropped from the left.
func (h *Hash) SetBytes(b []byte) {
Expand Down Expand Up @@ -324,6 +364,46 @@ func (a *Address) UnmarshalJSON(input []byte) error {
return hexutil.UnmarshalFixedJSON(addressT, input, a[:])
}

// MarshalSSZ implements fastssz.Marshaler.
func (a Address) MarshalSSZ() ([]byte, error) {
return a[:], nil
}

// MarshalSSZTo implements fastssz.Marshaler.
func (a Address) MarshalSSZTo(dst []byte) ([]byte, error) {
if len(dst) < AddressLength {
return nil, fmt.Errorf("destination buffer too small: len %d < want %d", len(dst), AddressLength)
}
copy(dst, a[:])
return dst[AddressLength:], nil
}

// SizeSSZ implements fastssz.Marshaler.
func (a Address) SizeSSZ() int {
return AddressLength
}

// UnmarshalSSZ implements fastssz.Unmarshaler.
func (a *Address) UnmarshalSSZ(buf []byte) error {
if len(buf) != AddressLength {
return fmt.Errorf("source buffer size mismatch: have %d < want %d", len(buf), AddressLength)
}
copy(a[:], buf)
return nil
}

// HashTreeRoot implements fastssz.HashRoot.
func (a Address) HashTreeRoot() ([32]byte, error) {
return [32]byte{}, nil
}

/*
// HashTreeRootWith implements fastssz.HashRoot.
func (a Address) HashTreeRootWith(hh *ssz.Hasher) error {
hh.Append(a[:])
return nil
}
*/
// Scan implements Scanner for database/sql.
func (a *Address) Scan(src interface{}) error {
srcB, ok := src.([]byte)
Expand Down

0 comments on commit 08e6251

Please sign in to comment.