Skip to content

Commit

Permalink
core: avoid warning when loading the transaction journal
Browse files Browse the repository at this point in the history
  • Loading branch information
karalabe committed Oct 20, 2017
1 parent 65738c1 commit 0af1ab0
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions core/tx_journal.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ import (
// into the journal, but no such file is currently open.
var errNoActiveJournal = errors.New("no active journal")

// devNull is a WriteCloser that just discards anything written into it. Its
// goal is to allow the transaction journal to write into a fake journal when
// loading transactions on startup without printing warnings due to no file
// being readt for write.
type devNull struct{}

func (*devNull) Write(p []byte) (n int, err error) { return len(p), nil }
func (*devNull) Close() error { return nil }

// txJournal is a rotating log of transactions with the aim of storing locally
// created transactions to allow non-executed ones to survive node restarts.
type txJournal struct {
Expand Down Expand Up @@ -59,6 +68,10 @@ func (journal *txJournal) load(add func(*types.Transaction) error) error {
}
defer input.Close()

// Temporarilly discard any journal additions (don't double add on load)
journal.writer = new(devNull)
defer func() { journal.writer = nil }()

// Inject all transactions from the journal into the pool
stream := rlp.NewStream(input, 0)
total, dropped := 0, 0
Expand Down

0 comments on commit 0af1ab0

Please sign in to comment.