Skip to content

Commit

Permalink
Merge branch 'tooling-dashboard/style-balance-box' into tooling-dashb…
Browse files Browse the repository at this point in the history
…oard/style-my-coins
  • Loading branch information
evavirseda authored Oct 29, 2024
2 parents b832e54 + ae85129 commit 51f0356
Show file tree
Hide file tree
Showing 121 changed files with 2,820 additions and 2,959 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 48 additions & 26 deletions apps/ui-kit/src/lib/components/organisms/dialog/Dialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import cx from 'classnames';
import * as React from 'react';
import { Close } from '@iota/ui-icons';
import { useEffect, useState } from 'react';
import { DialogPosition } from './dialog.enums';

const Dialog = RadixDialog.Root;
const DialogTrigger = RadixDialog.Trigger;
Expand Down Expand Up @@ -35,34 +36,55 @@ const DialogContent = React.forwardRef<
React.ComponentPropsWithoutRef<typeof RadixDialog.Content> & {
containerId?: string;
showCloseOnOverlay?: boolean;
position?: DialogPosition;
}
>(({ className, containerId, showCloseOnOverlay, children, ...props }, ref) => {
const [containerElement, setContainerElement] = useState<HTMLElement | undefined>(undefined);
>(
(
{
className,
containerId,
showCloseOnOverlay,
children,
position = DialogPosition.Center,
...props
},
ref,
) => {
const [containerElement, setContainerElement] = useState<HTMLElement | undefined>(
undefined,
);

useEffect(() => {
// This ensures document.getElementById is called in the client-side environment only.
// note. containerElement cant be null
const element = containerId ? document.getElementById(containerId) : undefined;
setContainerElement(element ?? undefined);
}, [containerId]);

return (
<RadixDialog.Portal container={containerElement}>
<DialogOverlay showCloseIcon={showCloseOnOverlay} />
<RadixDialog.Content
ref={ref}
className="absolute left-1/2 top-1/2 z-[99999] flex max-h-[60vh] w-80 max-w-[85vw] -translate-x-1/2 -translate-y-1/2 flex-col justify-center overflow-hidden rounded-xl bg-primary-100 dark:bg-neutral-6 md:w-96"
{...props}
>
<VisuallyHidden.Root>
<RadixDialog.Title />
<RadixDialog.Description />
</VisuallyHidden.Root>
{children}
</RadixDialog.Content>
</RadixDialog.Portal>
);
});
useEffect(() => {
// This ensures document.getElementById is called in the client-side environment only.
// note. containerElement cant be null
const element = containerId ? document.getElementById(containerId) : undefined;
setContainerElement(element ?? undefined);
}, [containerId]);
const positionClass =
position === DialogPosition.Right
? 'right-0 h-screen top-0 w-full max-w-[500px]'
: 'max-h-[60vh] left-1/2 top-1/2 -translate-x-1/2 -translate-y-1/2 rounded-xl w-80 max-w-[85vw]';
return (
<RadixDialog.Portal container={containerElement}>
<DialogOverlay showCloseIcon={showCloseOnOverlay} />
<RadixDialog.Content
ref={ref}
className={cx(
'absolute z-[99999] flex flex-col justify-center overflow-hidden bg-primary-100 dark:bg-neutral-6 md:w-96',
positionClass,
)}
{...props}
>
<VisuallyHidden.Root>
<RadixDialog.Title />
<RadixDialog.Description />
</VisuallyHidden.Root>
{children}
</RadixDialog.Content>
</RadixDialog.Portal>
);
},
);
DialogContent.displayName = RadixDialog.Content.displayName;

const DialogTitle = React.forwardRef<
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0

export enum DialogPosition {
Center = 'center',
Right = 'right',
}
1 change: 1 addition & 0 deletions apps/ui-kit/src/lib/components/organisms/dialog/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
// SPDX-License-Identifier: Apache-2.0

export * from './Dialog';
export * from './dialog.enums';
49 changes: 48 additions & 1 deletion apps/ui-kit/src/storybook/stories/organisms/Dialog.stories.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2024 IOTA Stiftung
// SPDX-License-Identifier: Apache-2.0
import { ButtonSize } from '@/lib/components';
import { ButtonSize, DialogPosition } from '@/lib/components';

