Skip to content

Do not include other transactions from mempool on hVM state transition #38

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

Merged
merged 1 commit into from
May 13, 2025
Merged
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
39 changes: 21 additions & 18 deletions miner/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,25 +155,8 @@ func (miner *Miner) generateWork(params *generateParams, witness bool) *newPaylo
return &newPayloadResult{err: fmt.Errorf("failed to force-include tx: %s type: %d sender: %s nonce: %d, err: %w", tx.Hash(), tx.Type(), from, tx.Nonce(), err)}
}
}
if !params.noTxs {
// use shared interrupt if present
interrupt := params.interrupt
if interrupt == nil {
interrupt = new(atomic.Int32)
}
timer := time.AfterFunc(max(minRecommitInterruptInterval, miner.config.Recommit), func() {
interrupt.Store(commitInterruptTimeout)
})

err := miner.fillTransactions(interrupt, work)
timer.Stop() // don't need timeout interruption any more
if errors.Is(err, errBlockInterruptedByTimeout) {
log.Warn("Block building is interrupted", "allowance", common.PrettyDuration(miner.config.Recommit))
} else if errors.Is(err, errBlockInterruptedByResolve) {
log.Info("Block building got interrupted by payload resolution")
}
}

containsBtcAttrDepTx := false
if !params.noTxs {
// First, check whether a new Bitcoin Attributes Deposited tx should be included.
// This is a redundant check since GetBitcoinAttributesForNextBlock will return nil with no error if hVM is not enabled/activated.
Expand All @@ -191,6 +174,7 @@ func (miner *Miner) generateWork(params *generateParams, witness bool) *newPaylo
return &newPayloadResult{err: fmt.Errorf("failed to force-include Bitcoin Attributes Deposited tx: %s type: %d sender: %s nonce: %d, err: %w", cast.Hash(), cast.Type(), from, cast.Nonce(), err)}
}
work.tcount++
containsBtcAttrDepTx = true
}
} else {
log.Info("worker not generating a Bitcoin Attributes Deposited transaction")
Expand All @@ -208,6 +192,25 @@ func (miner *Miner) generateWork(params *generateParams, witness bool) *newPaylo
}
}

if !params.noTxs && !containsBtcAttrDepTx {
// use shared interrupt if present
interrupt := params.interrupt
if interrupt == nil {
interrupt = new(atomic.Int32)
}
timer := time.AfterFunc(max(minRecommitInterruptInterval, miner.config.Recommit), func() {
interrupt.Store(commitInterruptTimeout)
})

err := miner.fillTransactions(interrupt, work)
timer.Stop() // don't need timeout interruption any more
if errors.Is(err, errBlockInterruptedByTimeout) {
log.Warn("Block building is interrupted", "allowance", common.PrettyDuration(miner.config.Recommit))
} else if errors.Is(err, errBlockInterruptedByResolve) {
log.Info("Block building got interrupted by payload resolution")
}
}

if intr := params.interrupt; intr != nil && params.isUpdate && intr.Load() != commitInterruptNone {
return &newPayloadResult{err: errInterruptedUpdate}
}
Expand Down