-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CLI option to control feerate argument from memppol
- add in-top-x-mb argument to control how much to prioritize the transaction feerate so the transaction can get in the top x MB of the mempool - add functional test
- Loading branch information
Showing
13 changed files
with
266 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
#!/usr/bin/env python3 | ||
# Copyright (c) 2023 RBB S.r.l | ||
# Copyright (c) 2017-2021 The Bitcoin Core developers | ||
# opensource@mintlayer.org | ||
# SPDX-License-Identifier: MIT | ||
# Licensed under the MIT License; | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# https://github.com/mintlayer/mintlayer-core/blob/master/LICENSE | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
"""Wallet high fee submission test | ||
Check that: | ||
* We can create a new wallet, | ||
* get an address | ||
* send coins to the wallet's address | ||
* sync the wallet with the node | ||
* check balance | ||
* submit many txs with high fee | ||
* try to spend coins from the wallet should fail | ||
""" | ||
|
||
from time import time | ||
import scalecodec | ||
from test_framework.test_framework import BitcoinTestFramework | ||
from test_framework.mintlayer import (calc_tx_id, make_tx_dict, reward_input, tx_input, MLT_COIN, tx_output) | ||
from test_framework.util import assert_raises_rpc_error | ||
from test_framework.mintlayer import mintlayer_hash, block_input_data_obj | ||
from test_framework.wallet_cli_controller import WalletCliController | ||
|
||
import asyncio | ||
import sys | ||
|
||
class WalletSubmitTransaction(BitcoinTestFramework): | ||
|
||
def set_test_params(self): | ||
self.setup_clean_chain = True | ||
self.num_nodes = 1 | ||
self.extra_args = [[ | ||
"--blockprod-min-peers-to-produce-blocks=0", | ||
]] | ||
|
||
def setup_network(self): | ||
self.setup_nodes() | ||
self.sync_all(self.nodes[0:1]) | ||
|
||
def make_tx(self, inputs, outputs, flags = 0, calc_id = True): | ||
self.log.info(f"making tx") | ||
signed_tx = make_tx_dict(inputs, outputs, flags) | ||
self.log.info(f"calc tx id") | ||
tx_id = calc_tx_id(signed_tx) if calc_id else None | ||
self.log.info(f"obj") | ||
signed_tx_obj = scalecodec.base.RuntimeConfiguration().create_scale_object('SignedTransaction') | ||
self.log.info(f"encode") | ||
encoded_tx = signed_tx_obj.encode(signed_tx).to_hex()[2:] | ||
return (encoded_tx, tx_id) | ||
|
||
|
||
def generate_block(self): | ||
node = self.nodes[0] | ||
|
||
block_input_data = { "PoW": { "reward_destination": "AnyoneCanSpend" } } | ||
block_input_data = block_input_data_obj.encode(block_input_data).to_hex()[2:] | ||
|
||
# create a new block, taking transactions from mempool | ||
block = node.blockprod_generate_block(block_input_data, None) | ||
node.chainstate_submit_block(block) | ||
block_id = node.chainstate_best_block_id() | ||
|
||
# Wait for mempool to sync | ||
self.wait_until(lambda: node.mempool_local_best_block_id() == block_id, timeout = 5) | ||
|
||
return block_id | ||
|
||
def run_test(self): | ||
if 'win32' in sys.platform: | ||
asyncio.set_event_loop_policy(asyncio.WindowsProactorEventLoopPolicy()) | ||
asyncio.run(self.async_test()) | ||
|
||
async def async_test(self): | ||
node = self.nodes[0] | ||
async with WalletCliController(node, self.config, self.log, ["--in-top-x-mb", "1"]) as wallet: | ||
# new wallet | ||
await wallet.create_wallet() | ||
|
||
# check it is on genesis | ||
best_block_height = await wallet.get_best_block_height() | ||
self.log.info(f"best block height = {best_block_height}") | ||
assert best_block_height == '0' | ||
|
||
# new address | ||
pub_key_bytes = await wallet.new_public_key() | ||
assert len(pub_key_bytes) == 33 | ||
|
||
# Get chain tip | ||
tip_id = node.chainstate_best_block_id() | ||
self.log.debug(f'Tip: {tip_id}') | ||
|
||
# Submit a valid transaction | ||
output = { | ||
'Transfer': [ { 'Coin': 10 * MLT_COIN }, { 'PublicKey': {'key': {'Secp256k1Schnorr' : {'pubkey_data': pub_key_bytes}}} } ], | ||
} | ||
total = 300000 | ||
output2 = { | ||
'Transfer': [ { 'Coin': total * MLT_COIN }, { 'AnyoneCanSpend': None } ], | ||
} | ||
encoded_tx, tx_id = self.make_tx([reward_input(tip_id)], [output2, output], 0) | ||
|
||
self.log.debug(f"Encoded transaction {tx_id}: {encoded_tx}") | ||
|
||
node.mempool_submit_transaction(encoded_tx) | ||
assert node.mempool_contains_tx(tx_id) | ||
|
||
block_id = self.generate_block() # Block 1 | ||
assert not node.mempool_contains_tx(tx_id) | ||
|
||
# sync the wallet | ||
output = await wallet.sync() | ||
assert "Success" in output | ||
|
||
# check wallet best block if it is synced | ||
best_block_height = await wallet.get_best_block_height() | ||
assert best_block_height == '1' | ||
|
||
best_block_id = await wallet.get_best_block() | ||
assert best_block_id == block_id | ||
|
||
balance = await wallet.get_balance() | ||
assert "Coins amount: 10" in balance | ||
|
||
transactions = node.test_functions_generate_transactions(tx_id, 25, total - 300, 300) | ||
for idx, encoded_tx in enumerate(transactions): | ||
self.log.info(f"submitting tx {idx}") | ||
node.mempool_submit_transaction(encoded_tx) | ||
|
||
# try to send 9 out of 10 to itself, 1 coin should not be enough to pay the high fee | ||
address = await wallet.new_address() | ||
output = await wallet.send_to_address(address, 9) | ||
self.log.info(output) | ||
assert "successfully" not in output | ||
|
||
|
||
if __name__ == '__main__': | ||
WalletSubmitTransaction().main() | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.