-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
refactor: cleanup {address,spent}index, remove platform-specific types, split out timestamp index #5577
Conversation
e0c38be
to
459c57d
Compare
This pull request has conflicts, please rebase. |
strong enums (enum class) cannot be converted implicitly to another type, requiring you to either use a static_cast or use to_underlying, which is a part of C++23, which this codebase doesn't support. the idea of scoping a weak enum into a namespace is courtesy of https://stackoverflow.com/a/46294875/13845753
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.
@kwvg I will add to review couple more comments later, WIP done
@@ -1,5 +1,6 @@ | |||
// Copyright (c) 2009-2010 Satoshi Nakamoto | |||
// Copyright (c) 2009-2015 The Bitcoin Core developers | |||
// Copyright (c) 2023 The Dash Core developers |
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.
seems as this file never has been in bitcoin so far as I see...
Probably need to remove Statoshi and Bitcoin Core from copyright.
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 assume the copyrights were added in because they borrowed logic from Nakamoto-era code and beyond. I was surprised to find that their own copyright was missing so it was added in to make the original author of the code much more apparent.
src/addressindex.h
Outdated
@@ -41,21 +41,21 @@ struct CMempoolAddressDelta | |||
struct CMempoolAddressDeltaKey | |||
{ | |||
public: | |||
int32_t m_address_type; | |||
uint8_t m_address_type{AddressType::UNKNOWN}; |
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.
ok, but there's usage of m_address_type in src/rpc/misc.cpp
better to refactor them too
there are two problems with "int spending;" - the integer, which implies that there are gradient states when there is none, only boolean (vin is spent, vout is UTXO) - the name, "spending" implies the existence of a middle state, there is none a reason why int may have been used is due to needing it in the comparison struct CMempoolAddressDeltaKeyCompare, though, using an int isn't necessary as when used with a comparison operator, a bool is implicitly converted to an int. see, https://en.cppreference.com/w/cpp/language/implicit_conversion (Integral promotion)
m_address_type is (de)serialized using ser_writedata8, making the maximum numbers of bits read or written to, 8. AddressType does not have values below 0, therefore the data type is changed to better reflect the way it is stored.
the size of size_t is platform-dependent, (de)serialization is done assuming the the value is 32 bits. changed to uint32_t as index value cannot be less than zero.
Co-authored-by: Konstantin Akimov <knstqq@gmail.com>
Co-authored-by: Konstantin Akimov <knstqq@gmail.com>
…type Co-authored-by: Konstantin Akimov <knstqq@gmail.com>
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.
utACK
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.
👍 ACK (reindexed on testnet with all indexes on, no performance regression vs develop, rpc results look sane)
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.
utACK for squash merge
Motivation
Since #914, the source of the code being imported, BitPay, has discontinued their Bitcoin Core fork and the software that relies on it (source) . The set of changes were added into Dash Core in Aug 2016, the last set of changes introduced to the fork were in Sep 2016 (commit).
Dash maintains Insight, a now discontinued BitPay codebase, on its own by forking it (source) and Dash Core developers have had to make modifications to the imported code to make sure it fits within current internal APIs. But aside from that, the code has been more or less, left alone.
It is important to note that a lot has changed from Bitcoin Core 0.12. A dedicated, independent, transaction index was introduced in v0.17 (source), a block filter index was introduced in v0.19 (source) and a coin stats index was introduced in v22 (source), all of which, are currently integrated into Dash Core, making the infrastructure to create indexes, readily available.
When working on #5574, a concern was raised about certain changes that were made to fit with new Dash Core backports. This in turn, inspired looking through the codebase and noticing a disparity in maintenance efforts, also noticing the usage of magic values, repetitive code, outdated code conventions, unclear naming conventions, etc.
Additional Information
This pull request explicitly aims to maintain backwards-compatibility (i.e. requiring no reindexing).
The set of changes include
uint32_t
overunsigned int
). Guidance was taken from cppreference using the LP64 data model.index
to refer to the position of the input/output in thevin
/vout
vectors and other structs used it to refer to the position of the transaction in thevtx
vector).enums
for values within a limited range2
,1
,1
respectively, with0
for unknown. This has been replaced withAddressType
CMempoolAddressDeltaKey
used anint
to mark if a transaction is an input or an output by calling itspending
. It would be more appropriate to use abool
as there are no gradient states. A further explanation is present in the commit body, including reasons why this approach may be taken.addressType
is represented as a 32-bit member but is (de)serialized as an 8-bit value. It would be more appropriate to useuint8_t
instead.size_t
for values, that while influenced by the size of a vector, are (de)serialized as 32-bit values. It was replaced withuint32_t
.