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

Create Global Params For Fee Estimator Congestion and Priority Params #1258

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions lib/block_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -3491,6 +3491,74 @@ func (bav *UtxoView) _connectUpdateGlobalParams(
}
newGlobalParamsEntry.MempoolFeeEstimatorNumPastBlocks = val
}
if len(extraData[MempoolCongestionFactorBasisPointsKey]) > 0 {
val, bytesRead := Uvarint(
extraData[MempoolCongestionFactorBasisPointsKey],
)
if val > MaxBasisPoints {
return 0, 0, nil, fmt.Errorf(
"_connectUpdateGlobalParams: MempoolCongestionFactorBasisPoints must be <= %d",
MaxBasisPoints,
)
}
if bytesRead <= 0 {
return 0, 0, nil, fmt.Errorf(
"_connectUpdateGlobalParams: unable to decode MempoolCongestionFactorBasisPoints as uint64",
)
}
newGlobalParamsEntry.MempoolCongestionFactorBasisPoints = val
}
if len(extraData[MempoolPastBlocksCongestionFactorBasisPointsKey]) > 0 {
val, bytesRead := Uvarint(
extraData[MempoolPastBlocksCongestionFactorBasisPointsKey],
)
if val > MaxBasisPoints {
return 0, 0, nil, fmt.Errorf(
"_connectUpdateGlobalParams: MempoolPastBlocksCongestionFactorBasisPoints must be <= %d",
MaxBasisPoints,
)
}
if bytesRead <= 0 {
return 0, 0, nil, fmt.Errorf(
"_connectUpdateGlobalParams: unable to decode MempoolPastBlocksCongestionFactorBasisPoints as uint64",
)
}
newGlobalParamsEntry.MempoolPastBlocksCongestionFactorBasisPoints = val
}
if len(extraData[MempoolPriorityPercentileBasisPointsKey]) > 0 {
val, bytesRead := Uvarint(
extraData[MempoolPriorityPercentileBasisPointsKey],
)
if val > MaxBasisPoints {
return 0, 0, nil, fmt.Errorf(
"_connectUpdateGlobalParams: MempoolPriorityPercentileBasisPoints must be <= %d",
MaxBasisPoints,
)
}
if bytesRead <= 0 {
return 0, 0, nil, fmt.Errorf(
"_connectUpdateGlobalParams: unable to decode MempoolPriorityPercentileBasisPoints as uint64",
)
}
newGlobalParamsEntry.MempoolPriorityPercentileBasisPoints = val
}
if len(extraData[MempoolPastBlocksPriorityPercentileBasisPointsKey]) > 0 {
val, bytesRead := Uvarint(
extraData[MempoolPastBlocksPriorityPercentileBasisPointsKey],
)
if val > MaxBasisPoints {
return 0, 0, nil, fmt.Errorf(
"_connectUpdateGlobalParams: MempoolPastBlocksPriorityPercentileBasisPoints must be <= %d",
MaxBasisPoints,
)
}
if bytesRead <= 0 {
return 0, 0, nil, fmt.Errorf(
"_connectUpdateGlobalParams: unable to decode MempoolPastBlocksPriorityPercentileBasisPoints as uint64",
)
}
newGlobalParamsEntry.MempoolPastBlocksPriorityPercentileBasisPoints = val
Copy link
Member

Choose a reason for hiding this comment

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

I probably would have named this PastBlocksPriorityPercentileBasisPoints instead of MempoolPastBlocksPriorityPercentileBasisPoints or would have used a prefix like FeeEstimator for these so we would have FeeEstimatorPastBlocksPriorityPercentileBasisPoints. That feels a bit wordy tho. I just think using Mempool as a prefix is a bit confusing, but these were the names DH was using so if that's what he wants, it's fine by me.

}
if len(extraData[MaxBlockSizeBytesPoSKey]) > 0 {
val, bytesRead := Uvarint(
extraData[MaxBlockSizeBytesPoSKey],
Expand Down
36 changes: 36 additions & 0 deletions lib/block_view_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -4236,6 +4236,18 @@ type GlobalParamsEntry struct {
// the fee for a new txn.
MempoolFeeEstimatorNumPastBlocks uint64

// DefaultMempoolCongestionFactorBasisPoints and DefaultMempoolPastBlocksCongestionFactorBasisPoints are the default values
// for GlobalParams.MempoolCongestionFactorBasisPoints and GlobalParams.DefaultMempoolPastBlocksCongestionFactorBasisPoints.
/// See comments in GlobalParamsEntry for a description of their usage.
MempoolCongestionFactorBasisPoints uint64
MempoolPastBlocksCongestionFactorBasisPoints uint64

// MempoolPriorityPercentileBasisPoints and MempoolPastBlocksPriorityPercentileBasisPoints are the default values
// for GlobalParams.DefaultMempoolPriorityPercentileBasisPoints and GlobalParams.DefaultMempoolPastBlocksPriorityPercentileBasisPoints.
// See comments in GlobalParamsEntry for a description of their usage.
MempoolPriorityPercentileBasisPoints uint64
MempoolPastBlocksPriorityPercentileBasisPoints uint64

// MaxBlockSizeBytesPoS is the maximum size of a block in bytes.
MaxBlockSizeBytesPoS uint64

Expand Down Expand Up @@ -4275,6 +4287,10 @@ func (gp *GlobalParamsEntry) Copy() *GlobalParamsEntry {
MempoolMaxSizeBytes: gp.MempoolMaxSizeBytes,
MempoolFeeEstimatorNumMempoolBlocks: gp.MempoolFeeEstimatorNumMempoolBlocks,
MempoolFeeEstimatorNumPastBlocks: gp.MempoolFeeEstimatorNumPastBlocks,
MempoolCongestionFactorBasisPoints: gp.MempoolCongestionFactorBasisPoints,
MempoolPastBlocksCongestionFactorBasisPoints: gp.MempoolPastBlocksCongestionFactorBasisPoints,
MempoolPriorityPercentileBasisPoints: gp.MempoolPriorityPercentileBasisPoints,
MempoolPastBlocksPriorityPercentileBasisPoints: gp.MempoolPastBlocksPriorityPercentileBasisPoints,
MaxBlockSizeBytesPoS: gp.MaxBlockSizeBytesPoS,
SoftMaxBlockSizeBytesPoS: gp.SoftMaxBlockSizeBytesPoS,
MaxTxnSizeBytesPoS: gp.MaxTxnSizeBytesPoS,
Expand Down Expand Up @@ -4309,6 +4325,10 @@ func (gp *GlobalParamsEntry) RawEncodeWithoutMetadata(blockHeight uint64, skipMe
data = append(data, UintToBuf(gp.MempoolMaxSizeBytes)...)
data = append(data, UintToBuf(gp.MempoolFeeEstimatorNumMempoolBlocks)...)
data = append(data, UintToBuf(gp.MempoolFeeEstimatorNumPastBlocks)...)
data = append(data, UintToBuf(gp.MempoolCongestionFactorBasisPoints)...)
data = append(data, UintToBuf(gp.MempoolPastBlocksCongestionFactorBasisPoints)...)
data = append(data, UintToBuf(gp.MempoolPriorityPercentileBasisPoints)...)
data = append(data, UintToBuf(gp.MempoolPastBlocksPriorityPercentileBasisPoints)...)
data = append(data, UintToBuf(gp.MaxBlockSizeBytesPoS)...)
data = append(data, UintToBuf(gp.SoftMaxBlockSizeBytesPoS)...)
data = append(data, UintToBuf(gp.MaxTxnSizeBytesPoS)...)
Expand Down Expand Up @@ -4406,6 +4426,22 @@ func (gp *GlobalParamsEntry) RawDecodeWithoutMetadata(blockHeight uint64, rr *by
if err != nil {
return errors.Wrapf(err, "GlobalParamsEntry.Decode: Problem reading MempoolFeeEstimatorNumPastBlocks")
}
gp.MempoolCongestionFactorBasisPoints, err = ReadUvarint(rr)
if err != nil {
return errors.Wrapf(err, "GlobalParamsEntry.Decode: Problem reading MempoolCongestionFactorBasisPoints")
}
gp.MempoolPastBlocksCongestionFactorBasisPoints, err = ReadUvarint(rr)
if err != nil {
return errors.Wrapf(err, "GlobalParamsEntry.Decode: Problem reading MempoolPastBlocksCongestionFactorBasisPoints")
}
gp.MempoolPriorityPercentileBasisPoints, err = ReadUvarint(rr)
if err != nil {
return errors.Wrapf(err, "GlobalParamsEntry.Decode: Problem reading MempoolPriorityPercentileBasisPoints")
}
gp.MempoolPastBlocksPriorityPercentileBasisPoints, err = ReadUvarint(rr)
if err != nil {
return errors.Wrapf(err, "GlobalParamsEntry.Decode: Problem reading MempoolPastBlocksPriorityPercentileBasisPoints")
}
gp.MaxBlockSizeBytesPoS, err = ReadUvarint(rr)
if err != nil {
return errors.Wrapf(err, "GlobalParamsEntry.Decode: Problem reading MaxBlockSizeBytesPoS")
Expand Down
4 changes: 4 additions & 0 deletions lib/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -1753,6 +1753,10 @@ const (
MempoolMaxSizeBytesKey = "MempoolMaxSizeBytes"
MempoolFeeEstimatorNumMempoolBlocksKey = "MempoolFeeEstimatorNumMempoolBlocks"
MempoolFeeEstimatorNumPastBlocksKey = "MempoolFeeEstimatorNumPastBlocks"
MempoolCongestionFactorBasisPointsKey = "MempoolCongestionFactorBasisPoints"
MempoolPastBlocksCongestionFactorBasisPointsKey = "MempoolPastBlocksCongestionFactorBasisPoints"
MempoolPriorityPercentileBasisPointsKey = "MempoolPriorityPercentileBasisPoints"
MempoolPastBlocksPriorityPercentileBasisPointsKey = "MempoolPastBlocksPriorityPercentileBasisPoints"
MaxBlockSizeBytesPoSKey = "MaxBlockSizeBytesPoS"
SoftMaxBlockSizeBytesPoSKey = "SoftMaxBlockSizeBytesPoS"
MaxTxnSizeBytesPoSKey = "MaxTxnSizeBytesPoS"
Expand Down
Loading