I found a problem with clique: if there is only one last signer in the whole network, it can vote to set its own permission to false. After the resolution is passed, len(signers) will be equal to 0, which will cause this code to crash in this line.’(number % uint64(len(signers))) == uint64(offset)’. Crash information: panic: runtime error: integer divide by zero

This commit is contained in:
root 2018-09-10 20:15:20 +08:00
parent ae992a5d73
commit f6ed68e13e

View file

@ -24,6 +24,7 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/ethdb" "github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/params" "github.com/ethereum/go-ethereum/params"
lru "github.com/hashicorp/golang-lru" lru "github.com/hashicorp/golang-lru"
) )
@ -308,5 +309,11 @@ func (s *Snapshot) inturn(number uint64, signer common.Address) bool {
for offset < len(signers) && signers[offset] != signer { for offset < len(signers) && signers[offset] != signer {
offset++ offset++
} }
if len(signers) == 0 {
log.Warn("no signer. len(signers)==0")
return false
}
return (number % uint64(len(signers))) == uint64(offset) return (number % uint64(len(signers))) == uint64(offset)
} }