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

Migrate Loop to typescript #505

Merged
merged 2 commits into from
May 7, 2019
Merged

Migrate Loop to typescript #505

merged 2 commits into from
May 7, 2019

Conversation

s1na
Copy link
Contributor

@s1na s1na commented May 7, 2019

I already noticed the positive effects of typing everything, and the effects become more obvious the more everything is typed! It led to a few minor fixes (some just type or doc annotations, and one possible bug). I also removed vmError in loop's result as it was redundant.

Two points I hope we can improve in next PRs:

  • Structure input options and results being returned more strictly.
  • Make exception handling somewhat more consistent (e.g. remove exception from the results, as an optional exceptionError suffices), and always return a VmError (not the error string directly).

(To be merged into #479)

@@ -522,11 +540,6 @@ export default class EEI {
// push the created address to the stack
return new BN(results.createdAddress)
}
} else {
// creation failed so don't increment the nonce
if (results.vm.createdAddress) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

results.vm.createdAddress is always undefined, as createdAddress is set on results itself. I fixed this, which led to some test failing. Had a look at geth and the contract creator's nonce is incremented, but not decremented on failure.

Copy link
Member

Choose a reason for hiding this comment

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

👍

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.

Some questions for my own understanding, but no real blockers, looks good!

With the TypeScript benefits sounds really great, can't wait for a time when I'll have time again to dig deeper and get my hands more directly on the code again and experience this myself. 😄

origin: Buffer
block: any
contract: Account
}
Copy link
Member

Choose a reason for hiding this comment

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

Phew, the transparency of this is mind blowing. Really neat! ☺️

@@ -36,7 +54,7 @@ export default class EEI {
}

refundGas (amount: BN): void {
this._result.gasRefund.iaddn(amount)
this._result.gasRefund.iadd(amount)
}
Copy link
Member

Choose a reason for hiding this comment

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

Uh, this didn't cause a bug before?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It wasn't a bug because refundGas was called with a number always (see changes in opFns). I changed them to pass a BN instead of a normal number.

@@ -554,7 +567,7 @@ export default class EEI {
}
}

function trap (err: string) {
function trap (err: ERROR) {
Copy link
Member

Choose a reason for hiding this comment

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

Yeah, seems that these kind of typings are also very much a driver for consistency. Great to have this error cleanup.

Copy link
Member

Choose a reason for hiding this comment

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

Or at least some start. 😋

message: Message
txContext: TxContext
pc?: number
}
Copy link
Member

Choose a reason for hiding this comment

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

Program counter can be optimal sometimes?

Copy link
Member

Choose a reason for hiding this comment

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

Ah, just for the options, self-answered. 😀

stateManager: StateManager
storageReader: StorageReader
eei?: EEI
}
Copy link
Member

Choose a reason for hiding this comment

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

Again here: this is wonderful.

runState: Object.assign({}, this._runState, this._result, this._runState.eei._env),
exception: err ? 0 : 1,
runState: Object.assign({}, this._runState, this._result, this._runState.eei!._env),
exception: err ? 0 as IsException : 1 as IsException,
exceptionError: err,
Copy link
Member

Choose a reason for hiding this comment

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

What's happening here with eei! ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because eei is optional, typescript would give an error that it could be undefined, the ! tells the compiler I know it isn't undefined 😄 (because it's initialized in initRunState). Agree this is something that can be improved.

Copy link
Member

Choose a reason for hiding this comment

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

Ah ok, thanks.

@holgerd77
Copy link
Member

More strict options and results sound great, very much in favor.

@s1na s1na merged commit 37a4de1 into v4 May 7, 2019
@s1na s1na deleted the ts/loop branch May 7, 2019 13:07
@s1na s1na mentioned this pull request May 7, 2019
23 tasks
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.

3 participants