Page MenuHomePhabricator

[avalanche] improve stake generation in functional test
ClosedPublic

Authored by PiRK on Apr 23 2021, 07:35.

Details

Reviewers
deadalnix
Group Reviewers
Restricted Project
Commits
rABC6aba8b30bd60: [avalanche] improve stake generation in functional test
Summary

This adds a function to generate 10 stakes per block, by splitting each coinbase transaction into 10 UTXOs, instead of using a whole coinbase UTXO for each stake.

It makes it possible to generate more stakes that are above the dust threshold limit. Coinbase UTXOs are only valid up to block 900 on regtest, due to halvings every 150 blocks.

This fixes the test failure in D9345, when testing a proof with 1000 stakes.

Test Plan

ninja check-functional

Verify that renaming the get_stakes function did not affect any other test.
grep -r get_stakes test/functional

Run the tests with the wallet disabled:

cmake .. -DBUILD_BITCOIN_WALLET=OFF -GNinja
ninja check-functional

Event Timeline

Failed tests logs:

====== Bitcoin ABC functional tests: abc_p2p_avalanche.py ======

------- Stdout: -------
2021-04-23T07:39:08.282000Z TestFramework (INFO): Initializing test directory /work/abc-ci-builds/build-debug/test/tmp/test_runner_₿₵_  _20210423_073711/abc_p2p_avalanche_38
2021-04-23T07:39:08.612000Z TestFramework (INFO): Check the node is signalling the avalanche service.
2021-04-23T07:39:10.514000Z TestFramework (ERROR): Unexpected exception caught during testing
Traceback (most recent call last):
  File "/work/test/functional/test_framework/test_framework.py", line 126, in main
    self.run_test()
  File "/work/test/functional/abc_p2p_avalanche.py", line 158, in run_test
    stakes = get_stakes(node, [blockhashes[0]], addrkey0.key)
TypeError: get_stakes() takes 2 positional arguments but 3 were given
2021-04-23T07:39:10.565000Z TestFramework (INFO): Stopping nodes
2021-04-23T07:39:10.867000Z TestFramework (WARNING): Not cleaning up dir /work/abc-ci-builds/build-debug/test/tmp/test_runner_₿₵_  _20210423_073711/abc_p2p_avalanche_38
2021-04-23T07:39:10.867000Z TestFramework (ERROR): Test failed. Test logging available at /work/abc-ci-builds/build-debug/test/tmp/test_runner_₿₵_  _20210423_073711/abc_p2p_avalanche_38/test_framework.log
2021-04-23T07:39:10.867000Z TestFramework (ERROR): 
2021-04-23T07:39:10.868000Z TestFramework (ERROR): Hint: Call /work/test/functional/combine_logs.py '/work/abc-ci-builds/build-debug/test/tmp/test_runner_₿₵_  _20210423_073711/abc_p2p_avalanche_38' to consolidate all logs
2021-04-23T07:39:10.868000Z TestFramework (ERROR): 
2021-04-23T07:39:10.868000Z TestFramework (ERROR): If this failure happened unexpectedly or intermittently, please file a bug and provide a link or upload of the combined log.
2021-04-23T07:39:10.868000Z TestFramework (ERROR): https://github.com/Bitcoin-ABC/bitcoin-abc/issues
2021-04-23T07:39:10.868000Z TestFramework (ERROR):

Each failure log is accessible here:
Bitcoin ABC functional tests: abc_p2p_avalanche.py

Failed tests logs:

====== Bitcoin ABC functional tests: abc_p2p_avalanche.py ======

------- Stdout: -------
2021-04-23T07:40:51.593000Z TestFramework (INFO): Initializing test directory /work/abc-ci-builds/build-without-wallet/test/tmp/test_runner_₿₵_  _20210423_074019/abc_p2p_avalanche_223
2021-04-23T07:40:51.906000Z TestFramework (INFO): Check the node is signalling the avalanche service.
2021-04-23T07:40:53.579000Z TestFramework (ERROR): Unexpected exception caught during testing
Traceback (most recent call last):
  File "/work/test/functional/test_framework/test_framework.py", line 126, in main
    self.run_test()
  File "/work/test/functional/abc_p2p_avalanche.py", line 158, in run_test
    stakes = get_stakes(node, [blockhashes[0]], addrkey0.key)
