mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-17 18:30:45 +00:00
merge waitPeriod into minePeriod (#274)
* merge waitperiod into mindePeriod * merge waitperiod into mindePeriod
This commit is contained in:
parent
767dfde1da
commit
2df16bbd37
7 changed files with 32 additions and 39 deletions
|
|
@ -125,7 +125,6 @@ func (w *wizard) makeGenesis() {
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
fmt.Println("How many seconds should blocks take? (default = 2)")
|
fmt.Println("How many seconds should blocks take? (default = 2)")
|
||||||
genesis.Config.XDPoS.Period = uint64(w.readDefaultInt(2))
|
genesis.Config.XDPoS.Period = uint64(w.readDefaultInt(2))
|
||||||
genesis.Config.XDPoS.V2.CurrentConfig.WaitPeriod = int(genesis.Config.XDPoS.Period)
|
|
||||||
genesis.Config.XDPoS.V2.CurrentConfig.MinePeriod = int(genesis.Config.XDPoS.Period)
|
genesis.Config.XDPoS.V2.CurrentConfig.MinePeriod = int(genesis.Config.XDPoS.Period)
|
||||||
|
|
||||||
fmt.Println()
|
fmt.Println()
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ type XDPoS struct {
|
||||||
signingTxsCache *lru.Cache
|
signingTxsCache *lru.Cache
|
||||||
|
|
||||||
// Share Channel
|
// Share Channel
|
||||||
WaitPeriodCh chan int // Miner wait Period Channel
|
MinePeriodCh chan int // Miner wait Period Channel
|
||||||
|
|
||||||
// Trading and lending service
|
// Trading and lending service
|
||||||
GetXDCXService func() utils.TradingService
|
GetXDCXService func() utils.TradingService
|
||||||
|
|
@ -97,7 +97,7 @@ func New(chainConfig *params.ChainConfig, db ethdb.Database) *XDPoS {
|
||||||
|
|
||||||
log.Info("xdc config loading", "config", config)
|
log.Info("xdc config loading", "config", config)
|
||||||
|
|
||||||
waitPeriodCh := make(chan int)
|
minePeriodCh := make(chan int)
|
||||||
|
|
||||||
// Allocate the snapshot caches and create the engine
|
// Allocate the snapshot caches and create the engine
|
||||||
signingTxsCache, _ := lru.New(utils.BlockSignersCacheLimit)
|
signingTxsCache, _ := lru.New(utils.BlockSignersCacheLimit)
|
||||||
|
|
@ -106,11 +106,11 @@ func New(chainConfig *params.ChainConfig, db ethdb.Database) *XDPoS {
|
||||||
config: config,
|
config: config,
|
||||||
db: db,
|
db: db,
|
||||||
|
|
||||||
WaitPeriodCh: waitPeriodCh,
|
MinePeriodCh: minePeriodCh,
|
||||||
|
|
||||||
signingTxsCache: signingTxsCache,
|
signingTxsCache: signingTxsCache,
|
||||||
EngineV1: engine_v1.New(chainConfig, db),
|
EngineV1: engine_v1.New(chainConfig, db),
|
||||||
EngineV2: engine_v2.New(chainConfig, db, waitPeriodCh),
|
EngineV2: engine_v2.New(chainConfig, db, minePeriodCh),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -124,7 +124,7 @@ func NewFaker(db ethdb.Database, chainConfig *params.ChainConfig) *XDPoS {
|
||||||
conf = chainConfig.XDPoS
|
conf = chainConfig.XDPoS
|
||||||
}
|
}
|
||||||
|
|
||||||
waitPeriodCh := make(chan int)
|
minePeriodCh := make(chan int)
|
||||||
|
|
||||||
// Allocate the snapshot caches and create the engine
|
// Allocate the snapshot caches and create the engine
|
||||||
signingTxsCache, _ := lru.New(utils.BlockSignersCacheLimit)
|
signingTxsCache, _ := lru.New(utils.BlockSignersCacheLimit)
|
||||||
|
|
@ -133,14 +133,14 @@ func NewFaker(db ethdb.Database, chainConfig *params.ChainConfig) *XDPoS {
|
||||||
config: conf,
|
config: conf,
|
||||||
db: db,
|
db: db,
|
||||||
|
|
||||||
WaitPeriodCh: waitPeriodCh,
|
MinePeriodCh: minePeriodCh,
|
||||||
|
|
||||||
GetXDCXService: func() utils.TradingService { return nil },
|
GetXDCXService: func() utils.TradingService { return nil },
|
||||||
GetLendingService: func() utils.LendingService { return nil },
|
GetLendingService: func() utils.LendingService { return nil },
|
||||||
|
|
||||||
signingTxsCache: signingTxsCache,
|
signingTxsCache: signingTxsCache,
|
||||||
EngineV1: engine_v1.NewFaker(db, chainConfig),
|
EngineV1: engine_v1.NewFaker(db, chainConfig),
|
||||||
EngineV2: engine_v2.New(chainConfig, db, waitPeriodCh),
|
EngineV2: engine_v2.New(chainConfig, db, minePeriodCh),
|
||||||
}
|
}
|
||||||
return fakeEngine
|
return fakeEngine
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,9 +30,9 @@ import (
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// timeout waiting for M1
|
// timeout waiting for M1
|
||||||
waitPeriod = 10
|
minePeriod = 10
|
||||||
// timeout for checkpoint.
|
// timeout for checkpoint.
|
||||||
waitPeriodCheckpoint = 20
|
minePeriodCheckpoint = 20
|
||||||
)
|
)
|
||||||
|
|
||||||
// XDPoS is the delegated-proof-of-stake consensus engine proposed to support the
|
// XDPoS is the delegated-proof-of-stake consensus engine proposed to support the
|
||||||
|
|
@ -62,7 +62,9 @@ type XDPoS_v1 struct {
|
||||||
HookGetSignersFromContract func(blockHash common.Hash) ([]common.Address, error)
|
HookGetSignersFromContract func(blockHash common.Hash) ([]common.Address, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* V1 Block
|
/*
|
||||||
|
V1 Block
|
||||||
|
|
||||||
SignerFn is a signer callback function to request a hash to be signed by a
|
SignerFn is a signer callback function to request a hash to be signed by a
|
||||||
backing account.
|
backing account.
|
||||||
type SignerFn func(accounts.Account, []byte) ([]byte, error)
|
type SignerFn func(accounts.Account, []byte) ([]byte, error)
|
||||||
|
|
@ -409,11 +411,11 @@ func (x *XDPoS_v1) YourTurn(chain consensus.ChainReader, parent *types.Header, s
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
h := utils.Hop(len, preIndex, curIndex)
|
h := utils.Hop(len, preIndex, curIndex)
|
||||||
gap := waitPeriod * int64(h)
|
gap := minePeriod * int64(h)
|
||||||
// Check nearest checkpoint block in hop range.
|
// Check nearest checkpoint block in hop range.
|
||||||
nearest := x.config.Epoch - (parent.Number.Uint64() % x.config.Epoch)
|
nearest := x.config.Epoch - (parent.Number.Uint64() % x.config.Epoch)
|
||||||
if uint64(h) >= nearest {
|
if uint64(h) >= nearest {
|
||||||
gap = waitPeriodCheckpoint * int64(h)
|
gap = minePeriodCheckpoint * int64(h)
|
||||||
}
|
}
|
||||||
log.Info("Distance from the parent block", "seconds", gap, "hops", h)
|
log.Info("Distance from the parent block", "seconds", gap, "hops", h)
|
||||||
waitedTime := time.Now().Unix() - parent.Time.Int64()
|
waitedTime := time.Now().Unix() - parent.Time.Int64()
|
||||||
|
|
|
||||||
|
|
@ -42,7 +42,7 @@ type XDPoS_v2 struct {
|
||||||
signLock sync.RWMutex // Protects the signer fields
|
signLock sync.RWMutex // Protects the signer fields
|
||||||
|
|
||||||
BroadcastCh chan interface{}
|
BroadcastCh chan interface{}
|
||||||
waitPeriodCh chan int
|
minePeriodCh chan int
|
||||||
|
|
||||||
timeoutWorker *countdown.CountdownTimer // Timer to generate broadcast timeout msg if threashold reached
|
timeoutWorker *countdown.CountdownTimer // Timer to generate broadcast timeout msg if threashold reached
|
||||||
timeoutCount int // number of timeout being sent
|
timeoutCount int // number of timeout being sent
|
||||||
|
|
@ -66,7 +66,7 @@ type XDPoS_v2 struct {
|
||||||
votePoolCollectionTime time.Time
|
votePoolCollectionTime time.Time
|
||||||
}
|
}
|
||||||
|
|
||||||
func New(chainConfig *params.ChainConfig, db ethdb.Database, waitPeriodCh chan int) *XDPoS_v2 {
|
func New(chainConfig *params.ChainConfig, db ethdb.Database, minePeriodCh chan int) *XDPoS_v2 {
|
||||||
config := chainConfig.XDPoS
|
config := chainConfig.XDPoS
|
||||||
// Setup timeoutTimer
|
// Setup timeoutTimer
|
||||||
duration := time.Duration(config.V2.CurrentConfig.TimeoutPeriod) * time.Second
|
duration := time.Duration(config.V2.CurrentConfig.TimeoutPeriod) * time.Second
|
||||||
|
|
@ -93,7 +93,7 @@ func New(chainConfig *params.ChainConfig, db ethdb.Database, waitPeriodCh chan i
|
||||||
epochSwitches: epochSwitches,
|
epochSwitches: epochSwitches,
|
||||||
timeoutWorker: timeoutTimer,
|
timeoutWorker: timeoutTimer,
|
||||||
BroadcastCh: make(chan interface{}),
|
BroadcastCh: make(chan interface{}),
|
||||||
waitPeriodCh: waitPeriodCh,
|
minePeriodCh: minePeriodCh,
|
||||||
|
|
||||||
timeoutPool: timeoutPool,
|
timeoutPool: timeoutPool,
|
||||||
votePool: votePool,
|
votePool: votePool,
|
||||||
|
|
@ -139,7 +139,7 @@ func (x *XDPoS_v2) UpdateParams(header *types.Header) {
|
||||||
|
|
||||||
// avoid deadlock
|
// avoid deadlock
|
||||||
go func() {
|
go func() {
|
||||||
x.waitPeriodCh <- x.config.V2.CurrentConfig.WaitPeriod
|
x.minePeriodCh <- x.config.V2.CurrentConfig.MinePeriod
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -229,10 +229,10 @@ func (x *XDPoS_v2) initial(chain consensus.ChainReader, header *types.Header) er
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initial timeout
|
// Initial timeout
|
||||||
log.Info("[initial] miner wait period", "period", x.config.V2.CurrentConfig.WaitPeriod)
|
log.Info("[initial] miner wait period", "period", x.config.V2.CurrentConfig.MinePeriod)
|
||||||
// avoid deadlock
|
// avoid deadlock
|
||||||
go func() {
|
go func() {
|
||||||
x.waitPeriodCh <- x.config.V2.CurrentConfig.WaitPeriod
|
x.minePeriodCh <- x.config.V2.CurrentConfig.MinePeriod
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// Kick-off the countdown timer
|
// Kick-off the countdown timer
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,8 @@ func TestInitialFirstV2Block(t *testing.T) {
|
||||||
assert.Equal(t, uint64(450), snap.Number)
|
assert.Equal(t, uint64(450), snap.Number)
|
||||||
|
|
||||||
// Test Running channels
|
// Test Running channels
|
||||||
waitPeriod := <-adaptor.WaitPeriodCh
|
minePeriod := <-adaptor.MinePeriodCh
|
||||||
assert.Equal(t, params.TestXDPoSMockChainConfig.XDPoS.V2.CurrentConfig.WaitPeriod, waitPeriod)
|
assert.Equal(t, params.TestXDPoSMockChainConfig.XDPoS.V2.CurrentConfig.MinePeriod, minePeriod)
|
||||||
|
|
||||||
t.Logf("Waiting %d secs for timeout to happen", params.TestXDPoSMockChainConfig.XDPoS.V2.CurrentConfig.TimeoutPeriod)
|
t.Logf("Waiting %d secs for timeout to happen", params.TestXDPoSMockChainConfig.XDPoS.V2.CurrentConfig.TimeoutPeriod)
|
||||||
timeoutMsg := <-adaptor.EngineV2.BroadcastCh
|
timeoutMsg := <-adaptor.EngineV2.BroadcastCh
|
||||||
|
|
|
||||||
|
|
@ -267,11 +267,11 @@ func (self *worker) update() {
|
||||||
defer self.chainSideSub.Unsubscribe()
|
defer self.chainSideSub.Unsubscribe()
|
||||||
|
|
||||||
// timeout waiting for v1 inital value
|
// timeout waiting for v1 inital value
|
||||||
waitPeriod := 2
|
minePeriod := 2
|
||||||
WaitPeriodCh := self.engine.(*XDPoS.XDPoS).WaitPeriodCh
|
MinePeriodCh := self.engine.(*XDPoS.XDPoS).MinePeriodCh
|
||||||
defer close(WaitPeriodCh)
|
defer close(MinePeriodCh)
|
||||||
|
|
||||||
timeout := time.NewTimer(time.Duration(waitPeriod) * time.Second)
|
timeout := time.NewTimer(time.Duration(minePeriod) * time.Second)
|
||||||
c := make(chan struct{})
|
c := make(chan struct{})
|
||||||
finish := make(chan struct{})
|
finish := make(chan struct{})
|
||||||
defer close(finish)
|
defer close(finish)
|
||||||
|
|
@ -290,21 +290,21 @@ func (self *worker) update() {
|
||||||
for {
|
for {
|
||||||
// A real event arrived, process interesting content
|
// A real event arrived, process interesting content
|
||||||
select {
|
select {
|
||||||
case v := <-WaitPeriodCh:
|
case v := <-MinePeriodCh:
|
||||||
log.Info("[worker] update wait period", "period", v)
|
log.Info("[worker] update wait period", "period", v)
|
||||||
waitPeriod = v
|
minePeriod = v
|
||||||
timeout.Reset(time.Duration(waitPeriod) * time.Second)
|
timeout.Reset(time.Duration(minePeriod) * time.Second)
|
||||||
|
|
||||||
case <-c:
|
case <-c:
|
||||||
if atomic.LoadInt32(&self.mining) == 1 {
|
if atomic.LoadInt32(&self.mining) == 1 {
|
||||||
self.commitNewWork()
|
self.commitNewWork()
|
||||||
}
|
}
|
||||||
timeout.Reset(time.Duration(waitPeriod) * time.Second)
|
timeout.Reset(time.Duration(minePeriod) * time.Second)
|
||||||
|
|
||||||
// Handle ChainHeadEvent
|
// Handle ChainHeadEvent
|
||||||
case <-self.chainHeadCh:
|
case <-self.chainHeadCh:
|
||||||
self.commitNewWork()
|
self.commitNewWork()
|
||||||
timeout.Reset(time.Duration(waitPeriod) * time.Second)
|
timeout.Reset(time.Duration(minePeriod) * time.Second)
|
||||||
|
|
||||||
// Handle ChainSideEvent
|
// Handle ChainSideEvent
|
||||||
case ev := <-self.chainSideCh:
|
case ev := <-self.chainSideCh:
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,6 @@ var (
|
||||||
CertThreshold: 73, // based on masternode is 108
|
CertThreshold: 73, // based on masternode is 108
|
||||||
TimeoutSyncThreshold: 3,
|
TimeoutSyncThreshold: 3,
|
||||||
TimeoutPeriod: 60,
|
TimeoutPeriod: 60,
|
||||||
WaitPeriod: 10,
|
|
||||||
MinePeriod: 10,
|
MinePeriod: 10,
|
||||||
},
|
},
|
||||||
9999999999: {
|
9999999999: {
|
||||||
|
|
@ -53,7 +52,6 @@ var (
|
||||||
CertThreshold: 73, // based on masternode is 108
|
CertThreshold: 73, // based on masternode is 108
|
||||||
TimeoutSyncThreshold: 3,
|
TimeoutSyncThreshold: 3,
|
||||||
TimeoutPeriod: 60,
|
TimeoutPeriod: 60,
|
||||||
WaitPeriod: 10,
|
|
||||||
MinePeriod: 10,
|
MinePeriod: 10,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -64,7 +62,6 @@ var (
|
||||||
CertThreshold: 3,
|
CertThreshold: 3,
|
||||||
TimeoutSyncThreshold: 2,
|
TimeoutSyncThreshold: 2,
|
||||||
TimeoutPeriod: 4,
|
TimeoutPeriod: 4,
|
||||||
WaitPeriod: 1,
|
|
||||||
MinePeriod: 2,
|
MinePeriod: 2,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -75,7 +72,6 @@ var (
|
||||||
CertThreshold: 73, // based on masternode is 108
|
CertThreshold: 73, // based on masternode is 108
|
||||||
TimeoutSyncThreshold: 5,
|
TimeoutSyncThreshold: 5,
|
||||||
TimeoutPeriod: 10,
|
TimeoutPeriod: 10,
|
||||||
WaitPeriod: 2,
|
|
||||||
MinePeriod: 2,
|
MinePeriod: 2,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
@ -86,7 +82,6 @@ var (
|
||||||
CertThreshold: 3,
|
CertThreshold: 3,
|
||||||
TimeoutSyncThreshold: 2,
|
TimeoutSyncThreshold: 2,
|
||||||
TimeoutPeriod: 4,
|
TimeoutPeriod: 4,
|
||||||
WaitPeriod: 1,
|
|
||||||
MinePeriod: 2,
|
MinePeriod: 2,
|
||||||
},
|
},
|
||||||
10: {
|
10: {
|
||||||
|
|
@ -94,7 +89,6 @@ var (
|
||||||
CertThreshold: 5,
|
CertThreshold: 5,
|
||||||
TimeoutSyncThreshold: 2,
|
TimeoutSyncThreshold: 2,
|
||||||
TimeoutPeriod: 4,
|
TimeoutPeriod: 4,
|
||||||
WaitPeriod: 2,
|
|
||||||
MinePeriod: 3,
|
MinePeriod: 3,
|
||||||
},
|
},
|
||||||
899: {
|
899: {
|
||||||
|
|
@ -102,8 +96,7 @@ var (
|
||||||
CertThreshold: 5,
|
CertThreshold: 5,
|
||||||
TimeoutSyncThreshold: 4,
|
TimeoutSyncThreshold: 4,
|
||||||
TimeoutPeriod: 5,
|
TimeoutPeriod: 5,
|
||||||
WaitPeriod: 2,
|
MinePeriod: 2,
|
||||||
MinePeriod: 3,
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -341,7 +334,6 @@ type V2 struct {
|
||||||
|
|
||||||
type V2Config struct {
|
type V2Config struct {
|
||||||
SwitchRound uint64 `json:"switchRound"` // v1 to v2 switch block number
|
SwitchRound uint64 `json:"switchRound"` // v1 to v2 switch block number
|
||||||
WaitPeriod int `json:"waitPeriod"` // Miner wait period to check mine event
|
|
||||||
MinePeriod int `json:"minePeriod"` // Miner mine period to mine a block
|
MinePeriod int `json:"minePeriod"` // Miner mine period to mine a block
|
||||||
TimeoutSyncThreshold int `json:"timeoutSyncThreshold"` // send syncInfo after number of timeout
|
TimeoutSyncThreshold int `json:"timeoutSyncThreshold"` // send syncInfo after number of timeout
|
||||||
TimeoutPeriod int `json:"timeoutPeriod"` // Duration in ms
|
TimeoutPeriod int `json:"timeoutPeriod"` // Duration in ms
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue