From d347db7b42abcb0170ee943582ac3e99fb7d6256 Mon Sep 17 00:00:00 2001 From: iamsofonias Date: Mon, 22 Apr 2024 14:53:12 -0400 Subject: [PATCH 1/3] Create Global Params For Fee Estimator Congestion and Priority Params --- lib/block_view_types.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/block_view_types.go b/lib/block_view_types.go index ebb676dde..a60a10098 100644 --- a/lib/block_view_types.go +++ b/lib/block_view_types.go @@ -4236,6 +4236,18 @@ type GlobalParamsEntry struct { // the fee for a new txn. MempoolFeeEstimatorNumPastBlocks uint64 + // DefaultMempoolCongestionFactorBasisPoints and DefaultPastBlocksCongestionFactorBasisPoints are the default values + // for GlobalParams.MempoolCongestionFactorBasisPoints and GlobalParams.DefaultPastBlocksCongestionFactorBasisPoints. + /// See comments in GlobalParamsEntry for a description of their usage. + MempoolCongestionFactorBasisPoints uint64 + PastBlocksCongestionFactorBasisPoints uint64 + + // MempoolPriorityPercentileBasisPoints and PastBlocksPriorityPercentileBasisPoints are the default values + // for GlobalParams.DefaultMempoolPriorityPercentileBasisPoints and GlobalParams.DefaultPastBlocksPriorityPercentileBasisPoints. + // See comments in GlobalParamsEntry for a description of their usage. + MempoolPriorityPercentileBasisPoints uint64 + PastBlocksPriorityPercentileBasisPoints uint64 + // MaxBlockSizeBytesPoS is the maximum size of a block in bytes. MaxBlockSizeBytesPoS uint64 @@ -4275,6 +4287,10 @@ func (gp *GlobalParamsEntry) Copy() *GlobalParamsEntry { MempoolMaxSizeBytes: gp.MempoolMaxSizeBytes, MempoolFeeEstimatorNumMempoolBlocks: gp.MempoolFeeEstimatorNumMempoolBlocks, MempoolFeeEstimatorNumPastBlocks: gp.MempoolFeeEstimatorNumPastBlocks, + MempoolCongestionFactorBasisPoints: gp.MempoolCongestionFactorBasisPoints, + PastBlocksCongestionFactorBasisPoints: gp.PastBlocksCongestionFactorBasisPoints, + MempoolPriorityPercentileBasisPoints: gp.MempoolPriorityPercentileBasisPoints, + PastBlocksPriorityPercentileBasisPoints: gp.PastBlocksPriorityPercentileBasisPoints, MaxBlockSizeBytesPoS: gp.MaxBlockSizeBytesPoS, SoftMaxBlockSizeBytesPoS: gp.SoftMaxBlockSizeBytesPoS, MaxTxnSizeBytesPoS: gp.MaxTxnSizeBytesPoS, From 4bc7b662339c56099b7d7e9972f03ab1d4c244d1 Mon Sep 17 00:00:00 2001 From: iamsofonias Date: Mon, 22 Apr 2024 16:15:54 -0400 Subject: [PATCH 2/3] Implement encode and decode --- lib/block_view.go | 68 +++++++++++++++++++++++++++++++++++++++++ lib/block_view_types.go | 20 ++++++++++++ lib/constants.go | 4 +++ 3 files changed, 92 insertions(+) diff --git a/lib/block_view.go b/lib/block_view.go index 8f3c57098..1c75c0f4e 100644 --- a/lib/block_view.go +++ b/lib/block_view.go @@ -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[PastBlocksCongestionFactorBasisPointsKey]) > 0 { + val, bytesRead := Uvarint( + extraData[PastBlocksCongestionFactorBasisPointsKey], + ) + if val > MaxBasisPoints { + return 0, 0, nil, fmt.Errorf( + "_connectUpdateGlobalParams: PastBlocksCongestionFactorBasisPoints must be <= %d", + MaxBasisPoints, + ) + } + if bytesRead <= 0 { + return 0, 0, nil, fmt.Errorf( + "_connectUpdateGlobalParams: unable to decode PastBlocksCongestionFactorBasisPoints as uint64", + ) + } + newGlobalParamsEntry.PastBlocksCongestionFactorBasisPoints = 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[PastBlocksPriorityPercentileBasisPointsKey]) > 0 { + val, bytesRead := Uvarint( + extraData[PastBlocksPriorityPercentileBasisPointsKey], + ) + if val > MaxBasisPoints { + return 0, 0, nil, fmt.Errorf( + "_connectUpdateGlobalParams: PastBlocksPriorityPercentileBasisPoints must be <= %d", + MaxBasisPoints, + ) + } + if bytesRead <= 0 { + return 0, 0, nil, fmt.Errorf( + "_connectUpdateGlobalParams: unable to decode PastBlocksPriorityPercentileBasisPoints as uint64", + ) + } + newGlobalParamsEntry.PastBlocksPriorityPercentileBasisPoints = val + } if len(extraData[MaxBlockSizeBytesPoSKey]) > 0 { val, bytesRead := Uvarint( extraData[MaxBlockSizeBytesPoSKey], diff --git a/lib/block_view_types.go b/lib/block_view_types.go index a60a10098..6019bb165 100644 --- a/lib/block_view_types.go +++ b/lib/block_view_types.go @@ -4325,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.PastBlocksCongestionFactorBasisPoints)...) + data = append(data, UintToBuf(gp.MempoolPriorityPercentileBasisPoints)...) + data = append(data, UintToBuf(gp.PastBlocksPriorityPercentileBasisPoints)...) data = append(data, UintToBuf(gp.MaxBlockSizeBytesPoS)...) data = append(data, UintToBuf(gp.SoftMaxBlockSizeBytesPoS)...) data = append(data, UintToBuf(gp.MaxTxnSizeBytesPoS)...) @@ -4422,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.PastBlocksCongestionFactorBasisPoints, err = ReadUvarint(rr) + if err != nil { + return errors.Wrapf(err, "GlobalParamsEntry.Decode: Problem reading PastBlocksCongestionFactorBasisPoints") + } + gp.MempoolPriorityPercentileBasisPoints, err = ReadUvarint(rr) + if err != nil { + return errors.Wrapf(err, "GlobalParamsEntry.Decode: Problem reading MempoolPriorityPercentileBasisPoints") + } + gp.PastBlocksPriorityPercentileBasisPoints, err = ReadUvarint(rr) + if err != nil { + return errors.Wrapf(err, "GlobalParamsEntry.Decode: Problem reading PastBlocksPriorityPercentileBasisPoints") + } gp.MaxBlockSizeBytesPoS, err = ReadUvarint(rr) if err != nil { return errors.Wrapf(err, "GlobalParamsEntry.Decode: Problem reading MaxBlockSizeBytesPoS") diff --git a/lib/constants.go b/lib/constants.go index eced4d227..b2b0681c3 100644 --- a/lib/constants.go +++ b/lib/constants.go @@ -1753,6 +1753,10 @@ const ( MempoolMaxSizeBytesKey = "MempoolMaxSizeBytes" MempoolFeeEstimatorNumMempoolBlocksKey = "MempoolFeeEstimatorNumMempoolBlocks" MempoolFeeEstimatorNumPastBlocksKey = "MempoolFeeEstimatorNumPastBlocks" + MempoolCongestionFactorBasisPointsKey = "MempoolCongestionFactorBasisPoints" + PastBlocksCongestionFactorBasisPointsKey = "PastBlocksCongestionFactorBasisPoints" + MempoolPriorityPercentileBasisPointsKey = "MempoolPriorityPercentileBasisPoints" + PastBlocksPriorityPercentileBasisPointsKey = "PastBlocksPriorityPercentileBasisPoints" MaxBlockSizeBytesPoSKey = "MaxBlockSizeBytesPoS" SoftMaxBlockSizeBytesPoSKey = "SoftMaxBlockSizeBytesPoS" MaxTxnSizeBytesPoSKey = "MaxTxnSizeBytesPoS" From 03f90a4c509c3cb5d04b0ff511893201055eee1d Mon Sep 17 00:00:00 2001 From: iamsofonias Date: Mon, 22 Apr 2024 16:24:10 -0400 Subject: [PATCH 3/3] Rename --- lib/block_view.go | 20 ++++++++++---------- lib/block_view_types.go | 32 ++++++++++++++++---------------- lib/constants.go | 4 ++-- 3 files changed, 28 insertions(+), 28 deletions(-) diff --git a/lib/block_view.go b/lib/block_view.go index 1c75c0f4e..e38f72dee 100644 --- a/lib/block_view.go +++ b/lib/block_view.go @@ -3508,22 +3508,22 @@ func (bav *UtxoView) _connectUpdateGlobalParams( } newGlobalParamsEntry.MempoolCongestionFactorBasisPoints = val } - if len(extraData[PastBlocksCongestionFactorBasisPointsKey]) > 0 { + if len(extraData[MempoolPastBlocksCongestionFactorBasisPointsKey]) > 0 { val, bytesRead := Uvarint( - extraData[PastBlocksCongestionFactorBasisPointsKey], + extraData[MempoolPastBlocksCongestionFactorBasisPointsKey], ) if val > MaxBasisPoints { return 0, 0, nil, fmt.Errorf( - "_connectUpdateGlobalParams: PastBlocksCongestionFactorBasisPoints must be <= %d", + "_connectUpdateGlobalParams: MempoolPastBlocksCongestionFactorBasisPoints must be <= %d", MaxBasisPoints, ) } if bytesRead <= 0 { return 0, 0, nil, fmt.Errorf( - "_connectUpdateGlobalParams: unable to decode PastBlocksCongestionFactorBasisPoints as uint64", + "_connectUpdateGlobalParams: unable to decode MempoolPastBlocksCongestionFactorBasisPoints as uint64", ) } - newGlobalParamsEntry.PastBlocksCongestionFactorBasisPoints = val + newGlobalParamsEntry.MempoolPastBlocksCongestionFactorBasisPoints = val } if len(extraData[MempoolPriorityPercentileBasisPointsKey]) > 0 { val, bytesRead := Uvarint( @@ -3542,22 +3542,22 @@ func (bav *UtxoView) _connectUpdateGlobalParams( } newGlobalParamsEntry.MempoolPriorityPercentileBasisPoints = val } - if len(extraData[PastBlocksPriorityPercentileBasisPointsKey]) > 0 { + if len(extraData[MempoolPastBlocksPriorityPercentileBasisPointsKey]) > 0 { val, bytesRead := Uvarint( - extraData[PastBlocksPriorityPercentileBasisPointsKey], + extraData[MempoolPastBlocksPriorityPercentileBasisPointsKey], ) if val > MaxBasisPoints { return 0, 0, nil, fmt.Errorf( - "_connectUpdateGlobalParams: PastBlocksPriorityPercentileBasisPoints must be <= %d", + "_connectUpdateGlobalParams: MempoolPastBlocksPriorityPercentileBasisPoints must be <= %d", MaxBasisPoints, ) } if bytesRead <= 0 { return 0, 0, nil, fmt.Errorf( - "_connectUpdateGlobalParams: unable to decode PastBlocksPriorityPercentileBasisPoints as uint64", + "_connectUpdateGlobalParams: unable to decode MempoolPastBlocksPriorityPercentileBasisPoints as uint64", ) } - newGlobalParamsEntry.PastBlocksPriorityPercentileBasisPoints = val + newGlobalParamsEntry.MempoolPastBlocksPriorityPercentileBasisPoints = val } if len(extraData[MaxBlockSizeBytesPoSKey]) > 0 { val, bytesRead := Uvarint( diff --git a/lib/block_view_types.go b/lib/block_view_types.go index 6019bb165..9bc0d5fae 100644 --- a/lib/block_view_types.go +++ b/lib/block_view_types.go @@ -4236,17 +4236,17 @@ type GlobalParamsEntry struct { // the fee for a new txn. MempoolFeeEstimatorNumPastBlocks uint64 - // DefaultMempoolCongestionFactorBasisPoints and DefaultPastBlocksCongestionFactorBasisPoints are the default values - // for GlobalParams.MempoolCongestionFactorBasisPoints and GlobalParams.DefaultPastBlocksCongestionFactorBasisPoints. + // 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 - PastBlocksCongestionFactorBasisPoints uint64 + MempoolCongestionFactorBasisPoints uint64 + MempoolPastBlocksCongestionFactorBasisPoints uint64 - // MempoolPriorityPercentileBasisPoints and PastBlocksPriorityPercentileBasisPoints are the default values - // for GlobalParams.DefaultMempoolPriorityPercentileBasisPoints and GlobalParams.DefaultPastBlocksPriorityPercentileBasisPoints. + // 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 - PastBlocksPriorityPercentileBasisPoints uint64 + MempoolPriorityPercentileBasisPoints uint64 + MempoolPastBlocksPriorityPercentileBasisPoints uint64 // MaxBlockSizeBytesPoS is the maximum size of a block in bytes. MaxBlockSizeBytesPoS uint64 @@ -4288,9 +4288,9 @@ func (gp *GlobalParamsEntry) Copy() *GlobalParamsEntry { MempoolFeeEstimatorNumMempoolBlocks: gp.MempoolFeeEstimatorNumMempoolBlocks, MempoolFeeEstimatorNumPastBlocks: gp.MempoolFeeEstimatorNumPastBlocks, MempoolCongestionFactorBasisPoints: gp.MempoolCongestionFactorBasisPoints, - PastBlocksCongestionFactorBasisPoints: gp.PastBlocksCongestionFactorBasisPoints, + MempoolPastBlocksCongestionFactorBasisPoints: gp.MempoolPastBlocksCongestionFactorBasisPoints, MempoolPriorityPercentileBasisPoints: gp.MempoolPriorityPercentileBasisPoints, - PastBlocksPriorityPercentileBasisPoints: gp.PastBlocksPriorityPercentileBasisPoints, + MempoolPastBlocksPriorityPercentileBasisPoints: gp.MempoolPastBlocksPriorityPercentileBasisPoints, MaxBlockSizeBytesPoS: gp.MaxBlockSizeBytesPoS, SoftMaxBlockSizeBytesPoS: gp.SoftMaxBlockSizeBytesPoS, MaxTxnSizeBytesPoS: gp.MaxTxnSizeBytesPoS, @@ -4326,9 +4326,9 @@ func (gp *GlobalParamsEntry) RawEncodeWithoutMetadata(blockHeight uint64, skipMe data = append(data, UintToBuf(gp.MempoolFeeEstimatorNumMempoolBlocks)...) data = append(data, UintToBuf(gp.MempoolFeeEstimatorNumPastBlocks)...) data = append(data, UintToBuf(gp.MempoolCongestionFactorBasisPoints)...) - data = append(data, UintToBuf(gp.PastBlocksCongestionFactorBasisPoints)...) + data = append(data, UintToBuf(gp.MempoolPastBlocksCongestionFactorBasisPoints)...) data = append(data, UintToBuf(gp.MempoolPriorityPercentileBasisPoints)...) - data = append(data, UintToBuf(gp.PastBlocksPriorityPercentileBasisPoints)...) + data = append(data, UintToBuf(gp.MempoolPastBlocksPriorityPercentileBasisPoints)...) data = append(data, UintToBuf(gp.MaxBlockSizeBytesPoS)...) data = append(data, UintToBuf(gp.SoftMaxBlockSizeBytesPoS)...) data = append(data, UintToBuf(gp.MaxTxnSizeBytesPoS)...) @@ -4430,17 +4430,17 @@ func (gp *GlobalParamsEntry) RawDecodeWithoutMetadata(blockHeight uint64, rr *by if err != nil { return errors.Wrapf(err, "GlobalParamsEntry.Decode: Problem reading MempoolCongestionFactorBasisPoints") } - gp.PastBlocksCongestionFactorBasisPoints, err = ReadUvarint(rr) + gp.MempoolPastBlocksCongestionFactorBasisPoints, err = ReadUvarint(rr) if err != nil { - return errors.Wrapf(err, "GlobalParamsEntry.Decode: Problem reading PastBlocksCongestionFactorBasisPoints") + 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.PastBlocksPriorityPercentileBasisPoints, err = ReadUvarint(rr) + gp.MempoolPastBlocksPriorityPercentileBasisPoints, err = ReadUvarint(rr) if err != nil { - return errors.Wrapf(err, "GlobalParamsEntry.Decode: Problem reading PastBlocksPriorityPercentileBasisPoints") + return errors.Wrapf(err, "GlobalParamsEntry.Decode: Problem reading MempoolPastBlocksPriorityPercentileBasisPoints") } gp.MaxBlockSizeBytesPoS, err = ReadUvarint(rr) if err != nil { diff --git a/lib/constants.go b/lib/constants.go index b2b0681c3..66960a993 100644 --- a/lib/constants.go +++ b/lib/constants.go @@ -1754,9 +1754,9 @@ const ( MempoolFeeEstimatorNumMempoolBlocksKey = "MempoolFeeEstimatorNumMempoolBlocks" MempoolFeeEstimatorNumPastBlocksKey = "MempoolFeeEstimatorNumPastBlocks" MempoolCongestionFactorBasisPointsKey = "MempoolCongestionFactorBasisPoints" - PastBlocksCongestionFactorBasisPointsKey = "PastBlocksCongestionFactorBasisPoints" + MempoolPastBlocksCongestionFactorBasisPointsKey = "MempoolPastBlocksCongestionFactorBasisPoints" MempoolPriorityPercentileBasisPointsKey = "MempoolPriorityPercentileBasisPoints" - PastBlocksPriorityPercentileBasisPointsKey = "PastBlocksPriorityPercentileBasisPoints" + MempoolPastBlocksPriorityPercentileBasisPointsKey = "MempoolPastBlocksPriorityPercentileBasisPoints" MaxBlockSizeBytesPoSKey = "MaxBlockSizeBytesPoS" SoftMaxBlockSizeBytesPoSKey = "SoftMaxBlockSizeBytesPoS" MaxTxnSizeBytesPoSKey = "MaxTxnSizeBytesPoS"