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

fix(consensus)!: optmise foreign pledging for output-only case #1244

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion applications/tari_swarm_daemon/webui/src/routes/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ function ExtraInfoVN({ name, url, addTxToPool, autoRefresh, state, horizontal }:
<div onClick={() => copyToClipboard(tx)}>{copied == tx ? "Copied" : shorten(tx)}</div>
<div style={{ color: known ? "green" : "red" }}><b>{known && "Yes" || "No"}</b></div>
<div>{abort_details || <i>unknown</i>}</div>
<div>{final_decision || <i>unknown</i>}</div>
<div>{("Abort" in final_decision) ? <>Abort ({final_decision.Abort})</> : <>Commit</>}</div>
</>
);
})}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,9 +273,9 @@ where TValidator: Validator<Transaction, Context = (), Error = TransactionValida
.await
.map_err(|_| MempoolError::ConsensusChannelClosed)?;

// If we received the message from our local shard group, we don't need to gossip it again on the topic
// (prevents Duplicate errors)
if sender_shard_group.map_or(true, |sg| sg != local_committee_shard.shard_group()) {
// If we received the message from gossip (sender_shard_group is Some), we don't need to gossip it again on
// the topic (prevents Duplicate errors)
if sender_shard_group.is_none() {
// This validator is involved, we to send the transaction to local replicas
if let Err(e) = self
.gossip
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
// USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import { IoExpandOutline } from "react-icons/io5";
import { useState } from "react";
import { ReactNode, useState } from "react";
import Dialog from "@mui/material/Dialog";
import IconButton from "@mui/material/IconButton";
import Typography from "@mui/material/Typography";
Expand All @@ -31,7 +31,13 @@ import { CodeBlock } from "./StyledComponents";
import useMediaQuery from "@mui/material/useMediaQuery";
import { useTheme } from "@mui/material/styles";

export default function CodeBlockExpand({ title, children }: any) {
interface Props {
title: string;
children?: ReactNode;
contentsWhenUnexpanded?: ReactNode;
}

export default function CodeBlockDialog({ title, children, contentsWhenUnexpanded = false }: Props) {
const [open, setOpen] = useState(false);
const theme = useTheme();
const matches = useMediaQuery(theme.breakpoints.down("md"));
Expand All @@ -46,12 +52,7 @@ export default function CodeBlockExpand({ title, children }: any) {

return (
<div>
<CodeBlock
style={{
position: "relative",
}}
>
{children}
{contentsWhenUnexpanded ? (
<IconButton
onClick={handleClickOpen}
style={{
Expand All @@ -60,9 +61,27 @@ export default function CodeBlockExpand({ title, children }: any) {
float: "right",
}}
>
{contentsWhenUnexpanded}
<IoExpandOutline style={{ height: 16, width: 16 }} />
</IconButton>
</CodeBlock>
) : (
<CodeBlock
style={{
position: "relative",
}}
>
{children}
<IconButton
onClick={handleClickOpen}
style={{
position: "sticky",
bottom: "0",
float: "right",
}}
>
<IoExpandOutline style={{ height: 16, width: 16 }} />
</IconButton>
</CodeBlock>)}
<Dialog fullScreen={matches} open={open} onClose={handleClose} maxWidth="xl" fullWidth>
<Box
style={{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import { Table, TableBody, TableCell, TableContainer, TableHead, TableRow } from
import StatusChip from "../../Components/StatusChip";
import type { TransactionAtom } from "@tari-project/typescript-bindings";
import { Link } from "react-router-dom";
import { renderJson } from "../../utils/helpers";
import CodeBlockDialog from "../../Components/CodeBlock";

function Transaction({ transaction }: { transaction: TransactionAtom }) {
const decision = typeof transaction.decision === "object" ? "Abort" : "Commit";
Expand All @@ -36,6 +38,11 @@ function Transaction({ transaction }: { transaction: TransactionAtom }) {
<TableCell>
<StatusChip status={decision} />
</TableCell>
<TableCell>
<CodeBlockDialog title="Evidence" contentsWhenUnexpanded={<></>}>
{renderJson(transaction.evidence)}
</CodeBlockDialog>
</TableCell>
<TableCell>{transaction.leader_fee?.fee}</TableCell>
<TableCell>{transaction.transaction_fee}</TableCell>
</TableRow>
Expand All @@ -50,6 +57,7 @@ export default function Transactions({ transactions }: { transactions: Transacti
<TableRow>
<TableCell>Transaction ID</TableCell>
<TableCell>Decision</TableCell>
<TableCell>Evidence</TableCell>
<TableCell>Leader fee</TableCell>
<TableCell>Transaction fee</TableCell>
</TableRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import CopyToClipboard from "../../Components/CopyToClipboard";
import { renderJson } from "../../utils/helpers";
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";
import KeyboardArrowUpIcon from "@mui/icons-material/KeyboardArrowUp";
import CodeBlockExpand from "../../Components/CodeBlock";
import CodeBlockDialog from "../../Components/CodeBlock";
import type { Event } from "@tari-project/typescript-bindings";

function RowData({ substate_id, template_address, topic, tx_hash, payload }: Event, index: number) {
Expand Down Expand Up @@ -67,7 +67,7 @@ function RowData({ substate_id, template_address, topic, tx_hash, payload }: Eve
<TableRow>
<DataTableCell style={{ paddingBottom: 0, paddingTop: 0 }} colSpan={5}>
<Collapse in={open} timeout="auto" unmountOnExit>
<CodeBlockExpand title="Payload">{renderJson(payload)}</CodeBlockExpand>
<CodeBlockDialog title="Payload">{renderJson(payload)}</CodeBlockDialog>
</Collapse>
</DataTableCell>
</TableRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { DataTableCell, AccordionIconButton } from "../../Components/StyledCompo
import { renderJson } from "../../utils/helpers";
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";
import KeyboardArrowUpIcon from "@mui/icons-material/KeyboardArrowUp";
import CodeBlockExpand from "../../Components/CodeBlock";
import CodeBlockDialog from "../../Components/CodeBlock";
import type { Instruction } from "@tari-project/typescript-bindings";

function RowData({ title, data, index }: { title: string; data: Instruction; index: number }) {
Expand All @@ -51,7 +51,7 @@ function RowData({ title, data, index }: { title: string; data: Instruction; ind
<TableRow key={`${index}-2`}>
<DataTableCell style={{ paddingBottom: 0, paddingTop: 0 }} colSpan={2}>
<Collapse in={open} timeout="auto" unmountOnExit>
<CodeBlockExpand title={title}>{renderJson(data)}</CodeBlockExpand>
<CodeBlockDialog title={title}>{renderJson(data)}</CodeBlockDialog>
</Collapse>
</DataTableCell>
</TableRow>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import { DataTableCell, AccordionIconButton } from "../../Components/StyledCompo
import { renderJson } from "../../utils/helpers";
import KeyboardArrowDownIcon from "@mui/icons-material/KeyboardArrowDown";
import KeyboardArrowUpIcon from "@mui/icons-material/KeyboardArrowUp";
import CodeBlockExpand from "../../Components/CodeBlock";
import CodeBlockDialog from "../../Components/CodeBlock";
import type { Instruction } from "@tari-project/typescript-bindings";

function RowData({ title, data }: { title: string; data: Instruction }, index: number) {
Expand All @@ -51,7 +51,7 @@ function RowData({ title, data }: { title: string; data: Instruction }, index: n
<TableRow key={`${index}-2`}>
<DataTableCell style={{ paddingBottom: 0, paddingTop: 0 }} colSpan={2}>
<Collapse in={open} timeout="auto" unmountOnExit>
<CodeBlockExpand title={title}>{renderJson(data)}</CodeBlockExpand>
<CodeBlockDialog title={title}>{renderJson(data)}</CodeBlockDialog>
</Collapse>
</DataTableCell>
</TableRow>
Expand Down
21 changes: 13 additions & 8 deletions applications/tari_validator_node_web_ui/src/utils/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ import { toHexString } from "../routes/VN/Components/helpers";
import type { ShardGroup, SubstateId } from "@tari-project/typescript-bindings";

export const renderJson = (json: any) => {
if (!json) {
return <span>Null</span>;
}
if (Array.isArray(json)) {

if (json && Array.isArray(json)) {
//eslint-disable-next-line eqeqeq
if (json.length == 32) {
return <span className="string">"{toHexString(json)}"</span>;
Expand All @@ -43,7 +41,12 @@ export const renderJson = (json: any) => {
],
</>
);
} else if (typeof json === "object") {
}

if (typeof json === "object") {
if (!json) {
return <span>null</span>;
}
return (
<>
{"{"}
Expand All @@ -57,10 +60,12 @@ export const renderJson = (json: any) => {
{"}"}
</>
);
} else {
if (typeof json === "string") return <span className="string">"{json}"</span>;
return <span className="other">{json}</span>;
}

if (typeof json === "string") return <span className="string">"{json}"</span>;
if (typeof json === "number") return <span className="number">"{json}"</span>;
if (typeof json === "boolean") return <span className="boolean">{json ? "true" : "false"}</span>;
return <span className="other">{json}</span>;
};

export function fromHexString(hexString: string) {
Expand Down
10 changes: 9 additions & 1 deletion dan_layer/common_types/src/committee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use serde::{Deserialize, Serialize};
use tari_common_types::types::PublicKey;
use tari_engine_types::substate::SubstateId;

use crate::{NumPreshards, ShardGroup, SubstateAddress};
use crate::{Epoch, NumPreshards, ShardGroup, SubstateAddress};

#[derive(Debug, Clone, PartialEq, Eq, Serialize, Default, Hash)]
#[cfg_attr(
Expand Down Expand Up @@ -180,6 +180,7 @@ pub struct CommitteeInfo {
num_shard_group_members: u32,
num_committees: u32,
shard_group: ShardGroup,
epoch: Epoch,
}

impl CommitteeInfo {
Expand All @@ -188,15 +189,22 @@ impl CommitteeInfo {
num_shard_group_members: u32,
num_committees: u32,
shard_group: ShardGroup,
epoch: Epoch,
) -> Self {
Self {
num_shards,
num_shard_group_members,
num_committees,
shard_group,
epoch,
}
}

/// Returns the epoch of this CommitteeInfo.
pub fn epoch(&self) -> Epoch {
self.epoch
}

/// Returns $n - f$ (i.e $2f + 1$) where n is the number of committee members and f is the tolerated failure nodes.
pub fn quorum_threshold(&self) -> u32 {
self.num_shard_group_members - self.max_failures()
Expand Down
3 changes: 3 additions & 0 deletions dan_layer/consensus/src/hotstuff/block_change_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,9 @@ impl ProposedBlockChangeSet {
}

pub fn log_everything(&self) {
if !log_enabled!(log::Level::Debug) {
return;
}
const LOG_TARGET: &str = "tari::dan::consensus::block_change_set::debug";
debug!(target: LOG_TARGET, "❌ No vote: {}", self.no_vote_reason.display());
let _timer = TraceTimer::debug(LOG_TARGET, "ProposedBlockChangeSet::save_for_debug");
Expand Down
21 changes: 16 additions & 5 deletions dan_layer/consensus/src/hotstuff/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,13 @@ pub enum HotStuffError {
#[error("Substate store error: {0}")]
SubstateStoreError(#[from] SubstateStoreError),
#[error(
"Validator node omitted transaction pledges: remote_block_id={foreign_block_id}, \
transaction_id={transaction_id}"
"Validator node omitted transaction pledges: remote_block={foreign_block}, transaction_id={transaction_id}, \
is_prepare_phase={is_prepare_phase}"
)]
ForeignNodeOmittedTransactionPledges {
foreign_block_id: BlockId,
foreign_block: LeafBlock,
transaction_id: TransactionId,
is_prepare_phase: bool,
},
#[error("Block building error: {0}")]
BlockBuildingError(#[from] BlockError),
Expand Down Expand Up @@ -233,15 +234,25 @@ pub enum ProposalValidationError {
#[error("Foreign node in {shard_group} submitted malformed BlockPledge for block {block_id}")]
ForeignMalformedPledges { block_id: BlockId, shard_group: ShardGroup },
#[error(
"Foreign node in {shard_group} submitted invalid pledge for block {block_id}, transaction {transaction_id}: \
"Foreign node in {shard_group} submitted invalid pledge for block {block}, transaction {transaction_id}: \
{details}"
)]
ForeignInvalidPledge {
block_id: BlockId,
block: LeafBlock,
transaction_id: TransactionId,
shard_group: ShardGroup,
details: String,
},
#[error(
"Foreign node in {shard_group} submitted invalid epoch for block {block_id}. Current epoch: {current_epoch}, \
block epoch: {block_epoch}"
)]
ForeignInvalidEpoch {
block_id: BlockId,
shard_group: ShardGroup,
current_epoch: Epoch,
block_epoch: Epoch,
},
#[error(
"Foreign node in {shard_group} submitted proposal {block_id} but justify QC justifies {justify_qc_block_id}"
)]
Expand Down
Loading
Loading