les: separate peer into clientPeer and serverPeer (#19991)

* les: separate peer into clientPeer and serverPeer

* les: address comments
This commit is contained in:
gary rong
2020-02-26 17:41:24 +08:00
committed by GitHub
parent fadf84a752
commit 4fabd9cbd2
25 changed files with 1296 additions and 1174 deletions

View File

@ -51,7 +51,7 @@ const (
// In addition to the checkpoint registered in the registrar contract, there are
// several legacy hardcoded checkpoints in our codebase. These checkpoints are
// also considered as valid.
func (h *clientHandler) validateCheckpoint(peer *peer) error {
func (h *clientHandler) validateCheckpoint(peer *serverPeer) error {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*10)
defer cancel()
@ -87,7 +87,7 @@ func (h *clientHandler) validateCheckpoint(peer *peer) error {
}
// synchronise tries to sync up our local chain with a remote peer.
func (h *clientHandler) synchronise(peer *peer) {
func (h *clientHandler) synchronise(peer *serverPeer) {
// Short circuit if the peer is nil.
if peer == nil {
return
@ -95,7 +95,7 @@ func (h *clientHandler) synchronise(peer *peer) {
// Make sure the peer's TD is higher than our own.
latest := h.backend.blockchain.CurrentHeader()
currentTd := rawdb.ReadTd(h.backend.chainDb, latest.Hash(), latest.Number.Uint64())
if currentTd != nil && peer.headBlockInfo().Td.Cmp(currentTd) < 0 {
if currentTd != nil && peer.Td().Cmp(currentTd) < 0 {
return
}
// Recap the checkpoint.