fix bug where no chains other than platform created if staking disabled

This commit is contained in:
Dan Laine 2020-03-19 17:59:12 -04:00
parent fb5f6a9d5d
commit 633e72394f
3 changed files with 15 additions and 7 deletions

View File

@ -361,8 +361,9 @@ func (n *Node) initChains() {
n.vmManager.RegisterVMFactory(
/*vmID=*/ platformvm.ID,
/*vmFactory=*/ &platformvm.Factory{
ChainManager: n.chainManager,
Validators: vdrs,
ChainManager: n.chainManager,
Validators: vdrs,
StakingEnabled: n.Config.EnableStaking,
},
)

View File

@ -16,14 +16,16 @@ var (
// Factory can create new instances of the Platform Chain
type Factory struct {
ChainManager chains.Manager
Validators validators.Manager
ChainManager chains.Manager
Validators validators.Manager
StakingEnabled bool
}
// New returns a new instance of the Platform Chain
func (f *Factory) New() interface{} {
return &VM{
ChainManager: f.ChainManager,
Validators: f.Validators,
ChainManager: f.ChainManager,
Validators: f.Validators,
StakingEnabled: f.StakingEnabled,
}
}

View File

@ -136,8 +136,13 @@ func init() {
type VM struct {
*core.SnowmanVM
// Node's validator manager
// Maps Subnets --> nodes in the Subnet
Validators validators.Manager
// true if the node is being run with staking enabled
StakingEnabled bool
// The node's chain manager
ChainManager chains.Manager
@ -327,7 +332,7 @@ func (vm *VM) createChain(tx *CreateChainTx) {
vm.Ctx.Log.Error("blockchain %s validated by Subnet %s but couldn't get that Subnet. Blockchain not created")
return
}
if !validators.Contains(vm.Ctx.NodeID) { // This node doesn't validate this blockchain
if !validators.Contains(vm.Ctx.NodeID) && vm.StakingEnabled { // This node doesn't validate this blockchain
return
}