-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Jailed validators pt 2: block processor + getValidatorInfo endpoint (#…
…1643) * Update block processor + getValidator info endpoint * Add a label to prominently display statuses
- Loading branch information
Showing
13 changed files
with
138 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
--- | ||
'@penumbra-zone/services': minor | ||
'@penumbra-zone/storage': minor | ||
'minifront': minor | ||
'@penumbra-zone/query': minor | ||
'@penumbra-zone/types': minor | ||
--- | ||
|
||
Support viewing fresh state of jailed validators |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
.../minifront/src/components/staking/account/delegation-value-view/validator-state-label.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { ValidatorState_ValidatorStateEnum } from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/stake/v1/stake_pb.js'; | ||
import { cn } from '@repo/ui/lib/utils'; | ||
|
||
interface LabelInfo { | ||
label: string; | ||
color: string; | ||
} | ||
|
||
const validatorStateMap = new Map<ValidatorState_ValidatorStateEnum, LabelInfo>([ | ||
[ValidatorState_ValidatorStateEnum.UNSPECIFIED, { label: 'UNSPECIFIED', color: 'bg-gray-500' }], | ||
[ValidatorState_ValidatorStateEnum.DEFINED, { label: 'DEFINED', color: 'bg-blue-500' }], | ||
[ValidatorState_ValidatorStateEnum.INACTIVE, { label: 'INACTIVE', color: 'bg-yellow-600' }], | ||
[ValidatorState_ValidatorStateEnum.ACTIVE, { label: 'ACTIVE', color: 'bg-green-500' }], | ||
[ValidatorState_ValidatorStateEnum.JAILED, { label: 'JAILED', color: 'bg-orange-700' }], | ||
[ValidatorState_ValidatorStateEnum.TOMBSTONED, { label: 'TOMBSTONED', color: 'bg-red-800' }], | ||
[ValidatorState_ValidatorStateEnum.DISABLED, { label: 'DISABLED', color: 'bg-purple-600' }], | ||
]); | ||
|
||
const getStateLabel = (state: ValidatorState_ValidatorStateEnum) => | ||
validatorStateMap.get(state) ?? { | ||
label: 'UNKNOWN', | ||
color: 'bg-yellow-600', | ||
}; | ||
|
||
export const ValidatorStateLabel = ({ state }: { state: ValidatorState_ValidatorStateEnum }) => { | ||
if (state === ValidatorState_ValidatorStateEnum.ACTIVE) { | ||
return <></>; | ||
} | ||
|
||
const { label, color } = getStateLabel(state); | ||
return ( | ||
<div className={cn('flex items-center justify-center rounded p-1 font-mono -mt-1', color)}> | ||
{label} | ||
</div> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,31 @@ | ||
import { Impl } from './index.js'; | ||
import { servicesCtx } from '../ctx/prax.js'; | ||
import { Code, ConnectError } from '@connectrpc/connect'; | ||
import { | ||
GetValidatorInfoRequest, | ||
GetValidatorInfoResponse, | ||
} from '@buf/penumbra-zone_penumbra.bufbuild_es/penumbra/core/component/stake/v1/stake_pb.js'; | ||
|
||
export const getValidatorInfo: Impl['getValidatorInfo'] = async (req, ctx) => { | ||
if (!req.identityKey) { | ||
throw new ConnectError('Missing identityKey in request', Code.InvalidArgument); | ||
} | ||
const services = await ctx.values.get(servicesCtx)(); | ||
const { indexedDb } = await services.getWalletServices(); | ||
const { indexedDb, querier } = await services.getWalletServices(); | ||
|
||
const validatorInfo = await indexedDb.getValidatorInfo(req.identityKey); | ||
// Step 1: Try to find validator info in database | ||
const infoInDb = await indexedDb.getValidatorInfo(req.identityKey); | ||
if (infoInDb) { | ||
return new GetValidatorInfoResponse({ validatorInfo: infoInDb }); | ||
} | ||
|
||
if (!validatorInfo) { | ||
throw new ConnectError('No found validator info', Code.NotFound); | ||
// Step 2: If none locally, query remote node | ||
const { validatorInfo: infoFromNode } = await querier.stake.validatorInfo( | ||
new GetValidatorInfoRequest({ identityKey: req.identityKey }), | ||
); | ||
if (infoFromNode) { | ||
return new GetValidatorInfoResponse({ validatorInfo: infoFromNode }); | ||
} | ||
return { validatorInfo }; | ||
|
||
throw new ConnectError('No found validator info', Code.NotFound); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters