Skip to content

Commit

Permalink
rename mined_at to proposed_height
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Jan 22, 2024
1 parent 806a8f1 commit f325479
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 25 deletions.
17 changes: 8 additions & 9 deletions dan_layer/consensus/src/hotstuff/on_propose.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,17 +190,16 @@ where TConsensusSpec: ConsensusSpec
let pending_proposals = ForeignProposal::get_all_pending(tx, locked_block.block_id(), parent_block.block_id())?;
let commands = ForeignProposal::get_all_new(tx)?
.into_iter()
.filter_map(|foreign_proposal| {
if pending_proposals.iter().any(|pending_proposal| {
.filter(|foreign_proposal| {
// If the foreign proposal is already pending, don't propose it again
!pending_proposals.iter().any(|pending_proposal| {
pending_proposal.bucket == foreign_proposal.bucket &&
pending_proposal.block_id == foreign_proposal.block_id
}) {
None
} else {
Some(Ok(Command::ForeignProposal(
foreign_proposal.set_mined_at(parent_block.height().saturating_add(NodeHeight(1))),
)))
}
})
})
.map(|mut foreign_proposal| {
foreign_proposal.set_proposed_height(parent_block.height().saturating_add(NodeHeight(1)));
Ok(Command::ForeignProposal(foreign_proposal))
})
.chain(batch.into_iter().map(|t| match t.current_stage() {
// If the transaction is New, propose to Prepare it
Expand Down
8 changes: 4 additions & 4 deletions dan_layer/p2p/src/conversions/consensus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ impl From<ForeignProposalState> for proto::consensus::ForeignProposalState {
fn from(value: ForeignProposalState) -> Self {
match value {
ForeignProposalState::New => proto::consensus::ForeignProposalState::New,
ForeignProposalState::Mined => proto::consensus::ForeignProposalState::Mined,
ForeignProposalState::Proposed => proto::consensus::ForeignProposalState::Mined,
ForeignProposalState::Deleted => proto::consensus::ForeignProposalState::Deleted,
}
}
Expand All @@ -375,7 +375,7 @@ impl TryFrom<proto::consensus::ForeignProposalState> for ForeignProposalState {
fn try_from(value: proto::consensus::ForeignProposalState) -> Result<Self, Self::Error> {
match value {
proto::consensus::ForeignProposalState::New => Ok(ForeignProposalState::New),
proto::consensus::ForeignProposalState::Mined => Ok(ForeignProposalState::Mined),
proto::consensus::ForeignProposalState::Mined => Ok(ForeignProposalState::Proposed),
proto::consensus::ForeignProposalState::Deleted => Ok(ForeignProposalState::Deleted),
proto::consensus::ForeignProposalState::UnknownState => Err(anyhow!("Foreign proposal state not provided")),
}
Expand All @@ -390,7 +390,7 @@ impl From<&ForeignProposal> for proto::consensus::ForeignProposal {
bucket: value.bucket.as_u32(),
block_id: value.block_id.as_bytes().to_vec(),
state: proto::consensus::ForeignProposalState::from(value.state).into(),
mined_at: value.mined_at.map(|a| a.0).unwrap_or(0),
mined_at: value.proposed_height.map(|a| a.0).unwrap_or(0),
}
}
}
Expand All @@ -405,7 +405,7 @@ impl TryFrom<proto::consensus::ForeignProposal> for ForeignProposal {
state: proto::consensus::ForeignProposalState::try_from(value.state)
.map_err(|_| anyhow!("Invalid foreign proposal state value {}", value.state))?
.try_into()?,
mined_at: if value.mined_at == 0 {
proposed_height: if value.mined_at == 0 {
None
} else {
Some(NodeHeight(value.mined_at))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- This file should undo anything in `up.sql`
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
ALTER TABLE foreign_proposals
RENAME COLUMN mined_at TO proposed_height;

UPDATE foreign_proposals
SET state = 'Proposed'
WHERE state = 'Mined';
3 changes: 2 additions & 1 deletion dan_layer/state_store_sqlite/src/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use tari_dan_storage::{
Decision,
Evidence,
ForeignProposal,
ForeignProposalState,
ForeignReceiveCounters,
ForeignSendCounters,
HighQc,
Expand Down Expand Up @@ -398,7 +399,7 @@ impl<TAddr: NodeAddressable + Serialize + DeserializeOwned> StateStoreReadTransa
use crate::schema::foreign_proposals;

let foreign_proposals = foreign_proposals::table
.filter(foreign_proposals::state.eq("New"))
.filter(foreign_proposals::state.eq(ForeignProposalState::New.to_string()))
.load::<sql_models::ForeignProposal>(self.connection())
.map_err(|e| SqliteStorageError::DieselError {
operation: "foreign_proposal_get_all",
Expand Down
2 changes: 1 addition & 1 deletion dan_layer/state_store_sqlite/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ diesel::table! {
bucket -> Integer,
block_id -> Text,
state -> Text,
mined_at -> Nullable<BigInt>,
proposed_height -> Nullable<BigInt>,
created_at -> Timestamp,
}
}
Expand Down
2 changes: 1 addition & 1 deletion dan_layer/state_store_sqlite/src/sql_models/bookkeeping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl TryFrom<ForeignProposal> for consensus_models::ForeignProposal {
bucket: Shard::from(value.bucket as u32),
block_id: deserialize_hex_try_from(&value.block_id)?,
state: parse_from_string(&value.state)?,
mined_at: value.mined_at.map(|mined_at| NodeHeight(mined_at as u64)),
proposed_height: value.mined_at.map(|mined_at| NodeHeight(mined_at as u64)),
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion dan_layer/state_store_sqlite/src/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ impl<TAddr: NodeAddressable> StateStoreWriteTransaction for SqliteStateStoreWrit
foreign_proposals::bucket.eq(foreign_proposal.bucket.as_u32() as i32),
foreign_proposals::block_id.eq(serialize_hex(foreign_proposal.block_id)),
foreign_proposals::state.eq(foreign_proposal.state.to_string()),
foreign_proposals::mined_at.eq(foreign_proposal.mined_at.map(|h| h.as_u64() as i64)),
foreign_proposals::proposed_height.eq(foreign_proposal.proposed_height.map(|h| h.as_u64() as i64)),
);

diesel::insert_into(foreign_proposals::table)
Expand Down
16 changes: 8 additions & 8 deletions dan_layer/storage/src/consensus_models/foreign_proposal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ use crate::{StateStoreReadTransaction, StateStoreWriteTransaction, StorageError}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize, PartialOrd, Ord)]
pub enum ForeignProposalState {
New,
Mined,
Proposed,
Deleted,
}

impl Display for ForeignProposalState {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
match self {
ForeignProposalState::New => write!(f, "New"),
ForeignProposalState::Mined => write!(f, "Mined"),
ForeignProposalState::Proposed => write!(f, "Proposed"),
ForeignProposalState::Deleted => write!(f, "Deleted"),
}
}
Expand All @@ -36,7 +36,7 @@ impl FromStr for ForeignProposalState {
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"New" => Ok(ForeignProposalState::New),
"Mined" => Ok(ForeignProposalState::Mined),
"Proposed" => Ok(ForeignProposalState::Proposed),
"Deleted" => Ok(ForeignProposalState::Deleted),
_ => Err(anyhow::anyhow!("Invalid foreign proposal state {}", s)),
}
Expand All @@ -48,7 +48,7 @@ pub struct ForeignProposal {
pub bucket: Shard,
pub block_id: BlockId,
pub state: ForeignProposalState,
pub mined_at: Option<NodeHeight>,
pub proposed_height: Option<NodeHeight>,
}

impl ForeignProposal {
Expand All @@ -57,13 +57,13 @@ impl ForeignProposal {
bucket,
block_id,
state: ForeignProposalState::New,
mined_at: None,
proposed_height: None,
}
}

pub fn set_mined_at(mut self, mined_at: NodeHeight) -> Self {
self.mined_at = Some(mined_at);
self.state = ForeignProposalState::Mined;
pub fn set_proposed_height(&mut self, mined_at: NodeHeight) -> &mut Self {
self.proposed_height = Some(mined_at);
self.state = ForeignProposalState::Proposed;
self
}
}
Expand Down

0 comments on commit f325479

Please sign in to comment.