TypeError: get_stakes() takes 2 positional arguments but 3 were given
2021-04-23T07:40:53.630000Z TestFramework (INFO): Stopping nodes
2021-04-23T07:40:53.831000Z TestFramework (WARNING): Not cleaning up dir /work/abc-ci-builds/build-without-wallet/test/tmp/test_runner_₿₵_  _20210423_074019/abc_p2p_avalanche_223
2021-04-23T07:40:53.831000Z TestFramework (ERROR): Test failed. Test logging available at /work/abc-ci-builds/build-without-wallet/test/tmp/test_runner_₿₵_  _20210423_074019/abc_p2p_avalanche_223/test_framework.log
2021-04-23T07:40:53.832000Z TestFramework (ERROR): 
2021-04-23T07:40:53.832000Z TestFramework (ERROR): Hint: Call /work/test/functional/combine_logs.py '/work/abc-ci-builds/build-without-wallet/test/tmp/test_runner_₿₵_  _20210423_074019/abc_p2p_avalanche_223' to consolidate all logs
2021-04-23T07:40:53.832000Z TestFramework (ERROR): 
2021-04-23T07:40:53.832000Z TestFramework (ERROR): If this failure happened unexpectedly or intermittently, please file a bug and provide a link or upload of the combined log.
2021-04-23T07:40:53.832000Z TestFramework (ERROR): https://github.com/Bitcoin-ABC/bitcoin-abc/issues
2021-04-23T07:40:53.832000Z TestFramework (ERROR):
====== Bitcoin ABC functional tests: abc_rpc_avalancheproof.py ======

------- Stdout: -------
2021-04-23T07:41:03.299000Z TestFramework (INFO): Initializing test directory /work/abc-ci-builds/build-without-wallet/test/tmp/test_runner_₿₵_  _20210423_074019/abc_rpc_avalancheproof_240
2021-04-23T07:41:03.587000Z TestFramework (INFO): Make build a valid proof and restart the node to use it
2021-04-23T07:41:03.997000Z TestFramework (INFO): The proof verification should be delayed until IBD is complete
2021-04-23T07:41:04.000000Z TestFramework (INFO): A proof using the maximum number of stakes is accepted...
2021-04-23T07:41:04.091000Z TestFramework (ERROR): JSONRPC error
Traceback (most recent call last):
  File "/work/test/functional/test_framework/test_framework.py", line 126, in main
    self.run_test()
  File "/work/test/functional/abc_rpc_avalancheproof.py", line 87, in run_test
    too_many_stakes = get_stakes(node, AVALANCHE_MAX_PROOF_STAKES + 1)
  File "/work/test/functional/test_framework/avatools.py", line 67, in get_stakes
    utxos = node.listunspent()
  File "/work/test/functional/test_framework/coverage.py", line 48, in __call__
    return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs)
  File "/work/test/functional/test_framework/authproxy.py", line 159, in __call__
    raise JSONRPCException(response['error'], status)
test_framework.authproxy.JSONRPCException: Method not found (-32601)
2021-04-23T07:41:04.142000Z TestFramework (INFO): Stopping nodes
2021-04-23T07:41:04.395000Z TestFramework (WARNING): Not cleaning up dir /work/abc-ci-builds/build-without-wallet/test/tmp/test_runner_₿₵_  _20210423_074019/abc_rpc_avalancheproof_240
2021-04-23T07:41:04.395000Z TestFramework (ERROR): Test failed. Test logging available at /work/abc-ci-builds/build-without-wallet/test/tmp/test_runner_₿₵_  _20210423_074019/abc_rpc_avalancheproof_240/test_framework.log
2021-04-23T07:41:04.395000Z TestFramework (ERROR): 
2021-04-23T07:41:04.396000Z TestFramework (ERROR): Hint: Call /work/test/functional/combine_logs.py '/work/abc-ci-builds/build-without-wallet/test/tmp/test_runner_₿₵_  _20210423_074019/abc_rpc_avalancheproof_240' to consolidate all logs
2021-04-23T07:41:04.396000Z TestFramework (ERROR): 
2021-04-23T07:41:04.396000Z TestFramework (ERROR): If this failure happened unexpectedly or intermittently, please file a bug and provide a link or upload of the combined log.
2021-04-23T07:41:04.397000Z TestFramework (ERROR): https://github.com/Bitcoin-ABC/bitcoin-abc/issues
2021-04-23T07:41:04.397000Z TestFramework (ERROR):

Each failure log is accessible here:
Bitcoin ABC functional tests: abc_p2p_avalanche.py
Bitcoin ABC functional tests: abc_rpc_avalancheproof.py

Failed tests logs:

====== Bitcoin ABC functional tests: abc_p2p_avalanche.py ======

