-
Notifications
You must be signed in to change notification settings - Fork 758
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Define a Blockchain interface #566
Conversation
Some general questions:
|
Yes, that could be passed. The problem with this approach is that it's not clear what to override. The only safe way is to override everything, which is not ideal. Using a class as an interface is also possible in TS. You could do
You don't need that, as TS has structural typing, like Go. But it's safer to do it, as the compiler can ensure your implementation matches the interface.
That's true, so I guess it should be placed in
I'm not sure about this, as not long ago the default implementation was |
Yes, I would also very much say that this should be defined in |
I would generally have a tendency to move further bigger additions to the VM like this one (depending on how it will be finally implemented) to be targeted for a For a second beta I am currently not sure if we should rather wait for the block TS transition - seems not too far away that this will be merged - and include that as well, if you think otherwise please ping me. |
I completely agree. This doesn't need to be included in v4, especially if we define the interface in
I think it |
@s1na is the patricia tree TS update something we also want to take into the first v4 release (this would very much complete everything) or is this too early and should we give this a bit more time and also release with v4.1? |
Well, it would be nice if that were included, because currently the whole Generally one thing we can do to make decisions about versions easier is to try and have somewhat regular releases. Whatever makes it by the deadline goes into the release, everything else remains for the next one. Kinda like how the hardforks are being planned now. Not sure what you think of that @holgerd77? |
@s1na feel that it's too static and partially too much of a burden, since we are just a handful of people and often concentrate over some time on just 2-3 libraries for concurrent work. I would rather stick to the current concept. It's currently on the VM a bit lofty during this beta releases period, but otherwise it works reasonably well I would say. |
Totally! This was one of my main takeaways while integrating Block v3.0.0 as well. I like the idea of making the in-memory/mock version the default and users define alternative implementations. One practical implication of having it defined at |
A |
As I commented multiple times before, I'm working on an EIP1193-compatible provider backed by
ethereumjs-vm
for Buidler.When testing it against real-world smart contract test suites, I profiled it and discovered that
ethereumjs-blockchain
was taking ~30% of the time, making my provider waaaay slower than running the tests against Ganache. I starting investigating and discovered that Ganache doesn't useethereumjs-blockchain
. This led me to think that it was too slow for that task.I eventually discovered that
ethereumjs-blockchain
is not that slow. It still serializes and deserializes blocks much more times than needed for my use-case, but the root of the problem was that I had anO(n)
algorithm in my code that was callinggetBlock
lots and lots of times 😓Despite fixing my issue, I kept thinking about this, and I'm now convinced that neither this library nor
ethereumjs-block
should useethereumjs-blockchain
directly, but should let the user choose their blockchain implementation. This is complicated now, as theBlockchain
type is used in multiple places. This can still be done by hacking the type system with anany
or extendingethereumjs-blockchain
, but that's far from ideal.This PR creates a
Blockchain
interface that includes just the necessary functions for this library andethereumjs-block
to work.It also defines a
MockBlockchain
that is used if noblockchain
is provided to theVM
constructor. I guess this was the reason to have aFakeBlockchain
before.Finally, if we do this,
ethereumjs-blockchain
can be a dev dependency. This will lead to faster installations for users of this module that choose not to useethereumjs-blockchain
.What do you think @s1na and @holgerd77?
I also think that similar reasoning may apply to the
StateManager
. If we define it as an interface, users of this library can plug-in their own implementations easily.