Skip to content

Commit eade962

Browse files
authored
Merge pull request #1175 from Concordium/cooldown-changes
Cooldown changes
2 parents fec7af3 + 0b33407 commit eade962

File tree

38 files changed

+5239
-1208
lines changed

38 files changed

+5239
-1208
lines changed

CHANGELOG.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,24 @@
22

33
## Unreleased changes
44

5+
## 7.0.3
6+
7+
- Fix a bug in the computation of the genesis height after the second protocol update. (#1237)
8+
- Fix a bug where an error was incorrectly thrown when loading the consenus state immediately
9+
after a protocol update (in the new consensus version) (#1236).
10+
11+
## 7.0.2
12+
13+
- Fix the timing of paydays after protocol update from version 6 to 7.
14+
- Improve consensus behaviour in the event of an unrecoverable exception.
15+
16+
## 7.0.1
17+
18+
- Fix a bug in migration from protocol version 6 to 7.
19+
- Support "reboot" protocol update at protocol version 7.
20+
21+
## 7.0.0
22+
523
- Fix a bug where `GetBakersRewardPeriod` returns incorrect data (#1176).
624
- Fix a bug where `GetPoolInfo` returns incorrect data (#1177).
725
- Change the severity of logs for failed gRPC API requests to DEBUG level.
@@ -20,6 +38,16 @@
2038
`TransferToPublic` remains enabled, allowing existing encrypted balances to be
2139
decrypted.
2240
- Improve logging around protocol update events.
41+
- Changes to stake cooldown behavior in protocol version 7:
42+
- When stake is reduced or removed from a validator or delegator, it becomes
43+
inactive, and is not counted for future stake calculations. The inactive
44+
stake is not spendable, but is released after a cooldown period elapses.
45+
- Changes to validators and delegators can be made while stake is in cooldown,
46+
including changing the stake, or changing directly between validator and
47+
delegator.
48+
- Fix a bug where a configure-validator transaction that is rejected for having
49+
a duplicate aggregation key would report the old key for the validator,
50+
rather than the key that is a duplicate.
2351

2452
## 6.3.1
2553

concordium-base

Submodule concordium-base updated 39 files

concordium-consensus/src-lib/Concordium/External.hs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ stopBaker cptr = mask_ $ do
726726
-- | 16 | ResultNonexistingSenderAccount | The transaction's sender account does not exist according to the focus block | No |
727727
-- +-------+---------------------------------------------+-----------------------------------------------------------------------------------------------+----------+
728728
-- | 17 | ResultDuplicateNonce | The sequence number for this account or update type was already used | No |
729-
-- i+-------+---------------------------------------------+-----------------------------------------------------------------------------------------------+----------+
729+
-- +-------+---------------------------------------------+-----------------------------------------------------------------------------------------------+----------+
730730
-- | 18 | ResultNonceTooLarge | The transaction seq. number is larger than the next one for this account/update type | No |
731731
-- +-------+---------------------------------------------+-----------------------------------------------------------------------------------------------+----------+
732732
-- | 19 | ResultTooLowEnergy | The stated transaction energy is lower than the minimum amount necessary to execute it | No |
@@ -755,6 +755,8 @@ stopBaker cptr = mask_ $ do
755755
-- +-------+---------------------------------------------+-----------------------------------------------------------------------------------------------+----------+
756756
-- | 31 | ResultDoubleSign | The consensus message is a result of malignant double signing. | No |
757757
-- +-------+---------------------------------------------+-----------------------------------------------------------------------------------------------+----------+
758+
-- | 32 | ResultConsensusFailure | The consensus has thrown an exception and entered an unrecoverable state. | No |
759+
-- +-------+---------------------------------------------+-----------------------------------------------------------------------------------------------+----------+
758760
type ReceiveResult = Int64
759761

760762
-- | Convert an 'UpdateResult' to the corresponding 'ReceiveResult' value.
@@ -791,12 +793,13 @@ toReceiveResult ResultChainUpdateInvalidSignatures = 28
791793
toReceiveResult ResultEnergyExceeded = 29
792794
toReceiveResult ResultInsufficientFunds = 30
793795
toReceiveResult ResultDoubleSign = 31
796+
toReceiveResult ResultConsensusFailure = 32
794797

795798
-- | Handle receipt of a block.
796799
-- The possible return codes are @ResultSuccess@, @ResultSerializationFail@,
797800
-- @ResultInvalid@, @ResultPendingBlock@, @ResultDuplicate@, @ResultStale@,
798801
-- @ResultConsensusShutDown@, @ResultEarlyBlock@, @ResultInvalidGenesisIndex@, and
799-
-- @ResultDoubleSign@.
802+
-- @ResultDoubleSign@. Additionally @ResultConsensusFailure@ is returned if an exception occurs.
800803
-- 'receiveBlock' may invoke the callbacks for new finalization messages.
801804
-- If the block was successfully verified i.e. baker signature, finalization proofs etc. then
802805
-- the continuation for executing the block will be written to the 'Ptr' provided.
@@ -827,25 +830,27 @@ receiveBlock bptr genIndex msg msgLen ptrPtrExecuteBlock = do
827830
poke ptrPtrExecuteBlock =<< newStablePtr eb
828831
return $ toReceiveResult receiveResult
829832

830-
-- | Execute a block that has been received and succesfully verified.
833+
-- | Execute a block that has been received and successfully verified.
831834
-- The 'MV.ExecuteBlock' continuation is obtained via first calling 'receiveBlock' which in return
832835
-- will construct a pointer to the continuation.
833836
-- The 'StablePtr' is freed here and so this function should only be called once for each 'MV.ExecuteBlock'.
834837
-- The possible return codes are @ResultSuccess@, @ResultSerializationFail@, @ResultInvalid@
835838
-- and @ResultConsensusShutDown@.
839+
-- Additionally @ResultConsensusFailure@ is returned if an exception occurs.
836840
executeBlock :: StablePtr ConsensusRunner -> StablePtr MV.ExecuteBlock -> IO ReceiveResult
837841
executeBlock ptrConsensus ptrCont = do
838842
(ConsensusRunner mvr) <- deRefStablePtr ptrConsensus
839843
executableBlock <- deRefStablePtr ptrCont
840844
freeStablePtr ptrCont
841845
mvLog mvr External LLTrace "Executing block."
842-
res <- MV.runBlock executableBlock
846+
res <- runMVR (MV.executeBlock executableBlock) mvr
843847
return $ toReceiveResult res
844848

845849
-- | Handle receipt of a finalization message.
846850
-- The possible return codes are @ResultSuccess@, @ResultSerializationFail@, @ResultInvalid@,
847851
-- @ResultPendingFinalization@, @ResultDuplicate@, @ResultStale@, @ResultIncorrectFinalizationSession@,
848852
-- @ResultUnverifiable@, @ResultConsensusShutDown@, @ResultInvalidGenesisIndex@, and @ResultDoubleSign@.
853+
-- Additionally @ResultConsensusFailure@ is returned if an exception occurs.
849854
-- 'receiveFinalization' may invoke the callbacks for new finalization messages.
850855
receiveFinalizationMessage ::
851856
StablePtr ConsensusRunner ->
@@ -863,6 +868,7 @@ receiveFinalizationMessage bptr genIndex msg msgLen = do
863868
-- The possible return codes are @ResultSuccess@, @ResultSerializationFail@, @ResultInvalid@,
864869
-- @ResultPendingBlock@, @ResultPendingFinalization@, @ResultDuplicate@, @ResultStale@,
865870
-- @ResultConsensusShutDown@ and @ResultInvalidGenesisIndex@.
871+
-- Additionally @ResultConsensusFailure@ is returned if an exception occurs.
866872
-- 'receiveFinalizationRecord' may invoke the callbacks for new finalization messages.
867873
receiveFinalizationRecord ::
868874
StablePtr ConsensusRunner ->
@@ -885,7 +891,8 @@ receiveFinalizationRecord bptr genIndex msg msgLen = do
885891
-- @ResultCredentialDeploymentInvalidIP@, @ResultCredentialDeploymentInvalidAR@,
886892
-- @ResultCredentialDeploymentExpired@, @ResultChainUpdateInvalidSequenceNumber@,
887893
-- @ResultChainUpdateInvalidEffectiveTime@, @ResultChainUpdateInvalidSignatures@,
888-
-- @ResultEnergyExceeded@
894+
-- @ResultEnergyExceeded@.
895+
-- Additionally @ResultConsensusFailure@ is returned if an exception occurs.
889896
receiveTransaction :: StablePtr ConsensusRunner -> CString -> Int64 -> Ptr Word8 -> IO ReceiveResult
890897
receiveTransaction bptr transactionData transactionLen outPtr = do
891898
(ConsensusRunner mvr) <- deRefStablePtr bptr
@@ -907,6 +914,7 @@ receiveTransaction bptr transactionData transactionLen outPtr = do
907914
-- * @ResultPendingBlock@ -- the sender has some data I am missing, and should be marked pending
908915
-- * @ResultSuccess@ -- I do not require additional data from the sender, so mark it as up-to-date
909916
-- * @ResultContinueCatchUp@ -- The sender should be marked pending if it is currently up-to-date (no change otherwise)
917+
-- * @ResultConsensusFailure@ -- an internal exception occurred
910918
receiveCatchUpStatus ::
911919
-- | Consensus pointer
912920
StablePtr ConsensusRunner ->
@@ -957,6 +965,7 @@ getCatchUpStatus cptr genIndexPtr resPtr = do
957965

958966
-- | Import a file consisting of a set of blocks and finalization records for the purposes of
959967
-- out-of-band catch-up.
968+
-- @ResultConsensusFailure@ is returned if an exception occurs.
960969
importBlocks ::
961970
-- | Consensus runner
962971
StablePtr ConsensusRunner ->

concordium-consensus/src/Concordium/GlobalState/BakerInfo.hs

Lines changed: 123 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,15 @@ data BakerKeyUpdate = BakerKeyUpdate
111111
}
112112
deriving (Eq, Ord, Show)
113113

114+
-- | Extract the 'BakerKeyUpdate' from a 'BakerKeysWithProofs'.
115+
bakerKeysWithoutProofs :: BakerKeysWithProofs -> BakerKeyUpdate
116+
bakerKeysWithoutProofs BakerKeysWithProofs{..} =
117+
BakerKeyUpdate
118+
{ bkuSignKey = bkwpSignatureVerifyKey,
119+
bkuAggregationKey = bkwpAggregationVerifyKey,
120+
bkuElectionKey = bkwpElectionVerifyKey
121+
}
122+
114123
data BakerKeyUpdateResult
115124
= -- | The keys were updated successfully
116125
BKUSuccess !BakerId
@@ -174,32 +183,83 @@ data BakerAddResult
174183
BAStakeUnderThreshold
175184
deriving (Eq, Ord, Show)
176185

177-
-- | Data structure used to add/remove/update baker.
178-
data BakerConfigure
179-
= -- | Add a baker, all fields are required.
180-
BakerConfigureAdd
181-
{ bcaKeys :: !BakerKeyUpdate,
182-
bcaCapital :: !Amount,
183-
bcaRestakeEarnings :: !Bool,
184-
bcaOpenForDelegation :: !OpenStatus,
185-
bcaMetadataURL :: !UrlText,
186-
bcaTransactionFeeCommission :: !AmountFraction,
187-
bcaBakingRewardCommission :: !AmountFraction,
188-
bcaFinalizationRewardCommission :: !AmountFraction
189-
}
190-
| -- | Update baker with optional fields.
191-
BakerConfigureUpdate
192-
{ -- | The timestamp of the current slot (slot time).
193-
bcuSlotTimestamp :: !Timestamp,
194-
bcuKeys :: !(Maybe BakerKeyUpdate),
195-
bcuCapital :: !(Maybe Amount),
196-
bcuRestakeEarnings :: !(Maybe Bool),
197-
bcuOpenForDelegation :: !(Maybe OpenStatus),
198-
bcuMetadataURL :: !(Maybe UrlText),
199-
bcuTransactionFeeCommission :: !(Maybe AmountFraction),
200-
bcuBakingRewardCommission :: !(Maybe AmountFraction),
201-
bcuFinalizationRewardCommission :: !(Maybe AmountFraction)
186+
-- | Result of remove baker.
187+
data BakerRemoveResult
188+
= -- | The baker was removed, effective from the given epoch.
189+
BRRemoved !BakerId !Epoch
190+
| -- | This is not a valid baker.
191+
BRInvalidBaker
192+
| -- | A change is already pending on this baker.
193+
BRChangePending !BakerId
194+
deriving (Eq, Ord, Show)
195+
196+
-- | Parameters for adding a validator.
197+
data ValidatorAdd = ValidatorAdd
198+
{ -- | The keys for the validator.
199+
vaKeys :: !BakerKeyUpdate,
200+
-- | The initial stake.
201+
vaCapital :: !Amount,
202+
-- | Whether to restake earned rewards
203+
vaRestakeEarnings :: !Bool,
204+
-- | Whether the validator pool is open for delegation.
205+
vaOpenForDelegation :: !OpenStatus,
206+
-- | The metadata URL for the validator.
207+
vaMetadataURL :: !UrlText,
208+
-- | The commission rates for the validator.
209+
vaCommissionRates :: !CommissionRates
210+
}
211+
deriving (Eq, Show)
212+
213+
-- | Parameters for updating an existing validator. Where a field is 'Nothing', the field is not
214+
-- updated.
215+
data ValidatorUpdate = ValidatorUpdate
216+
{ -- | The new keys for the validator.
217+
vuKeys :: !(Maybe BakerKeyUpdate),
218+
-- | The new capital for the validator. If this is @Just 0@, the validator is removed.
219+
vuCapital :: !(Maybe Amount),
220+
-- | Whether to restake earned rewards.
221+
vuRestakeEarnings :: !(Maybe Bool),
222+
-- | Whether the validator pool is open for delegation.
223+
vuOpenForDelegation :: !(Maybe OpenStatus),
224+
-- | The new metadata URL for the validator.
225+
vuMetadataURL :: !(Maybe UrlText),
226+
-- | The new transaction fee commission for the validator.
227+
vuTransactionFeeCommission :: !(Maybe AmountFraction),
228+
-- | The new baking reward commission for the validator.
229+
vuBakingRewardCommission :: !(Maybe AmountFraction),
230+
-- | The new finalization reward commission for the validator.
231+
vuFinalizationRewardCommission :: !(Maybe AmountFraction)
232+
}
233+
deriving (Eq, Show)
234+
235+
-- | A 'ValidatorUpdate' that removes the validator.
236+
validatorRemove :: ValidatorUpdate
237+
validatorRemove =
238+
ValidatorUpdate
239+
{ vuKeys = Nothing,
240+
vuCapital = Just 0,
241+
vuRestakeEarnings = Nothing,
242+
vuOpenForDelegation = Nothing,
243+
vuMetadataURL = Nothing,
244+
vuTransactionFeeCommission = Nothing,
245+
vuBakingRewardCommission = Nothing,
246+
vuFinalizationRewardCommission = Nothing
202247
}
248+
249+
-- | Failure modes when configuring a validator.
250+
data ValidatorConfigureFailure
251+
= -- | The stake is below the required threshold dictated by current chain parameters.
252+
VCFStakeUnderThreshold
253+
| -- | The transaction fee commission is not in the allowed range.
254+
VCFTransactionFeeCommissionNotInRange
255+
| -- | The baking reward commission is not in the allowed range.
256+
VCFBakingRewardCommissionNotInRange
257+
| -- | The finalization reward commission is not in the allowed range.
258+
VCFFinalizationRewardCommissionNotInRange
259+
| -- | The aggregation key is already in use by another validator.
260+
VCFDuplicateAggregationKey !BakerAggregationVerifyKey
261+
| -- | A change is already pending on this validator.
262+
VCFChangePending
203263
deriving (Eq, Show)
204264

205265
-- | A baker update change result from configure baker. Used to indicate whether the configure will cause
@@ -216,55 +276,37 @@ data BakerConfigureUpdateChange
216276
| BakerConfigureFinalizationRewardCommission !AmountFraction
217277
deriving (Eq, Show)
218278

219-
-- | Result of configure baker.
220-
data BakerConfigureResult
221-
= -- | Configure baker successful.
222-
BCSuccess ![BakerConfigureUpdateChange] !BakerId
223-
| -- | Account unknown.
224-
BCInvalidAccount
225-
| -- | The aggregation key already exists.
226-
BCDuplicateAggregationKey !BakerAggregationVerifyKey
227-
| -- | The stake is below the required threshold dictated by current chain parameters.
228-
BCStakeUnderThreshold
229-
| -- | The finalization reward commission is not in the allowed range.
230-
BCFinalizationRewardCommissionNotInRange
231-
| -- | The baking reward commission is not in the allowed range.
232-
BCBakingRewardCommissionNotInRange
233-
| -- | The transaction fee commission is not in the allowed range.
234-
BCTransactionFeeCommissionNotInRange
235-
| -- | A change is already pending on this baker.
236-
BCChangePending
237-
| -- | This is not a valid baker.
238-
BCInvalidBaker
279+
-- | Parameters for adding a delegator.
280+
data DelegatorAdd = DelegatorAdd
281+
{ -- | The initial staked capital for the delegator.
282+
daCapital :: !Amount,
283+
-- | Whether to restake earnings.
284+
daRestakeEarnings :: !Bool,
285+
-- | The delegation target for the delegator.
286+
daDelegationTarget :: !DelegationTarget
287+
}
239288
deriving (Eq, Show)
240289

241-
-- | Result of remove baker.
242-
data BakerRemoveResult
243-
= -- | The baker was removed, effective from the given epoch.
244-
BRRemoved !BakerId !Epoch
245-
| -- | This is not a valid baker.
246-
BRInvalidBaker
247-
| -- | A change is already pending on this baker.
248-
BRChangePending !BakerId
249-
deriving (Eq, Ord, Show)
290+
-- | Parameters for updating an existing delegator. Where a field is 'Nothing', the field is not
291+
-- updated.
292+
data DelegatorUpdate = DelegatorUpdate
293+
{ -- | The new capital for the delegator. If this is @Just 0@, the delegator is removed.
294+
duCapital :: !(Maybe Amount),
295+
-- | Whether to restake earnings.
296+
duRestakeEarnings :: !(Maybe Bool),
297+
-- | The new delegation target for the delegator.
298+
duDelegationTarget :: !(Maybe DelegationTarget)
299+
}
300+
deriving (Eq, Show)
250301

251-
-- | Data structure used to add/remove/update delegator.
252-
data DelegationConfigure
253-
= -- | Add a delegator, all fields are required.
254-
DelegationConfigureAdd
255-
{ dcaCapital :: !Amount,
256-
dcaRestakeEarnings :: !Bool,
257-
dcaDelegationTarget :: !DelegationTarget
258-
}
259-
| -- | Update delegator with optional fields.
260-
DelegationConfigureUpdate
261-
{ -- | The timestamp of the current slot (slot time of the block in which the update occurs).
262-
dcuSlotTimestamp :: !Timestamp,
263-
dcuCapital :: !(Maybe Amount),
264-
dcuRestakeEarnings :: !(Maybe Bool),
265-
dcuDelegationTarget :: !(Maybe DelegationTarget)
302+
-- | A 'DelegatorUpdate' that removes the delegator.
303+
delegatorRemove :: DelegatorUpdate
304+
delegatorRemove =
305+
DelegatorUpdate
306+
{ duCapital = Just 0,
307+
duRestakeEarnings = Nothing,
308+
duDelegationTarget = Nothing
266309
}
267-
deriving (Eq, Show)
268310

269311
-- | A delegation update change result from configure delegation. Used to indicate whether the
270312
-- configure will cause any changes to the delegator's stake, restake earnings flag, etc.
@@ -275,24 +317,19 @@ data DelegationConfigureUpdateChange
275317
| DelegationConfigureDelegationTarget !DelegationTarget
276318
deriving (Eq, Show)
277319

278-
-- | Result of configure delegator.
279-
data DelegationConfigureResult
280-
= -- | Configure delegation successful.
281-
DCSuccess ![DelegationConfigureUpdateChange] !DelegatorId
282-
| -- | Account unknown.
283-
DCInvalidAccount
284-
| -- | A change is already pending on this delegator.
285-
DCChangePending
286-
| -- | This is not a valid delegator.
287-
DCInvalidDelegator
288-
| -- | Delegation target is not a valid baker.
289-
DCInvalidDelegationTarget !BakerId
320+
-- | Failure modes for configuring a delegator.
321+
data DelegatorConfigureFailure
322+
= -- | The delegation target is not a valid baker.
323+
DCFInvalidDelegationTarget !BakerId
290324
| -- | The pool is not open for delegators.
291-
DCPoolClosed
325+
DCFPoolClosed
292326
| -- | The pool's total capital would become too large.
293-
DCPoolStakeOverThreshold
294-
| -- | The delegated capital would become too large in comparison with pool owner's equity capital.
295-
DCPoolOverDelegated
327+
DCFPoolStakeOverThreshold
328+
| -- | The delegated capital would become too large in comparison with pool owner's equity
329+
-- capital.
330+
DCFPoolOverDelegated
331+
| -- | A change is already pending on this delegator.
332+
DCFChangePending
296333
deriving (Eq, Show)
297334

298335
-- | Construct an 'AccountBaker' from a 'GenesisBaker'.

0 commit comments

Comments
 (0)