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

gas_limit for blocks, mined by Parity will be divisible by 37 #4154

Merged
merged 8 commits into from
Jan 16, 2017

Conversation

svyatonik
Copy link
Collaborator

closes [todo: backport then close] #4129

@svyatonik svyatonik added A0-pleasereview 🤓 Pull request needs code review. M4-core ⛓ Core client code / Rust. labels Jan 12, 2017
@svyatonik svyatonik closed this Jan 13, 2017
@svyatonik svyatonik reopened this Jan 13, 2017
@svyatonik svyatonik changed the title gas_limit for blocks, mined by Parity will be divisible by 13 gas_limit for blocks, mined by Parity will be divisible by 37 Jan 13, 2017
@gavofyork
Copy link
Contributor

haven't checked the logic - might be worth pulling out the determinant logic into a separate function that takes min, max, target and determinant and returns the closest value v to target such that v >= min && v <= max and, if possible, v % determinant == 0

@svyatonik
Copy link
Collaborator Author

I just wanted to decrease number of U256 operations, as in two first if branches there's no need to check that result is in [lower_limit; upper_limit]. I agree that separate function which will round-up result will be more convenient && understandable, but it will cost in extra-ops. So - if you insist, I'll make an extra func, if not - let it be as it is now.

@gavofyork
Copy link
Contributor

gavofyork commented Jan 13, 2017

premature optimisation is the root of all evil :-)

i don't think it's on a hotpath; feel free to benchmark the two approaches for block import but i expect any difference will not be significant.

if it is, maybe do the range check inline and abstract the other clause out into a function with debug_asserts to ensure range inclusion?

@svyatonik svyatonik closed this Jan 13, 2017
@svyatonik
Copy link
Collaborator Author

Added separate round_block_gas_limit method which will round gas_limit to the nearest (not nearest actually - first try to increase && then to decrease if increasing fail) multiplier of 37. Still > 1 calls of this method, as in first 2 branches we should only respect protocol limits && in 3 we can respect both protocol && miner limits. These calls can be merged if we consider miner limits as 'flexible' (i.e. we are trying to respect, but can break these limits a bit)

@svyatonik svyatonik reopened this Jan 13, 2017
@gavofyork
Copy link
Contributor

probably best to leave as is and respect them.

@gavofyork gavofyork added A8-looksgood 🦄 Pull request is reviewed well. and removed A0-pleasereview 🤓 Pull request needs code review. labels Jan 13, 2017
@gavofyork
Copy link
Contributor

looks good to me. @arkpar , @rphmeier , @tomusdrw please review carefully.

// Try to round gas_limit a bit so that:
// 1) it will still be in desired range
// 2) it will be a nearest (with tendency to increase) multiplier of PARITY_GAS_LIMIT_DETERMINANT
fn round_block_gas_limit(&self, gas_limit: U256, lower_limit: U256, upper_limit: U256) -> U256 {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: why take self? seems to be unused here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

removed

@coveralls
Copy link

Coverage Status

Changes Unknown when pulling e7a142f on block_identification into ** on master**.

}
let total_lower_limit = max(lower_limit, gas_floor_target);
let total_upper_limit = min(upper_limit, gas_ceil_target);
let gas_limit = max(gas_floor_target, min(total_upper_limit,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it would make more sense to have max(total_upper_limit, .. (I know it wasn't like this in previous implementation, but still it would make sense)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

If I change this to max(total_upper_limit, .. it will always stick to the upper_limit:
max(upper_limit, lower_limit + something) = uper_limit
So this definitely changes the logic significantly and in strange way :)
Maybe you mean max(total_lower_limit, ... - I see that this is logical. However:
max(N, N + M), where N && M are U256 are always larger than N (let's omit overflows)
Previously it wasn't there, because there were no total_lower_limit && it is an extra-op, but now everything is known && I could easily change this, if this is what you meant. Just ping me

@arkpar arkpar merged commit bac6293 into master Jan 16, 2017
@arkpar arkpar deleted the block_identification branch January 16, 2017 13:29
arkpar pushed a commit that referenced this pull request Jan 16, 2017
* gas_limit for new blocks will divide evenly by 13

* increased PARITY_GAS_LIMIT_DETERMINANT to 37

* separate method for marking mined block

* debug_asserts(gas_limit within protocol range)

* round_block_gas_limit method is now static

* made round_block_gas_limit free-function

* multiplier->multiple [ci skip]
arkpar pushed a commit that referenced this pull request Jan 16, 2017
* gas_limit for new blocks will divide evenly by 13

* increased PARITY_GAS_LIMIT_DETERMINANT to 37

* separate method for marking mined block

* debug_asserts(gas_limit within protocol range)

* round_block_gas_limit method is now static

* made round_block_gas_limit free-function

* multiplier->multiple [ci skip]
arkpar pushed a commit that referenced this pull request Jan 16, 2017
* gas_limit for new blocks will divide evenly by 13

* increased PARITY_GAS_LIMIT_DETERMINANT to 37

* separate method for marking mined block

* debug_asserts(gas_limit within protocol range)

* round_block_gas_limit method is now static

* made round_block_gas_limit free-function

* multiplier->multiple
gavofyork pushed a commit that referenced this pull request Jan 16, 2017
…#4176)

* gas_limit for new blocks will divide evenly by 13

* increased PARITY_GAS_LIMIT_DETERMINANT to 37

* separate method for marking mined block

* debug_asserts(gas_limit within protocol range)

* round_block_gas_limit method is now static

* made round_block_gas_limit free-function

* multiplier->multiple
arkpar pushed a commit that referenced this pull request Jan 16, 2017
* gas_limit for new blocks will divide evenly by 13

* increased PARITY_GAS_LIMIT_DETERMINANT to 37

* separate method for marking mined block

* debug_asserts(gas_limit within protocol range)

* round_block_gas_limit method is now static

* made round_block_gas_limit free-function

* multiplier->multiple
arkpar added a commit that referenced this pull request Jan 16, 2017
…#4179)

* gas_limit for new blocks will divide evenly by 13

* increased PARITY_GAS_LIMIT_DETERMINANT to 37

* separate method for marking mined block

* debug_asserts(gas_limit within protocol range)

* round_block_gas_limit method is now static

* made round_block_gas_limit free-function

* multiplier->multiple
arkpar added a commit that referenced this pull request Jan 16, 2017
…#4176)

* gas_limit for new blocks will divide evenly by 13

* increased PARITY_GAS_LIMIT_DETERMINANT to 37

* separate method for marking mined block

* debug_asserts(gas_limit within protocol range)

* round_block_gas_limit method is now static

* made round_block_gas_limit free-function

* multiplier renamed to multiple
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A8-looksgood 🦄 Pull request is reviewed well. M4-core ⛓ Core client code / Rust.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants