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

Implement getchains RPC command. #19

Merged
merged 2 commits into from
Mar 15, 2014

Conversation

domob1812
Copy link
Contributor

This patch adds a new RPC command "getchains" that returns all known heads of blockchain branches. For heads not on the main chain, also all block hashes along the branch connecting it back to the fork point from the main chain are returned.

Implement a new "getchains" RPC command, that returns all heads of
blockchain forks known.
Add additional result fields to getchains output that show the branches
connecting the heads to the main chain.
chronokings pushed a commit that referenced this pull request Mar 15, 2014
Implement getchains RPC command.
@chronokings chronokings merged commit ae4f3a9 into chronokings:master Mar 15, 2014
@domob1812 domob1812 deleted the rpc-get-chains branch March 16, 2014 08:26
dexX7 pushed a commit to dexX7/mastercore-rpc-tests that referenced this pull request Nov 10, 2014
Port over chronokings/huntercoin#19 from
Huntercoin:  This implements a new RPC command "getchaintips" that can be
used to find all currently active chain heads.  This is similar to the
-printblocktree startup option, but it can be used without restarting
just via the RPC interface on a running daemon.
xawksow added a commit to DGCDev/digitalcoin that referenced this pull request Apr 20, 2015
Port over chronokings/huntercoin#19 from
Huntercoin:  This implements a new RPC command "getchaintips" that can be
used to find all currently active chain heads.  This is similar to the
-printblocktree startup option, but it can be used without restarting
just via the RPC interface on a running daemon.
supasonic added a commit to supasonic/Mintcoin-Desktop-Wallet that referenced this pull request Apr 24, 2016
Break up CAddrMan's IMPLEMENT_SERIALIZE


overhaul serialization code

The implementation of each class' serialization/deserialization is no longer
passed within a macro. The implementation now lies within a template of form:

template <typename T, typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
    size_t nSerSize = 0;
    /* CODE */
    return nSerSize;
}

In cases when codepath should depend on whether or not we are just deserializing
(old fGetSize, fWrite, fRead flags) an additional clause can be used:
bool fRead = boost::is_same<Operation, CSerActionUnserialize>();

The IMPLEMENT_SERIALIZE macro will now be a freestanding clause added within
class' body (similiar to Qt's Q_OBJECT) to implement GetSerializeSize,
Serialize and Unserialize. These are now wrappers around
the "SerializationOp" template.


remove fields of ser_streamplaceholder

The nType and nVersion fields of stream objects are never accessed
from outside the class (or perhaps from the inside too, I haven't checked).
Thus no need to have them in a placeholder, whose only purpose is to
fill the "Stream" template parameter in serialization implementation.


rework overhauled serialization methods to non-static

Thanks to Pieter Wuille for most of the work on this commit.
I did not fixup the overhaul commit, because a rebase conflicted
with "remove fields of ser_streamplaceholder".
I prefer not to risk making a mistake while resolving it.


Use CSizeComputer to avoid counting sizes in SerializationOp


Serializer simplifications after IMPLEMENT_SERIALIZE overhaul


Rename IMPLEMENT_SERIALIZE to ADD_SERIALIZE_METHODS


CBlockIndex()::SetNull() method to avoid code repetition


Move UpdateTime to pow


replace ComputeMinWork with CheckMinWork


Fix a few "Uninitialized scalar field" warnings

Fix a few warnings reported by Coverity.
None of these is critical, but making sure that class fields are
initialized can avoid heisenbugs.


Move CBlockIndex::GetBlockWork() to pow::GetProofIncrement(nBits)


Do merkle root and txid duplicates check simultaneously

Move the txid duplicates check into BuildMerkleTree, where it can be done
much more efficiently (without needing to build a full txid set to detect
duplicates).

The previous version (using the std::set<uint256> to detect duplicates) was
also slightly too weak. A block mined with actual duplicate transactions
(which is invalid, due to the inputs of the duplicated transactions being
seen as double spends) would trigger the duplicates logic, resulting in the
block not being stored on disk, and rerequested. This change fixes that by
only triggering in the case of duplicated transactions that can actually
result in an identical merkle root.


Move CMerkleTx to wallet.cpp/h

It is only used by the wallet so it has no place in main


Clean up CMerkleTx::SetMerkleBranch.

The case SetMerkleBranch(NULL) was never actually used, and thus the
involved code (loading the block from disk) can be removed and the
implementation simplified.


Use OR of respective block flags for masks


checkpoints.cpp depends on main, it can use mapBlockIndex directly


Introduce BlockMap type for mapBlockIndex


Use boost::unordered_map for mapBlockIndex


Use memcmp for uint256 equality/inequality


Decouple CChain from mapBlockIndex


Move CBlockIndex, CChain and related code out of main


MOVEONLY: Move void UpdateTime() from pow.o to miner.o (plus fix incl…

…ude main.h -> chain.h)


CBlockIndex::GetBlockWork() + GetProofIncrement(nBits) -> GetBlockPro…

…of(CBlockIndex)


Implement "getchaintips" RPC command to monitor blockchain forks.

Port over chronokings/huntercoin#19 from
Huntercoin:  This implements a new RPC command "getchaintips" that can be
used to find all currently active chain heads.  This is similar to the
-printblocktree startup option, but it can be used without restarting
just via the RPC interface on a running daemon.


BTC Commit(s):
b069750d3f27c96a83700a08a2bb819902268857
3d796f89962842e91e7d88e57c1d2d579f01052e
5d96b4ae0188fcad36105642c5d69249d37fdbb5
84881f8c472cc67dc757686eb7dc3b495b13cab8
31e9a8384a77947f6777d035992f4734618ed206
47eb76597efb7dadb36dd98bc20bd80b2db9cd50
3f6540ad8f9c7b45a0dd2b260a282d3adad2406f
834e46e847188df513b8b57ab30fe9940f2b2dd0
c2c02f3fa99385f5a5be722fda6f71522c93bdaa
654871d43677947d124673c9e0dd2984f0d3ca61
8bdd2877c4f959b0c4b93f3d9d1f465fb4960f3f
b343c1a1e34f851e70649ad1f49855a7d878f9ef
584a358997e52a87e8c5402269c7fb3784ed2065
0101483f46396a7f1d19a9d29a1da15639ce4233
4b0deb3b2df5882061ae6c44947eda831420cd5e
910526d8487e5db04b4f280efcd05d95e6dc273f
a0dbe433bdb3f22be639fbb675c371277fba6d80
145d5be896db4e8fda17039bed26100e38fae2f0
8a41e1edd4d31d08b7360d7e5964c1c40a7aa1b6
1e4f87f5a13e34a457b537e9d13a212e6c5b754f
6db83db3eb96809da3e680464b152f82785e38e6
e8b5f0d549b1b76611c7374bed9ceec7d09fa847
22c4272bf4ea04689fc0ea08e637caa46ba12c98
092b58d13d658baebbf03a6d5209f368f19e50a8
b33bd7a3be1cbcc8d255178307976b7762125b18
supasonic added a commit to supasonic/Mintcoin-Desktop-Wallet that referenced this pull request Apr 30, 2016
Break up CAddrMan's IMPLEMENT_SERIALIZE


overhaul serialization code

The implementation of each class' serialization/deserialization is no longer
passed within a macro. The implementation now lies within a template of form:

template <typename T, typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
    size_t nSerSize = 0;
    /* CODE */
    return nSerSize;
}

In cases when codepath should depend on whether or not we are just deserializing
(old fGetSize, fWrite, fRead flags) an additional clause can be used:
bool fRead = boost::is_same<Operation, CSerActionUnserialize>();

The IMPLEMENT_SERIALIZE macro will now be a freestanding clause added within
class' body (similiar to Qt's Q_OBJECT) to implement GetSerializeSize,
Serialize and Unserialize. These are now wrappers around
the "SerializationOp" template.


remove fields of ser_streamplaceholder

The nType and nVersion fields of stream objects are never accessed
from outside the class (or perhaps from the inside too, I haven't checked).
Thus no need to have them in a placeholder, whose only purpose is to
fill the "Stream" template parameter in serialization implementation.


rework overhauled serialization methods to non-static

Thanks to Pieter Wuille for most of the work on this commit.
I did not fixup the overhaul commit, because a rebase conflicted
with "remove fields of ser_streamplaceholder".
I prefer not to risk making a mistake while resolving it.


Use CSizeComputer to avoid counting sizes in SerializationOp


Serializer simplifications after IMPLEMENT_SERIALIZE overhaul


Rename IMPLEMENT_SERIALIZE to ADD_SERIALIZE_METHODS


CBlockIndex()::SetNull() method to avoid code repetition


Move UpdateTime to pow


replace ComputeMinWork with CheckMinWork


Fix a few "Uninitialized scalar field" warnings

Fix a few warnings reported by Coverity.
None of these is critical, but making sure that class fields are
initialized can avoid heisenbugs.


Move CBlockIndex::GetBlockWork() to pow::GetProofIncrement(nBits)


Do merkle root and txid duplicates check simultaneously

Move the txid duplicates check into BuildMerkleTree, where it can be done
much more efficiently (without needing to build a full txid set to detect
duplicates).

The previous version (using the std::set<uint256> to detect duplicates) was
also slightly too weak. A block mined with actual duplicate transactions
(which is invalid, due to the inputs of the duplicated transactions being
seen as double spends) would trigger the duplicates logic, resulting in the
block not being stored on disk, and rerequested. This change fixes that by
only triggering in the case of duplicated transactions that can actually
result in an identical merkle root.


Move CMerkleTx to wallet.cpp/h

It is only used by the wallet so it has no place in main


Clean up CMerkleTx::SetMerkleBranch.

The case SetMerkleBranch(NULL) was never actually used, and thus the
involved code (loading the block from disk) can be removed and the
implementation simplified.


Use OR of respective block flags for masks


checkpoints.cpp depends on main, it can use mapBlockIndex directly


Introduce BlockMap type for mapBlockIndex


Use boost::unordered_map for mapBlockIndex


Use memcmp for uint256 equality/inequality


Decouple CChain from mapBlockIndex


Move CBlockIndex, CChain and related code out of main


MOVEONLY: Move void UpdateTime() from pow.o to miner.o (plus fix incl…

…ude main.h -> chain.h)


CBlockIndex::GetBlockWork() + GetProofIncrement(nBits) -> GetBlockPro…

…of(CBlockIndex)


Implement "getchaintips" RPC command to monitor blockchain forks.

Port over chronokings/huntercoin#19 from
Huntercoin:  This implements a new RPC command "getchaintips" that can be
used to find all currently active chain heads.  This is similar to the
-printblocktree startup option, but it can be used without restarting
just via the RPC interface on a running daemon.


BTC Commit(s):
b069750d3f27c96a83700a08a2bb819902268857
3d796f89962842e91e7d88e57c1d2d579f01052e
5d96b4ae0188fcad36105642c5d69249d37fdbb5
84881f8c472cc67dc757686eb7dc3b495b13cab8
31e9a8384a77947f6777d035992f4734618ed206
47eb76597efb7dadb36dd98bc20bd80b2db9cd50
3f6540ad8f9c7b45a0dd2b260a282d3adad2406f
834e46e847188df513b8b57ab30fe9940f2b2dd0
c2c02f3fa99385f5a5be722fda6f71522c93bdaa
654871d43677947d124673c9e0dd2984f0d3ca61
8bdd2877c4f959b0c4b93f3d9d1f465fb4960f3f
b343c1a1e34f851e70649ad1f49855a7d878f9ef
584a358997e52a87e8c5402269c7fb3784ed2065
0101483f46396a7f1d19a9d29a1da15639ce4233
4b0deb3b2df5882061ae6c44947eda831420cd5e
910526d8487e5db04b4f280efcd05d95e6dc273f
a0dbe433bdb3f22be639fbb675c371277fba6d80
145d5be896db4e8fda17039bed26100e38fae2f0
8a41e1edd4d31d08b7360d7e5964c1c40a7aa1b6
1e4f87f5a13e34a457b537e9d13a212e6c5b754f
6db83db3eb96809da3e680464b152f82785e38e6
e8b5f0d549b1b76611c7374bed9ceec7d09fa847
22c4272bf4ea04689fc0ea08e637caa46ba12c98
092b58d13d658baebbf03a6d5209f368f19e50a8
b33bd7a3be1cbcc8d255178307976b7762125b18
supasonic added a commit to supasonic/Mintcoin-Desktop-Wallet that referenced this pull request May 13, 2016
Break up CAddrMan's IMPLEMENT_SERIALIZE

overhaul serialization code

The implementation of each class' serialization/deserialization is no longer
passed within a macro. The implementation now lies within a template of form:

template <typename T, typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
    size_t nSerSize = 0;
    /* CODE */
    return nSerSize;
}

In cases when codepath should depend on whether or not we are just deserializing
(old fGetSize, fWrite, fRead flags) an additional clause can be used:
bool fRead = boost::is_same<Operation, CSerActionUnserialize>();

The IMPLEMENT_SERIALIZE macro will now be a freestanding clause added within
class' body (similiar to Qt's Q_OBJECT) to implement GetSerializeSize,
Serialize and Unserialize. These are now wrappers around
the "SerializationOp" template.

remove fields of ser_streamplaceholder

The nType and nVersion fields of stream objects are never accessed
from outside the class (or perhaps from the inside too, I haven't checked).
Thus no need to have them in a placeholder, whose only purpose is to
fill the "Stream" template parameter in serialization implementation.

rework overhauled serialization methods to non-static

Thanks to Pieter Wuille for most of the work on this commit.
I did not fixup the overhaul commit, because a rebase conflicted
with "remove fields of ser_streamplaceholder".
I prefer not to risk making a mistake while resolving it.

Use CSizeComputer to avoid counting sizes in SerializationOp

Serializer simplifications after IMPLEMENT_SERIALIZE overhaul

Rename IMPLEMENT_SERIALIZE to ADD_SERIALIZE_METHODS

CBlockIndex()::SetNull() method to avoid code repetition

Move UpdateTime to pow

replace ComputeMinWork with CheckMinWork

Fix a few "Uninitialized scalar field" warnings

Fix a few warnings reported by Coverity.
None of these is critical, but making sure that class fields are
initialized can avoid heisenbugs.

Move CBlockIndex::GetBlockWork() to pow::GetProofIncrement(nBits)

Do merkle root and txid duplicates check simultaneously

Move the txid duplicates check into BuildMerkleTree, where it can be done
much more efficiently (without needing to build a full txid set to detect
duplicates).

The previous version (using the std::set<uint256> to detect duplicates) was
also slightly too weak. A block mined with actual duplicate transactions
(which is invalid, due to the inputs of the duplicated transactions being
seen as double spends) would trigger the duplicates logic, resulting in the
block not being stored on disk, and rerequested. This change fixes that by
only triggering in the case of duplicated transactions that can actually
result in an identical merkle root.

Move CMerkleTx to wallet.cpp/h

It is only used by the wallet so it has no place in main

Clean up CMerkleTx::SetMerkleBranch.

The case SetMerkleBranch(NULL) was never actually used, and thus the
involved code (loading the block from disk) can be removed and the
implementation simplified.

Use OR of respective block flags for masks

checkpoints.cpp depends on main, it can use mapBlockIndex directly

Introduce BlockMap type for mapBlockIndex

Use boost::unordered_map for mapBlockIndex

Use memcmp for uint256 equality/inequality

Decouple CChain from mapBlockIndex

Move CBlockIndex, CChain and related code out of main

MOVEONLY: Move void UpdateTime() from pow.o to miner.o (plus fix incl…

…ude main.h -> chain.h)

CBlockIndex::GetBlockWork() + GetProofIncrement(nBits) -> GetBlockPro…

…of(CBlockIndex)

Implement "getchaintips" RPC command to monitor blockchain forks.

Port over chronokings/huntercoin#19 from
Huntercoin:  This implements a new RPC command "getchaintips" that can be
used to find all currently active chain heads.  This is similar to the
-printblocktree startup option, but it can be used without restarting
just via the RPC interface on a running daemon.

BTC Commit(s):
b069750d3f27c96a83700a08a2bb819902268857
3d796f89962842e91e7d88e57c1d2d579f01052e
5d96b4ae0188fcad36105642c5d69249d37fdbb5
84881f8c472cc67dc757686eb7dc3b495b13cab8
31e9a8384a77947f6777d035992f4734618ed206
47eb76597efb7dadb36dd98bc20bd80b2db9cd50
3f6540ad8f9c7b45a0dd2b260a282d3adad2406f
834e46e847188df513b8b57ab30fe9940f2b2dd0
c2c02f3fa99385f5a5be722fda6f71522c93bdaa
654871d43677947d124673c9e0dd2984f0d3ca61
8bdd2877c4f959b0c4b93f3d9d1f465fb4960f3f
b343c1a1e34f851e70649ad1f49855a7d878f9ef
584a358997e52a87e8c5402269c7fb3784ed2065
0101483f46396a7f1d19a9d29a1da15639ce4233
4b0deb3b2df5882061ae6c44947eda831420cd5e
910526d8487e5db04b4f280efcd05d95e6dc273f
a0dbe433bdb3f22be639fbb675c371277fba6d80
145d5be896db4e8fda17039bed26100e38fae2f0
8a41e1edd4d31d08b7360d7e5964c1c40a7aa1b6
1e4f87f5a13e34a457b537e9d13a212e6c5b754f
6db83db3eb96809da3e680464b152f82785e38e6
e8b5f0d549b1b76611c7374bed9ceec7d09fa847
22c4272bf4ea04689fc0ea08e637caa46ba12c98
092b58d13d658baebbf03a6d5209f368f19e50a8
b33bd7a3be1cbcc8d255178307976b7762125b18
supasonic added a commit to supasonic/Mintcoin-Desktop-Wallet that referenced this pull request May 13, 2016
Break up CAddrMan's IMPLEMENT_SERIALIZE

overhaul serialization code

The implementation of each class' serialization/deserialization is no longer
passed within a macro. The implementation now lies within a template of form:

template <typename T, typename Stream, typename Operation>
inline static size_t SerializationOp(T thisPtr, Stream& s, Operation ser_action, int nType, int nVersion) {
    size_t nSerSize = 0;
    /* CODE */
    return nSerSize;
}

In cases when codepath should depend on whether or not we are just deserializing
(old fGetSize, fWrite, fRead flags) an additional clause can be used:
bool fRead = boost::is_same<Operation, CSerActionUnserialize>();

The IMPLEMENT_SERIALIZE macro will now be a freestanding clause added within
class' body (similiar to Qt's Q_OBJECT) to implement GetSerializeSize,
Serialize and Unserialize. These are now wrappers around
the "SerializationOp" template.

remove fields of ser_streamplaceholder

The nType and nVersion fields of stream objects are never accessed
from outside the class (or perhaps from the inside too, I haven't checked).
Thus no need to have them in a placeholder, whose only purpose is to
fill the "Stream" template parameter in serialization implementation.

rework overhauled serialization methods to non-static

Thanks to Pieter Wuille for most of the work on this commit.
I did not fixup the overhaul commit, because a rebase conflicted
with "remove fields of ser_streamplaceholder".
I prefer not to risk making a mistake while resolving it.

Use CSizeComputer to avoid counting sizes in SerializationOp

Serializer simplifications after IMPLEMENT_SERIALIZE overhaul

Rename IMPLEMENT_SERIALIZE to ADD_SERIALIZE_METHODS

CBlockIndex()::SetNull() method to avoid code repetition

Move UpdateTime to pow

replace ComputeMinWork with CheckMinWork

Fix a few "Uninitialized scalar field" warnings

Fix a few warnings reported by Coverity.
None of these is critical, but making sure that class fields are
initialized can avoid heisenbugs.

Move CBlockIndex::GetBlockWork() to pow::GetProofIncrement(nBits)

Do merkle root and txid duplicates check simultaneously

Move the txid duplicates check into BuildMerkleTree, where it can be done
much more efficiently (without needing to build a full txid set to detect
duplicates).

The previous version (using the std::set<uint256> to detect duplicates) was
also slightly too weak. A block mined with actual duplicate transactions
(which is invalid, due to the inputs of the duplicated transactions being
seen as double spends) would trigger the duplicates logic, resulting in the
block not being stored on disk, and rerequested. This change fixes that by
only triggering in the case of duplicated transactions that can actually
result in an identical merkle root.

Move CMerkleTx to wallet.cpp/h

It is only used by the wallet so it has no place in main

Clean up CMerkleTx::SetMerkleBranch.

The case SetMerkleBranch(NULL) was never actually used, and thus the
involved code (loading the block from disk) can be removed and the
implementation simplified.

Use OR of respective block flags for masks

checkpoints.cpp depends on main, it can use mapBlockIndex directly

Introduce BlockMap type for mapBlockIndex

Use boost::unordered_map for mapBlockIndex

Use memcmp for uint256 equality/inequality

Decouple CChain from mapBlockIndex

Move CBlockIndex, CChain and related code out of main

MOVEONLY: Move void UpdateTime() from pow.o to miner.o (plus fix incl…

…ude main.h -> chain.h)

CBlockIndex::GetBlockWork() + GetProofIncrement(nBits) -> GetBlockPro…

…of(CBlockIndex)

Implement "getchaintips" RPC command to monitor blockchain forks.

Port over chronokings/huntercoin#19 from
Huntercoin:  This implements a new RPC command "getchaintips" that can be
used to find all currently active chain heads.  This is similar to the
-printblocktree startup option, but it can be used without restarting
just via the RPC interface on a running daemon.

BTC Commit(s):
b069750d3f27c96a83700a08a2bb819902268857
3d796f89962842e91e7d88e57c1d2d579f01052e
5d96b4ae0188fcad36105642c5d69249d37fdbb5
84881f8c472cc67dc757686eb7dc3b495b13cab8
31e9a8384a77947f6777d035992f4734618ed206
47eb76597efb7dadb36dd98bc20bd80b2db9cd50
3f6540ad8f9c7b45a0dd2b260a282d3adad2406f
834e46e847188df513b8b57ab30fe9940f2b2dd0
c2c02f3fa99385f5a5be722fda6f71522c93bdaa
654871d43677947d124673c9e0dd2984f0d3ca61
8bdd2877c4f959b0c4b93f3d9d1f465fb4960f3f
b343c1a1e34f851e70649ad1f49855a7d878f9ef
584a358997e52a87e8c5402269c7fb3784ed2065
0101483f46396a7f1d19a9d29a1da15639ce4233
4b0deb3b2df5882061ae6c44947eda831420cd5e
910526d8487e5db04b4f280efcd05d95e6dc273f
a0dbe433bdb3f22be639fbb675c371277fba6d80
145d5be896db4e8fda17039bed26100e38fae2f0
8a41e1edd4d31d08b7360d7e5964c1c40a7aa1b6
1e4f87f5a13e34a457b537e9d13a212e6c5b754f
6db83db3eb96809da3e680464b152f82785e38e6
e8b5f0d549b1b76611c7374bed9ceec7d09fa847
22c4272bf4ea04689fc0ea08e637caa46ba12c98
092b58d13d658baebbf03a6d5209f368f19e50a8
b33bd7a3be1cbcc8d255178307976b7762125b18
reddink pushed a commit to reddcoin-project/reddcoin-3.10 that referenced this pull request May 27, 2020
Port over chronokings/huntercoin#19 from
Huntercoin:  This implements a new RPC command "getchaintips" that can be
used to find all currently active chain heads.  This is similar to the
-printblocktree startup option, but it can be used without restarting
just via the RPC interface on a running daemon.

(cherry picked from commit b33bd7a)
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

2 participants