Skip to content

Commit

Permalink
e2pg: exotic bugfix. dest range filter when stop < start
Browse files Browse the repository at this point in the history
The prior code assumed that if r.stop was 0 then destRange is
effectively uninitialized and therefore no filtering should be done.
However, it is possible for the stop value to be zero [1] and thus a
more thorough uninitialized check should be preformed.

[1]: See commit: 90334ab
  • Loading branch information
ryandotsmith committed Nov 7, 2023
1 parent 90334ab commit 5f53f46
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion e2pg/e2pg.go
Original file line number Diff line number Diff line change
Expand Up @@ -588,7 +588,7 @@ func (r *destRange) load(ctx context.Context, pg wpg.Conn, name, srcName string)

func (r *destRange) filter(blks []eth.Block) []eth.Block {
switch {
case r.stop == 0:
case r.start == 0 && r.stop == 0:
return blks
case len(blks) == 0:
return blks
Expand Down
6 changes: 6 additions & 0 deletions e2pg/e2pg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,12 @@ func TestDestRanges_Filter(t *testing.T) {
r: destRange{start: 15, stop: 10},
want: []eth.Block(nil),
},
{
desc: "[0, 10] -> [5, 0]",
input: br(0, 10),
r: destRange{start: 5, stop: 0},
want: []eth.Block(nil),
},
}
for _, tc := range cases {
got := tc.r.filter(tc.input)
Expand Down

0 comments on commit 5f53f46

Please sign in to comment.