-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
305 additions
and
2 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 |
---|---|---|
@@ -1,5 +1,11 @@ | ||
# Changelog | ||
|
||
## Unreleased | ||
|
||
### Added | ||
|
||
- Support for block energy limit chain update. | ||
|
||
## 1.5.0 | ||
|
||
### Added | ||
|
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
46 changes: 46 additions & 0 deletions
46
app/pages/multisig/updates/BlockEnergyLimit/BlockEnergyLimitView.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,46 @@ | ||
import React from 'react'; | ||
import { isChainParametersV0, isChainParametersV1 } from '@concordium/web-sdk'; | ||
import Loading from '~/cross-app-components/Loading'; | ||
import { BlockEnergyLimit } from '~/utils/types'; | ||
import withChainData, { ChainData } from '~/utils/withChainData'; | ||
import Label from '~/components/Label'; | ||
|
||
interface Props extends ChainData { | ||
blockEnergyLimit: BlockEnergyLimit; | ||
} | ||
|
||
/** | ||
* Displays an overview of a baker stake threshold. | ||
*/ | ||
export default withChainData(function BlockEnergyLimitView({ | ||
blockEnergyLimit, | ||
chainParameters, | ||
}: Props) { | ||
if (!chainParameters) { | ||
return <Loading inline />; | ||
} | ||
|
||
if ( | ||
isChainParametersV0(chainParameters) || | ||
isChainParametersV1(chainParameters) | ||
) { | ||
throw new Error('Connected node used outdated chainParameters format'); | ||
} | ||
|
||
return ( | ||
<> | ||
<div> | ||
<Label className="mB5">Current block energy limit:</Label> | ||
<div className="body3 mono"> | ||
{chainParameters.blockEnergyLimit.toString()} | ||
</div> | ||
</div> | ||
<div> | ||
<Label className="mB5">New block energy limit:</Label> | ||
<div className="body3 mono"> | ||
{blockEnergyLimit.blockEnergyLimit.toString()} | ||
</div> | ||
</div> | ||
</> | ||
); | ||
}); |
69 changes: 69 additions & 0 deletions
69
app/pages/multisig/updates/BlockEnergyLimit/UpdateBlockEnergyLimit.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,69 @@ | ||
import React from 'react'; | ||
import { isChainParametersV0, isChainParametersV1 } from '@concordium/web-sdk'; | ||
import { EqualRecord } from '~/utils/types'; | ||
import { UpdateProps } from '~/utils/transactionTypes'; | ||
import Form from '~/components/Form/'; | ||
import { mustBeAnInteger, requiredMessage, enterHere } from '../common/util'; | ||
|
||
export interface BlockEnergyLimitFields { | ||
blockEnergyLimit: bigint; | ||
} | ||
|
||
const fieldNames: EqualRecord<BlockEnergyLimitFields> = { | ||
blockEnergyLimit: 'blockEnergyLimit', | ||
}; | ||
|
||
export const fieldDisplays = { | ||
blockEnergyLimit: 'block energy limit', | ||
}; | ||
|
||
/** | ||
* Component for creating an update block energy limit transaction. | ||
*/ | ||
export default function BlockEnergyLimit({ | ||
defaults, | ||
chainParameters, | ||
}: UpdateProps): JSX.Element | null { | ||
if ( | ||
isChainParametersV0(chainParameters) || | ||
isChainParametersV1(chainParameters) | ||
) { | ||
throw new Error('Connected node used outdated chainParameters format'); | ||
} | ||
|
||
const currentBlockEnergyLimit = chainParameters.blockEnergyLimit; | ||
|
||
return ( | ||
<div> | ||
<div className="body3 mono mB10"> | ||
Current {fieldDisplays.blockEnergyLimit}:{' '} | ||
{currentBlockEnergyLimit.toString()} NRG | ||
</div> | ||
<Form.Input | ||
className="body2" | ||
name={fieldNames.blockEnergyLimit} | ||
defaultValue={ | ||
defaults.blockEnergyLimit || | ||
currentBlockEnergyLimit.toString() | ||
} | ||
label={`New ${fieldDisplays.blockEnergyLimit} (NRG)`} | ||
placeholder={enterHere(fieldDisplays.blockEnergyLimit)} | ||
rules={{ | ||
required: requiredMessage(fieldDisplays.blockEnergyLimit), | ||
min: { | ||
value: 1, | ||
message: 'Block energy limit must be positive', | ||
}, | ||
max: { | ||
value: '18446744073709551615', | ||
message: | ||
'Block energy limit must be below 18446744073709551615', | ||
}, | ||
validate: { | ||
mustBeAnInteger, | ||
}, | ||
}} | ||
/> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
// eslint-disable-next-line import/prefer-default-export | ||
export const hasDelegationProtocol = (pv: bigint) => pv >= 4n; | ||
|
||
export const hasConsensusUpdateProtocol = (pv: bigint) => pv >= 6n; |
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,94 @@ | ||
import React from 'react'; | ||
import { | ||
isChainParametersV0, | ||
isChainParametersV1, | ||
NextUpdateSequenceNumbers, | ||
} from '@concordium/web-sdk'; | ||
import BlockEnergyLimitView from '~/pages/multisig/updates/BlockEnergyLimit/BlockEnergyLimitView'; | ||
import UpdateBlockEnergyLimit, { | ||
BlockEnergyLimitFields, | ||
} from '~/pages/multisig/updates/BlockEnergyLimit/UpdateBlockEnergyLimit'; | ||
import ConcordiumLedgerClient from '../../features/ledger/ConcordiumLedgerClient'; | ||
import { getGovernanceLevel2Path } from '../../features/ledger/Path'; | ||
import { createUpdateMultiSignatureTransaction } from '../MultiSignatureTransactionHelper'; | ||
import { Authorizations, ChainParameters } from '../../node/NodeApiTypes'; | ||
import { UpdateInstructionHandler } from '../transactionTypes'; | ||
import { | ||
UpdateInstruction, | ||
isBlockEnergyLimit, | ||
BlockEnergyLimit, | ||
MultiSignatureTransaction, | ||
UpdateType, | ||
} from '../types'; | ||
import { serializeBlockEnergyLimit } from '../UpdateSerialization'; | ||
import UpdateHandlerBase from './UpdateHandlerBase'; | ||
|
||
const TYPE = 'Update block energy limit'; | ||
|
||
type TransactionType = UpdateInstruction<BlockEnergyLimit>; | ||
|
||
export default class BlockEnergyLimitHandler | ||
extends UpdateHandlerBase<TransactionType> | ||
implements | ||
UpdateInstructionHandler<TransactionType, ConcordiumLedgerClient> { | ||
constructor() { | ||
super(TYPE, isBlockEnergyLimit); | ||
} | ||
|
||
async createTransaction( | ||
chainParameters: ChainParameters, | ||
nextUpdateSequenceNumbers: NextUpdateSequenceNumbers, | ||
{ blockEnergyLimit }: BlockEnergyLimitFields, | ||
effectiveTime: bigint, | ||
expiryTime: bigint | ||
): Promise<Omit<MultiSignatureTransaction, 'id'> | undefined> { | ||
if (!chainParameters || !nextUpdateSequenceNumbers) { | ||
return undefined; | ||
} | ||
|
||
if ( | ||
isChainParametersV0(chainParameters) || | ||
isChainParametersV1(chainParameters) | ||
) { | ||
throw new Error('Update incompatible with chain protocol version'); | ||
} | ||
|
||
const sequenceNumber = nextUpdateSequenceNumbers.blockEnergyLimit; | ||
const { threshold } = chainParameters.level2Keys.electionDifficulty; | ||
|
||
return createUpdateMultiSignatureTransaction( | ||
{ blockEnergyLimit: BigInt(blockEnergyLimit) }, | ||
UpdateType.BlockEnergyLimit, | ||
sequenceNumber, | ||
threshold, | ||
effectiveTime, | ||
expiryTime | ||
); | ||
} | ||
|
||
serializePayload(transaction: TransactionType) { | ||
return serializeBlockEnergyLimit(transaction.payload); | ||
} | ||
|
||
signTransaction( | ||
transaction: TransactionType, | ||
ledger: ConcordiumLedgerClient | ||
) { | ||
const path: number[] = getGovernanceLevel2Path(); | ||
return ledger.signBlockEnergyLimit( | ||
transaction, | ||
this.serializePayload(transaction), | ||
path | ||
); | ||
} | ||
|
||
view(transaction: TransactionType) { | ||
return <BlockEnergyLimitView blockEnergyLimit={transaction.payload} />; | ||
} | ||
|
||
getAuthorization(authorizations: Authorizations) { | ||
return authorizations.electionDifficulty; | ||
} | ||
|
||
update = UpdateBlockEnergyLimit; | ||
} |
Oops, something went wrong.