Skip to content

Commit

Permalink
Remove the fromheight parameter of /txs/accounts (#114)
Browse files Browse the repository at this point in the history
This PR removes the yet unreleased `fromheight` parameter of the `/txs/accounts` endpoint.

The original purpose of that parameter was to facilitate efficient pagination of the `/txs/accounts` results, but it has since been obsoleted for that purpose by the `Chainweb-Next`-token-based pagination workflow. The `Chainweb-Next`-based pagination is superior, because it doesn't require the client to figure out how to stitch together the result chunks produced by each request and it is easier to reuse across endpoints independent of whether specifying `height` limits is a reasonable or efficient way to paginate for a given endpoint.

Admittedly, `fromheight` could still be useful independent of pagination, but I'm not convinced that adding query parameters to `chainweb-data` endpoints for hypothetical use cases is a good idea at this stage, especially considering the backward compatibility burden that entails.

* Remove the fromheight parameter of /txs/accounts

* Update the chainweb-api pin
  • Loading branch information
enobayram authored Dec 24, 2022
1 parent 72745ba commit ffd59eb
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 14 deletions.
2 changes: 1 addition & 1 deletion cabal.project
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ source-repository-package
source-repository-package
type: git
location: https://github.com/kadena-io/chainweb-api.git
tag: 6ffcf6265309bcd08034652523c940e4b71e9153
tag: 953019e5eedc1d23833cb7b5b6c5f53627ff2b20

source-repository-package
type: git
Expand Down
4 changes: 2 additions & 2 deletions deps/chainweb-api/github.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"repo": "chainweb-api",
"branch": "master",
"private": false,
"rev": "6ffcf6265309bcd08034652523c940e4b71e9153",
"sha256": "1pagn20ss7w6llck75d2yvcjv1lji31knd39fppc6a8av64n6n8g"
"rev": "953019e5eedc1d23833cb7b5b6c5f53627ff2b20",
"sha256": "1q33fkigjk34z101jb7j827bfp3hhhglqip6rxvqpg09p26nc03p"
}
14 changes: 6 additions & 8 deletions exec/Chainweb/Server.hs
Original file line number Diff line number Diff line change
Expand Up @@ -511,27 +511,25 @@ accountHandler
-> Text -- ^ account identifier
-> Maybe Text -- ^ token type
-> Maybe ChainId -- ^ chain identifier
-> Maybe BlockHeight
-> Maybe Limit
-> Maybe Offset
-> Maybe NextToken
-> Handler (NextHeaders [AccountDetail])
accountHandler logger pool req account token chain fromHeight limit offset mbNext = do
accountHandler logger pool req account token chain limit offset mbNext = do
liftIO $ logger Info $
fromString $ printf "Account search from %s for: %s %s %s" (show $ remoteHost req) (T.unpack account) (maybe "coin" T.unpack token) (maybe "<all-chains>" show chain)
queryStart <- case (mbNext, fromHeight, offset) of
(Just nextToken, Nothing, Nothing) -> case readToken nextToken of
queryStart <- case (mbNext, offset) of
(Just nextToken, Nothing) -> case readToken nextToken of
Nothing -> throw400 $ toS $ "Invalid next token: " <> unNextToken nextToken
Just ((hgt, reqkey, idx) :: AccountNextToken) -> return $
AQSContinue (fromIntegral hgt) (rkcbFromText reqkey) (fromIntegral idx)
(Just _, Just _, _) -> throw400 $ "next token query parameter not allowed with fromheight"
(Just _, _, Just _) -> throw400 $ "next token query parameter not allowed with offset"
(Nothing, _, _) -> do
(Just _, Just _) -> throw400 $ "next token query parameter not allowed with offset"
(Nothing, _) -> do
boundedOffset <- Offset <$> case offset of
Just (Offset o) -> if o >= 10000 then throw400 errMsg else return o
where errMsg = toS (printf "the maximum allowed offset is 10,000. You requested %d" o :: String)
Nothing -> return 0
return $ AQSNewQuery fromHeight boundedOffset
return $ AQSNewQuery boundedOffset
liftIO $ P.withResource pool $ \c -> do
let boundedLimit = Limit $ maybe 20 (min 100 . unLimit) limit
r <- runBeamPostgresDebug (logger Debug . T.pack) c $
Expand Down
5 changes: 2 additions & 3 deletions lib/ChainwebDb/Queries.hs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ _bytequery = \case
SqlSelect s -> pgRenderSyntaxScript $ fromPgSelect s

data AccountQueryStart
= AQSNewQuery (Maybe BlockHeight) Offset
= AQSNewQuery Offset
| AQSContinue BlockHeight ReqKeyOrCoinbase Int

accountQueryStmt
Expand Down Expand Up @@ -202,8 +202,7 @@ accountQueryStmt (Limit limit) account token chain aqs =
rowFilter tr
return (tr,_block_creationTime blk)
(Offset offset, rowFilter) = case aqs of
AQSNewQuery mbHeight ofst -> (,) ofst $ \tr ->
whenArg mbHeight $ \bh -> guard_ $ _tr_height tr <=. val_ (fromIntegral bh)
AQSNewQuery ofst -> (ofst, const $ return ())
AQSContinue height reqKey idx -> (,) (Offset 0) $ \tr ->
guard_ $ tupleCmp (<.)
[ _tr_height tr :<> fromIntegral height
Expand Down

0 comments on commit ffd59eb

Please sign in to comment.