-
Notifications
You must be signed in to change notification settings - Fork 217
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
Hardfork countdown support #1932
Conversation
(ApiEraTransitionInfo $ ApiT info) | ||
(Just $ ApiEpochInfo | ||
(ApiT epochN) | ||
(Slotting.epochStartTime (Slotting.slotParams gp) epochN) |
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.
Be aware of this: #1913 (comment)
9fcc194
to
bb4a45e
Compare
bors try |
tryBuild failed |
c4f1e12
to
ffe5e25
Compare
bors try |
tryBuild failed |
} deriving (Eq, Generic, Show) | ||
|
||
data ApiEraTransition = ApiEraTransition | ||
{ transition :: !ApiEraTransitionInfo |
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.
Why not simply "ApiT EraTransitionInfo" here? What does the indirection gives us?
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.
this was removed on saturday, I do not know how you saw it as I squashed all commits before.
toApiEpochNo epochN = | ||
ApiEpochInfo | ||
(ApiT epochN) | ||
(Slotting.epochStartTime (Slotting.slotParams gp) epochN) |
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.
This needs to use the time interpreter.
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.
done in 35f6385
addColumn conn (DBField ProtocolParametersHardforkEpoch) value | ||
where | ||
value = case defaultHardforkEpoch defaultFieldValues of | ||
Nothing -> "NULL" |
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.
Does this work fine? Have you run the automated migration tests?
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.
so I run :
nix-build nix/migration-tests.nix -o migration-tests
./migration-tests/runall.sh
and I see some failures:
[cardano-wallet.pools-db:Error:13] [2020-07-27 14:01:13.46 UTC] Failed to migrate the database: PersistError "\n\nDatabase migration: manual intervention required.\nThe unsafe actions are prefixed by '***' below:\n\n CREATE TEMP TABLE \"pool_owner_backup\"(\"pool_id\" VARCHAR NOT NULL,\"slot\" INTEGER NOT NULL,\"slot_internal_index\" INTEGER NOT NULL,\"pool_owner\" VARCHAR NOT NULL,\"pool_owner_index\" INTEGER NOT NULL, PRIMARY KEY (\"pool_id\",\"slot\",\"slot_internal_index\",\"pool_owner\",\"pool_owner_index\"));\n INSERT INTO \"pool_owner_backup\"(\"pool_id\",\"pool_owner\",\"pool_owner_index\") SELECT \"pool_id\",\"pool_owner\",\"pool_owner_index\" FROM \"pool_owner\";\n DROP TABLE \"pool_owner\";\n CREATE TABLE \"pool_owner\"(\"pool_id\" VARCHAR NOT NULL,\"slot\" INTEGER NOT NULL,\"slot_internal_index\" INTEGER NOT NULL,\"pool_owner\" VARCHAR NOT NULL,\"pool_owner_index\" INTEGER NOT NULL, PRIMARY KEY (\"pool_id\",\"slot\",\"slot_internal_index\",\"pool_owner\",\"pool_owner_index\"), CONSTRAINT \"pool_ownerfk_registration_pool_id\" FOREIGN KEY(\"pool_id\",\"slot\",\"slot_internal_index\") REFERENCES \"pool_registration\"(\"pool_id\",\"slot\",\"slot_internal_index\") ON DELETE CASCADE);\n INSERT INTO \"pool_owner\" SELECT \"pool_id\",\"slot\",\"slot_internal_index\",\"pool_owner\",\"pool_owner_index\" FROM \"pool_owner_backup\";\n DROP TABLE \"pool_owner_backup\";\n CREATE TEMP TABLE \"pool_registration_backup\"(\"pool_id\" VARCHAR NOT NULL,\"slot\" INTEGER NOT NULL,\"slot_internal_index\" INTEGER NOT NULL,\"margin_numerator\" INTEGER NOT NULL,\"margin_denominator\" INTEGER NOT NULL,\"cost\" INTEGER NOT NULL,\"pledge\" INTEGER NOT NULL,\"metadata_url\" VARCHAR NULL,\"metadata_hash\" VARCHAR NULL, PRIMARY KEY (\"pool_id\",\"slot\",\"slot_internal_index\"));\n INSERT INTO \"pool_registration_backup\"(\"pool_id\",\"slot\",\"cost\") SELECT \"pool_id\",\"slot\",\"cost\" FROM \"pool_registration\";\n*** DROP TABLE \"pool_registration\";\n CREATE TABLE \"pool_registration\"(\"pool_id\" VARCHAR NOT NULL,\"slot\" INTEGER NOT NULL,\"slot_internal_index\" INTEGER NOT NULL,\"margin_numerator\" INTEGER NOT NULL,\"margin_denominator\" INTEGER NOT NULL,\"cost\" INTEGER NOT NULL,\"pledge\" INTEGER NOT NULL,\"metadata_url\" VARCHAR NULL,\"metadata_hash\" VARCHAR NULL, PRIMARY KEY (\"pool_id\",\"slot\",\"slot_internal_index\"));\n INSERT INTO \"pool_registration\" SELECT \"pool_id\",\"slot\",\"slot_internal_index\",\"margin_numerator\",\"margin_denominator\",\"cost\",\"pledge\",\"metadata_url\",\"metadata_hash\" FROM \"pool_registration_backup\";\n DROP TABLE \"pool_registration_backup\";\n CREATE TABLE \"pool_retirement\"(\"pool_id\" VARCHAR NOT NULL,\"slot\" INTEGER NOT NULL,\"slot_internal_index\" INTEGER NOT NULL,\"epoch\" INTEGER NOT NULL, PRIMARY KEY (\"pool_id\",\"slot\",\"slot_internal_index\"));\n CREATE TABLE \"pool_metadata\"(\"metadata_hash\" VARCHAR NOT NULL,\"name\" VARCHAR NOT NULL,\"ticker\" VARCHAR NOT NULL,\"description\" VARCHAR NULL,\"homepage\" VARCHAR NOT NULL, PRIMARY KEY (\"metadata_hash\"));\n CREATE TABLE \"pool_metadata_fetch_attempts\"(\"metadata_hash\" VARCHAR NOT NULL,\"metadata_url\" VARCHAR NOT NULL,\"retry_after\" TIMESTAMP NOT NULL,\"retry_count\" INTEGER NOT NULL, PRIMARY KEY (\"metadata_hash\",\"metadata_url\"));\n"
also
[cardano-wallet.pools-db:Error:13] [2020-07-27 14:00:50.77 UTC] Failed to migrate the database: : NOT NULL constraint failed: pool_owner_backup.slot
BUT do not see problems with hardfork_epoch
. We will deal with this in separate PR to my best knowledge
fromPersistValue = fromPersistValue >=> mkEpochNo | ||
|
||
instance PersistFieldSql EpochNo where | ||
sqlType _ = sqlType (Proxy @Text) |
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.
🤔 Why is the epoch number stored as a Text
? Wouldn't something like a Word32 or Word64 be more suitable (especially for things like filtering and where clauses)?
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.
frankly speaking I was here mimicking how we handled this for SlotNo
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.
We do store SlotNo
as Word64
though 😅
deriving via Word64 instance (PersistFieldSql SlotNo)
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.
yes, very true -> done in a3a5f8f
Right boundM -> | ||
onPParamsUpdate' $ convert boundM ls | ||
Left (e2 :: AcquireFailure) -> | ||
traceWith tr $ MsgLocalStateQueryError TipSyncClient $ show e2 |
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.
Hmmm. The logic feels sort of weird / intertwined here. Query data is mixed with handling results which makes the whole a bit hard to follow (+ causes some logic duplication in the error handling).
What about:
- run the GetCurrentPParams & GetEraStart in "parallel"
- combine them via an applicative together in
handleParamsUpdate
So something along the lines of:
queryLocalState
:: Point (CardanoBlock sc)
-> m ()
queryLocalState pt = do
mb <- localStateQueryQ `send`
CmdQueryLocalState pt (QueryAnytimeShelley GetEraStart)
pp <- localStateQueryQ `send`
CmdQueryLocalState pt (QueryIfCurrentShelley Shelley.GetCurrentPParams)
sequence (handleParamsUpdate fromShelleyPParams <$> mb <*> pp)
>>= handleAcquireFailure
st <- localStateQueryQ `send`
CmdQueryLocalState pt (QueryIfCurrentByron Byron.GetUpdateInterfaceState)
sequence (handleParamsUpdate protocolParametersFromUpdateState <$> mb <*> st)
>>= handleAcquireFailure
handleAcquireFailure
:: Either AcquireFailure ()
-> m ()
handleAcquireFailure = \case
Right () ->
pure ()
Left e ->
traceWith tr $ MsgLocalStateQueryError TipSyncClient $ show e
handleParamsUpdate
:: (Maybe Bound -> p -> W.ProtocolParameters)
-> (Maybe Bound)
-> (Either (MismatchEraInfo (CardanoEras sc)) p)
-> m ()
handleParamsUpdate convert boundM = \case
Right ls -> do
onPParamsUpdate' $ convert boundM ls
Left mismatch -> do
traceWith tr $ MsgLocalStateQueryEraMismatch mismatch
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.
yes, it is much better. I was planning to do it after proof of concept solution
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.
done in 611ac05
ffe5e25
to
611ac05
Compare
I will need to wait for mainnet test when #1943 is merged - to my best knowledge |
@@ -46,4 +48,5 @@ spec = do | |||
[ expectField (#decentralizationLevel) (`shouldBe` d) | |||
, expectField (#desiredPoolNumber) (`shouldBe` nOpt) | |||
, expectField (#minimumUtxoValue) (`shouldBe` minUtxoValue) | |||
, expectField (#hardforkEpochInfo) (`shouldNotBe` Nothing) |
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.
Will this one be ever true? Since we only run the test scenarios AFTER the hard-fork has happened, I'd assume that Nothing
will be returned forever. No ?
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 was Nothing...if you run this test once! ie., one has to wait for tip client waiting to make local query
stack test --ta '-m "NETWORK_PARAMS - Able to fetch network parameters"' cardano-wallet-shelley:integration
But when running several tests then I have Just ... so I used eventually
a3a5f8f
to
a1b4f57
Compare
where c = unsafeEpochNo n | ||
|
||
persistEpochNo :: EpochNo -> PersistValue | ||
persistEpochNo = toPersistValue . fromIntegral @Word31 @Word32 . unEpochNo |
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 better 😄
specifications/api/swagger.yaml
Outdated
@@ -848,6 +848,7 @@ components: | |||
decentralization_level: *percentage | |||
desired_pool_number: *stakePoolsNumber | |||
minimum_utxo_value: *amount | |||
hardfork_epoch_info: *epochInfo |
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 just hardfork
? or hardfork_at
for consistency across the API namings?
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, will change very soon
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.
done in ed5a885
setup: cardano-wallet-shelley produced with this branch and connected to the mainnet
after 18:30 UTC:
Thanks @Anviking and @piotr-iohk with helping in verifying this! |
extend swagger add testing and correct swagger introduce EraTransitionInfo in Primitive.Types extend NetworkParameters change ApiNetworkParameter to be not list but potential value extend db schema and migration plus simplify usage of EraTransition simplify the stuff
ed5a885
to
1dc53db
Compare
bors r+ |
1932: Hardfork countdown support r=KtorZ a=paweljakubas # Issue Number <!-- Put here a reference to the issue this PR relates to and which requirements it tackles --> #1917 # Overview <!-- Detail in a few bullet points the work accomplished in this PR --> - [x] I have extended `ApiNetworkParameters` - [x] I have updated swagger accordingly - [x] I have updated core `TypeSpec` - [x] I have extended `NetworkParameters` - [x] I have extended DB schema and addressed DB migrations - [x] I have used `QueryAnytimeShelley EraStart` from `CardanoQuery` to get value - [x] I have tested the above # Comments <!-- Additional comments or screenshots to attach if any --> To move forward I need #1909 to be merged. As, ``` QueryAnyTimeShelley EraStart :: Query CardanoBlock ``` <!-- 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 <[email protected]>
Build failed |
Unit tests running OOM. Reported in the spreadsheet, hopefully fixed by #1954. |
Issue Number
#1917
Overview
ApiNetworkParameters
TypeSpec
NetworkParameters
QueryAnytimeShelley EraStart
fromCardanoQuery
to get valueComments
To move forward I need #1909 to be merged.
As,