feat(BB): Better proposal, better docs, better logging, papa johns (#172)
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
sdkmempool "github.com/cosmos/cosmos-sdk/types/mempool"
|
||||
"github.com/skip-mev/pob/blockbuster"
|
||||
)
|
||||
|
||||
// GetTxHashStr returns the hex-encoded hash of the transaction alongside the
|
||||
@@ -52,13 +51,13 @@ func RemoveTxsFromLane(txs map[sdk.Tx]struct{}, mempool sdkmempool.Mempool) erro
|
||||
|
||||
// GetMaxTxBytesForLane returns the maximum number of bytes that can be included in the proposal
|
||||
// for the given lane.
|
||||
func GetMaxTxBytesForLane(proposal *blockbuster.Proposal, ratio sdk.Dec) int64 {
|
||||
func GetMaxTxBytesForLane(maxTxBytes, totalTxBytes int64, ratio sdk.Dec) int64 {
|
||||
// In the case where the ratio is zero, we return the max tx bytes remaining. Note, the only
|
||||
// lane that should have a ratio of zero is the default lane. This means the default lane
|
||||
// will have no limit on the number of transactions it can include in a block and is only
|
||||
// limited by the maxTxBytes included in the PrepareProposalRequest.
|
||||
if ratio.IsZero() {
|
||||
remainder := proposal.MaxTxBytes - proposal.TotalTxBytes
|
||||
remainder := maxTxBytes - totalTxBytes
|
||||
if remainder < 0 {
|
||||
return 0
|
||||
}
|
||||
@@ -67,5 +66,5 @@ func GetMaxTxBytesForLane(proposal *blockbuster.Proposal, ratio sdk.Dec) int64 {
|
||||
}
|
||||
|
||||
// Otherwise, we calculate the max tx bytes for the lane based on the ratio.
|
||||
return ratio.MulInt64(proposal.MaxTxBytes).TruncateInt().Int64()
|
||||
return ratio.MulInt64(maxTxBytes).TruncateInt().Int64()
|
||||
}
|
||||
|
||||
@@ -1,79 +1,66 @@
|
||||
package utils
|
||||
package utils_test
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
sdk "github.com/cosmos/cosmos-sdk/types"
|
||||
"github.com/skip-mev/pob/blockbuster"
|
||||
"github.com/skip-mev/pob/blockbuster/utils"
|
||||
)
|
||||
|
||||
func TestGetMaxTxBytesForLane(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
proposal *blockbuster.Proposal
|
||||
ratio sdk.Dec
|
||||
expected int64
|
||||
name string
|
||||
maxTxBytes int64
|
||||
totalTxBytes int64
|
||||
ratio sdk.Dec
|
||||
expected int64
|
||||
}{
|
||||
{
|
||||
"ratio is zero",
|
||||
&blockbuster.Proposal{
|
||||
MaxTxBytes: 100,
|
||||
TotalTxBytes: 50,
|
||||
},
|
||||
100,
|
||||
50,
|
||||
sdk.ZeroDec(),
|
||||
50,
|
||||
},
|
||||
{
|
||||
"ratio is zero",
|
||||
&blockbuster.Proposal{
|
||||
MaxTxBytes: 100,
|
||||
TotalTxBytes: 100,
|
||||
},
|
||||
100,
|
||||
100,
|
||||
sdk.ZeroDec(),
|
||||
0,
|
||||
},
|
||||
{
|
||||
"ratio is zero",
|
||||
&blockbuster.Proposal{
|
||||
MaxTxBytes: 100,
|
||||
TotalTxBytes: 150,
|
||||
},
|
||||
100,
|
||||
150,
|
||||
sdk.ZeroDec(),
|
||||
0,
|
||||
},
|
||||
{
|
||||
"ratio is 1",
|
||||
&blockbuster.Proposal{
|
||||
MaxTxBytes: 100,
|
||||
TotalTxBytes: 50,
|
||||
},
|
||||
100,
|
||||
50,
|
||||
sdk.OneDec(),
|
||||
100,
|
||||
},
|
||||
{
|
||||
"ratio is 10%",
|
||||
&blockbuster.Proposal{
|
||||
MaxTxBytes: 100,
|
||||
TotalTxBytes: 50,
|
||||
},
|
||||
100,
|
||||
50,
|
||||
sdk.MustNewDecFromStr("0.1"),
|
||||
10,
|
||||
},
|
||||
{
|
||||
"ratio is 25%",
|
||||
&blockbuster.Proposal{
|
||||
MaxTxBytes: 100,
|
||||
TotalTxBytes: 50,
|
||||
},
|
||||
100,
|
||||
50,
|
||||
sdk.MustNewDecFromStr("0.25"),
|
||||
25,
|
||||
},
|
||||
{
|
||||
"ratio is 50%",
|
||||
&blockbuster.Proposal{
|
||||
MaxTxBytes: 101,
|
||||
TotalTxBytes: 50,
|
||||
},
|
||||
101,
|
||||
50,
|
||||
sdk.MustNewDecFromStr("0.5"),
|
||||
50,
|
||||
},
|
||||
@@ -81,7 +68,7 @@ func TestGetMaxTxBytesForLane(t *testing.T) {
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
actual := GetMaxTxBytesForLane(tc.proposal, tc.ratio)
|
||||
actual := utils.GetMaxTxBytesForLane(tc.maxTxBytes, tc.totalTxBytes, tc.ratio)
|
||||
if actual != tc.expected {
|
||||
t.Errorf("expected %d, got %d", tc.expected, actual)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user