mirror of
https://github.com/kaspanet/kaspad.git
synced 2026-02-26 13:15:47 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dbf9c09a2e | ||
|
|
5e9fc2defc | ||
|
|
bdc3cbceaa | ||
|
|
a71528fefb | ||
|
|
6725742d2c |
@@ -82,7 +82,7 @@ func GetBlocksHandler(order string, skip uint64, limit uint64) (interface{}, err
|
||||
}
|
||||
|
||||
// GetAcceptedTransactionIDsByBlockHashHandler returns an array of transaction IDs for a given block hash
|
||||
func GetAcceptedTransactionIDsByBlockHashHandler(blockHash *daghash.Hash) ([]string, error) {
|
||||
func GetAcceptedTransactionIDsByBlockHashHandler(blockHash string) ([]string, error) {
|
||||
db, err := database.DB()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -80,8 +80,8 @@ func GetTransactionByHashHandler(txHash string) (interface{}, error) {
|
||||
// where the given address is either an input or an output.
|
||||
func GetTransactionsByAddressHandler(address string, skip uint64, limit uint64) (interface{}, error) {
|
||||
if limit > maxGetTransactionsLimit {
|
||||
return nil, httpserverutils.NewHandlerError(http.StatusUnprocessableEntity,
|
||||
errors.Errorf("The maximum allowed value for the limit is %d", maxGetTransactionsLimit))
|
||||
return nil, httpserverutils.NewHandlerError(http.StatusBadRequest,
|
||||
errors.Errorf("Limit higher than %d or lower than 0 was requested.", maxGetTransactionsLimit))
|
||||
}
|
||||
|
||||
db, err := database.DB()
|
||||
|
||||
@@ -71,7 +71,7 @@ func Connect() error {
|
||||
User: cfg.RPCUser,
|
||||
Pass: cfg.RPCPassword,
|
||||
DisableTLS: cfg.DisableTLS,
|
||||
RequestTimeout: time.Second * 5,
|
||||
RequestTimeout: time.Second * 60,
|
||||
}
|
||||
|
||||
if !cfg.DisableTLS {
|
||||
|
||||
@@ -96,7 +96,7 @@ func PublishAcceptedTransactionsNotifications(addedChainBlocks []*rpcclient.Chai
|
||||
// PublishUnacceptedTransactionsNotifications publishes notification for each unaccepted transaction of the given chain-block
|
||||
func PublishUnacceptedTransactionsNotifications(removedChainHashes []*daghash.Hash) error {
|
||||
for _, removedHash := range removedChainHashes {
|
||||
transactionIDs, err := controllers.GetAcceptedTransactionIDsByBlockHashHandler(removedHash)
|
||||
transactionIDs, err := controllers.GetAcceptedTransactionIDsByBlockHashHandler(removedHash.String())
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -86,7 +86,11 @@ func convertQueryParamToInt(queryParams map[string]string, param string, default
|
||||
if _, ok := queryParams[param]; ok {
|
||||
intValue, err := strconv.Atoi(queryParams[param])
|
||||
if err != nil {
|
||||
return 0, httpserverutils.NewHandlerError(http.StatusUnprocessableEntity, errors.Wrap(err, fmt.Sprintf("Couldn't parse the '%s' query parameter", param)))
|
||||
errorMessage := fmt.Sprintf("Couldn't parse the '%s' query parameter", param)
|
||||
return 0, httpserverutils.NewHandlerErrorWithCustomClientMessage(
|
||||
http.StatusUnprocessableEntity,
|
||||
errors.Wrap(err, errorMessage),
|
||||
errorMessage)
|
||||
}
|
||||
return intValue, nil
|
||||
}
|
||||
@@ -159,7 +163,8 @@ func getBlocksHandler(_ *httpserverutils.ServerContext, _ *http.Request, _ map[s
|
||||
order := defaultGetBlocksOrder
|
||||
if orderParamValue, ok := queryParams[queryParamOrder]; ok {
|
||||
if orderParamValue != controllers.OrderAscending && orderParamValue != controllers.OrderDescending {
|
||||
return nil, httpserverutils.NewHandlerError(http.StatusUnprocessableEntity, errors.Errorf("'%s' is not a valid value for the '%s' query parameter", orderParamValue, queryParamLimit))
|
||||
return nil, httpserverutils.NewHandlerError(http.StatusUnprocessableEntity, errors.Errorf(
|
||||
"Couldn't parse the '%s' query parameter", queryParamLimit))
|
||||
}
|
||||
order = orderParamValue
|
||||
}
|
||||
|
||||
@@ -57,7 +57,6 @@ func startSync(doneChan chan struct{}) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infof("Finished syncing past data")
|
||||
|
||||
// Keep the node and the API server in sync
|
||||
return sync(client, doneChan)
|
||||
@@ -66,14 +65,17 @@ func startSync(doneChan chan struct{}) error {
|
||||
// fetchInitialData downloads all data that's currently missing from
|
||||
// the database.
|
||||
func fetchInitialData(client *jsonrpc.Client) error {
|
||||
log.Infof("Syncing past blocks")
|
||||
err := syncBlocks(client)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infof("Syncing past selected parent chain")
|
||||
err = syncSelectedParentChain(client)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
log.Infof("Finished syncing past data")
|
||||
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
|
||||
// the bluest block, and then inserts them into the database.
|
||||
func syncBlocks(client *jsonrpc.Client) error {
|
||||
@@ -115,6 +124,7 @@ func syncBlocks(client *jsonrpc.Client) error {
|
||||
var rawBlocks []string
|
||||
var verboseBlocks []btcjson.GetBlockVerboseResult
|
||||
for {
|
||||
log.Debugf("Calling getBlocks with start hash %v", stringPointerToString(startHash))
|
||||
blocksResult, err := client.GetBlocks(true, true, startHash)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -142,6 +152,7 @@ func syncSelectedParentChain(client *jsonrpc.Client) error {
|
||||
}
|
||||
|
||||
for {
|
||||
log.Debugf("Calling getChainFromBlock with start hash %s", stringPointerToString(startHash))
|
||||
chainFromBlockResult, err := client.GetChainFromBlock(false, startHash)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -195,7 +195,7 @@ func (dag *BlockDAG) IsKnownOrphan(hash *daghash.Hash) bool {
|
||||
// GetOrphanMissingAncestorHashes returns all of the missing parents in the orphan's sub-DAG
|
||||
//
|
||||
// This function is safe for concurrent access.
|
||||
func (dag *BlockDAG) GetOrphanMissingAncestorHashes(hash *daghash.Hash) ([]*daghash.Hash, error) {
|
||||
func (dag *BlockDAG) GetOrphanMissingAncestorHashes(orphanHash *daghash.Hash) ([]*daghash.Hash, error) {
|
||||
// Protect concurrent access. Using a read lock only so multiple
|
||||
// readers can query without blocking each other.
|
||||
dag.orphanLock.RLock()
|
||||
@@ -204,7 +204,7 @@ func (dag *BlockDAG) GetOrphanMissingAncestorHashes(hash *daghash.Hash) ([]*dagh
|
||||
missingAncestorsHashes := make([]*daghash.Hash, 0)
|
||||
|
||||
visited := make(map[daghash.Hash]bool)
|
||||
queue := []*daghash.Hash{hash}
|
||||
queue := []*daghash.Hash{orphanHash}
|
||||
for len(queue) > 0 {
|
||||
var current *daghash.Hash
|
||||
current, queue = queue[0], queue[1:]
|
||||
@@ -216,7 +216,7 @@ func (dag *BlockDAG) GetOrphanMissingAncestorHashes(hash *daghash.Hash) ([]*dagh
|
||||
queue = append(queue, parentHash)
|
||||
}
|
||||
} else {
|
||||
if !dag.BlockExists(current) {
|
||||
if !dag.BlockExists(current) && current != orphanHash {
|
||||
missingAncestorsHashes = append(missingAncestorsHashes, current)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -782,7 +782,11 @@ func newFutureError(err error) chan *response {
|
||||
func receiveFuture(f chan *response) ([]byte, error) {
|
||||
// Wait for a response on the returned channel.
|
||||
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
|
||||
|
||||
@@ -275,21 +275,8 @@ func buildGetBlockVerboseResult(s *Server, block *util.Block, isVerboseTx bool)
|
||||
txns := block.Transactions()
|
||||
rawTxns := make([]btcjson.TxRawResult, len(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(),
|
||||
&blockHeader, hash.String(), acceptingBlock, confirmations, false)
|
||||
&blockHeader, hash.String(), nil, nil, false)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user