[NOD-384] Remove mass from rpc results (#449)

* [NOD-384] Remove mass from rpc results

* [NOD-384] Fix tests
This commit is contained in:
Ori Newman 2019-11-04 18:06:01 +02:00 committed by Dan Aharoni
parent a8f0d7b05b
commit 3cc6f2d648
6 changed files with 8 additions and 63 deletions

View File

@ -312,7 +312,6 @@ func insertBlock(dbTx *gorm.DB, rawBlock btcjson.GetBlockVerboseResult) (*dbmode
Nonce: rawBlock.Nonce,
BlueScore: rawBlock.BlueScore,
IsChainBlock: false, // This must be false for updateSelectedParentChain to work properly
Mass: rawBlock.Mass,
}
// Set genesis block as the initial chain block
@ -427,7 +426,6 @@ func insertTransaction(dbTx *gorm.DB, transaction *btcjson.TxRawResult, dbSubnet
LockTime: transaction.LockTime,
SubnetworkID: dbSubnetwork.ID,
Gas: transaction.Gas,
Mass: transaction.Mass,
PayloadHash: transaction.PayloadHash,
Payload: payload,
}

View File

@ -34,7 +34,6 @@ type GetBlockVerboseResult struct {
Size int32 `json:"size"`
Height uint64 `json:"height"`
BlueScore uint64 `json:"blueScore"`
Mass uint64 `json:"mass"`
IsChainBlock bool `json:"isChainBlock"`
Version int32 `json:"version"`
VersionHex string `json:"versionHex"`
@ -440,7 +439,6 @@ type TxRawResult struct {
LockTime uint64 `json:"lockTime"`
Subnetwork string `json:"subnetwork"`
Gas uint64 `json:"gas"`
Mass uint64 `json:"mass"`
PayloadHash string `json:"payloadHash"`
Payload string `json:"payload"`
Vin []Vin `json:"vin"`

View File

@ -64,7 +64,7 @@ func TestDAGSvrWsNtfns(t *testing.T) {
{
name: "txAcceptedVerbose",
newNtfn: func() (interface{}, error) {
return btcjson.NewCmd("txAcceptedVerbose", `{"hex":"001122","txid":"123","version":1,"locktime":4294967295,"subnetwork":"0000000000000000000000000000000000000000","gas":0,"mass":0,"payloadHash":"","payload":"","vin":null,"vout":null,"isInMempool":false}`)
return btcjson.NewCmd("txAcceptedVerbose", `{"hex":"001122","txid":"123","version":1,"locktime":4294967295,"subnetwork":"0000000000000000000000000000000000000000","gas":0,"payloadHash":"","payload":"","vin":null,"vout":null,"isInMempool":false}`)
},
staticNtfn: func() interface{} {
txResult := btcjson.TxRawResult{
@ -79,7 +79,7 @@ func TestDAGSvrWsNtfns(t *testing.T) {
}
return btcjson.NewTxAcceptedVerboseNtfn(txResult)
},
marshalled: `{"jsonrpc":"1.0","method":"txAcceptedVerbose","params":[{"hex":"001122","txId":"123","version":1,"lockTime":4294967295,"subnetwork":"0000000000000000000000000000000000000000","gas":0,"mass":0,"payloadHash":"","payload":"","vin":null,"vout":null,"isInMempool":false}],"id":null}`,
marshalled: `{"jsonrpc":"1.0","method":"txAcceptedVerbose","params":[{"hex":"001122","txId":"123","version":1,"lockTime":4294967295,"subnetwork":"0000000000000000000000000000000000000000","gas":0,"payloadHash":"","payload":"","vin":null,"vout":null,"isInMempool":false}],"id":null}`,
unmarshalled: &btcjson.TxAcceptedVerboseNtfn{
RawTx: btcjson.TxRawResult{
Hex: "001122",
@ -96,7 +96,7 @@ func TestDAGSvrWsNtfns(t *testing.T) {
{
name: "txAcceptedVerbose with subnetwork, gas and paylaod",
newNtfn: func() (interface{}, error) {
return btcjson.NewCmd("txAcceptedVerbose", `{"hex":"001122","txId":"123","version":1,"lockTime":4294967295,"subnetwork":"000000000000000000000000000000000000432d","gas":10,"mass":0,"payloadHash":"bf8ccdb364499a3e628200c3d3512c2c2a43b7a7d4f1a40d7f716715e449f442","payload":"102030","vin":null,"vout":null,"isInMempool":false}`)
return btcjson.NewCmd("txAcceptedVerbose", `{"hex":"001122","txId":"123","version":1,"lockTime":4294967295,"subnetwork":"000000000000000000000000000000000000432d","gas":10,"payloadHash":"bf8ccdb364499a3e628200c3d3512c2c2a43b7a7d4f1a40d7f716715e449f442","payload":"102030","vin":null,"vout":null,"isInMempool":false}`)
},
staticNtfn: func() interface{} {
txResult := btcjson.TxRawResult{
@ -114,7 +114,7 @@ func TestDAGSvrWsNtfns(t *testing.T) {
}
return btcjson.NewTxAcceptedVerboseNtfn(txResult)
},
marshalled: `{"jsonrpc":"1.0","method":"txAcceptedVerbose","params":[{"hex":"001122","txId":"123","version":1,"lockTime":4294967295,"subnetwork":"000000000000000000000000000000000000432d","gas":10,"mass":0,"payloadHash":"bf8ccdb364499a3e628200c3d3512c2c2a43b7a7d4f1a40d7f716715e449f442","payload":"102030","vin":null,"vout":null,"isInMempool":false}],"id":null}`,
marshalled: `{"jsonrpc":"1.0","method":"txAcceptedVerbose","params":[{"hex":"001122","txId":"123","version":1,"lockTime":4294967295,"subnetwork":"000000000000000000000000000000000000432d","gas":10,"payloadHash":"bf8ccdb364499a3e628200c3d3512c2c2a43b7a7d4f1a40d7f716715e449f442","payload":"102030","vin":null,"vout":null,"isInMempool":false}],"id":null}`,
unmarshalled: &btcjson.TxAcceptedVerboseNtfn{
RawTx: btcjson.TxRawResult{
Hex: "001122",

View File

@ -4,7 +4,6 @@ import (
"bytes"
"encoding/hex"
"fmt"
"github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/btcjson"
"github.com/daglabs/btcd/dagconfig"
"github.com/daglabs/btcd/txscript"
@ -142,7 +141,7 @@ func createVoutList(mtx *wire.MsgTx, chainParams *dagconfig.Params, filterAddrMa
// to a raw transaction JSON object.
func createTxRawResult(dagParams *dagconfig.Params, mtx *wire.MsgTx,
txID string, blkHeader *wire.BlockHeader, blkHash string,
acceptingBlock *daghash.Hash, confirmations *uint64, isInMempool bool, txMass uint64) (*btcjson.TxRawResult, error) {
acceptingBlock *daghash.Hash, confirmations *uint64, isInMempool bool) (*btcjson.TxRawResult, error) {
mtxHex, err := messageToHex(mtx)
if err != nil {
@ -165,7 +164,6 @@ func createTxRawResult(dagParams *dagconfig.Params, mtx *wire.MsgTx,
LockTime: mtx.LockTime,
Subnetwork: mtx.SubnetworkID.String(),
Gas: mtx.Gas,
Mass: txMass,
PayloadHash: payloadHash,
Payload: hex.EncodeToString(mtx.Payload),
}
@ -240,17 +238,6 @@ func buildGetBlockVerboseResult(s *Server, block *util.Block, isVerboseTx bool)
return nil, internalRPCError(err.Error(), context)
}
pastUTXO, err := s.cfg.DAG.BlockPastUTXO(block.Hash())
if err != nil {
context := "Could not get block past utxo"
return nil, internalRPCError(err.Error(), context)
}
blockMass, err := blockdag.CalcBlockMass(pastUTXO, block.Transactions())
if err != nil {
context := "Could not get block mass"
return nil, internalRPCError(err.Error(), context)
}
isChainBlock := s.cfg.DAG.IsInSelectedParentChain(hash)
result := &btcjson.GetBlockVerboseResult{
@ -266,7 +253,6 @@ func buildGetBlockVerboseResult(s *Server, block *util.Block, isVerboseTx bool)
Confirmations: blockConfirmations,
Height: blockChainHeight,
BlueScore: blockBlueScore,
Mass: blockMass,
IsChainBlock: isChainBlock,
Size: int32(block.MsgBlock().SerializeSize()),
Bits: strconv.FormatInt(int64(blockHeader.Bits), 16),
@ -299,12 +285,8 @@ func buildGetBlockVerboseResult(s *Server, block *util.Block, isVerboseTx bool)
}
confirmations = &txConfirmations
}
txMass, err := blockdag.CalcTxMassFromUTXOSet(tx, pastUTXO)
if err != nil {
return nil, err
}
rawTxn, err := createTxRawResult(params, tx.MsgTx(), tx.ID().String(),
&blockHeader, hash.String(), acceptingBlock, confirmations, false, txMass)
&blockHeader, hash.String(), acceptingBlock, confirmations, false)
if err != nil {
return nil, err
}

View File

@ -4,7 +4,6 @@ import (
"bytes"
"encoding/hex"
"github.com/daglabs/btcd/blockdag"
"github.com/daglabs/btcd/btcjson"
"github.com/daglabs/btcd/database"
"github.com/daglabs/btcd/util"
@ -31,7 +30,6 @@ func handleGetRawTransaction(s *Server, cmd interface{}, closeChan <-chan struct
// try the block database.
var tx *util.Tx
var blkHash *daghash.Hash
var txMass uint64
isInMempool := false
mempoolTx, err := s.cfg.TxMemPool.FetchTransaction(txID)
if err != nil {
@ -68,10 +66,6 @@ func handleGetRawTransaction(s *Server, cmd interface{}, closeChan <-chan struct
}
tx = util.NewTx(&mtx)
txMass, err = calcTxMassFromTxIndex(s, tx)
if err != nil {
return nil, err
}
} else {
// When the verbose flag isn't set, simply return the
// network-serialized transaction as a hex-encoded string.
@ -88,12 +82,6 @@ func handleGetRawTransaction(s *Server, cmd interface{}, closeChan <-chan struct
return mtxHex, nil
}
var err error
txMass, err = blockdag.CalcTxMassFromUTXOSet(mempoolTx, s.cfg.DAG.UTXOSet())
if err != nil {
return nil, err
}
tx = mempoolTx
isInMempool = true
}
@ -121,34 +109,13 @@ func handleGetRawTransaction(s *Server, cmd interface{}, closeChan <-chan struct
}
}
rawTxn, err := createTxRawResult(s.cfg.DAGParams, tx.MsgTx(), txID.String(),
blkHeader, blkHashStr, nil, &confirmations, isInMempool, txMass)
blkHeader, blkHashStr, nil, &confirmations, isInMempool)
if err != nil {
return nil, err
}
return *rawTxn, nil
}
func calcTxMassFromTxIndex(s *Server, tx *util.Tx) (uint64, error) {
if tx.IsCoinBase() {
return blockdag.CalcTxMass(tx, nil), nil
}
previousScriptPubKeys := make([][]byte, len(tx.MsgTx().TxIn))
for i, txIn := range tx.MsgTx().TxIn {
txBytes, _, err := fetchTxBytesAndBlockHashFromTxIndex(s, &txIn.PreviousOutpoint.TxID)
if err != nil {
return 0, err
}
var msgTx wire.MsgTx
err = msgTx.Deserialize(bytes.NewReader(txBytes))
if err != nil {
context := "Failed to deserialize transaction"
return 0, internalRPCError(err.Error(), context)
}
previousScriptPubKeys[i] = msgTx.TxOut[txIn.PreviousOutpoint.Index].ScriptPubKey
}
return blockdag.CalcTxMass(tx, previousScriptPubKeys), nil
}
func fetchTxBytesAndBlockHashFromTxIndex(s *Server, txID *daghash.TxID) ([]byte, *daghash.Hash, error) {
blockRegion, err := s.cfg.TxIndex.TxFirstBlockRegion(txID)
if err != nil {

View File

@ -735,7 +735,7 @@ func (m *wsNotificationManager) notifyForNewTx(clients map[chan struct{}]*wsClie
initializeMarshalledJSONVerbose := func() bool {
net := m.server.cfg.DAGParams
build := func() ([]byte, bool) {
rawTx, err := createTxRawResult(net, mtx, txIDStr, nil, "", nil, nil, true, 0)
rawTx, err := createTxRawResult(net, mtx, txIDStr, nil, "", nil, nil, true)
if err != nil {
return nil, false
}