diff --git a/ledger/state/storeview.go b/ledger/state/storeview.go index e82483ac..43e24e0d 100644 --- a/ledger/state/storeview.go +++ b/ledger/state/storeview.go @@ -86,7 +86,7 @@ func (sv *StoreView) IncrementHeight() { func (sv *StoreView) Save() common.Hash { rootHash, err := sv.store.Commit() - logger.Infof("Commit to data store, height: %v, rootHash: %v", sv.height+1, rootHash.Hex()) + logger.Debugf("Commit to data store, height: %v, rootHash: %v", sv.height+1, rootHash.Hex()) if err != nil { log.Panicf("Failed to save the StoreView: %v", err) diff --git a/rpc/query.go b/rpc/query.go index cf659c22..2a0d3990 100644 --- a/rpc/query.go +++ b/rpc/query.go @@ -364,7 +364,7 @@ func (t *ThetaRPCService) GetBlockByHeight(args *GetBlockByHeightArgs, result *G type GetBlocksByRangeArgs struct { Start common.JSONUint64 `json:"start"` - End common.JSONUint64 `json:"end"` + End common.JSONUint64 `json:"end"` } func (t *ThetaRPCService) GetBlocksByRange(args *GetBlocksByRangeArgs, result *GetBlocksResult) (err error) { @@ -376,7 +376,7 @@ func (t *ThetaRPCService) GetBlocksByRange(args *GetBlocksByRangeArgs, result *G return errors.New("Starting block must be less than ending block") } - if args.End - args.Start > 100 { + if args.End-args.Start > 100 { return errors.New("Can't retrieve more than 100 blocks at a time") } @@ -464,16 +464,16 @@ func (t *ThetaRPCService) GetStatus(args *GetStatusArgs, result *GetStatusResult result.PeerID = t.dispatcher.LibP2PID() // TODO: use ID() instead after 1.3.0 upgrade result.ChainID = t.consensus.Chain().ChainID latestFinalizedHash := s.LastFinalizedBlock + var latestFinalizedBlock *core.ExtendedBlock if !latestFinalizedHash.IsEmpty() { result.LatestFinalizedBlockHash = latestFinalizedHash - block, err := t.chain.FindBlock(latestFinalizedHash) + latestFinalizedBlock, err = t.chain.FindBlock(latestFinalizedHash) if err != nil { return err } - result.LatestFinalizedBlockEpoch = common.JSONUint64(block.Epoch) - result.LatestFinalizedBlockHeight = common.JSONUint64(block.Height) - result.LatestFinalizedBlockTime = (*common.JSONBig)(block.Timestamp) - result.Syncing = isSyncing(block) + result.LatestFinalizedBlockEpoch = common.JSONUint64(latestFinalizedBlock.Epoch) + result.LatestFinalizedBlockHeight = common.JSONUint64(latestFinalizedBlock.Height) + result.LatestFinalizedBlockTime = (*common.JSONBig)(latestFinalizedBlock.Timestamp) } result.CurrentEpoch = common.JSONUint64(s.Epoch) result.CurrentTime = (*common.JSONBig)(big.NewInt(time.Now().Unix())) @@ -491,6 +491,9 @@ func (t *ThetaRPCService) GetStatus(args *GetStatusArgs, result *GetStatusResult } result.CurrentHeight = common.JSONUint64(maxVoteHeight - 1) // current finalized height is at most maxVoteHeight-1 } + + result.Syncing = isSyncing(latestFinalizedBlock, uint64(result.CurrentHeight)) + return } @@ -666,10 +669,18 @@ func getTxType(tx types.Tx) byte { return t } -func isSyncing(block *core.ExtendedBlock) bool { +func isSyncing(lastestFinalizedBlock *core.ExtendedBlock, currentHeight uint64) bool { + if lastestFinalizedBlock == nil { + return true + } currentTime := big.NewInt(time.Now().Unix()) maxDiff := new(big.Int).SetUint64(30) // thirty seconds, about 5 blocks threshold := new(big.Int).Sub(currentTime, maxDiff) - isSyncing := block.Timestamp.Cmp(threshold) < 0 + isSyncing := lastestFinalizedBlock.Timestamp.Cmp(threshold) < 0 + + if isSyncing { // sometimes the validator node clock is off, so here we also compare the block heights + isSyncing = (currentHeight - lastestFinalizedBlock.Height) > 5 + } + return isSyncing }