-
Notifications
You must be signed in to change notification settings - Fork 790
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
VM, Blockchain: fix storing unsettled promises #1201
Conversation
Codecov Report
Flags with carried forward coverage won't be shown. Click here to find out more. |
a5eb812
to
902add9
Compare
This PR has somewhat conflicting readyness settings, what's the status? |
I don't think I can make any of the changes I would have liked in this PR without any breaking changes, since moving from stored to unstored promises is a breaking change itself (for example if anyone was using or relying on them). I think we can put this PR on the back burner until we are ready to merge breaking changes for v6 where we can make some broader changes and refactor the async init code. |
@ryanio ok, have added to the v6 planning notes and added a "blocked" label here. |
* make constructor private (prefer use of async `Blockchain.create`) * update usage, tests * move types to dedicated file
902add9
to
a0e000c
Compare
Phew, rebased this, that was not trivial :) Holger I know you decided against this approach since private constructors block inheritance, so I am going to think more about it, maybe we just make them deprecated and note they are not private for the reason of inheritance but their use is strongly discouraged over the async methods. (edit: ok I undid the private constructor and made sure both had deprecation messages) |
3b211e1
to
0651191
Compare
0651191
to
3473e72
Compare
That's what I also suggested yeah, but I have to admit that I am also still unsure. On the other hand it would be a huge win to have this somewhat ensured that devs are not unsafely calling into this. But I do am somewhat anxious on this that we might have not considered all use cases here and might put some unpractical restrictions on users by doing so. Some additional thoughts I had here:
|
packages/blockchain/src/types.ts
Outdated
* provided from the `common` will be used. | ||
*/ | ||
genesisBlock?: Block | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where is this huge type file coming from? Is this a forgotten artifact from the interface PR which also happened around that time? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah no I was just moving them from index.ts
because it was getting so long. I will undo this though because I see the benefit of keeping it along with the source code now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I guess on Blockchain we likely also want to restructure the exports and use the index.ts
file just for exporting things and move code and types to dedicated files, a bit as we are planning for the VM (see #1024 VM TODOs).
If you agree respectively have no reservations you might directly want to do in this PR since this is breaking already?
oh nice, |
IMO protected constructors with async |
@alcuadrado great, thanks! that's weird, typescript is erroring out (on local and ci) when I added
|
Am I correct that we would now redo (respectively: re-point) this towards |
this hasn't been updated or merged into anything yet, a good candidate i can pick up when we are ready to bring it in :) |
I will pick this up next week and start fresh with a new PR targeting develop. |
#1181
This PR resolves storing unsettled promises in
VM
,Blockchain
by preferring to useVM.create
andBlockchain.create
instead ofnew VM
andnew Blockchain
as this lets us safely run async init code.VM
:mcl
is now initialized insideVM.init()
and has no stored promise.Blockchain
:init
is run duringBlockchain.create()
and has no stored promise.Both classes have boolean
_isInitialized
and check internally to make sure they do not init more than once.Sometimes in the client a
Blockchain
orVM
is set up in a constructor. In this case, theinit
is added to the classes'open
method.