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

acp 99 #2647

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft

acp 99 #2647

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
13 changes: 12 additions & 1 deletion cmd/blockchaincmd/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,18 @@
ux.Logger.GreenCheckmarkToUser("Proof of Stake Validator Manager contract successfully initialized on blockchain %s", blockchainName)
} else {
ux.Logger.PrintToUser("Initializing Proof of Authority Validator Manager contract on blockchain %s ...", blockchainName)
if err := subnetSDK.InitializeProofOfAuthority(
//if err := subnetSDK.InitializeProofOfAuthority(

Check failure on line 398 in cmd/blockchaincmd/convert.go

View workflow job for this annotation

GitHub Actions / Lint

commentFormatting: put a space between `//` and comment text (gocritic)
// aggregatorCtx,
// network,
// genesisPrivateKey,
// extraAggregatorPeers,
// aggregatorAllowPrivatePeers,
// aggregatorLogger,
// validatorManagerAddrStr,
//); err != nil {
// return tracked, err
//}
if err := subnetSDK.InitializeValidatorManager(
aggregatorCtx,
network,
genesisPrivateKey,
Expand Down

Large diffs are not rendered by default.

12 changes: 10 additions & 2 deletions pkg/validatormanager/validatormanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,8 +187,16 @@
aggregatorLogger logging.Logger,
validatorManagerAddressStr string,
) error {
return subnet.InitializeProofOfAuthority(
ctx,
//return subnet.InitializeProofOfAuthority(

Check failure on line 190 in pkg/validatormanager/validatormanager.go

View workflow job for this annotation

GitHub Actions / Lint

commentFormatting: put a space between `//` and comment text (gocritic)
// ctx,
// network,
// privateKey,
// aggregatorExtraPeerEndpoints,
// aggregatorAllowPrivatePeers,
// aggregatorLogger,
// validatorManagerAddressStr,
//)
return subnet.InitializeValidatorManager(ctx,
network,
privateKey,
aggregatorExtraPeerEndpoints,
Expand Down
82 changes: 82 additions & 0 deletions sdk/blockchain/blockchain.go
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,88 @@ func (c *Subnet) InitializeProofOfAuthority(
return nil
}

func (c *Subnet) InitializeValidatorManager(
ctx context.Context,
network models.Network,
privateKey string,
aggregatorExtraPeerEndpoints []info.Peer,
aggregatorAllowPrivatePeers bool,
aggregatorLogger logging.Logger,
validatorManagerAddressStr string,
) error {
if c.SubnetID == ids.Empty {
return fmt.Errorf("unable to initialize Proof of Authority: %w", errMissingSubnetID)
}

if c.BlockchainID == ids.Empty {
return fmt.Errorf("unable to initialize Proof of Authority: %w", errMissingBlockchainID)
}

if c.RPC == "" {
return fmt.Errorf("unable to initialize Proof of Authority: %w", errMissingRPC)
}

if c.OwnerAddress == nil {
return fmt.Errorf("unable to initialize Proof of Authority: %w", errMissingOwnerAddress)
}

if len(c.BootstrapValidators) == 0 {
return fmt.Errorf("unable to initialize Proof of Authority: %w", errMissingBootstrapValidators)
}

if err := evm.SetupProposerVM(
c.RPC,
privateKey,
); err != nil {
ux.Logger.RedXToUser("failure setting proposer VM on L1: %s", err)
}
managerAddress := common.HexToAddress(validatorManagerAddressStr)
tx, _, err := validatormanager.InitializeValidatorManager(
c.RPC,
managerAddress,
privateKey,
c.SubnetID,
*c.OwnerAddress,
)
if err != nil {
if !errors.Is(err, validatormanager.ErrAlreadyInitialized) {
return evm.TransactionError(tx, err, "failure initializing poa validator manager")
}
ux.Logger.PrintToUser("Warning: the PoA contract is already initialized.")
}

subnetConversionSignedMessage, err := validatormanager.GetPChainSubnetConversionWarpMessage(
ctx,
network,
aggregatorLogger,
0,
aggregatorAllowPrivatePeers,
aggregatorExtraPeerEndpoints,
c.SubnetID,
c.BlockchainID,
managerAddress,
c.BootstrapValidators,
)
if err != nil {
return fmt.Errorf("failure signing subnet conversion warp message: %w", err)
}

tx, _, err = validatormanager.InitializeValidatorsSet(
c.RPC,
managerAddress,
privateKey,
c.SubnetID,
c.BlockchainID,
c.BootstrapValidators,
subnetConversionSignedMessage,
)
if err != nil {
return evm.TransactionError(tx, err, "failure initializing validators set on poa manager")
}

return nil
}

func (c *Subnet) InitializeProofOfStake(
ctx context.Context,
network models.Network,
Expand Down
36 changes: 36 additions & 0 deletions sdk/validatormanager/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ type ValidatorManagerSettings struct {
MaximumChurnPercentage uint8
}

type ACP99ValidatorManagerSettings struct {
OwnerAddress common.Address
SubnetID [32]byte
ChurnPeriodSeconds uint64
MaximumChurnPercentage uint8
}

type NativeTokenValidatorManagerSettings struct {
BaseSettings ValidatorManagerSettings
MinimumStakeAmount *big.Int
Expand Down Expand Up @@ -294,3 +301,32 @@ func InitializeValidatorsSet(
uint32(0),
)
}

func InitializeValidatorManager(
rpcURL string,
managerAddress common.Address,
privateKey string,
subnetID ids.ID,
ownerAddress common.Address,
) (*types.Transaction, *types.Receipt, error) {
const (
defaultChurnPeriodSeconds = uint64(0)
defaultMaximumChurnPercentage = uint8(20)
)
params := ACP99ValidatorManagerSettings{
OwnerAddress: ownerAddress,
SubnetID: subnetID,
ChurnPeriodSeconds: defaultChurnPeriodSeconds,
MaximumChurnPercentage: defaultMaximumChurnPercentage,
}
return contract.TxToMethod(
rpcURL,
privateKey,
managerAddress,
nil,
"initialize validator manager",
ErrorSignatureToError,
"initialize((address,bytes32,uint64,uint8))",
params,
)
}
4 changes: 3 additions & 1 deletion tests/e2e/testcases/validatormanager/suite.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,9 @@

ctx, cancel := utils.GetSignatureAggregatorContext()
defer cancel()
err = subnetSDK.InitializeProofOfAuthority(ctx, network, k.PrivKeyHex(), extraAggregatorPeers, true, logging.NoLog{}, ProxyContractAddress)
//err = subnetSDK.InitializeProofOfAuthority(ctx, network, k.PrivKeyHex(), extraAggregatorPeers, true, logging.NoLog{}, ProxyContractAddress)

Check failure on line 218 in tests/e2e/testcases/validatormanager/suite.go

View workflow job for this annotation

GitHub Actions / Lint

commentFormatting: put a space between `//` and comment text (gocritic)
//gomega.Expect(err).Should(gomega.BeNil())
err = subnetSDK.InitializeValidatorManager(ctx, network, k.PrivKeyHex(), extraAggregatorPeers, true, logging.NoLog{}, ProxyContractAddress)
gomega.Expect(err).Should(gomega.BeNil())
})
})
Loading