Comments (10)
@holgerd77 Now, THAT is a bug! Good catch. It turns out I wasn't saving headHeader/headBlock updates to the db after calls to putBlock(). This will explain why _headHeader is always the genesis hash in the _initLock.await() call. I'll submit a new PR today to fix this with some additional test cases.
NOTE: this will still not affect the return value from getHead(), which still uses the "vm" head value that will always remain at genesisHead until iterator() is called.
from ethereumjs-blockchain.
@holgerd77 The way this module worked before 3.0.0 was that getHead() returned the “vm” head by default. This “vm” head is only updated when the iterator() function is called. putBlock() updates the headHeader, which is different from the “vm” head. Although I prefer that getHead() return the headHeader or blockHeader by default, I kept it this way to make sure I didn’t break existing code in other modules.
So this isn’t a bug and is working as expected. You can test this by trying your test code against a pre-3.0.0 version of the module.
from ethereumjs-blockchain.
Hmm, irritating.
So how do I get the current head block atm? Even...
blockchain._initLock.await(function () {
console.log(blockchain._headHeader)
})
returns the same genesis hash on both times.
from ethereumjs-blockchain.
Since we are introducing new functionality, should we add two new functions to access the heads of the current headerchain and blockchain?
Maybe getHeadHeader()
and getHeadBlock()
?
In geth, these represent and heads of the latest light sync and latest full sync.
from ethereumjs-blockchain.
I have to admit that haven't really gotten this concept of this 'vm' heads naming. Is this by definition always the canonical chain?
from ethereumjs-blockchain.
Then we should really consider to change this "only on iterator
call update" semantics. I can't imagine that people rely on this behavior since it doesn't really make that much sense (or does it and I am not seeing the point?), so I think we wouldn't that much risk of breaking something.
Otherwise if we have that old getHead
functionality and the new two functions named as proposed this would be confusing if things behave so differently. Generally I would be very much in favor to add something like that.
If 'vm' == 'canonical' (javascript equal operator semantics, hehe), then we might also just rename this to 'canonical', 'vm' seems to not make that much sense here (and is probably also not really in use in the new version since we just released v3.0.0).
from ethereumjs-blockchain.
i think it's more accurate to think of a "head" as a cursor along the canonical chain.
geth only tracks three heads: the headerchain head (used for light syncs), blockchain head (used for full syncs), and a fast sync head (used to track the latest synced block during fast syncs).
However, the original ethereumjs-blockchain implementaion allowed for the tracking of an unlimited number of heads, each assigned its own name ("vm" is the default name). This functionality is used by ethereumjs-vm to track where it is in the canonical chain during calls to iterator(). Since each time a new VM iterates through the chain, it starts from the genesis block. That's why we maintain a separate field called _headHeader and _headBlock so that they aren't overwritten as VMs iterate through the chain from the beginning.
from ethereumjs-blockchain.
I agree. This is VERY confusing!
It would be nice to just have the VM maintain its own cursor internally, instead of having the blockchain maintain it. This way, getHead() can be modified to return the actual _headHeader (or _headBlock... whichever makes more sense)
from ethereumjs-blockchain.
Ok, thanks for the explanation, didn't have the whole picture on that. Then maybe let's do a you proposed with the two new functions and otherwise keep the current functionality until the next breaking release. We can/should additionally make this clear in the (API) docs.
from ethereumjs-blockchain.
Created a PR to address the issues discussed above: #52
from ethereumjs-blockchain.
Related Issues (20)
- Use tsdoc tags for Blockchain constructor's params
- Add an example of how to use this library in the README HOT 1
- Update default/latest HF to Petersburg HOT 1
- This library doesn't run in the browser HOT 3
- BlockchainOptions#validate is too coarse HOT 5
- Modernizing this library's tests HOT 2
- Make sure test fixture is not outdated HOT 2
- Migrate ethereumjs-blockchain from Travis to Github Actions
- Coverage report ceased to work HOT 3
- blockchain.putGenesis seems not work HOT 1
- An in-range update of ethereumjs-util is breaking the build 🚨 HOT 2
- How to use Nodejs/Javascript and LevelUp to read Blocks from local geth database files (.ldb)? HOT 2
- Move wiki content to the README
- Support for setting network (genesis) and allowing hardfork-specific validation HOT 1
- An in-range update of tape is breaking the build 🚨 HOT 3
- Example running existing geth data HOT 1
- Support Question, headline replaced by admin
- NPM package doesn't contain the code for 3.3.1 HOT 2
- Auto-generated documentation with TSDocs HOT 3
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 ethereumjs-blockchain.