------- Stdout: -------
2021-04-23T07:43:55.533000Z TestFramework (INFO): Initializing test directory /work/abc-ci-builds/build-diff/test/tmp/test_runner_₿₵_  _20210423_074206/abc_p2p_avalanche_438
2021-04-23T07:43:55.855000Z TestFramework (INFO): Check the node is signalling the avalanche service.
2021-04-23T07:43:57.559000Z TestFramework (ERROR): Unexpected exception caught during testing
Traceback (most recent call last):
  File "/work/test/functional/test_framework/test_framework.py", line 126, in main
    self.run_test()
  File "/work/test/functional/abc_p2p_avalanche.py", line 158, in run_test
    stakes = get_stakes(node, [blockhashes[0]], addrkey0.key)
TypeError: get_stakes() takes 2 positional arguments but 3 were given
2021-04-23T07:43:57.610000Z TestFramework (INFO): Stopping nodes
2021-04-23T07:43:57.812000Z TestFramework (WARNING): Not cleaning up dir /work/abc-ci-builds/build-diff/test/tmp/test_runner_₿₵_  _20210423_074206/abc_p2p_avalanche_438
2021-04-23T07:43:57.812000Z TestFramework (ERROR): Test failed. Test logging available at /work/abc-ci-builds/build-diff/test/tmp/test_runner_₿₵_  _20210423_074206/abc_p2p_avalanche_438/test_framework.log
2021-04-23T07:43:57.812000Z TestFramework (ERROR): 
2021-04-23T07:43:57.812000Z TestFramework (ERROR): Hint: Call /work/test/functional/combine_logs.py '/work/abc-ci-builds/build-diff/test/tmp/test_runner_₿₵_  _20210423_074206/abc_p2p_avalanche_438' to consolidate all logs
2021-04-23T07:43:57.812000Z TestFramework (ERROR): 
2021-04-23T07:43:57.812000Z TestFramework (ERROR): If this failure happened unexpectedly or intermittently, please file a bug and provide a link or upload of the combined log.
2021-04-23T07:43:57.812000Z TestFramework (ERROR): https://github.com/Bitcoin-ABC/bitcoin-abc/issues
2021-04-23T07:43:57.812000Z TestFramework (ERROR):
====== Bitcoin ABC functional tests with the next upgrade activated: abc_p2p_avalanche.py ======

------- Stdout: -------
2021-04-23T07:46:54.919000Z TestFramework (INFO): Initializing test directory /work/abc-ci-builds/build-diff/test/tmp/test_runner_₿₵_  _20210423_074506/abc_p2p_avalanche_46
2021-04-23T07:46:55.242000Z TestFramework (INFO): Check the node is signalling the avalanche service.
2021-04-23T07:46:56.942000Z TestFramework (ERROR): Unexpected exception caught during testing
Traceback (most recent call last):
  File "/work/test/functional/test_framework/test_framework.py", line 126, in main
    self.run_test()
  File "/work/test/functional/abc_p2p_avalanche.py", line 158, in run_test
    stakes = get_stakes(node, [blockhashes[0]], addrkey0.key)
TypeError: get_stakes() takes 2 positional arguments but 3 were given
2021-04-23T07:46:56.993000Z TestFramework (INFO): Stopping nodes
2021-04-23T07:46:57.194000Z TestFramework (WARNING): Not cleaning up dir /work/abc-ci-builds/build-diff/test/tmp/test_runner_₿₵_  _20210423_074506/abc_p2p_avalanche_46
2021-04-23T07:46:57.194000Z TestFramework (ERROR): Test failed. Test logging available at /work/abc-ci-builds/build-diff/test/tmp/test_runner_₿₵_  _20210423_074506/abc_p2p_avalanche_46/test_framework.log
2021-04-23T07:46:57.194000Z TestFramework (ERROR): 
2021-04-23T07:46:57.194000Z TestFramework (ERROR): Hint: Call /work/test/functional/combine_logs.py '/work/abc-ci-builds/build-diff/test/tmp/test_runner_₿₵_  _20210423_074506/abc_p2p_avalanche_46' to consolidate all logs
2021-04-23T07:46:57.194000Z TestFramework (ERROR): 
2021-04-23T07:46:57.195000Z TestFramework (ERROR): If this failure happened unexpectedly or intermittently, please file a bug and provide a link or upload of the combined log.
2021-04-23T07:46:57.195000Z TestFramework (ERROR): https://github.com/Bitcoin-ABC/bitcoin-abc/issues
2021-04-23T07:46:57.195000Z TestFramework (ERROR):

Each failure log is accessible here:
Bitcoin ABC functional tests: abc_p2p_avalanche.py
Bitcoin ABC functional tests with the next upgrade activated: abc_p2p_avalanche.py

