Skip to content

Commit

Permalink
web ui fixes, test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sdbondi committed Aug 19, 2024
1 parent a0c46ce commit 221b7b1
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 81 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,23 +122,11 @@ export default function TransactionDetails() {
} else {
reason = txResult.Reject;
}
const getReasonString = (x: RejectReason): string => {
if (typeof x === "string") {
return x;
} else if ("ShardsNotPledged" in x) {
return `ShardsNotPledged: ${x["ShardsNotPledged"]}`;
} else if ("ExecutionFailure" in x) {
return `ExecutionFailure: ${x["ExecutionFailure"]}`;
} else if ("ShardPledgedToAnotherPayload" in x) {
return `ShardPledgedToAnotherPayload: ${x["ShardPledgedToAnotherPayload"]}`;
} else if ("ShardRejected" in x) {
return `ShardRejected: ${x["ShardRejected"]}`;
} else if ("FeesNotPaid" in x) {
return `FeesNotPaid: ${x["FeesNotPaid"]}`;
}
return "Unknown reason";
};
return getReasonString(reason);
if (typeof reason === "string") {
return reason;
} else {
return JSON.stringify(reason);
}
};

if (data.status === "Rejected" || data.status === "InvalidTransaction") {
Expand Down
7 changes: 6 additions & 1 deletion applications/tari_dan_wallet_web_ui/src/utils/json_rpc.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,12 @@ import { AccountGetDefaultRequest, TemplatesGetRequest, WalletDaemonClient } fro
let clientInstance: WalletDaemonClient | null = null;
let pendingClientInstance: Promise<WalletDaemonClient> | null = null;
let outerAddress: URL | null = null;
const DEFAULT_WALLET_ADDRESS = new URL(import.meta.env.VITE_DAEMON_JRPC_ADDRESS || "http://localhost:9000");
const DEFAULT_WALLET_ADDRESS = new URL(
import.meta.env.VITE_DAEMON_JRPC_ADDRESS ||
import.meta.env.VITE_JSON_RPC_ADDRESS ||
import.meta.env.VITE_JRPC_ADDRESS ||
"http://localhost:9000",
);

export async function getClientAddress(): Promise<URL> {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,28 @@ import Loading from "../../Components/Loading";
import { getBlock, getIdentity } from "../../utils/json_rpc";
import Transactions from "./Transactions";
import { primitiveDateTimeToDate, primitiveDateTimeToSecs } from "../../utils/helpers";
import type { Block, TransactionAtom } from "@tari-project/typescript-bindings";
import type { Block, Command, TransactionAtom } from "@tari-project/typescript-bindings";
import type { VNGetIdentityResponse } from "@tari-project/typescript-bindings";

// TODO: refactor this component
const COMMANDS = [
"LocalOnly",
"Prepare",
"LocalPrepare",
"AllPrepare",
"SomePrepare",
"LocalAccept",
"AllAccept",
"SomeAccept",
];
export default function BlockDetails() {
const { blockId } = useParams();
const [expandedPanels, setExpandedPanels] = useState<string[]>([]);
const [loading, setLoading] = useState<boolean>(true);
const [error, setError] = useState<String>();
const [block, setBlock] = useState<Block>();

const [blockData, setBlockData] = useState<{ [key: string]: TransactionAtom[] }>({});

const [localOnly, setLocalOnly] = useState<TransactionAtom[]>([]);
const [prepare, setPrepare] = useState<TransactionAtom[]>([]);
const [localPrepared, setLocalPrepared] = useState<TransactionAtom[]>([]);
Expand Down Expand Up @@ -72,25 +84,35 @@ export default function BlockDetails() {
setLocalPrepared([]);
setAccept([]);
setEpochEvents([]);
const data: { [key: string]: TransactionAtom[] } = {};
for (let command of resp.block.commands) {
if (typeof command === "object") {
if ("LocalOnly" in command) {
let newLocalOnly = command.LocalOnly;
setLocalOnly((localOnly: TransactionAtom[]) => [...localOnly, newLocalOnly]);
} else if ("Prepare" in command) {
let newPrepare = command.Prepare;
setPrepare((prepare: TransactionAtom[]) => [...prepare, newPrepare]);
} else if ("LocalPrepare" in command) {
let newLocalPrepared = command.LocalPrepare;
setLocalPrepared((localPrepared: TransactionAtom[]) => [...localPrepared, newLocalPrepared]);
} else if ("AllAccept" in command) {
let newAccept = command.AllAccept;
setAccept((accept: TransactionAtom[]) => [...accept, newAccept]);
}
let cmd = Object.keys(command)[0];
data[cmd] ||= [];
data[cmd].push(command[cmd as keyof Command]);

// if ("LocalOnly" in command) {
// let newLocalOnly = command.LocalOnly;
// data["LocalOnly"] ||= [];
// data["LocalOnly"].push(newLocalOnly);
// } else if ("Prepare" in command) {
// let newPrepare = command.Prepare;
// data["Prepare"] ||= [];
// data["Prepare"].push(newPrepare);
// } else if ("LocalPrepare" in command) {
// let newLocalPrepared = command.LocalPrepare;
// data["LocalPrepare"] ||= [];
// data["LocalPrepare"].push(newLocalPrepared);
// } else if ("AllAccept" in command) {
// let newAccept = command.AllAccept;
// setAccept((accept: TransactionAtom[]) => [...accept, newAccept]);
// }
} else {
setEpochEvents((epochEvents: string[]) => [...epochEvents, command as string]);
}
}

setBlockData(data);
})
.catch((err) => {
setError(err && err.message ? err.message : `Unknown error: ${JSON.stringify(err)}`);
Expand All @@ -112,7 +134,15 @@ export default function BlockDetails() {
};

const expandAll = () => {
setExpandedPanels(["panel1", "panel2", "panel3", "panel4", "panel5"]);
for (let cmd in COMMANDS) {
setExpandedPanels((prevExpandedPanels: string[]) => {
if (!prevExpandedPanels.includes(`panel${cmd}`)) {
return [...prevExpandedPanels, `panel${cmd}`];
} else {
return prevExpandedPanels;
}
});
}
};

const collapseAll = () => {
Expand Down Expand Up @@ -228,56 +258,36 @@ export default function BlockDetails() {
</div>
</>
)}
{COMMANDS.map((cmd, i) => {
if (!blockData[cmd]) {
return <> </>;
}
return (
<Accordion
key={i}
expanded={expandedPanels.includes(`panel${cmd}`)}
onChange={handleChange(`panel${cmd}`)}
>
<AccordionSummary aria-controls={`panel${cmd}bh-content`} id={`panel${cmd}bh-header`}>
<Typography>{cmd}</Typography>
</AccordionSummary>
<AccordionDetails>
<Transactions transactions={blockData[cmd]} />
</AccordionDetails>
</Accordion>
);
})}
{epochEvents.length > 0 && (
<Accordion expanded={expandedPanels.includes("panel1")} onChange={handleChange("panel1")}>
<AccordionSummary aria-controls="panel1bh-content" id="panel1bh-header">
<Accordion expanded={expandedPanels.includes("panelEpochEvents")}
onChange={handleChange("panelEpochEvents")}>
<AccordionSummary aria-controls="panelEpochEventsbh-content" id="panelEpochEventsbh-header">
<Typography>EpochEvent</Typography>
</AccordionSummary>
<AccordionDetails>
<ul>{epochEvents.map((evt, i) => <li key={i}>{evt}</li>)}</ul>
</AccordionDetails>
</Accordion>
)}
{localOnly.length > 0 && (
<Accordion expanded={expandedPanels.includes("panel2")} onChange={handleChange("panel2")}>
<AccordionSummary aria-controls="panel2bh-content" id="panel2bh-header">
<Typography>LocalOnly</Typography>
</AccordionSummary>
<AccordionDetails>
<Transactions transactions={localOnly} />
</AccordionDetails>
</Accordion>
)}
{prepare.length > 0 && (
<Accordion expanded={expandedPanels.includes("panel3")} onChange={handleChange("panel3")}>
<AccordionSummary aria-controls="panel3bh-content" id="panel3bh-header">
<Typography>Prepare</Typography>
</AccordionSummary>
<AccordionDetails>
<Transactions transactions={prepare} />
</AccordionDetails>
</Accordion>
)}
{localPrepared.length > 0 && (
<Accordion expanded={expandedPanels.includes("panel4")} onChange={handleChange("panel4")}>
<AccordionSummary aria-controls="panel4bh-content" id="panel4bh-header">
<Typography>Local prepared</Typography>
</AccordionSummary>
<AccordionDetails>
<Transactions transactions={localPrepared} />
</AccordionDetails>
</Accordion>
)}
{accept.length > 0 && (
<Accordion expanded={expandedPanels.includes("panel5")} onChange={handleChange("panel5")}>
<AccordionSummary aria-controls="panel5bh-content" id="panel5bh-header">
<Typography>Accept</Typography>
</AccordionSummary>
<AccordionDetails>
<Transactions transactions={accept} />
</AccordionDetails>
</Accordion>
)}
</div>
</Fade>
)}
Expand Down
3 changes: 1 addition & 2 deletions dan_layer/consensus/src/hotstuff/substate_store/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ pub enum SubstateStoreError {
#[error("Expected substate {id} to be DOWN but it was UP")]
ExpectedSubstateDown { id: VersionedSubstateId },
#[error(
"Failed to lock substate {substate_id} with flag {requested_lock} due to conflict with existing \
{existing_lock} lock"
"Failed to {requested_lock} lock substate {substate_id} due to conflict with existing {existing_lock} lock"
)]
LockConflict {
substate_id: VersionedSubstateId,
Expand Down
7 changes: 4 additions & 3 deletions dan_layer/storage_sqlite/tests/global_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

use diesel::{Connection, SqliteConnection};
use rand::rngs::OsRng;
use tari_common_types::types::PublicKey;
use tari_common_types::types::{FixedHash, PublicKey};
use tari_crypto::keys::PublicKey as _;
use tari_dan_common_types::{shard::Shard, Epoch, PeerAddress, ShardGroup, SubstateAddress};
use tari_dan_storage::global::{GlobalDb, ValidatorNodeDb};
Expand All @@ -24,7 +24,8 @@ fn new_public_key() -> PublicKey {
}

fn derived_substate_address(public_key: &PublicKey) -> SubstateAddress {
SubstateAddress::from_bytes(public_key.as_bytes()).unwrap()
let hash = FixedHash::try_from(public_key.as_bytes()).unwrap();
SubstateAddress::from_hash_and_version(hash, 0)
}

fn insert_vns(
Expand Down Expand Up @@ -88,7 +89,7 @@ fn insert_and_get_within_epoch() {
}

#[test]
fn change_committee_bucket() {
fn change_committee_shard_group() {
let db = create_db();
let mut tx = db.create_transaction().unwrap();
let mut validator_nodes = db.validator_nodes(&mut tx);
Expand Down

0 comments on commit 221b7b1

Please sign in to comment.