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

Allow both consensus and runtime to limit block building #1581

Merged
merged 12 commits into from
Feb 1, 2019

Conversation

tomusdrw
Copy link
Contributor

Closes #1354

  • Transactions size limitation is now in the runtime instead of basic_authorship.
  • We do have a hardcoded block size limit though (enforced in evaluation)
  • Additional maximal Duration is passed to the proposer from consensus to prevent missing a slot.

@tomusdrw tomusdrw added A0-please_review Pull request needs code review. M4-core labels Jan 25, 2019
@@ -283,6 +283,14 @@ impl<T: Trait> Module<T> {
storage::unhashed::get(well_known_keys::EXTRINSIC_INDEX)
}

/// Gets a total length of all executed extrinsics.
pub fn extrinsics_len() -> u32 {
let index = Self::extrinsic_index().unwrap_or_default();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm really hasitant about computing that after every extrinsic, but was unsure if it's ok to use storage for that. Would be storage::unhashed most likely alike EXTRINSIC_INDEX.

Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

Better to store the length rather than the data. There will be extrinsics of > 1MB in length and getting them in and out of storage quickly eats up heap and probably has no good effect on the effectiveness of the trie db cache.

@gavofyork gavofyork added A5-grumble and removed A0-please_review Pull request needs code review. labels Jan 29, 2019
@tomusdrw tomusdrw added A0-please_review Pull request needs code review. and removed A5-grumble labels Jan 31, 2019
// Verify the signature is good.
let xt = uxt.check(&Default::default()).map_err(internal::ApplyError::BadSignature)?;

// Check the size of the block if that extrinsic is applied.
if <system::Module<System>>::all_extrinsics_len() + encoded_len as u32 > internal::MAX_TRANSACTIONS_SIZE {
Copy link
Contributor

Choose a reason for hiding this comment

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

it would be cool to make this generic so it's not only by block size -- so it could be a dynamic gas limit or something similar. srml-contract could have an inherent for NewGasLimit which always has to be within some range of the old gas limit. And an implementation of the ExtrinsicLimiter trait that checks if the total gas used in the block is up to the gas limit.

Copy link
Contributor

Choose a reason for hiding this comment

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

@tomusdrw could we file an issue for that?

Copy link
Contributor

Choose a reason for hiding this comment

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

@pepyakin how are srml_contract gas limits currently handled?

Copy link
Contributor

Choose a reason for hiding this comment

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

Right now, the node is greedy, it will cram how many extrinsics it can in a block. At the same time, gas block limit in place so the first extrinsics will drain the gas up to the block limit and then all following extrinsics will fail because of lack of gas available in the block.

Copy link
Contributor Author

@tomusdrw tomusdrw Feb 1, 2019

Choose a reason for hiding this comment

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

Yeah, we had a small discussion with @pepyakin the other day. Maybe we can take it further and figure out the way how other modules can affect the way executive counts the transaction weight.
Logged here: #1651

Copy link
Member

Choose a reason for hiding this comment

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

later extrinsics should at least fail with a "transaction not valid in this block (but maybe in the future)" error. they should definitely not execute with no side-effects similarly to a failed transfer.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, I'm going to do a follow up PR on this to convert this error: https://github.com/paritytech/substrate/blob/master/srml/contract/src/gas.rs#L209 into FullBlock. This would be a temporary patch before #1651 provides a more generic solution.

@gavofyork gavofyork added A3-needsresolving and removed A0-please_review Pull request needs code review. A3-needsresolving labels Feb 1, 2019
@tomusdrw
Copy link
Contributor Author

tomusdrw commented Feb 1, 2019

rebased on master

@gavofyork gavofyork merged commit 6cf70c4 into master Feb 1, 2019
@gavofyork gavofyork deleted the td-blocktimeout branch February 1, 2019 12:58
MTDK1 pushed a commit to bdevux/substrate that referenced this pull request Apr 12, 2019
…1581)

* Limit block size in runtime,

* Add test for basic authorship.

* Store length of extrinsics instead of computing it.

* Don't rely on note_extrinsic

* Use hashed version of storage and write test.

* Recompile runtime.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants