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

Stop node from using P2PKH outputs for staking #1002

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
2 changes: 0 additions & 2 deletions src/script/ismine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,7 @@ bool IsStakeableByMe(const CKeyStore &keystore, const CScript &script_pub_key)
IsMineInfo is_mine_info;
const isminetype is_mine = IsMine(keystore, script_pub_key, &is_mine_info);

// UNIT-E TODO: Restrict to witness programs only once #212 is merged (fixes #48)
switch (is_mine_info.type) {
case TX_PUBKEYHASH:
case TX_WITNESS_V0_KEYHASH: {
if (is_mine != ISMINE_SPENDABLE) {
// Non-remote-staking scripts can be used as stake only if they
Expand Down
2 changes: 1 addition & 1 deletion src/test/esperanza/walletextension_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ BOOST_FIXTURE_TEST_CASE(get_stakeable_coins, TestChain100Setup) {
}

// Make the first coinbase mature
CScript coinbase_script = GetScriptForDestination(coinbaseKey.GetPubKey().GetID());
CScript coinbase_script = GetScriptForDestination(WitnessV0KeyHash(coinbaseKey.GetPubKey().GetID()));
CreateAndProcessBlock({}, coinbase_script);

CTransaction &stakeable = coinbaseTxns.front();
Expand Down
2 changes: 1 addition & 1 deletion src/test/script_standard_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ BOOST_AUTO_TEST_CASE(script_standard_IsMine)
keystore.AddKey(keys[0]);
result = IsMine(keystore, scriptPubKey);
BOOST_CHECK_EQUAL(result, ISMINE_SPENDABLE);
BOOST_CHECK(IsStakeableByMe(keystore, scriptPubKey));
BOOST_CHECK(!IsStakeableByMe(keystore, scriptPubKey));
}

// P2PKH uncompressed
Expand Down
18 changes: 17 additions & 1 deletion test/functional/proposer_stakeable_balance.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from test_framework.util import *
from test_framework.test_framework import UnitETestFramework


class ProposerStakeableBalanceTest(UnitETestFramework):

def set_test_params(self):
Expand All @@ -14,7 +15,7 @@ def set_test_params(self):
'-proposing=1',
'-minimumchainwork=0',
'-maxtipage=1000000000'
] for i in range(0, self.num_nodes))
] for _ in range(0, self.num_nodes))
self.setup_clean_chain = True

def run_test(self):
Expand Down Expand Up @@ -86,6 +87,21 @@ def predicate(i):
assert_equal(wallet['balance'], Decimal('0.00000000'))
assert_equal(wallet['stakeable_balance'], Decimal('0.00000000'))

# Check that if we send all the money to a P2PKH address we cannot stake anymore.
disconnect_all_nodes(nodes)

p2pkh_tx = nodes[0].sendtoaddress(nodes[0].getnewaddress("", "legacy"), nodes[0].getbalance(), "", "", True)

wait_until(lambda: p2pkh_tx in nodes[0].getrawmempool())
connect_nodes(nodes[0], nodes[1].index)
sync_mempools(nodes[0:1])

wait_until(lambda: nodes[0].gettransaction(p2pkh_tx)['confirmations'] > 0, timeout=60)

assert_equal(len(nodes[0].liststakeablecoins()['stakeable_coins']), 0)
assert_equal(nodes[0].liststakeablecoins()['stakeable_balance'], Decimal('0.00000000'))
assert_equal(nodes[0].proposerstatus()['wallets'][0]['stakeable_balance'], Decimal('0.00000000'))
Gnappuraz marked this conversation as resolved.
Show resolved Hide resolved

print("Test succeeded.")

if __name__ == '__main__':
Expand Down
9 changes: 9 additions & 0 deletions test/functional/test_framework/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,15 @@ def connect_nodes_bi(nodes, a, b):
connect_nodes(nodes[a], b)
connect_nodes(nodes[b], a)

def disconnect_nodes_bi(nodes, a, b):
disconnect_nodes(nodes[a], b)
disconnect_nodes(nodes[b], a)

def disconnect_all_nodes(nodes):
Gnappuraz marked this conversation as resolved.
Show resolved Hide resolved
for i in range(0, len(nodes)):
if i+1 < len(nodes):
connect_nodes_bi(nodes, i, i + 1)
Gnappuraz marked this conversation as resolved.
Show resolved Hide resolved

Copy link
Member

@kostyantyn kostyantyn Apr 17, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understood the usage of this function but let's say if node 0 is connected to node 2, they won't be disconnected.
Shouldn't it be:

for (a, b) in itertools.combinations(nodes, 2):
  disconnect_nodes_bi(nodes, a, b)

def sync_blocks(rpc_connections, *, wait=1, timeout=60, height=None):
"""
Wait until everybody has the same tip.
Expand Down