|
|
@ -7,30 +7,28 @@ import ( |
|
|
|
"strconv" |
|
|
|
"strconv" |
|
|
|
"time" |
|
|
|
"time" |
|
|
|
|
|
|
|
|
|
|
|
"github.com/harmony-one/harmony/internal/tikv" |
|
|
|
|
|
|
|
"github.com/multiformats/go-multiaddr" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
prom "github.com/harmony-one/harmony/api/service/prometheus" |
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
"github.com/ethereum/go-ethereum/common" |
|
|
|
"github.com/ethereum/go-ethereum/rlp" |
|
|
|
"github.com/ethereum/go-ethereum/rlp" |
|
|
|
lru "github.com/hashicorp/golang-lru" |
|
|
|
|
|
|
|
"github.com/pkg/errors" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"github.com/harmony-one/harmony/api/service" |
|
|
|
"github.com/harmony-one/harmony/api/service" |
|
|
|
"github.com/harmony-one/harmony/api/service/legacysync" |
|
|
|
"github.com/harmony-one/harmony/api/service/legacysync" |
|
|
|
legdownloader "github.com/harmony-one/harmony/api/service/legacysync/downloader" |
|
|
|
legdownloader "github.com/harmony-one/harmony/api/service/legacysync/downloader" |
|
|
|
downloader_pb "github.com/harmony-one/harmony/api/service/legacysync/downloader/proto" |
|
|
|
downloader_pb "github.com/harmony-one/harmony/api/service/legacysync/downloader/proto" |
|
|
|
|
|
|
|
prom "github.com/harmony-one/harmony/api/service/prometheus" |
|
|
|
"github.com/harmony-one/harmony/api/service/stagedstreamsync" |
|
|
|
"github.com/harmony-one/harmony/api/service/stagedstreamsync" |
|
|
|
"github.com/harmony-one/harmony/api/service/stagedsync" |
|
|
|
"github.com/harmony-one/harmony/api/service/stagedsync" |
|
|
|
"github.com/harmony-one/harmony/api/service/synchronize" |
|
|
|
"github.com/harmony-one/harmony/api/service/synchronize" |
|
|
|
|
|
|
|
"github.com/harmony-one/harmony/consensus" |
|
|
|
"github.com/harmony-one/harmony/core" |
|
|
|
"github.com/harmony-one/harmony/core" |
|
|
|
"github.com/harmony-one/harmony/core/types" |
|
|
|
"github.com/harmony-one/harmony/core/types" |
|
|
|
nodeconfig "github.com/harmony-one/harmony/internal/configs/node" |
|
|
|
nodeconfig "github.com/harmony-one/harmony/internal/configs/node" |
|
|
|
|
|
|
|
"github.com/harmony-one/harmony/internal/tikv" |
|
|
|
"github.com/harmony-one/harmony/internal/utils" |
|
|
|
"github.com/harmony-one/harmony/internal/utils" |
|
|
|
"github.com/harmony-one/harmony/p2p" |
|
|
|
"github.com/harmony-one/harmony/p2p" |
|
|
|
"github.com/harmony-one/harmony/shard" |
|
|
|
"github.com/harmony-one/harmony/shard" |
|
|
|
|
|
|
|
lru "github.com/hashicorp/golang-lru" |
|
|
|
|
|
|
|
"github.com/multiformats/go-multiaddr" |
|
|
|
|
|
|
|
"github.com/pkg/errors" |
|
|
|
|
|
|
|
"github.com/prometheus/client_golang/prometheus" |
|
|
|
) |
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
// Constants related to doing syncing.
|
|
|
|
// Constants related to doing syncing.
|
|
|
@ -279,20 +277,16 @@ func (node *Node) DoSyncing(bc core.BlockChain, willJoinConsensus bool) { |
|
|
|
for { |
|
|
|
for { |
|
|
|
select { |
|
|
|
select { |
|
|
|
case <-ticker.C: |
|
|
|
case <-ticker.C: |
|
|
|
node.doSync(bc, willJoinConsensus) |
|
|
|
node.doSync(node.SyncInstance(), node.SyncingPeerProvider, bc, node.Consensus, willJoinConsensus) |
|
|
|
case <-node.Consensus.BlockNumLowChan: |
|
|
|
|
|
|
|
node.doSync(bc, willJoinConsensus) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// doSync keep the node in sync with other peers, willJoinConsensus means the node will try to join consensus after catch up
|
|
|
|
// doSync keep the node in sync with other peers, willJoinConsensus means the node will try to join consensus after catch up
|
|
|
|
func (node *Node) doSync(bc core.BlockChain, willJoinConsensus bool) { |
|
|
|
func (node *Node) doSync(syncInstance ISync, syncingPeerProvider SyncingPeerProvider, bc core.BlockChain, consensus *consensus.Consensus, willJoinConsensus bool) { |
|
|
|
|
|
|
|
|
|
|
|
syncInstance := node.SyncInstance() |
|
|
|
|
|
|
|
if syncInstance.GetActivePeerNumber() < legacysync.NumPeersLowBound { |
|
|
|
if syncInstance.GetActivePeerNumber() < legacysync.NumPeersLowBound { |
|
|
|
shardID := bc.ShardID() |
|
|
|
shardID := bc.ShardID() |
|
|
|
peers, err := node.SyncingPeerProvider.SyncingPeers(shardID) |
|
|
|
peers, err := syncingPeerProvider.SyncingPeers(shardID) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
utils.Logger().Warn(). |
|
|
|
utils.Logger().Warn(). |
|
|
|
Err(err). |
|
|
|
Err(err). |
|
|
@ -313,13 +307,13 @@ func (node *Node) doSync(bc core.BlockChain, willJoinConsensus bool) { |
|
|
|
if isSynchronized, _, _ := syncInstance.GetParsedSyncStatusDoubleChecked(); !isSynchronized { |
|
|
|
if isSynchronized, _, _ := syncInstance.GetParsedSyncStatusDoubleChecked(); !isSynchronized { |
|
|
|
node.IsSynchronized.UnSet() |
|
|
|
node.IsSynchronized.UnSet() |
|
|
|
if willJoinConsensus { |
|
|
|
if willJoinConsensus { |
|
|
|
node.Consensus.BlocksNotSynchronized() |
|
|
|
consensus.BlocksNotSynchronized() |
|
|
|
} |
|
|
|
} |
|
|
|
isBeacon := bc.ShardID() == shard.BeaconChainShardID |
|
|
|
isBeacon := bc.ShardID() == shard.BeaconChainShardID |
|
|
|
syncInstance.SyncLoop(bc, isBeacon, node.Consensus, legacysync.LoopMinTime) |
|
|
|
syncInstance.SyncLoop(bc, isBeacon, consensus, legacysync.LoopMinTime) |
|
|
|
if willJoinConsensus { |
|
|
|
if willJoinConsensus { |
|
|
|
node.IsSynchronized.Set() |
|
|
|
node.IsSynchronized.Set() |
|
|
|
node.Consensus.BlocksSynchronized() |
|
|
|
consensus.BlocksSynchronized() |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
node.IsSynchronized.Set() |
|
|
|
node.IsSynchronized.Set() |
|
|
@ -415,7 +409,7 @@ func (node *Node) SendNewBlockToUnsync() { |
|
|
|
utils.Logger().Warn().Msg("[SYNC] unable to encode block to hashes") |
|
|
|
utils.Logger().Warn().Msg("[SYNC] unable to encode block to hashes") |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
blockWithSigBytes, err := node.getEncodedBlockWithSigFromBlock(block) |
|
|
|
blockWithSigBytes, err := getEncodedBlockWithSigFromBlock(block) |
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
utils.Logger().Warn().Err(err).Msg("[SYNC] rlp encode BlockWithSig") |
|
|
|
utils.Logger().Warn().Err(err).Msg("[SYNC] rlp encode BlockWithSig") |
|
|
|
continue |
|
|
|
continue |
|
|
@ -747,7 +741,7 @@ func (node *Node) getEncodedBlockWithSigByHeight(height uint64) ([]byte, error) |
|
|
|
return b, nil |
|
|
|
return b, nil |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (node *Node) getEncodedBlockWithSigFromBlock(block *types.Block) ([]byte, error) { |
|
|
|
func getEncodedBlockWithSigFromBlock(block *types.Block) ([]byte, error) { |
|
|
|
bwh := legacysync.BlockWithSig{ |
|
|
|
bwh := legacysync.BlockWithSig{ |
|
|
|
Block: block, |
|
|
|
Block: block, |
|
|
|
CommitSigAndBitmap: block.GetCurrentCommitSig(), |
|
|
|
CommitSigAndBitmap: block.GetCurrentCommitSig(), |
|
|
|