fix(utxo): correct block header deserialization for AuxPow and KAWPOW coins#2563
fix(utxo): correct block header deserialization for AuxPow and KAWPOW coins#2563
Conversation
… coins
Swaps for coins like NMC, CHTA, and XEC were failing with an
`UnexpectedEnd` error during MTP steps. This was due to
overly broad conditional logic in `BlockHeader::deserialize` which
misinterpreted block header structures based on version numbers.
This commit corrects the logic in two ways:
1. The check for AuxPow headers is changed from a hardcoded list of
versions to the correct bitmask check (`version & (1 << 8)`). This
is the proper way to detect AuxPow and makes the logic robust against
base version changes.
2. KAWPOW header parsing is now specialized to apply only to Ravencoin.
A `CoinVariant::RVN` is introduced, and the deserializer now checks
for this variant before attempting to read RVN-specific fields. This
prevents conflicts with other coins (like CHTA) that use the same
version number but have a different header structure.
A utility test for scanning and debugging block headers has also been
added to assist with future diagnostics.
- In `utxo_tests.rs`: - Remove an unreachable `break` condition from the header scanning loop. - Reformat the panic message in the `test_scan_and_deserialize_block_headers` utility to improve terminal readability by reordering and removing extra indentation. - In `block_header.rs`: - Add parentheses to a conditional in the `BlockHeader` deserialization logic to enhance code clarity and consistency.
|
@mariocynicys all your review comments have been addressed :) |
* dev: fix(utxo): correct block header deserialization for AuxPow and KAWPOW coins (#2563)
|
i got an "UnexpectedEnd" error when i called recover_funds_of_swap on this swap on maker: the error message is simply idk if that is the same as what the PR fixes or not |
The |
* dev: chore(rust 1.89): make CI clippy/fmt pass (wasm32, all-targets) (#2581) fix(utxo): deserialize sapling root for PIVX block headers (#2572) improvement(dep-stack): security bumps (#2562) fix(utxo): correct block header deserialization for AuxPow and KAWPOW coins (#2563) # Conflicts: # mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs
* dev: fix(ordermatch): ignore loop-back; clear on null root; reject stale keep-alives (#2580) fix(clippy): fix clippy warnings for #2565 (#2589) fix(Trezor): fix utxo and eth calls due to firmware changes (#2565) fix(utxo): calculate min_trading_vol based on fixed tx fees (#2564) feat(protocol): [0] solana support (#2586) fix(utxo): fix header deserialization; guard AuxPoW (#2583) chore(rust 1.89): make CI clippy/fmt pass (wasm32, all-targets) (#2581) fix(utxo): deserialize sapling root for PIVX block headers (#2572) improvement(dep-stack): security bumps (#2562) fix(utxo): correct block header deserialization for AuxPow and KAWPOW coins (#2563)
* dev: (24 commits) fix(ordermatch): ignore loop-back; clear on null root; reject stale keep-alives (#2580) fix(clippy): fix clippy warnings for #2565 (#2589) fix(Trezor): fix utxo and eth calls due to firmware changes (#2565) fix(utxo): calculate min_trading_vol based on fixed tx fees (#2564) feat(protocol): [0] solana support (#2586) fix(utxo): fix header deserialization; guard AuxPoW (#2583) chore(rust 1.89): make CI clippy/fmt pass (wasm32, all-targets) (#2581) fix(utxo): deserialize sapling root for PIVX block headers (#2572) improvement(dep-stack): security bumps (#2562) fix(utxo): correct block header deserialization for AuxPow and KAWPOW coins (#2563) feat(wallet-connect): impl BTC (UTxO) activation via WalletConnect (#2499) feat(utxo): add new fixed txfee option for DINGO-like coins (#2454) ci(pull-requests): review notification bot (#2468) improvement(walletconnect): return the `pairing_topic` in `new_connection` response (#2538) bless clippy (#2560) refactor(toolchain): use latest available stable compiler (#2557) feat(wallet): implement unified offline private key export API (#2542) improve note for docker test start failure (#2550) fix(DOCS): add note for macos to fix docker containers startup failure (#2544) refactor(toolchain): general stabilization for stable rust (#2528) ... # Conflicts: # mm2src/coins/eth.rs # mm2src/coins/eth/eth_swap_v2/eth_maker_swap_v2.rs # mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs # mm2src/coins/eth/eth_tests.rs # mm2src/coins/eth/eth_withdraw.rs # mm2src/coins/eth/v2_activation.rs # mm2src/coins/nft.rs # mm2src/coins/qrc20.rs # mm2src/mm2_main/src/rpc/dispatcher/dispatcher.rs # mm2src/mm2_main/src/rpc/lp_commands/one_inch/rpcs.rs # mm2src/mm2_main/src/rpc/lp_commands/tokens.rs # mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs
* dev: improvement(`static mut`s): `static mut` removal (#2590) fix(orders): set subscription on kickstart and skip GC of own pubkeys (#2597) fix(ordermatch): ignore loop-back; clear on null root; reject stale keep-alives (#2580) fix(clippy): fix clippy warnings for #2565 (#2589) fix(Trezor): fix utxo and eth calls due to firmware changes (#2565) fix(utxo): calculate min_trading_vol based on fixed tx fees (#2564) feat(protocol): [0] solana support (#2586) fix(utxo): fix header deserialization; guard AuxPoW (#2583) chore(rust 1.89): make CI clippy/fmt pass (wasm32, all-targets) (#2581) fix(utxo): deserialize sapling root for PIVX block headers (#2572) improvement(dep-stack): security bumps (#2562) fix(utxo): correct block header deserialization for AuxPow and KAWPOW coins (#2563) feat(wallet-connect): impl BTC (UTxO) activation via WalletConnect (#2499) feat(utxo): add new fixed txfee option for DINGO-like coins (#2454) ci(pull-requests): review notification bot (#2468) improvement(walletconnect): return the `pairing_topic` in `new_connection` response (#2538) bless clippy (#2560) refactor(toolchain): use latest available stable compiler (#2557) feat(wallet): implement unified offline private key export API (#2542) chore(release): v2.3.0-beta (#2284) # Conflicts: # mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs
* dev: (28 commits) fix build script failing to find .git/HEAD (GLEECBTC#2601) refactor(EVM): rename fn, fix timeouts, add activation req validation (GLEECBTC#2543) improvement(`static mut`s): `static mut` removal (GLEECBTC#2590) fix(orders): set subscription on kickstart and skip GC of own pubkeys (GLEECBTC#2597) fix(ordermatch): ignore loop-back; clear on null root; reject stale keep-alives (GLEECBTC#2580) fix(clippy): fix clippy warnings for GLEECBTC#2565 (GLEECBTC#2589) fix(Trezor): fix utxo and eth calls due to firmware changes (GLEECBTC#2565) fix(utxo): calculate min_trading_vol based on fixed tx fees (GLEECBTC#2564) feat(protocol): [0] solana support (GLEECBTC#2586) fix(utxo): fix header deserialization; guard AuxPoW (GLEECBTC#2583) chore(rust 1.89): make CI clippy/fmt pass (wasm32, all-targets) (GLEECBTC#2581) fix(utxo): deserialize sapling root for PIVX block headers (GLEECBTC#2572) improvement(dep-stack): security bumps (GLEECBTC#2562) fix(utxo): correct block header deserialization for AuxPow and KAWPOW coins (GLEECBTC#2563) feat(wallet-connect): impl BTC (UTxO) activation via WalletConnect (GLEECBTC#2499) feat(utxo): add new fixed txfee option for DINGO-like coins (GLEECBTC#2454) ci(pull-requests): review notification bot (GLEECBTC#2468) improvement(walletconnect): return the `pairing_topic` in `new_connection` response (GLEECBTC#2538) bless clippy (GLEECBTC#2560) refactor(toolchain): use latest available stable compiler (GLEECBTC#2557) ... # Conflicts: # mm2src/coins/eth.rs # mm2src/coins/eth/eth_rpc.rs # mm2src/coins/eth/eth_swap_v2/eth_maker_swap_v2.rs # mm2src/coins/eth/eth_swap_v2/eth_taker_swap_v2.rs # mm2src/coins/eth/eth_withdraw.rs # mm2src/coins/eth/v2_activation.rs # mm2src/coins/lightning.rs # mm2src/coins/lp_coins.rs # mm2src/coins/nft.rs # mm2src/coins/qrc20.rs # mm2src/coins/siacoin.rs # mm2src/coins/tendermint/tendermint_token.rs # mm2src/coins/test_coin.rs # mm2src/coins/utxo/bch.rs # mm2src/coins/utxo/qtum.rs # mm2src/coins/utxo/slp.rs # mm2src/coins/utxo/utxo_standard.rs # mm2src/coins/z_coin.rs # mm2src/coins_activation/src/bch_with_tokens_activation.rs # mm2src/coins_activation/src/erc20_token_activation.rs # mm2src/coins_activation/src/eth_with_token_activation.rs # mm2src/coins_activation/src/init_erc20_token_activation.rs # mm2src/coins_activation/src/init_token.rs # mm2src/coins_activation/src/platform_coin_with_tokens.rs # mm2src/coins_activation/src/slp_token_activation.rs # mm2src/coins_activation/src/tendermint_with_assets_activation.rs # mm2src/coins_activation/src/token.rs # mm2src/mm2_main/src/lp_swap.rs # mm2src/mm2_main/src/lp_swap/check_balance.rs # mm2src/mm2_main/src/lp_swap/maker_swap.rs # mm2src/mm2_main/src/lp_swap/max_maker_vol_rpc.rs # mm2src/mm2_main/src/lp_swap/swap_v2_rpcs.rs # mm2src/mm2_main/src/lp_swap/taker_swap.rs # mm2src/mm2_main/src/lp_swap/trade_preimage.rs # mm2src/mm2_main/src/rpc/dispatcher/dispatcher.rs # mm2src/mm2_main/src/rpc/lp_commands/legacy.rs # mm2src/mm2_main/src/rpc/lp_commands/lr_swap.rs # mm2src/mm2_main/src/rpc/lp_commands/lr_swap/lr_impl.rs # mm2src/mm2_main/src/rpc/lp_commands/one_inch/errors.rs # mm2src/mm2_main/src/rpc/lp_commands/one_inch/rpcs.rs # mm2src/mm2_main/src/rpc/lp_commands/tokens.rs # mm2src/mm2_main/tests/docker_tests/docker_tests_common.rs # mm2src/mm2_main/tests/docker_tests/docker_tests_inner.rs # mm2src/mm2_main/tests/docker_tests/eth_docker_tests.rs # mm2src/mm2_main/tests/integration_tests_common/mod.rs # mm2src/trading_api/src/one_inch_api/client.rs
… coins (#2563) This commit fixes the `UnexpectedEnd` error that caused swap failures for several UTXO-based coins, including Namecoin (NMC), Cheetahcoin (CHTA), and eCash (XEC). It also adds `test_scan_and_deserialize_block_headers` as a utility ignored test to debug similar deserialization errors in the future.
Resolves #2048
This pull request addresses a critical
UnexpectedEnderror that caused swap failures for several UTXO-based coins, including Namecoin (NMC), Cheetahcoin (CHTA), and eCash (XEC).The Problem
The root cause was an overly broad conditional logic within the
BlockHeader::deserializefunction. This single function attempted to parse multiple different block header formats usingifconditions based on the blockversionnumber. This led to two primary failure modes:1. Incorrect
KAWPOWParsingCoins like CHTA use the same
versionnumber as Ravencoin (0x30000000) for their KAWPOW implementation but do not include the extra header fields (n_height,n_nonce_u64,mix_hash) that RVN does. The deserializer was incorrectly attempting to read these non-existent fields for CHTA, causing a stream read to fail withUnexpectedEnd.2. Brittle AuxPow Detection
The logic for detecting Auxiliary Proof-of-Work (AuxPow) headers relied on a hardcoded list of exact version numbers. The correct method is to check for a specific bit flag (
1 << 8) in the version field, as the base version can change. This made the check fragile and prone to failure if a block with a different base version but an active AuxPow flag was encountered.The Solution
This patch refactors the deserialization logic to be more precise and robust:
1. Specialized KAWPOW Logic
CoinVariant::RVNhas been added inmm2src/mm2_bitcoin/serialization/src/reader.rsmm2src/mm2_bitcoin/chain/src/block_header.rsnow explicitly checksreader.coin_variant().is_rvn()before attempting to parse RVN-specific header fields2. Correct AuxPow Detection
matches!macro to the correct bitmask check:(version & AUXPOW_VERSION_FLAG) != 03. Added Debug Utility Test
test_scan_and_deserialize_block_headers, has been added tomm2src/coins/utxo/utxo_tests.rsImpact
These changes resolve the swap failures for the affected coins and make the UTXO header deserialization logic significantly more robust and maintainable.