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 1 commit
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
24 changes: 23 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,27 @@ 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.
for node in self.nodes[2:]:
node.stop_node(wait=0)

self.nodes = self.nodes[0:2]
Gnappuraz marked this conversation as resolved.
Show resolved Hide resolved

# Disconnecting all nodes to stop proposal.
disconnect_nodes(nodes[0], nodes[1].index)

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