-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
76 lines (67 loc) · 3.61 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright (C) 2019-2023, Ava Labs, Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package subnets
import (
"errors"
"fmt"
"time"
"github.com/DioneProtocol/odysseygo/ids"
"github.com/DioneProtocol/odysseygo/snow/consensus/snowball"
"github.com/DioneProtocol/odysseygo/utils/set"
)
var errAllowedNodesWhenNotValidatorOnly = errors.New("allowedNodes can only be set when ValidatorOnly is true")
type GossipConfig struct {
AcceptedFrontierValidatorSize uint `json:"gossipAcceptedFrontierValidatorSize" yaml:"gossipAcceptedFrontierValidatorSize"`
AcceptedFrontierNonValidatorSize uint `json:"gossipAcceptedFrontierNonValidatorSize" yaml:"gossipAcceptedFrontierNonValidatorSize"`
AcceptedFrontierPeerSize uint `json:"gossipAcceptedFrontierPeerSize" yaml:"gossipAcceptedFrontierPeerSize"`
OnAcceptValidatorSize uint `json:"gossipOnAcceptValidatorSize" yaml:"gossipOnAcceptValidatorSize"`
OnAcceptNonValidatorSize uint `json:"gossipOnAcceptNonValidatorSize" yaml:"gossipOnAcceptNonValidatorSize"`
OnAcceptPeerSize uint `json:"gossipOnAcceptPeerSize" yaml:"gossipOnAcceptPeerSize"`
AppGossipValidatorSize uint `json:"appGossipValidatorSize" yaml:"appGossipValidatorSize"`
AppGossipNonValidatorSize uint `json:"appGossipNonValidatorSize" yaml:"appGossipNonValidatorSize"`
AppGossipPeerSize uint `json:"appGossipPeerSize" yaml:"appGossipPeerSize"`
}
type Config struct {
GossipConfig
// ValidatorOnly indicates that this Subnet's Chains are available to only subnet validators.
// No chain related messages will go out to non-validators.
// Validators will drop messages received from non-validators.
// Also see [AllowedNodes] to allow non-validators to connect to this Subnet.
ValidatorOnly bool `json:"validatorOnly" yaml:"validatorOnly"`
// AllowedNodes is the set of node IDs that are explicitly allowed to connect to this Subnet when
// ValidatorOnly is enabled.
AllowedNodes set.Set[ids.NodeID] `json:"allowedNodes" yaml:"allowedNodes"`
ConsensusParameters snowball.Parameters `json:"consensusParameters" yaml:"consensusParameters"`
// ProposerMinBlockDelay is the minimum delay this node will enforce when
// building a snowman++ block.
//
// TODO: Remove this flag once all VMs throttle their own block production.
ProposerMinBlockDelay time.Duration `json:"proposerMinBlockDelay" yaml:"proposerMinBlockDelay"`
// ProposerNumHistoricalBlocks is the number of historical snowman++ blocks
// this node will index per chain. If set to 0, the node will index all
// snowman++ blocks.
//
// Note: The last accepted block is not considered a historical block. This
// prevents the user from only storing the last accepted block, which can
// never be safe due to the non-atomic commits between the proposervm
// database and the innerVM's database.
//
// Invariant: This value must be set such that the proposervm never needs to
// rollback more blocks than have been deleted. On startup, the proposervm
// rolls back its accepted chain to match the innerVM's accepted chain. If
// the innerVM is not persisting its last accepted block quickly enough, the
// database can become corrupted.
//
// TODO: Move this flag once the proposervm is configurable on a per-chain
// basis.
ProposerNumHistoricalBlocks uint64 `json:"proposerNumHistoricalBlocks" yaml:"proposerNumHistoricalBlocks"`
}
func (c *Config) Valid() error {
if err := c.ConsensusParameters.Verify(); err != nil {
return fmt.Errorf("consensus %w", err)
}
if !c.ValidatorOnly && c.AllowedNodes.Len() > 0 {
return errAllowedNodesWhenNotValidatorOnly
}
return nil
}