Skip to content

Commit

Permalink
Merge pull request #1580 from Phala-Network/prb-v3.2
Browse files Browse the repository at this point in the history
prb v3.2
  • Loading branch information
nanometerzhu authored May 31, 2024
2 parents 99e7a2c + 8ec772e commit ff9d2f6
Show file tree
Hide file tree
Showing 29 changed files with 3,701 additions and 2,337 deletions.
61 changes: 40 additions & 21 deletions Cargo.lock

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

12 changes: 12 additions & 0 deletions crates/phaxt/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,18 @@ impl<'a, T: Config> ExtraRpcClient<'a, T> {
pub async fn system_sync_state(&self) -> Result<SyncState, Error> {
self.client.request("system_syncState", rpc_params![]).await
}

/// Fetch next nonce for an Account
///
/// Return account nonce adjusted for extrinsics currently in transaction pool
pub async fn system_account_next_index(&self, account_id: &T::AccountId) -> Result<u64, Error>
where
T::AccountId: Serialize,
{
self.client
.request("system_accountNextIndex", rpc_params![&account_id])
.await
}
}

impl<'a, T: Config> ExtraRpcClient<'a, T>
Expand Down
2 changes: 1 addition & 1 deletion frontend/apps/prb3-monitor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"next": "13.3.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-icons": "^4.8.0",
"react-icons": "^5.0.1",
"styletron-engine-atomic": "^1.5.0",
"styletron-react": "^6.1.0",
"swr": "^2.1.4",
Expand Down
2 changes: 1 addition & 1 deletion frontend/apps/prb3-monitor/src/pages/status/tx.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ export default function WorkerStatusPage() {
<div className={css({height: '100%', margin: '0 20px 20px'})}>
<StatefulDataTable
initialSortIndex={0}
initialSortDirection="ASC"
initialSortDirection="DESC"
resizableColumnWidths
columns={columns}
rows={data?.txs || []}
Expand Down
58 changes: 57 additions & 1 deletion frontend/apps/prb3-monitor/src/pages/status/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, {useCallback, useMemo} from 'react';
import {styled, useStyletron} from 'baseui';
import {StatefulDataTable, CategoricalColumn, NumericalColumn, StringColumn, COLUMNS} from 'baseui/data-table';
import {MobileHeader} from 'baseui/mobile-header';
import {TbAnalyze, TbCloudUpload, TbRefresh} from 'react-icons/tb';
import {TbAnalyze, TbCloudUpload, TbRefresh, TbCloudCheck} from 'react-icons/tb';
import Head from 'next/head';
import {useAtomValue} from 'jotai';
import {currentFetcherAtom, currentWmAtom} from '@/state';
Expand Down Expand Up @@ -195,6 +195,34 @@ export default function WorkerStatusPage() {
</span>
),
},

{
label: 'Take Checkpoint',
onClick: async ({selection}) => {
if (!confirm('Are you sure?')) {
return;
}
try {
await rawFetcher({
url: '/workers/take_checkpoint',
method: 'PUT',
data: {ids: selection.map((i) => i.id)},
});
toaster.positive('Requested, check worker status for progress.');
} catch (e) {
console.error(e);
toaster.negative(e.toString());
} finally {
await mutate();
}
},
renderIcon: () => (
<span className={css({display: 'flex', alignItems: 'center', fontSize: '12px', lineHeight: '0'})}>
<TbCloudCheck className={css({marginRight: '3px'})} size={16} />
Take Checkpoint
</span>
),
},
];
}, [css, mutate, rawFetcher]);
const rowActions = useMemo(() => {
Expand Down Expand Up @@ -254,6 +282,34 @@ export default function WorkerStatusPage() {
</span>
),
},

{
label: 'Take Checkpoint',
onClick: async ({row}) => {
if (!confirm('Are you sure?')) {
return;
}
try {
await rawFetcher({
url: '/workers/take_checkpoint',
method: 'PUT',
data: {ids: [row.id]},
});
toaster.positive('Requested, check worker status for progress.');
} catch (e) {
console.error(e);
toaster.negative(e.toString());
} finally {
await mutate();
}
},
renderIcon: () => (
<span className={css({display: 'flex', alignItems: 'center', fontSize: '15px', lineHeight: '0'})}>
<TbCloudCheck className={css({marginRight: '3px'})} size={16} />
Take Checkpoint
</span>
),
},
];
}, [css, mutate, rawFetcher]);

Expand Down
17 changes: 13 additions & 4 deletions standalone/pherry/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,21 @@ pub async fn get_authority_with_proof_at(
})
}

pub async fn verify(api: &RelaychainApi, header: &Header, mut justifications: &[u8]) -> Result<()> {
pub async fn verify(api: &RelaychainApi, header: &Header, justifications: &[u8]) -> Result<()> {
if header.number == 0 {
return Ok(());
}
let prev_header = get_header_at(api, Some(header.number - 1)).await?.0;
let auth_set = get_authority_with_proof_at(api, &prev_header).await?;
verify_with_prev_authority_set(
auth_set.authority_set.id,
&auth_set.authority_set.list,
header,
justifications
)
}

pub fn verify_with_prev_authority_set(set_id: u64, authorities: &AuthorityList, header: &Header, mut justifications: &[u8]) -> Result<()> {
let justification: GrandpaJustification<UnsigedBlock> =
Decode::decode(&mut justifications).context("Failed to decode justification")?;
if (
Expand All @@ -97,11 +106,11 @@ pub async fn verify(api: &RelaychainApi, header: &Header, mut justifications: &[
bail!("Invalid commit target in grandpa justification");
}
justification
.verify(auth_set.authority_set.id, &auth_set.authority_set.list)
.verify(set_id, authorities)
.context("Failed to verify justification")?;
info!(
"Verified grandpa justification at block {}, auth_id={}",
header.number, auth_set.authority_set.id
header.number, set_id
);
Ok(())
}
}
Loading

0 comments on commit ff9d2f6

Please sign in to comment.