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

Ensure Blocks Don't Overpack With Txs #1790

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions chain/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"go.opentelemetry.io/otel/attribute"
"go.uber.org/zap"

"github.com/ava-labs/hypersdk/consts"
"github.com/ava-labs/hypersdk/internal/executor"
"github.com/ava-labs/hypersdk/internal/fees"
"github.com/ava-labs/hypersdk/keys"
Expand Down Expand Up @@ -181,8 +182,15 @@ func (c *Builder) BuildBlock(ctx context.Context, parentView state.View, parent
e := executor.New(streamBatch, c.config.TransactionExecutionCores, MaxKeyDependencies, c.metrics.executorBuildRecorder)
pending := make(map[ids.ID]*Transaction, streamBatch)
var pendingLock sync.Mutex
totalTxSize := 0
for li, ltx := range txs {
txsAttempted++
if totalTxSize += ltx.Size(); totalTxSize > consts.MaxTotalTxSizePerBlock {
c.log.Debug("Transactions in block exceeded allotted limit ", zap.Int("size", ltx.Size()))
restorable = append(restorable, txs[li:]...)
break
}

i := li
tx := ltx

Expand Down
2 changes: 2 additions & 0 deletions consts/consts.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ const (
// 2 MiB - ProposerVM header - Protobuf encoding overhead (we assume this is
// no more than 50 KiB of overhead but is likely much less)
NetworkSizeLimit = 2_044_723 // 1.95 MiB
// We leave room for other block data to be included alongside the transactions
MaxTotalTxSizePerBlock = 1_572_864 // 1.5 MiB

// FIXME: should use the standard math.MaxUint8, etc.
MaxUint8 = ^uint8(0)
Expand Down
Loading