From 8458f581eacb568122a5692382e5b9a6aaa8ad79 Mon Sep 17 00:00:00 2001 From: chao Date: Wed, 16 Oct 2019 14:44:53 -0700 Subject: [PATCH 1/2] update consensus and committee informatin for at end of every epoch; fix bls library source broken --- node/node_syncing.go | 4 +++- scripts/setup_bls_build_flags.sh | 7 ------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/node/node_syncing.go b/node/node_syncing.go index 4c1eacd62..14f7cc8d2 100644 --- a/node/node_syncing.go +++ b/node/node_syncing.go @@ -235,7 +235,9 @@ SyncingLoop: node.Consensus.BlocksNotSynchronized() } node.stateSync.SyncLoop(bc, worker, false) - if node.NodeConfig.Role() == nodeconfig.ExplorerNode { + // update the consensus and committee information at the end of epoch including explorer node + // only when the syncing shard is different than node's own shard, we don't update it + if node.Blockchain().ShardID() == bc.ShardID() && core.ShardingSchedule.IsLastBlock(bc.CurrentBlock().NumberU64()) { node.Consensus.UpdateConsensusInformation() } if willJoinConsensus { diff --git a/scripts/setup_bls_build_flags.sh b/scripts/setup_bls_build_flags.sh index 111174d3b..13d4f4695 100644 --- a/scripts/setup_bls_build_flags.sh +++ b/scripts/setup_bls_build_flags.sh @@ -35,10 +35,3 @@ case $OS in export DYLD_FALLBACK_LIBRARY_PATH=$LD_LIBRARY_PATH ;; esac - -if [ "$1" == '-v' ]; then - echo "{ \"CGO_CFLAGS\" : \"$CGO_CFLAGS\", - \"CGO_LDFLAGS\" : \"$CGO_LDFLAGS\", - \"LD_LIBRARY_PATH\" : \"$LD_LIBRARY_PATH\", - \"DYLD_FALLBACK_LIBRARY_PATH\" : \"$DYLD_FALLBACK_LIBRARY_PATH\"}" | jq "." -fi From 1ee9a599d05db7f54ebd0b41f121109b285891aa Mon Sep 17 00:00:00 2001 From: Chao Ma Date: Wed, 16 Oct 2019 22:52:18 -0700 Subject: [PATCH 2/2] update consensus information in sync loop --- api/service/syncing/syncing.go | 7 ++++++- node/node_syncing.go | 9 ++------- scripts/setup_bls_build_flags.sh | 7 +++++++ 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/api/service/syncing/syncing.go b/api/service/syncing/syncing.go index ed2128e35..35d5c4d26 100644 --- a/api/service/syncing/syncing.go +++ b/api/service/syncing/syncing.go @@ -15,6 +15,7 @@ import ( "github.com/ethereum/go-ethereum/rlp" "github.com/harmony-one/harmony/api/service/syncing/downloader" pb "github.com/harmony-one/harmony/api/service/syncing/downloader/proto" + "github.com/harmony-one/harmony/consensus" "github.com/harmony-one/harmony/core" "github.com/harmony-one/harmony/core/types" "github.com/harmony-one/harmony/internal/ctxerror" @@ -741,7 +742,7 @@ func (ss *StateSync) IsOutOfSync(bc *core.BlockChain) bool { } // SyncLoop will keep syncing with peers until catches up -func (ss *StateSync) SyncLoop(bc *core.BlockChain, worker *worker.Worker, isBeacon bool) { +func (ss *StateSync) SyncLoop(bc *core.BlockChain, worker *worker.Worker, isBeacon bool, consensus *consensus.Consensus) { if !isBeacon { ss.RegisterNodeInfo() } @@ -754,6 +755,7 @@ Loop: case <-ticker.C: otherHeight := ss.getMaxPeerHeight(isBeacon) currentHeight := bc.CurrentBlock().NumberU64() + if currentHeight >= otherHeight { utils.Logger().Info().Msgf("[SYNC] Node is now IN SYNC! (isBeacon: %t, ShardID: %d, otherHeight: %d, currentHeight: %d)", isBeacon, bc.ShardID(), otherHeight, currentHeight) break Loop @@ -767,6 +769,9 @@ Loop: } ss.ProcessStateSync(startHash[:], size, bc, worker) ss.purgeOldBlocksFromCache() + if consensus != nil { + consensus.UpdateConsensusInformation() + } } } ss.purgeAllBlocksFromCache() diff --git a/node/node_syncing.go b/node/node_syncing.go index 14f7cc8d2..b72419cea 100644 --- a/node/node_syncing.go +++ b/node/node_syncing.go @@ -192,7 +192,7 @@ func (node *Node) DoBeaconSyncing() { continue } } - node.beaconSync.SyncLoop(node.Beaconchain(), node.BeaconWorker, true) + node.beaconSync.SyncLoop(node.Beaconchain(), node.BeaconWorker, true, nil) time.Sleep(BeaconSyncFrequency * time.Second) } } @@ -234,12 +234,7 @@ SyncingLoop: if willJoinConsensus { node.Consensus.BlocksNotSynchronized() } - node.stateSync.SyncLoop(bc, worker, false) - // update the consensus and committee information at the end of epoch including explorer node - // only when the syncing shard is different than node's own shard, we don't update it - if node.Blockchain().ShardID() == bc.ShardID() && core.ShardingSchedule.IsLastBlock(bc.CurrentBlock().NumberU64()) { - node.Consensus.UpdateConsensusInformation() - } + node.stateSync.SyncLoop(bc, worker, false, node.Consensus) if willJoinConsensus { node.stateMutex.Lock() node.State = NodeReadyForConsensus diff --git a/scripts/setup_bls_build_flags.sh b/scripts/setup_bls_build_flags.sh index 13d4f4695..111174d3b 100644 --- a/scripts/setup_bls_build_flags.sh +++ b/scripts/setup_bls_build_flags.sh @@ -35,3 +35,10 @@ case $OS in export DYLD_FALLBACK_LIBRARY_PATH=$LD_LIBRARY_PATH ;; esac + +if [ "$1" == '-v' ]; then + echo "{ \"CGO_CFLAGS\" : \"$CGO_CFLAGS\", + \"CGO_LDFLAGS\" : \"$CGO_LDFLAGS\", + \"LD_LIBRARY_PATH\" : \"$LD_LIBRARY_PATH\", + \"DYLD_FALLBACK_LIBRARY_PATH\" : \"$DYLD_FALLBACK_LIBRARY_PATH\"}" | jq "." +fi