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

Adding gas and byte size limits to collections #91

Merged
merged 14 commits into from Oct 28, 2020

Conversation

ramtinms
Copy link
Member

@ramtinms ramtinms commented Oct 23, 2020

This PR updates the collection builder logic to consider the maximum gas and byte size limits while building a collection.

@ramtinms ramtinms changed the base branch from master to ramtin/4876-tx-size-limit October 23, 2020 23:14
cmd/collection/main.go Outdated Show resolved Hide resolved
module/builder/collection/builder.go Outdated Show resolved Hide resolved
@ramtinms ramtinms changed the title [WIP] Add gas and byte size limits to collections Adding gas and byte size limits to collections Oct 27, 2020
@ramtinms ramtinms self-assigned this Oct 27, 2020
Copy link
Member

@jordanschalm jordanschalm left a comment

Choose a reason for hiding this comment

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

Thanks for adding 💯

module/builder/collection/builder_test.go Outdated Show resolved Hide resolved
module/builder/collection/builder_test.go Outdated Show resolved Hide resolved
module/builder/collection/builder_test.go Outdated Show resolved Hide resolved
Co-authored-by: Jordan Schalm <jordan@dapperlabs.com>
Base automatically changed from ramtin/4876-tx-size-limit to master October 28, 2020 18:02
Copy link
Contributor

@m4ksio m4ksio left a comment

Choose a reason for hiding this comment

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

Minor comments

module/builder/collection/builder.go Outdated Show resolved Hide resolved
@@ -28,6 +28,12 @@ type Config struct {
// UnlimitedPayer is a set of addresses which are not affected by per-payer
// rate limiting.
UnlimitedPayers map[flow.Address]struct{}

// MaxCollectionByteSize is the maximum byte size of a collection.
MaxCollectionByteSize uint
Copy link
Contributor

Choose a reason for hiding this comment

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

any reason why one is uint and other uint64?

Copy link
Member Author

Choose a reason for hiding this comment

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

not really, I think anyway is better to avoid uint in case we run the protocol on 32bits machines in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

I changed it to uint64 👍

log = log.With().
Hex("local_cluster", logging.ID(localCluster.Fingerprint())).
Hex("tx_cluster", logging.ID(txCluster.Fingerprint())).
Hex("local_cluster", logging.ID(localClusterFingerPrint)).
Copy link
Contributor

Choose a reason for hiding this comment

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

is fingerprint an ID? I understand that this function, AFAIR just hexprints it, but seems semantically wrong to use ID() on fingerprint

Copy link
Member Author

Choose a reason for hiding this comment

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

I think fingerprint is different than ID here as it ignores some data parts I guess, but since I don't know that much about this part of the code, I won't change it right now.

Copy link
Member Author

@ramtinms ramtinms Oct 28, 2020

Choose a reason for hiding this comment

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

I see your point on semantics. the issue is we don't have a fingerprint type, and it still returns an Identifier type

module/builder/collection/config.go Outdated Show resolved Hide resolved
@@ -36,6 +42,8 @@ func DefaultConfig() Config {
ExpiryBuffer: 15, // 15 blocks for collections to be included
MaxPayerTransactionRate: 0, // no rate limiting
UnlimitedPayers: make(map[flow.Address]struct{}), // no unlimited payers
MaxCollectionByteSize: 1000000, // 1MB
MaxCollectionTotalGas: uint64(1000000), // 1M
Copy link
Member

Choose a reason for hiding this comment

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

The limit has been defined there, why defining again here?

Could we let me refer to the same number?

I'm afraid one day we change one place and forgot to change the other.

Copy link
Member Author

Choose a reason for hiding this comment

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

I just followed the convention in the code to have a DefaultConfig and command line support to change it if needed. I won't change it as it needs to change all other values as well. maybe something for the future to change, cc: @jordanschalm

module/builder/collection/builder.go Outdated Show resolved Hide resolved
for _, tx := range b.transactions.All() {

// if we have reached maximum number of transactions, stop
if uint(len(transactions)) >= b.config.MaxCollectionSize {
break
}

// we can break cause
// max byte size per tx << the max collection byte size
// to make it more effective in the future we can continue adding smaller ones
Copy link
Member

Choose a reason for hiding this comment

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

I'm concerned by this comment:

In the worst case, if the byte size of the first transaction returned by transactions.All() is bigger than the collection's max byte size, then no transaction will be added. The leader will keep proposing empty collections.

Could we add a check to say if the single transaction's byte size is bigger than the max colleciton byte size, we will continue instead of break:


			if tx.ByteSize() > b.config.MaxCollectionByteSize {
				continue
			}
			if totalByteSize+tx.ByteSize() > b.config.MaxCollectionByteSize {
				break
			}

This could act as a "filter", or we could simply remove that over-sized transaction from the mempool

Same comment to the GasLimit

Copy link
Member Author

@ramtinms ramtinms Oct 28, 2020

Choose a reason for hiding this comment

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

I think we covered this case by setting the tx max limit to 64K, but you're right there is no harm covering this edge case in case one day we removed tx size limits

Copy link
Contributor

Choose a reason for hiding this comment

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

Finally we get to coin-selection problem!

Copy link
Member Author

Choose a reason for hiding this comment

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

applied the suggested changes.

@ramtinms ramtinms merged commit 45905b8 into master Oct 28, 2020
@ramtinms ramtinms deleted the ramtin/add-more-limits-to-collections branch October 28, 2020 22:26
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.

None yet

4 participants