mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-21 06:04:33 +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,11 +314,15 @@ func (x *XDPoS) GetMasternodesByNumber(chain consensus.ChainReader, blockNumber
|
|||
}
|
||||
|
||||
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 {
|
||||
err := x.initialV2(chain, parent)
|
||||
if err != nil {
|
||||
log.Error("[YourTurn] Error when initialise v2", "Error", err, "ParentBlock", parent)
|
||||
return false, err
|
||||
if x.config.V2.SwitchBlock != nil && parent.Number.Cmp(x.config.V2.SwitchBlock) != -1 {
|
||||
if parent.Number.Cmp(x.config.V2.SwitchBlock) == 0 {
|
||||
err := x.initialV2FromLastV1(chain, parent)
|
||||
if err != nil {
|
||||
log.Error("[YourTurn] Error while initilising first v2 block from the last v1 block", "ParentBlockHash", parent.Hash(), "Error", 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)) {
|
||||
|
|
@ -481,12 +485,15 @@ func (x *XDPoS) GetCachedSigningTxs(hash common.Hash) (interface{}, bool) {
|
|||
return x.signingTxsCache.Get(hash)
|
||||
}
|
||||
|
||||
//V2
|
||||
func (x *XDPoS) initialV2(chain consensus.ChainReader, header *types.Header) error {
|
||||
// V2 specific helper function to initilise consensus engine variables
|
||||
func (x *XDPoS) initialV2FromLastV1(chain consensus.ChainReader, header *types.Header) error {
|
||||
checkpointBlockNumber := header.Number.Uint64() - header.Number.Uint64()%x.config.Epoch
|
||||
checkpointHeader := chain.GetHeaderByNumber(checkpointBlockNumber)
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ func (x *XDPoS_v2) SignHash(header *types.Header) (hash common.Hash) {
|
|||
func (x *XDPoS_v2) Initial(chain consensus.ChainReader, header *types.Header, masternodes []common.Address) error {
|
||||
log.Info("[Initial] initial v2 related parameters")
|
||||
|
||||
if x.highestQuorumCert.ProposedBlockInfo.Round != 0 { //already initialized
|
||||
if x.highestQuorumCert.ProposedBlockInfo.Round != 0 { // already initialized
|
||||
log.Warn("[Initial] Already initialized")
|
||||
return nil
|
||||
}
|
||||
|
|
@ -128,7 +128,7 @@ func (x *XDPoS_v2) Initial(chain consensus.ChainReader, header *types.Header, ma
|
|||
defer x.lock.Unlock()
|
||||
// Check header if it is the first consensus v2 block, if so, assign initial values to current round and highestQC
|
||||
|
||||
log.Info("[Initial] highest QC for consensus v2 first block", "Block Num", header.Number.String(), "BlockHash", header.Hash())
|
||||
log.Info("[Initial] highest QC for consensus v2 first block", "BlockNum", header.Number.String(), "BlockHash", header.Hash())
|
||||
// Generate new parent blockInfo and put it into QC
|
||||
blockInfo := &utils.BlockInfo{
|
||||
Hash: header.Hash(),
|
||||
|
|
@ -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)
|
||||
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
|
||||
log.Info("[Initial] miner wait period", "period", x.config.WaitPeriod)
|
||||
|
|
|
|||
Loading…
Reference in a new issue