-
Notifications
You must be signed in to change notification settings - Fork 112
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
chore(lib/grandpa): make interval configurable #1903
Changes from 1 commit
6aeb9b6
740393d
5fed082
09408cb
775514d
b73826c
6f6f085
4010a66
798f675
0e72a6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,6 +85,9 @@ var ( | |
// DefaultDiscoveryInterval is the default interval for searching for DHT peers | ||
DefaultDiscoveryInterval = time.Second * 10 | ||
|
||
// DefaultGrandpaInterval | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah I'd mention that this is the time for a grandpa sub-round There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added this in there. Still working on understanding all of the polkadot pieces... |
||
DefaultGrandpaInterval = time.Second | ||
|
||
// RPCConfig | ||
|
||
// DefaultRPCHTTPHost rpc host | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -631,6 +631,12 @@ func setDotNetworkConfig(ctx *cli.Context, tomlCfg ctoml.NetworkConfig, cfg *dot | |||||||||||||
cfg.DiscoveryInterval = 0 | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this should be set to the default value if it's not set |
||||||||||||||
} | ||||||||||||||
|
||||||||||||||
if tomlCfg.GrandpaInterval > 0 { | ||||||||||||||
cfg.GrandpaInterval = time.Second * time.Duration(tomlCfg.GrandpaInterval) | ||||||||||||||
} else { | ||||||||||||||
cfg.GrandpaInterval = 0 | ||||||||||||||
} | ||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here, please move to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unless
Suggested change
|
||||||||||||||
|
||||||||||||||
// check --port flag and update node configuration | ||||||||||||||
if port := ctx.GlobalUint(PortFlag.Name); port != 0 { | ||||||||||||||
cfg.Port = uint32(port) | ||||||||||||||
|
@@ -676,6 +682,7 @@ func setDotNetworkConfig(ctx *cli.Context, tomlCfg ctoml.NetworkConfig, cfg *dot | |||||||||||||
"maxpeers", cfg.MaxPeers, | ||||||||||||||
"persistent-peers", cfg.PersistentPeers, | ||||||||||||||
"discovery-interval", cfg.DiscoveryInterval, | ||||||||||||||
"grandpa-interval", cfg.GrandpaInterval, | ||||||||||||||
) | ||||||||||||||
} | ||||||||||||||
|
||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -390,6 +390,7 @@ func TestNetworkConfigFromFlags(t *testing.T) { | |
NoBootstrap: testCfg.Network.NoBootstrap, | ||
NoMDNS: testCfg.Network.NoMDNS, | ||
DiscoveryInterval: time.Second * 10, | ||
GrandpaInterval: time.Second, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can this value be replaced with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes I have updated this. |
||
}, | ||
}, | ||
{ | ||
|
@@ -403,6 +404,7 @@ func TestNetworkConfigFromFlags(t *testing.T) { | |
NoBootstrap: testCfg.Network.NoBootstrap, | ||
NoMDNS: testCfg.Network.NoMDNS, | ||
DiscoveryInterval: time.Second * 10, | ||
GrandpaInterval: time.Second, | ||
}, | ||
}, | ||
{ | ||
|
@@ -416,6 +418,7 @@ func TestNetworkConfigFromFlags(t *testing.T) { | |
NoBootstrap: testCfg.Network.NoBootstrap, | ||
NoMDNS: testCfg.Network.NoMDNS, | ||
DiscoveryInterval: time.Second * 10, | ||
GrandpaInterval: time.Second, | ||
}, | ||
}, | ||
{ | ||
|
@@ -429,6 +432,7 @@ func TestNetworkConfigFromFlags(t *testing.T) { | |
NoBootstrap: true, | ||
NoMDNS: testCfg.Network.NoMDNS, | ||
DiscoveryInterval: time.Second * 10, | ||
GrandpaInterval: time.Second, | ||
}, | ||
}, | ||
{ | ||
|
@@ -442,6 +446,7 @@ func TestNetworkConfigFromFlags(t *testing.T) { | |
NoBootstrap: testCfg.Network.NoBootstrap, | ||
NoMDNS: true, | ||
DiscoveryInterval: time.Second * 10, | ||
GrandpaInterval: time.Second, | ||
}, | ||
}, | ||
} | ||
|
@@ -816,6 +821,7 @@ func TestUpdateConfigFromGenesisData(t *testing.T) { | |
NoBootstrap: testCfg.Network.NoBootstrap, | ||
NoMDNS: testCfg.Network.NoMDNS, | ||
DiscoveryInterval: testCfg.Network.DiscoveryInterval, | ||
GrandpaInterval: testCfg.Network.GrandpaInterval, | ||
}, | ||
RPC: testCfg.RPC, | ||
System: testCfg.System, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,8 +41,7 @@ const ( | |
) | ||
|
||
var ( | ||
interval = time.Second // TODO: make this configurable; currently 1s is same as substrate; total round length is interval * 2 | ||
logger = log.New("pkg", "grandpa") | ||
logger = log.New("pkg", "grandpa") | ||
) | ||
|
||
// Service represents the current state of the grandpa protocol | ||
|
@@ -62,6 +61,7 @@ type Service struct { | |
resumed chan struct{} // this channel will be closed when the service resumes | ||
messageHandler *MessageHandler | ||
network Network | ||
interval time.Duration | ||
|
||
// current state information | ||
state *State // current state | ||
|
@@ -92,6 +92,7 @@ type Config struct { | |
Voters []Voter | ||
Keypair *ed25519.Keypair | ||
Authority bool | ||
Interval time.Duration | ||
} | ||
|
||
// NewService returns a new GRANDPA Service instance. | ||
|
@@ -166,6 +167,7 @@ func NewService(cfg *Config) (*Service, error) { | |
resumed: make(chan struct{}), | ||
network: cfg.Network, | ||
finalisedCh: finalisedCh, | ||
interval: cfg.Interval, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you add a check in this function that will error if |
||
} | ||
|
||
s.messageHandler = NewMessageHandler(s, s.blockState) | ||
|
@@ -464,7 +466,7 @@ func (s *Service) playGrandpaRound() error { | |
|
||
logger.Debug("receiving pre-vote messages...") | ||
go s.receiveMessages(ctx) | ||
time.Sleep(interval) | ||
time.Sleep(s.interval) | ||
qdm12 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
if s.paused.Load().(bool) { | ||
return ErrServicePaused | ||
|
@@ -493,7 +495,7 @@ func (s *Service) playGrandpaRound() error { | |
go s.sendVoteMessage(prevote, vm, roundComplete) | ||
|
||
logger.Debug("receiving pre-commit messages...") | ||
time.Sleep(interval) | ||
time.Sleep(s.interval) | ||
|
||
if s.paused.Load().(bool) { | ||
return ErrServicePaused | ||
|
@@ -526,7 +528,7 @@ func (s *Service) playGrandpaRound() error { | |
} | ||
|
||
func (s *Service) sendVoteMessage(stage Subround, msg *VoteMessage, roundComplete <-chan struct{}) { | ||
ticker := time.NewTicker(interval * 4) | ||
ticker := time.NewTicker(s.interval * 4) | ||
defer ticker.Stop() | ||
|
||
for { | ||
|
@@ -550,7 +552,7 @@ func (s *Service) sendVoteMessage(stage Subround, msg *VoteMessage, roundComplet | |
|
||
// attemptToFinalize loops until the round is finalisable | ||
func (s *Service) attemptToFinalize() error { | ||
ticker := time.NewTicker(interval / 100) | ||
ticker := time.NewTicker(s.interval / 100) | ||
|
||
for { | ||
select { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
could you put this under
core
instead ofnetwork
, as it's consensus related?