Skip to content
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

Merged
merged 6 commits into from
Jan 23, 2020

Conversation

paweljakubas
Copy link
Contributor

@paweljakubas paweljakubas commented Jan 21, 2020

Issue Number

#1291

Overview

  • I have added new endpoint scaffolding with needed types
  • I have extended swagger
  • I have updated unit tests

Comments

@paweljakubas paweljakubas force-pushed the paweljakubas/1291/blockchain-params-endpoint branch from be23675 to a481cd2 Compare January 22, 2020 12:09
@paweljakubas paweljakubas marked this pull request as ready for review January 22, 2020 12:10
@paweljakubas paweljakubas self-assigned this Jan 22, 2020
Copy link
Member

@Anviking Anviking left a 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.

lib/core/src/Cardano/Wallet/Api.hs Show resolved Hide resolved
@@ -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")
Copy link
Member

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 = ApiEpochNumberLatestApiEpochNumber EpochNumber

Copy link
Member

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.

Copy link
Contributor Author

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
Copy link
Member

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.

Copy link
Contributor Author

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"
Copy link
Member

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.

Copy link
Contributor Author

@paweljakubas paweljakubas Jan 22, 2020

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

Copy link
Contributor Author

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

Copy link
Member

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: "
}

Copy link
Contributor Author

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

Copy link
Contributor Author

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)
Copy link
Member

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?

Copy link
Contributor Author

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>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🆒 👍

@Anviking
Copy link
Member

CI failing with

Path parameter 'epoch' for 'get' operation in '/network/parameters/{epoch}' was not resolved

@paweljakubas
Copy link
Contributor Author

added also ApiEpochNumber to Api.TypesSpec and ... found subtle error where T.decimal was cycling Word31 numbers. Adopted proper fix

@paweljakubas paweljakubas force-pushed the paweljakubas/1291/blockchain-params-endpoint branch from a481cd2 to 43df705 Compare January 22, 2020 22:09
@paweljakubas paweljakubas force-pushed the paweljakubas/1291/blockchain-params-endpoint branch 4 times, most recently from 347c232 to b6ea48b Compare January 23, 2020 10:30
Copy link
Member

@Anviking Anviking left a 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)
Copy link
Member

@Anviking Anviking Jan 23, 2020

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]

Copy link
Member

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%.

@paweljakubas paweljakubas force-pushed the paweljakubas/1291/blockchain-params-endpoint branch 3 times, most recently from 1bf3e3a to 8858f6b Compare January 23, 2020 11:16
@paweljakubas
Copy link
Contributor Author

bors r+

iohk-bors bot added a commit that referenced this pull request Jan 23, 2020
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>
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Jan 23, 2020

Build failed

@paweljakubas paweljakubas force-pushed the paweljakubas/1291/blockchain-params-endpoint branch from 8858f6b to 43e2f18 Compare January 23, 2020 12:33
@paweljakubas
Copy link
Contributor Author

bors r+

iohk-bors bot added a commit that referenced this pull request Jan 23, 2020
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
@iohk-bors
Copy link
Contributor

iohk-bors bot commented Jan 23, 2020

Build succeeded

@iohk-bors iohk-bors bot merged commit 43e2f18 into master Jan 23, 2020
@Anviking Anviking deleted the paweljakubas/1291/blockchain-params-endpoint branch January 23, 2020 21:38
@Anviking Anviking mentioned this pull request Jan 27, 2020
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants