Skip to content

Commit

Permalink
l2geth: Dedupe dumper addresses in memory (ethereum-optimism#3852)
Browse files Browse the repository at this point in the history
Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
  • Loading branch information
mslipper and mergify[bot] authored Nov 2, 2022
1 parent 05d367e commit 4e65ceb
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .changeset/kind-ravens-shake.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@eth-optimism/l2geth': patch
---

Dedupe dumper addresses in memory
13 changes: 10 additions & 3 deletions l2geth/statedumper/dumper.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,25 @@ func NewStateDumper() StateDumper {
}

return &FileStateDumper{
f: f,
f: f,
ethCache: make(map[common.Address]bool),
}
}

type FileStateDumper struct {
f io.Writer
mtx sync.Mutex
f io.Writer
ethCache map[common.Address]bool
mtx sync.Mutex
}

func (s *FileStateDumper) WriteETH(address common.Address) {
s.mtx.Lock()
defer s.mtx.Unlock()
if s.ethCache[address] {
return
}
s.ethCache[address] = true

if _, err := s.f.Write([]byte(fmt.Sprintf("ETH|%s\n", address.Hex()))); err != nil {
panic(err)
}
Expand Down

0 comments on commit 4e65ceb

Please sign in to comment.