Skip to content

Conversation

abi87
Copy link
Contributor

@abi87 abi87 commented Nov 20, 2023

Why this should be merged

We could simplify the mempool api further by:

  1. Removing responsability of pinging engine for block building in case a tx is added to mempool
  2. Having to specify via a boolean whether the block expected to be built is empty or not

How this works

Just a mempool interface change

How this was tested

CI

@abi87 abi87 requested a review from dhrubabasu November 20, 2023 18:11
Comment on lines 310 to 312
if !emptyBlockPermitted && !m.HasTxs() {
return
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Removing this check is what I was worried about. I think the explicit override is less error-prone- we don't want to accidentally build empty blocks

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Copy link
Contributor

@dhrubabasu dhrubabasu Nov 20, 2023

Choose a reason for hiding this comment

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

I think this is still a concern, this PR accounts for not calling it in Add when there are no txs added but this method is also consumed outside of the Mempool interface in the builder

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 don't really see where the concern is

Copy link
Contributor

@dhrubabasu dhrubabasu Nov 21, 2023

Choose a reason for hiding this comment

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

This PR does not guard against sending extra common.PendingTxs messages if the mempool is empty in RequestBuildBlock. Since it is an exported method on the Mempool interface, I believe it should guard against that. This is consistent to how the mempool is implemented in the AVM https://github.com/ava-labs/avalanchego/blob/dev/vms/avm/txs/mempool/mempool.go#L202-L204

With the way this PR is implemented, any consumers of the Mempool interface can call RequestBuildBlock un-restricted. When reviewing future PRs that interact with the mempool, we'll need to keep in mind that there is no guard for the P-Chain mempool. With an explicit boolean that overrides the check, reviewers can easily tell that the code is correct and does not send extra common.PendingTxs messages to the engine.

https://github.com/ava-labs/avalanchego/blob/simplify_block_build_request/vms/platformvm/txs/mempool/mempool.go#L243-L246

	// notify engine only if we are ready to build a block
	if addedTx {
		m.RequestBuildBlock()
	}

I'd like to move forward with the base PR for these reasons (consistency + more obviously correct code). If you disagree, let's discuss offline.

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 really don't think #2333 it's more obviously correct. I think the two alternatives are equally correct.
I would not speculate on what option is easier to inspect and instead wait for other reviewers to evaluate the proposals.

@abi87 abi87 marked this pull request as ready for review November 20, 2023 18:24
}

func (m *mempool) Add(tx *txs.Tx) error {
func (m *mempool) Add(txs []*txs.Tx) error {
Copy link
Contributor

@dhrubabasu dhrubabasu Nov 20, 2023

Choose a reason for hiding this comment

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

This won't add any of the later txs in txs if one in the middle fails a check. I think we should retain the single tx Add instead of moving to an array

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for spotting this. Fixed while keeping the addition of a tx slice. I really like the simmetry with Remove

Copy link
Contributor

@dhrubabasu dhrubabasu left a comment

Choose a reason for hiding this comment

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

I think I'd prefer the base PR. Removing the boolean would make the interface simpler but it's better to be explicit about permitting empty blocks, especially since the P-Chain block builder is calling RequestBuildBlock.

@danlaine
Copy link

fwiw I also prefer the code as it is in https://github.com/ava-labs/avalanchego/pull/2333/files

Base automatically changed from move-engine-to-mempool to dev November 28, 2023 16:18
@abi87 abi87 closed this Nov 29, 2023
@dhrubabasu dhrubabasu deleted the simplify_block_build_request branch November 29, 2023 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants