Skip to content
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

Common: add BN support #1150

Merged
merged 12 commits into from
Mar 16, 2021
Merged

Common: add BN support #1150

merged 12 commits into from
Mar 16, 2021

Conversation

ryanio
Copy link
Contributor

@ryanio ryanio commented Mar 15, 2021

This PR adds big number support to Common by updating functions with number input types to BNLike.

See this comment for the full list of functions changed.

For functions containing number outputs, alternative methods have been added (e.g. chainId -> chainIdBN) and the original methods have been deprecated with suggestion to use the BN alternatives for large number support.

Closes #914

@codecov
Copy link

codecov bot commented Mar 15, 2021

Codecov Report

Merging #1150 (5ebf583) into master (d40ba15) will increase coverage by 0.06%.
The diff coverage is 86.56%.

Impacted file tree graph

Flag Coverage Δ
block 81.78% <100.00%> (+0.17%) ⬆️
blockchain 84.13% <100.00%> (ø)
client 83.80% <66.66%> (-0.23%) ⬇️
common 87.39% <91.66%> (+1.27%) ⬆️
devp2p 84.32% <73.33%> (+0.12%) ⬆️
ethash 82.08% <ø> (ø)
tx 84.25% <100.00%> (+0.24%) ⬆️
vm 81.67% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

@holgerd77
Copy link
Member

@ryanio oh sorry, not sure if you are still working on this here, just updated the branch (by merge), if this conflicts with anything you do locally, just force-push.

@ryanio
Copy link
Contributor Author

ryanio commented Mar 15, 2021

@holgerd77 no problem, thanks, yes just updating some of the dependent packages now based on these new changes, will follow as additional commits

@ryanio ryanio force-pushed the common-bn-support branch from 6084a47 to 7d588ee Compare March 15, 2021 19:39
@ryanio ryanio force-pushed the common-bn-support branch from 7d588ee to aa17707 Compare March 15, 2021 20:01
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.

Looks great, also with this deep-reaching updates on the consuming libraries! 😄 👍 🎉

Will approve and merge.

@@ -188,17 +191,17 @@ export default class Common extends EventEmitter {
* @param blockNumber
* @returns The name of the HF
*/
getHardforkByBlockNumber(blockNumber: number): string {
getHardforkByBlockNumber(blockNumber: BNLike): string {
blockNumber = toType(blockNumber, TypeOutput.BN)
Copy link
Member

Choose a reason for hiding this comment

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

Oh, yeah, that plays out really nice here. 😄

): boolean {
opts = opts !== undefined ? opts : {}
const onlyActive = opts.onlyActive === undefined ? false : opts.onlyActive
hardfork1 = this._chooseHardfork(hardfork1, opts.onlySupported)
Copy link
Member

Choose a reason for hiding this comment

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

Side note, just because I am seeing it here: we might want to consider to remove onlySupported and/or onlyActive HF options on the next breaking release - this is not really used (maybe in the VM, but I would think this is rather not necessary to be managed in Common) - have added a reminder note to v6 Release planning.

if (this._unsignedTxImplementsEIP155()) {
v += this.common.chainId() * 2 + 8
vBN.iadd(this.common.chainIdBN().muln(2).addn(8))
Copy link
Member

Choose a reason for hiding this comment

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

👍

@holgerd77 holgerd77 merged commit 619ab5b into master Mar 16, 2021
@holgerd77 holgerd77 deleted the common-bn-support branch March 16, 2021 10:50
@@ -136,7 +136,7 @@ export class EthProtocol extends Protocol {
encodeStatus(): any {
// TODO: add latestBlock for more precise ETH/64 forkhash switch
return {
networkId: this.chain.networkId,
networkId: this.chain.networkId.toNumber(),
Copy link
Member

Choose a reason for hiding this comment

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

This change is currently breaking the client CLI start on Yolo v3.

Copy link
Member

Choose a reason for hiding this comment

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

Just checked, for RLPx the networkId can actually be removed completely from here, since the devp2p library is not using this passed in networkId any more but using the networkId from Common directly.

Not sure about libp2p though.

@ryanio ryanio mentioned this pull request Mar 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BN support in Common
2 participants