Skip to content

Commit

Permalink
Load less blocks for forking local chain
Browse files Browse the repository at this point in the history
  • Loading branch information
dyng committed Mar 5, 2023
1 parent 8591858 commit a244331
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
12 changes: 8 additions & 4 deletions internal/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,15 @@ func (s *Service) GetAccount(address string) (*Account, error) {
return a, nil
}

// GetLatestTransactions returns transactions of last n blocks.
func (s *Service) GetLatestTransactions(n int) (common.Transactions, error) {
// GetLatestTransactions returns last n transactions of at most nBlock blocks.
func (s *Service) GetLatestTransactions(n int, nBlock int) (common.Transactions, error) {
max, err := s.GetBlockHeight()
if err != nil {
return nil, err
}

min := uint64(1)
cnt := uint64(n)
cnt := uint64(nBlock)
if max > cnt-1 {
min = max - cnt + 1
}
Expand All @@ -152,6 +152,10 @@ func (s *Service) GetLatestTransactions(n int) (common.Transactions, error) {
}

transactions = append(transactions, txns...)

if len(transactions) >= n {
break
}
}

return transactions, nil
Expand Down Expand Up @@ -189,7 +193,7 @@ func (s *Service) GetTransactionHistory(address common.Address) (common.Transact
}

func (s *Service) transactionsByTraverse(address common.Address) (common.Transactions, error) {
candidates, err := s.GetLatestTransactions(100)
candidates, err := s.GetLatestTransactions(100, 5)
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions internal/view/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ func (a *App) firstSync() error {
a.root.home.transactionList.LoadAsync(func() (common.Transactions, error) {
netType := a.service.GetNetwork().NetType()
if netType == serv.TypeDevnet {
return a.service.GetLatestTransactions(100)
return a.service.GetLatestTransactions(100, 5)
} else {
return a.service.GetLatestTransactions(1)
return a.service.GetLatestTransactions(100, 1)
}
})

Expand Down

0 comments on commit a244331

Please sign in to comment.