Skip to content
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
69 changes: 48 additions & 21 deletions chain/src/services/namada.rs
Original file line number Diff line number Diff line change
Expand Up @@ -605,30 +605,57 @@ pub async fn query_all_votes(
client: &HttpClient,
proposals_ids: Vec<u64>,
) -> anyhow::Result<HashSet<GovernanceVote>> {
let votes: Vec<HashSet<GovernanceVote>> =
futures::stream::iter(proposals_ids)
.filter_map(|proposal_id| async move {
let votes = rpc::query_proposal_votes(client, proposal_id)
.await
.ok()?;
let votes = futures::stream::iter(proposals_ids)
.filter_map(|proposal_id| async move {
let votes =
rpc::query_proposal_votes(client, proposal_id).await.ok()?;

let votes = votes
.into_iter()
.map(|vote| GovernanceVote {
proposal_id,
vote: ProposalVoteKind::from(vote.data),
address: Id::from(vote.delegator),
})
.collect::<HashSet<_>>();

Some(votes)
})
.map(futures::future::ready)
.buffer_unordered(32)
.collect::<Vec<_>>()
.await;

let votes = votes
.into_iter()
.map(|vote| GovernanceVote {
proposal_id,
vote: ProposalVoteKind::from(vote.data),
address: Id::from(vote.delegator),
})
.collect::<HashSet<_>>();
let mut voter_count: HashMap<(Id, u64), u64> = HashMap::new();
for vote in votes.iter().flatten() {
*voter_count
.entry((vote.address.clone(), vote.proposal_id))
.or_insert(0) += 1;
}

Some(votes)
let mut seen_voters = HashSet::new();
anyhow::Ok(
votes
.iter()
.flatten()
.filter(|&vote| {
seen_voters.insert((vote.address.clone(), vote.proposal_id))
})
.map(futures::future::ready)
.buffer_unordered(32)
.collect::<Vec<_>>()
.await;

anyhow::Ok(votes.iter().flatten().cloned().collect())
.cloned()
.map(|mut vote| {
if let Some(count) =
voter_count.get(&(vote.address.clone(), vote.proposal_id))
{
if *count > 1_u64 {
vote.vote = ProposalVoteKind::Unknown;
}
vote
} else {
vote
}
})
.collect(),
)
}

pub async fn get_validator_set_at_epoch(
Expand Down
14 changes: 1 addition & 13 deletions orm/migrations/2024-12-10-110059_validator_states/down.sql
Original file line number Diff line number Diff line change
@@ -1,14 +1,2 @@
-- This file should undo anything in `up.sql`

-- Step 1: Rename the existing enum type
ALTER TYPE VALIDATOR_STATE RENAME TO VALIDATOR_STATE_OLD;

-- Step 2: Create the new enum type without the added values
CREATE TYPE VALIDATOR_STATE AS ENUM ('consensus', 'inactive', 'jailed', 'below_capacity', 'below_threshold', 'unknown');

-- Step 3: Update all columns to use the new enum type
ALTER TABLE validators ALTER COLUMN state TYPE VALIDATOR_STATE
USING state::text::VALIDATOR_STATE;

-- Step 4: Drop the old enum type
DROP TYPE VALIDATOR_STATE_OLD;
SELECT 1;
2 changes: 2 additions & 0 deletions orm/migrations/2025-01-13-115313_vote_unknown/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
SELECT 1;
2 changes: 2 additions & 0 deletions orm/migrations/2025-01-13-115313_vote_unknown/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Your SQL goes here
ALTER TYPE VOTE_KIND ADD VALUE 'unknown';
2 changes: 2 additions & 0 deletions orm/src/governance_votes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub enum GovernanceVoteKindDb {
Nay,
Yay,
Abstain,
Unknown,
}

impl From<ProposalVoteKind> for GovernanceVoteKindDb {
Expand All @@ -18,6 +19,7 @@ impl From<ProposalVoteKind> for GovernanceVoteKindDb {
ProposalVoteKind::Nay => Self::Nay,
ProposalVoteKind::Yay => Self::Yay,
ProposalVoteKind::Abstain => Self::Abstain,
ProposalVoteKind::Unknown => Self::Unknown,
}
}
}
Expand Down
1 change: 1 addition & 0 deletions shared/src/vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub enum ProposalVoteKind {
Nay,
Yay,
Abstain,
Unknown,
}

impl From<ProposalVote> for ProposalVoteKind {
Expand Down
2 changes: 1 addition & 1 deletion swagger.yml
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ components:
type: string
vote:
type: string
enum: [yay, nay, abstain]
enum: [yay, nay, abstain, unknown]
voterAddress:
type: string
Reward:
Expand Down
2 changes: 2 additions & 0 deletions webserver/src/response/governance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub enum VoteType {
Yay,
Nay,
Abstain,
Unknown,
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand Down Expand Up @@ -219,6 +220,7 @@ impl From<GovernanceProposalVoteDb> for ProposalVote {
GovernanceVoteKindDb::Nay => VoteType::Nay,
GovernanceVoteKindDb::Yay => VoteType::Yay,
GovernanceVoteKindDb::Abstain => VoteType::Abstain,
GovernanceVoteKindDb::Unknown => VoteType::Unknown,
},
voter_address: value.voter_address,
}
Expand Down
Loading