mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-23 13:16:42 +00:00
core/txpool/locals: fix the writer setup
This commit is contained in:
parent
0a8a981a58
commit
dba43fcdd2
2 changed files with 23 additions and 2 deletions
|
|
@ -112,8 +112,18 @@ 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
|
||||||
|
}
|
||||||
|
|
||||||
// Open the journal file for appending
|
func (journal *journal) setupWriter() error {
|
||||||
|
if journal.writer != nil {
|
||||||
|
if err := journal.writer.Close(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
journal.writer = nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Re-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)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -121,7 +131,7 @@ func (journal *journal) load(add func([]*types.Transaction) []error) error {
|
||||||
}
|
}
|
||||||
journal.writer = sink
|
journal.writer = sink
|
||||||
|
|
||||||
return failure
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// insert adds the specified transaction to the local disk journal.
|
// insert adds the specified transaction to the local disk journal.
|
||||||
|
|
|
||||||
|
|
@ -185,6 +185,17 @@ func (tracker *TxTracker) loop() {
|
||||||
tracker.TrackAll(transactions)
|
tracker.TrackAll(transactions)
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// Setup the writer for the upcoming transactions. Lock to prevent
|
||||||
|
// journal.setupWriter <-> journal.insert (via TrackAll) conflicts.
|
||||||
|
tracker.mu.Lock()
|
||||||
|
if err := tracker.journal.setupWriter(); err != nil {
|
||||||
|
log.Error("Failed to setup the journal writer", "err", err)
|
||||||
|
tracker.mu.Unlock()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
tracker.mu.Unlock()
|
||||||
|
|
||||||
defer tracker.journal.close()
|
defer tracker.journal.close()
|
||||||
}
|
}
|
||||||
var (
|
var (
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue