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

eth: fix the block range assignment for log filter #17284

Merged
merged 1 commit into from
Jul 31, 2018

Conversation

rjl493456442
Copy link
Member

No description provided.

@rjl493456442 rjl493456442 requested a review from karalabe as a code owner July 31, 2018 08:26
}
if crit.ToBlock == nil {
end = int64(rpc.LatestBlockNumber)
crit.ToBlock = big.NewInt(rpc.LatestBlockNumber.Int64())
}
Copy link
Member

Choose a reason for hiding this comment

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

Please keep the variables and update those instead of the criteria. I don't think in general it's a good idea to modify input parameters:

 		begin := rpc.LatestBlockNumber.Int64()
 		if crit.FromBlock != nil {
 			begin = crit.FromBlock.Int64()
 		}
 		end := rpc.LatestBlockNumber.Int64()
 		if crit.ToBlock != nil {
 			end = crit.ToBlock.Int64()
 		}

)
if crit.FromBlock == nil {
begin = int64(rpc.LatestBlockNumber)
begin := rpc.LatestBlockNumber.Int64()
Copy link
Member

@ligi ligi Jul 31, 2018

Choose a reason for hiding this comment

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

nit: seems a bit wasteful to first get the value and then don't use it in some cases. How about if crit.FromBlock != nil begin = crit.FromBlock.Int64() else begin = rpc.LatestBlockNumber.Int64()

SCNR: would be even nicer in a language that supports this: begin = (if (crit.FromBlock != nil) crit.FromBlock else rpc.LatestBlockNumber).Int64() or even begin = (crit.FromBlock?:rpc.LatestBlockNumber).Int64

Copy link
Member

Choose a reason for hiding this comment

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

LatestBlockNumber is just a big.Int constant, so the cost of this op is a cast from big.Int to int64. The more optimal version isn't really worth the more complex code.

Copy link
Member

Choose a reason for hiding this comment

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

I do not think the code is more complex this way. I think this way it is more expressive and tells the developer what it is doing instantly - saving a few cycles in the process. But might also just be my language bias as I would have this in mind but it is not possible in go AFAIK: begin = (crit.FromBlock?:rpc.LatestBlockNumber).Int64
As I prefixed - just a nit & just something that went through my mind when reading the code - no real need to change something.

Copy link
Member

@karalabe karalabe left a comment

Choose a reason for hiding this comment

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

LGTM

@karalabe karalabe added this to the 1.8.13 milestone Jul 31, 2018
@karalabe karalabe merged commit c4a1d4f into ethereum:master Jul 31, 2018
firmianavan pushed a commit to firmianavan/go-ethereum that referenced this pull request Aug 28, 2018
gzliudan pushed a commit to gzliudan/XDPoSChain that referenced this pull request Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants