Coder Social home page Coder Social logo

Comments (10)

vpulim avatar vpulim commented on June 13, 2024 1

@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.

vpulim avatar vpulim commented on June 13, 2024

@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.

holgerd77 avatar holgerd77 commented on June 13, 2024

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.

vpulim avatar vpulim commented on June 13, 2024

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.

holgerd77 avatar holgerd77 commented on June 13, 2024

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.

holgerd77 avatar holgerd77 commented on June 13, 2024

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.

vpulim avatar vpulim commented on June 13, 2024

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.

vpulim avatar vpulim commented on June 13, 2024

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.

holgerd77 avatar holgerd77 commented on June 13, 2024

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.

vpulim avatar vpulim commented on June 13, 2024

Created a PR to address the issues discussed above: #52

from ethereumjs-blockchain.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.