Skip to content

Commit

Permalink
Merge #1828
Browse files Browse the repository at this point in the history
1828: Fix #1353  Improve endorsement draws in api get_addresses endpoint r=yvan-sraka a=AureliaDolo



Co-authored-by: Aurelia <adolo@massa.network>
  • Loading branch information
bors[bot] and AureliaDolo authored Nov 23, 2021
2 parents 3e93f91 + 414b773 commit dba9fc4
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 6 deletions.
18 changes: 15 additions & 3 deletions api/src/public.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ use futures::{stream::FuturesUnordered, StreamExt};
use jsonrpc_core::BoxFuture;
use models::address::{AddressHashMap, AddressHashSet};
use models::api::{
APIConfig, AddressInfo, BlockInfo, BlockInfoContent, BlockSummary, EndorsementInfo, NodeStatus,
OperationInfo, TimeInterval,
APIConfig, AddressInfo, BlockInfo, BlockInfoContent, BlockSummary, EndorsementInfo,
IndexedSlot, NodeStatus, OperationInfo, TimeInterval,
};
use models::clique::Clique;
use models::crypto::PubkeySig;
Expand Down Expand Up @@ -415,7 +415,19 @@ impl Endpoints for API<Public> {
.filter(|(_, (ad, _))| *ad == address)
.map(|(slot, _)| *slot)
.collect(),
endorsement_draws: Default::default(), // TODO: update wait for !238
endorsement_draws: next_draws
.iter()
.map(|(slot, (_, addrs))| {
addrs.iter().enumerate().filter_map(|(index, ad)| {
if *ad == address {
Some(IndexedSlot { slot: *slot, index })
} else {
None
}
})
})
.flatten()
.collect(),
blocks_created: blocks.remove(&address).ok_or(ApiError::NotFound)?,
involved_in_endorsements: Default::default(), // TODO: update wait for !238
involved_in_operations: operations
Expand Down
18 changes: 15 additions & 3 deletions models/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ pub struct AddressInfo {
pub ledger_info: LedgerInfo,
pub rolls: RollsInfo,
pub block_draws: HashSet<Slot>,
pub endorsement_draws: HashMap<String, u64>, // u64 is the index
pub endorsement_draws: HashSet<IndexedSlot>,
pub blocks_created: BlockHashSet,
pub involved_in_endorsements: EndorsementHashSet,
pub involved_in_operations: OperationHashSet,
Expand All @@ -181,8 +181,7 @@ impl std::fmt::Display for AddressInfo {
"Endorsement draws: {}",
self.endorsement_draws
.iter()
.map(|(slot, idx)| format!(" {}: index {}", slot, idx))
.fold("\n".to_string(), |acc, s| format!("{}{}", acc, s))
.fold("\n".to_string(), |acc, s| format!("{} {}", acc, s))
)?;
writeln!(
f,
Expand Down Expand Up @@ -238,6 +237,19 @@ impl AddressInfo {
}
}

/// When an address is drawn to create an endorsement it is selected for a specific index
#[derive(Debug, Deserialize, Serialize, Hash, PartialEq, Eq)]
pub struct IndexedSlot {
pub slot: Slot,
pub index: usize,
}

impl std::fmt::Display for IndexedSlot {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
writeln!(f, "Slot: {}, Index: {}", self.slot, self.index)
}
}

pub struct CompactAddressInfo {
pub address: Address,
pub thread: u8,
Expand Down

0 comments on commit dba9fc4

Please sign in to comment.