Skip to content

Commit c0d05f2

Browse files
acp poa works
1 parent ac51f36 commit c0d05f2

File tree

5 files changed

+143
-4
lines changed

5 files changed

+143
-4
lines changed

cmd/blockchaincmd/convert.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,18 @@ func InitializeValidatorManager(
395395
ux.Logger.GreenCheckmarkToUser("Proof of Stake Validator Manager contract successfully initialized on blockchain %s", blockchainName)
396396
} else {
397397
ux.Logger.PrintToUser("Initializing Proof of Authority Validator Manager contract on blockchain %s ...", blockchainName)
398-
if err := subnetSDK.InitializeProofOfAuthority(
398+
//if err := subnetSDK.InitializeProofOfAuthority(
399+
// aggregatorCtx,
400+
// network,
401+
// genesisPrivateKey,
402+
// extraAggregatorPeers,
403+
// aggregatorAllowPrivatePeers,
404+
// aggregatorLogger,
405+
// validatorManagerAddrStr,
406+
//); err != nil {
407+
// return tracked, err
408+
//}
409+
if err := subnetSDK.InitializeValidatorManager(
399410
aggregatorCtx,
400411
network,
401412
genesisPrivateKey,

pkg/validatormanager/validatormanager.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,8 +187,16 @@ func SetupPoA(
187187
aggregatorLogger logging.Logger,
188188
validatorManagerAddressStr string,
189189
) error {
190-
return subnet.InitializeProofOfAuthority(
191-
ctx,
190+
//return subnet.InitializeProofOfAuthority(
191+
// ctx,
192+
// network,
193+
// privateKey,
194+
// aggregatorExtraPeerEndpoints,
195+
// aggregatorAllowPrivatePeers,
196+
// aggregatorLogger,
197+
// validatorManagerAddressStr,
198+
//)
199+
return subnet.InitializeValidatorManager(ctx,
192200
network,
193201
privateKey,
194202
aggregatorExtraPeerEndpoints,

sdk/blockchain/blockchain.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,88 @@ func (c *Subnet) InitializeProofOfAuthority(
424424
return nil
425425
}
426426

427+
func (c *Subnet) InitializeValidatorManager(
428+
ctx context.Context,
429+
network models.Network,
430+
privateKey string,
431+
aggregatorExtraPeerEndpoints []info.Peer,
432+
aggregatorAllowPrivatePeers bool,
433+
aggregatorLogger logging.Logger,
434+
validatorManagerAddressStr string,
435+
) error {
436+
if c.SubnetID == ids.Empty {
437+
return fmt.Errorf("unable to initialize Proof of Authority: %w", errMissingSubnetID)
438+
}
439+
440+
if c.BlockchainID == ids.Empty {
441+
return fmt.Errorf("unable to initialize Proof of Authority: %w", errMissingBlockchainID)
442+
}
443+
444+
if c.RPC == "" {
445+
return fmt.Errorf("unable to initialize Proof of Authority: %w", errMissingRPC)
446+
}
447+
448+
if c.OwnerAddress == nil {
449+
return fmt.Errorf("unable to initialize Proof of Authority: %w", errMissingOwnerAddress)
450+
}
451+
452+
if len(c.BootstrapValidators) == 0 {
453+
return fmt.Errorf("unable to initialize Proof of Authority: %w", errMissingBootstrapValidators)
454+
}
455+
456+
if err := evm.SetupProposerVM(
457+
c.RPC,
458+
privateKey,
459+
); err != nil {
460+
ux.Logger.RedXToUser("failure setting proposer VM on L1: %s", err)
461+
}
462+
managerAddress := common.HexToAddress(validatorManagerAddressStr)
463+
tx, _, err := validatormanager.InitializeValidatorManager(
464+
c.RPC,
465+
managerAddress,
466+
privateKey,
467+
c.SubnetID,
468+
*c.OwnerAddress,
469+
)
470+
if err != nil {
471+
if !errors.Is(err, validatormanager.ErrAlreadyInitialized) {
472+
return evm.TransactionError(tx, err, "failure initializing poa validator manager")
473+
}
474+
ux.Logger.PrintToUser("Warning: the PoA contract is already initialized.")
475+
}
476+
477+
subnetConversionSignedMessage, err := validatormanager.GetPChainSubnetConversionWarpMessage(
478+
ctx,
479+
network,
480+
aggregatorLogger,
481+
0,
482+
aggregatorAllowPrivatePeers,
483+
aggregatorExtraPeerEndpoints,
484+
c.SubnetID,
485+
c.BlockchainID,
486+
managerAddress,
487+
c.BootstrapValidators,
488+
)
489+
if err != nil {
490+
return fmt.Errorf("failure signing subnet conversion warp message: %w", err)
491+
}
492+
493+
tx, _, err = validatormanager.InitializeValidatorsSet(
494+
c.RPC,
495+
managerAddress,
496+
privateKey,
497+
c.SubnetID,
498+
c.BlockchainID,
499+
c.BootstrapValidators,
500+
subnetConversionSignedMessage,
501+
)
502+
if err != nil {
503+
return evm.TransactionError(tx, err, "failure initializing validators set on poa manager")
504+
}
505+
506+
return nil
507+
}
508+
427509
func (c *Subnet) InitializeProofOfStake(
428510
ctx context.Context,
429511
network models.Network,

sdk/validatormanager/root.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@ type ValidatorManagerSettings struct {
2929
MaximumChurnPercentage uint8
3030
}
3131

32+
type ACP99ValidatorManagerSettings struct {
33+
OwnerAddress common.Address
34+
SubnetID [32]byte
35+
ChurnPeriodSeconds uint64
36+
MaximumChurnPercentage uint8
37+
}
38+
3239
type NativeTokenValidatorManagerSettings struct {
3340
BaseSettings ValidatorManagerSettings
3441
MinimumStakeAmount *big.Int
@@ -294,3 +301,32 @@ func InitializeValidatorsSet(
294301
uint32(0),
295302
)
296303
}
304+
305+
func InitializeValidatorManager(
306+
rpcURL string,
307+
managerAddress common.Address,
308+
privateKey string,
309+
subnetID ids.ID,
310+
ownerAddress common.Address,
311+
) (*types.Transaction, *types.Receipt, error) {
312+
const (
313+
defaultChurnPeriodSeconds = uint64(0)
314+
defaultMaximumChurnPercentage = uint8(20)
315+
)
316+
params := ACP99ValidatorManagerSettings{
317+
OwnerAddress: ownerAddress,
318+
SubnetID: subnetID,
319+
ChurnPeriodSeconds: defaultChurnPeriodSeconds,
320+
MaximumChurnPercentage: defaultMaximumChurnPercentage,
321+
}
322+
return contract.TxToMethod(
323+
rpcURL,
324+
privateKey,
325+
managerAddress,
326+
nil,
327+
"initialize validator manager",
328+
ErrorSignatureToError,
329+
"initialize((address,bytes32,uint64,uint8))",
330+
params,
331+
)
332+
}

tests/e2e/testcases/validatormanager/suite.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ var _ = ginkgo.Describe("[Validator Manager POA Set Up]", ginkgo.Ordered, func()
215215

216216
ctx, cancel := utils.GetSignatureAggregatorContext()
217217
defer cancel()
218-
err = subnetSDK.InitializeProofOfAuthority(ctx, network, k.PrivKeyHex(), extraAggregatorPeers, true, logging.NoLog{}, ProxyContractAddress)
218+
//err = subnetSDK.InitializeProofOfAuthority(ctx, network, k.PrivKeyHex(), extraAggregatorPeers, true, logging.NoLog{}, ProxyContractAddress)
219+
//gomega.Expect(err).Should(gomega.BeNil())
220+
err = subnetSDK.InitializeValidatorManager(ctx, network, k.PrivKeyHex(), extraAggregatorPeers, true, logging.NoLog{}, ProxyContractAddress)
219221
gomega.Expect(err).Should(gomega.BeNil())
220222
})
221223
})

0 commit comments

Comments
 (0)