Fix another functional test that was affected by renaming get_stakes
Update the test plan to include the entire functional test suite.

Failed tests logs:

====== Bitcoin ABC functional tests: abc_rpc_avalancheproof.py ======

------- Stdout: -------
2021-04-23T08:00:04.849000Z TestFramework (INFO): Initializing test directory /work/abc-ci-builds/build-without-wallet/test/tmp/test_runner_₿₵_  _20210423_075918/abc_rpc_avalancheproof_86
2021-04-23T08:00:05.151000Z TestFramework (INFO): Make build a valid proof and restart the node to use it
2021-04-23T08:00:05.565000Z TestFramework (INFO): The proof verification should be delayed until IBD is complete
2021-04-23T08:00:05.582000Z TestFramework (INFO): A proof using the maximum number of stakes is accepted...
2021-04-23T08:00:05.716000Z TestFramework (ERROR): JSONRPC error
Traceback (most recent call last):
  File "/work/test/functional/test_framework/test_framework.py", line 126, in main
    self.run_test()
  File "/work/test/functional/abc_rpc_avalancheproof.py", line 87, in run_test
    too_many_stakes = get_stakes(node, AVALANCHE_MAX_PROOF_STAKES + 1)
  File "/work/test/functional/test_framework/avatools.py", line 67, in get_stakes
    utxos = node.listunspent()
  File "/work/test/functional/test_framework/coverage.py", line 48, in __call__
    return_val = self.auth_service_proxy_instance.__call__(*args, **kwargs)
  File "/work/test/functional/test_framework/authproxy.py", line 159, in __call__
    raise JSONRPCException(response['error'], status)
test_framework.authproxy.JSONRPCException: Method not found (-32601)
2021-04-23T08:00:05.767000Z TestFramework (INFO): Stopping nodes
2021-04-23T08:00:05.969000Z TestFramework (WARNING): Not cleaning up dir /work/abc-ci-builds/build-without-wallet/test/tmp/test_runner_₿₵_  _20210423_075918/abc_rpc_avalancheproof_86
2021-04-23T08:00:05.970000Z TestFramework (ERROR): Test failed. Test logging available at /work/abc-ci-builds/build-without-wallet/test/tmp/test_runner_₿₵_  _20210423_075918/abc_rpc_avalancheproof_86/test_framework.log
2021-04-23T08:00:05.970000Z TestFramework (ERROR): 
2021-04-23T08:00:05.970000Z TestFramework (ERROR): Hint: Call /work/test/functional/combine_logs.py '/work/abc-ci-builds/build-without-wallet/test/tmp/test_runner_₿₵_  _20210423_075918/abc_rpc_avalancheproof_86' to consolidate all logs
2021-04-23T08:00:05.971000Z TestFramework (ERROR): 
2021-04-23T08:00:05.971000Z TestFramework (ERROR): If this failure happened unexpectedly or intermittently, please file a bug and provide a link or upload of the combined log.
2021-04-23T08:00:05.971000Z TestFramework (ERROR): https://github.com/Bitcoin-ABC/bitcoin-abc/issues
2021-04-23T08:00:05.971000Z TestFramework (ERROR):

Each failure log is accessible here:
Bitcoin ABC functional tests: abc_rpc_avalancheproof.py

PiRK edited the test plan for this revision. (Show Details)

This new way of generating stakes requires the wallet to be compiled. Fix the test to run only when possible, update the test plan.
Use a different bad proof for the delegateavalancheproof test, so that it does not depend on the wallet.

deadalnix requested changes to this revision.Apr 23 2021, 15:31
deadalnix added a subscriber: deadalnix.

I have nothing against generating proofs this way, but the abstraction provided is clearly not good.

