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

Support protocol 7 API changes #198

Merged
Show file tree
Hide file tree
Changes from 12 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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Unreleased changes

- Add `cis3` module and `Cis3Contract` for interacting with CIS3 contracts.
- Updated the concordium-base submodule to incorporate protocol 7 changes.
This updates some protobuf messages relating to cooldown and baker pool status.
limemloh marked this conversation as resolved.
Show resolved Hide resolved

## 4.3.0

Expand Down Expand Up @@ -126,7 +128,7 @@
serialization macros.
- Bump minimum supported rust version to 1.64.
- When using derive(Serial,Deserial) macros from the smart_contracts modules
`concordium_std` must be made available, for example as
`concordium_std` must be made available, for example as
`use concordium_rust_sdk::smart_contracts::common as concordium_std`

## 2.3.0
Expand Down
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
let spec = repo.revparse_single("HEAD")?.id();
std::fs::write(
"./src/v2/proto_schema_version.rs",
format!("pub const PROTO_SCHEMA_VERSION: &str = \"{}\";", spec),
format!("pub const PROTO_SCHEMA_VERSION: &str = \"{}\";\n", spec),
)?;
}
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion concordium-base
Submodule concordium-base updated 32 files
+1 −1 Setup.hs
+1 −0 concordium-base.cabal
+1 −1 concordium-grpc-api
+6 −5 haskell-src/Concordium/Cost.hs
+17 −0 haskell-src/Concordium/Crypto/EncryptedTransfers.hs
+34 −14 haskell-src/Concordium/GRPC2.hs
+8 −0 haskell-src/Concordium/ID/Types.hs
+1 −1 haskell-src/Concordium/Types.hs
+111 −68 haskell-src/Concordium/Types/Accounts.hs
+278 −15 haskell-src/Concordium/Types/Execution.hs
+1 −1 haskell-src/Concordium/Types/Migration.hs
+8 −0 haskell-src/Concordium/Types/Parameters.hs
+63 −33 haskell-src/Concordium/Types/ProtocolVersion.hs
+65 −36 haskell-src/Concordium/Types/Queries.hs
+2 −4 haskell-src/Concordium/Types/Transactions.hs
+47 −2 haskell-src/Concordium/Wasm.hs
+60 −2 haskell-tests/Generators.hs
+2 −0 haskell-tests/Spec.hs
+113 −14 haskell-tests/Types/PayloadSerializationSpec.hs
+99 −0 haskell-tests/Types/PayloadSpec.hs
+5 −1 mobile_wallet/CHANGELOG.md
+5 −5 mobile_wallet/Cargo.lock
+1 −1 mobile_wallet/Cargo.toml
+6 −0 mobile_wallet/src/lib.rs
+3 −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
+4 −3 rust-src/concordium_base/src/lib.rs
+93 −6 rust-src/concordium_base/src/transactions.rs
+119 −41 rust-src/concordium_base/src/web3id/mod.rs
+1 −0 smart-contracts/contracts-common/concordium-contracts-common/CHANGELOG.md
+2 −2 smart-contracts/contracts-common/concordium-contracts-common/src/types.rs
1 change: 1 addition & 0 deletions examples/v2_dry_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ async fn test_all(endpoint: v2::Endpoint) -> anyhow::Result<()> {
// Update the timestamp to now.
let _fut7 = dry_run.begin_set_timestamp(Timestamp::now()).await?;
// Execute a transfer to the encrypted balance on account 0.
#[allow(deprecated)]
let payload = Payload::TransferToEncrypted {
amount: Amount::from_ccd(20),
};
Expand Down
5 changes: 4 additions & 1 deletion examples/v2_send_encrypted_transfer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ async fn main() -> anyhow::Result<()> {
)?;
send::transfer_to_public(&keys.account_keys, keys.address, nonce, expiry, data)
}
Receiver::Encrypt => {
Receiver::Encrypt =>
{
#[allow(deprecated)]
send::transfer_to_encrypted(&keys.account_keys, keys.address, nonce, expiry, app.amount)
}
Receiver::Transfer(addr) => {
Expand All @@ -127,6 +129,7 @@ async fn main() -> anyhow::Result<()> {
&receiver.response.account_encryption_key,
&mut rng,
)?;
#[allow(deprecated)]
send::encrypted_transfer(&keys.account_keys, keys.address, nonce, expiry, addr, data)
}
};
Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
//! - [`common`] has some common type definitions, as well as traits and helpers
//! for binary serialization
//! - [`encrypted_transfers`] implements structures and zero knowledge proofs
//! related to encrypted transfers
//! related to encrypted transfers. Note that this functionality has been
//! deprecated in protocol version 7.
//! - [`eddsa_ed25519`] is a re-export of the signature scheme used for blocks
//! and accounts on the Concordium blockchain.
//! - [`aggregate_sig`] is a re-export of the BLS signature scheme, used by the
Expand Down
91 changes: 83 additions & 8 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,13 @@ impl AccountEncryptedAmount {
let mut combined = self.self_amount.clone();
let mut agg_amount = encrypted_transfers::decrypt_amount(table, sk, &self.self_amount);
let mut index = self.start_index;
#[allow(deprecated)]
if let Some((agg, num_agg)) = self.aggregated_amount.as_ref() {
agg_amount += encrypted_transfers::decrypt_amount(table, sk, agg);
combined = encrypted_transfers::aggregate(&combined, agg);
index += u64::from(*num_agg);
}
#[allow(deprecated)]
for amount in &self.incoming_amounts {
agg_amount += encrypted_transfers::decrypt_amount(table, sk, amount);
combined = encrypted_transfers::aggregate(&combined, amount);
Expand Down Expand Up @@ -192,6 +194,7 @@ impl AccountEncryptedAmount {
{
let agg_amount = self.decrypt_and_combine(ctx, sk);
if amount <= agg_amount.agg_amount {
#[allow(deprecated)]
let data = encrypted_transfers::make_transfer_data(
ctx.params,
receiver_pk,
Expand Down Expand Up @@ -285,6 +288,46 @@ impl AccountStakingInfo {
}
}

/// The status of a cooldown. When stake is removed from a baker or delegator
/// (from protocol version 7) it first enters the pre-pre-cooldown state.
/// The next time the stake snaphot is taken (at the epoch transition before
/// a payday) it enters the pre-cooldown state. At the subsequent payday, it
/// enters the cooldown state. At the payday after the end of the cooldown
/// period, the stake is finally released.
#[derive(SerdeSerialize, SerdeDeserialize, Debug, PartialEq)]
pub enum CooldownStatus {
Victor-N-Suadicani marked this conversation as resolved.
Show resolved Hide resolved
/// The amount is in cooldown and will expire at the specified time,
/// becoming available at the subsequent pay day.
Cooldown,

/// The amount will enter cooldown at the next pay day. The specified
/// end time is projected to be the end of the cooldown period,
/// but the actual end time will be determined at the payday,
/// and may be different if the global cooldown period changes.
PreCooldown,

/// The amount will enter pre-cooldown at the next snapshot epoch (i.e.
/// the epoch transition before a pay day transition). As with
/// pre-cooldown, the specified end time is projected, but the
/// actual end time will be determined later.
PrePreCooldown,
}

#[derive(SerdeSerialize, SerdeDeserialize, Debug, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct Cooldown {
/// The time in milliseconds since the Unix epoch when the cooldown period
/// ends.
pub end_time: Timestamp,

/// The amount that is in cooldown and set to be released at the end of the
/// cooldown period.
pub amount: Amount,

/// The status of the cooldown.
pub status: CooldownStatus,
}

#[derive(SerdeSerialize, SerdeDeserialize, Debug, PartialEq)]
#[serde(rename_all = "camelCase")]
/// Account information exposed via the node's API. This is always the state of
Expand Down Expand Up @@ -327,6 +370,19 @@ pub struct AccountInfo {
pub account_stake: Option<AccountStakingInfo>,
/// Canonical address of the account.
pub account_address: AccountAddress,

/// The stake on the account that is in cooldown.
/// There can be multiple amounts in cooldown that expire at different
/// times.
/// Empty for nodes using protocol version 6 or lower.
pub cooldowns: Vec<Cooldown>,
Victor-N-Suadicani marked this conversation as resolved.
Show resolved Hide resolved

/// The available (unencrypted) balance of the account (i.e. that can be
/// transferred or used to pay for transactions). This is the balance
/// minus the locked amount. The locked amount is the maximum of the
/// amount in the release schedule and the total amount that is actively
/// staked or in cooldown (inactive stake).
pub available_balance: Amount,
}

impl From<&AccountInfo> for AccountAccessStructure {
Expand Down Expand Up @@ -595,9 +651,26 @@ mod lottery_power_parser {
/// the state of the baker that is currently eligible for baking.
pub struct BakerPoolStatus {
/// The 'BakerId' of the pool owner.
pub baker_id: BakerId,
pub baker_id: BakerId,
/// The account address of the pool owner.
pub baker_address: AccountAddress,
pub baker_address: AccountAddress,
/// The active status of the pool. This reflects any changes to the pool
/// since the last snapshot.
pub active_baker_pool_status: Option<ActiveBakerPoolStatus>,
/// Status of the pool in the current reward period. This will be [`None`]
/// if the pool is not a baker in the payday (e.g., because they just
/// registered and a new payday has not started yet).
pub current_payday_status: Option<CurrentPaydayBakerPoolStatus>,
/// Total capital staked across all pools.
pub all_pool_total_capital: Amount,
}

// Information about a baker pool's active stake and status. This does not
// reflect the stake used for the current reward period, but rather the stake
// that is currently active.
#[derive(SerdeSerialize, SerdeDeserialize, Debug, Clone, PartialEq)]
#[serde(rename_all = "camelCase")]
pub struct ActiveBakerPoolStatus {
/// The equity capital provided by the pool owner.
pub baker_equity_capital: Amount,
/// The capital delegated to the pool by other accounts.
Expand All @@ -610,12 +683,6 @@ pub struct BakerPoolStatus {
pub pool_info: BakerPoolInfo,
/// Any pending change to the baker's stake.
pub baker_stake_pending_change: PoolPendingChange,
/// Status of the pool in the current reward period. This will be [`None`]
/// if the pool is not a baker in the payday (e.g., because they just
/// registered and a new payday has not started yet).
pub current_payday_status: Option<CurrentPaydayBakerPoolStatus>,
/// Total capital staked across all pools.
pub all_pool_total_capital: Amount,
}

#[derive(SerdeSerialize, SerdeDeserialize, Debug, Clone)]
Expand Down Expand Up @@ -1705,19 +1772,27 @@ impl AccountTransactionEffects {
AccountTransactionEffects::ContractUpdateIssued { .. } => Some(Update),
AccountTransactionEffects::AccountTransfer { .. } => Some(Transfer),
AccountTransactionEffects::AccountTransferWithMemo { .. } => Some(TransferWithMemo),
#[allow(deprecated)]
AccountTransactionEffects::BakerAdded { .. } => Some(AddBaker),
#[allow(deprecated)]
AccountTransactionEffects::BakerRemoved { .. } => Some(RemoveBaker),
#[allow(deprecated)]
AccountTransactionEffects::BakerStakeUpdated { .. } => Some(UpdateBakerStake),
#[allow(deprecated)]
AccountTransactionEffects::BakerRestakeEarningsUpdated { .. } => {
Some(UpdateBakerRestakeEarnings)
}
#[allow(deprecated)]
AccountTransactionEffects::BakerKeysUpdated { .. } => Some(UpdateBakerKeys),
#[allow(deprecated)]
AccountTransactionEffects::EncryptedAmountTransferred { .. } => {
Some(EncryptedAmountTransfer)
}
#[allow(deprecated)]
AccountTransactionEffects::EncryptedAmountTransferredWithMemo { .. } => {
Some(EncryptedAmountTransferWithMemo)
}
#[allow(deprecated)]
AccountTransactionEffects::TransferredToEncrypted { .. } => Some(TransferToEncrypted),
AccountTransactionEffects::TransferredToPublic { .. } => Some(TransferToPublic),
AccountTransactionEffects::TransferredWithSchedule { .. } => Some(TransferWithSchedule),
Expand Down
29 changes: 25 additions & 4 deletions src/types/summary_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,10 +462,14 @@ impl From<super::BlockItemSummary> for BlockItemSummary {
},
Event::TransferMemo { memo },
),
super::AccountTransactionEffects::BakerAdded { data } => {
super::AccountTransactionEffects::BakerAdded { data } =>
{
#[allow(deprecated)]
mk_success_1(TransactionType::AddBaker, Event::BakerAdded { data })
}
super::AccountTransactionEffects::BakerRemoved { baker_id } => {
super::AccountTransactionEffects::BakerRemoved { baker_id } =>
{
#[allow(deprecated)]
mk_success_1(TransactionType::RemoveBaker, Event::BakerRemoved {
baker_id,
account: sender,
Expand All @@ -474,6 +478,7 @@ impl From<super::BlockItemSummary> for BlockItemSummary {
super::AccountTransactionEffects::BakerStakeUpdated { data } => {
if let Some(data) = data {
mk_success_1(
#[allow(deprecated)]
TransactionType::UpdateBakerStake,
if data.increased {
Event::BakerStakeIncreased {
Expand All @@ -491,6 +496,7 @@ impl From<super::BlockItemSummary> for BlockItemSummary {
)
} else {
(
#[allow(deprecated)]
Some(TransactionType::UpdateBakerStake),
BlockItemResult::Success { events: Vec::new() },
)
Expand All @@ -500,14 +506,17 @@ impl From<super::BlockItemSummary> for BlockItemSummary {
baker_id,
restake_earnings,
} => mk_success_1(
#[allow(deprecated)]
TransactionType::UpdateBakerRestakeEarnings,
Event::BakerSetRestakeEarnings {
baker_id,
account: sender,
restake_earnings,
},
),
super::AccountTransactionEffects::BakerKeysUpdated { data } => {
super::AccountTransactionEffects::BakerKeysUpdated { data } =>
{
#[allow(deprecated)]
mk_success_1(TransactionType::UpdateBakerKeys, Event::BakerKeysUpdated {
data,
})
Expand All @@ -516,6 +525,7 @@ impl From<super::BlockItemSummary> for BlockItemSummary {
removed,
added,
} => mk_success_2(
#[allow(deprecated)]
TransactionType::EncryptedAmountTransfer,
Event::EncryptedAmountsRemoved { data: removed },
Event::NewEncryptedAmount { data: added },
Expand All @@ -525,12 +535,15 @@ impl From<super::BlockItemSummary> for BlockItemSummary {
added,
memo,
} => mk_success_3(
#[allow(deprecated)]
TransactionType::EncryptedAmountTransferWithMemo,
Event::EncryptedAmountsRemoved { data: removed },
Event::NewEncryptedAmount { data: added },
Event::TransferMemo { memo },
),
super::AccountTransactionEffects::TransferredToEncrypted { data } => {
super::AccountTransactionEffects::TransferredToEncrypted { data } =>
{
#[allow(deprecated)]
mk_success_1(
TransactionType::TransferToEncrypted,
Event::EncryptedSelfAmountAdded { data },
Expand Down Expand Up @@ -899,6 +912,7 @@ fn convert_account_transaction(
_ => Err(ConversionError::InvalidTransactionResult),
}
}
#[allow(deprecated)]
TransactionType::AddBaker => {
let effects = with_singleton(events, |e| match e {
Event::BakerAdded { data } => {
Expand All @@ -908,6 +922,7 @@ fn convert_account_transaction(
})?;
mk_success(effects)
}
#[allow(deprecated)]
TransactionType::RemoveBaker => {
let effects = with_singleton(events, |e| match e {
Event::BakerRemoved {
Expand All @@ -918,6 +933,7 @@ fn convert_account_transaction(
})?;
mk_success(effects)
}
#[allow(deprecated)]
TransactionType::UpdateBakerStake => {
let effects = if events.is_empty() {
super::AccountTransactionEffects::BakerStakeUpdated { data: None }
Expand Down Expand Up @@ -950,6 +966,7 @@ fn convert_account_transaction(
};
mk_success(effects)
}
#[allow(deprecated)]
TransactionType::UpdateBakerRestakeEarnings => {
let effects = with_singleton(events, |e| match e {
Event::BakerSetRestakeEarnings {
Expand All @@ -966,6 +983,7 @@ fn convert_account_transaction(
})?;
mk_success(effects)
}
#[allow(deprecated)]
TransactionType::UpdateBakerKeys => {
let effects = with_singleton(events, |e| match e {
Event::BakerKeysUpdated { data } => {
Expand All @@ -984,6 +1002,7 @@ fn convert_account_transaction(
})?;
mk_success(effects)
}
#[allow(deprecated)]
TransactionType::EncryptedAmountTransfer => {
let events_arr: [_; 2] = events
.try_into()
Expand All @@ -1000,6 +1019,7 @@ fn convert_account_transaction(
_ => Err(ConversionError::InvalidTransactionResult),
}
}
#[allow(deprecated)]
TransactionType::EncryptedAmountTransferWithMemo => {
let events_arr: [_; 3] = events
.try_into()
Expand All @@ -1017,6 +1037,7 @@ fn convert_account_transaction(
_ => Err(ConversionError::InvalidTransactionResult),
}
}
#[allow(deprecated)]
TransactionType::TransferToEncrypted => {
let effects = with_singleton(events, |e| match e {
Event::EncryptedSelfAmountAdded { data } => {
Expand Down
Loading