From b29841558383a58530319ab4983a550261708d91 Mon Sep 17 00:00:00 2001 From: Antonin Hildebrand Date: Mon, 25 Mar 2019 23:24:06 +0100 Subject: [PATCH] Improve error message about non-active segwit on simnet I started playing with simnet and was confronted with error message: ``` [ERR] FNDG: Unable to broadcast funding tx for ChannelPoint(:0): -22: TX rejected: transaction has witness data, but segwit isn't active yet ``` I wasn't aware of the activation period so I got quite puzzled. Google helped. But I think the message could mention likely cause. Newly it optionally prints something like: ``` (The threshold for segwit activation is 300 blocks on simnet, current best height is 113) ``` --- mempool/mempool.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/mempool/mempool.go b/mempool/mempool.go index 63a86a16..7ada3d29 100644 --- a/mempool/mempool.go +++ b/mempool/mempool.go @@ -927,7 +927,7 @@ func (mp *TxPool) validateReplacement(tx *btcutil.Tx, func (mp *TxPool) maybeAcceptTransaction(tx *btcutil.Tx, isNew, rateLimit, rejectDupOrphans bool) ([]*chainhash.Hash, *TxDesc, error) { txHash := tx.Hash() - // If a transaction has iwtness data, and segwit isn't active yet, If + // If a transaction has witness data, and segwit isn't active yet, If // segwit isn't active yet, then we won't accept it into the mempool as // it can't be mined yet. if tx.MsgTx().HasWitness() { @@ -937,8 +937,14 @@ func (mp *TxPool) maybeAcceptTransaction(tx *btcutil.Tx, isNew, rateLimit, rejec } if !segwitActive { + simnetHint := "" + if mp.cfg.ChainParams.Net == wire.SimNet { + bestHeight := mp.cfg.BestHeight() + simnetHint = fmt.Sprintf(" (The threshold for segwit activation is 300 blocks on simnet, "+ + "current best height is %d)", bestHeight) + } str := fmt.Sprintf("transaction %v has witness data, "+ - "but segwit isn't active yet", txHash) + "but segwit isn't active yet%s", txHash, simnetHint) return nil, nil, txRuleError(wire.RejectNonstandard, str) } }