-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
mempool: Refactor mempool code to its own package. #737
Conversation
de7feaf
to
b3f8262
Compare
ok |
This does the minimum work necessary to refactor the mempool code into its own package. The idea is that separating this code into its own package will greatly improve its testability, allow independent benchmarking and profiling, and open up some interesting opportunities for future development related to the memory pool. There are likely some areas related to policy that could be further refactored, however it is better to do that in future commits in order to keep the changeset as small as possible during this refactor. Overview of the major changes: - Create the new package - Move several files into the new package: - mempool.go -> mempool/mempool.go - mempoolerror.go -> mempool/error.go - policy.go -> mempool/policy.go - policy_test.go -> mempool/policy_test.go - Update mempool logging to use the new mempool package logger - Rename mempoolPolicy to Policy (so it's now mempool.Policy) - Rename mempoolConfig to Config (so it's now mempool.Config) - Rename mempoolTxDesc to TxDesc (so it's now mempool.TxDesc) - Rename txMemPool to TxPool (so it's now mempool.TxPool) - Move defaultBlockPrioritySize to the new package and export it - Export DefaultMinRelayTxFee from the mempool package - Export the CalcPriority function from the mempool package - Introduce a new RawMempoolVerbose function on the TxPool and update the RPC server to use it - Update all references to the mempool to use the package. - Add a skeleton README.md
b3f8262
to
1bc016c
Compare
func newTxMemPool(cfg *mempoolConfig) *txMemPool { | ||
memPool := &txMemPool{ | ||
func New(cfg *Config) *TxPool { | ||
return &TxPool{ | ||
cfg: *cfg, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor nit: why does the New()
function accept a *Config
, but then immediately deference it?
It seems that either New()
should be changed to accept a Config
, or the TxPool
's cfg
attribute be changed to be a *Config
rather than a Config
.
I know this behavior has been in place since the mempool was slightly refactored to use the previous mempoolConfig
, but it's been bugging me since then... 🤓
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's to avoid two copies although it's small and only done once, so it probably really doesn't matter.
The intent is to make sure once a config is provided it can't be changed by the caller hence the deref to make a copy. Accepting it as a parameter means that parameter is a copy and then setting the field in the type is another copy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't mind changing it if it really bugs folks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, I hadn't considered possible mutation of the config after it had been passed to the mempool.
With that knowledge, it no longer bugs me 🙂
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The config is not safe for concurrent access though, it should be treated as immutable.
edit: nvm I only read half this conversation, this is exactly what davec is trying to avoid by making a local copy.
The changes read well. I like how the commit is rather minimal in its refactorings. This is a great step towards future mempool extensions such as shared distributed |
This does the minimum work necessary to refactor the mempool code into its own package. The idea is that separating this code into its own package will greatly improve its testability, allow independent
benchmarking and profiling, and open up some interesting opportunities for future development related to the memory pool.
There are likely some areas related to policy that could be further refactored, however it is better to do that in future commits in order to keep the changeset as small as possible during this refactor.
Overview of the major changes:
mempool.go
->mempool/mempool.go
mempoolerror.go
->mempool/error.go
policy.go
->mempool/policy.go
policy_test.go
->mempool/policy_test.go
mempoolPolicy
toPolicy
(so it's nowmempool.Policy
)mempoolConfig
toConfig
(so it's nowmempool.Config
)mempoolTxDesc
toTxDesc
(so it's nowmempool.TxDesc
)txMemPool
toTxPool
(so it's nowmempool.TxPool
)defaultBlockPrioritySize
to the new package and export itDefaultMinRelayTxFee
from themempool
packageCalcPriority
function from themempool
packageRawMempoolVerbose
function on theTxPool
and updatethe RPC server to use it
mempool
to use the packageREADME.md