Skip to content

miner: refactor helper functions in worker.go#21044

Merged
fjl merged 10 commits intoethereum:masterfrom
robert-zaremba:small-optimizations
Jul 28, 2020
Merged

miner: refactor helper functions in worker.go#21044
fjl merged 10 commits intoethereum:masterfrom
robert-zaremba:small-optimizations

Conversation

@robert-zaremba
Copy link
Copy Markdown
Contributor

This is a cosmetic update.

  • Update documentation (I hope few updates here are making it more clear)
  • extract common functionality from 2 lengthy functions in miner/worker.go - this improves readability and can also help with testing.

@robert-zaremba robert-zaremba requested a review from karalabe as a code owner May 8, 2020 06:02
@robert-zaremba robert-zaremba force-pushed the small-optimizations branch from 77c111c to 60a82f6 Compare May 8, 2020 06:27
Comment thread consensus/clique/clique.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is an interface method, it should not point to anything explicit. It's up to the caller. Please delete that part.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It's highly coupled with Wallet.SignData behaviour, notably hashing the message before signing. The current Clique implementation depends on it:

  • SignData will hash the data under the hood (without your knowledge)
  • ecrecovery will not hash, and if you forget about it you will have a wrong result.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is an interface, whether the current mplementation is a specific code is not relevant.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've updated the comment. I added a note about current implementation, but if you want I can remove it.

Comment thread consensus/clique/clique.go Outdated
Comment thread consensus/consensus.go Outdated
Comment thread miner/worker.go Outdated
Comment thread miner/worker.go
Comment thread miner/worker.go Outdated
Comment thread miner/worker.go
feesWei.Add(feesWei, new(big.Int).Mul(new(big.Int).SetUint64(receipts[i].GasUsed), tx.GasPrice()))
}
return new(big.Float).Quo(new(big.Float).SetInt(feesWei), new(big.Float).SetInt(big.NewInt(params.Ether)))
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This method is again a small utility code that's used solely for 1 log line. Moving it into a separate method makes things weirder because it makes the reader wonder what the importance is.

Copy link
Copy Markdown
Contributor Author

@robert-zaremba robert-zaremba May 8, 2020

Choose a reason for hiding this comment

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

My motivation is similar to the case with copyCurrentReceipts. This function is used in commit - the for loop is not necessary there (it is there only to create a log) and obfuscates the function, making slower to read.

In general - I would be happy, and I hope others would also benefit, if we have more such abstractions.

@robert-zaremba
Copy link
Copy Markdown
Contributor Author

Hi @karalabe , I've responded on all comments. Any chance we can move forward?

@robert-zaremba
Copy link
Copy Markdown
Contributor Author

Hi, is anything still blocking this PR to be merged?

@robert-zaremba
Copy link
Copy Markdown
Contributor Author

Hi, can we merge this PR?

@fjl fjl merged commit 37564ce into ethereum:master Jul 28, 2020
@fjl fjl changed the title Small optimizations miner: refactor helper functions in worker.go Jul 28, 2020
enriquefynn pushed a commit to enriquefynn/go-ethereum that referenced this pull request Mar 10, 2021
This reduces complexity of some lengthy functions in worker.go,
making the code easier to read.
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.

4 participants