diff --git a/BRPeer.c b/BRPeer.c index 27af838..0d1e313 100644 --- a/BRPeer.c +++ b/BRPeer.c @@ -419,6 +419,7 @@ static int _BRPeerAcceptTxMessage(BRPeer *peer, const uint8_t *msg, size_t msgLe uint64_t feeAmount = BRTransactionStandardFee(tx); //DEV: uncomment for debugging +// peer_log(peer, "from _BRPeerAcceptTxMessage"); // peer_log(peer, "tx details: hash=%s, version=%d, blockHeight=%d, timestamp=%d, lockTime=%u", // u256hex(tx->txHash), tx->version, tx->blockHeight, tx->timestamp, tx->lockTime); // @@ -438,15 +439,19 @@ static int _BRPeerAcceptTxMessage(BRPeer *peer, const uint8_t *msg, size_t msgLe // } // // peer_log(peer, "tx size=%zu bytes, fee=%llu", txSize, feeAmount); +// +// if (feeAmount/txSize < 10) { +// peer_log(peer, "stuck tx: %s, (low fee: %llu lit/byte)", u256hex(txHash), feeAmount/txSize); +// } - if (txSize > 0 && tx->blockHeight == TX_UNCONFIRMED && feeAmount/txSize < 10) { - //don't relay to wallet - peer_log(peer, "skipping stuck transaction: %s, (low fee: %llu litoshis/byte, min. is 10 litoshis/byte)", u256hex(txHash), feeAmount/txSize); + // Check if the transaction has a low fee rate + if (txSize > 0 && tx->blockHeight == TX_UNCONFIRMED && tx->timestamp == 0 && feeAmount/txSize < 10) { + // Don't relay to wallet + peer_log(peer, "skipping stuck transaction: %s, (low fee: %llu sat/byte)", u256hex(txHash), feeAmount/txSize); BRTransactionFree(tx); if (ctx->rejectedTx) ctx->rejectedTx(ctx->info, txHash, REJECT_LOWFEE); - r = 1; - } - else if (ctx->relayedTx) { + r = 0; + } else if (ctx->relayedTx) { ctx->relayedTx(ctx->info, tx); } else BRTransactionFree(tx); @@ -577,6 +582,35 @@ static int _BRPeerAcceptGetdataMessage(BRPeer *peer, const uint8_t *msg, size_t } peer_log(peer, "publishing tx: %s", txHex); + + size_t txSize = BRTransactionSize(tx); + uint64_t feeAmount = BRTransactionStandardFee(tx); + + //DEV: uncomment for debugging +// peer_log(peer, "from _BRPeerAcceptGetdataMessage"); +// peer_log(peer, "tx details: hash=%s, version=%d, blockHeight=%d, timestamp=%d, lockTime=%u", +// u256hex(tx->txHash), tx->version, tx->blockHeight, tx->timestamp, tx->lockTime); +// +// peer_log(peer, "tx inputs: count=%zu", tx->inCount); +// for (size_t i = 0; i < tx->inCount; i++) { +// peer_log(peer, " input[%zu]: txHash=%s, index=%u, signature length=%zu, sequence=%u", +// i, u256hex(tx->inputs[i].txHash), tx->inputs[i].index, +// tx->inputs[i].sigLen, tx->inputs[i].sequence); +// } +// +// peer_log(peer, "tx outputs: count=%zu", tx->outCount); +// for (size_t j = 0; j < tx->outCount; j++) { +// char addr[75] = ""; +// BRAddressFromScriptPubKey(addr, sizeof(addr), tx->outputs[j].script, tx->outputs[j].scriptLen); +// peer_log(peer, " output[%zu]: amount=%llu, scriptLen=%zu, address=%s", +// j, tx->outputs[j].amount, tx->outputs[j].scriptLen, addr); +// } +// +// peer_log(peer, "tx size=%zu bytes, fee=%llu", txSize, feeAmount); +// if (feeAmount/txSize < 10) { +// peer_log(peer, "stuck tx: %s, (low fee: %llu lit/byte)", u256hex(tx->txHash), feeAmount/txSize); +// } + BRPeerSendMessage(peer, buf, bufLen, MSG_TX); break; } diff --git a/BRPeerManager.c b/BRPeerManager.c index 4af405b..1375c56 100644 --- a/BRPeerManager.c +++ b/BRPeerManager.c @@ -1222,6 +1222,35 @@ static void _peerHasTx(void *info, UInt256 txHash) } if (tx) { + + //DEV: uncomment for debugging +// peer_log(peer, "from _peerHasTx"); +// size_t txSize = BRTransactionSize(tx); +// uint64_t feeAmount = BRTransactionStandardFee(tx); +// peer_log(peer, "tx details: hash=%s, version=%d, blockHeight=%d, timestamp=%d, lockTime=%u", +// u256hex(tx->txHash), tx->version, tx->blockHeight, tx->timestamp, tx->lockTime); +// +// peer_log(peer, "tx inputs: count=%zu", tx->inCount); +// for (size_t i = 0; i < tx->inCount; i++) { +// peer_log(peer, " input[%zu]: txHash=%s, index=%u, signature length=%zu, sequence=%u", +// i, u256hex(tx->inputs[i].txHash), tx->inputs[i].index, +// tx->inputs[i].sigLen, tx->inputs[i].sequence); +// } +// +// peer_log(peer, "tx outputs: count=%zu", tx->outCount); +// for (size_t j = 0; j < tx->outCount; j++) { +// char addr[75] = ""; +// BRAddressFromScriptPubKey(addr, sizeof(addr), tx->outputs[j].script, tx->outputs[j].scriptLen); +// peer_log(peer, " output[%zu]: amount=%llu, scriptLen=%zu, address=%s", +// j, tx->outputs[j].amount, tx->outputs[j].scriptLen, addr); +// } +// +// peer_log(peer, "tx size=%zu bytes, fee=%llu", txSize, feeAmount); +// if (feeAmount/txSize < 10) { +// peer_log(peer, "stuck tx: %s, (low fee: %llu lit/byte)", u256hex(tx->txHash), feeAmount/txSize); +// } + + isWalletTx = BRWalletRegisterTransaction(manager->wallet, tx); if (isWalletTx) tx = BRWalletTransactionForHash(manager->wallet, tx->txHash); @@ -1258,13 +1287,6 @@ static void _peerRejectedTx(void *info, UInt256 txHash, uint8_t code) _BRTxPeerListRemovePeer(manager->txRequests, txHash, peer); if (tx) { - - // Handle tx rejection - if (tx->blockHeight == TX_UNCONFIRMED && (code == REJECT_DUST || code == REJECT_LOWFEE || code == REJECT_NONSTANDARD)) { - peer_log(peer, "transaction rejected as dust/lowfee/nonstandard, removing: %s", u256hex(txHash)); - BRWalletRemoveTransaction(manager->wallet, txHash); - } - if (_BRTxPeerListRemovePeer(manager->txRelays, txHash, peer) && tx->blockHeight == TX_UNCONFIRMED) { // set timestamp 0 to mark tx as unverified _BRPeerManagerUpdateTx(manager, &txHash, 1, TX_UNCONFIRMED, 0);