use traceResult instead of traceData

pull/3818/head
peekpi 3 years ago
parent 0d7dae9345
commit d21f18f96c
  1. 14
      api/service/explorer/schema.go
  2. 10
      api/service/explorer/service.go
  3. 16
      api/service/explorer/storage.go
  4. 4
      node/node_explorer.go

@ -37,21 +37,21 @@ func writeCheckpoint(db databaseWriter, bn uint64) error {
return db.Put(blockCheckpoint, []byte{})
}
func GetTraceDataKey(hash common.Hash) []byte {
func getTraceResultKey(hash common.Hash) []byte {
return []byte(fmt.Sprintf("%s_%x", TracePrefix, hash))
}
func isTraceDataInDB(db databaseReader, hash common.Hash) (bool, error) {
key := GetTraceDataKey(hash)
func isTraceResultInDB(db databaseReader, hash common.Hash) (bool, error) {
key := getTraceResultKey(hash)
return db.Has(key)
}
func writeTraceData(db databaseWriter, hash common.Hash, data []byte) error {
key := GetTraceDataKey(hash)
func writeTraceResult(db databaseWriter, hash common.Hash, data []byte) error {
key := getTraceResultKey(hash)
return db.Put(key, data)
}
func getTraceData(db databaseReader, hash common.Hash) ([]byte, error) {
key := GetTraceDataKey(hash)
func getTraceResult(db databaseReader, hash common.Hash) ([]byte, error) {
key := getTraceResultKey(hash)
return db.Get(key)
}

@ -187,13 +187,13 @@ func (s *Service) GetStakingTxHashesByAccount(address string) ([]ethCommon.Hash,
return s.storage.GetStakingTxsByAddress(address)
}
func (s *Service) GetTraceDataByHash(hash ethCommon.Hash) (json.RawMessage, error) {
return s.storage.GetTraceDataByHash(hash)
func (s *Service) GetTraceResultByHash(hash ethCommon.Hash) (json.RawMessage, error) {
return s.storage.GetTraceResultByHash(hash)
}
// TraceNewBlock instruct the explorer storage to trace data in explorer DB
func (s *Service) TraceNewBlock(hash ethCommon.Hash, data []byte) {
s.storage.TraceNewBlock(hash, data)
// DumpTraceResult instruct the explorer storage to trace data in explorer DB
func (s *Service) DumpTraceResult(hash ethCommon.Hash, data []byte) {
s.storage.DumpTraceResult(hash, data)
}
// DumpNewBlock instruct the explorer storage to dump block data in explorer DB

@ -82,7 +82,7 @@ func (s *storage) Close() {
close(s.closeC)
}
func (s *storage) TraceNewBlock(hash common.Hash, data []byte) {
func (s *storage) DumpTraceResult(hash common.Hash, data []byte) {
s.tm.AddNewTraceTask(hash, data)
}
@ -126,11 +126,11 @@ func (s *storage) GetStakingTxsByAddress(addr string) ([]common.Hash, []TxType,
return getStakingTxnHashesByAccount(s.db, oneAddress(addr))
}
func (s *storage) GetTraceDataByHash(hash common.Hash) (json.RawMessage, error) {
func (s *storage) GetTraceResultByHash(hash common.Hash) (json.RawMessage, error) {
if !s.available.IsSet() {
return nil, ErrExplorerNotReady
}
return getTraceData(s.db, hash)
return getTraceResult(s.db, hash)
}
func (s *storage) run() {
@ -291,14 +291,14 @@ LOOP:
return
}
}
case traceData := <-bc.tm.T:
if exist, err := isTraceDataInDB(bc.db, traceData.hash); exist || err != nil {
case traceResult := <-bc.tm.T:
if exist, err := isTraceResultInDB(bc.db, traceResult.hash); exist || err != nil {
continue
}
traceData.btc = bc.db.NewBatch()
_ = writeTraceData(traceData.btc, traceData.hash, traceData.data)
traceResult.btc = bc.db.NewBatch()
_ = writeTraceResult(traceResult.btc, traceResult.hash, traceResult.data)
select {
case bc.resultT <- traceData:
case bc.resultT <- traceResult:
case <-bc.closeC:
return
}

@ -134,7 +134,7 @@ func (node *Node) TraceLoopForExplorer() {
if traceResults, err := ev.Tracer.GetResult(); err == nil {
if exp, err := node.getExplorerService(); err == nil {
if raw, err := json.Marshal(traceResults); err == nil {
exp.TraceNewBlock(ev.Block.Hash(), raw)
exp.DumpTraceResult(ev.Block.Hash(), raw)
}
}
}
@ -279,7 +279,7 @@ func (node *Node) GetTraceResultByHash(hash common.Hash) (json.RawMessage, error
if err != nil {
return nil, err
}
return exp.GetTraceDataByHash(hash)
return exp.GetTraceResultByHash(hash)
}
func (node *Node) getExplorerService() (*explorer.Service, error) {

Loading…
Cancel
Save