Skip to content
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

Rename l1ID -> subnetID #695

Merged
merged 4 commits into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

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

Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ enum SampleMessageReceiverAction {
contract SampleMessageReceiver is ITeleporterReceiver {
address public immutable teleporterContract;
string public latestMessage;
bytes32 public latestMessageSenderL1ID;
bytes32 public latestMessageSenderSubnetID;
address public latestMessageSenderAddress;

constructor(address teleporterContractAddress) {
Expand Down Expand Up @@ -59,7 +59,7 @@ contract SampleMessageReceiver is ITeleporterReceiver {
require(msg.sender == teleporterContract, "unauthorized");
require(succeed, "intended to fail");
latestMessage = message;
latestMessageSenderL1ID = sourceBlockchainID;
latestMessageSenderSubnetID = sourceBlockchainID;
latestMessageSenderAddress = originSenderAddress;
}

Expand All @@ -73,7 +73,7 @@ contract SampleMessageReceiver is ITeleporterReceiver {
ITeleporterMessenger messenger = ITeleporterMessenger(teleporterContract);
messenger.receiveCrossChainMessage(0, address(42));
latestMessage = message;
latestMessageSenderL1ID = sourceBlockchainID;
latestMessageSenderSubnetID = sourceBlockchainID;
latestMessageSenderAddress = originSenderAddress;
}
}
Expand Down Expand Up @@ -128,7 +128,7 @@ contract HandleInitialMessageExecutionTest is TeleporterMessengerTest {

// Check that the message had the proper affect on the destination contract.
assertEq(destinationContract.latestMessage(), messageString);
assertEq(destinationContract.latestMessageSenderL1ID(), DEFAULT_SOURCE_BLOCKCHAIN_ID);
assertEq(destinationContract.latestMessageSenderSubnetID(), DEFAULT_SOURCE_BLOCKCHAIN_ID);
assertEq(destinationContract.latestMessageSenderAddress(), address(this));
assertEq(
teleporterMessenger.getRelayerRewardAddress(expectedMessageID),
Expand Down Expand Up @@ -203,7 +203,7 @@ contract HandleInitialMessageExecutionTest is TeleporterMessengerTest {

// Check that the message hash was stored in state and the message did not have any affect on the destination.
assertEq(destinationContract.latestMessage(), "");
assertEq(destinationContract.latestMessageSenderL1ID(), bytes32(0));
assertEq(destinationContract.latestMessageSenderSubnetID(), bytes32(0));
assertEq(destinationContract.latestMessageSenderAddress(), address(0));
assertEq(
teleporterMessenger.getRelayerRewardAddress(messageID), DEFAULT_RELAYER_REWARD_ADDRESS
Expand Down Expand Up @@ -251,7 +251,7 @@ contract HandleInitialMessageExecutionTest is TeleporterMessengerTest {

// Check that the message hash was stored in state and the message did not have any affect on the destination.
assertEq(destinationContract.latestMessage(), "");
assertEq(destinationContract.latestMessageSenderL1ID(), bytes32(0));
assertEq(destinationContract.latestMessageSenderSubnetID(), bytes32(0));
assertEq(destinationContract.latestMessageSenderAddress(), address(0));
assertEq(
teleporterMessenger.getRelayerRewardAddress(messageID), DEFAULT_RELAYER_REWARD_ADDRESS
Expand Down
10 changes: 5 additions & 5 deletions contracts/teleporter/tests/RetryMessageExecutionTests.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ enum FlakyMessageReceiverAction {
contract FlakyMessageReceiver is ITeleporterReceiver {
address public immutable teleporterContract;
string public latestMessage;
bytes32 public latestMessageSenderL1ID;
bytes32 public latestMessageSenderSubnetID;
address public latestMessageSenderAddress;

constructor(address teleporterContractAddress) {
Expand Down Expand Up @@ -61,7 +61,7 @@ contract FlakyMessageReceiver is ITeleporterReceiver {
require(msg.sender == teleporterContract, "unauthorized");
require(block.number % 2 != 0, "even block number");
latestMessage = message;
latestMessageSenderL1ID = sourceBlockchainID;
latestMessageSenderSubnetID = sourceBlockchainID;
latestMessageSenderAddress = originSenderAddress;
}

Expand All @@ -77,7 +77,7 @@ contract FlakyMessageReceiver is ITeleporterReceiver {
ITeleporterMessenger messenger = ITeleporterMessenger(teleporterContract);
messenger.receiveCrossChainMessage(0, address(42));
latestMessage = message;
latestMessageSenderL1ID = sourceBlockchainID;
latestMessageSenderSubnetID = sourceBlockchainID;
latestMessageSenderAddress = originSenderAddress;
}
}
Expand Down Expand Up @@ -227,7 +227,7 @@ contract RetryMessageExecutionTest is TeleporterMessengerTest {
// Check that the message execution didn't have any effect, but
// the message was marked as marked as delivered.
assertEq(destinationContract.latestMessage(), "");
assertEq(destinationContract.latestMessageSenderL1ID(), bytes32(0));
assertEq(destinationContract.latestMessageSenderSubnetID(), bytes32(0));
assertEq(destinationContract.latestMessageSenderAddress(), address(0));
assertEq(
teleporterMessenger.getRelayerRewardAddress(messageID), DEFAULT_RELAYER_REWARD_ADDRESS
Expand Down Expand Up @@ -255,7 +255,7 @@ contract RetryMessageExecutionTest is TeleporterMessengerTest {

// Check that the message had the proper affect on the destination contract.
assertEq(destinationContract.latestMessage(), messageString);
assertEq(destinationContract.latestMessageSenderL1ID(), sourceBlockchainID);
assertEq(destinationContract.latestMessageSenderSubnetID(), sourceBlockchainID);
assertEq(destinationContract.latestMessageSenderAddress(), address(this));

return (sourceBlockchainID, message);
Expand Down
2 changes: 1 addition & 1 deletion contracts/validator-manager/PoSValidatorManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ abstract contract PoSValidatorManager is
uint256 _weightToValueFactor;
/// @notice The reward calculator for this validator manager.
IRewardCalculator _rewardCalculator;
/// @notice The ID of the blockchain that submits uptime proofs. This must be a blockchain validated by the l1ID that this contract manages.
/// @notice The ID of the blockchain that submits uptime proofs. This must be a blockchain validated by the subnetID that this contract manages.
bytes32 _uptimeBlockchainID;
/// @notice Maps the validation ID to its requirements.
mapping(bytes32 validationID => PoSValidatorInfo) _posValidatorInfo;
Expand Down
4 changes: 4 additions & 0 deletions contracts/validator-manager/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ PoSValidatorManager <|-- ERC20TokenStakingManager
PoSValidatorManager <|-- NativeTokenStakingManager
```

## A Note on Nomenclature

The contracts in this directory are only useful to L1s that have been converted from Subnets as described in ACP-77. As such, `l1`/`L1` is generally preferred over `subnet`/`Subnet` in the source code. The one major exception is that `subnetID` should be used to refer to both Subnets that have not been converted, and L1s that have. This is because an L1 must first be initialized as a Subnet by issuing a `CreateSubnetTx` on the P-Chain, the transaction hash of which becomes the `subnetID`. Rather than change the name and/or value of this identifier, it is simpler for both to remain static in perpetuity.

## Deploying

Three concrete `ValidatorManager` contracts are provided - `PoAValidatorManager`, `NativeTokenStakingManager`, and `ERC20TokenStakingManager`. `NativeTokenStakingManager`, and `ERC20TokenStakingManager` implement `PoSValidatorManager`, which itself implements `ValidatorManager`. These are implemented as [upgradeable](https://github.com/OpenZeppelin/openzeppelin-contracts-upgradeable/blob/main/contracts/proxy/utils/Initializable.sol#L56) contracts. There are numerous [guides](https://blog.chain.link/upgradable-smart-contracts/) for deploying upgradeable smart contracts, but the general steps are as follows:
Expand Down
10 changes: 5 additions & 5 deletions contracts/validator-manager/ValidatorManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida
/// @custom:storage-location erc7201:avalanche-icm.storage.ValidatorManager

struct ValidatorManagerStorage {
/// @notice The l1ID associated with this validator manager.
bytes32 _l1ID;
/// @notice The subnetID associated with this validator manager.
bytes32 _subnetID;
/// @notice The number of seconds after which to reset the churn tracker.
uint64 _churnPeriodSeconds;
/// @notice The maximum churn rate allowed per churn period.
Expand Down Expand Up @@ -123,7 +123,7 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida
onlyInitializing
{
ValidatorManagerStorage storage $ = _getValidatorManagerStorage();
$._l1ID = settings.l1ID;
$._subnetID = settings.subnetID;

if (
settings.maximumChurnPercentage > MAXIMUM_CHURN_PERCENTAGE_LIMIT
Expand Down Expand Up @@ -174,7 +174,7 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida

// Validation ID of the initial validators is the sha256 hash of the
// convert subnet to L1 tx ID and the index of the initial validator.
bytes32 validationID = sha256(abi.encodePacked(conversionData.l1ID, i));
bytes32 validationID = sha256(abi.encodePacked(conversionData.subnetID, i));

// Save the initial validator as an active validator.

Expand Down Expand Up @@ -277,7 +277,7 @@ abstract contract ValidatorManager is Initializable, ContextUpgradeable, IValida
(bytes32 validationID, bytes memory registerL1ValidatorMessage) = ValidatorMessages
.packRegisterL1ValidatorMessage(
ValidatorMessages.ValidationPeriod({
l1ID: $._l1ID,
subnetID: $._subnetID,
nodeID: input.nodeID,
blsPublicKey: input.blsPublicKey,
remainingBalanceOwner: input.remainingBalanceOwner,
Expand Down
Loading
Loading