-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Acp 77 updates #585
Acp 77 updates #585
Changes from 25 commits
6121347
6e8fa6b
f1a5147
b412e48
9515841
3b06b23
80902f0
b015856
54e0c76
e6ffd3b
90967aa
907e41d
506c603
29214d2
85daef0
5f26868
3f0b287
f74c575
0ca3a53
2207e65
b553d96
f90c70d
f4bb683
f281179
06a244e
d6e0632
ead93bc
7c1e007
72ea62d
63bad1a
406caf7
2d5bbb3
3b62b9b
c8ebfd2
5a76c07
0fa2ae8
c3a0640
70b85e9
b4710e5
c9320a9
7136669
3ecdb46
2f3390a
e033da0
e0e108b
f57c860
11e8a39
0cb408f
380fc9a
a3b77b0
9123f15
ec11cd1
9a962ed
f49fe5f
6ec27cc
02ce9d0
43c2279
391b03c
cbe7a7e
4bd2158
098442e
646e4dd
4cbde54
dac3220
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,3 +44,4 @@ server.log | |
|
||
# Forge documentation | ||
docs/ | ||
coverage/ |
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,115 @@ | ||
## Warp Message Format Reference | ||
|
||
### `SubnetConversionMessage` | ||
|
||
- Description: Confirms conversion to a Permissionless Subnet on the P-Chain | ||
|
||
- Signed by: P-Chain | ||
|
||
- Consumed by: Validator Manager contract | ||
|
||
Specification: | ||
|
||
``` | ||
SubnetConversionMessage | ||
+--------------------+----------+----------+ | ||
| codecID : uint16 | 2 bytes | | ||
+--------------------+----------+----------+ | ||
| typeID : uint32 | 4 bytes | | ||
+--------------------+----------+----------+ | ||
| subnetConversionID : [32]byte | 32 bytes | | ||
+--------------------+----------+----------+ | ||
| 38 bytes | | ||
+----------+ | ||
``` | ||
|
||
where `subnetConversionID` is defined as the `sha256` hash of the serialization of the `SubnetConversionData`, defined as follows: | ||
|
||
``` | ||
ValidatorData | ||
+--------------+----------+------------------------+ | ||
| nodeID : []byte | 4 + len(nodeID) bytes | | ||
+--------------+----------+------------------------+ | ||
| blsPublicKey : [48]byte | 48 bytes | | ||
+--------------+----------+------------------------+ | ||
| weight : uint64 | 8 bytes | | ||
+--------------+----------+------------------------+ | ||
| 60 + len(nodeID) bytes | | ||
+------------------------+ | ||
|
||
SubnetConversionData | ||
+----------------+-----------------+--------------------------------------------------------+ | ||
| codecID : uint16 | 2 bytes | | ||
+----------------+-----------------+--------------------------------------------------------+ | ||
| subnetID : [32]byte | 32 bytes | | ||
+----------------+-----------------+--------------------------------------------------------+ | ||
| managerChainID : [32]byte | 32 bytes | | ||
+----------------+-----------------+--------------------------------------------------------+ | ||
| managerAddress : []byte | 4 + len(managerAddress) bytes | | ||
+----------------+-----------------+--------------------------------------------------------+ | ||
| validators : []ValidatorData | 4 + sum(validatorLengths) bytes | | ||
+----------------+-----------------+--------------------------------------------------------+ | ||
| 74 + len(managerAddress) + len(validatorLengths) bytes | | ||
+--------------------------------------------------------+ | ||
``` | ||
|
||
### `RegisterSubnetValidatorMessage` | ||
|
||
Description: Register a Subnet Validator on the P-Chain | ||
- Description: Registers a Subnet Validator on the P-Chain | ||
|
||
Signed by: Subnet | ||
Consumed by: P-Chain | ||
- Signed by: Subnet | ||
|
||
- Consumed by: P-Chain | ||
|
||
Specification: | ||
|
||
``` | ||
+--------------+----------+-----------+ | ||
| codecID : uint16 | 2 bytes | | ||
+--------------+----------+-----------+ | ||
| typeID : uint32 | 4 bytes | | ||
+--------------+----------+-----------+ | ||
| subnetID : [32]byte | 32 bytes | | ||
+--------------+----------+-----------+ | ||
| nodeID : [32]byte | 32 bytes | | ||
+--------------+----------+-----------+ | ||
| weight : uint64 | 8 bytes | | ||
+--------------+----------+-----------+ | ||
| blsPublicKey : [48]byte | 48 bytes | | ||
+--------------+----------+-----------+ | ||
| expiry : uint64 | 8 bytes | | ||
+--------------+----------+-----------+ | ||
| 134 bytes | | ||
+-----------+ | ||
PChainOwner | ||
+-----------+------------+-------------------------------+ | ||
| threshold : uint32 | 4 bytes | | ||
+-----------+------------+-------------------------------+ | ||
| addresses : [][20]byte | 4 + len(addresses) * 20 bytes | | ||
+-----------+------------+-------------------------------+ | ||
| 8 + len(addresses) * 20 bytes | | ||
+-------------------------------+ | ||
|
||
RegisterSubnetValidatorMessage | ||
+-----------------------+-------------+--------------------------------------------------------------------+ | ||
| codecID : uint16 | 2 bytes | | ||
+-----------------------+-------------+--------------------------------------------------------------------+ | ||
| typeID : uint32 | 4 bytes | | ||
+-----------------------+-------------+-------------------------------------------------------------------+ | ||
| subnetID : [32]byte | 32 bytes | | ||
+-----------------------+-------------+--------------------------------------------------------------------+ | ||
| nodeID : []byte | 4 + len(nodeID) bytes | | ||
+-----------------------+-------------+--------------------------------------------------------------------+ | ||
| blsPublicKey : [48]byte | 48 bytes | | ||
+-----------------------+-------------+--------------------------------------------------------------------+ | ||
| expiry : uint64 | 8 bytes | | ||
+-----------------------+-------------+--------------------------------------------------------------------+ | ||
| remainingBalanceOwner : PChainOwner | 4 + len(addresses) * 20 bytes | | ||
+-----------------------+-------------+--------------------------------------------------------------------+ | ||
| disableOwner : PChainOwner | 4 + len(addresses) * 20 bytes | | ||
+-----------------------+-------------+--------------------------------------------------------------------+ | ||
| weight : uint64 | 8 bytes | | ||
+-----------------------+-------------+--------------------------------------------------------------------+ | ||
| 114 + len(nodeID) + (len(addresses1) + len(addresses2)) * 20 bytes | | ||
+--------------------------------------------------------------------+ | ||
|
||
``` | ||
|
||
### `SubnetValidatorRegistrationMessage` | ||
|
||
Description: Confirms a Subnet Validator's registration validity on the P-Chain | ||
- Description: Confirms a Subnet Validator's registration validity on the P-Chain | ||
|
||
- Signed by: P-Chain | ||
|
||
Signed by: P-Chain | ||
Consumed by: Validator Manager contract | ||
- Consumed by: Validator Manager contract | ||
|
||
Specification: | ||
|
||
``` | ||
SubnetValidatorRegistrationMessage | ||
+--------------+----------+----------+ | ||
| codecID : uint16 | 2 bytes | | ||
+--------------+----------+----------+ | ||
|
@@ -53,39 +123,27 @@ Specification: | |
+----------+ | ||
``` | ||
|
||
### `ValidationUptimeMessage` | ||
### `SubnetValidatorWeightMessage` | ||
|
||
Description: Provides a Validator's uptime for calculating staking rewards | ||
- Description: Used to set and acknowledge a Validator's stake weight on another chain | ||
|
||
Signed by: Subnet | ||
Consumed by: Validator Manager contract | ||
- To effect a weight change: | ||
|
||
Specification: | ||
- Signed by: Subnet | ||
|
||
``` | ||
+--------------+----------+----------+ | ||
| codecID : uint16 | 2 bytes | | ||
+--------------+----------+----------+ | ||
| typeID : uint32 | 4 bytes | | ||
+--------------+----------+----------+ | ||
| validationID : [32]byte | 32 bytes | | ||
+--------------+----------+----------+ | ||
| uptime : uint64 | 8 bytes | | ||
+--------------+----------+----------+ | ||
| 46 bytes | | ||
+----------+ | ||
``` | ||
- Consumed by: P-Chain | ||
|
||
### `SetSubnetValidatorWeightMessage` | ||
- To acknowledge the weight change: | ||
|
||
Description: Used to set a Validator's stake weight on another chain | ||
- Signed by P-Chain | ||
|
||
Signed by: Subnet | ||
Consumed by: P-Chain | ||
|
||
- Consumed by Subnet | ||
|
||
Specification: | ||
|
||
``` | ||
SubnetValidatorWeightMessage | ||
+--------------+----------+----------+ | ||
| codecID : uint16 | 2 bytes | | ||
+--------------+----------+----------+ | ||
|
@@ -101,27 +159,27 @@ Specification: | |
+----------+ | ||
``` | ||
|
||
### `SubnetValidatorWeightUpdateMessage` | ||
### `ValidationUptimeMessage` | ||
|
||
- Description: Provides a Validator's uptime for calculating staking rewards | ||
|
||
Description: Acknowledges a Validator weight update | ||
- Signed by: Subnet | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not for this PR, but just a heads up that we'll be updating the terminology from subnet -> L1 soon, including for these message names and transaction types. Subnets will refer to pre-Etna Subnets, where their validator set must also validate the primary network, making it a subset of the primary network validators. L1s will refer to post-Etna sovereign networks, whose validators sets can be completely independent of the primary network. |
||
|
||
Signed by: P-Chain | ||
Consumed by: Validator Manager contract | ||
- Consumed by: Validator Manager contract | ||
|
||
Specification: | ||
|
||
``` | ||
ValidationUptimeMessage | ||
+--------------+----------+----------+ | ||
| codecID : uint16 | 2 bytes | | ||
+--------------+----------+----------+ | ||
| typeID : uint32 | 4 bytes | | ||
+--------------+----------+----------+ | ||
| validationID : [32]byte | 32 bytes | | ||
+--------------+----------+----------+ | ||
| nonce : uint64 | 8 bytes | | ||
+--------------+----------+----------+ | ||
| weight : uint64 | 8 bytes | | ||
| uptime : uint64 | 8 bytes | | ||
+--------------+----------+----------+ | ||
| 54 bytes | | ||
| 46 bytes | | ||
+----------+ | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49,7 +49,7 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida | |
/// @notice Maps the validationID to the validator information. | ||
mapping(bytes32 => Validator) _validationPeriods; | ||
/// @notice Maps the nodeID to the validationID for validation periods that have not ended. | ||
mapping(bytes32 => bytes32) _registeredValidators; | ||
mapping(bytes => bytes32) _registeredValidators; | ||
/// @notice Boolean that indicates if the initial validator set has been set. | ||
bool _initializedValidatorSet; | ||
} | ||
|
@@ -73,15 +73,15 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida | |
error InvalidInitializationStatus(); | ||
error InvalidMaximumChurnPercentage(uint8 maximumChurnPercentage); | ||
error InvalidBLSKeyLength(uint256 length); | ||
error InvalidNodeID(bytes32 nodeID); | ||
error InvalidNodeID(bytes nodeID); | ||
error InvalidSubnetConversionID( | ||
bytes32 encodedSubnetConversionID, bytes32 expectedSubnetConversionID | ||
); | ||
error InvalidValidationID(bytes32 validationID); | ||
error InvalidValidatorStatus(ValidatorStatus status); | ||
error InvalidWarpMessage(); | ||
error MaxChurnRateExceeded(uint64 churnAmount); | ||
error NodeAlreadyRegistered(bytes32 nodeID); | ||
error NodeAlreadyRegistered(bytes nodeID); | ||
error UnexpectedRegistrationStatus(bool validRegistration); | ||
|
||
// solhint-disable ordering | ||
|
@@ -166,20 +166,17 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida | |
uint256 totalWeight; | ||
for (uint32 i; i < numInitialValidators; ++i) { | ||
InitialValidator memory initialValidator = subnetConversionData.initialValidators[i]; | ||
bytes32 nodeID = initialValidator.nodeID; | ||
|
||
if ($._registeredValidators[nodeID] != bytes32(0)) { | ||
revert NodeAlreadyRegistered(nodeID); | ||
if ($._registeredValidators[initialValidator.nodeID] != bytes32(0)) { | ||
revert NodeAlreadyRegistered(initialValidator.nodeID); | ||
} | ||
|
||
// Validation ID of the initial validators is the sha256 hash of the | ||
// convert Subnet tx ID and the index of the initial validator. | ||
bytes32 validationID = | ||
sha256(abi.encodePacked(subnetConversionData.convertSubnetTxID, i)); | ||
bytes32 validationID = sha256(abi.encodePacked(subnetConversionData.subnetID, i)); | ||
|
||
// Save the initial validator as an active validator. | ||
|
||
$._registeredValidators[nodeID] = validationID; | ||
$._registeredValidators[initialValidator.nodeID] = validationID; | ||
$._validationPeriods[validationID] = Validator({ | ||
status: ValidatorStatus.Active, | ||
nodeID: initialValidator.nodeID, | ||
|
@@ -236,7 +233,7 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida | |
if (input.blsPublicKey.length != BLS_PUBLIC_KEY_LENGTH) { | ||
revert InvalidBLSKeyLength(input.blsPublicKey.length); | ||
} | ||
if (input.nodeID == bytes32(0)) { | ||
if (input.nodeID.length == 0) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As of Etna, the P-Chain will only support 20 byte node IDs, but it's planned to add support for other node IDs in the future (particularly 32-byte Ed25519 node IDs). I've gone back and forth on if we should require 20 byte node IDs here and track them as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I elected to use variable length nodeIDs in order to reduce the amount of deviation from the ACP-77 spec. The main consideration to using |
||
revert InvalidNodeID(input.nodeID); | ||
} | ||
if ($._registeredValidators[input.nodeID] != bytes32(0)) { | ||
|
@@ -251,9 +248,11 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida | |
ValidatorMessages.ValidationPeriod({ | ||
subnetID: $._subnetID, | ||
nodeID: input.nodeID, | ||
weight: weight, | ||
blsPublicKey: input.blsPublicKey, | ||
registrationExpiry: input.registrationExpiry | ||
remainingBalanceOwner: input.remainingBalanceOwner, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we validate the
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good call, added these validation checks |
||
disableOwner: input.disableOwner, | ||
registrationExpiry: input.registrationExpiry, | ||
weight: weight | ||
}) | ||
); | ||
$._pendingRegisterValidationMessages[validationID] = registerSubnetValidatorMessage; | ||
|
@@ -325,7 +324,7 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida | |
); | ||
} | ||
|
||
function registeredValidators(bytes32 nodeID) public view returns (bytes32) { | ||
function registeredValidators(bytes calldata nodeID) public view returns (bytes32) { | ||
ValidatorManagerStorage storage $ = _getValidatorManagerStorage(); | ||
return $._registeredValidators[nodeID]; | ||
} | ||
|
@@ -390,7 +389,7 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida | |
} | ||
|
||
WARP_MESSENGER.sendWarpMessage( | ||
ValidatorMessages.packSetSubnetValidatorWeightMessage( | ||
ValidatorMessages.packSubnetValidatorWeightMessage( | ||
validationID, validator.messageNonce, 0 | ||
) | ||
); | ||
|
@@ -496,7 +495,7 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida | |
|
||
// Submit the message to the Warp precompile. | ||
bytes32 messageID = WARP_MESSENGER.sendWarpMessage( | ||
ValidatorMessages.packSetSubnetValidatorWeightMessage(validationID, nonce, newWeight) | ||
ValidatorMessages.packSubnetValidatorWeightMessage(validationID, nonce, newWeight) | ||
); | ||
|
||
emit ValidatorWeightUpdate({ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't matter at all for this PR, but worth noting that markdown supports tables that provide auto-formatting in the future. It makes it easy to modify in the future without having to manually correct all of the spacing.