Skip to content

Commit

Permalink
Merge pull request #1421 from psgreco/master-fixlock
Browse files Browse the repository at this point in the history
Fix tests and build warnings
  • Loading branch information
delta1 authored Feb 24, 2025
2 parents 1ded388 + b92a3ce commit 7ed2768
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 40 deletions.
4 changes: 2 additions & 2 deletions build_msvc/bitcoind/bitcoind.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@
<Target Name="AfterBuild">
<Copy SourceFiles="$(ConfigIniIn)" DestinationFiles="$(ConfigIniOut)" ></Copy>
<ReplaceInFile FilePath="$(ConfigIniOut)"
Replace="@PACKAGE_NAME@" By="Bitcoin Core"></ReplaceInFile>
Replace="@PACKAGE_NAME@" By="Elements Core"></ReplaceInFile>
<ReplaceInFile FilePath="$(ConfigIniOut)"
Replace="@PACKAGE_BUGREPORT@" By="https://github.com/bitcoin/bitcoin/issues"></ReplaceInFile>
Replace="@PACKAGE_BUGREPORT@" By="https://github.com/ElementsProject/elements/issues"></ReplaceInFile>
<ReplaceInFile FilePath="$(ConfigIniOut)"
Replace="@abs_top_srcdir@" By="..\.." ToFullPath="true"></ReplaceInFile>
<ReplaceInFile FilePath="$(ConfigIniOut)"
Expand Down
2 changes: 1 addition & 1 deletion src/block_proof.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static bool CheckProofGeneric(const CBlockHeader& block, const uint32_t max_bloc
| SCRIPT_VERIFY_SIGPUSHONLY // Witness is push-only
| SCRIPT_VERIFY_LOW_S // Stop easiest signature fiddling
| SCRIPT_VERIFY_WITNESS // Witness and to enforce cleanstack
| (is_dyna ? 0 : SCRIPT_NO_SIGHASH_BYTE); // Non-dynafed blocks do not have sighash byte
| (is_dyna ? SCRIPT_VERIFY_NONE : SCRIPT_NO_SIGHASH_BYTE); // Non-dynafed blocks do not have sighash byte
return GenericVerifyScript(scriptSig, witness, challenge, proof_flags, block);
}

Expand Down
43 changes: 22 additions & 21 deletions src/net_processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2122,29 +2122,30 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, const Peer& peer,
// If we are already too far ahead of where we want to be on headers, discard
// the received headers. We can still get ahead by up to a single maximum-sized
// headers message here, but never further, so that's fine.
if (pindexBestHeader) {
int64_t headers_ahead = pindexBestHeader->nHeight - m_chainman.ActiveHeight();
bool too_far_ahead = node::fTrimHeaders && (headers_ahead >= node::nHeaderDownloadBuffer);
if (too_far_ahead) {
LOCK(cs_main);
CNodeState *nodestate = State(pfrom.GetId());
if ((nodestate->pindexBestKnownBlock == nullptr) ||
if (node::fTrimHeaders) {
LOCK(cs_main);
if (pindexBestHeader) {
int64_t headers_ahead = pindexBestHeader->nHeight - m_chainman.ActiveHeight();
if (headers_ahead >= node::nHeaderDownloadBuffer) {
CNodeState *nodestate = State(pfrom.GetId());
if ((nodestate->pindexBestKnownBlock == nullptr) ||
(nodestate->pindexBestKnownBlock->nHeight < m_chainman.ActiveHeight())) {
// Our notion of what blocks a peer has available is based on its pindexBestKnownBlock,
// which is based on headers received from it. If we don't have one, or it's too old,
// then we can never get blocks from this peer until we accept headers from it first.
LogPrint(BCLog::NET, "NOT discarding headers from peer=%d, to update its block availability. (current best header %d, active chain height %d)\n", pfrom.GetId(), pindexBestHeader->nHeight, m_chainman.ActiveHeight());
} else {
LogPrint(BCLog::NET, "Discarding received headers and pausing header sync from peer=%d, because we are too far ahead of block sync. (%d > %d)\n", pfrom.GetId(), pindexBestHeader->nHeight, m_chainman.ActiveHeight());
if (nodestate->fSyncStarted) {
// Cancel sync from this node, so we don't penalize it later.
// This will cause us to automatically start syncing from a different node (or restart syncing from the same node) later,
// if we still need to sync headers.
nSyncStarted--;
nodestate->fSyncStarted = false;
nodestate->m_headers_sync_timeout = 0us;
// Our notion of what blocks a peer has available is based on its pindexBestKnownBlock,
// which is based on headers received from it. If we don't have one, or it's too old,
// then we can never get blocks from this peer until we accept headers from it first.
LogPrint(BCLog::NET, "NOT discarding headers from peer=%d, to update its block availability. (current best header %d, active chain height %d)\n", pfrom.GetId(), pindexBestHeader->nHeight, m_chainman.ActiveHeight());
} else {
LogPrint(BCLog::NET, "Discarding received headers and pausing header sync from peer=%d, because we are too far ahead of block sync. (%d > %d)\n", pfrom.GetId(), pindexBestHeader->nHeight, m_chainman.ActiveHeight());
if (nodestate->fSyncStarted) {
// Cancel sync from this node, so we don't penalize it later.
// This will cause us to automatically start syncing from a different node (or restart syncing from the same node) later,
// if we still need to sync headers.
nSyncStarted--;
nodestate->fSyncStarted = false;
nodestate->m_headers_sync_timeout = 0us;
}
return;
}
return;
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/rpc/request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,10 @@ static fs::path GetMainchainAuthCookieFile()
if (gArgs.GetChainName() == "liquidv1") {
cookie_file = ".cookie";
}
return fsbridge::AbsPathJoin(GetMainchainDefaultDataDir(), fs::PathFromString(gArgs.GetArg("-mainchainrpccookiefile", cookie_file)));
fs::path cookie_path = fs::PathFromString(gArgs.GetArg("-mainchainrpccookiefile", cookie_file));
if (cookie_path.is_absolute())
return cookie_path;
return fsbridge::AbsPathJoin(GetMainchainDefaultDataDir(), cookie_path);
}

bool GetMainchainAuthCookie(std::string *cookie_out)
Expand All @@ -148,7 +151,7 @@ bool GetMainchainAuthCookie(std::string *cookie_out)
std::string cookie;

std::filesystem::path filepath = GetMainchainAuthCookieFile();
file.open(filepath.string().c_str());
file.open(filepath);
if (!file.is_open())
return false;
std::getline(file, cookie);
Expand Down
3 changes: 2 additions & 1 deletion test/functional/feature_confidential_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
)
import os
import re
import tempfile

from test_framework.liquid_addr import (
encode,
Expand All @@ -51,7 +52,7 @@ def skip_test_if_missing_module(self):
self.skip_if_no_wallet()

def test_wallet_recovery(self):
file_path = "/tmp/blind_details"
file_path = os.path.join(tempfile.gettempdir(), "blind_details")
try:
os.remove(file_path)
except OSError:
Expand Down
37 changes: 25 additions & 12 deletions test/functional/feature_discount_ct.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from decimal import Decimal
from test_framework.test_framework import BitcoinTestFramework
from test_framework.util import (
assert_approx,
assert_equal,
)

Expand Down Expand Up @@ -80,10 +81,12 @@ def run_test(self):
assert_equal(len(vout), 3)
assert_equal(tx['fee']['bitcoin'], Decimal('-0.00000326'))
assert_equal(decoded['vsize'], 326)
assert_equal(decoded['weight'], 1302)
# tx weight can be 1301 or 1302, accept both
assert_approx(decoded['weight'], 1301.5, 0.5)
self.generate(node0, 1)
tx = node1.getrawtransaction(txid, True)
assert_equal(tx['discountweight'], 1302)
# tx discountweight can be 1301 or 1302, accept both
assert_approx(tx['discountweight'], 1301.5, 0.5)
assert_equal(tx['discountvsize'], 326)

self.log.info("Send confidential tx to node 0")
Expand All @@ -98,10 +101,12 @@ def run_test(self):
assert_equal(len(vout), 3)
assert_equal(tx['fee']['bitcoin'], Decimal('-0.00002575'))
assert_equal(decoded['vsize'], 2575)
assert_equal(decoded['weight'], 10300)
# tx weight can be 10299 or 10300, accept both
assert_approx(decoded['weight'], 10299.5, 0.5)
self.generate(node0, 1)
tx = node1.getrawtransaction(txid, True)
assert_equal(tx['discountweight'], 1302)
# tx discountweight can be 1301 or 1302, accept both
assert_approx(tx['discountweight'], 1301.5, 0.5)
assert_equal(tx['discountvsize'], 326) # node1 has discountvsize

self.log.info("Send explicit tx to node 1")
Expand All @@ -116,10 +121,12 @@ def run_test(self):
assert_equal(len(vout), 3)
assert_equal(tx['fee']['bitcoin'], Decimal('-0.00000326'))
assert_equal(decoded['vsize'], 326)
assert_equal(decoded['weight'], 1302)
# tx weight can be 1301 or 1302, accept both
assert_approx(decoded['weight'], 1301.5, 0.5)
self.generate(node0, 1)
tx = node1.getrawtransaction(txid, True)
assert_equal(tx['discountweight'], 1302)
# tx weight can be 1301 or 1302, accept both
assert_approx(tx['discountweight'], 1301.5, 0.5)
assert_equal(tx['discountvsize'], 326)

self.log.info("Send confidential (undiscounted) tx to node 1")
Expand All @@ -134,10 +141,12 @@ def run_test(self):
assert_equal(len(vout), 3)
assert_equal(tx['fee']['bitcoin'], Decimal('-0.00002575'))
assert_equal(decoded['vsize'], 2575)
assert_equal(decoded['weight'], 10300)
# tx weight can be 10299 or 10300, accept both
assert_approx(decoded['weight'], 10299.5, 0.5)
self.generate(node0, 1)
tx = node1.getrawtransaction(txid, True)
assert_equal(tx['discountweight'], 1302)
# tx discountweight can be 1301 or 1302, accept both
assert_approx(tx['discountweight'], 1301.5, 0.5)
assert_equal(tx['discountvsize'], 326) # node1 has discountvsize

self.log.info("Send confidential (discounted) tx to node 1")
Expand All @@ -161,8 +170,10 @@ def run_test(self):
else:
assert_equal(decoded['fee'][bitcoin], Decimal('0.00000326'))
assert_equal(decoded['vsize'], 2575)
assert_equal(decoded['weight'], 10300)
assert_equal(decoded['discountweight'], 1302)
# tx weight can be 10299 or 10300, accept both
assert_approx(decoded['weight'], 10299.5, 0.5)
# tx discountweight can be 1301 or 1302, accept both
assert_approx(decoded['discountweight'], 1301.5, 0.5)
assert_equal(decoded['discountvsize'], 326)

# node0 only has vsize
Expand Down Expand Up @@ -191,8 +202,10 @@ def run_test(self):
else:
assert_equal(decoded['fee'][bitcoin], Decimal('0.00000033'))
assert_equal(decoded['vsize'], 2575)
assert_equal(decoded['weight'], 10300)
assert_equal(decoded['discountweight'], 1302)
# tx weight can be 10299 or 10300, accept both
assert_approx(decoded['weight'], 10299.5, 0.5)
# tx discountweight can be 1301 or 1302, accept both
assert_approx(decoded['discountweight'], 1301.5, 0.5)
assert_equal(decoded['discountvsize'], 326)
# node0 only has vsize
tx = node0.getrawtransaction(txid, True)
Expand Down
3 changes: 2 additions & 1 deletion test/functional/feature_fedpeg.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env python3

import time
import os

from test_framework.authproxy import JSONRPCException
from test_framework.test_framework import BitcoinTestFramework
Expand Down Expand Up @@ -152,7 +153,7 @@ def setup_network(self, split=False):
else:
# Need to specify where to find parent cookie file
datadir = get_datadir_path(self.options.tmpdir, n)
extra_args.append('-mainchainrpccookiefile='+datadir+"/" + parent_chain + "/.cookie")
extra_args.append('-mainchainrpccookiefile='+os.path.join(datadir, parent_chain, ".cookie"))

self.add_nodes(1, [extra_args], chain=["elementsregtest"])
self.start_node(2+n)
Expand Down

0 comments on commit 7ed2768

Please sign in to comment.