Skip to content

Commit

Permalink
offline mode reader
Browse files Browse the repository at this point in the history
  • Loading branch information
diego1q2w committed Jun 16, 2022
1 parent 0bc8c59 commit f87636b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
7 changes: 6 additions & 1 deletion api/service/explorer/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,12 @@ type Service struct {

// New returns explorer service.
func New(harmonyConfig *harmonyconfig.HarmonyConfig, selfPeer *p2p.Peer, bc *core.BlockChain, backend hmy.NodeAPI) *Service {
dbPath := defaultDBPath(selfPeer.IP, selfPeer.Port)
pathIP := selfPeer.IP
if harmonyConfig.General.UseTiKV {
pathIP = nodeconfig.DefaultPublicListenIP // using the same pathIP for the TIKV mode, so it remains constant across readers and writers, since this is used as prefix for the DB keys
}

dbPath := defaultDBPath(pathIP, selfPeer.Port)
storage, err := newStorage(harmonyConfig, bc, dbPath)
if err != nil {
utils.Logger().Fatal().Err(err).Msg("cannot open explorer DB")
Expand Down
2 changes: 2 additions & 0 deletions cmd/harmony/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,8 @@ func setupNodeAndRun(hc harmonyconfig.HarmonyConfig) {
currentNode.StartGRPCSyncClient()
}

currentNode.NodeSyncing()

if err := currentNode.StartServices(); err != nil {
fmt.Fprint(os.Stderr, err.Error())
os.Exit(-1)
Expand Down
16 changes: 10 additions & 6 deletions node/node_syncing.go
Original file line number Diff line number Diff line change
Expand Up @@ -342,17 +342,21 @@ func (node *Node) StartGRPCSyncClient() {
Msg("SupportBeaconSyncing")
go node.doBeaconSyncing()
}
}

// NodeSyncing makes sure to start all the processes needed to sync the node based on different configuration factors.
func (node *Node) NodeSyncing() {
if node.HarmonyConfig.General.UseTiKV {
node.syncFromTiKVWriter()
node.syncFromTiKVWriter() // this is for both reader and backup writers

if node.HarmonyConfig.TiKV.Role == "Writer" {
node.supportSyncing()
} else {
if node.HarmonyConfig.TiKV.Role == "Reader" {
node.Consensus.UpdateConsensusInformation()
}
} else {
node.supportSyncing()
if node.HarmonyConfig.TiKV.Role == "Writer" {
node.supportSyncing() // the writer needs to be in sync with it's other peers
}
} else if !node.HarmonyConfig.General.IsOffline && node.HarmonyConfig.DNSSync.Client {
node.supportSyncing() // for non-writer-reader mode a.k.a tikv nodes
}
}

Expand Down

0 comments on commit f87636b

Please sign in to comment.