mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-05 21:56:50 +00:00
(#DEV-14) Remove anything Segwit related in btcd package + some edits in btcjson+rpcclient to make tests pass
This commit is contained in:
parent
ecf8ea0bee
commit
734abd749b
5
.gitignore
vendored
5
.gitignore
vendored
@ -34,4 +34,7 @@ _testmain.go
|
||||
*.exe
|
||||
|
||||
# IDE
|
||||
.idea
|
||||
.idea
|
||||
.vscode
|
||||
debug
|
||||
debug.test
|
||||
|
@ -30,9 +30,7 @@ type GetBlockHeaderVerboseResult struct {
|
||||
type GetBlockVerboseResult struct {
|
||||
Hash string `json:"hash"`
|
||||
Confirmations uint64 `json:"confirmations"`
|
||||
StrippedSize int32 `json:"strippedsize"`
|
||||
Size int32 `json:"size"`
|
||||
Weight int32 `json:"weight"`
|
||||
Height int64 `json:"height"`
|
||||
Version int32 `json:"version"`
|
||||
VersionHex string `json:"versionHex"`
|
||||
@ -122,7 +120,6 @@ type GetBlockTemplateResultTx struct {
|
||||
Depends []int64 `json:"depends"`
|
||||
Fee int64 `json:"fee"`
|
||||
SigOps int64 `json:"sigops"`
|
||||
Weight int64 `json:"weight"`
|
||||
}
|
||||
|
||||
// GetBlockTemplateResultAux models the coinbaseaux field of the
|
||||
@ -142,7 +139,6 @@ type GetBlockTemplateResult struct {
|
||||
PreviousHash string `json:"previousblockhash"`
|
||||
SigOpLimit int64 `json:"sigoplimit,omitempty"`
|
||||
SizeLimit int64 `json:"sizelimit,omitempty"`
|
||||
WeightLimit int64 `json:"weightlimit,omitempty"`
|
||||
Transactions []GetBlockTemplateResultTx `json:"transactions"`
|
||||
Version int32 `json:"version"`
|
||||
CoinbaseAux *GetBlockTemplateResultAux `json:"coinbaseaux,omitempty"`
|
||||
@ -150,9 +146,6 @@ type GetBlockTemplateResult struct {
|
||||
CoinbaseValue *int64 `json:"coinbasevalue,omitempty"`
|
||||
WorkID string `json:"workid,omitempty"`
|
||||
|
||||
// Witness commitment defined in BIP 0141.
|
||||
DefaultWitnessCommitment string `json:"default_witness_commitment,omitempty"`
|
||||
|
||||
// Optional long polling from BIP 0022.
|
||||
LongPollID string `json:"longpollid,omitempty"`
|
||||
LongPollURI string `json:"longpolluri,omitempty"`
|
||||
@ -316,7 +309,6 @@ type Vin struct {
|
||||
Vout uint32 `json:"vout"`
|
||||
ScriptSig *ScriptSig `json:"scriptSig"`
|
||||
Sequence uint32 `json:"sequence"`
|
||||
Witness []string `json:"txinwitness"`
|
||||
}
|
||||
|
||||
// IsCoinBase returns a bool to show if a Vin is a Coinbase one or not.
|
||||
@ -324,44 +316,19 @@ func (v *Vin) IsCoinBase() bool {
|
||||
return len(v.Coinbase) > 0
|
||||
}
|
||||
|
||||
// HasWitness returns a bool to show if a Vin has any witness data associated
|
||||
// with it or not.
|
||||
func (v *Vin) HasWitness() bool {
|
||||
return len(v.Witness) > 0
|
||||
}
|
||||
|
||||
// MarshalJSON provides a custom Marshal method for Vin.
|
||||
func (v *Vin) MarshalJSON() ([]byte, error) {
|
||||
if v.IsCoinBase() {
|
||||
coinbaseStruct := struct {
|
||||
Coinbase string `json:"coinbase"`
|
||||
Sequence uint32 `json:"sequence"`
|
||||
Witness []string `json:"witness,omitempty"`
|
||||
Coinbase string `json:"coinbase"`
|
||||
Sequence uint32 `json:"sequence"`
|
||||
}{
|
||||
Coinbase: v.Coinbase,
|
||||
Sequence: v.Sequence,
|
||||
Witness: v.Witness,
|
||||
}
|
||||
return json.Marshal(coinbaseStruct)
|
||||
}
|
||||
|
||||
if v.HasWitness() {
|
||||
txStruct := struct {
|
||||
Txid string `json:"txid"`
|
||||
Vout uint32 `json:"vout"`
|
||||
ScriptSig *ScriptSig `json:"scriptSig"`
|
||||
Witness []string `json:"txinwitness"`
|
||||
Sequence uint32 `json:"sequence"`
|
||||
}{
|
||||
Txid: v.Txid,
|
||||
Vout: v.Vout,
|
||||
ScriptSig: v.ScriptSig,
|
||||
Witness: v.Witness,
|
||||
Sequence: v.Sequence,
|
||||
}
|
||||
return json.Marshal(txStruct)
|
||||
}
|
||||
|
||||
txStruct := struct {
|
||||
Txid string `json:"txid"`
|
||||
Vout uint32 `json:"vout"`
|
||||
@ -388,7 +355,6 @@ type VinPrevOut struct {
|
||||
Txid string `json:"txid"`
|
||||
Vout uint32 `json:"vout"`
|
||||
ScriptSig *ScriptSig `json:"scriptSig"`
|
||||
Witness []string `json:"txinwitness"`
|
||||
PrevOut *PrevOut `json:"prevOut"`
|
||||
Sequence uint32 `json:"sequence"`
|
||||
}
|
||||
@ -398,12 +364,6 @@ func (v *VinPrevOut) IsCoinBase() bool {
|
||||
return len(v.Coinbase) > 0
|
||||
}
|
||||
|
||||
// HasWitness returns a bool to show if a Vin has any witness data associated
|
||||
// with it or not.
|
||||
func (v *VinPrevOut) HasWitness() bool {
|
||||
return len(v.Witness) > 0
|
||||
}
|
||||
|
||||
// MarshalJSON provides a custom Marshal method for VinPrevOut.
|
||||
func (v *VinPrevOut) MarshalJSON() ([]byte, error) {
|
||||
if v.IsCoinBase() {
|
||||
@ -417,25 +377,6 @@ func (v *VinPrevOut) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(coinbaseStruct)
|
||||
}
|
||||
|
||||
if v.HasWitness() {
|
||||
txStruct := struct {
|
||||
Txid string `json:"txid"`
|
||||
Vout uint32 `json:"vout"`
|
||||
ScriptSig *ScriptSig `json:"scriptSig"`
|
||||
Witness []string `json:"txinwitness"`
|
||||
PrevOut *PrevOut `json:"prevOut,omitempty"`
|
||||
Sequence uint32 `json:"sequence"`
|
||||
}{
|
||||
Txid: v.Txid,
|
||||
Vout: v.Vout,
|
||||
ScriptSig: v.ScriptSig,
|
||||
Witness: v.Witness,
|
||||
PrevOut: v.PrevOut,
|
||||
Sequence: v.Sequence,
|
||||
}
|
||||
return json.Marshal(txStruct)
|
||||
}
|
||||
|
||||
txStruct := struct {
|
||||
Txid string `json:"txid"`
|
||||
Vout uint32 `json:"vout"`
|
||||
@ -462,18 +403,17 @@ type Vout struct {
|
||||
|
||||
// GetMiningInfoResult models the data from the getmininginfo command.
|
||||
type GetMiningInfoResult struct {
|
||||
Blocks int64 `json:"blocks"`
|
||||
CurrentBlockSize uint64 `json:"currentblocksize"`
|
||||
CurrentBlockWeight uint64 `json:"currentblockweight"`
|
||||
CurrentBlockTx uint64 `json:"currentblocktx"`
|
||||
Difficulty float64 `json:"difficulty"`
|
||||
Errors string `json:"errors"`
|
||||
Generate bool `json:"generate"`
|
||||
GenProcLimit int32 `json:"genproclimit"`
|
||||
HashesPerSec int64 `json:"hashespersec"`
|
||||
NetworkHashPS int64 `json:"networkhashps"`
|
||||
PooledTx uint64 `json:"pooledtx"`
|
||||
TestNet bool `json:"testnet"`
|
||||
Blocks int64 `json:"blocks"`
|
||||
CurrentBlockSize uint64 `json:"currentblocksize"`
|
||||
CurrentBlockTx uint64 `json:"currentblocktx"`
|
||||
Difficulty float64 `json:"difficulty"`
|
||||
Errors string `json:"errors"`
|
||||
Generate bool `json:"generate"`
|
||||
GenProcLimit int32 `json:"genproclimit"`
|
||||
HashesPerSec int64 `json:"hashespersec"`
|
||||
NetworkHashPS int64 `json:"networkhashps"`
|
||||
PooledTx uint64 `json:"pooledtx"`
|
||||
TestNet bool `json:"testnet"`
|
||||
}
|
||||
|
||||
// GetWorkResult models the data from the getwork command.
|
||||
|
@ -27,19 +27,6 @@ func NewAddMultisigAddressCmd(nRequired int, keys []string, account *string) *Ad
|
||||
}
|
||||
}
|
||||
|
||||
// AddWitnessAddressCmd defines the addwitnessaddress JSON-RPC command.
|
||||
type AddWitnessAddressCmd struct {
|
||||
Address string
|
||||
}
|
||||
|
||||
// NewAddWitnessAddressCmd returns a new instance which can be used to issue a
|
||||
// addwitnessaddress JSON-RPC command.
|
||||
func NewAddWitnessAddressCmd(address string) *AddWitnessAddressCmd {
|
||||
return &AddWitnessAddressCmd{
|
||||
Address: address,
|
||||
}
|
||||
}
|
||||
|
||||
// CreateMultisigCmd defines the createmultisig JSON-RPC command.
|
||||
type CreateMultisigCmd struct {
|
||||
NRequired int
|
||||
@ -658,7 +645,6 @@ func init() {
|
||||
flags := UFWalletOnly
|
||||
|
||||
MustRegisterCmd("addmultisigaddress", (*AddMultisigAddressCmd)(nil), flags)
|
||||
MustRegisterCmd("addwitnessaddress", (*AddWitnessAddressCmd)(nil), flags)
|
||||
MustRegisterCmd("createmultisig", (*CreateMultisigCmd)(nil), flags)
|
||||
MustRegisterCmd("dumpprivkey", (*DumpPrivKeyCmd)(nil), flags)
|
||||
MustRegisterCmd("encryptwallet", (*EncryptWalletCmd)(nil), flags)
|
||||
|
@ -61,19 +61,6 @@ func TestWalletSvrCmds(t *testing.T) {
|
||||
Account: btcjson.String("test"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "addwitnessaddress",
|
||||
newCmd: func() (interface{}, error) {
|
||||
return btcjson.NewCmd("addwitnessaddress", "1address")
|
||||
},
|
||||
staticCmd: func() interface{} {
|
||||
return btcjson.NewAddWitnessAddressCmd("1address")
|
||||
},
|
||||
marshalled: `{"jsonrpc":"1.0","method":"addwitnessaddress","params":["1address"],"id":1}`,
|
||||
unmarshalled: &btcjson.AddWitnessAddressCmd{
|
||||
Address: "1address",
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "createmultisig",
|
||||
newCmd: func() (interface{}, error) {
|
||||
|
41
config.go
41
config.go
@ -20,6 +20,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/go-socks/socks"
|
||||
"github.com/daglabs/btcd/blockchain"
|
||||
"github.com/daglabs/btcd/chaincfg"
|
||||
"github.com/daglabs/btcd/chaincfg/chainhash"
|
||||
@ -28,7 +29,6 @@ import (
|
||||
_ "github.com/daglabs/btcd/database/ffldb"
|
||||
"github.com/daglabs/btcd/mempool"
|
||||
"github.com/daglabs/btcutil"
|
||||
"github.com/btcsuite/go-socks/socks"
|
||||
flags "github.com/jessevdk/go-flags"
|
||||
)
|
||||
|
||||
@ -49,12 +49,8 @@ const (
|
||||
defaultFreeTxRelayLimit = 15.0
|
||||
defaultBlockMinSize = 0
|
||||
defaultBlockMaxSize = 750000
|
||||
defaultBlockMinWeight = 0
|
||||
defaultBlockMaxWeight = 3000000
|
||||
blockMaxSizeMin = 1000
|
||||
blockMaxSizeMax = blockchain.MaxBlockBaseSize - 1000
|
||||
blockMaxWeightMin = 4000
|
||||
blockMaxWeightMax = blockchain.MaxBlockWeight - 4000
|
||||
defaultGenerate = false
|
||||
defaultMaxOrphanTransactions = 100
|
||||
defaultMaxOrphanTxSize = 100000
|
||||
@ -145,8 +141,6 @@ type config struct {
|
||||
MiningAddrs []string `long:"miningaddr" description:"Add the specified payment address to the list of addresses to use for generated blocks -- At least one address is required if the generate option is set"`
|
||||
BlockMinSize uint32 `long:"blockminsize" description:"Mininum block size in bytes to be used when creating a block"`
|
||||
BlockMaxSize uint32 `long:"blockmaxsize" description:"Maximum block size in bytes to be used when creating a block"`
|
||||
BlockMinWeight uint32 `long:"blockminweight" description:"Mininum block weight to be used when creating a block"`
|
||||
BlockMaxWeight uint32 `long:"blockmaxweight" description:"Maximum block weight to be used when creating a block"`
|
||||
BlockPrioritySize uint32 `long:"blockprioritysize" description:"Size in bytes for high-priority/low-fee transactions when creating a block"`
|
||||
UserAgentComments []string `long:"uacomment" description:"Comment to add to the user agent -- See BIP 14 for more information."`
|
||||
NoPeerBloomFilters bool `long:"nopeerbloomfilters" description:"Disable bloom filtering support"`
|
||||
@ -417,8 +411,6 @@ func loadConfig() (*config, []string, error) {
|
||||
FreeTxRelayLimit: defaultFreeTxRelayLimit,
|
||||
BlockMinSize: defaultBlockMinSize,
|
||||
BlockMaxSize: defaultBlockMaxSize,
|
||||
BlockMinWeight: defaultBlockMinWeight,
|
||||
BlockMaxWeight: defaultBlockMaxWeight,
|
||||
BlockPrioritySize: mempool.DefaultBlockPrioritySize,
|
||||
MaxOrphanTxs: defaultMaxOrphanTransactions,
|
||||
SigCacheMaxSize: defaultSigCacheMaxSize,
|
||||
@ -771,19 +763,6 @@ func loadConfig() (*config, []string, error) {
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// Limit the max block weight to a sane value.
|
||||
if cfg.BlockMaxWeight < blockMaxWeightMin ||
|
||||
cfg.BlockMaxWeight > blockMaxWeightMax {
|
||||
|
||||
str := "%s: The blockmaxweight option must be in between %d " +
|
||||
"and %d -- parsed [%d]"
|
||||
err := fmt.Errorf(str, funcName, blockMaxWeightMin,
|
||||
blockMaxWeightMax, cfg.BlockMaxWeight)
|
||||
fmt.Fprintln(os.Stderr, err)
|
||||
fmt.Fprintln(os.Stderr, usageMessage)
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
// Limit the max orphan count to a sane vlue.
|
||||
if cfg.MaxOrphanTxs < 0 {
|
||||
str := "%s: The maxorphantx option may not be less than 0 " +
|
||||
@ -797,24 +776,6 @@ func loadConfig() (*config, []string, error) {
|
||||
// Limit the block priority and minimum block sizes to max block size.
|
||||
cfg.BlockPrioritySize = minUint32(cfg.BlockPrioritySize, cfg.BlockMaxSize)
|
||||
cfg.BlockMinSize = minUint32(cfg.BlockMinSize, cfg.BlockMaxSize)
|
||||
cfg.BlockMinWeight = minUint32(cfg.BlockMinWeight, cfg.BlockMaxWeight)
|
||||
|
||||
switch {
|
||||
// If the max block size isn't set, but the max weight is, then we'll
|
||||
// set the limit for the max block size to a safe limit so weight takes
|
||||
// precedence.
|
||||
case cfg.BlockMaxSize == defaultBlockMaxSize &&
|
||||
cfg.BlockMaxWeight != defaultBlockMaxWeight:
|
||||
|
||||
cfg.BlockMaxSize = blockchain.MaxBlockBaseSize - 1000
|
||||
|
||||
// If the max block weight isn't set, but the block size is, then we'll
|
||||
// scale the set weight accordingly based on the max block size value.
|
||||
case cfg.BlockMaxSize != defaultBlockMaxSize &&
|
||||
cfg.BlockMaxWeight == defaultBlockMaxWeight:
|
||||
|
||||
cfg.BlockMaxWeight = cfg.BlockMaxSize * blockchain.WitnessScaleFactor
|
||||
}
|
||||
|
||||
// Look for illegal characters in the user agent comments.
|
||||
for _, uaComment := range cfg.UserAgentComments {
|
||||
|
@ -965,22 +965,6 @@ func (r FutureAddWitnessAddressResult) Receive() (btcutil.Address, error) {
|
||||
return btcutil.DecodeAddress(addr, &chaincfg.MainNetParams)
|
||||
}
|
||||
|
||||
// AddWitnessAddressAsync returns an instance of a type that can be used to get
|
||||
// the result of the RPC at some future time by invoking the Receive function on
|
||||
// the returned instance.
|
||||
//
|
||||
// See AddWitnessAddress for the blocking version and more details.
|
||||
func (c *Client) AddWitnessAddressAsync(address string) FutureAddWitnessAddressResult {
|
||||
cmd := btcjson.NewAddWitnessAddressCmd(address)
|
||||
return c.sendCmd(cmd)
|
||||
}
|
||||
|
||||
// AddWitnessAddress adds a witness address for a script and returns the new
|
||||
// address (P2SH of the witness script).
|
||||
func (c *Client) AddWitnessAddress(address string) (btcutil.Address, error) {
|
||||
return c.AddWitnessAddressAsync(address).Receive()
|
||||
}
|
||||
|
||||
// FutureGetAccountAddressResult is a future promise to deliver the result of a
|
||||
// GetAccountAddressAsync RPC invocation (or an applicable error).
|
||||
type FutureGetAccountAddressResult chan *response
|
||||
|
74
rpcserver.go
74
rpcserver.go
@ -27,6 +27,7 @@ import (
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/btcsuite/websocket"
|
||||
"github.com/daglabs/btcd/blockchain"
|
||||
"github.com/daglabs/btcd/blockchain/indexers"
|
||||
"github.com/daglabs/btcd/btcec"
|
||||
@ -41,7 +42,6 @@ import (
|
||||
"github.com/daglabs/btcd/txscript"
|
||||
"github.com/daglabs/btcd/wire"
|
||||
"github.com/daglabs/btcutil"
|
||||
"github.com/btcsuite/websocket"
|
||||
)
|
||||
|
||||
// API version constants
|
||||
@ -500,7 +500,7 @@ func peerExists(connMgr rpcserverConnManager, addr string, nodeID int32) bool {
|
||||
// latest protocol version and returns a hex-encoded string of the result.
|
||||
func messageToHex(msg wire.Message) (string, error) {
|
||||
var buf bytes.Buffer
|
||||
if err := msg.BtcEncode(&buf, maxProtocolVersion, wire.WitnessEncoding); err != nil {
|
||||
if err := msg.BtcEncode(&buf, maxProtocolVersion, wire.BaseEncoding); err != nil {
|
||||
context := fmt.Sprintf("Failed to encode msg of type %T", msg)
|
||||
return "", internalRPCError(err.Error(), context)
|
||||
}
|
||||
@ -634,23 +634,6 @@ func handleDebugLevel(s *rpcServer, cmd interface{}, closeChan <-chan struct{})
|
||||
return "Done.", nil
|
||||
}
|
||||
|
||||
// witnessToHex formats the passed witness stack as a slice of hex-encoded
|
||||
// strings to be used in a JSON response.
|
||||
func witnessToHex(witness wire.TxWitness) []string {
|
||||
// Ensure nil is returned when there are no entries versus an empty
|
||||
// slice so it can properly be omitted as necessary.
|
||||
if len(witness) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
result := make([]string, 0, len(witness))
|
||||
for _, wit := range witness {
|
||||
result = append(result, hex.EncodeToString(wit))
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// createVinList returns a slice of JSON objects for the inputs of the passed
|
||||
// transaction.
|
||||
func createVinList(mtx *wire.MsgTx) []btcjson.Vin {
|
||||
@ -660,7 +643,6 @@ func createVinList(mtx *wire.MsgTx) []btcjson.Vin {
|
||||
txIn := mtx.TxIn[0]
|
||||
vinList[0].Coinbase = hex.EncodeToString(txIn.SignatureScript)
|
||||
vinList[0].Sequence = txIn.Sequence
|
||||
vinList[0].Witness = witnessToHex(txIn.Witness)
|
||||
return vinList
|
||||
}
|
||||
|
||||
@ -678,10 +660,6 @@ func createVinList(mtx *wire.MsgTx) []btcjson.Vin {
|
||||
Asm: disbuf,
|
||||
Hex: hex.EncodeToString(txIn.SignatureScript),
|
||||
}
|
||||
|
||||
if mtx.HasWitness() {
|
||||
vinEntry.Witness = witnessToHex(txIn.Witness)
|
||||
}
|
||||
}
|
||||
|
||||
return vinList
|
||||
@ -753,7 +731,7 @@ func createTxRawResult(chainParams *chaincfg.Params, mtx *wire.MsgTx,
|
||||
txReply := &btcjson.TxRawResult{
|
||||
Hex: mtxHex,
|
||||
Txid: txHash,
|
||||
Hash: mtx.WitnessHash().String(),
|
||||
Hash: mtx.TxHash().String(),
|
||||
Size: int32(mtx.SerializeSize()),
|
||||
Vsize: int32(mempool.GetTxVirtualSize(btcutil.NewTx(mtx))),
|
||||
Vin: createVinList(mtx),
|
||||
@ -1129,8 +1107,6 @@ func handleGetBlock(s *rpcServer, cmd interface{}, closeChan <-chan struct{}) (i
|
||||
Confirmations: uint64(1 + best.Height - blockHeight),
|
||||
Height: int64(blockHeight),
|
||||
Size: int32(len(blkBytes)),
|
||||
StrippedSize: int32(blk.MsgBlock().SerializeSizeStripped()),
|
||||
Weight: int32(blockchain.GetBlockWeight(blk)),
|
||||
Bits: strconv.FormatInt(int64(blockHeader.Bits), 16),
|
||||
Difficulty: getDifficultyRatio(blockHeader.Bits, params),
|
||||
NextHash: nextHashString,
|
||||
@ -1247,9 +1223,6 @@ func handleGetBlockChainInfo(s *rpcServer, cmd interface{}, closeChan <-chan str
|
||||
case chaincfg.DeploymentCSV:
|
||||
forkName = "csv"
|
||||
|
||||
case chaincfg.DeploymentSegwit:
|
||||
forkName = "segwit"
|
||||
|
||||
default:
|
||||
return nil, &btcjson.RPCError{
|
||||
Code: btcjson.ErrRPCInternal.Code,
|
||||
@ -1718,14 +1691,12 @@ func (state *gbtWorkState) blockTemplateResult(useCoinbaseValue bool, submitOld
|
||||
return nil, internalRPCError(err.Error(), context)
|
||||
}
|
||||
|
||||
bTx := btcutil.NewTx(tx)
|
||||
resultTx := btcjson.GetBlockTemplateResultTx{
|
||||
Data: hex.EncodeToString(txBuf.Bytes()),
|
||||
Hash: txHash.String(),
|
||||
Depends: depends,
|
||||
Fee: template.Fees[i],
|
||||
SigOps: template.SigOpCosts[i],
|
||||
Weight: blockchain.GetTransactionWeight(bTx),
|
||||
}
|
||||
transactions = append(transactions, resultTx)
|
||||
}
|
||||
@ -1741,7 +1712,6 @@ func (state *gbtWorkState) blockTemplateResult(useCoinbaseValue bool, submitOld
|
||||
CurTime: header.Timestamp.Unix(),
|
||||
Height: int64(template.Height),
|
||||
PreviousHash: header.PrevBlock.String(),
|
||||
WeightLimit: blockchain.MaxBlockWeight,
|
||||
SigOpLimit: blockchain.MaxBlockSigOpsCost,
|
||||
SizeLimit: wire.MaxBlockPayload,
|
||||
Transactions: transactions,
|
||||
@ -1755,11 +1725,6 @@ func (state *gbtWorkState) blockTemplateResult(useCoinbaseValue bool, submitOld
|
||||
NonceRange: gbtNonceRange,
|
||||
Capabilities: gbtCapabilities,
|
||||
}
|
||||
// If the generated block template includes transactions with witness
|
||||
// data, then include the witness commitment in the GBT result.
|
||||
if template.WitnessCommitment != nil {
|
||||
reply.DefaultWitnessCommitment = hex.EncodeToString(template.WitnessCommitment)
|
||||
}
|
||||
|
||||
if useCoinbaseValue {
|
||||
reply.CoinbaseAux = gbtCoinbaseAux
|
||||
@ -1997,8 +1962,6 @@ func chainErrToGBTErrString(err error) string {
|
||||
return "duplicate"
|
||||
case blockchain.ErrBlockTooBig:
|
||||
return "bad-blk-length"
|
||||
case blockchain.ErrBlockWeightTooHigh:
|
||||
return "bad-blk-weight"
|
||||
case blockchain.ErrBlockVersionTooOld:
|
||||
return "bad-version"
|
||||
case blockchain.ErrInvalidTime:
|
||||
@ -2067,12 +2030,6 @@ func chainErrToGBTErrString(err error) string {
|
||||
return "bad-script-malformed"
|
||||
case blockchain.ErrScriptValidation:
|
||||
return "bad-script-validate"
|
||||
case blockchain.ErrUnexpectedWitness:
|
||||
return "unexpected-witness"
|
||||
case blockchain.ErrInvalidWitnessCommitment:
|
||||
return "bad-witness-nonce-size"
|
||||
case blockchain.ErrWitnessCommitmentMismatch:
|
||||
return "bad-witness-merkle-match"
|
||||
case blockchain.ErrPreviousBlockUnknown:
|
||||
return "prev-blk-not-found"
|
||||
case blockchain.ErrInvalidAncestorBlock:
|
||||
@ -2355,17 +2312,16 @@ func handleGetMiningInfo(s *rpcServer, cmd interface{}, closeChan <-chan struct{
|
||||
|
||||
best := s.cfg.Chain.BestSnapshot()
|
||||
result := btcjson.GetMiningInfoResult{
|
||||
Blocks: int64(best.Height),
|
||||
CurrentBlockSize: best.BlockSize,
|
||||
CurrentBlockWeight: best.BlockWeight,
|
||||
CurrentBlockTx: best.NumTxns,
|
||||
Difficulty: getDifficultyRatio(best.Bits, s.cfg.ChainParams),
|
||||
Generate: s.cfg.CPUMiner.IsMining(),
|
||||
GenProcLimit: s.cfg.CPUMiner.NumWorkers(),
|
||||
HashesPerSec: int64(s.cfg.CPUMiner.HashesPerSecond()),
|
||||
NetworkHashPS: networkHashesPerSec,
|
||||
PooledTx: uint64(s.cfg.TxMemPool.Count()),
|
||||
TestNet: cfg.TestNet3,
|
||||
Blocks: int64(best.Height),
|
||||
CurrentBlockSize: best.BlockSize,
|
||||
CurrentBlockTx: best.NumTxns,
|
||||
Difficulty: getDifficultyRatio(best.Bits, s.cfg.ChainParams),
|
||||
Generate: s.cfg.CPUMiner.IsMining(),
|
||||
GenProcLimit: s.cfg.CPUMiner.NumWorkers(),
|
||||
HashesPerSec: int64(s.cfg.CPUMiner.HashesPerSecond()),
|
||||
NetworkHashPS: networkHashesPerSec,
|
||||
PooledTx: uint64(s.cfg.TxMemPool.Count()),
|
||||
TestNet: cfg.TestNet3,
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
@ -2943,10 +2899,6 @@ func createVinListPrevOut(s *rpcServer, mtx *wire.MsgTx, chainParams *chaincfg.P
|
||||
},
|
||||
}
|
||||
|
||||
if len(txIn.Witness) != 0 {
|
||||
vinEntry.Witness = witnessToHex(txIn.Witness)
|
||||
}
|
||||
|
||||
// Add the entry to the list now if it already passed the filter
|
||||
// since the previous output might not be available.
|
||||
passesFilter := len(filterAddrMap) == 0
|
||||
|
@ -65,21 +65,19 @@ var helpDescsEnUS = map[string]string{
|
||||
"prevout-value": "previous output value",
|
||||
|
||||
// VinPrevOut help.
|
||||
"vinprevout-coinbase": "The hex-encoded bytes of the signature script (coinbase txns only)",
|
||||
"vinprevout-txid": "The hash of the origin transaction (non-coinbase txns only)",
|
||||
"vinprevout-vout": "The index of the output being redeemed from the origin transaction (non-coinbase txns only)",
|
||||
"vinprevout-scriptSig": "The signature script used to redeem the origin transaction as a JSON object (non-coinbase txns only)",
|
||||
"vinprevout-txinwitness": "The witness stack of the passed input, encoded as a JSON string array",
|
||||
"vinprevout-prevOut": "Data from the origin transaction output with index vout.",
|
||||
"vinprevout-sequence": "The script sequence number",
|
||||
"vinprevout-coinbase": "The hex-encoded bytes of the signature script (coinbase txns only)",
|
||||
"vinprevout-txid": "The hash of the origin transaction (non-coinbase txns only)",
|
||||
"vinprevout-vout": "The index of the output being redeemed from the origin transaction (non-coinbase txns only)",
|
||||
"vinprevout-scriptSig": "The signature script used to redeem the origin transaction as a JSON object (non-coinbase txns only)",
|
||||
"vinprevout-prevOut": "Data from the origin transaction output with index vout.",
|
||||
"vinprevout-sequence": "The script sequence number",
|
||||
|
||||
// Vin help.
|
||||
"vin-coinbase": "The hex-encoded bytes of the signature script (coinbase txns only)",
|
||||
"vin-txid": "The hash of the origin transaction (non-coinbase txns only)",
|
||||
"vin-vout": "The index of the output being redeemed from the origin transaction (non-coinbase txns only)",
|
||||
"vin-scriptSig": "The signature script used to redeem the origin transaction as a JSON object (non-coinbase txns only)",
|
||||
"vin-txinwitness": "The witness used to redeem the input encoded as a string array of its items",
|
||||
"vin-sequence": "The script sequence number",
|
||||
"vin-coinbase": "The hex-encoded bytes of the signature script (coinbase txns only)",
|
||||
"vin-txid": "The hash of the origin transaction (non-coinbase txns only)",
|
||||
"vin-vout": "The index of the output being redeemed from the origin transaction (non-coinbase txns only)",
|
||||
"vin-scriptSig": "The signature script used to redeem the origin transaction as a JSON object (non-coinbase txns only)",
|
||||
"vin-sequence": "The script sequence number",
|
||||
|
||||
// ScriptPubKeyResult help.
|
||||
"scriptpubkeyresult-asm": "Disassembly of the script",
|
||||
@ -240,8 +238,6 @@ var helpDescsEnUS = map[string]string{
|
||||
"getblockverboseresult-difficulty": "The proof-of-work difficulty as a multiple of the minimum difficulty",
|
||||
"getblockverboseresult-previousblockhash": "The hash of the previous block",
|
||||
"getblockverboseresult-nextblockhash": "The hash of the next block (only if there is one)",
|
||||
"getblockverboseresult-strippedsize": "The size of the block without witness data",
|
||||
"getblockverboseresult-weight": "The weight of the block",
|
||||
|
||||
// GetBlockCountCmd help.
|
||||
"getblockcount--synopsis": "Returns the number of blocks in the longest block chain.",
|
||||
@ -291,37 +287,34 @@ var helpDescsEnUS = map[string]string{
|
||||
"getblocktemplateresulttx-depends": "Other transactions before this one (by 1-based index in the 'transactions' list) that must be present in the final block if this one is",
|
||||
"getblocktemplateresulttx-fee": "Difference in value between transaction inputs and outputs (in Satoshi)",
|
||||
"getblocktemplateresulttx-sigops": "Total number of signature operations as counted for purposes of block limits",
|
||||
"getblocktemplateresulttx-weight": "The weight of the transaction",
|
||||
|
||||
// GetBlockTemplateResultAux help.
|
||||
"getblocktemplateresultaux-flags": "Hex-encoded byte-for-byte data to include in the coinbase signature script",
|
||||
|
||||
// GetBlockTemplateResult help.
|
||||
"getblocktemplateresult-bits": "Hex-encoded compressed difficulty",
|
||||
"getblocktemplateresult-curtime": "Current time as seen by the server (recommended for block time); must fall within mintime/maxtime rules",
|
||||
"getblocktemplateresult-height": "Height of the block to be solved",
|
||||
"getblocktemplateresult-previousblockhash": "Hex-encoded big-endian hash of the previous block",
|
||||
"getblocktemplateresult-sigoplimit": "Number of sigops allowed in blocks ",
|
||||
"getblocktemplateresult-sizelimit": "Number of bytes allowed in blocks",
|
||||
"getblocktemplateresult-transactions": "Array of transactions as JSON objects",
|
||||
"getblocktemplateresult-version": "The block version",
|
||||
"getblocktemplateresult-coinbaseaux": "Data that should be included in the coinbase signature script",
|
||||
"getblocktemplateresult-coinbasetxn": "Information about the coinbase transaction",
|
||||
"getblocktemplateresult-coinbasevalue": "Total amount available for the coinbase in Satoshi",
|
||||
"getblocktemplateresult-workid": "This value must be returned with result if provided (not provided)",
|
||||
"getblocktemplateresult-longpollid": "Identifier for long poll request which allows monitoring for expiration",
|
||||
"getblocktemplateresult-longpolluri": "An alternate URI to use for long poll requests if provided (not provided)",
|
||||
"getblocktemplateresult-submitold": "Not applicable",
|
||||
"getblocktemplateresult-target": "Hex-encoded big-endian number which valid results must be less than",
|
||||
"getblocktemplateresult-expires": "Maximum number of seconds (starting from when the server sent the response) this work is valid for",
|
||||
"getblocktemplateresult-maxtime": "Maximum allowed time",
|
||||
"getblocktemplateresult-mintime": "Minimum allowed time",
|
||||
"getblocktemplateresult-mutable": "List of mutations the server explicitly allows",
|
||||
"getblocktemplateresult-noncerange": "Two concatenated hex-encoded big-endian 32-bit integers which represent the valid ranges of nonces the miner may scan",
|
||||
"getblocktemplateresult-capabilities": "List of server capabilities including 'proposal' to indicate support for block proposals",
|
||||
"getblocktemplateresult-reject-reason": "Reason the proposal was invalid as-is (only applies to proposal responses)",
|
||||
"getblocktemplateresult-default_witness_commitment": "The witness commitment itself. Will be populated if the block has witness data",
|
||||
"getblocktemplateresult-weightlimit": "The current limit on the max allowed weight of a block",
|
||||
"getblocktemplateresult-bits": "Hex-encoded compressed difficulty",
|
||||
"getblocktemplateresult-curtime": "Current time as seen by the server (recommended for block time); must fall within mintime/maxtime rules",
|
||||
"getblocktemplateresult-height": "Height of the block to be solved",
|
||||
"getblocktemplateresult-previousblockhash": "Hex-encoded big-endian hash of the previous block",
|
||||
"getblocktemplateresult-sigoplimit": "Number of sigops allowed in blocks ",
|
||||
"getblocktemplateresult-sizelimit": "Number of bytes allowed in blocks",
|
||||
"getblocktemplateresult-transactions": "Array of transactions as JSON objects",
|
||||
"getblocktemplateresult-version": "The block version",
|
||||
"getblocktemplateresult-coinbaseaux": "Data that should be included in the coinbase signature script",
|
||||
"getblocktemplateresult-coinbasetxn": "Information about the coinbase transaction",
|
||||
"getblocktemplateresult-coinbasevalue": "Total amount available for the coinbase in Satoshi",
|
||||
"getblocktemplateresult-workid": "This value must be returned with result if provided (not provided)",
|
||||
"getblocktemplateresult-longpollid": "Identifier for long poll request which allows monitoring for expiration",
|
||||
"getblocktemplateresult-longpolluri": "An alternate URI to use for long poll requests if provided (not provided)",
|
||||
"getblocktemplateresult-submitold": "Not applicable",
|
||||
"getblocktemplateresult-target": "Hex-encoded big-endian number which valid results must be less than",
|
||||
"getblocktemplateresult-expires": "Maximum number of seconds (starting from when the server sent the response) this work is valid for",
|
||||
"getblocktemplateresult-maxtime": "Maximum allowed time",
|
||||
"getblocktemplateresult-mintime": "Minimum allowed time",
|
||||
"getblocktemplateresult-mutable": "List of mutations the server explicitly allows",
|
||||
"getblocktemplateresult-noncerange": "Two concatenated hex-encoded big-endian 32-bit integers which represent the valid ranges of nonces the miner may scan",
|
||||
"getblocktemplateresult-capabilities": "List of server capabilities including 'proposal' to indicate support for block proposals",
|
||||
"getblocktemplateresult-reject-reason": "Reason the proposal was invalid as-is (only applies to proposal responses)",
|
||||
|
||||
// GetBlockTemplateCmd help.
|
||||
"getblocktemplate--synopsis": "Returns a JSON object with information necessary to construct a block to mine or accepts a proposal to validate.\n" +
|
||||
@ -411,18 +404,17 @@ var helpDescsEnUS = map[string]string{
|
||||
"getmempoolinforesult-size": "Number of transactions in the mempool",
|
||||
|
||||
// GetMiningInfoResult help.
|
||||
"getmininginforesult-blocks": "Height of the latest best block",
|
||||
"getmininginforesult-currentblocksize": "Size of the latest best block",
|
||||
"getmininginforesult-currentblockweight": "Weight of the latest best block",
|
||||
"getmininginforesult-currentblocktx": "Number of transactions in the latest best block",
|
||||
"getmininginforesult-difficulty": "Current target difficulty",
|
||||
"getmininginforesult-errors": "Any current errors",
|
||||
"getmininginforesult-generate": "Whether or not server is set to generate coins",
|
||||
"getmininginforesult-genproclimit": "Number of processors to use for coin generation (-1 when disabled)",
|
||||
"getmininginforesult-hashespersec": "Recent hashes per second performance measurement while generating coins",
|
||||
"getmininginforesult-networkhashps": "Estimated network hashes per second for the most recent blocks",
|
||||
"getmininginforesult-pooledtx": "Number of transactions in the memory pool",
|
||||
"getmininginforesult-testnet": "Whether or not server is using testnet",
|
||||
"getmininginforesult-blocks": "Height of the latest best block",
|
||||
"getmininginforesult-currentblocksize": "Size of the latest best block",
|
||||
"getmininginforesult-currentblocktx": "Number of transactions in the latest best block",
|
||||
"getmininginforesult-difficulty": "Current target difficulty",
|
||||
"getmininginforesult-errors": "Any current errors",
|
||||
"getmininginforesult-generate": "Whether or not server is set to generate coins",
|
||||
"getmininginforesult-genproclimit": "Number of processors to use for coin generation (-1 when disabled)",
|
||||
"getmininginforesult-hashespersec": "Recent hashes per second performance measurement while generating coins",
|
||||
"getmininginforesult-networkhashps": "Estimated network hashes per second for the most recent blocks",
|
||||
"getmininginforesult-pooledtx": "Number of transactions in the memory pool",
|
||||
"getmininginforesult-testnet": "Whether or not server is using testnet",
|
||||
|
||||
// GetMiningInfoCmd help.
|
||||
"getmininginfo--synopsis": "Returns a JSON object containing mining-related information.",
|
||||
|
@ -4,7 +4,9 @@
|
||||
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// TestHelp ensures the help is reasonably accurate by checking that every
|
||||
// command specified also has result types defined and the one-line usage and
|
||||
|
30
server.go
30
server.go
@ -43,8 +43,7 @@ import (
|
||||
const (
|
||||
// defaultServices describes the default services that are supported by
|
||||
// the server.
|
||||
defaultServices = wire.SFNodeNetwork | wire.SFNodeBloom |
|
||||
wire.SFNodeWitness | wire.SFNodeCF
|
||||
defaultServices = wire.SFNodeNetwork | wire.SFNodeBloom | wire.SFNodeCF
|
||||
|
||||
// defaultRequiredServices describes the default services that are
|
||||
// required to be supported by outbound peers.
|
||||
@ -410,25 +409,6 @@ func (sp *serverPeer) OnVersion(_ *peer.Peer, msg *wire.MsgVersion) {
|
||||
|
||||
// Outbound connections.
|
||||
if !sp.Inbound() {
|
||||
// After soft-fork activation, only make outbound
|
||||
// connection to peers if they flag that they're segwit
|
||||
// enabled.
|
||||
chain := sp.server.chain
|
||||
segwitActive, err := chain.IsDeploymentActive(chaincfg.DeploymentSegwit)
|
||||
if err != nil {
|
||||
peerLog.Errorf("Unable to query for segwit "+
|
||||
"soft-fork state: %v", err)
|
||||
return
|
||||
}
|
||||
|
||||
if segwitActive && !sp.IsWitnessEnabled() {
|
||||
peerLog.Infof("Disconnecting non-segwit "+
|
||||
"peer %v, isn't segwit enabled and "+
|
||||
"we need more segwit enabled peers", sp)
|
||||
sp.Disconnect()
|
||||
return
|
||||
}
|
||||
|
||||
// TODO(davec): Only do this if not doing the initial block
|
||||
// download and the local address is routable.
|
||||
if !cfg.DisableListen /* && isCurrent? */ {
|
||||
@ -637,16 +617,10 @@ func (sp *serverPeer) OnGetData(_ *peer.Peer, msg *wire.MsgGetData) {
|
||||
}
|
||||
var err error
|
||||
switch iv.Type {
|
||||
case wire.InvTypeWitnessTx:
|
||||
err = sp.server.pushTxMsg(sp, &iv.Hash, c, waitChan, wire.WitnessEncoding)
|
||||
case wire.InvTypeTx:
|
||||
err = sp.server.pushTxMsg(sp, &iv.Hash, c, waitChan, wire.BaseEncoding)
|
||||
case wire.InvTypeWitnessBlock:
|
||||
err = sp.server.pushBlockMsg(sp, &iv.Hash, c, waitChan, wire.WitnessEncoding)
|
||||
case wire.InvTypeBlock:
|
||||
err = sp.server.pushBlockMsg(sp, &iv.Hash, c, waitChan, wire.BaseEncoding)
|
||||
case wire.InvTypeFilteredWitnessBlock:
|
||||
err = sp.server.pushMerkleBlockMsg(sp, &iv.Hash, c, waitChan, wire.WitnessEncoding)
|
||||
case wire.InvTypeFilteredBlock:
|
||||
err = sp.server.pushMerkleBlockMsg(sp, &iv.Hash, c, waitChan, wire.BaseEncoding)
|
||||
default:
|
||||
@ -2601,8 +2575,6 @@ func newServer(listenAddrs []string, db database.DB, chainParams *chaincfg.Param
|
||||
// NOTE: The CPU miner relies on the mempool, so the mempool has to be
|
||||
// created before calling the function to create the CPU miner.
|
||||
policy := mining.Policy{
|
||||
BlockMinWeight: cfg.BlockMinWeight,
|
||||
BlockMaxWeight: cfg.BlockMaxWeight,
|
||||
BlockMinSize: cfg.BlockMinSize,
|
||||
BlockMaxSize: cfg.BlockMaxSize,
|
||||
BlockPrioritySize: cfg.BlockPrioritySize,
|
||||
|
Loading…
x
Reference in New Issue
Block a user