Skip to content

Conversation

@ceyonur
Copy link
Contributor

@ceyonur ceyonur commented Apr 15, 2023

Why this should be merged

We needed to separate network logic from builder to add new handlers for GossipHandler. This PR refactors the networking/handlers in platform vm by moving networking logic to a new package, and decreases any cross-dependency between platformvm-network and builder.

How this works

Moves networking logic in the builder to a separate package. Implements the new networking package with external handlers. Removes unnecessary requestIDs from TxGossip handlers.

How this was tested

Added new UTs

@ceyonur ceyonur added vm This involves virtual machines networking This involves networking cleanup Code quality improvement labels Apr 15, 2023
@ceyonur ceyonur self-assigned this Apr 15, 2023
@ceyonur ceyonur requested a review from joshua-kim April 26, 2023 16:51
Uptimes uptime.Manager
Rewards reward.Calculator
Bootstrapped *utils.Atomic[bool]
Mempool mempool.Mempool
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we need mempool to be an attribute of the backend. Just drop it and simply pass it in blockbuilder.New

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We already both use mempool + txExecutorBackend as arguments in blockbuilder.New and blockexecutor.NewManager. I thought Backend serves as provider for both of these New functions, so that we can use Backend to group common objects. (instead of passing it as separate argument)

Copy link
Contributor

Choose a reason for hiding this comment

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

I see but the backend is used in other places where mempool is not needed. Not sure if I am changing my mind here, but now it feels cleaner to keep mempool our of backend.
Anyhow, we can let other reviewers express their opinion on this

env.ctx.Lock.Lock()
defer func() {
require.NoError(shutdownEnvironment(env))
env.ctx.Lock.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Unlock follow Shutdown call in prod code. I would keep that order here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm I was thinking that Shutdown might try to grab the lock

Copy link
Contributor

Choose a reason for hiding this comment

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

No in prod code it's the message handler responsible to grab the lock. In general we don't grap the Ctx.Lock in the platformvm. It's assume that callers duly do that


require.Equal(txID, retrivedTx.ID())

// show that transaction is not re-gossiped is recently added to mempool
Copy link
Contributor

@abi87 abi87 Apr 27, 2023

Choose a reason for hiding this comment

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

typo: if recently added

FlowChecker: res.utxosHandler,
Uptimes: res.uptimes,
Rewards: rewardsCalc,
Mempool: res.mempool,
Copy link
Contributor

Choose a reason for hiding this comment

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

if Mempool is removed from the backend (I think it's cleaner to pass it to block Builder from the constructor), this change can be reverted.

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 answered it above:#1363 (comment)

We would end up taking the same mempool + txExecutor args in both blockbuilder/blockexecutor.

Copy link
Contributor

@abi87 abi87 left a comment

Choose a reason for hiding this comment

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

just minor cleanups and I think we are good.
While the BlockBuilder <---> Mempool circular dependency is still there, the rest is definitely saner. Thanks C

Copy link
Contributor

@abi87 abi87 left a comment

Choose a reason for hiding this comment

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

just cleanup

@ceyonur
Copy link
Contributor Author

ceyonur commented Apr 28, 2023

just minor cleanups and I think we are good. While the BlockBuilder <---> Mempool circular dependency is still there, the rest is definitely saner. Thanks C

I think we can break this dependency by making Mempool a subscribable struct then blockbuilder can subscribe to Mempool.Add() with a callback for ResetBlockTimer.

Copy link
Contributor

@abi87 abi87 left a comment

Choose a reason for hiding this comment

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

only open point it's whether including mempool in backend struct. We can decide this together

joshua-kim pushed a commit to joshua-kim/avalanchego that referenced this pull request Apr 28, 2023
Co-authored-by: Vie <yangchenzhong@gmail.com>
@github-actions
Copy link

This PR has become stale because it has been open for 30 days with no activity. Adding the lifecycle/frozen label will cause this PR to ignore lifecycle events.

@github-actions
Copy link

This PR has become stale because it has been open for 30 days with no activity. Adding the lifecycle/frozen label will cause this PR to ignore lifecycle events.

@ceyonur ceyonur closed this Nov 13, 2023
@dhrubabasu dhrubabasu deleted the platformvm-network-refactor branch November 13, 2023 20:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cleanup Code quality improvement networking This involves networking vm This involves virtual machines

Projects

Archived in project
Status: In Review 👀

Development

Successfully merging this pull request may close these issues.

4 participants