remove setWriter function and add writer in load function

This commit is contained in:
Kyrin 2025-10-16 23:25:56 +08:00 committed by GitHub
parent fe6d9e1018
commit 0a8a981a58
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -71,7 +71,6 @@ 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 }()
// 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)
@ -114,17 +113,6 @@ func (journal *journal) load(add func([]*types.Transaction) []error) error {
} }
log.Info("Loaded local transaction journal", "transactions", total, "dropped", dropped) log.Info("Loaded local transaction journal", "transactions", total, "dropped", dropped)
return failure
}
// setWriter opens the journal file for writing new transactions.
func (journal *journal) setWriter() error {
// Close the current writer if any
if journal.writer != nil {
journal.writer.Close()
journal.writer = nil
}
// Open the journal file for appending // Open the journal file for appending
// Use O_APPEND to ensure we always write to the end of the file // Use O_APPEND to ensure we always write to the end of the file
sink, err := os.OpenFile(journal.path, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644) sink, err := os.OpenFile(journal.path, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0644)
@ -132,7 +120,8 @@ func (journal *journal) setWriter() error {
return err return err
} }
journal.writer = sink journal.writer = sink
return nil
return failure
} }
// insert adds the specified transaction to the local disk journal. // insert adds the specified transaction to the local disk journal.