Skip to content

Conversation

@mattac21
Copy link
Contributor

@mattac21 mattac21 commented Jan 10, 2026

Description

Kicks off proposal creation immediately after commit, so that hopefully when we go to propose, a proposal has already been created and we can return instantly.

This is having some (likely) locking issues where the prepare_proposal abci time is low, but from CometBFT's point of view, it is taking > the Commit step's duration. Same with process proposal, which typically is around 50ms for a 50mil max gas block, but here it is around 200ms for some unknown reason.
Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • tackled an existing issue or discussed with a team member
  • left instructions on how to review the changes
  • targeted the main branch

latestProposal: &abci.ResponsePrepareProposal{},
done: make(chan struct{}),
}
go pb.loop()

Check notice

Code scanning / CodeQL

Spawning a Go routine Note

Spawning a Go routine may be a possible source of non-determinism
@mattac21 mattac21 force-pushed the ma/proposal-builder branch from 551c3ee to 928c11c Compare January 11, 2026 05:39
Comment on lines 190 to 238
go func() {
start := time.Now()
defer func() { telemetry.MeasureSince(start, proposalCreationDurationKey) }()

// We create a per goroutine instance of the ProposalHandler
// since it the internal txSelector is not thread safe.
abciProposalHandler := baseapp.NewDefaultProposalHandler(pb.evmMempool, pb.txVerifier)
abciProposalHandler.SetSignerExtractionAdapter(
NewEthSignerExtractionAdapter(
sdkmempool.NewDefaultSignerExtractionAdapter(),
),
)
abciProposalHandler.SetTxSelector(NewNoCopyProposalTxSelector())

// TODO: there is an issue that must be solved here.
// CometBFT typically supplies this value in the
// PrepareProposalRequest, it uses the MaxBlockBytes as
// used here, and then subtracts away the space that it
// knows will be used for storing encoding info, header
// info, validator commits, and evidence. We do not have
// access to that info at this point.
//
// One possible solution would be to introduce a new ABCI
// method for CometBFT to inform the application of the
// smaller MaxTxBytes immediately after Commit is
// processed, which is when we need to start building
// proposals.
const blockOverheadBytes = 2000 // 2000 will suffice for comets overhead assuming 5 vals and no evidence
maxTxBytes := pb.app.GetConsensusParams(proposalContext).Block.MaxBytes - blockOverheadBytes

req := &abci.RequestPrepareProposal{
MaxTxBytes: maxTxBytes,
Height: proposalContext.BlockHeight(),
}

// TODO: there is a lot of state setup done in baseapp that happens
// before the PrepareProposalHandler is called. I don't think this
// is actually required here, but this should be investigated more.
resp, err := abciProposalHandler.PrepareProposalHandler()(proposalContext, req)
if err != nil {
pb.logger.Error("failed to prepare proposal", "height", req.Height, "err", err)
resp = &abci.ResponsePrepareProposal{}
}
pb.setLatestProposal(proposalContext.BlockHeight(), time.Since(start), resp)
pb.logger.Debug("created a new proposal", "for_height", proposalContext.BlockHeight())

inflightProposals--
telemetry.SetGauge(float32(inflightProposals), inflightProposalsKey)
}()

Check notice

Code scanning / CodeQL

Spawning a Go routine Note

Spawning a Go routine may be a possible source of non-determinism
telemetry.SetGauge(float32(inflightProposals), inflightProposalsKey)

go func() {
start := time.Now()

Check warning

Code scanning / CodeQL

Calling the system time Warning

Calling the system time may be a possible source of non-determinism
@mattac21 mattac21 force-pushed the ma/proposal-builder branch from 3605d35 to f0a0784 Compare January 12, 2026 15:16
}

func (pb *ProposalBuilder) waitForProposalCreation() {
defer func(t0 time.Time) { telemetry.MeasureSince(t0, prepareProposalWaitDuration) }(time.Now())

Check warning

Code scanning / CodeQL

Calling the system time Warning

Calling the system time may be a possible source of non-determinism
@mattac21 mattac21 changed the title feat(mempool): Proposal Builder feat(mempool): Optimistic Proposals Jan 15, 2026
@mattac21 mattac21 force-pushed the ma/proposal-builder branch from 4f5580e to 31a1834 Compare January 15, 2026 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants