Skip to content

Commit 7ed2768

Browse files
authored
Merge pull request #1421 from psgreco/master-fixlock
Fix tests and build warnings
2 parents 1ded388 + b92a3ce commit 7ed2768

File tree

7 files changed

+59
-40
lines changed

7 files changed

+59
-40
lines changed

build_msvc/bitcoind/bitcoind.vcxproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@
5757
<Target Name="AfterBuild">
5858
<Copy SourceFiles="$(ConfigIniIn)" DestinationFiles="$(ConfigIniOut)" ></Copy>
5959
<ReplaceInFile FilePath="$(ConfigIniOut)"
60-
Replace="@PACKAGE_NAME@" By="Bitcoin Core"></ReplaceInFile>
60+
Replace="@PACKAGE_NAME@" By="Elements Core"></ReplaceInFile>
6161
<ReplaceInFile FilePath="$(ConfigIniOut)"
62-
Replace="@PACKAGE_BUGREPORT@" By="https://github.com/bitcoin/bitcoin/issues"></ReplaceInFile>
62+
Replace="@PACKAGE_BUGREPORT@" By="https://github.com/ElementsProject/elements/issues"></ReplaceInFile>
6363
<ReplaceInFile FilePath="$(ConfigIniOut)"
6464
Replace="@abs_top_srcdir@" By="..\.." ToFullPath="true"></ReplaceInFile>
6565
<ReplaceInFile FilePath="$(ConfigIniOut)"

src/block_proof.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ static bool CheckProofGeneric(const CBlockHeader& block, const uint32_t max_bloc
4343
| SCRIPT_VERIFY_SIGPUSHONLY // Witness is push-only
4444
| SCRIPT_VERIFY_LOW_S // Stop easiest signature fiddling
4545
| SCRIPT_VERIFY_WITNESS // Witness and to enforce cleanstack
46-
| (is_dyna ? 0 : SCRIPT_NO_SIGHASH_BYTE); // Non-dynafed blocks do not have sighash byte
46+
| (is_dyna ? SCRIPT_VERIFY_NONE : SCRIPT_NO_SIGHASH_BYTE); // Non-dynafed blocks do not have sighash byte
4747
return GenericVerifyScript(scriptSig, witness, challenge, proof_flags, block);
4848
}
4949

src/net_processing.cpp

+22-21
Original file line numberDiff line numberDiff line change
@@ -2122,29 +2122,30 @@ void PeerManagerImpl::ProcessHeadersMessage(CNode& pfrom, const Peer& peer,
21222122
// If we are already too far ahead of where we want to be on headers, discard
21232123
// the received headers. We can still get ahead by up to a single maximum-sized
21242124
// headers message here, but never further, so that's fine.
2125-
if (pindexBestHeader) {
2126-
int64_t headers_ahead = pindexBestHeader->nHeight - m_chainman.ActiveHeight();
2127-
bool too_far_ahead = node::fTrimHeaders && (headers_ahead >= node::nHeaderDownloadBuffer);
2128-
if (too_far_ahead) {
2129-
LOCK(cs_main);
2130-
CNodeState *nodestate = State(pfrom.GetId());
2131-
if ((nodestate->pindexBestKnownBlock == nullptr) ||
2125+
if (node::fTrimHeaders) {
2126+
LOCK(cs_main);
2127+
if (pindexBestHeader) {
2128+
int64_t headers_ahead = pindexBestHeader->nHeight - m_chainman.ActiveHeight();
2129+
if (headers_ahead >= node::nHeaderDownloadBuffer) {
2130+
CNodeState *nodestate = State(pfrom.GetId());
2131+
if ((nodestate->pindexBestKnownBlock == nullptr) ||
21322132
(nodestate->pindexBestKnownBlock->nHeight < m_chainman.ActiveHeight())) {
2133-
// Our notion of what blocks a peer has available is based on its pindexBestKnownBlock,
2134-
// which is based on headers received from it. If we don't have one, or it's too old,
2135-
// then we can never get blocks from this peer until we accept headers from it first.
2136-
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());
2137-
} else {
2138-
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());
2139-
if (nodestate->fSyncStarted) {
2140-
// Cancel sync from this node, so we don't penalize it later.
2141-
// This will cause us to automatically start syncing from a different node (or restart syncing from the same node) later,
2142-
// if we still need to sync headers.
2143-
nSyncStarted--;
2144-
nodestate->fSyncStarted = false;
2145-
nodestate->m_headers_sync_timeout = 0us;
2133+
// Our notion of what blocks a peer has available is based on its pindexBestKnownBlock,
2134+
// which is based on headers received from it. If we don't have one, or it's too old,
2135+
// then we can never get blocks from this peer until we accept headers from it first.
2136+
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());
2137+
} else {
2138+
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());
2139+
if (nodestate->fSyncStarted) {
2140+
// Cancel sync from this node, so we don't penalize it later.
2141+
// This will cause us to automatically start syncing from a different node (or restart syncing from the same node) later,
2142+
// if we still need to sync headers.
2143+
nSyncStarted--;
2144+
nodestate->fSyncStarted = false;
2145+
nodestate->m_headers_sync_timeout = 0us;
2146+
}
2147+
return;
21462148
}
2147-
return;
21482149
}
21492150
}
21502151
}

src/rpc/request.cpp

+5-2
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,10 @@ static fs::path GetMainchainAuthCookieFile()
139139
if (gArgs.GetChainName() == "liquidv1") {
140140
cookie_file = ".cookie";
141141
}
142-
return fsbridge::AbsPathJoin(GetMainchainDefaultDataDir(), fs::PathFromString(gArgs.GetArg("-mainchainrpccookiefile", cookie_file)));
142+
fs::path cookie_path = fs::PathFromString(gArgs.GetArg("-mainchainrpccookiefile", cookie_file));
143+
if (cookie_path.is_absolute())
144+
return cookie_path;
145+
return fsbridge::AbsPathJoin(GetMainchainDefaultDataDir(), cookie_path);
143146
}
144147

145148
bool GetMainchainAuthCookie(std::string *cookie_out)
@@ -148,7 +151,7 @@ bool GetMainchainAuthCookie(std::string *cookie_out)
148151
std::string cookie;
149152

150153
std::filesystem::path filepath = GetMainchainAuthCookieFile();
151-
file.open(filepath.string().c_str());
154+
file.open(filepath);
152155
if (!file.is_open())
153156
return false;
154157
std::getline(file, cookie);

test/functional/feature_confidential_transactions.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
)
2626
import os
2727
import re
28+
import tempfile
2829

2930
from test_framework.liquid_addr import (
3031
encode,
@@ -51,7 +52,7 @@ def skip_test_if_missing_module(self):
5152
self.skip_if_no_wallet()
5253

5354
def test_wallet_recovery(self):
54-
file_path = "/tmp/blind_details"
55+
file_path = os.path.join(tempfile.gettempdir(), "blind_details")
5556
try:
5657
os.remove(file_path)
5758
except OSError:

test/functional/feature_discount_ct.py

+25-12
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from decimal import Decimal
77
from test_framework.test_framework import BitcoinTestFramework
88
from test_framework.util import (
9+
assert_approx,
910
assert_equal,
1011
)
1112

@@ -80,10 +81,12 @@ def run_test(self):
8081
assert_equal(len(vout), 3)
8182
assert_equal(tx['fee']['bitcoin'], Decimal('-0.00000326'))
8283
assert_equal(decoded['vsize'], 326)
83-
assert_equal(decoded['weight'], 1302)
84+
# tx weight can be 1301 or 1302, accept both
85+
assert_approx(decoded['weight'], 1301.5, 0.5)
8486
self.generate(node0, 1)
8587
tx = node1.getrawtransaction(txid, True)
86-
assert_equal(tx['discountweight'], 1302)
88+
# tx discountweight can be 1301 or 1302, accept both
89+
assert_approx(tx['discountweight'], 1301.5, 0.5)
8790
assert_equal(tx['discountvsize'], 326)
8891

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

107112
self.log.info("Send explicit tx to node 1")
@@ -116,10 +121,12 @@ def run_test(self):
116121
assert_equal(len(vout), 3)
117122
assert_equal(tx['fee']['bitcoin'], Decimal('-0.00000326'))
118123
assert_equal(decoded['vsize'], 326)
119-
assert_equal(decoded['weight'], 1302)
124+
# tx weight can be 1301 or 1302, accept both
125+
assert_approx(decoded['weight'], 1301.5, 0.5)
120126
self.generate(node0, 1)
121127
tx = node1.getrawtransaction(txid, True)
122-
assert_equal(tx['discountweight'], 1302)
128+
# tx weight can be 1301 or 1302, accept both
129+
assert_approx(tx['discountweight'], 1301.5, 0.5)
123130
assert_equal(tx['discountvsize'], 326)
124131

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

143152
self.log.info("Send confidential (discounted) tx to node 1")
@@ -161,8 +170,10 @@ def run_test(self):
161170
else:
162171
assert_equal(decoded['fee'][bitcoin], Decimal('0.00000326'))
163172
assert_equal(decoded['vsize'], 2575)
164-
assert_equal(decoded['weight'], 10300)
165-
assert_equal(decoded['discountweight'], 1302)
173+
# tx weight can be 10299 or 10300, accept both
174+
assert_approx(decoded['weight'], 10299.5, 0.5)
175+
# tx discountweight can be 1301 or 1302, accept both
176+
assert_approx(decoded['discountweight'], 1301.5, 0.5)
166177
assert_equal(decoded['discountvsize'], 326)
167178

168179
# node0 only has vsize
@@ -191,8 +202,10 @@ def run_test(self):
191202
else:
192203
assert_equal(decoded['fee'][bitcoin], Decimal('0.00000033'))
193204
assert_equal(decoded['vsize'], 2575)
194-
assert_equal(decoded['weight'], 10300)
195-
assert_equal(decoded['discountweight'], 1302)
205+
# tx weight can be 10299 or 10300, accept both
206+
assert_approx(decoded['weight'], 10299.5, 0.5)
207+
# tx discountweight can be 1301 or 1302, accept both
208+
assert_approx(decoded['discountweight'], 1301.5, 0.5)
196209
assert_equal(decoded['discountvsize'], 326)
197210
# node0 only has vsize
198211
tx = node0.getrawtransaction(txid, True)

test/functional/feature_fedpeg.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python3
22

33
import time
4+
import os
45

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

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

0 commit comments

Comments
 (0)