@gadcl your solution involves an extra read of a full block whenever the blocks don't appear in order in the file.
This can be easily avoided - consider fetchBlockFromFile(height primitives.BlockHeight, file *os.File, currentOffset int) (*protocol.BlockPairContainer, int, error)
notice in inbound and outbound currentOffset arguments. fetchBlockFromFile() can check the index of the requested block in memory, then compare it to the inbound currentOffset, if they are different you seek. otherwise just read.
Before returning fetchBlockFromFile() will add the bytes read (returned from decode) to the effective offset (the real offset where the requested block began) and return the sum which should always be the current cursor offset.
@gadcl your solution involves an extra read of a full block whenever the blocks don't appear in order in the file.
This can be easily avoided - consider
fetchBlockFromFile(height primitives.BlockHeight, file *os.File, currentOffset int) (*protocol.BlockPairContainer, int, error)
notice in inbound and outbound
currentOffset
arguments.fetchBlockFromFile()
can check the index of the requested block in memory, then compare it to the inboundcurrentOffset
, if they are different you seek. otherwise just read. Before returningfetchBlockFromFile()
will add the bytes read (returned fromdecode
) to the effective offset (the real offset where the requested block began) and return the sum which should always be the current cursor offset.What do you think?