mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 02:40:45 +00:00
Split initialise v2 into two scenarios
This commit is contained in:
parent
89acbdd742
commit
125f8a8957
2 changed files with 22 additions and 11 deletions
|
|
@ -314,12 +314,16 @@ func (x *XDPoS) GetMasternodesByNumber(chain consensus.ChainReader, blockNumber
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *XDPoS) YourTurn(chain consensus.ChainReader, parent *types.Header, signer common.Address) (bool, error) {
|
func (x *XDPoS) YourTurn(chain consensus.ChainReader, parent *types.Header, signer common.Address) (bool, error) {
|
||||||
if x.config.V2.SwitchBlock != nil && parent.Number.Cmp(x.config.V2.SwitchBlock) == 0 {
|
if x.config.V2.SwitchBlock != nil && parent.Number.Cmp(x.config.V2.SwitchBlock) != -1 {
|
||||||
err := x.initialV2(chain, parent)
|
if parent.Number.Cmp(x.config.V2.SwitchBlock) == 0 {
|
||||||
|
err := x.initialV2FromLastV1(chain, parent)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("[YourTurn] Error when initialise v2", "Error", err, "ParentBlock", parent)
|
log.Error("[YourTurn] Error while initilising first v2 block from the last v1 block", "ParentBlockHash", parent.Hash(), "Error", err)
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
|
} else if parent.Number.Cmp(x.config.V2.SwitchBlock) == 1 { // TODO: XIN-147
|
||||||
|
log.Info("[YourTurn] Initilising v2 after sync or restarted", "currentBlockNum", chain.CurrentHeader().Number, "currentBlockHash", chain.CurrentHeader().Hash())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
switch x.config.BlockConsensusVersion(big.NewInt(parent.Number.Int64() + 1)) {
|
switch x.config.BlockConsensusVersion(big.NewInt(parent.Number.Int64() + 1)) {
|
||||||
case params.ConsensusEngineVersion2:
|
case params.ConsensusEngineVersion2:
|
||||||
|
|
@ -481,12 +485,15 @@ func (x *XDPoS) GetCachedSigningTxs(hash common.Hash) (interface{}, bool) {
|
||||||
return x.signingTxsCache.Get(hash)
|
return x.signingTxsCache.Get(hash)
|
||||||
}
|
}
|
||||||
|
|
||||||
//V2
|
// V2 specific helper function to initilise consensus engine variables
|
||||||
func (x *XDPoS) initialV2(chain consensus.ChainReader, header *types.Header) error {
|
func (x *XDPoS) initialV2FromLastV1(chain consensus.ChainReader, header *types.Header) error {
|
||||||
checkpointBlockNumber := header.Number.Uint64() - header.Number.Uint64()%x.config.Epoch
|
checkpointBlockNumber := header.Number.Uint64() - header.Number.Uint64()%x.config.Epoch
|
||||||
checkpointHeader := chain.GetHeaderByNumber(checkpointBlockNumber)
|
checkpointHeader := chain.GetHeaderByNumber(checkpointBlockNumber)
|
||||||
masternodes := x.EngineV1.GetMasternodesFromCheckpointHeader(checkpointHeader)
|
masternodes := x.EngineV1.GetMasternodesFromCheckpointHeader(checkpointHeader)
|
||||||
x.EngineV2.Initial(chain, header, masternodes)
|
err := x.EngineV2.Initial(chain, header, masternodes)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -148,7 +148,11 @@ func (x *XDPoS_v2) Initial(chain consensus.ChainReader, header *types.Header, ma
|
||||||
|
|
||||||
snap := newSnapshot(lastGapNum, lastGapHeader.Hash(), x.currentRound, x.highestQuorumCert, masternodes)
|
snap := newSnapshot(lastGapNum, lastGapHeader.Hash(), x.currentRound, x.highestQuorumCert, masternodes)
|
||||||
x.snapshots.Add(snap.Hash, snap)
|
x.snapshots.Add(snap.Hash, snap)
|
||||||
storeSnapshot(snap, x.db)
|
err := storeSnapshot(snap, x.db)
|
||||||
|
if err != nil {
|
||||||
|
log.Error("[Initial] Error while storo snapshot", "error", err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Initial timeout
|
// Initial timeout
|
||||||
log.Info("[Initial] miner wait period", "period", x.config.WaitPeriod)
|
log.Info("[Initial] miner wait period", "period", x.config.WaitPeriod)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue