Skip to content

Commit b9ab41a

Browse files
authored
Add option to provide BLS keys to validators in the genesis (#2371)
1 parent 42161aa commit b9ab41a

File tree

5 files changed

+50
-24
lines changed

5 files changed

+50
-24
lines changed

genesis/config.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/ava-labs/avalanchego/utils/constants"
1818
"github.com/ava-labs/avalanchego/utils/formatting/address"
1919
"github.com/ava-labs/avalanchego/utils/math"
20+
"github.com/ava-labs/avalanchego/vms/platformvm/signer"
2021
)
2122

2223
var (
@@ -58,9 +59,10 @@ func (a Allocation) Less(other Allocation) bool {
5859
}
5960

6061
type Staker struct {
61-
NodeID ids.NodeID `json:"nodeID"`
62-
RewardAddress ids.ShortID `json:"rewardAddress"`
63-
DelegationFee uint32 `json:"delegationFee"`
62+
NodeID ids.NodeID `json:"nodeID"`
63+
RewardAddress ids.ShortID `json:"rewardAddress"`
64+
DelegationFee uint32 `json:"delegationFee"`
65+
Signer *signer.ProofOfPossession `json:"signer,omitempty"`
6466
}
6567

6668
func (s Staker) Unparse(networkID uint32) (UnparsedStaker, error) {
@@ -73,6 +75,7 @@ func (s Staker) Unparse(networkID uint32) (UnparsedStaker, error) {
7375
NodeID: s.NodeID,
7476
RewardAddress: avaxAddr,
7577
DelegationFee: s.DelegationFee,
78+
Signer: s.Signer,
7679
}, err
7780
}
7881

genesis/genesis.go

+1
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,7 @@ func FromConfig(config *Config) ([]byte, ids.ID, error) {
430430
},
431431
Staked: utxos,
432432
ExactDelegationFee: &delegationFee,
433+
Signer: staker.Signer,
433434
},
434435
)
435436
}

genesis/unparsed_config.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"github.com/ava-labs/avalanchego/ids"
1111
"github.com/ava-labs/avalanchego/utils/formatting/address"
12+
"github.com/ava-labs/avalanchego/vms/platformvm/signer"
1213
)
1314

1415
var errInvalidETHAddress = errors.New("invalid eth address")
@@ -54,15 +55,17 @@ func (ua UnparsedAllocation) Parse() (Allocation, error) {
5455
}
5556

5657
type UnparsedStaker struct {
57-
NodeID ids.NodeID `json:"nodeID"`
58-
RewardAddress string `json:"rewardAddress"`
59-
DelegationFee uint32 `json:"delegationFee"`
58+
NodeID ids.NodeID `json:"nodeID"`
59+
RewardAddress string `json:"rewardAddress"`
60+
DelegationFee uint32 `json:"delegationFee"`
61+
Signer *signer.ProofOfPossession `json:"signer,omitempty"`
6062
}
6163

6264
func (us UnparsedStaker) Parse() (Staker, error) {
6365
s := Staker{
6466
NodeID: us.NodeID,
6567
DelegationFee: us.DelegationFee,
68+
Signer: us.Signer,
6669
}
6770

6871
_, _, avaxAddrBytes, err := address.Parse(us.RewardAddress)

vms/platformvm/api/static_service.go

+32-13
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,11 @@ type PermissionlessValidator struct {
138138
// GenesisPermissionlessValidator should to be used for genesis validators only.
139139
type GenesisPermissionlessValidator struct {
140140
GenesisValidator
141-
RewardOwner *Owner `json:"rewardOwner,omitempty"`
142-
DelegationFee json.Float32 `json:"delegationFee"`
143-
ExactDelegationFee *json.Uint32 `json:"exactDelegationFee,omitempty"`
144-
Staked []UTXO `json:"staked,omitempty"`
141+
RewardOwner *Owner `json:"rewardOwner,omitempty"`
142+
DelegationFee json.Float32 `json:"delegationFee"`
143+
ExactDelegationFee *json.Uint32 `json:"exactDelegationFee,omitempty"`
144+
Staked []UTXO `json:"staked,omitempty"`
145+
Signer *signer.ProofOfPossession `json:"signer,omitempty"`
145146
}
146147

147148
// PermissionedValidator is the repr. of a permissioned validator sent over APIs.
@@ -315,21 +316,39 @@ func (*StaticService) BuildGenesis(_ *http.Request, args *BuildGenesisArgs, repl
315316
delegationFee = uint32(*vdr.ExactDelegationFee)
316317
}
317318

318-
tx := &txs.Tx{Unsigned: &txs.AddValidatorTx{
319-
BaseTx: txs.BaseTx{BaseTx: avax.BaseTx{
319+
var (
320+
baseTx = txs.BaseTx{BaseTx: avax.BaseTx{
320321
NetworkID: uint32(args.NetworkID),
321322
BlockchainID: ids.Empty,
322-
}},
323-
Validator: txs.Validator{
323+
}}
324+
validator = txs.Validator{
324325
NodeID: vdr.NodeID,
325326
Start: uint64(args.Time),
326327
End: uint64(vdr.EndTime),
327328
Wght: weight,
328-
},
329-
StakeOuts: stake,
330-
RewardsOwner: owner,
331-
DelegationShares: delegationFee,
332-
}}
329+
}
330+
tx *txs.Tx
331+
)
332+
if vdr.Signer == nil {
333+
tx = &txs.Tx{Unsigned: &txs.AddValidatorTx{
334+
BaseTx: baseTx,
335+
Validator: validator,
336+
StakeOuts: stake,
337+
RewardsOwner: owner,
338+
DelegationShares: delegationFee,
339+
}}
340+
} else {
341+
tx = &txs.Tx{Unsigned: &txs.AddPermissionlessValidatorTx{
342+
BaseTx: baseTx,
343+
Validator: validator,
344+
Signer: vdr.Signer,
345+
StakeOuts: stake,
346+
ValidatorRewardsOwner: owner,
347+
DelegatorRewardsOwner: owner,
348+
DelegationShares: delegationFee,
349+
}}
350+
}
351+
333352
if err := tx.Initialize(txs.GenesisCodec); err != nil {
334353
return err
335354
}

vms/platformvm/state/state.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -1319,13 +1319,13 @@ func (s *state) syncGenesis(genesisBlk block.Block, genesis *genesis.Genesis) er
13191319

13201320
// Persist primary network validator set at genesis
13211321
for _, vdrTx := range genesis.Validators {
1322-
tx, ok := vdrTx.Unsigned.(*txs.AddValidatorTx)
1322+
validatorTx, ok := vdrTx.Unsigned.(txs.ValidatorTx)
13231323
if !ok {
1324-
return fmt.Errorf("expected tx type *txs.AddValidatorTx but got %T", vdrTx.Unsigned)
1324+
return fmt.Errorf("expected tx type txs.ValidatorTx but got %T", vdrTx.Unsigned)
13251325
}
13261326

1327-
stakeAmount := tx.Validator.Wght
1328-
stakeDuration := tx.Validator.Duration()
1327+
stakeAmount := validatorTx.Weight()
1328+
stakeDuration := validatorTx.EndTime().Sub(validatorTx.StartTime())
13291329
currentSupply, err := s.GetCurrentSupply(constants.PrimaryNetworkID)
13301330
if err != nil {
13311331
return err
@@ -1341,7 +1341,7 @@ func (s *state) syncGenesis(genesisBlk block.Block, genesis *genesis.Genesis) er
13411341
return err
13421342
}
13431343

1344-
staker, err := NewCurrentStaker(vdrTx.ID(), tx, potentialReward)
1344+
staker, err := NewCurrentStaker(vdrTx.ID(), validatorTx, potentialReward)
13451345
if err != nil {
13461346
return err
13471347
}

0 commit comments

Comments
 (0)