-
Notifications
You must be signed in to change notification settings - Fork 211
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Blockchain params endpoint - part 1 #1294
Blockchain params endpoint - part 1 #1294
Conversation
be23675
to
a481cd2
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Left a few comments. Most notably I think ApiEpochNumber
could be less stringly typed.
@@ -446,6 +466,33 @@ instance FromHttpApiData Iso8601Time where | |||
instance ToHttpApiData Iso8601Time where | |||
toUrlPiece = toText | |||
|
|||
instance FromText ApiEpochNumber where | |||
fromText txt = case txt of | |||
"latest" -> Right (ApiEpochNumber "latest") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🤔 What about defining ApiEpochNumber
as something like:
data ApiEpochNumber = ApiEpochNumberLatest | ApiEpochNumber EpochNumber
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like when actually using ApiEpochNumber
, you'd have to re-parse the Text
into either the notion of latest or an EpochNumber
anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was persuaded and used the propose type. It is more precise and better reflect situation
activeSlotCoefficient (x :: ApiNetworkParameters) | ||
} | ||
in | ||
x' === x .&&. show x' === show x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"pointless tests to trigger coverage for record accessors"
Hm, ok 👍
Unrelated to the PR, but do we still care about coverage to this extent? We have removed the badge from the readme at least.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, pointless tests
title says it all
-> NetworkLayer IO t Block | ||
-> ApiEpochNumber | ||
-> Handler ApiNetworkParameters | ||
getNetworkParameters _ _ _ = error "not implemented" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think best practice is to throwError err501
instead of erroring.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would do this if we had not Handler
but ExceptT
. When Handler
then I need to do :
liftHandler $ throwE err501
and then we have
No instance for (LiftHandler ServantErr)
So I would rather to stick to error and in replace it in the next PR with implementation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, but we can use here :
liftIO $ throwIO err501
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a memory of err501
being used in the wallet, but I don't remember exactly how.
With liftIO $ throwIO err501
we actually get a 500:
http http://localhost:8090/v2/network/parameters/latest
HTTP/1.1 500 Internal Server Error
Content-Type: text/plain; charset=utf-8
Date: Thu, 23 Jan 2020 10:08:45 GMT
Server: Warp/3.2.27
Transfer-Encoding: chunked
Something went wrong
Which is the same result as error "not implemeted"
.
Whereas with Handler $ throwE err501
we at least get a 501 (but with generic code and message)
http http://localhost:8090/v2/network/parameters/latest
HTTP/1.1 501 Not Implemented
Content-Type: application/json;charset=utf-8
Date: Thu, 23 Jan 2020 10:10:33 GMT
Server: Warp/3.2.27
Transfer-Encoding: chunked
{
"code": "unexpected_error",
"message": "It looks like something unexpected went wrong. Unfortunately I don't yet know how to handle this type of situation. Here's some information about what happened: "
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree. used Handler $ throwE err501
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the end used Servant's throwError err501
instance Arbitrary (Quantity "second" NominalDiffTime) where | ||
shrink (Quantity 0.0) = [] | ||
shrink _ = [Quantity 0.0] | ||
arbitrary = Quantity . fromInteger <$> choose (0, 100) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems ok, but why so small?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, increased to 10000
parameters: | ||
- *parametersEpoch | ||
description: | | ||
<p align="right">status: <strong>under development</strong></p> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🆒 👍
CI failing with
|
added also |
a481cd2
to
43df705
Compare
347c232
to
b6ea48b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
, slotLength :: !(Quantity "second" NominalDiffTime) | ||
, epochLength :: !(Quantity "slot" Word32) | ||
, epochStability :: !(Quantity "block" Word32) | ||
, activeSlotCoefficient :: !(Quantity "percent" Percentage) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Percentage
Though I think you might find in the next PR that ActiveSlotCoeff
is a Double
whereas Percentage
is a Word, [0, 100]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, U/S says:
active_slot_coefficient: *percentage
And in x-percentage
is a number
. So it should be able to be a floating point.
I imagine some users would like to have the full 33.333333%
instead of just 33%
.
1bf3e3a
to
8858f6b
Compare
bors r+ |
1294: Blockchain params endpoint - part 1 r=paweljakubas a=paweljakubas # Issue Number <!-- Put here a reference to the issue this PR relates to and which requirements it tackles --> #1291 # Overview <!-- Detail in a few bullet points the work accomplished in this PR --> - [x] I have added new endpoint scaffolding with needed types - [x] I have extended swagger - [x] I have updated unit tests # Comments <!-- Additional comments or screenshots to attach if any --> <!-- Don't forget to: ✓ Self-review your changes to make sure nothing unexpected slipped through ✓ Assign yourself to the PR ✓ Assign one or several reviewer(s) ✓ Once created, link this PR to its corresponding ticket ✓ Assign the PR to a corresponding milestone ✓ Acknowledge any changes required to the Wiki --> Co-authored-by: Pawel Jakubas <pawel.jakubas@iohk.io>
Build failed |
8858f6b
to
43e2f18
Compare
bors r+ |
1294: Blockchain params endpoint - part 1 r=paweljakubas a=paweljakubas # Issue Number <!-- Put here a reference to the issue this PR relates to and which requirements it tackles --> #1291 # Overview <!-- Detail in a few bullet points the work accomplished in this PR --> - [x] I have added new endpoint scaffolding with needed types - [x] I have extended swagger - [x] I have updated unit tests # Comments <!-- Additional comments or screenshots to attach if any --> <!-- Don't forget to: ✓ Self-review your changes to make sure nothing unexpected slipped through ✓ Assign yourself to the PR ✓ Assign one or several reviewer(s) ✓ Once created, link this PR to its corresponding ticket ✓ Assign the PR to a corresponding milestone ✓ Acknowledge any changes required to the Wiki --> Co-authored-by: Pawel Jakubas <pawel.jakubas@iohk.io>
fix attempt use better response for unimplemented API endpoint epoch -> epochId fix swagger use throwError from Servant to service err501 update Wallet.Api literal in endpoint
Build succeeded |
Issue Number
#1291
Overview
Comments