Comments (7)
I hope you don't mind me creating the issue here. I find it is easier to link to bits of code for the context, and this would have been a giant wall of text on #general at slack.
from libbitcoin-database.
Now that I know a bit more about how pop header works, I want to look at this again and see how I could handle this.
Can we leave it open for a few more days. I'll report back here.
from libbitcoin-database.
I believe the presumption is that links always exist and that therefore failure to dereference a link is undefined behavior. This is achieved by never deleting store elements. This is probably why it’s not been clearly dealt with. However given that the performance cost is low we could certainly provide defined behavior here. Returning a not_found element seems appropriate.
Good work.
from libbitcoin-database.
Hi @evoskuil
Thanks for the encouraging words.
I looked at a way to return a not_found element when trying to read past the end of file, but then I came across how slab_manager does it and record_manager used to do it. There's a comment here https://github.com/libbitcoin/libbitcoin-database/blob/master/include/bitcoin/database/impl/record_manager.ipp#L137 which I repeat here:
// If record >= count() then we should still be within the file. The
// condition implies a block has been unconfirmed while reading it.
As I understand, we no longer remove records from record manager. So, will it make sense to bring back this assertion in the form of record_count < link
? The change will resolve the situation that started this issue.
However, looking at the change history I can see there was a commit to take out the call to count()
from within get
to try to reduce the locks taken. Is that still a concern?
I am proposing to change the get method to include an assertion. Otherwise it is a bit twisted for an hash_table using a record_map to know if it is reading past the eof. It is only the record manager that knows the count. Instead we could change record_manager::get to be:
template <typename Link>
memory_ptr record_manager<Link>::get(Link link) const
{
BITCOIN_ASSERT_MSG(link < count(), "Read past end of file.");
// The accessor must remain in scope until the end of the block.
const auto memory = file_.access();
memory->increment(header_size_ + link_to_position(link));
return memory;
}
With the change above, all the tests pass on travis, but I wonder if there is a case that is not handled in the tests yet and requires this assertion to not be there.
To be honest, I am not sure how useful it is to catch the "read beyond end of file" case. So I am quite happy to park this whole issue for now and come back to it, if needed, after looking more at data_base class and blockchain repo.
from libbitcoin-database.
I believe it’s possible for the count to shrink during or as the result of a reorg, in the case where the top height is reduced in either the confirmed or candidate chain. This affects only the height arrays. Otherwise count (logical file size) should never be reduced.
from libbitcoin-database.
Status?
from libbitcoin-database.
Status?
from libbitcoin-database.
Related Issues (20)
- Flush lock slows block out protocol noticeably. HOT 1
- Set file growth rate automatically if configured (default). HOT 1
- array_index is 32 bit, will require expansion. HOT 3
- call end_write before return HOT 1
- History store row allocator requires concurrency guard. HOT 14
- Rename history database to address database. HOT 1
- Hash tables not safe for read while conflict delete.
- Port resolution to issues #150 and #159 to master. HOT 1
- Changes to std::hash template for db keys limits portability. HOT 1
- Primitives require file_offset and array_index type parameterization. HOT 1
- Store tx offset vs. point in address row file. HOT 2
- [master] Header storage exceedingly slow. HOT 2
- Use tx link instead of tx hash for input_point. HOT 2
- Support unconfirmed tx as output spender. HOT 2
- [master] flush_lock must be file-specific for parallel write flushing. HOT 2
- Remove hash from block_database::unindex or check that hash matches HOT 2
- Add configurable operational file size minimums. HOT 1
- [master] Build warnings. HOT 3
- MacOS (all): no template named 'unary_function' in namespace 'std'.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libbitcoin-database.