import type { Meta, StoryObj } from '@storybook/react';

Expand Down Expand Up @@ -54,3 +54,50 @@ export default meta;
type Story = StoryObj<typeof meta>;

export const Default: Story = {};

export const RightDialog: Story = {
render: () => {
const [open, setOpen] = useState(false);
return (
<div className="flex">
<Button size={ButtonSize.Small} text="Open Dialog" onClick={() => setOpen(true)} />
<Dialog open={open} onOpenChange={setOpen}>
<DialogContent showCloseOnOverlay position={DialogPosition.Right}>
<div className="h-full w-full">
<Header
title="Connect Ledger Wallet"
titleCentered
onClose={() => setOpen(false)}
onBack={() => setOpen(false)}
/>
<div className="flex h-full w-full flex-col items-center justify-center">
<DialogBody>
<div className="flex flex-col items-center gap-2">
<div className="mt-4.5">Logo</div>
<div className="mt-4.5 break-words text-center">
Connect your ledger to your computer, unlock it, and
launch the IOTA app. Click Continue when done.
</div>
<div className="mt-4.5">
{' '}
Need more help? View tutorial.
</div>
</div>
</DialogBody>
<div className="flex w-full flex-row justify-center gap-2 px-md--rs pb-md--rs pt-sm--rs">
<Button
size={ButtonSize.Small}
type={ButtonType.Outlined}
text="Cancel"
onClick={() => setOpen(false)}
/>
<Button size={ButtonSize.Small} text="Connect" />
</div>
</div>
</div>
</DialogContent>
</Dialog>
</div>
);
},
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import { Settings } from '@iota/ui-icons';

export function TopNav() {
return (
<div className="flex h-[52px] w-full flex-row items-center justify-end gap-md py-xs--rs">
<div className="flex w-full flex-row items-center justify-end gap-md py-xs--rs">
<Badge label="Mainnet" type={BadgeType.PrimarySoft} />
<ConnectButton />
<ConnectButton size="md" />
<Button icon={<Settings />} type={ButtonType.Ghost} />
</div>
);
Expand Down
135 changes: 10 additions & 125 deletions crates/iota-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ use iota_types::{
CheckpointSummaryResponse, CheckpointTimestamp, ECMHLiveObjectSetDigest,
VerifiedCheckpoint,
},
messages_consensus::{AuthorityCapabilitiesV1, AuthorityCapabilitiesV2},
messages_consensus::AuthorityCapabilitiesV1,
messages_grpc::{
HandleTransactionResponse, LayoutGenerationOption, ObjectInfoRequest,
ObjectInfoRequestKind, ObjectInfoResponse, TransactionInfoRequest, TransactionInfoResponse,
Expand Down Expand Up @@ -4321,7 +4321,6 @@ impl AuthorityState {
Some(res)
}

// TODO: delete once authority_capabilities_v2 is deployed everywhere
/// Returns the new protocol version and system packages that the network
/// has voted to upgrade to. If the proposed protocol version is not
/// supported, None is returned.
Expand All @@ -4336,86 +4335,6 @@ impl AuthorityState {
buffer_stake_bps = 10000;
}

// For each validator, gather the protocol version and system packages that it
// would like to upgrade to in the next epoch.
let mut desired_upgrades: Vec<_> = capabilities
.into_iter()
.filter_map(|mut cap| {
// A validator that lists no packages is voting against any change at all.
if cap.available_system_packages.is_empty() {
return None;
}

cap.available_system_packages.sort();

info!(
"validator {:?} supports {:?} with system packages: {:?}",
cap.authority.concise(),
cap.supported_protocol_versions,
cap.available_system_packages,
);

// A validator that only supports the current protocol version is also voting
// against any change, because framework upgrades always require a protocol
// version bump.
cap.supported_protocol_versions
.is_version_supported(proposed_protocol_version)
.then_some((cap.available_system_packages, cap.authority))
})
.collect();

// There can only be one set of votes that have a majority, find one if it
// exists.
desired_upgrades.sort();
desired_upgrades
.into_iter()
.chunk_by(|(packages, _authority)| packages.clone())
.into_iter()
.find_map(|(packages, group)| {
// should have been filtered out earlier.
assert!(!packages.is_empty());

let mut stake_aggregator: StakeAggregator<(), true> =
StakeAggregator::new(Arc::new(committee.clone()));

for (_, authority) in group {
stake_aggregator.insert_generic(authority, ());
}

let total_votes = stake_aggregator.total_votes();
let quorum_threshold = committee.quorum_threshold();
let f = committee.total_votes() - committee.quorum_threshold();

// multiple by buffer_stake_bps / 10000, rounded up.
let buffer_stake = (f * buffer_stake_bps + 9999) / 10000;
let effective_threshold = quorum_threshold + buffer_stake;

info!(
?total_votes,
?quorum_threshold,
?buffer_stake_bps,
?effective_threshold,
?proposed_protocol_version,
?packages,
"support for upgrade"
);

let has_support = total_votes >= effective_threshold;
has_support.then_some((proposed_protocol_version, packages))
})
}

fn is_protocol_version_supported_v2(
proposed_protocol_version: ProtocolVersion,
committee: &Committee,
capabilities: Vec<AuthorityCapabilitiesV2>,
mut buffer_stake_bps: u64,
) -> Option<(ProtocolVersion, Vec<ObjectRef>)> {
if buffer_stake_bps > 10000 {
warn!("clamping buffer_stake_bps to 10000");
buffer_stake_bps = 10000;
}

// For each validator, gather the protocol version and system packages that it
// would like to upgrade to in the next epoch.
let mut desired_upgrades: Vec<_> = capabilities
Expand Down Expand Up @@ -4486,7 +4405,6 @@ impl AuthorityState {
})
}

// TODO: delete once authority_capabilities_v2 is deployed everywhere
/// Selects the highest supported protocol version and system packages that
/// the network has voted to upgrade to. If no upgrade is supported,
/// returns the current protocol version and system packages.
Expand All @@ -4499,32 +4417,10 @@ impl AuthorityState {
let mut next_protocol_version = current_protocol_version;
let mut system_packages = vec![];

while let Some((version, packages)) = Self::is_protocol_version_supported_v1(
next_protocol_version + 1,
committee,
capabilities.clone(),
buffer_stake_bps,
) {
next_protocol_version = version;
system_packages = packages;
}

(next_protocol_version, system_packages)
}

fn choose_protocol_version_and_system_packages_v2(
current_protocol_version: ProtocolVersion,
committee: &Committee,
capabilities: Vec<AuthorityCapabilitiesV2>,
buffer_stake_bps: u64,
) -> (ProtocolVersion, Vec<ObjectRef>) {
let mut next_protocol_version = current_protocol_version;
let mut system_packages = vec![];

// Finds the highest supported protocol version and system packages by
// incrementing the proposed protocol version by one until no further
// upgrades are supported.
while let Some((version, packages)) = Self::is_protocol_version_supported_v2(
while let Some((version, packages)) = Self::is_protocol_version_supported_v1(
next_protocol_version + 1,
committee,
capabilities.clone(),
Expand Down Expand Up @@ -4661,25 +4557,14 @@ impl AuthorityState {
let buffer_stake_bps = epoch_store.get_effective_buffer_stake_bps();

let (next_epoch_protocol_version, next_epoch_system_packages) =
if epoch_store.protocol_config().authority_capabilities_v2() {
Self::choose_protocol_version_and_system_packages_v2(
epoch_store.protocol_version(),
epoch_store.committee(),
epoch_store
.get_capabilities_v2()
.expect("read capabilities from db cannot fail"),
buffer_stake_bps,
)
} else {
Self::choose_protocol_version_and_system_packages_v1(
epoch_store.protocol_version(),
epoch_store.committee(),
epoch_store
.get_capabilities_v1()
.expect("read capabilities from db cannot fail"),
buffer_stake_bps,
)
};
Self::choose_protocol_version_and_system_packages_v1(
epoch_store.protocol_version(),
epoch_store.committee(),
epoch_store
.get_capabilities_v1()
.expect("read capabilities from db cannot fail"),
buffer_stake_bps,
);

// since system packages are created during the current epoch, they should abide
// by the rules of the current epoch, including the current epoch's max
Expand Down
Loading

0 comments on commit 51f0356

Please sign in to comment.