mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-03-30 15:08:33 +00:00
(#DEV-14) Removed segwit from mempool package + anything related to virtual size in btcjson and btcd
This commit is contained in:
parent
82b87df13e
commit
7930ceebd4
@ -257,7 +257,6 @@ type GetPeerInfoResult struct {
|
||||
// getrawmempool returns an array of transaction hashes.
|
||||
type GetRawMempoolVerboseResult struct {
|
||||
Size int32 `json:"size"`
|
||||
Vsize int32 `json:"vsize"`
|
||||
Fee float64 `json:"fee"`
|
||||
Time int64 `json:"time"`
|
||||
Height int64 `json:"height"`
|
||||
@ -444,7 +443,6 @@ type TxRawResult struct {
|
||||
Txid string `json:"txid"`
|
||||
Hash string `json:"hash,omitempty"`
|
||||
Size int32 `json:"size,omitempty"`
|
||||
Vsize int32 `json:"vsize,omitempty"`
|
||||
Version int32 `json:"version"`
|
||||
LockTime uint32 `json:"locktime"`
|
||||
Vin []Vin `json:"vin"`
|
||||
@ -462,7 +460,6 @@ type SearchRawTransactionsResult struct {
|
||||
Txid string `json:"txid"`
|
||||
Hash string `json:"hash"`
|
||||
Size string `json:"size"`
|
||||
Vsize string `json:"vsize"`
|
||||
Version int32 `json:"version"`
|
||||
LockTime uint32 `json:"locktime"`
|
||||
Vin []VinPrevOut `json:"vin"`
|
||||
|
@ -208,7 +208,7 @@ func (ef *FeeEstimator) ObserveTransaction(t *TxDesc) {
|
||||
|
||||
hash := *t.Tx.Hash()
|
||||
if _, ok := ef.observed[hash]; !ok {
|
||||
size := uint32(GetTxVirtualSize(t.Tx))
|
||||
size := uint32(t.Tx.MsgTx().SerializeSize())
|
||||
|
||||
ef.observed[hash] = &observedTransaction{
|
||||
hash: hash,
|
||||
|
@ -527,7 +527,7 @@ func (mp *TxPool) addTransaction(utxoView *blockchain.UtxoViewpoint, tx *btcutil
|
||||
Added: time.Now(),
|
||||
Height: height,
|
||||
Fee: fee,
|
||||
FeePerKB: fee * 1000 / GetTxVirtualSize(tx),
|
||||
FeePerKB: fee * 1000 / int64(tx.MsgTx().SerializeSize()),
|
||||
},
|
||||
StartingPriority: mining.CalcPriority(tx.MsgTx(), utxoView, height),
|
||||
}
|
||||
@ -639,22 +639,6 @@ func (mp *TxPool) FetchTransaction(txHash *chainhash.Hash) (*btcutil.Tx, error)
|
||||
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
|
||||
// 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() {
|
||||
segwitActive, err := mp.cfg.IsDeploymentActive(chaincfg.DeploymentSegwit)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
if !segwitActive {
|
||||
str := fmt.Sprintf("transaction %v has witness data, "+
|
||||
"but segwit isn't active yet", txHash)
|
||||
return nil, nil, txRuleError(wire.RejectNonstandard, str)
|
||||
}
|
||||
}
|
||||
|
||||
// Don't accept the transaction if it already exists in the pool. This
|
||||
// applies to orphan transactions as well when the reject duplicate
|
||||
// orphans flag is set. This check is intended to be a quick check to
|
||||
@ -825,8 +809,7 @@ func (mp *TxPool) maybeAcceptTransaction(tx *btcutil.Tx, isNew, rateLimit, rejec
|
||||
// the coinbase address itself can contain signature operations, the
|
||||
// maximum allowed signature operations per transaction is less than
|
||||
// the maximum allowed signature operations per block.
|
||||
// TODO(roasbeef): last bool should be conditional on segwit activation
|
||||
sigOpCost, err := blockchain.GetSigOpCost(tx, false, utxoView, true, true)
|
||||
sigOpCost, err := blockchain.GetSigOpCost(tx, false, utxoView, true, false)
|
||||
if err != nil {
|
||||
if cerr, ok := err.(blockchain.RuleError); ok {
|
||||
return nil, nil, chainRuleError(cerr)
|
||||
@ -850,7 +833,7 @@ func (mp *TxPool) maybeAcceptTransaction(tx *btcutil.Tx, isNew, rateLimit, rejec
|
||||
// which is more desirable. Therefore, as long as the size of the
|
||||
// transaction does not exceeed 1000 less than the reserved space for
|
||||
// high-priority transactions, don't require a fee for it.
|
||||
serializedSize := GetTxVirtualSize(tx)
|
||||
serializedSize := int64(tx.MsgTx().SerializeSize())
|
||||
minFee := calcMinRequiredTxRelayFee(serializedSize,
|
||||
mp.cfg.Policy.MinRelayTxFee)
|
||||
if serializedSize >= (DefaultBlockPrioritySize-1000) && txFee < minFee {
|
||||
@ -1196,7 +1179,6 @@ func (mp *TxPool) RawMempoolVerbose() map[string]*btcjson.GetRawMempoolVerboseRe
|
||||
|
||||
mpd := &btcjson.GetRawMempoolVerboseResult{
|
||||
Size: int32(tx.MsgTx().SerializeSize()),
|
||||
Vsize: int32(GetTxVirtualSize(tx)),
|
||||
Fee: btcutil.Amount(desc.Fee).ToBTC(),
|
||||
Time: desc.Added.Unix(),
|
||||
Height: int64(desc.Height),
|
||||
|
@ -19,10 +19,6 @@ const (
|
||||
// that are considered standard in a pay-to-script-hash script.
|
||||
maxStandardP2SHSigOps = 15
|
||||
|
||||
// maxStandardTxCost is the max weight permitted by any transaction
|
||||
// according to the current default policy.
|
||||
maxStandardTxWeight = 400000
|
||||
|
||||
// maxStandardSigScriptSize is the maximum size allowed for a
|
||||
// transaction input signature script to be considered standard. This
|
||||
// value allows for a 15-of-15 CHECKMULTISIG pay-to-script-hash with
|
||||
@ -42,6 +38,11 @@ const (
|
||||
// (1 + 15*74 + 3) + (15*34 + 3) + 23 = 1650
|
||||
maxStandardSigScriptSize = 1650
|
||||
|
||||
// MaxStandardTxSize is the maximum size allowed for transactions that
|
||||
// are considered standard and will therefore be relayed and considered
|
||||
// for mining.
|
||||
MaxStandardTxSize = 100000
|
||||
|
||||
// DefaultMinRelayTxFee is the minimum fee in satoshi that is required
|
||||
// for a transaction to be treated as free for relay and mining
|
||||
// purposes. It is also used to help determine if a transaction is
|
||||
@ -215,18 +216,6 @@ func isDust(txOut *wire.TxOut, minRelayTxFee btcutil.Amount) bool {
|
||||
// 36 prev outpoint, 1 script len, 73 script [1 OP_DATA_72,
|
||||
// 72 sig], 4 sequence
|
||||
//
|
||||
// Pay-to-witness-pubkey-hash bytes breakdown:
|
||||
//
|
||||
// Output to witness key hash (31 bytes);
|
||||
// 8 value, 1 script len, 22 script [1 OP_0, 1 OP_DATA_20,
|
||||
// 20 bytes hash160]
|
||||
//
|
||||
// Input (67 bytes as the 107 witness stack is discounted):
|
||||
// 36 prev outpoint, 1 script len, 0 script (not sigScript), 107
|
||||
// witness stack bytes [1 element length, 33 compressed pubkey,
|
||||
// element length 72 sig], 4 sequence
|
||||
//
|
||||
//
|
||||
// Theoretically this could examine the script type of the output script
|
||||
// and use a different size for the typical input script size for
|
||||
// pay-to-pubkey vs pay-to-pubkey-hash inputs per the above breakdowns,
|
||||
@ -236,22 +225,8 @@ func isDust(txOut *wire.TxOut, minRelayTxFee btcutil.Amount) bool {
|
||||
//
|
||||
// The most common scripts are pay-to-pubkey-hash, and as per the above
|
||||
// breakdown, the minimum size of a p2pkh input script is 148 bytes. So
|
||||
// that figure is used. If the output being spent is a witness program,
|
||||
// then we apply the witness discount to the size of the signature.
|
||||
//
|
||||
// The segwit analogue to p2pkh is a p2wkh output. This is the smallest
|
||||
// output possible using the new segwit features. The 107 bytes of
|
||||
// witness data is discounted by a factor of 4, leading to a computed
|
||||
// value of 67 bytes of witness data.
|
||||
//
|
||||
// Both cases share a 41 byte preamble required to reference the input
|
||||
// being spent and the sequence number of the input.
|
||||
totalSize := txOut.SerializeSize() + 41
|
||||
if txscript.IsWitnessProgram(txOut.PkScript) {
|
||||
totalSize += (107 / blockchain.WitnessScaleFactor)
|
||||
} else {
|
||||
totalSize += 107
|
||||
}
|
||||
// that figure is used.
|
||||
totalSize := txOut.SerializeSize() + 148
|
||||
|
||||
// The output is considered dust if the cost to the network to spend the
|
||||
// coins is more than 1/3 of the minimum free transaction relay fee.
|
||||
@ -299,10 +274,10 @@ func checkTransactionStandard(tx *btcutil.Tx, height int32,
|
||||
// almost as much to process as the sender fees, limit the maximum
|
||||
// size of a transaction. This also helps mitigate CPU exhaustion
|
||||
// attacks.
|
||||
txWeight := blockchain.GetTransactionWeight(tx)
|
||||
if txWeight > maxStandardTxWeight {
|
||||
str := fmt.Sprintf("weight of transaction %v is larger than max "+
|
||||
"allowed weight of %v", txWeight, maxStandardTxWeight)
|
||||
serializedLen := msgTx.SerializeSize()
|
||||
if serializedLen > MaxStandardTxSize {
|
||||
str := fmt.Sprintf("transaction size of %v is larger than max "+
|
||||
"allowed size of %v", serializedLen, MaxStandardTxSize)
|
||||
return txRuleError(wire.RejectNonstandard, str)
|
||||
}
|
||||
|
||||
@ -367,16 +342,3 @@ func checkTransactionStandard(tx *btcutil.Tx, height int32,
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// GetTxVirtualSize computes the virtual size of a given transaction. A
|
||||
// transaction's virtual size is based off its weight, creating a discount for
|
||||
// any witness data it contains, proportional to the current
|
||||
// blockchain.WitnessScaleFactor value.
|
||||
func GetTxVirtualSize(tx *btcutil.Tx) int64 {
|
||||
// vSize := (weight(tx) + 3) / 4
|
||||
// := (((baseSize * 3) + totalSize) + 3) / 4
|
||||
// We add 3 here as a way to compute the ceiling of the prior arithmetic
|
||||
// to 4. The division by 4 creates a discount for wit witness data.
|
||||
return (blockchain.GetTransactionWeight(tx) + (blockchain.WitnessScaleFactor - 1)) /
|
||||
blockchain.WitnessScaleFactor
|
||||
}
|
||||
|
@ -41,13 +41,13 @@ func TestCalcMinRequiredTxRelayFee(t *testing.T) {
|
||||
},
|
||||
{
|
||||
"max standard tx size with default minimum relay fee",
|
||||
maxStandardTxWeight / 4,
|
||||
MaxStandardTxSize,
|
||||
DefaultMinRelayTxFee,
|
||||
100000,
|
||||
},
|
||||
{
|
||||
"max standard tx size with max satoshi relay fee",
|
||||
maxStandardTxWeight / 4,
|
||||
MaxStandardTxSize,
|
||||
btcutil.MaxSatoshi,
|
||||
btcutil.MaxSatoshi,
|
||||
},
|
||||
@ -360,7 +360,7 @@ func TestCheckTransactionStandard(t *testing.T) {
|
||||
TxOut: []*wire.TxOut{{
|
||||
Value: 0,
|
||||
PkScript: bytes.Repeat([]byte{0x00},
|
||||
(maxStandardTxWeight/4)+1),
|
||||
MaxStandardTxSize+1),
|
||||
}},
|
||||
LockTime: 0,
|
||||
},
|
||||
|
@ -733,7 +733,6 @@ func createTxRawResult(chainParams *chaincfg.Params, mtx *wire.MsgTx,
|
||||
Txid: txHash,
|
||||
Hash: mtx.TxHash().String(),
|
||||
Size: int32(mtx.SerializeSize()),
|
||||
Vsize: int32(mempool.GetTxVirtualSize(btcutil.NewTx(mtx))),
|
||||
Vin: createVinList(mtx),
|
||||
Vout: createVoutList(mtx, chainParams, nil),
|
||||
Version: mtx.Version,
|
||||
|
@ -204,7 +204,6 @@ var helpDescsEnUS = map[string]string{
|
||||
"txrawresult-time": "Transaction time in seconds since 1 Jan 1970 GMT",
|
||||
"txrawresult-blocktime": "Block time in seconds since the 1 Jan 1970 GMT",
|
||||
"txrawresult-size": "The size of the transaction in bytes",
|
||||
"txrawresult-vsize": "The virtual size of the transaction in bytes",
|
||||
"txrawresult-hash": "The wtxid of the transaction",
|
||||
|
||||
// SearchRawTransactionsResult help.
|
||||
@ -220,7 +219,6 @@ var helpDescsEnUS = map[string]string{
|
||||
"searchrawtransactionsresult-time": "Transaction time in seconds since 1 Jan 1970 GMT",
|
||||
"searchrawtransactionsresult-blocktime": "Block time in seconds since the 1 Jan 1970 GMT",
|
||||
"searchrawtransactionsresult-size": "The size of the transaction in bytes",
|
||||
"searchrawtransactionsresult-vsize": "The virtual size of the transaction in bytes",
|
||||
|
||||
// GetBlockVerboseResult help.
|
||||
"getblockverboseresult-hash": "The hash of the block (same as provided)",
|
||||
@ -467,7 +465,6 @@ var helpDescsEnUS = map[string]string{
|
||||
"getrawmempoolverboseresult-startingpriority": "Priority when transaction entered the pool",
|
||||
"getrawmempoolverboseresult-currentpriority": "Current priority",
|
||||
"getrawmempoolverboseresult-depends": "Unconfirmed transactions used as inputs for this transaction",
|
||||
"getrawmempoolverboseresult-vsize": "The virtual size of a transaction",
|
||||
|
||||
// GetRawMempoolCmd help.
|
||||
"getrawmempool--synopsis": "Returns information about all of the transactions currently in the memory pool.",
|
||||
|
Loading…
x
Reference in New Issue
Block a user