test/functional/test_framework/avatools.py
56 ↗(On Diff #28258)

I don't think this behavior can be reasonably expected from the name of the function.

This is doing a ton of stuff under the hood and it is unlikely that this will compose well in general as it'll have a ton of side effects that don't have much to do with getting stakes. In fact, I'm confident than in practice, it is not really possible to use this function without knowing its implementation.

86 ↗(On Diff #28258)

Why generate a stake for each utxo and then throw away all the one after count?

This revision now requires changes to proceed.Apr 23 2021, 15:31
PiRK edited the test plan for this revision. (Show Details)

Rename functions get_ -> create_ to indicate that new UTXOs are generated.

Reduce side effects, by spending and using only transactions that have been by generated the function. Previously the function used all available UTXOs, even existing stakes already in use.

Cache the block height in the last loop, to avoid unneccessary calls to node.getblock, as it is likely that all coins will have the same block height.
Similarly, avoid calling node.dumpprivkey(addr) for each coin when there are only 10 distinct addresses.

Reduce the level of abstraction: let the caller generate the new blocks, and pass them to the function as a list of hashes.
This makes the function's signature more consistent with create_coinbase_stakes.

Tail of the build log:

rpc_psbt.py                                      | ✓ Passed  | 19 s
rpc_rawtransaction.py                            | ✓ Passed  | 40 s
rpc_scantxoutset.py                              | ✓ Passed  | 3 s
rpc_setban.py                                    | ✓ Passed  | 2 s
rpc_signmessage.py                               | ✓ Passed  | 1 s
rpc_signrawtransaction.py                        | ✓ Passed  | 2 s
rpc_txoutproof.py                                | ✓ Passed  | 2 s
rpc_uptime.py                                    | ✓ Passed  | 1 s
rpc_users.py                                     | ✓ Passed  | 5 s
rpc_whitelist.py                                 | ✓ Passed  | 1 s
tool_wallet.py                                   | ✓ Passed  | 4 s
wallet_abandonconflict.py                        | ✓ Passed  | 5 s
wallet_address_types.py                          | ✓ Passed  | 14 s
wallet_avoidreuse.py                             | ✓ Passed  | 5 s
wallet_backup.py                                 | ✓ Passed  | 29 s
wallet_balance.py                                | ✓ Passed  | 9 s
wallet_basic.py                                  | ✓ Passed  | 24 s
wallet_coinbase_category.py                      | ✓ Passed  | 1 s
wallet_create_tx.py                              | ✓ Passed  | 9 s
wallet_createwallet.py                           | ✓ Passed  | 2 s
wallet_createwallet.py --usecli                  | ✓ Passed  | 3 s
wallet_descriptor.py                             | ✓ Passed  | 6 s
wallet_disable.py                                | ✓ Passed  | 0 s
wallet_dump.py                                   | ✓ Passed  | 6 s
wallet_encryption.py                             | ✓ Passed  | 5 s
wallet_groups.py                                 | ✓ Passed  | 34 s
wallet_hd.py                                     | ✓ Passed  | 6 s
wallet_import_rescan.py                          | ✓ Passed  | 7 s
wallet_import_with_label.py                      | ✓ Passed  | 1 s
wallet_importdescriptors.py                      | ✓ Passed  | 5 s
wallet_importmulti.py                            | ✓ Passed  | 3 s
wallet_importprunedfunds.py                      | ✓ Passed  | 2 s
wallet_keypool.py                                | ✓ Passed  | 3 s
wallet_keypool_topup.py                          | ✓ Passed  | 2 s
wallet_labels.py                                 | ✓ Passed  | 2 s
wallet_listreceivedby.py                         | ✓ Passed  | 32 s
wallet_listsinceblock.py                         | ✓ Passed  | 5 s
wallet_listtransactions.py                       | ✓ Passed  | 8 s
wallet_multiwallet.py                            | ✓ Passed  | 12 s
wallet_multiwallet.py --usecli                   | ✓ Passed  | 14 s
wallet_reorgsrestore.py                          | ✓ Passed  | 3 s
wallet_resendwallettransactions.py               | ✓ Passed  | 6 s
wallet_txn_clone.py                              | ✓ Passed  | 2 s
wallet_txn_clone.py --mineblock                  | ✓ Passed  | 3 s
wallet_txn_doublespend.py                        | ✓ Passed  | 1 s
wallet_txn_doublespend.py --mineblock            | ✓ Passed  | 3 s
wallet_watchonly.py                              | ✓ Passed  | 1 s
wallet_watchonly.py --usecli                     | ✓ Passed  | 1 s
wallet_zapwallettxes.py                          | ✓ Passed  | 5 s

ALL                                              | ✓ Passed  | 898 s (accumulated) 
Runtime: 180 s

----------------------------------------------------------------------
Ran 5 tests in 0.001s

OK

ninja: build stopped: cannot make progress due to previous errors.
Build build-diff failed with exit code 1
deadalnix requested changes to this revision.Apr 26 2021, 21:27

The test are not passing.

This revision now requires changes to proceed.Apr 26 2021, 21:27

Rebase. The test failure is an unrelated failure in a leveldb unit test. It is a rare intermittent failure (see D6751).

I'm going to green this for the sake of progress and this is fairly contained, but I think there are still problems in the API.

This revision is now accepted and ready to land.Apr 27 2021, 15:20