Skip to content

Commit

Permalink
emit events
Browse files Browse the repository at this point in the history
  • Loading branch information
cam-schultz committed Jan 10, 2025
1 parent 4ed02ad commit 7cd9742
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 134 deletions.
145 changes: 80 additions & 65 deletions contracts/validator-manager/ACP99Manager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ struct Validator {
uint64 startingWeight;
uint64 sentNonce;
uint64 receivedNonce;
uint64 weightChangedAt;
uint64 weight;
uint64 startTime;
uint64 endTime;
Expand All @@ -72,59 +71,106 @@ struct Validator {
* validator management, as specified in ACP-77
*/
abstract contract ACP99Manager {
/// @notice Emitted when an initial validator is registered
/// @notice Emitted when an initial validator is registered.
event RegisteredInitialValidator(
bytes32 indexed nodeID, bytes32 indexed validationID, uint64 weight
bytes32 indexed validationID, bytes nodeID, uint64 weight
);
/// @notice Emitted when a validator registration to the L1 is initiated
/// @notice Emitted when a validator registration to the L1 is initiated.
event InitiatedValidatorRegistration(
bytes32 indexed nodeID,
bytes32 indexed validationID,
bytes nodeID,
bytes32 registrationMessageID,
uint64 registrationExpiry,
uint64 weight
);
/// @notice Emitted when a validator registration to the L1 is completed
/// @notice Emitted when a validator registration to the L1 is completed.
event CompletedValidatorRegistration(
bytes32 indexed nodeID, bytes32 indexed validationID, uint64 weight
bytes32 indexed validationID, bytes nodeID, uint64 weight
);
/// @notice Emitted when a validator weight update is initiated
/// @notice Emitted when removal of an L1 validator is initiated.
event InitiatedValidatorRemoval(
bytes32 indexed validationID,
bytes32 validatorWeightMessageID,
uint64 weight,
uint64 endTime
);
/// @notice Emitted when removal of an L1 validator is completed.
event CompletedValidatorRemoval(
bytes32 indexed validationID
);
/// @notice Emitted when a validator weight update is initiated.
event InitiatedValidatorWeightUpdate(
bytes32 indexed nodeID,
bytes32 indexed validationID,
uint64 nonce,
bytes32 weightUpdateMessageID,
uint64 weight
);
/// @notice Emitted when a validator weight update is completed
/// @notice Emitted when a validator weight update is completed.
event CompletedValidatorWeightUpdate(
bytes32 indexed nodeID, bytes32 indexed validationID, uint64 nonce, uint64 weight
bytes32 indexed validationID, uint64 nonce, uint64 weight
);

/// @notice Returns the SubnetID of the L1 tied to this manager
function subnetID() virtual public view returns (bytes32 subnetID);

/// @notice Returns the validator details for a given validation ID.
function getValidator(
bytes32 validationID
) virtual public view returns (Validator memory validator);

/// @notice Returns the total weight of the current L1 validator set.
function l1TotalWeight() virtual public view returns (uint64 weight);

/**
* @notice Verifies and sets the initial validator set for the chain through a P-Chain
* SubnetToL1ConversionMessage.
* @notice Verifies and sets the initial validator set for the chain by consuming a
* SubnetToL1ConversionMessage from the P-Chain.
*
* Emits a {RegisteredInitialValidator} event for each initial validator in {conversionData}.
*
* @param conversionData The Subnet conversion message data used to recompute and verify against the ConversionID.
* @param messsageIndex The index that contains the SubnetToL1ConversionMessage Warp message containing the ConversionID to be verified against the provided {conversionData}
* @param messsageIndex The index that contains the SubnetToL1ConversionMessage ICM message containing the
* ConversionID to be verified against the provided {conversionData}.
*/
function initializeValidatorSet(
ConversionData calldata conversionData,
uint32 messsageIndex
) virtual public;

/**
* @notice Initiates validator registration by issuing a RegisterL1ValidatorMessage. The validator should
* not be considered active until completeValidatorRegistration is called.
*
* Emits an {InitiatedValidatorRegistration} event on success.
*
* @param nodeID The ID of the node to add to the L1.
* @param blsPublicKey The BLS public key of the validator.
* @param registrationExpiry The time after which this message is invalid.
* @param remainingBalanceOwner The remaining balance owner of the validator.
* @param disableOwner The disable owner of the validator.
* @param weight The weight of the node on the L1.
* @return validationID The ID of the registered validator.
*/
function _initiateValidatorRegistration(
bytes memory nodeID,
bytes memory blsPublicKey,
uint64 registrationExpiry,
PChainOwner memory remainingBalanceOwner,
PChainOwner memory disableOwner,
uint64 weight
) virtual internal returns (bytes32 validationID);

/**
* @notice Completes the validator registration process by returning an acknowledgement of the registration of a
* validationID from the P-Chain. The validator should not be considered active until this method is successfully called.
*
* Emits a {CompletedValidatorRegistration} event on success.
*
* @param messageIndex The index of the Warp message to be received providing the acknowledgement.
* @param messageIndex The index of the L1ValidatorRegistrationMessage to be received providing the acknowledgement.
* @return validationID The ID of the registered validator.
*/
function completeValidatorRegistration(
uint32 messageIndex
) virtual public returns (bytes32);
) virtual public returns (bytes32 validationID);

/**
* @notice Initiates validator removal by issuing a L1ValidatorWeightMessage with the weight set to zero.
Expand All @@ -151,62 +197,31 @@ abstract contract ACP99Manager {
) virtual public returns (bytes32 validationID);

/**
* @notice Completes the validator weight update process by returning an acknowledgement of the weight update of a
* validationID from the P-Chain. The validator weight change should not have any effect until this method is successfully called.
*
* Emits a {CompletedValidatorWeightUpdate} event on success
*
* @param messageIndex The index of the Warp message to be received providing the acknowledgement.
*/
function completeValidatorWeightUpdate(
uint32 messageIndex
) virtual public returns (bytes32);

/// @notice Returns the ID of the Subnet tied to this manager
function subnetID() virtual public view returns (bytes32);

/// @notice Returns the validation details for a given validation ID
function getValidator(
bytes32 validationID
) virtual public view returns (Validator memory);

/// @notice Returns the total weight of the current L1 validator set
function l1TotalWeight() virtual public view returns (uint64);

/**
* @notice Initiate a validator registration by issuing a RegisterL1ValidatorTx Warp message. The validator should
* not be considered active until completeValidatorRegistration is called.
* @notice Initiates validator weight update by issuing a L1ValidatorWeightMessage with a nonzero weight.
* The validator weight change should not have any effect until completeValidatorWeightUpdate is successfully called.
*
* Emits an {InitiatedValidatorRegistration} event on success.
* Emits an {InitiatedValidatorWeightUpdate} event on success.
*
* @param nodeID The ID of the node to add to the L1
* @param blsPublicKey The BLS public key of the validator
* @param registrationExpiry The time after which this message is invalid
* @param remainingBalanceOwner The remaining balance owner of the validator
* @param disableOwner The disable owner of the validator
* @param weight The weight of the node on the L1
* @param validationID The ID of the validator to modify.
* @param weight The new weight of the validator.
* @return nonce The validator nonce associated with the weight change.
* @return messageID The ID of the L1ValidatorWeightMessage used to update the validator's weight.
*/
function _initiateValidatorRegistration(
bytes memory nodeID,
bytes memory blsPublicKey,
uint64 registrationExpiry,
PChainOwner memory remainingBalanceOwner,
PChainOwner memory disableOwner,
function _initiateValidatorWeightUpdate(
bytes32 validationID,
uint64 weight
) virtual internal returns (bytes32);
) virtual internal returns (uint64 nonce, bytes32 messageID);

/**
* @notice Initiate a validator weight update by issuing a SetL1ValidatorWeightTx Warp message.
* If the weight is 0, this initiates the removal of the validator from the L1. The validator weight change
* should not have any effect until completeValidatorWeightUpdate is successfully called.
* @notice Completes the validator weight update process by consuming a L1ValidatorWeightMessage from the P-Chain
* acknowledging the weight update. The validator weight change should not have any effect until this method is successfully called.
*
* Emits an {InitiatedValidatorWeightUpdate} event on success.
* Emits a {CompletedValidatorWeightUpdate} event on success.
*
* @param validationID The ID of the validation period to modify
* @param weight The new weight of the validation
* @param messageIndex The index of the L1ValidatorWeightMessage message to be received providing the acknowledgement.
* @return validationID The ID of the validator.
*/
function _initiateValidatorWeightUpdate(
bytes32 validationID,
uint64 weight
) virtual internal returns (uint64, bytes32);
function completeValidatorWeightUpdate(
uint32 messageIndex
) virtual public returns (bytes32 validationID);
}
24 changes: 13 additions & 11 deletions contracts/validator-manager/ValidatorManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida
$._validationPeriods[validationID].endTime = 0;
totalWeight += initialValidator.weight;

emit InitialValidatorCreated(
emit RegisteredInitialValidator(
validationID, initialValidator.nodeID, initialValidator.weight
);
}
Expand Down Expand Up @@ -306,8 +306,8 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida
$._validationPeriods[validationID].startTime = 0; // The validation period only starts once the registration is acknowledged.
$._validationPeriods[validationID].endTime = 0;

emit ValidationPeriodCreated(
validationID, nodeID, messageID, weight, registrationExpiry
emit InitiatedValidatorRegistration(
validationID, nodeID, messageID, registrationExpiry, weight
);

return validationID;
Expand Down Expand Up @@ -352,8 +352,8 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida
delete $._pendingRegisterValidationMessages[validationID];
$._validationPeriods[validationID].status = ValidatorStatus.Active;
$._validationPeriods[validationID].startTime = uint64(block.timestamp);
emit ValidationPeriodRegistered(
validationID, $._validationPeriods[validationID].weight, block.timestamp
emit CompletedValidatorRegistration(
validationID, $._validationPeriods[validationID].nodeID, $._validationPeriods[validationID].weight
);

return validationID;
Expand Down Expand Up @@ -389,7 +389,7 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida
uint32 messageIndex
) virtual override public returns (bytes32) {
WarpMessage memory warpMessage = _getPChainWarpMessage(messageIndex);
(bytes32 validationID, uint64 nonce,) =
(bytes32 validationID, uint64 nonce, uint64 weight) =
ValidatorMessages.unpackL1ValidatorWeightMessage(warpMessage.payload);

ValidatorManagerStorage storage $ = _getValidatorManagerStorage();
Expand All @@ -402,6 +402,8 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida

$._validationPeriods[validationID].receivedNonce = nonce;

emit CompletedValidatorWeightUpdate(validationID, nonce, weight);

return validationID;
}

Expand Down Expand Up @@ -439,7 +441,7 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida
(, bytes32 messageID) = _initiateValidatorWeightUpdate(validationID, 0);

// Emit the event to signal the start of the validator removal process.
emit ValidatorRemovalInitialized(validationID, messageID, validator.weight, block.timestamp);
emit InitiatedValidatorRemoval(validationID, messageID, validator.weight, uint64(block.timestamp));
}

/**
Expand Down Expand Up @@ -504,7 +506,7 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida
$._validationPeriods[validationID] = validator;

// Emit event.
emit ValidationPeriodEnded(validationID, validator.status);
emit CompletedValidatorRemoval(validationID);

return (validationID, validator);
}
Expand Down Expand Up @@ -554,11 +556,11 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida
ValidatorMessages.packL1ValidatorWeightMessage(validationID, nonce, newWeight)
);

emit ValidatorWeightUpdate({
emit InitiatedValidatorWeightUpdate({
validationID: validationID,
nonce: nonce,
weight: newWeight,
setWeightMessageID: messageID
weightUpdateMessageID: messageID,
weight: newWeight
});

return (nonce, messageID);
Expand Down
58 changes: 0 additions & 58 deletions contracts/validator-manager/interfaces/IValidatorManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,64 +44,6 @@ struct ValidatorRegistrationInput {
* @notice Interface for Validator Manager contracts that implement Subnet-only Validator management.
*/
interface IValidatorManager {
/**
* @notice Emitted when a new validation period is created by locking stake in the manager contract.
* Note: This event does not mean that the validation period has been successfully registered on the P-Chain,
* and rewards for this validation period will not begin accruing until the {ValidationPeriodRegistered} event is
* emitted.
* @param validationID The ID of the validation period being created.
* @param nodeID The node ID of the validator being registered.
* @param registerValidationMessageID The ID of the ICM message that will be sent to the P-Chain to register the
* validation period.
* @param weight The weight of the validator being registered.
* @param registrationExpiry The Unix timestamp after which the reigistration is no longer valid on the P-Chain.
*/
event ValidationPeriodCreated(
bytes32 indexed validationID,
bytes indexed nodeID,
bytes32 indexed registerValidationMessageID,
uint64 weight,
uint64 registrationExpiry
);

event InitialValidatorCreated(
bytes32 indexed validationID, bytes indexed nodeID, uint64 weight
);

/**
* @notice Emitted when the staking manager learns that the validation period has been successfully registered
* on the P-Chain. Rewards for this validation period will begin accruing when this event is emitted.
* @param validationID The ID of the validation period being registered.
* @param weight The weight of the validator being registered.
* @param timestamp The time at which the validation period was registered with the contract.
*/
event ValidationPeriodRegistered(
bytes32 indexed validationID, uint64 weight, uint256 timestamp
);

/**
* @notice Emitted when the process of ending a registered validation period is started by calling
* {initializeEndValidation}.
* Note: The stake for this validation period remains locked until a {ValidationPeriodRemoved} event is emitted.
* @param validationID The ID of the validation period being removed.
* @param setWeightMessageID The ID of the ICM message that updates the validator's weight on the P-Chain.
* @param weight The weight of the validator being removed.
* @param endTime The time at which the removal was initiated.
*/
event ValidatorRemovalInitialized(
bytes32 indexed validationID,
bytes32 indexed setWeightMessageID,
uint64 weight,
uint256 endTime
);

/**
* @notice Emitted when the stake for a validation period is unlocked and returned to the staker.
* This is done by calling {completeEndValidation}, which provides proof from the P-Chain that the
* validation period is not active and will never be active in the future.
* @param validationID The ID of the validation period being removed.
*/
event ValidationPeriodEnded(bytes32 indexed validationID, ValidatorStatus indexed status);

/**
* @notice Event emitted when validator weight is updated.
Expand Down

0 comments on commit 7cd9742

Please sign in to comment.