Skip to content
This repository has been archived by the owner on Apr 6, 2020. It is now read-only.

Migrate to TypeScript #92

Merged
merged 1 commit into from
Mar 19, 2019
Merged

Migrate to TypeScript #92

merged 1 commit into from
Mar 19, 2019

Conversation

whymarrh
Copy link
Contributor

@whymarrh whymarrh commented Mar 7, 2019

This PR migrates the codebase to use TypeScript. This PR also replaces the Babel tooling with tooling from ethereumjs-config, resulting a project structure similar to the account, rlp, etc. libraries. I've made heavy use of any as a starting point for future restricting of the types (which will likely have to be accompanied by further refactoring). I've also dropped safe-buffer (as outlined in the organizations technical documentation).

@coveralls
Copy link

coveralls commented Mar 7, 2019

Coverage Status

Coverage decreased (-2.06%) to 94.226% when pulling 7d54aea on whymarrh:migrate-ts into 2262597 on ethereumjs:master.

@holgerd77
Copy link
Member

👍

package.json Show resolved Hide resolved
@holgerd77
Copy link
Member

holgerd77 commented Mar 7, 2019

Can you also add the return types to the functions?

@holgerd77
Copy link
Member

(corrected the comment above, please read on GitHub directly)

@holgerd77
Copy link
Member

Ok, that's REALLY a lot of any 😄, is it not possible to be more precise in many cases?

@holgerd77
Copy link
Member

(but if you think that's too much work load on this iteration - so be it - then we do it next round separately)

@whymarrh
Copy link
Contributor Author

whymarrh commented Mar 7, 2019

I am looking at being more specific with the types as I can, but there I think I might have to do a separate PR.

@whymarrh whymarrh force-pushed the migrate-ts branch 2 times, most recently from 7d54aea to ee24224 Compare March 7, 2019 23:32
@whymarrh
Copy link
Contributor Author

whymarrh commented Mar 7, 2019

is it not possible to be more precise in many cases?

The main sticking point is that there are a good few functions in the index file that manipulate the arguments/overload the functions and to express that properly I would need to rewrite the functions themselves and I don't want them to get lost in the diff noise.

@holgerd77
Copy link
Member

Ah ok, no, them leave as-is, we can also add the return types later.

.editorconfig Outdated
insert_final_newline = true

[*.md]
indent_size = 4
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What kind of editor configuration is this here? Even if this might be useful I would prefer not to side introduce here and eventually discuss along a separate PR, can you please remove?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, I'll add this in a separate PR

@holgerd77
Copy link
Member

Generally: just realizing the scope of this work by scrolling completely through for the first time, really great! 😀 👍

@holgerd77
Copy link
Member

Can you do one integration test on this and open a PR on the VM pointing the blockchain dependency towards this branch so that we can see if CI runs through? This will largely help build up confidence that this has no side effects (especially after the experiences with the other TS transitions 😆).

@whymarrh
Copy link
Contributor Author

whymarrh commented Mar 8, 2019

Can you do one integration test on this and open a PR on the VM pointing the blockchain dependency towards this branch so that we can see if CI runs through?

For sure, I'll add that

@whymarrh
Copy link
Contributor Author

Can you do one integration test on this and open a PR on the VM pointing the blockchain dependency towards this branch so that we can see if CI runs through?

Using this branch is a bit tricky with the new build process. The published versions will have compiled TS code where the branch doesn't. I could add a temporary step to ethereumjs/ethereumjs-monorepo#469 that compiles the source, how does that sound?

@holgerd77
Copy link
Member

@whymarrh Whatever is easier for you, you can also do a local test run and post the results here.

@holgerd77
Copy link
Member

This lacks a prettier.config.js file, see e.g. the one from the account library.

@holgerd77
Copy link
Member

Also .prettierignore.

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not completely through yet, some things to clarify or update, can already be addressed.

const level = require("level-mem");
const semaphore = require("semaphore");

export default class Blockchain {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for notation: this will be the same kind of API breaking module loading as along the other TS transitions.

src/cache.ts Outdated Show resolved Hide resolved
src/util.ts Outdated Show resolved Hide resolved
src/dbManager.ts Show resolved Hide resolved
package.json Show resolved Hide resolved
@whymarrh whymarrh force-pushed the migrate-ts branch 3 times, most recently from c3fb550 to 4373b4b Compare March 12, 2019 01:32
@whymarrh
Copy link
Contributor Author

I've got ethereumjs/ethereumjs-monorepo#469 to build successfully based on (a form of) these changes

@holgerd77
Copy link
Member

This has now linting errors since prettier is activated and CI is failing.

src/index.ts Outdated
_initLock: any;
_putSemaphore: any;
_staleHeadBlock: any;
_staleHeads: any;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice resorting and - generally - property collection, finally gives some overview what's inside. 😄 👍

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be continued... 😄

}
this._initLock.go();
});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

constructor(): Ok.

src/index.ts Outdated
}
cb();
}
);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get meta(), _init(): Ok.

self._headBlock = genesisHash;
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getHeads(): Ok.

},
cb
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok till here.

this._putBlockOrHeader(block, done, isGenesis);
}, cb);
});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lockUnlock extracted, good.

next();
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_putBlockOrHeader(): Ok.

}

nextBlock(blockId);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok until here.

* Gets block details by its hash
* @deprecated
*/
getDetails(_: string, cb: any) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this hash -> _ replacement some convention to mark things as deprecated? Other reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The hash argument isn't used so it's a convention to note that it's not used


_saveHeads(cb: any) {
this._batchDbOps(this._saveHeadOps(), cb);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok till here.

cb();
}
});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok till here.

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I'm through finally 😄. Apart from another prettier fix run and a handful minor comments to be addressed I think this should actually be ready to merge since tests are also passing on the VM. Really great job! 👍

src/index.ts Outdated
});
}

_delBlock(blockHash: any, cb: any) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be safe to use Buffer here as a type too as in delBlock().

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll update this to use Buffer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch

src/index.ts Show resolved Hide resolved
src/index.ts Outdated Show resolved Hide resolved
src/index.ts Show resolved Hide resolved
src/index.ts Show resolved Hide resolved
src/index.ts Show resolved Hide resolved
test/index.ts Show resolved Hide resolved
@whymarrh whymarrh force-pushed the migrate-ts branch 2 times, most recently from 417159c to bad4381 Compare March 15, 2019 14:47
@whymarrh
Copy link
Contributor Author

@holgerd77 updated again, let me know how it looks now

@holgerd77
Copy link
Member

Hi @whymarrh, thanks for the updates, can you please have a final look at the CI run some time after you push and check that this is ok? Otherwise this is always blocking.

Linting is still failing, probably prettier fix run still needs to be applied.

@holgerd77
Copy link
Member

@whymarrh Can you do this final prettier run so that we can get this over the finish line?

@whymarrh
Copy link
Contributor Author

Updated. We'll also want to drop 83fb9c0 from this PR or before we publish.

@holgerd77
Copy link
Member

@whymarrh Not completely getting it. Why did you introduce this in the first place and why didn't you remove now along this update? Is this something which needs further work?

@whymarrh
Copy link
Contributor Author

@holgerd77 updated and removed 83fb9c0. Apologies for the confusion, what wasn't clear? To be able to use this package via Git in ethereumjs/ethereumjs-monorepo#469 the files entry needed to be dropped. I've dropped them now and we can deal with that PR separately now—that PR no longer works but that's fine, once we publish a version of this package I can update that PR with the version from the registry.

From that PR's description:

Note: while [ethereumjs/ethereumjs-blockchain#92] is in-progress this will be pointing to a Git URL of my fork. Once the PR is merged (and the tests here will serve as a useful smoke test) this PR will be updated with the correct version on the registry.

Copy link
Member

@holgerd77 holgerd77 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry, wasn't aware of this connection.

Looks good now, will merge! 😀🎷🎺🥁

@holgerd77 holgerd77 merged commit a898360 into ethereumjs:master Mar 19, 2019
@whymarrh whymarrh deleted the migrate-ts branch March 19, 2019 10:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants