Skip to content

2025 implement bip352 receiving #8

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

Open
wants to merge 20 commits into
base: implement-bip352-sending
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/interfaces/chain.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class FoundBlock
//! Read block data from disk. If the block exists but doesn't have data
//! (for example due to pruning), the CBlock variable will be set to null.
FoundBlock& data(CBlock& data) { m_data = &data; return *this; }
//! Read block's undo data from disk.
FoundBlock& undoData(CBlockUndo& undo) { m_undo = &undo; return *this; }

uint256* m_hash = nullptr;
int* m_height = nullptr;
Expand All @@ -71,6 +73,7 @@ class FoundBlock
CBlockLocator* m_locator = nullptr;
const FoundBlock* m_next_block = nullptr;
CBlock* m_data = nullptr;
CBlockUndo* m_undo = nullptr;
mutable bool found = false;
};

Expand Down Expand Up @@ -318,7 +321,7 @@ class Chain
{
public:
virtual ~Notifications() = default;
virtual void transactionAddedToMempool(const CTransactionRef& tx) {}
virtual void transactionAddedToMempool(const CTransactionRef& tx, const std::map<COutPoint, Coin>& spent_coins) {}
virtual void transactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason) {}
virtual void blockConnected(ChainstateRole role, const BlockInfo& block) {}
virtual void blockDisconnected(const BlockInfo& block) {}
Expand Down
7 changes: 7 additions & 0 deletions src/key.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,13 @@ void CKey::MakeNewKey(bool fCompressedIn) {
fCompressed = fCompressedIn;
}

bool CKey::TweakAdd(const unsigned char *tweak32)
{
assert(keydata);
// Modify the current CKey's data directly.
return secp256k1_ec_seckey_tweak_add(secp256k1_context_sign, keydata->data(), tweak32);
}

CPrivKey CKey::GetPrivKey() const {
assert(keydata);
CPrivKey seckey;
Expand Down
2 changes: 2 additions & 0 deletions src/key.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,8 @@ class CKey
//! Generate a new private key using a cryptographic PRNG.
void MakeNewKey(bool fCompressed);

bool TweakAdd(const unsigned char *tweak32);

/**
* Convert the private key to a CPrivKey (serialized OpenSSL private key data).
* This is expensive.
Expand Down
16 changes: 13 additions & 3 deletions src/node/interfaces.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include <sync.h>
#include <txmempool.h>
#include <uint256.h>
#include <undo.h>
#include <univalue.h>
#include <util/check.h>
#include <util/result.h>
Expand Down Expand Up @@ -446,6 +447,10 @@ bool FillBlock(const CBlockIndex* index, const FoundBlock& block, UniqueLock<Rec
REVERSE_LOCK(lock);
if (!blockman.ReadBlock(*block.m_data, *index)) block.m_data->SetNull();
}
if (block.m_undo) {
REVERSE_LOCK(lock);
if (!blockman.ReadBlockUndo(*block.m_undo, *index)) block.m_undo->vtxundo.clear();
}
block.found = true;
return true;
}
Expand All @@ -456,9 +461,9 @@ class NotificationsProxy : public CValidationInterface
explicit NotificationsProxy(std::shared_ptr<Chain::Notifications> notifications)
: m_notifications(std::move(notifications)) {}
virtual ~NotificationsProxy() = default;
void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t mempool_sequence) override
void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t mempool_sequence, const std::map<COutPoint, Coin>& spent_coins) override
{
m_notifications->transactionAddedToMempool(tx.info.m_tx);
m_notifications->transactionAddedToMempool(tx.info.m_tx, spent_coins);
}
void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason reason, uint64_t mempool_sequence) override
{
Expand Down Expand Up @@ -860,7 +865,12 @@ class ChainImpl : public Chain
if (!m_node.mempool) return;
LOCK2(::cs_main, m_node.mempool->cs);
for (const CTxMemPoolEntry& entry : m_node.mempool->entryAll()) {
notifications.transactionAddedToMempool(entry.GetSharedTx());
std::map<COutPoint, Coin> spent_coins;
for (const CTxIn& txin : entry.GetTx().vin) {
spent_coins[txin.prevout];
}
findCoins(spent_coins);
notifications.transactionAddedToMempool(entry.GetSharedTx(), spent_coins);
}
}
bool hasAssumedValidChain() override
Expand Down
6 changes: 6 additions & 0 deletions src/outputtype.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ static const std::string OUTPUT_TYPE_STRING_LEGACY = "legacy";
static const std::string OUTPUT_TYPE_STRING_P2SH_SEGWIT = "p2sh-segwit";
static const std::string OUTPUT_TYPE_STRING_BECH32 = "bech32";
static const std::string OUTPUT_TYPE_STRING_BECH32M = "bech32m";
static const std::string OUTPUT_TYPE_STRING_SILENT_PAYMENTS = "silent-payments";
static const std::string OUTPUT_TYPE_STRING_UNKNOWN = "unknown";

std::optional<OutputType> ParseOutputType(const std::string& type)
Expand All @@ -31,6 +32,8 @@ std::optional<OutputType> ParseOutputType(const std::string& type)
return OutputType::BECH32;
} else if (type == OUTPUT_TYPE_STRING_BECH32M) {
return OutputType::BECH32M;
} else if (type == OUTPUT_TYPE_STRING_SILENT_PAYMENTS) {
return OutputType::SILENT_PAYMENTS;
}
return std::nullopt;
}
Expand All @@ -42,6 +45,7 @@ const std::string& FormatOutputType(OutputType type)
case OutputType::P2SH_SEGWIT: return OUTPUT_TYPE_STRING_P2SH_SEGWIT;
case OutputType::BECH32: return OUTPUT_TYPE_STRING_BECH32;
case OutputType::BECH32M: return OUTPUT_TYPE_STRING_BECH32M;
case OutputType::SILENT_PAYMENTS: return OUTPUT_TYPE_STRING_SILENT_PAYMENTS;
case OutputType::UNKNOWN: return OUTPUT_TYPE_STRING_UNKNOWN;
} // no default case, so the compiler can warn about missing cases
assert(false);
Expand All @@ -63,6 +67,7 @@ CTxDestination GetDestinationForKey(const CPubKey& key, OutputType type)
}
}
case OutputType::BECH32M:
case OutputType::SILENT_PAYMENTS:
case OutputType::UNKNOWN: {} // This function should never be used with BECH32M or UNKNOWN, so let it assert
} // no default case, so the compiler can warn about missing cases
assert(false);
Expand Down Expand Up @@ -102,6 +107,7 @@ CTxDestination AddAndGetDestinationForScript(FlatSigningProvider& keystore, cons
}
}
case OutputType::BECH32M:
case OutputType::SILENT_PAYMENTS:
case OutputType::UNKNOWN: {} // This function should not be used for BECH32M or UNKNOWN, so let it assert
} // no default case, so the compiler can warn about missing cases
assert(false);
Expand Down
2 changes: 2 additions & 0 deletions src/outputtype.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ enum class OutputType {
P2SH_SEGWIT,
BECH32,
BECH32M,
SILENT_PAYMENTS,
UNKNOWN,
};

Expand All @@ -27,6 +28,7 @@ static constexpr auto OUTPUT_TYPES = std::array{
OutputType::P2SH_SEGWIT,
OutputType::BECH32,
OutputType::BECH32M,
OutputType::SILENT_PAYMENTS,
};

std::optional<OutputType> ParseOutputType(const std::string& str);
Expand Down
2 changes: 1 addition & 1 deletion src/policy/fees.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ CBlockPolicyEstimator::CBlockPolicyEstimator(const fs::path& estimation_filepath

CBlockPolicyEstimator::~CBlockPolicyEstimator() = default;

void CBlockPolicyEstimator::TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t /*unused*/)
void CBlockPolicyEstimator::TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t /*unused*/, const std::map<COutPoint, Coin>& /*unused*/)
{
processTransaction(tx);
}
Expand Down
2 changes: 1 addition & 1 deletion src/policy/fees.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ class CBlockPolicyEstimator : public CValidationInterface

protected:
/** Overridden from CValidationInterface. */
void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t /*unused*/) override
void TransactionAddedToMempool(const NewMempoolTransactionInfo& tx, uint64_t /*unused*/, const std::map<COutPoint, Coin>& /*unused*/) override
EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator);
void TransactionRemovedFromMempool(const CTransactionRef& tx, MemPoolRemovalReason /*unused*/, uint64_t /*unused*/) override
EXCLUSIVE_LOCKS_REQUIRED(!m_cs_fee_estimator);
Expand Down
17 changes: 17 additions & 0 deletions src/pubkey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,23 @@ std::optional<std::pair<XOnlyPubKey, bool>> XOnlyPubKey::CreateTapTweak(const ui
return ret;
}

bool CPubKey::TweakAdd(const unsigned char *tweak32)
{
secp256k1_pubkey original_pubkey;
int return_val = secp256k1_ec_pubkey_parse(secp256k1_context_static, &original_pubkey, data(), size());
assert(return_val);

return_val = secp256k1_ec_pubkey_tweak_add(secp256k1_context_static, &original_pubkey, tweak32);
assert(return_val);

unsigned char pubkey_bytes[COMPRESSED_SIZE];
size_t publen = COMPRESSED_SIZE;
return_val = secp256k1_ec_pubkey_serialize(secp256k1_context_static, pubkey_bytes, &publen, &original_pubkey, SECP256K1_EC_COMPRESSED);
assert(return_val);

Set(pubkey_bytes, pubkey_bytes + publen);
return IsValid();
}

bool CPubKey::Verify(const uint256 &hash, const std::vector<unsigned char>& vchSig) const {
if (!IsValid())
Expand Down
1 change: 1 addition & 0 deletions src/pubkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ class CPubKey
* If this public key is not fully valid, the return value will be false.
*/
bool Verify(const uint256& hash, const std::vector<unsigned char>& vchSig) const;
bool TweakAdd(const unsigned char *tweak32);

/**
* Check whether a signature is normalized (lower-S).
Expand Down
1 change: 1 addition & 0 deletions src/rpc/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@ static const CRPCConvertParam vRPCConvertParams[] =
{ "createwallet", 5, "descriptors"},
{ "createwallet", 6, "load_on_startup"},
{ "createwallet", 7, "external_signer"},
{ "createwallet", 8, "silent_payments" },
{ "restorewallet", 2, "load_on_startup"},
{ "loadwallet", 1, "load_on_startup"},
{ "unloadwallet", 1, "load_on_startup"},
Expand Down
4 changes: 3 additions & 1 deletion src/rpc/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,9 @@ class DescribeAddressVisitor

UniValue operator()(const V0SilentPaymentDestination& dest) const
{
return UniValue(UniValue::VOBJ);
UniValue obj(UniValue::VOBJ);
obj.pushKV("iswitness", false);
return obj;
}

UniValue operator()(const PubKeyDestination& dest) const
Expand Down
Loading
Loading