diff --git a/applications/tari_dan_wallet_web_ui/src/routes/Transactions/TransactionDetails.tsx b/applications/tari_dan_wallet_web_ui/src/routes/Transactions/TransactionDetails.tsx index 4e9e391cd..3436fad54 100644 --- a/applications/tari_dan_wallet_web_ui/src/routes/Transactions/TransactionDetails.tsx +++ b/applications/tari_dan_wallet_web_ui/src/routes/Transactions/TransactionDetails.tsx @@ -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") { diff --git a/applications/tari_dan_wallet_web_ui/src/utils/json_rpc.tsx b/applications/tari_dan_wallet_web_ui/src/utils/json_rpc.tsx index 3ffb1710c..a48e40a7d 100644 --- a/applications/tari_dan_wallet_web_ui/src/utils/json_rpc.tsx +++ b/applications/tari_dan_wallet_web_ui/src/utils/json_rpc.tsx @@ -83,7 +83,12 @@ import { AccountGetDefaultRequest, TemplatesGetRequest, WalletDaemonClient } fro let clientInstance: WalletDaemonClient | null = null; let pendingClientInstance: Promise | 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 { try { diff --git a/applications/tari_validator_node_web_ui/src/routes/Blocks/BlockDetails.tsx b/applications/tari_validator_node_web_ui/src/routes/Blocks/BlockDetails.tsx index 2c2b46e61..84158c892 100644 --- a/applications/tari_validator_node_web_ui/src/routes/Blocks/BlockDetails.tsx +++ b/applications/tari_validator_node_web_ui/src/routes/Blocks/BlockDetails.tsx @@ -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([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(); const [block, setBlock] = useState(); + + const [blockData, setBlockData] = useState<{ [key: string]: TransactionAtom[] }>({}); + const [localOnly, setLocalOnly] = useState([]); const [prepare, setPrepare] = useState([]); const [localPrepared, setLocalPrepared] = useState([]); @@ -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)}`); @@ -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 = () => { @@ -228,9 +258,29 @@ export default function BlockDetails() { )} + {COMMANDS.map((cmd, i) => { + if (!blockData[cmd]) { + return <> ; + } + return ( + + + {cmd} + + + + + + ); + })} {epochEvents.length > 0 && ( - - + + EpochEvent @@ -238,46 +288,6 @@ export default function BlockDetails() { )} - {localOnly.length > 0 && ( - - - LocalOnly - - - - - - )} - {prepare.length > 0 && ( - - - Prepare - - - - - - )} - {localPrepared.length > 0 && ( - - - Local prepared - - - - - - )} - {accept.length > 0 && ( - - - Accept - - - - - - )} )} diff --git a/dan_layer/consensus/src/hotstuff/substate_store/error.rs b/dan_layer/consensus/src/hotstuff/substate_store/error.rs index bc7d1506d..5950f7b78 100644 --- a/dan_layer/consensus/src/hotstuff/substate_store/error.rs +++ b/dan_layer/consensus/src/hotstuff/substate_store/error.rs @@ -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, diff --git a/dan_layer/storage_sqlite/tests/global_db.rs b/dan_layer/storage_sqlite/tests/global_db.rs index 9aa27f5d1..bd12cb7c3 100644 --- a/dan_layer/storage_sqlite/tests/global_db.rs +++ b/dan_layer/storage_sqlite/tests/global_db.rs @@ -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}; @@ -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( @@ -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);