Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This wires most read-only queries with timeout and cancel contexts. The new pgtimeout/T option is added to set the psql timeout with any string accepted by time.ParseDuration. The default is 1 hr, which is essentially unlimited in normal operation. Time timeout is passed to ChainDB via dcrpg.DBInfo.QueryTimeout. Add string dbtypes.PGCancelError set to the expected postgres error message when a statement is canceled at user request. Add timeoutError which provides a string "TIMEOUT of PostgreSQL query after %d seconds" where %d is the set timeout in ChainDB. Add IsTimeoutErr and IsTimeout to dbtypes. Add replaceCancelError which replaces an error that matches the PGCancelError with the friendly error from timeoutError. Use replaceCancelError to filter the output of several Retrieve* function calls. Create dbtypes.CtxDeadlineExceeded = context.DeadlineExceeded.Error(). In dbtypes.IsTimeout, detect either CtxDeadlineExceeded or TimeoutPrefix. Update replaceCancelError to recognize CtxDeadlineExceeded as well as PGCancelError, replacing them both with (*ChainDB).timeoutError. NOTE: As a general rule, where the context.WithTimeout context is created, the error returned from the retrieval function should be filtered with replaceCancelError. Create (*explorerUI).timeoutErrorPage(error) bool to show an appropriate status page if the error is a DB timeout, and return whether it was a timeout error. Use timeoutErrorPage after each call to a function in the explorerSource interface from a http.HandlerFunc. Handle timeouts in APIs too. Rename api/DataSourceAux.GetTxHistoryData to TxHistoryData. (*ChainDB).AddressBalance now returns an error. dev balance update error in sync is now not a sync error: Keep going with sync if the project fund balance query times out. This is in line with how errors from GetPgChartsData are treated (reported but ignored). Use context.Background for update/set functions that should not timeout. This also includes a dcrpg bug fix in VinsForTx where input scripts were incorrect. This affects transactions loaded for side chain blocks. The pkScripts were from the wrong vouts rows previously. This adds a new query joining vins and vouts, to get the correct vouts data for the given vins row ID. Add PkScriptByVinID and PkScriptByVoutID for clarity, calling PkScriptByVinID from VinsForTx. Rename explorer statuses and add timeout status: The status type is renamed from statusType to expStatus. The status strings of type expStatus are renamed with the prefix ExpStatus so they are loosely grouped. Add ExpStatusDBTimeout, which returns a 503 http status code. Modify AddressPage to check for sql.ErrNoRows and timeout errors, handling these appropriately. sql.ErrNoRows is not an error as this means there are no confirmed transactions. However, a timeout should send the user to the status page with the appropriate message. Any other non-nil error sends the user to the status page with a generic error message. Other changes: Rename (*ChainDB).RetrieveAddressSpentUnspent to AddressSpentUnspent for consistency, and to not conflict with the function in queries.go. Create HeightHashDB, which combines HeightDB and HashDB, and use it instead of directly calling RetrieveBestBlockHeight. This makes the timeout context creation a bit more elegant and less repetitive. Create PkScriptByID, which wraps RetrievePkScriptByID from queries.go with ChainDB's query timeout context. Remove the unused RetrieveAddressRecvCount function and the query string SelectAddressRecvCount. Document many query functions. Rename (*ChainDB).GetBlockSummaryTimeRange to BlockSummaryTimeRange. Rename GetTicketPoolBlockMaturity to TicketPoolBlockMaturity. Rename GetTicketPoolByDateAndInterval to TicketPoolByDateAndInterval. Rename GetTicketsPriceByHeight to TicketsPriceByHeight, and update explorerDataSource interface. Add (*ChainDB).BlockChainDbID wrapping RetrieveBlockChainDbID. Add (*ChainDB).TicketsByPrice wrapping retrieveTicketByPrice with a timeout context. Add (*ChainDB).TicketsByInputCount wrapping retrieveTicketsGroupedByType with a timeout context. Add CoinSupplyChartsData wrapping retrieveCoinSupply with timeout. Add DbTxByHash wrapping RetrieveDbTxByHash. Add FundingOutpointIndxByVinID wrapping RetrieveFundingOutpointIndxByVinID. Improve function names by removing get, retrieve, etc. Rename RetrieveTicketIDByHash to RetrieveTicketIDByHashNoCancel to indicate that the function should never be modified to accept a cancellable context. Create BlockFlagsNoCancel, a variation on BlockFlags. Create BlockChainDbIDNoCancel, a variation on BlockChainDbID. Use these two new functiOns in UpdateLastBlock. Add an error return to several insight-related queries. Lots of insight clean-up. Contextify GetAddressMetrics and retrieveAddressTxsCount. Add (*ChainDB).NumAddressIntervals, wrapping retrieveAddressTxsCount and TimeBasedGroupingToInterval. Add dbtypes.TimeIntervals, a slice of the day/week/month/year intervals. Do not display sync tx processing rate when none processed Rename (*ChainDB).GetAddressMetrics to AddressMetrics.
- Loading branch information