ledger/sync/tx: further simplify tx syncing
@@ -8,46 +8,26 @@ import (
)
func txSync(ledger *Ledger) func(ctx context.Context) error {
- queries := make(map[common.TransactionID]uint8)
-
return func(ctx context.Context) error {
- set := make(map[common.TransactionID]struct{})
+ var missing []common.TransactionID
ledger.mu.RLock()
for id := range ledger.graph.missing {
- if _, queried := queries[id]; !queried {
- set[id] = struct{}{}
- queries[id] = 0
- }
+ missing = append(missing, id)
}
ledger.mu.RUnlock()
- if len(set) == 0 {
+ if len(missing) == 0 {
return ErrNonePreferred
}
- var missing []common.TransactionID
-
- for id := range set {
- missing = append(missing, id)
- }
-
- for id, count := range queries {
- if count < 3 { // Query a missing transaction at most 3 times.
- missing = append(missing, id)
- count++
- } else {
- delete(queries, id)
- }
- }
-
fmt.Println("QUERYING", len(missing), "TRANSACTIONS")
- return downloadMissingTransactions(ctx, ledger, missing, queries)
+ return downloadMissingTransactions(ctx, ledger, missing)
}
}
-func downloadMissingTransactions(ctx context.Context, ledger *Ledger, missing []common.TransactionID, queries map[common.TransactionID]uint8) error {
+func downloadMissingTransactions(ctx context.Context, ledger *Ledger, missing []common.TransactionID) error {
evt := EventDownloadTX{
IDs: missing,
Result: make(chan []Transaction, 1),
@@ -81,8 +61,6 @@ func downloadMissingTransactions(ctx context.Context, ledger *Ledger, missing []
} else {
terr = errors.Wrap(err, terr.Error())
}
- } else {
- delete(queries, tx.ID)
}
}
