Fix writer restoration in journal loading

Restore original writer after loading transactions from journal.
This commit is contained in:
Kyrin 2025-10-16 15:04:23 +08:00 committed by GitHub
parent 24338b8817
commit d4dece7f86
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -58,6 +58,8 @@ func newTxJournal(path string) *journal {
// load parses a transaction journal dump from disk, loading its contents into // load parses a transaction journal dump from disk, loading its contents into
// the specified pool. // the specified pool.
func (journal *journal) load(add func([]*types.Transaction) []error) error { func (journal *journal) load(add func([]*types.Transaction) []error) error {
originalWriter := journal.writer
// Open the journal for loading any past transactions // Open the journal for loading any past transactions
input, err := os.Open(journal.path) input, err := os.Open(journal.path)
if errors.Is(err, fs.ErrNotExist) { if errors.Is(err, fs.ErrNotExist) {
@ -71,7 +73,7 @@ func (journal *journal) load(add func([]*types.Transaction) []error) error {
// Temporarily discard any journal additions (don't double add on load) // Temporarily discard any journal additions (don't double add on load)
journal.writer = new(devNull) journal.writer = new(devNull)
defer func() { journal.writer = nil }() defer func() { journal.writer = originalWriter }()
// Inject all transactions from the journal into the pool // Inject all transactions from the journal into the pool
stream := rlp.NewStream(input, 0) stream := rlp.NewStream(input, 0)