nimbus-eth2
nimbus-eth2 copied to clipboard
Feature/capella
Table of Contents
-
Bellatrix -> Capella (August 2022)
- Getting stuck
- Setup and overview
- Spec files (capella.nim)
- Fork file (forks.nim)
- Review
- Typing
-
Duplication
- Duplication should be preferred
-
Rebase on
unstable
- Tracking compiler errors
- Ran into a serialization problem with the spec
- Large amount of typing errors
- Polymorphic errors
- Ambiguous calls
- sizeof(U) !== sizeof(T)
Bellatrix -> Capella (August 2022)
In this guide I mostly lay out the problems I ran into while making the forward migration.
In general I would suggest getting the spec/datatypes/\* files done first and them performing a search-and replace sweep on the whole project.
Look for all complex matches and then prepare macros for different files to sweep.
Stop at unviable areas, tag with TODO and get it to compile first.
—
Getting stuck
If you run into some difficult type or other error that you can’t process. Try to compile a different part of the project using the command:
./env.sh nim c beacon_chain/foo.nim
Setup and overview
Started working on adding the relevant part of the spec files to the capella.nim I added More cleaning up of the spec files
Spec files (capella.nim)
Here it was useful to copy from previous spec files rather than the spec itself mostly because the spec file types can differ slightly Functions at the bottom of the page were required for later compilation steps Better to copy them and try to remove later if possible
Fork file (forks.nim)
Find and duplicate all bellatrix (previous entry) functions and type names Better to search next and modify in this case, there are many hidden ones
Review
Found a few places that should be checked later because the previous specversion had inconsistencies with the previous spec marked with TODO and left for the end
Typing
Started working on moving some types into helper and resttypes Sorted code in datatypes/capella.nim, and Added TODO to cleanup these parts later when assured I could remove them (I could not), More helpers work and slowly tracking the compiler errors
Duplication
Duplication starts with finding functions that match your previous fork name and duplicating them. I found that quick-search and replace (in selected region) was very helpful here.
Tried to generalise some functionality but was unable to easily because of typing errors.
Duplication should be preferred
As it prevents errors with previous forks.
Compiler errors tracked me to more duplicates, however these errors are not always helpful at telling you where the issue is as the compiler complains a lot about non-matching types.
Rebase on unstable
which was thankfully easy and required a few easy refactor
Understand the scope is much more spread Search and replace prev + new fork everywhere
Tracking compiler errors
In general these are helpful at this stage and tell you where to start looking. However,
at this stage it would be more helpful to start combing through files. I suggest:
- prepare a list of files containing
complex(prev_fork)
declarations - comb those files using a macro for cases one by one
these steps above will likely save you many compiler errors be sure to TODO tag the ones which differ from spec to spec
Ran into a serialization problem with the spec
seemed likely there was no spec version present, but the code was a bit out of date in one part. There was a better implementation below which takes the version (in REST) from the JSON body
Large amount of typing errors
This was likely because I culled out some
important functions from capella.nim
too early.
At this point I also ran into sizeof(U) or sizeof(T)
problems
which was caused because the spec is duplicated in a few places
and also made immutable. All areas must be updated correctly.
More typing problems, this time with shortLog
who’s asking
for a BeaconBlock and getting one, but does not seem happy.
Found some more missed areas from the first code sweep and fixed
them up.
Polymorphic errors
Sometimes we don’t import the spec files directly, but rather export them from some other file.
Search export {previous_fork_name}
and be sure that all of them are
updated with your new fork name.
Ambiguous calls
I found that some places the spec has new features from the bellatrix upgrade which need to be modified or in some way made non-ambiguous.
So far in the slow process of migration type ambiguity has been the single largest slowdown to progress.
sizeof(U) !== sizeof(T)
Go into datatypes/base.nim and uncomment the following lines:
# NOTE: Uncomment for debugging type size mismatch
echo alignLeft($T.typeof & ":", 50), T.sizeof
echo alignLeft($U.typeof & ":", 50), U.sizeof, "\n", repeat("-", 20)
Then rebuild. This should print out the typenames and the corresponding size when an isomorphicCast attempt is made during compile time. Hopefully this will allow you to narrow down exactly which types are causing the issue.
Most of these issues are caused by a missing duplicate item in one of your spec
files. It could also be in the file beacon_chain_db_immutable.nim
why does it modify all these submodule commits?
why does it modify all these submodule commits?
That's a good question 🤔 Before I had some problems with these vendor areas during a rebase I will revert them.
thanks for the docs and PR - capella support has now been added via other PR:s