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

Query fixes and refactoring #1209

Merged
merged 7 commits into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased changes

- Fix a bug where `GetBakersRewardPeriod` returns incorrect data (#1176).
- Fix a bug where `GetPoolInfo` returns incorrect data (#1177).
- Change the severity of logs for failed gRPC API requests to DEBUG level.
- Add support for new `invoke` calls from smart contracts in protocol version 7:
- query the contract module reference for a given contract address
Expand Down
2 changes: 1 addition & 1 deletion concordium-base
Submodule concordium-base updated 41 files
+2 −0 .gitignore
+1 −1 Setup.hs
+1 −0 concordium-base.cabal
+1 −1 concordium-grpc-api
+17 −0 haskell-src/Concordium/Crypto/EncryptedTransfers.hs
+34 −14 haskell-src/Concordium/GRPC2.hs
+13 −1 haskell-src/Concordium/ID/Types.hs
+1 −1 haskell-src/Concordium/Types.hs
+111 −68 haskell-src/Concordium/Types/Accounts.hs
+255 −0 haskell-src/Concordium/Types/Execution.hs
+1 −1 haskell-src/Concordium/Types/Migration.hs
+8 −0 haskell-src/Concordium/Types/Parameters.hs
+50 −33 haskell-src/Concordium/Types/ProtocolVersion.hs
+65 −36 haskell-src/Concordium/Types/Queries.hs
+2 −4 haskell-src/Concordium/Types/Transactions.hs
+45 −0 haskell-src/Concordium/Wasm.hs
+2 −0 haskell-tests/Spec.hs
+99 −0 haskell-tests/Types/PayloadSpec.hs
+13 −4 idiss-csharp/CHANGELOG.md
+1 −1 idiss-csharp/IdissExample/IdissExample.csproj
+12 −10 idiss-csharp/IdissLib/Idiss.cs
+33 −2 idiss-csharp/IdissLib/IdissLib.csproj
+3 −3 idiss-csharp/IdissLib/Types.cs
+1 −1 idiss-csharp/IdissLibTest/IdissLibTest.csproj
+29 −38 idiss-csharp/README.md
+5 −1 mobile_wallet/CHANGELOG.md
+1 −1 mobile_wallet/Cargo.lock
+1 −1 mobile_wallet/Cargo.toml
+4 −4 mobile_wallet/android/build-android.sh
+6 −0 mobile_wallet/src/lib.rs
+1 −1 rust-src/Cargo.lock
+2 −0 rust-src/concordium_base/CHANGELOG.md
+3 −0 rust-src/concordium_base/src/encrypted_transfers/ffi.rs
+22 −0 rust-src/concordium_base/src/encrypted_transfers/mod.rs
+5 −1 rust-src/concordium_base/src/id/types.rs
+93 −6 rust-src/concordium_base/src/transactions.rs
+6 −0 rust-src/wallet_library/CHANGELOG.md
+1 −1 rust-src/wallet_library/Cargo.toml
+3 −2 rust-src/wallet_library/src/default_wallet_config.rs
+1 −0 smart-contracts/contracts-common/concordium-contracts-common/CHANGELOG.md
+2 −2 smart-contracts/contracts-common/concordium-contracts-common/src/types.rs
8 changes: 4 additions & 4 deletions concordium-consensus/src-lib/Concordium/External/GRPC2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -548,10 +548,10 @@ getPoolInfoV2 cptr blockType blockHashPtr bakerId outHash outVec copierCbk = do
Ext.ConsensusRunner mvr <- deRefStablePtr cptr
let copier = callCopyToVecCallback copierCbk
bhi <- decodeBlockHashInput blockType blockHashPtr
response <- runMVR (Q.getPoolStatus bhi (Just $ fromIntegral bakerId)) mvr
response <- runMVR (Q.getPoolStatus bhi (fromIntegral bakerId)) mvr
copyHashTo outHash response
case fmap toProto <$> response of
Q.BQRBlock _ (Just (Left proto)) -> do
Q.BQRBlock _ (Just proto) -> do
let encoded = Proto.encodeMessage proto
BS.unsafeUseAsCStringLen encoded (\(ptr, len) -> copier outVec (castPtr ptr) (fromIntegral len))
return $ queryResultCode QRSuccess
Expand All @@ -573,10 +573,10 @@ getPassiveDelegationInfoV2 cptr blockType blockHashPtr outHash outVec copierCbk
Ext.ConsensusRunner mvr <- deRefStablePtr cptr
let copier = callCopyToVecCallback copierCbk
bhi <- decodeBlockHashInput blockType blockHashPtr
response <- runMVR (Q.getPoolStatus bhi Nothing) mvr
response <- runMVR (Q.getPassiveDelegationStatus bhi) mvr
copyHashTo outHash response
case fmap toProto <$> response of
Q.BQRBlock _ (Just (Right proto)) -> do
Q.BQRBlock _ (Just proto) -> do
let encoded = Proto.encodeMessage proto
BS.unsafeUseAsCStringLen encoded (\(ptr, len) -> copier outVec (castPtr ptr) (fromIntegral len))
return $ queryResultCode QRSuccess
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@ instance (IsAccountVersion av) => HashableTo (AccountHash av) (Account av) where
SAccountV0 -> AHIV0 (accountHashInputsV0 acc)
SAccountV1 -> AHIV1 (accountHashInputsV0 acc)
SAccountV2 -> AHIV2 (accountHashInputsV2 acc)
SAccountV3 -> undefined -- TODO: Implement account version 3
td202 marked this conversation as resolved.
Show resolved Hide resolved

instance forall av. (IsAccountVersion av) => HashableTo Hash.Hash (Account av) where
getHash = coerce @(AccountHash av) . getHash
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ type family AccountReleaseSchedule' (av :: AccountVersion) where
AccountReleaseSchedule' 'AccountV0 = ARSV0.AccountReleaseSchedule
AccountReleaseSchedule' 'AccountV1 = ARSV0.AccountReleaseSchedule
AccountReleaseSchedule' 'AccountV2 = ARSV1.AccountReleaseSchedule
AccountReleaseSchedule' 'AccountV3 = ARSV1.AccountReleaseSchedule

-- | Release schedule on an account, parametrized by the account version.
newtype AccountReleaseSchedule (av :: AccountVersion) = AccountReleaseSchedule
Expand All @@ -51,6 +52,7 @@ theAccountReleaseScheduleV1 ::
ARSV1.AccountReleaseSchedule
theAccountReleaseScheduleV1 = case accountVersion @av of
SAccountV2 -> theAccountReleaseSchedule
SAccountV3 -> theAccountReleaseSchedule

-- | Converse of 'theAccountReleaseScheduleV0'.
fromAccountReleaseScheduleV0 ::
Expand All @@ -70,25 +72,29 @@ fromAccountReleaseScheduleV1 ::
AccountReleaseSchedule av
fromAccountReleaseScheduleV1 = case accountVersion @av of
SAccountV2 -> AccountReleaseSchedule
SAccountV3 -> AccountReleaseSchedule

instance (IsAccountVersion av) => Eq (AccountReleaseSchedule av) where
(==) = case accountVersion @av of
SAccountV0 -> (==) `on` theAccountReleaseSchedule
SAccountV1 -> (==) `on` theAccountReleaseSchedule
SAccountV2 -> (==) `on` theAccountReleaseSchedule
SAccountV3 -> (==) `on` theAccountReleaseSchedule

instance (IsAccountVersion av) => Show (AccountReleaseSchedule av) where
show = case accountVersion @av of
SAccountV0 -> show . theAccountReleaseSchedule
SAccountV1 -> show . theAccountReleaseSchedule
SAccountV2 -> show . theAccountReleaseSchedule
SAccountV3 -> show . theAccountReleaseSchedule

-- | Produce an 'AccountReleaseSummary' from an 'AccountReleaseSchedule'.
toAccountReleaseSummary :: forall av. (IsAccountVersion av) => AccountReleaseSchedule av -> AccountReleaseSummary
toAccountReleaseSummary = case accountVersion @av of
SAccountV0 -> ARSV0.toAccountReleaseSummary . theAccountReleaseSchedule
SAccountV1 -> ARSV0.toAccountReleaseSummary . theAccountReleaseSchedule
SAccountV2 -> ARSV1.toAccountReleaseSummary . theAccountReleaseSchedule
SAccountV3 -> ARSV1.toAccountReleaseSummary . theAccountReleaseSchedule

instance (IsAccountVersion av, AccountStructureVersionFor av ~ 'AccountStructureV0) => HashableTo ARSV0.AccountReleaseScheduleHashV0 (AccountReleaseSchedule av) where
getHash = case accountVersion @av of
Expand All @@ -99,6 +105,7 @@ instance (IsAccountVersion av, AccountStructureVersionFor av ~ 'AccountStructure
instance (IsAccountVersion av, AccountStructureVersionFor av ~ 'AccountStructureV1) => HashableTo ARSV1.AccountReleaseScheduleHashV1 (AccountReleaseSchedule av) where
getHash = case accountVersion @av of
SAccountV2 -> getHash . theAccountReleaseSchedule
SAccountV3 -> getHash . theAccountReleaseSchedule
{-# INLINE getHash #-}

-- | Create an empty account release schedule
Expand All @@ -107,6 +114,7 @@ emptyAccountReleaseSchedule = case accountVersion @av of
SAccountV0 -> AccountReleaseSchedule ARSV0.emptyAccountReleaseSchedule
SAccountV1 -> AccountReleaseSchedule ARSV0.emptyAccountReleaseSchedule
SAccountV2 -> AccountReleaseSchedule ARSV1.emptyAccountReleaseSchedule
SAccountV3 -> AccountReleaseSchedule ARSV1.emptyAccountReleaseSchedule

-- | Add a list of amounts to this @AccountReleaseSchedule@.
--
Expand All @@ -121,6 +129,7 @@ addReleases = case accountVersion @av of
SAccountV0 -> \rels (AccountReleaseSchedule ars) -> AccountReleaseSchedule (ARSV0.addReleases rels ars)
SAccountV1 -> \rels (AccountReleaseSchedule ars) -> AccountReleaseSchedule (ARSV0.addReleases rels ars)
SAccountV2 -> \rels (AccountReleaseSchedule ars) -> AccountReleaseSchedule (ARSV1.addReleases rels ars)
SAccountV3 -> \rels (AccountReleaseSchedule ars) -> AccountReleaseSchedule (ARSV1.addReleases rels ars)

-- | Remove the amounts up to and including the given timestamp.
-- It returns the unlocked amount, maybe the next smallest timestamp for this account and the new account release schedule.
Expand All @@ -137,20 +146,24 @@ unlockAmountsUntil = case accountVersion @av of
_3 %~ AccountReleaseSchedule $ ARSV0.unlockAmountsUntil ts ars
SAccountV2 -> \ts (AccountReleaseSchedule ars) ->
_3 %~ AccountReleaseSchedule $ ARSV1.unlockAmountsUntil ts ars
SAccountV3 -> \ts (AccountReleaseSchedule ars) ->
_3 %~ AccountReleaseSchedule $ ARSV1.unlockAmountsUntil ts ars

-- | Get the timestamp at which the next scheduled release will occur (if any).
nextReleaseTimestamp :: forall av. (IsAccountVersion av) => AccountReleaseSchedule av -> Maybe Timestamp
nextReleaseTimestamp = case accountVersion @av of
SAccountV0 -> ARSV0.nextReleaseTimestamp . theAccountReleaseSchedule
SAccountV1 -> ARSV0.nextReleaseTimestamp . theAccountReleaseSchedule
SAccountV2 -> ARSV1.nextReleaseTimestamp . theAccountReleaseSchedule
SAccountV3 -> ARSV1.nextReleaseTimestamp . theAccountReleaseSchedule

-- | Get the total locked balance.
totalLockedUpBalance :: forall av. (IsAccountVersion av) => SimpleGetter (AccountReleaseSchedule av) Amount
totalLockedUpBalance = case accountVersion @av of
SAccountV0 -> to theAccountReleaseSchedule . ARSV0.totalLockedUpBalance
SAccountV1 -> to theAccountReleaseSchedule . ARSV0.totalLockedUpBalance
SAccountV2 -> to (ARSV1.arsTotalLockedAmount . theAccountReleaseSchedule)
SAccountV3 -> to (ARSV1.arsTotalLockedAmount . theAccountReleaseSchedule)

-- | Compute the sum of releases in the release schedule.
-- This should produce the same result as '_totalLockedUpBalance', and is provided for testing
Expand All @@ -160,3 +173,4 @@ sumOfReleases = case accountVersion @av of
SAccountV0 -> ARSV0.sumOfReleases . theAccountReleaseSchedule
SAccountV1 -> ARSV0.sumOfReleases . theAccountReleaseSchedule
SAccountV2 -> ARSV1.sumOfReleases . theAccountReleaseSchedule
SAccountV3 -> ARSV1.sumOfReleases . theAccountReleaseSchedule
18 changes: 12 additions & 6 deletions concordium-consensus/src/Concordium/GlobalState/BlockState.hs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ import Concordium.Types.Accounts
import Concordium.Types.Accounts.Releases
import Concordium.Types.AnonymityRevokers
import Concordium.Types.IdentityProviders
import Concordium.Types.Queries (PoolStatus, RewardStatus')
import Concordium.Types.Queries (BakerPoolStatus, PassiveDelegationStatus, RewardStatus')
import Concordium.Types.SeedState (SeedState, SeedStateVersion (..), SeedStateVersionFor)
import Concordium.Types.Transactions hiding (BareBlockItem (..))
import qualified Concordium.Types.UpdateQueues as UQ
Expand Down Expand Up @@ -646,14 +646,19 @@ class (ContractStateOperations m, AccountOperations m, ModuleQuery m) => BlockSt
-- | Get the epoch time of the next scheduled payday.
getPaydayEpoch :: (PVSupportsDelegation (MPV m)) => BlockState m -> m Epoch

-- | Get a 'PoolStatus' record describing the status of a baker pool (when the 'BakerId' is
-- provided) or the passive delegators (when 'Nothing' is provided). The result is 'Nothing'
-- if the 'BakerId' is not currently a baker.
-- | Get a 'BakerPoolStatus' record describing the status of a baker pool. The result is
-- 'Nothing' if the 'BakerId' is not an active or current-epoch baker.
getPoolStatus ::
(PVSupportsDelegation (MPV m)) =>
BlockState m ->
Maybe BakerId ->
m (Maybe PoolStatus)
BakerId ->
m (Maybe BakerPoolStatus)

-- | Get the status of passive delegation.
getPassiveDelegationStatus ::
(PVSupportsDelegation (MPV m)) =>
BlockState m ->
m PassiveDelegationStatus

-- | Distribution of newly-minted GTU.
data MintAmounts = MintAmounts
Expand Down Expand Up @@ -1502,6 +1507,7 @@ instance (Monad (t m), MonadTrans t, BlockStateQuery m) => BlockStateQuery (MGST
getChainParameters = lift . getChainParameters
getPaydayEpoch = lift . getPaydayEpoch
getPoolStatus s = lift . getPoolStatus s
getPassiveDelegationStatus = lift . getPassiveDelegationStatus
{-# INLINE getModule #-}
{-# INLINE getAccount #-}
{-# INLINE accountExists #-}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ instance (IsAccountVersion av, MonadBlobStore m) => BlobStorable m (PersistentAc
SAccountV0 -> fmap PAV0 <$> load
SAccountV1 -> fmap PAV1 <$> load
SAccountV2 -> fmap PAV2 <$> load
SAccountV3 -> undefined -- TODO: Implement account version 3

-- | Type of references to persistent accounts.
type AccountRef (av :: AccountVersion) = HashedCachedRef (AccountCache av) (PersistentAccount av)
Expand All @@ -82,6 +83,7 @@ instance (IsAccountVersion av, MonadBlobStore m) => BlobStorable m (PersistentBa
SAccountV0 -> fmap PBIRV0 <$!> load
SAccountV1 -> fmap PBIRV1 <$!> load
SAccountV2 -> fmap PBIRV2 <$!> load
SAccountV3 -> undefined -- TODO: Implement account version 3

-- * Account cache

Expand Down Expand Up @@ -457,6 +459,7 @@ makePersistentAccount tacc = case accountVersion @av of
SAccountV0 -> PAV0 <$> V0.makePersistentAccount tacc
SAccountV1 -> PAV1 <$> V0.makePersistentAccount tacc
SAccountV2 -> PAV2 <$> V1.makePersistentAccount tacc
SAccountV3 -> undefined -- TODO: Implement account version 3

-- | Create an empty account with the given public key, address and credential.
newAccount ::
Expand All @@ -470,6 +473,7 @@ newAccount = case accountVersion @av of
SAccountV0 -> \ctx addr cred -> PAV0 <$> V0.newAccount ctx addr cred
SAccountV1 -> \ctx addr cred -> PAV1 <$> V0.newAccount ctx addr cred
SAccountV2 -> \ctx addr cred -> PAV2 <$> V1.newAccount ctx addr cred
SAccountV3 -> undefined -- TODO: Implement account version 3

-- | Make a persistent account from a genesis account.
-- The data is immediately flushed to disc and cached.
Expand All @@ -489,6 +493,7 @@ makeFromGenesisAccount spv =
PAV1 <$> V0.makeFromGenesisAccount spv cryptoParams chainParameters genesisAccount
SAccountV2 -> \cryptoParams chainParameters genesisAccount ->
PAV2 <$> V1.makeFromGenesisAccount spv cryptoParams chainParameters genesisAccount
SAccountV3 -> undefined -- TODO: Implement account version 3

-- ** 'PersistentBakerInfoRef' creation

Expand All @@ -502,6 +507,7 @@ makePersistentBakerInfoRef = case accountVersion @av of
SAccountV0 -> fmap PBIRV0 . V0.makePersistentBakerInfoEx
SAccountV1 -> fmap PBIRV1 . V0.makePersistentBakerInfoEx
SAccountV2 -> fmap PBIRV2 . V1.makePersistentBakerInfoEx
SAccountV3 -> undefined -- TODO: Implement account version 3

-- * Migration

Expand All @@ -523,7 +529,7 @@ migratePersistentAccount m@StateMigrationParametersP2P3 (PAV0 acc) = PAV0 <$> V0
migratePersistentAccount m@StateMigrationParametersP3ToP4{} (PAV0 acc) = PAV1 <$> V0.migratePersistentAccount m acc
migratePersistentAccount m@StateMigrationParametersP4ToP5{} (PAV1 acc) = PAV2 <$> V1.migratePersistentAccountFromV0 m acc
migratePersistentAccount m@StateMigrationParametersP5ToP6{} (PAV2 acc) = PAV2 <$> V1.migratePersistentAccount m acc
migratePersistentAccount m@StateMigrationParametersP6ToP7{} (PAV2 acc) = PAV2 <$> V1.migratePersistentAccount m acc
migratePersistentAccount StateMigrationParametersP6ToP7{} _ = undefined -- TODO: Implement migration

-- | Migrate a 'PersistentBakerInfoRef' between protocol versions according to a state migration.
migratePersistentBakerInfoRef ::
Expand All @@ -540,7 +546,7 @@ migratePersistentBakerInfoRef m@StateMigrationParametersP2P3 (PBIRV0 bir) = PBIR
migratePersistentBakerInfoRef m@StateMigrationParametersP3ToP4{} (PBIRV0 bir) = PBIRV1 <$> V0.migratePersistentBakerInfoEx m bir
migratePersistentBakerInfoRef m@StateMigrationParametersP4ToP5{} (PBIRV1 bir) = PBIRV2 <$> V1.migratePersistentBakerInfoExFromV0 m bir
migratePersistentBakerInfoRef m@StateMigrationParametersP5ToP6{} (PBIRV2 bir) = PBIRV2 <$> V1.migratePersistentBakerInfoEx m bir
migratePersistentBakerInfoRef m@StateMigrationParametersP6ToP7{} (PBIRV2 bir) = PBIRV2 <$> V1.migratePersistentBakerInfoEx m bir
migratePersistentBakerInfoRef StateMigrationParametersP6ToP7{} _ = undefined -- TODO: Implement migration

-- * Conversion

Expand Down
Loading
Loading