From a43bb0172aef4932272ad1bdf1335f3522467bc2 Mon Sep 17 00:00:00 2001 From: Noel Date: Mon, 23 Oct 2023 10:42:56 +0200 Subject: [PATCH] Bug fix edge case locating entry (#69) --- README.md | 22 ++++++++++++++-------- datastreamer/streamfile.go | 8 +++++++- 2 files changed, 21 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 795efe1..e22e8ca 100644 --- a/README.md +++ b/README.md @@ -138,11 +138,13 @@ Stream relay server included in the datastream library allows scaling the number ## DATASTREAM CLI DEMO APP Build the binary datastream demo app (`dsdemo`): ``` -$ make build +make build ``` Run the app without parameters to see the available commands: ``` -$ ./dsdemo +./dsdemo +``` +``` NAME: dsdemo - Run a datastream server/client/relay demo cli app @@ -161,7 +163,9 @@ GLOBAL OPTIONS: ### SERVER Use the help option to check available parameters for the server command: ``` -$ ./dsdemo help server +./dsdemo help server +``` +``` NAME: dsdemo server - Run datastream server @@ -178,16 +182,18 @@ OPTIONS: ``` Run a datastream server with default parameters (port: `6900`, file: `datastream.bin`, log: `info`): ``` -$ ./dsdemo server +./dsdemo server ``` Or run a datastream server with custom parameters: ``` -$ ./dsdemo server --port 6969 --file seqstream.bin --log warn +./dsdemo server --port 6969 --file seqstream.bin --log warn ``` ### CLIENT Use the help option to check available parameters for the client command: ``` -$ ./dsdemo help client +./dsdemo help client +``` +``` NAME: dsdemo client - Run datastream client @@ -203,11 +209,11 @@ OPTIONS: ``` Run a datastream client with default parameters (server: `127.0.0.1:6900`, from: `latest`, log: `info`) ``` -$ ./dsdemo client +./dsdemo client ``` Or run a datastream client with custom parameters: ``` -$ ./dsdemo client --server 127.0.0.1:6969 --from 0 --log debug +./dsdemo client --server 127.0.0.1:6969 --from 0 --log debug ``` ## USE CASE: zkEVM SEQUENCER ENTRIES diff --git a/datastreamer/streamfile.go b/datastreamer/streamfile.go index b20755d..5abc73e 100644 --- a/datastreamer/streamfile.go +++ b/datastreamer/streamfile.go @@ -856,7 +856,13 @@ func (f *StreamFile) getFirstEntryOnNextPage(iterator *iteratorFile) (uint64, er } // Check if exists another data page - forward := pageDataSize - (curpos-pageHeaderSize)%pageDataSize + var forward int64 + if (curpos-pageHeaderSize)%pageDataSize == 0 { + forward = 0 + } else { + forward = pageDataSize - (curpos-pageHeaderSize)%pageDataSize + } + if curpos+forward >= int64(f.writtenHead.TotalLength) { return math.MaxUint64, nil }