Skip to content
Draft
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
45 changes: 28 additions & 17 deletions app/filtered_square_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,22 @@ func (fsb *FilteredSquareBuilder) Builder() *square.Builder {
return fsb.builder
}

func (fsb *FilteredSquareBuilder) Fill(ctx sdk.Context, txs [][]byte) [][]byte {
func (fsb *FilteredSquareBuilder) Fill(ctx sdk.Context, txs [][]byte, maxTxBytes int64) [][]byte {
logger := ctx.Logger().With("app/filtered-square-builder")

// note that there is an additional filter step for tx size of raw txs here
normalTxs, blobTxs := separateTxs(fsb.txConfig, txs)

var (
nonPFBMessageCount = 0
pfbMessageCount = 0
dec = fsb.txConfig.TxDecoder()
n = 0
m = 0
)
nonPFBMessageCount := 0
pfbMessageCount := 0
normalTxCount := 0
blobTxCount := 0
currentTxBytes := int64(0)

decoder := fsb.txConfig.TxDecoder()

for _, tx := range normalTxs {
sdkTx, err := dec(tx)
sdkTx, err := decoder(tx)
if err != nil {
logger.Error("decoding already checked transaction", "tx", tmbytes.HexBytes(coretypes.Tx(tx).Hash()), "error", err)
continue
Expand All @@ -79,6 +79,11 @@ func (fsb *FilteredSquareBuilder) Fill(ctx sdk.Context, txs [][]byte) [][]byte {
continue
}

if currentTxBytes+int64(len(tx)) > maxTxBytes {
logger.Debug("skipping tx because it was too large to fit in the block", "tx", tmbytes.HexBytes(coretypes.Tx(tx).Hash()))
continue
}

ctx, err = fsb.handler(ctx, sdkTx, false)
// either the transaction is invalid (ie incorrect nonce) and we
// simply want to remove this tx, or we're catching a panic from one
Expand All @@ -99,12 +104,13 @@ func (fsb *FilteredSquareBuilder) Fill(ctx sdk.Context, txs [][]byte) [][]byte {
}

nonPFBMessageCount += len(sdkTx.GetMsgs())
normalTxs[n] = tx
n++
normalTxs[normalTxCount] = tx
normalTxCount++
currentTxBytes += int64(len(tx))
}

for _, tx := range blobTxs {
sdkTx, err := dec(tx.Tx)
sdkTx, err := decoder(tx.Tx)
if err != nil {
logger.Error("decoding already checked blob transaction", "tx", tmbytes.HexBytes(coretypes.Tx(tx.Tx).Hash()), "error", err)
continue
Expand All @@ -122,6 +128,10 @@ func (fsb *FilteredSquareBuilder) Fill(ctx sdk.Context, txs [][]byte) [][]byte {
logger.Debug("skipping tx because it was too large to fit in the square", "tx", tmbytes.HexBytes(coretypes.Tx(tx.Tx).Hash()))
continue
}
if currentTxBytes+int64(len(tx.Tx)) > maxTxBytes {
logger.Debug("skipping tx because it was too large to fit in the block", "tx", tmbytes.HexBytes(coretypes.Tx(tx.Tx).Hash()))
continue
}

ctx, err = fsb.handler(ctx, sdkTx, false)
// either the transaction is invalid (ie incorrect nonce) and we
Expand All @@ -140,13 +150,14 @@ func (fsb *FilteredSquareBuilder) Fill(ctx sdk.Context, txs [][]byte) [][]byte {
}

pfbMessageCount += len(sdkTx.GetMsgs())
blobTxs[m] = tx
m++
blobTxs[blobTxCount] = tx
blobTxCount++
currentTxBytes += int64(len(tx.Tx))
}

kept := make([][]byte, 0, m+n)
kept = append(kept, normalTxs[:n]...)
kept = append(kept, encodeBlobTxs(blobTxs[:m])...)
kept := make([][]byte, 0, blobTxCount+normalTxCount)
kept = append(kept, normalTxs[:normalTxCount]...)
kept = append(kept, encodeBlobTxs(blobTxs[:blobTxCount])...)
return kept
}

Expand Down
2 changes: 1 addition & 1 deletion app/prepare_proposal.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func (app *App) PrepareProposalHandler(ctx sdk.Context, req *abci.RequestPrepare
return nil, fmt.Errorf("failed to create FilteredSquareBuilder: %w", err)
}

txs := fsb.Fill(ctx, req.Txs)
txs := fsb.Fill(ctx, req.Txs, req.MaxTxBytes)

// Build the square from the set of valid and prioritised transactions.
dataSquare, err := fsb.Build()
Expand Down
2 changes: 1 addition & 1 deletion test/util/malicious/out_of_order_prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (a *App) OutOfOrderPrepareProposal(req *abci.RequestPrepareProposal) (*abci
panic(err)
}

txs := fsb.Fill(sdkCtx, req.Txs)
txs := fsb.Fill(sdkCtx, req.Txs, req.MaxTxBytes)

// build the square from the set of valid and prioritised transactions.
// The txs returned are the ones used in the square and block
Expand Down
Loading