Skip to content

Commit

Permalink
Merge pull request #202 from Concordium/cooldown-events
Browse files Browse the repository at this point in the history
Support events when transationing directly between baker and delegator
  • Loading branch information
td202 authored Aug 16, 2024
2 parents 432dbff + b1d3844 commit a7a92b2
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
and `baker_stake_pending_change` fields are moved into a new type, `ActiveBakerPoolStatus`. A new field is added
to `BakerPoolStatus` which includes these fields, namely `active_baker_pool_status: Option<ActiveBakerPoolStatus>`.
This field is `Some(..)` iff `pool_info` is included in the node's `PoolInfoResponse`.
- `DelegationEvent` adds a `BakerRemoved` case, as `ConfigureDelegation` can replace a
baker with delegation from protocol 7.
- `BakerEvent` adds a `DelegationRemove` case, as `ConfigureBaker` can replace a delegator
with a baker from protocol 7.

## 4.3.0

Expand Down
15 changes: 15 additions & 0 deletions src/types/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2031,6 +2031,13 @@ pub enum DelegationEvent {
/// Delegator's id
delegator_id: DelegatorId,
},
BakerRemoved {
/// The id of the baker that was removed. If the account is a baker in
/// the current payday, it will remain so until the next payday,
/// although the baker record will be removed from the account
/// immediately.
baker_id: BakerId,
},
}

/// Events that may result from the [TransactionType::ConfigureBaker]
Expand Down Expand Up @@ -2095,6 +2102,14 @@ pub enum BakerEvent {
/// The finalization reward commission
finalization_reward_commission: AmountFraction,
},
/// Removed an existing delegator
DelegationRemoved {
/// The id of the delegator that was removed. If the account is a
/// delegator in the current payday, it will remain so until the
/// next payday, although the delegation record will be removed
/// from the account immediately.
delegator_id: DelegatorId,
},
}

#[derive(Debug, Clone)]
Expand Down
20 changes: 20 additions & 0 deletions src/types/summary_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,12 @@ impl From<super::BlockItemSummary> for BlockItemSummary {
super::BakerEvent::BakerKeysUpdated { data } => {
Event::BakerKeysUpdated { data }
}
super::BakerEvent::DelegationRemoved { delegator_id } => {
Event::DelegationRemoved {
delegator_id,
account: sender,
}
}
})
.collect();
(Some(ty), BlockItemResult::Success { events })
Expand Down Expand Up @@ -740,6 +746,12 @@ impl From<super::BlockItemSummary> for BlockItemSummary {
account: sender,
}
}
super::DelegationEvent::BakerRemoved { baker_id } => {
Event::BakerRemoved {
baker_id,
account: sender,
}
}
})
.collect();
(Some(ty), BlockItemResult::Success { events })
Expand Down Expand Up @@ -1187,6 +1199,10 @@ fn convert_account_transaction(
baker_id,
finalization_reward_commission,
}),
Event::DelegationRemoved {
delegator_id,
account: _,
} => Ok(super::BakerEvent::DelegationRemoved { delegator_id }),
_ => Err(ConversionError::InvalidTransactionResult),
})
.collect::<Result<_, ConversionError>>()?;
Expand Down Expand Up @@ -1236,6 +1252,10 @@ fn convert_account_transaction(
delegator_id,
account: _,
} => Ok(super::DelegationEvent::DelegationRemoved { delegator_id }),
Event::BakerRemoved {
baker_id,
account: _,
} => Ok(super::DelegationEvent::BakerRemoved { baker_id }),
_ => Err(ConversionError::InvalidTransactionResult),
})
.collect::<Result<_, ConversionError>>()?;
Expand Down
6 changes: 6 additions & 0 deletions src/v2/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1857,6 +1857,9 @@ impl TryFrom<DelegationEvent> for super::types::DelegationEvent {
delegation_event::Event::DelegationRemoved(v) => Self::DelegationRemoved {
delegator_id: v.try_into()?,
},
delegation_event::Event::BakerRemoved(v) => Self::BakerRemoved {
baker_id: v.baker_id.require()?.into(),
},
})
}
}
Expand Down Expand Up @@ -1935,6 +1938,9 @@ impl TryFrom<BakerEvent> for super::types::BakerEvent {
.into(),
}
}
baker_event::Event::DelegationRemoved(v) => Self::DelegationRemoved {
delegator_id: v.delegator_id.require()?.try_into()?,
},
})
}
}
Expand Down
25 changes: 23 additions & 2 deletions src/v2/generated/concordium.v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,7 @@ pub struct RegisteredData {
pub struct BakerEvent {
#[prost(
oneof = "baker_event::Event",
tags = "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11"
tags = "1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12"
)]
pub event: ::core::option::Option<baker_event::Event>,
}
Expand Down Expand Up @@ -1776,6 +1776,14 @@ pub mod baker_event {
#[prost(message, optional, tag = "2")]
pub finalization_reward_commission: ::core::option::Option<super::AmountFraction>,
}
/// Removed an existing delegator.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct DelegationRemoved {
/// Delegator's id.
#[prost(message, optional, tag = "1")]
pub delegator_id: ::core::option::Option<super::DelegatorId>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum Event {
Expand Down Expand Up @@ -1812,6 +1820,9 @@ pub mod baker_event {
/// The baker's finalization reward commission was updated.
#[prost(message, tag = "11")]
BakerSetFinalizationRewardCommission(BakerSetFinalizationRewardCommission),
/// An existing delegator was removed.
#[prost(message, tag = "12")]
DelegationRemoved(DelegationRemoved),
}
}
/// The identifier for a delegator.
Expand All @@ -1824,7 +1835,7 @@ pub struct DelegatorId {
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct DelegationEvent {
#[prost(oneof = "delegation_event::Event", tags = "1, 2, 3, 4, 5, 6")]
#[prost(oneof = "delegation_event::Event", tags = "1, 2, 3, 4, 5, 6, 7")]
pub event: ::core::option::Option<delegation_event::Event>,
}
/// Nested message and enum types in `DelegationEvent`.
Expand Down Expand Up @@ -1870,6 +1881,13 @@ pub mod delegation_event {
pub delegation_target: ::core::option::Option<super::DelegationTarget>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct BakerRemoved {
/// Baker's id
#[prost(message, optional, tag = "1")]
pub baker_id: ::core::option::Option<super::BakerId>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Oneof)]
pub enum Event {
/// The delegator's stake increased.
Expand All @@ -1890,6 +1908,9 @@ pub mod delegation_event {
/// A delegator was removed.
#[prost(message, tag = "6")]
DelegationRemoved(super::DelegatorId),
/// An existing baker was removed.
#[prost(message, tag = "7")]
BakerRemoved(BakerRemoved),
}
}
/// Effects of an account transaction. All variants except `None`
Expand Down
2 changes: 1 addition & 1 deletion src/v2/proto_schema_version.rs
Original file line number Diff line number Diff line change
@@ -1 +1 @@
pub const PROTO_SCHEMA_VERSION: &str = "7f9899b3a27fc2b0132a058a46f953e13d59f739";
pub const PROTO_SCHEMA_VERSION: &str = "066a8514c1e89bbaa7989c708ae737fc466b0737";

0 comments on commit a7a92b2

Please sign in to comment.