mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-07-18 02:40:45 +00:00
consensus/XDPoS: avoid use len as variable, close XFN-25 (#1656)
This commit is contained in:
parent
4aafff2826
commit
d8af7fa0d4
2 changed files with 11 additions and 11 deletions
|
|
@ -399,7 +399,7 @@ func (x *XDPoS_v1) whoIsCreator(snap *SnapshotV1, header *types.Header) (common.
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
func (x *XDPoS_v1) YourTurn(chain consensus.ChainReader, parent *types.Header, signer common.Address) (bool, error) {
|
func (x *XDPoS_v1) YourTurn(chain consensus.ChainReader, parent *types.Header, signer common.Address) (bool, error) {
|
||||||
len, preIndex, curIndex, ok, err := x.yourTurn(chain, parent, signer)
|
length, preIndex, curIndex, ok, err := x.yourTurn(chain, parent, signer)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Warn("Failed when trying to commit new work", "err", err)
|
log.Warn("Failed when trying to commit new work", "err", err)
|
||||||
|
|
@ -415,7 +415,7 @@ func (x *XDPoS_v1) YourTurn(chain consensus.ChainReader, parent *types.Header, s
|
||||||
// you're not allowed to create this block
|
// you're not allowed to create this block
|
||||||
return false, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
h := utils.Hop(len, preIndex, curIndex)
|
h := utils.Hop(length, preIndex, curIndex)
|
||||||
gap := minePeriod * 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)
|
||||||
|
|
@ -955,11 +955,11 @@ func (x *XDPoS_v1) calcDifficulty(chain consensus.ChainReader, parent *types.Hea
|
||||||
if x.config.SkipV1Validation {
|
if x.config.SkipV1Validation {
|
||||||
return big.NewInt(1)
|
return big.NewInt(1)
|
||||||
}
|
}
|
||||||
len, preIndex, curIndex, _, err := x.yourTurn(chain, parent, signer)
|
length, preIndex, curIndex, _, err := x.yourTurn(chain, parent, signer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return big.NewInt(int64(len + curIndex - preIndex))
|
return big.NewInt(int64(length + curIndex - preIndex))
|
||||||
}
|
}
|
||||||
return big.NewInt(int64(len - utils.Hop(len, preIndex, curIndex)))
|
return big.NewInt(int64(length - utils.Hop(length, preIndex, curIndex)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (x *XDPoS_v1) RecoverSigner(header *types.Header) (common.Address, error) {
|
func (x *XDPoS_v1) RecoverSigner(header *types.Header) (common.Address, error) {
|
||||||
|
|
|
||||||
|
|
@ -22,14 +22,14 @@ func Position(list []common.Address, x common.Address) int {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
func Hop(len, pre, cur int) int {
|
func Hop(length, preIndex, curIndex int) int {
|
||||||
switch {
|
switch {
|
||||||
case pre < cur:
|
case preIndex < curIndex:
|
||||||
return cur - (pre + 1)
|
return curIndex - (preIndex + 1)
|
||||||
case pre > cur:
|
case preIndex > curIndex:
|
||||||
return (len - pre) + (cur - 1)
|
return (length - preIndex) + (curIndex - 1)
|
||||||
default:
|
default:
|
||||||
return len - 1
|
return length - 1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue