Skip to content
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

Add gen block check time #382

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 26 additions & 25 deletions common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,31 +15,32 @@ const (
var Version string

type Configuration struct {
Magic int64 `json:"Magic"`
Version int `json:"Version"`
SeedList []string `json:"SeedList"`
BookKeepers []string `json:"BookKeepers"` // The default book keepers' publickey
HttpRestPort int `json:"HttpRestPort"`
RestCertPath string `json:"RestCertPath"`
RestKeyPath string `json:"RestKeyPath"`
HttpWsPort int `json:"HttpWsPort"`
HttpJsonPort int `json:"HttpJsonPort"`
HttpLocalPort int `json:"HttpLocalPort"`
OauthServerUrl string `json:"OauthServerUrl"`
NoticeServerUrl string `json:"NoticeServerUrl"`
NodePort int `json:"NodePort"`
NodeType string `json:"NodeType"`
WebSocketPort int `json:"WebSocketPort"`
PrintLevel int `json:"PrintLevel"`
IsTLS bool `json:"IsTLS"`
CertPath string `json:"CertPath"`
KeyPath string `json:"KeyPath"`
CAPath string `json:"CAPath"`
GenBlockTime uint `json:"GenBlockTime"`
MultiCoreNum uint `json:"MultiCoreNum"`
EncryptAlg string `json:"EncryptAlg"`
MaxLogSize int64 `json:"MaxLogSize"`
MaxTxInBlock int `json:"MaxTransactionInBlock"`
Magic int64 `json:"Magic"`
Version int `json:"Version"`
SeedList []string `json:"SeedList"`
BookKeepers []string `json:"BookKeepers"` // The default book keepers' publickey
HttpRestPort int `json:"HttpRestPort"`
RestCertPath string `json:"RestCertPath"`
RestKeyPath string `json:"RestKeyPath"`
HttpWsPort int `json:"HttpWsPort"`
HttpJsonPort int `json:"HttpJsonPort"`
HttpLocalPort int `json:"HttpLocalPort"`
OauthServerUrl string `json:"OauthServerUrl"`
NoticeServerUrl string `json:"NoticeServerUrl"`
NodePort int `json:"NodePort"`
NodeType string `json:"NodeType"`
WebSocketPort int `json:"WebSocketPort"`
PrintLevel int `json:"PrintLevel"`
IsTLS bool `json:"IsTLS"`
CertPath string `json:"CertPath"`
KeyPath string `json:"KeyPath"`
CAPath string `json:"CAPath"`
GenBlockTime uint `json:"GenBlockTime"`
GenBlockCheckTime uint `json:"GenBlockCheckTime"`
MultiCoreNum uint `json:"MultiCoreNum"`
EncryptAlg string `json:"EncryptAlg"`
MaxLogSize int64 `json:"MaxLogSize"`
MaxTxInBlock int `json:"MaxTransactionInBlock"`
}

type ConfigFile struct {
Expand Down
14 changes: 11 additions & 3 deletions consensus/dbft/dbftService.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ const (
)

var GenBlockTime = (MINGENBLOCKTIME * time.Second)
var GenBlockCheckTime = GenBlockTime

type DbftService struct {
context ConsensusContext
Expand Down Expand Up @@ -260,7 +261,7 @@ func (ds *DbftService) InitializeConsensus(viewNum byte) error {
ds.timeView = viewNum

ds.timer.Stop()
ds.timer.Reset(GenBlockTime << (viewNum + 1))
ds.timer.Reset((GenBlockTime + GenBlockCheckTime) << viewNum)
}
return nil
}
Expand Down Expand Up @@ -467,7 +468,7 @@ func (ds *DbftService) RequestChangeView() {
ds.context.ViewNumber, ds.context.ExpectedView[ds.context.BookKeeperIndex], ds.context.GetStateDetail()))

ds.timer.Stop()
ds.timer.Reset(GenBlockTime << (ds.context.ExpectedView[ds.context.BookKeeperIndex] + 1))
ds.timer.Reset((GenBlockTime + GenBlockCheckTime) << (ds.context.ExpectedView[ds.context.BookKeeperIndex]))

ds.SignAndRelay(ds.context.MakeChangeView())
ds.CheckExpectedView(ds.context.ExpectedView[ds.context.BookKeeperIndex])
Expand Down Expand Up @@ -507,6 +508,13 @@ func (ds *DbftService) Start() error {
log.Warn("The Generate block time should be longer than 6 seconds, so set it to be 6.")
}

genBlockCheckTime := config.Parameters.GenBlockCheckTime
if genBlockCheckTime <= 0 || genBlockCheckTime > config.Parameters.GenBlockTime {
GenBlockCheckTime = GenBlockTime
} else {
GenBlockCheckTime = time.Duration(config.Parameters.GenBlockCheckTime) * time.Second
}

ds.blockPersistCompletedSubscriber = ledger.DefaultLedger.Blockchain.BCEvents.Subscribe(events.EventBlockPersistCompleted, ds.BlockPersistCompleted)
ds.newInventorySubscriber = ds.localNet.GetEvent("consensus").Subscribe(events.EventNewInventory, ds.LocalNodeNewInventory)

Expand Down Expand Up @@ -560,7 +568,7 @@ func (ds *DbftService) Timeout() {
payload := ds.context.MakePrepareRequest()
ds.SignAndRelay(payload)
ds.timer.Stop()
ds.timer.Reset(GenBlockTime << (ds.timeView + 1))
ds.timer.Reset((GenBlockTime + GenBlockCheckTime) << ds.timeView)
} else if (ds.context.State.HasFlag(Primary) && ds.context.State.HasFlag(RequestSent)) || ds.context.State.HasFlag(Backup) {
ds.RequestChangeView()
}
Expand Down