mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-06-06 14:16:43 +00:00
[NOD-472] Don't fetch accepting block and tx confirmations for getBlocks (#498)
* [NOD-472] Don't fetch accepting block and tx confirmations for getBlocks * [NOD-472] Don't fetch accepting block and tx confirmations in any block verbose result * [NOD-472] Add stringPointerToString function
This commit is contained in:
parent
a71528fefb
commit
bdc3cbceaa
@ -71,7 +71,7 @@ func Connect() error {
|
|||||||
User: cfg.RPCUser,
|
User: cfg.RPCUser,
|
||||||
Pass: cfg.RPCPassword,
|
Pass: cfg.RPCPassword,
|
||||||
DisableTLS: cfg.DisableTLS,
|
DisableTLS: cfg.DisableTLS,
|
||||||
RequestTimeout: time.Second * 5,
|
RequestTimeout: time.Second * 60,
|
||||||
}
|
}
|
||||||
|
|
||||||
if !cfg.DisableTLS {
|
if !cfg.DisableTLS {
|
||||||
|
@ -57,7 +57,6 @@ func startSync(doneChan chan struct{}) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Infof("Finished syncing past data")
|
|
||||||
|
|
||||||
// Keep the node and the API server in sync
|
// Keep the node and the API server in sync
|
||||||
return sync(client, doneChan)
|
return sync(client, doneChan)
|
||||||
@ -66,14 +65,17 @@ func startSync(doneChan chan struct{}) error {
|
|||||||
// fetchInitialData downloads all data that's currently missing from
|
// fetchInitialData downloads all data that's currently missing from
|
||||||
// the database.
|
// the database.
|
||||||
func fetchInitialData(client *jsonrpc.Client) error {
|
func fetchInitialData(client *jsonrpc.Client) error {
|
||||||
|
log.Infof("Syncing past blocks")
|
||||||
err := syncBlocks(client)
|
err := syncBlocks(client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Infof("Syncing past selected parent chain")
|
||||||
err = syncSelectedParentChain(client)
|
err = syncSelectedParentChain(client)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
log.Infof("Finished syncing past data")
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,6 +103,13 @@ func sync(client *jsonrpc.Client, doneChan chan struct{}) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func stringPointerToString(str *string) string {
|
||||||
|
if str == nil {
|
||||||
|
return "<nil>"
|
||||||
|
}
|
||||||
|
return *str
|
||||||
|
}
|
||||||
|
|
||||||
// syncBlocks attempts to download all DAG blocks starting with
|
// syncBlocks attempts to download all DAG blocks starting with
|
||||||
// the bluest block, and then inserts them into the database.
|
// the bluest block, and then inserts them into the database.
|
||||||
func syncBlocks(client *jsonrpc.Client) error {
|
func syncBlocks(client *jsonrpc.Client) error {
|
||||||
@ -115,6 +124,7 @@ func syncBlocks(client *jsonrpc.Client) error {
|
|||||||
var rawBlocks []string
|
var rawBlocks []string
|
||||||
var verboseBlocks []btcjson.GetBlockVerboseResult
|
var verboseBlocks []btcjson.GetBlockVerboseResult
|
||||||
for {
|
for {
|
||||||
|
log.Debugf("Calling getBlocks with start hash %v", stringPointerToString(startHash))
|
||||||
blocksResult, err := client.GetBlocks(true, true, startHash)
|
blocksResult, err := client.GetBlocks(true, true, startHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -142,6 +152,7 @@ func syncSelectedParentChain(client *jsonrpc.Client) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
log.Debugf("Calling getChainFromBlock with start hash %s", stringPointerToString(startHash))
|
||||||
chainFromBlockResult, err := client.GetChainFromBlock(false, startHash)
|
chainFromBlockResult, err := client.GetChainFromBlock(false, startHash)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -782,7 +782,11 @@ func newFutureError(err error) chan *response {
|
|||||||
func receiveFuture(f chan *response) ([]byte, error) {
|
func receiveFuture(f chan *response) ([]byte, error) {
|
||||||
// Wait for a response on the returned channel.
|
// Wait for a response on the returned channel.
|
||||||
r := <-f
|
r := <-f
|
||||||
return r.result, r.err
|
var err error
|
||||||
|
if r.err != nil {
|
||||||
|
err = errors.Wrap(r.err, "got error from response channel")
|
||||||
|
}
|
||||||
|
return r.result, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// sendPost sends the passed request to the server by issuing an HTTP POST
|
// sendPost sends the passed request to the server by issuing an HTTP POST
|
||||||
|
@ -275,21 +275,8 @@ func buildGetBlockVerboseResult(s *Server, block *util.Block, isVerboseTx bool)
|
|||||||
txns := block.Transactions()
|
txns := block.Transactions()
|
||||||
rawTxns := make([]btcjson.TxRawResult, len(txns))
|
rawTxns := make([]btcjson.TxRawResult, len(txns))
|
||||||
for i, tx := range txns {
|
for i, tx := range txns {
|
||||||
var acceptingBlock *daghash.Hash
|
|
||||||
var confirmations *uint64
|
|
||||||
if s.cfg.TxIndex != nil {
|
|
||||||
acceptingBlock, err = s.cfg.TxIndex.BlockThatAcceptedTx(s.cfg.DAG, tx.ID())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
txConfirmations, err := txConfirmationsNoLock(s, tx.ID())
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
confirmations = &txConfirmations
|
|
||||||
}
|
|
||||||
rawTxn, err := createTxRawResult(params, tx.MsgTx(), tx.ID().String(),
|
rawTxn, err := createTxRawResult(params, tx.MsgTx(), tx.ID().String(),
|
||||||
&blockHeader, hash.String(), acceptingBlock, confirmations, false)
|
&blockHeader, hash.String(), nil, nil, false)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user