From 5f53f46298b2df3db4fee70d6dc3a325e50210b1 Mon Sep 17 00:00:00 2001 From: Ryan Smith Date: Mon, 6 Nov 2023 20:47:10 -0800 Subject: [PATCH] e2pg: exotic bugfix. dest range filter when stop < start 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: 90334ab557d2c464c2243ac708de1ebdebb4e8ad --- e2pg/e2pg.go | 2 +- e2pg/e2pg_test.go | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/e2pg/e2pg.go b/e2pg/e2pg.go index eb2494f4..45a5c173 100644 --- a/e2pg/e2pg.go +++ b/e2pg/e2pg.go @@ -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 diff --git a/e2pg/e2pg_test.go b/e2pg/e2pg_test.go index 3d92261b..ec61af81 100644 --- a/e2pg/e2pg_test.go +++ b/e2pg/e2pg_test.go @@ -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)